@gfazioli/mantine-book 1.0.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/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +18 -0
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/dist/cjs/Book/Book.cjs +327 -0
- package/dist/cjs/Book/Book.cjs.map +1 -0
- package/dist/cjs/Book/Book.context.cjs +28 -0
- package/dist/cjs/Book/Book.context.cjs.map +1 -0
- package/dist/cjs/Book/Book.module.css.cjs +7 -0
- package/dist/cjs/Book/Book.module.css.cjs.map +1 -0
- package/dist/cjs/Book/BookPage.cjs +27 -0
- package/dist/cjs/Book/BookPage.cjs.map +1 -0
- package/dist/cjs/Book/page-index.cjs +15 -0
- package/dist/cjs/Book/page-index.cjs.map +1 -0
- package/dist/cjs/Curl/Curl.cjs +298 -0
- package/dist/cjs/Curl/Curl.cjs.map +1 -0
- package/dist/cjs/Curl/Curl.module.css.cjs +7 -0
- package/dist/cjs/Curl/Curl.module.css.cjs.map +1 -0
- package/dist/cjs/Curl/webgl/CurlWebglLayer.cjs +262 -0
- package/dist/cjs/Curl/webgl/CurlWebglLayer.cjs.map +1 -0
- package/dist/cjs/Curl/webgl/glRenderer.cjs +358 -0
- package/dist/cjs/Curl/webgl/glRenderer.cjs.map +1 -0
- package/dist/cjs/Curl/webgl/pool.cjs +56 -0
- package/dist/cjs/Curl/webgl/pool.cjs.map +1 -0
- package/dist/cjs/Curl/webgl/poolContext.cjs +9 -0
- package/dist/cjs/Curl/webgl/poolContext.cjs.map +1 -0
- package/dist/cjs/Curl/webgl/snapshot.cjs +25 -0
- package/dist/cjs/Curl/webgl/snapshot.cjs.map +1 -0
- package/dist/cjs/flip/animator.cjs +53 -0
- package/dist/cjs/flip/animator.cjs.map +1 -0
- package/dist/cjs/flip/coneDeformer.cjs +36 -0
- package/dist/cjs/flip/coneDeformer.cjs.map +1 -0
- package/dist/cjs/flip/drag.cjs +185 -0
- package/dist/cjs/flip/drag.cjs.map +1 -0
- package/dist/cjs/flip/geometry.cjs +146 -0
- package/dist/cjs/flip/geometry.cjs.map +1 -0
- package/dist/cjs/flip/useCurlController.cjs +178 -0
- package/dist/cjs/flip/useCurlController.cjs.map +1 -0
- package/dist/cjs/index.cjs +14 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/Book/Book.context.mjs +24 -0
- package/dist/esm/Book/Book.context.mjs.map +1 -0
- package/dist/esm/Book/Book.mjs +325 -0
- package/dist/esm/Book/Book.mjs.map +1 -0
- package/dist/esm/Book/Book.module.css.mjs +5 -0
- package/dist/esm/Book/Book.module.css.mjs.map +1 -0
- package/dist/esm/Book/BookPage.mjs +25 -0
- package/dist/esm/Book/BookPage.mjs.map +1 -0
- package/dist/esm/Book/page-index.mjs +12 -0
- package/dist/esm/Book/page-index.mjs.map +1 -0
- package/dist/esm/Curl/Curl.mjs +295 -0
- package/dist/esm/Curl/Curl.mjs.map +1 -0
- package/dist/esm/Curl/Curl.module.css.mjs +5 -0
- package/dist/esm/Curl/Curl.module.css.mjs.map +1 -0
- package/dist/esm/Curl/webgl/CurlWebglLayer.mjs +260 -0
- package/dist/esm/Curl/webgl/CurlWebglLayer.mjs.map +1 -0
- package/dist/esm/Curl/webgl/glRenderer.mjs +356 -0
- package/dist/esm/Curl/webgl/glRenderer.mjs.map +1 -0
- package/dist/esm/Curl/webgl/pool.mjs +54 -0
- package/dist/esm/Curl/webgl/pool.mjs.map +1 -0
- package/dist/esm/Curl/webgl/poolContext.mjs +7 -0
- package/dist/esm/Curl/webgl/poolContext.mjs.map +1 -0
- package/dist/esm/Curl/webgl/snapshot.mjs +23 -0
- package/dist/esm/Curl/webgl/snapshot.mjs.map +1 -0
- package/dist/esm/flip/animator.mjs +50 -0
- package/dist/esm/flip/animator.mjs.map +1 -0
- package/dist/esm/flip/coneDeformer.mjs +34 -0
- package/dist/esm/flip/coneDeformer.mjs.map +1 -0
- package/dist/esm/flip/drag.mjs +180 -0
- package/dist/esm/flip/drag.mjs.map +1 -0
- package/dist/esm/flip/geometry.mjs +138 -0
- package/dist/esm/flip/geometry.mjs.map +1 -0
- package/dist/esm/flip/useCurlController.mjs +176 -0
- package/dist/esm/flip/useCurlController.mjs.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/styles.layer.css +1 -0
- package/dist/types/Book/Book.context.d.ts +52 -0
- package/dist/types/Book/Book.d.ts +116 -0
- package/dist/types/Book/BookPage.d.ts +22 -0
- package/dist/types/Book/page-index.d.ts +13 -0
- package/dist/types/Curl/Curl.d.ts +140 -0
- package/dist/types/Curl/webgl/CurlWebglLayer.d.ts +53 -0
- package/dist/types/Curl/webgl/glRenderer.d.ts +64 -0
- package/dist/types/Curl/webgl/pool.d.ts +40 -0
- package/dist/types/Curl/webgl/poolContext.d.ts +11 -0
- package/dist/types/Curl/webgl/snapshot.d.ts +16 -0
- package/dist/types/CurlFace/CurlFace.d.ts +43 -0
- package/dist/types/flip/animator.d.ts +64 -0
- package/dist/types/flip/coneDeformer.d.ts +55 -0
- package/dist/types/flip/drag.d.ts +152 -0
- package/dist/types/flip/geometry.d.ts +101 -0
- package/dist/types/flip/useCurlController.d.ts +66 -0
- package/dist/types/index.d.mts +9 -0
- package/dist/types/index.d.ts +9 -0
- package/package.json +58 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-curl geometry — pure math, no React, no DOM.
|
|
3
|
+
*
|
|
4
|
+
* A page fold is a REFLECTION: the grabbed point on the free edge (`anchor`)
|
|
5
|
+
* folds onto the pointer (`target`), so the crease is the perpendicular
|
|
6
|
+
* bisector of anchor→target and the lifted flap is the page rectangle's
|
|
7
|
+
* anchor-side reflected across that crease. This single model covers a grab
|
|
8
|
+
* at ANY point of the edge — corner, mid-height, anywhere — and a drag in ANY
|
|
9
|
+
* direction. (StPageFlip's corner fold is the special case anchor = a corner;
|
|
10
|
+
* see RESEARCH-page-curl.md for the derivation and the iBooks/cone background.)
|
|
11
|
+
*/
|
|
12
|
+
/** A point on the 2D page plane. The spine is at x = 0; the free edge at x = ±W. */
|
|
13
|
+
export interface Point {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ReflectionFold {
|
|
18
|
+
/** Region where the Front face stays flat (spine side of the crease). */
|
|
19
|
+
flatFront: Point[];
|
|
20
|
+
/** The lifted region (anchor side of the crease), in page coords. */
|
|
21
|
+
flap: Point[];
|
|
22
|
+
/** CSS 2D matrix [a,b,c,d,e,f] reflecting page coords across the crease. */
|
|
23
|
+
matrix: [number, number, number, number, number, number];
|
|
24
|
+
/** 0–100: how far the fold has swept from the free edge toward the spine. */
|
|
25
|
+
progress: number;
|
|
26
|
+
/** Crease midpoint and direction (page coords) — for shadows later. */
|
|
27
|
+
creaseMid: Point;
|
|
28
|
+
creaseDir: Point;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Clamp the drag target so the fold never folds the spine or degenerates.
|
|
32
|
+
*
|
|
33
|
+
* A spine corner C stays on the flat side of the crease ⟺ it is at least as
|
|
34
|
+
* close to the target as to the anchor (|C − target| ≤ |C − anchor|). So the
|
|
35
|
+
* valid region is the intersection of two discs centred on the spine corners
|
|
36
|
+
* with radii = the anchor's distances to them. For a corner anchor this
|
|
37
|
+
* reduces exactly to StPageFlip's two `LimitPointToCircle` clamps.
|
|
38
|
+
*/
|
|
39
|
+
export declare function clampReflectionTarget(anchor: Point, target: Point, _pageWidth: number, pageHeight: number): Point;
|
|
40
|
+
/**
|
|
41
|
+
* Compute the reflection fold for grabbing `anchor` (a point on the free edge)
|
|
42
|
+
* and dragging it to `rawTarget`. Returns `null` at rest (drag below epsilon).
|
|
43
|
+
*
|
|
44
|
+
* The target is clamped via {@link clampReflectionTarget}; the crease is the
|
|
45
|
+
* perpendicular bisector of anchor→target; `flatFront` is the page rect on the
|
|
46
|
+
* spine side; `flap` is the rect on the anchor side; and `matrix` reflects the
|
|
47
|
+
* flap across the crease (det −1, so it also mirrors the back-face content).
|
|
48
|
+
*/
|
|
49
|
+
export declare function computeReflectionFold(anchor: Point, rawTarget: Point, pageWidth: number, pageHeight: number): ReflectionFold | null;
|
|
50
|
+
/**
|
|
51
|
+
* Decide whether releasing the drag should COMPLETE the fold (turn the page)
|
|
52
|
+
* or snap it back. Completes when dragged past `threshold`, or on a fast swipe
|
|
53
|
+
* heading toward the spine.
|
|
54
|
+
*
|
|
55
|
+
* "Toward the spine" is SIDE-AWARE: while the sheet rests on the right
|
|
56
|
+
* (`anchorX > 0`) that's a leftward swipe (`velocityX < 0`); once flipped to
|
|
57
|
+
* the left (`anchorX < 0`) it's a rightward swipe (`velocityX > 0`). The sign
|
|
58
|
+
* product `velocityX * anchorX < 0` captures both symmetrically.
|
|
59
|
+
*/
|
|
60
|
+
export declare function shouldCompleteFold(progress: number, threshold: number, isSwipe: boolean, velocityX: number, anchorX: number): boolean;
|
|
61
|
+
export interface FoldShadow {
|
|
62
|
+
/** The lifted flap at its REFLECTED (visible) position, in page coords. */
|
|
63
|
+
flapPolygon: Point[];
|
|
64
|
+
/** Linear-gradient line (page coords): dark at the crease → transparent into
|
|
65
|
+
* the flap. Use as SVG `userSpaceOnUse` x1,y1 → x2,y2. */
|
|
66
|
+
gradient: {
|
|
67
|
+
x1: number;
|
|
68
|
+
y1: number;
|
|
69
|
+
x2: number;
|
|
70
|
+
y2: number;
|
|
71
|
+
};
|
|
72
|
+
/** 0–1 shadow strength: 0 at rest, peaks mid-fold, 0 at a full turn. */
|
|
73
|
+
strength: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Derive the curl shadow from a {@link ReflectionFold}. The lifted flap reads
|
|
77
|
+
* darkest where it curves away (at the crease) and lightest at its free edge,
|
|
78
|
+
* so the gradient runs along the crease normal (the drag direction) anchored at
|
|
79
|
+
* the crease midpoint. The polygon is the flap REFLECTED across the crease —
|
|
80
|
+
* i.e. where the back face is actually drawn — so the shading overlays it.
|
|
81
|
+
*/
|
|
82
|
+
export declare function computeFoldShadow(fold: ReflectionFold, _pageWidth: number): FoldShadow;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience formatter — turns a list of points into a CSS `polygon(...)`
|
|
85
|
+
* value with the given unit (default `px`), for use as a `clip-path`.
|
|
86
|
+
*
|
|
87
|
+
* Returns `null` for fewer than 3 vertices (degenerate); the consumer should
|
|
88
|
+
* then fall back to no clip-path (keeps the element fully visible).
|
|
89
|
+
*/
|
|
90
|
+
export declare function pointsToCssPolygon(points: Point[], unit?: 'px' | '%'): string | null;
|
|
91
|
+
/** Where a programmatic page turn pretends to grab the free edge. */
|
|
92
|
+
export type TurnOrigin = 'top' | 'middle' | 'bottom';
|
|
93
|
+
/** Y of the simulated grab point on the free edge for a programmatic turn. */
|
|
94
|
+
export declare function turnAnchorY(origin: TurnOrigin, height: number): number;
|
|
95
|
+
/**
|
|
96
|
+
* Y of the simulated pointer mid-turn. A corner grab arcs toward the page
|
|
97
|
+
* middle (a sine bump peaking at half-turn) so the crease tilts diagonally
|
|
98
|
+
* like a real corner curl, then lands back on the edge; a middle grab keeps a
|
|
99
|
+
* constant Y, which folds the page over with a straight vertical crease.
|
|
100
|
+
*/
|
|
101
|
+
export declare function turnTargetY(origin: TurnOrigin, eased: number, height: number): number;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type PointerEventHandler, type RefObject } from 'react';
|
|
2
|
+
import { type ReflectionFold, type TurnOrigin } from './geometry';
|
|
3
|
+
export interface FoldView {
|
|
4
|
+
/** The active fold geometry (page coords), or `null` at rest. */
|
|
5
|
+
fold: ReflectionFold | null;
|
|
6
|
+
/** Which side the sheet rests on: `false` = right half, `true` = left half. */
|
|
7
|
+
flipped: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface CurlControllerOptions {
|
|
10
|
+
/** Sheet width in px (the play-zone is twice this). */
|
|
11
|
+
width: number;
|
|
12
|
+
/** Sheet height in px. */
|
|
13
|
+
height: number;
|
|
14
|
+
/** Progress (0–100) at/above which a release completes the flip. */
|
|
15
|
+
threshold: number;
|
|
16
|
+
/** Settle animation duration in ms. */
|
|
17
|
+
flippingTime: number;
|
|
18
|
+
swipeDistance?: number;
|
|
19
|
+
swipeTimeThreshold?: number;
|
|
20
|
+
mobileScrollSupport?: boolean;
|
|
21
|
+
/** When true, the drag handlers are omitted (resting only). */
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Controlled resting side. When provided, the sheet rests on the given side
|
|
25
|
+
* (`true` = left half) and external changes settle the sheet flat on the new
|
|
26
|
+
* side; the internal flip still reports through `onFlip` so the owner can
|
|
27
|
+
* update this value.
|
|
28
|
+
*/
|
|
29
|
+
flipped?: boolean;
|
|
30
|
+
/** Simulated grab point of a programmatic (controlled) turn. @default 'bottom' */
|
|
31
|
+
turnOrigin?: TurnOrigin;
|
|
32
|
+
/** The play-zone root element — used to map pointer → page-local coords. */
|
|
33
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
34
|
+
onFold?: (info: {
|
|
35
|
+
progress: number;
|
|
36
|
+
phase: 'grab' | 'move' | 'settle';
|
|
37
|
+
}) => void;
|
|
38
|
+
onFlip?: (info: {
|
|
39
|
+
flipped: boolean;
|
|
40
|
+
}) => void;
|
|
41
|
+
}
|
|
42
|
+
export interface CurlController extends FoldView {
|
|
43
|
+
/** True while a fold is active (dragging or settling). */
|
|
44
|
+
folding: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 0–100 curl amount, SIGNED toward the spine: it grows only as the grabbed
|
|
47
|
+
* edge is dragged toward the spine, and is 0 when dragged away (so the WebGL
|
|
48
|
+
* curl tracks the drag direction instead of any horizontal motion).
|
|
49
|
+
*/
|
|
50
|
+
curlProgress: number;
|
|
51
|
+
/** Pointer handlers to spread on the play-zone root (empty when disabled). */
|
|
52
|
+
dragHandlers: {
|
|
53
|
+
onPointerDown?: PointerEventHandler;
|
|
54
|
+
onPointerMove?: PointerEventHandler;
|
|
55
|
+
onPointerUp?: PointerEventHandler;
|
|
56
|
+
onPointerCancel?: PointerEventHandler;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Single source of truth for a Curl's fold. Owns the grab → drag →
|
|
61
|
+
* release-settle state machine, built on {@link useDragController} +
|
|
62
|
+
* {@link useFlipAnimator} + the reflection-fold geometry. Both the DOM renderer
|
|
63
|
+
* and (later) the WebGL renderer consume the same {@link FoldView}, so the two
|
|
64
|
+
* can never diverge.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useCurlController(options: CurlControllerOptions): CurlController;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Book } from './Book/Book';
|
|
2
|
+
export type { BookBaseProps, BookCssVariables, BookFactory, BookPageData, BookProps, BookStylesNames, } from './Book/Book';
|
|
3
|
+
export type { BookContextValue, BookInheritableProps } from './Book/Book.context';
|
|
4
|
+
export { faceToTurnedPages, turnedPagesToFace } from './Book/page-index';
|
|
5
|
+
export { BookPage } from './Book/BookPage';
|
|
6
|
+
export type { BookPageProps } from './Book/BookPage';
|
|
7
|
+
export type { CurlFaceAlign, CurlFaceProps } from './CurlFace/CurlFace';
|
|
8
|
+
export type { CurlFactory, CurlProps, CurlStylesNames } from './Curl/Curl';
|
|
9
|
+
export type { Point, ReflectionFold, TurnOrigin } from './flip/geometry';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Book } from './Book/Book';
|
|
2
|
+
export type { BookBaseProps, BookCssVariables, BookFactory, BookPageData, BookProps, BookStylesNames, } from './Book/Book';
|
|
3
|
+
export type { BookContextValue, BookInheritableProps } from './Book/Book.context';
|
|
4
|
+
export { faceToTurnedPages, turnedPagesToFace } from './Book/page-index';
|
|
5
|
+
export { BookPage } from './Book/BookPage';
|
|
6
|
+
export type { BookPageProps } from './Book/BookPage';
|
|
7
|
+
export type { CurlFaceAlign, CurlFaceProps } from './CurlFace/CurlFace';
|
|
8
|
+
export type { CurlFactory, CurlProps, CurlStylesNames } from './Curl/Curl';
|
|
9
|
+
export type { Point, ReflectionFold, TurnOrigin } from './flip/geometry';
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gfazioli/mantine-book",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Realistic iBooks-style book component for React built with Mantine. Stack two-sided pages and turn them by dragging any point of the free edge in any direction, or through controlled page navigation — a pure-DOM reflection fold (flat) or a true 3D WebGL curl (rounded).",
|
|
5
|
+
"homepage": "https://gfazioli.github.io/mantine-book/",
|
|
6
|
+
"packageManager": "yarn@4.0.1",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "Giovambattista Fazioli <giovambattista.fazioli@gmail.com>",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"3d",
|
|
11
|
+
"book",
|
|
12
|
+
"component",
|
|
13
|
+
"curl",
|
|
14
|
+
"ebook",
|
|
15
|
+
"extension",
|
|
16
|
+
"flip",
|
|
17
|
+
"ibooks",
|
|
18
|
+
"mantine",
|
|
19
|
+
"mantine-ui",
|
|
20
|
+
"mantine-v9",
|
|
21
|
+
"page-curl",
|
|
22
|
+
"page-flip",
|
|
23
|
+
"page-turn",
|
|
24
|
+
"paper",
|
|
25
|
+
"react",
|
|
26
|
+
"react-component",
|
|
27
|
+
"typescript",
|
|
28
|
+
"webgl"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/cjs/index.cjs",
|
|
31
|
+
"module": "./dist/esm/index.mjs",
|
|
32
|
+
"types": "./dist/types/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/types/index.d.mts",
|
|
37
|
+
"default": "./dist/esm/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/types/index.d.ts",
|
|
41
|
+
"default": "./dist/cjs/index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./styles.css": "./dist/styles.css",
|
|
45
|
+
"./styles.layer.css": "./dist/styles.layer.css"
|
|
46
|
+
},
|
|
47
|
+
"repository": "https://github.com/gfazioli/mantine-book.git",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@zumer/snapdom": "^2.12.2"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@mantine/core": ">=9.0.0",
|
|
53
|
+
"@mantine/hooks": ">=9.0.0",
|
|
54
|
+
"react": "^18.x || ^19.x",
|
|
55
|
+
"react-dom": "^18.x || ^19.x"
|
|
56
|
+
},
|
|
57
|
+
"bugs": "https://github.com/gfazioli/mantine-book/issues"
|
|
58
|
+
}
|