@vysmo/flipbook 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 +100 -0
- package/dist/create.d.ts +18 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +598 -0
- package/dist/create.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +10 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +26 -0
- package/dist/loader.js.map +1 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
- package/src/__tests__/create.test.ts +465 -0
- package/src/__tests__/ssr.test.ts +18 -0
- package/src/__tests__/types-check.ts +91 -0
- package/src/create.ts +653 -0
- package/src/index.ts +9 -0
- package/src/loader.ts +31 -0
- package/src/types.ts +123 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maesto LLC
|
|
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
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @vysmo/flipbook
|
|
2
|
+
|
|
3
|
+
WebGL flipbook driven by the [`@vysmo/transitions`](https://www.npmjs.com/package/@vysmo/transitions) page-curl mesh shader. Click halves, keyboard nav, **drag corners to scrub mid-flip** — the page-curl shader's `progress` follows your pointer, release past 50% to commit the flip, less to revert. Drop-in component or headless API.
|
|
4
|
+
|
|
5
|
+
[Live demo + playground](https://vysmo.com/flipbook) · [Source](https://github.com/vysmodev)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @vysmo/flipbook @vysmo/transitions @vysmo/animations @vysmo/easings
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
(Peers ship separately so you can pin them per-project. They're transitive deps; `npm install @vysmo/flipbook` pulls them in automatically — just add to your own `package.json` if you want explicit version control.)
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createFlipbook } from "@vysmo/flipbook";
|
|
19
|
+
|
|
20
|
+
const flip = createFlipbook({
|
|
21
|
+
container: document.querySelector("#book")!,
|
|
22
|
+
pages: [
|
|
23
|
+
"/p1.jpg",
|
|
24
|
+
"/p2.jpg",
|
|
25
|
+
"/p3.jpg",
|
|
26
|
+
"/p4.jpg",
|
|
27
|
+
],
|
|
28
|
+
axis: "horizontal", // or "vertical"
|
|
29
|
+
loop: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Click halves / drag corners / arrow keys are all wired by default.
|
|
33
|
+
flip.next();
|
|
34
|
+
flip.prev();
|
|
35
|
+
flip.goTo(2);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Pages
|
|
39
|
+
|
|
40
|
+
`pages` accepts:
|
|
41
|
+
- Image URLs (string)
|
|
42
|
+
- `HTMLImageElement` (already-loaded)
|
|
43
|
+
- `HTMLCanvasElement` / `OffscreenCanvas`
|
|
44
|
+
- `HTMLVideoElement`
|
|
45
|
+
- Any other `TextureSource` (per [`@vysmo/transitions`](https://www.npmjs.com/package/@vysmo/transitions))
|
|
46
|
+
|
|
47
|
+
The flipbook resolves URL strings into images for you and uploads each page to the GPU via `TextureCache`.
|
|
48
|
+
|
|
49
|
+
## Drag-scrub
|
|
50
|
+
|
|
51
|
+
The signature feature: when you drag a corner of the book mid-flip, the page-curl shader's `progress` follows your pointer in real time. Release past 50% to commit; less to revert with a spring tween back to the previous page. This is what differentiates the component from a CSS-only flipbook — there's no equivalent without the shader.
|
|
52
|
+
|
|
53
|
+
Disable with `enableDrag: false` if you only want click + keyboard navigation.
|
|
54
|
+
|
|
55
|
+
## Options
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// @no-check
|
|
59
|
+
type FlipbookOptions = {
|
|
60
|
+
container: HTMLElement;
|
|
61
|
+
pages: PageSource[];
|
|
62
|
+
axis?: "horizontal" | "vertical"; // default "horizontal"
|
|
63
|
+
loop?: boolean; // wrap last → first
|
|
64
|
+
duration?: number; // ms per flip (default 900)
|
|
65
|
+
ease?: EasingFn; // default cubicInOut
|
|
66
|
+
radius?: number; // page-curl radius (default 0.35)
|
|
67
|
+
tilt?: number; // page-curl tilt (default 0.12)
|
|
68
|
+
backColor?: [number, number, number]; // back-of-page tint (default warm white)
|
|
69
|
+
enableDrag?: boolean; // default true
|
|
70
|
+
dragCommit?: number; // 0..1 — release threshold (default 0.5)
|
|
71
|
+
enableKeyboard?: boolean; // default true
|
|
72
|
+
autoplay?: boolean | number; // true → 4s; number → custom ms
|
|
73
|
+
// ... and a few more
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Events
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
flip.on("change", (current, previous) => /* … */);
|
|
81
|
+
flip.on("flipstart", (from, to) => /* … */);
|
|
82
|
+
flip.on("flipend", (from, to) => /* … */);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Disposal
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
flip.dispose(); // releases GPU resources, removes listeners
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Characteristics
|
|
92
|
+
|
|
93
|
+
- **DOM-only.** Requires `HTMLCanvasElement` and pointer / keyboard events.
|
|
94
|
+
- **WebGL2 only** (transitive — driven by `@vysmo/transitions`).
|
|
95
|
+
- **SSR-safe at module load.** Module imports cleanly in Node; constructing requires a live DOM.
|
|
96
|
+
- **Bundle:** ~3 KB gzipped (peers external).
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT.
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FlipbookHandle, FlipbookOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a WebGL flipbook around the page-curl mesh transition.
|
|
4
|
+
*
|
|
5
|
+
* Pass a container element + an array of page sources (image URLs,
|
|
6
|
+
* `HTMLImageElement`s, canvases, or videos) and you get a fully wired
|
|
7
|
+
* flipbook: click halves to flip, arrow keys for keyboard nav, drag the
|
|
8
|
+
* corner mid-flip to scrub the curl manually (release past 50% to commit,
|
|
9
|
+
* less to revert), optional autoplay with pause-on-hover.
|
|
10
|
+
*
|
|
11
|
+
* The handle exposes `.next()`, `.prev()`, `.goTo(index)`, `.play()`,
|
|
12
|
+
* `.pause()`, `.dispose()`, plus `.on(event, listener)` for lifecycle
|
|
13
|
+
* (`change`, `flipstart`, `flipend`).
|
|
14
|
+
*
|
|
15
|
+
* @throws Error if `options.pages` is empty.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createFlipbook(options: FlipbookOptions): FlipbookHandle;
|
|
18
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAIV,cAAc,EACd,eAAe,EAChB,MAAM,YAAY,CAAC;AAiBpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAolBvE"}
|