@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("SSR safety", () => {
|
|
4
|
+
it("window is undefined in this runtime", () => {
|
|
5
|
+
expect(typeof window).toBe("undefined");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("module loads without DOM globals", async () => {
|
|
9
|
+
const mod = await import("../index.js");
|
|
10
|
+
expect(mod).toBeDefined();
|
|
11
|
+
expect(typeof mod.createFlipbook).toBe("function");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("loader utilities can be imported at module load", async () => {
|
|
15
|
+
const { resolvePage } = await import("../loader.js");
|
|
16
|
+
expect(typeof resolvePage).toBe("function");
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { cubicInOut } from "@vysmo/easings";
|
|
2
|
+
import {
|
|
3
|
+
createFlipbook,
|
|
4
|
+
type FlipbookHandle,
|
|
5
|
+
type PageSource,
|
|
6
|
+
} from "../index.js";
|
|
7
|
+
|
|
8
|
+
declare const container: HTMLElement;
|
|
9
|
+
declare const img: HTMLImageElement;
|
|
10
|
+
declare const canvas: HTMLCanvasElement;
|
|
11
|
+
|
|
12
|
+
// --- PageSource union accepts strings, images, canvases -----------------
|
|
13
|
+
|
|
14
|
+
const _a: PageSource = "https://example.com/p1.jpg";
|
|
15
|
+
const _b: PageSource = img;
|
|
16
|
+
const _c: PageSource = canvas;
|
|
17
|
+
void [_a, _b, _c];
|
|
18
|
+
|
|
19
|
+
// --- Minimal and maximal option shapes ----------------------------------
|
|
20
|
+
|
|
21
|
+
const minimal: FlipbookHandle = createFlipbook({
|
|
22
|
+
container,
|
|
23
|
+
pages: ["a.jpg", "b.jpg"],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const full: FlipbookHandle = createFlipbook({
|
|
27
|
+
container,
|
|
28
|
+
pages: [img, canvas, "c.jpg"],
|
|
29
|
+
initialPage: 1,
|
|
30
|
+
axis: "vertical",
|
|
31
|
+
tilt: 0.1,
|
|
32
|
+
backColor: [0.95, 0.95, 0.95],
|
|
33
|
+
flipDuration: 1100,
|
|
34
|
+
ease: cubicInOut,
|
|
35
|
+
loop: false,
|
|
36
|
+
clickNavigation: false,
|
|
37
|
+
dragNavigation: false,
|
|
38
|
+
keyboardNavigation: false,
|
|
39
|
+
ariaLabel: "Magazine",
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
void [minimal, full];
|
|
43
|
+
|
|
44
|
+
// --- Handle surface -----------------------------------------------------
|
|
45
|
+
|
|
46
|
+
declare const f: FlipbookHandle;
|
|
47
|
+
|
|
48
|
+
const _current: number = f.current;
|
|
49
|
+
const _length: number = f.length;
|
|
50
|
+
const _isFlipping: boolean = f.isFlipping;
|
|
51
|
+
const _ready: Promise<void> = f.ready;
|
|
52
|
+
const _next: Promise<void> = f.next();
|
|
53
|
+
const _prev: Promise<void> = f.prev();
|
|
54
|
+
const _goA: Promise<void> = f.goTo(1);
|
|
55
|
+
const _goB: Promise<void> = f.goTo(1, { instant: true });
|
|
56
|
+
const _offChange: () => void = f.on("change", (cur, prev) => void [cur, prev]);
|
|
57
|
+
const _offStart: () => void = f.on(
|
|
58
|
+
"flipstart",
|
|
59
|
+
(from, to) => void [from, to],
|
|
60
|
+
);
|
|
61
|
+
const _offEnd: () => void = f.on("flipend", (from, to) => void [from, to]);
|
|
62
|
+
const _destroy: void = f.destroy();
|
|
63
|
+
|
|
64
|
+
void [
|
|
65
|
+
_current,
|
|
66
|
+
_length,
|
|
67
|
+
_isFlipping,
|
|
68
|
+
_ready,
|
|
69
|
+
_next,
|
|
70
|
+
_prev,
|
|
71
|
+
_goA,
|
|
72
|
+
_goB,
|
|
73
|
+
_offChange,
|
|
74
|
+
_offStart,
|
|
75
|
+
_offEnd,
|
|
76
|
+
_destroy,
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
// --- Negative assertions ------------------------------------------------
|
|
80
|
+
|
|
81
|
+
// @ts-expect-error — container is required
|
|
82
|
+
createFlipbook({ pages: ["a"] });
|
|
83
|
+
|
|
84
|
+
// @ts-expect-error — pages is required
|
|
85
|
+
createFlipbook({ container });
|
|
86
|
+
|
|
87
|
+
// @ts-expect-error — invalid axis literal
|
|
88
|
+
createFlipbook({ container, pages: ["a"], axis: "diagonal" });
|
|
89
|
+
|
|
90
|
+
// @ts-expect-error — unknown event name
|
|
91
|
+
f.on("nope", () => void 0);
|