@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,128 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
- Demonstrating empathy and kindness toward other people
|
|
21
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
- Giving and gracefully accepting constructive feedback
|
|
23
|
+
- Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
- Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
- The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
- Public or private harassment
|
|
34
|
+
- Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
giovambattista.fazioli@gmail.com.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
|
86
|
+
of actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
|
93
|
+
permanent ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
+
the community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.0, available at
|
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
128
|
+
https://www.contributor-covenant.org/translations.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
👏 Thank you for considering contributing to this project.
|
|
4
|
+
|
|
5
|
+
## Bug Reports
|
|
6
|
+
|
|
7
|
+
When encountering issues with software or applications, submitting a detailed bug report can significantly help developers in understanding and resolving the problem efficiently. A well-written bug report should include clear steps to reproduce the issue, the expected behavior, and the actual outcome.
|
|
8
|
+
|
|
9
|
+
Furthermore, providing information such as system specifications, error messages, and screenshots can aid in pinpointing the root cause of the bug. By utilizing platforms like GitHub, users can create issue tickets with relevant details, facilitating effective communication between users and developers. Remember, a comprehensive bug report not only assists in bug resolution but also improves the overall quality of the software.
|
|
10
|
+
|
|
11
|
+
🐛 [GitHub issue](https://github.com/gfazioli/mantine-book/issues)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Code contributors
|
|
15
|
+
|
|
16
|
+
Here's a list of all the people who have contributed to the codebase of this project so far:
|
|
17
|
+
|
|
18
|
+
[](https://github.com/gfazioli/mantine-book/graphs/contributors)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Giovambattista Fazioli
|
|
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,105 @@
|
|
|
1
|
+
# Mantine Book Component
|
|
2
|
+
|
|
3
|
+
<img alt="Mantine Book" src="https://github.com/gfazioli/mantine-book/blob/master/logo.jpeg" />
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@gfazioli/mantine-book)
|
|
8
|
+
[](https://www.npmjs.com/package/@gfazioli/mantine-book)
|
|
9
|
+
[](https://www.npmjs.com/package/@gfazioli/mantine-book)
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
[<kbd> <br/> ❤️ If this component has been useful to you or your team, please consider becoming a sponsor <br/> </kbd>](https://github.com/sponsors/gfazioli?o=esc)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
This component is created on top of the [Mantine](https://mantine.dev/) library.
|
|
21
|
+
It requires **Mantine 9.x** and **React 19**.
|
|
22
|
+
|
|
23
|
+
[Mantine Book](https://gfazioli.github.io/mantine-book/) renders a realistic iBooks-style book. `Book` stacks two-sided pages — each a `<Book.Page>` with `<Book.Page.Front>` and `<Book.Page.Back>` — that you turn by dragging any point of the free edge in any direction, or programmatically through the controlled `page` state. It offers two rendering paths: a pure-DOM **flat** reflection fold (the default, interactive at rest and SSR-safe) and a true 3D **rounded** WebGL curl with a lit specular ridge. Any JSX goes inside a face — text, images, MDX, even a canvas.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- 📖 **Multi-page book**: stack any number of two-sided pages; drag the right half to turn forward, the left half to turn back — the page beneath shows through the curl
|
|
28
|
+
- 🎯 **Compound API**: `<Book><Book.Page><Book.Page.Front>…</Book.Page.Front><Book.Page.Back>…</Book.Page.Back></Book.Page></Book>` — or the data-driven `pages={[{ front, back }]}` form
|
|
29
|
+
- 🧭 **Controlled navigation**: `page` / `defaultPage` / `onPageChange` with face-based indices — drive the book from arrows, pagination or keyboard; programmatic turns animate like a drag
|
|
30
|
+
- 🧬 **Inherited props**: visual and gesture props set on the Book cascade to every page via optional context, and any page can override them locally
|
|
31
|
+
- 📄 **Physical page curl**: grab any point of the free edge and drag in any direction — a perpendicular-bisector reflection fold, the generalization of a corner page-turn
|
|
32
|
+
- 🧊 **Two variants**: `flat` (pure DOM + CSS, the universal fallback) and `rounded` (a true 3D curl on a WebGL canvas, with a soft specular ridge and a `curlRadius` control)
|
|
33
|
+
- 🖱️ **Drag, swipe, release**: PointerEvents unify mouse and touch; a release settles open or back to rest past `flipThreshold`; `mobileScrollSupport` keeps page scroll working
|
|
34
|
+
- ⚡ **Quiescent at rest**: no perpetual `requestAnimationFrame` — rAF runs only during a drag or the release settle
|
|
35
|
+
- 🛟 **Graceful fallback**: `rounded` falls back to `flat` automatically when WebGL is unavailable or a face snapshot fails — always safe to opt in
|
|
36
|
+
- 🧩 **React-owned content**: faces are rendered once by React (no `innerHTML` cloning), so event handlers inside a face stay alive
|
|
37
|
+
- 📦 **Lazy WebGL**: the rounded renderer and its snapshot dependency load only when a rounded curl mounts — flat users pay nothing
|
|
38
|
+
- 🎨 **Mantine-native theming**: `MantineColor` for shadows, CSS-var dimensions, full Styles API
|
|
39
|
+
- 📦 **TypeScript**: complete type safety with exported prop interfaces
|
|
40
|
+
|
|
41
|
+
> [!note]
|
|
42
|
+
>
|
|
43
|
+
> → [Demo and Documentation](https://gfazioli.github.io/mantine-book/) → [More Mantine Components](https://mantine-extensions.vercel.app/)
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm install @gfazioli/mantine-book
|
|
49
|
+
```
|
|
50
|
+
or
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
yarn add @gfazioli/mantine-book
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
After installation import package styles at the root of your application:
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import '@gfazioli/mantine-book/styles.css';
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { Book } from '@gfazioli/mantine-book';
|
|
66
|
+
|
|
67
|
+
function Demo() {
|
|
68
|
+
return (
|
|
69
|
+
<Book width={300} height={420} variant="rounded">
|
|
70
|
+
<Book.Page>
|
|
71
|
+
<Book.Page.Front>Page 1</Book.Page.Front>
|
|
72
|
+
<Book.Page.Back>Page 2</Book.Page.Back>
|
|
73
|
+
</Book.Page>
|
|
74
|
+
<Book.Page>
|
|
75
|
+
<Book.Page.Front>Page 3</Book.Page.Front>
|
|
76
|
+
<Book.Page.Back>Page 4</Book.Page.Back>
|
|
77
|
+
</Book.Page>
|
|
78
|
+
</Book>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Sponsor
|
|
84
|
+
|
|
85
|
+
<div align="center">
|
|
86
|
+
|
|
87
|
+
[<kbd> <br/> ❤️ If this component has been useful to you or your team, please consider becoming a sponsor <br/> </kbd>](https://github.com/sponsors/gfazioli?o=esc)
|
|
88
|
+
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
Your support helps me:
|
|
92
|
+
|
|
93
|
+
- Keep the project actively maintained with timely bug fixes and security updates
|
|
94
|
+
- Add new features, improve performance, and refine the developer experience
|
|
95
|
+
- Expand test coverage and documentation for smoother adoption
|
|
96
|
+
- Ensure long‑term sustainability without relying on ad hoc free time
|
|
97
|
+
- Prioritize community requests and roadmap items that matter most
|
|
98
|
+
|
|
99
|
+
Open source thrives when those who benefit can give back—even a small monthly contribution makes a real difference.
|
|
100
|
+
|
|
101
|
+
💚 [Become a sponsor](https://github.com/sponsors/gfazioli?o=esc) today.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
[](https://www.star-history.com/#gfazioli/mantine-book&Timeline)
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var core = require('@mantine/core');
|
|
5
|
+
var hooks = require('@mantine/hooks');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var poolContext = require('../Curl/webgl/poolContext.cjs');
|
|
8
|
+
var Book_context = require('./Book.context.cjs');
|
|
9
|
+
var BookPage = require('./BookPage.cjs');
|
|
10
|
+
var pageIndex = require('./page-index.cjs');
|
|
11
|
+
var Book_module = require('./Book.module.css.cjs');
|
|
12
|
+
|
|
13
|
+
const defaultProps = {
|
|
14
|
+
defaultPage: 0,
|
|
15
|
+
width: 300,
|
|
16
|
+
height: 600,
|
|
17
|
+
disabled: false,
|
|
18
|
+
riffleDuration: 1e3
|
|
19
|
+
};
|
|
20
|
+
const varsResolver = core.createVarsResolver(
|
|
21
|
+
(theme, { width, height, revealBackground }) => ({
|
|
22
|
+
root: {
|
|
23
|
+
"--curl-page-width": `${width}px`,
|
|
24
|
+
"--curl-page-height": `${height}px`,
|
|
25
|
+
"--curl-reveal-background": revealBackground === void 0 ? void 0 : core.getThemeColor(revealBackground, theme)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
const RIFFLE_MIN_STEP = 80;
|
|
30
|
+
function useShallowStableStyle(style) {
|
|
31
|
+
const ref = React.useRef(style);
|
|
32
|
+
const prev = ref.current;
|
|
33
|
+
const same = prev === style || !!prev && !!style && Object.keys(prev).length === Object.keys(style).length && Object.keys(style).every(
|
|
34
|
+
(key) => prev[key] === style[key]
|
|
35
|
+
);
|
|
36
|
+
if (!same) {
|
|
37
|
+
ref.current = style;
|
|
38
|
+
}
|
|
39
|
+
return same ? prev : style;
|
|
40
|
+
}
|
|
41
|
+
const BookSheet = React.memo(function BookSheet2(props) {
|
|
42
|
+
const {
|
|
43
|
+
child,
|
|
44
|
+
index,
|
|
45
|
+
width,
|
|
46
|
+
height,
|
|
47
|
+
flipped,
|
|
48
|
+
disabled,
|
|
49
|
+
warm,
|
|
50
|
+
raised,
|
|
51
|
+
total,
|
|
52
|
+
stepTime,
|
|
53
|
+
stepFlat,
|
|
54
|
+
hard,
|
|
55
|
+
className,
|
|
56
|
+
style,
|
|
57
|
+
onFoldStep,
|
|
58
|
+
onFlipStep
|
|
59
|
+
} = props;
|
|
60
|
+
const childOnFold = child.props.onFold;
|
|
61
|
+
const childOnFlip = child.props.onFlip;
|
|
62
|
+
const overrides = {
|
|
63
|
+
width,
|
|
64
|
+
height,
|
|
65
|
+
flipped,
|
|
66
|
+
grabZone: "sheet",
|
|
67
|
+
disabled,
|
|
68
|
+
warmSnapshots: warm,
|
|
69
|
+
hard,
|
|
70
|
+
onFold: (info) => {
|
|
71
|
+
onFoldStep(index);
|
|
72
|
+
childOnFold?.(info);
|
|
73
|
+
},
|
|
74
|
+
onFlip: (info) => {
|
|
75
|
+
onFlipStep(index, info.flipped);
|
|
76
|
+
childOnFlip?.(info);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
if (stepTime !== void 0) {
|
|
80
|
+
overrides.flippingTime = stepTime;
|
|
81
|
+
}
|
|
82
|
+
if (stepFlat) {
|
|
83
|
+
overrides.variant = "flat";
|
|
84
|
+
}
|
|
85
|
+
const zIndex = raised ? total + 2 : flipped ? index + 1 : total - index;
|
|
86
|
+
return /* @__PURE__ */ React.createElement("div", { className, style: { ...style, zIndex } }, React.cloneElement(child, overrides));
|
|
87
|
+
});
|
|
88
|
+
const Book = core.factory((_props) => {
|
|
89
|
+
const { ref, ...restProps } = _props;
|
|
90
|
+
const props = core.useProps("Book", defaultProps, restProps);
|
|
91
|
+
const {
|
|
92
|
+
page,
|
|
93
|
+
defaultPage,
|
|
94
|
+
onPageChange,
|
|
95
|
+
width,
|
|
96
|
+
height,
|
|
97
|
+
disabled,
|
|
98
|
+
pages,
|
|
99
|
+
children,
|
|
100
|
+
pageAnnouncement,
|
|
101
|
+
riffleDuration,
|
|
102
|
+
withCover,
|
|
103
|
+
classNames,
|
|
104
|
+
style,
|
|
105
|
+
styles,
|
|
106
|
+
unstyled,
|
|
107
|
+
vars,
|
|
108
|
+
className,
|
|
109
|
+
mod,
|
|
110
|
+
// inheritable (forwarded to pages via context)
|
|
111
|
+
variant,
|
|
112
|
+
align,
|
|
113
|
+
shadowOpacity,
|
|
114
|
+
shadowColor,
|
|
115
|
+
pageBackground,
|
|
116
|
+
revealBackground,
|
|
117
|
+
curlRadius,
|
|
118
|
+
flippingTime,
|
|
119
|
+
flipThreshold,
|
|
120
|
+
swipeDistance,
|
|
121
|
+
swipeTimeThreshold,
|
|
122
|
+
turnOrigin,
|
|
123
|
+
mobileScrollSupport,
|
|
124
|
+
...others
|
|
125
|
+
} = props;
|
|
126
|
+
const getStyles = core.useStyles({
|
|
127
|
+
name: "Book",
|
|
128
|
+
props,
|
|
129
|
+
classes: Book_module,
|
|
130
|
+
className,
|
|
131
|
+
style,
|
|
132
|
+
classNames,
|
|
133
|
+
styles,
|
|
134
|
+
unstyled,
|
|
135
|
+
vars,
|
|
136
|
+
varsResolver
|
|
137
|
+
});
|
|
138
|
+
const ctxSource = {
|
|
139
|
+
// Mantine widens the factory `variant` to string; the payload constrains it.
|
|
140
|
+
variant,
|
|
141
|
+
align,
|
|
142
|
+
shadowOpacity,
|
|
143
|
+
shadowColor,
|
|
144
|
+
pageBackground,
|
|
145
|
+
curlRadius,
|
|
146
|
+
flippingTime,
|
|
147
|
+
flipThreshold,
|
|
148
|
+
swipeDistance,
|
|
149
|
+
swipeTimeThreshold,
|
|
150
|
+
mobileScrollSupport,
|
|
151
|
+
turnOrigin
|
|
152
|
+
};
|
|
153
|
+
const ctxValue = {};
|
|
154
|
+
for (const key of Book_context.INHERITABLE_PROPS) {
|
|
155
|
+
if (ctxSource[key] !== void 0) {
|
|
156
|
+
ctxValue[key] = ctxSource[key];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const sheets = React.useMemo(() => {
|
|
160
|
+
const childPages = React.Children.toArray(children).filter(
|
|
161
|
+
React.isValidElement
|
|
162
|
+
);
|
|
163
|
+
if (childPages.length > 0 || !pages) {
|
|
164
|
+
return childPages;
|
|
165
|
+
}
|
|
166
|
+
return pages.map((data, index) => /* @__PURE__ */ React.createElement(BookPage.BookPage, { key: index, ...data.props }, /* @__PURE__ */ React.createElement(BookPage.BookPage.Front, null, data.front), /* @__PURE__ */ React.createElement(BookPage.BookPage.Back, null, data.back)));
|
|
167
|
+
}, [children, pages]);
|
|
168
|
+
const total = sheets.length;
|
|
169
|
+
const [face, setFace] = hooks.useUncontrolled({
|
|
170
|
+
value: page,
|
|
171
|
+
defaultValue: defaultPage ?? 0,
|
|
172
|
+
finalValue: 0,
|
|
173
|
+
onChange: onPageChange
|
|
174
|
+
});
|
|
175
|
+
const turned = pageIndex.faceToTurnedPages(face, total);
|
|
176
|
+
const [foldingIndex, setFoldingIndex] = React.useState(null);
|
|
177
|
+
const poolHolderRef = React.useRef({ pool: null });
|
|
178
|
+
React.useEffect(() => {
|
|
179
|
+
const poolHolder = poolHolderRef.current;
|
|
180
|
+
return () => {
|
|
181
|
+
poolHolder.pool?.dispose();
|
|
182
|
+
poolHolder.pool = null;
|
|
183
|
+
};
|
|
184
|
+
}, []);
|
|
185
|
+
const [displayedState, setDisplayedTurned] = React.useState(
|
|
186
|
+
() => pageIndex.faceToTurnedPages(typeof page === "number" ? page : defaultPage ?? 0, total)
|
|
187
|
+
);
|
|
188
|
+
const [queueStep, setQueueStep] = React.useState(null);
|
|
189
|
+
const [stepTime, setStepTime] = React.useState(void 0);
|
|
190
|
+
const displayedTurned = Math.min(displayedState, total);
|
|
191
|
+
const effectiveTurned = queueStep === null ? displayedTurned : queueStep.forward ? Math.min(displayedTurned + 1, total) : Math.max(displayedTurned - 1, 0);
|
|
192
|
+
React.useLayoutEffect(() => {
|
|
193
|
+
if (queueStep !== null && queueStep.index >= total) {
|
|
194
|
+
setQueueStep(null);
|
|
195
|
+
setStepTime(void 0);
|
|
196
|
+
setFoldingIndex((current) => current !== null && current >= total ? null : current);
|
|
197
|
+
setDisplayedTurned((current) => Math.min(current, total));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (queueStep !== null || foldingIndex !== null || total === 0) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (displayedTurned === turned) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const steps = Math.abs(turned - displayedTurned);
|
|
207
|
+
const forward = turned > displayedTurned;
|
|
208
|
+
const index = forward ? displayedTurned : displayedTurned - 1;
|
|
209
|
+
setStepTime(
|
|
210
|
+
steps > 1 ? Math.max(RIFFLE_MIN_STEP, Math.min(flippingTime ?? 600, (riffleDuration ?? 1e3) / steps)) : void 0
|
|
211
|
+
);
|
|
212
|
+
setQueueStep({ index, forward });
|
|
213
|
+
}, [turned, displayedTurned, foldingIndex, queueStep, total, flippingTime, riffleDuration]);
|
|
214
|
+
const handleKeyDown = (event) => {
|
|
215
|
+
if (disabled || total === 0 || event.target !== event.currentTarget) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
let next = null;
|
|
219
|
+
if (event.key === "ArrowRight") {
|
|
220
|
+
next = turned < total ? pageIndex.turnedPagesToFace(turned + 1) : null;
|
|
221
|
+
} else if (event.key === "ArrowLeft") {
|
|
222
|
+
next = turned > 0 ? pageIndex.turnedPagesToFace(turned - 1) : null;
|
|
223
|
+
} else if (event.key === "Home") {
|
|
224
|
+
next = turned > 0 ? 0 : null;
|
|
225
|
+
} else if (event.key === "End") {
|
|
226
|
+
next = turned < total ? pageIndex.turnedPagesToFace(total) : null;
|
|
227
|
+
}
|
|
228
|
+
if (next !== null) {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
setFace(next);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const fromPage = turned === 0 ? 1 : 2 * turned;
|
|
234
|
+
const toPage = turned === total ? 2 * total : turned === 0 ? 1 : 2 * turned + 1;
|
|
235
|
+
const totalPages = total * 2;
|
|
236
|
+
const announcement = total === 0 ? null : pageAnnouncement?.({ from: fromPage, to: toPage, total: totalPages }) ?? (fromPage === toPage ? `Page ${fromPage} of ${totalPages}` : `Pages ${fromPage}\u2013${toPage} of ${totalPages}`);
|
|
237
|
+
const {
|
|
238
|
+
onKeyDown: userOnKeyDown,
|
|
239
|
+
"aria-label": ariaLabel,
|
|
240
|
+
"aria-labelledby": ariaLabelledby,
|
|
241
|
+
"aria-roledescription": ariaRoledescription = "book",
|
|
242
|
+
role = "group",
|
|
243
|
+
tabIndex,
|
|
244
|
+
...rest
|
|
245
|
+
} = others;
|
|
246
|
+
const queueStepRef = React.useRef(queueStep);
|
|
247
|
+
queueStepRef.current = queueStep;
|
|
248
|
+
const setFaceRef = React.useRef(setFace);
|
|
249
|
+
setFaceRef.current = setFace;
|
|
250
|
+
const handleFoldStep = React.useCallback((index) => {
|
|
251
|
+
setFoldingIndex(index);
|
|
252
|
+
}, []);
|
|
253
|
+
const handleFlipStep = React.useCallback((index, nowFlipped) => {
|
|
254
|
+
setFoldingIndex(null);
|
|
255
|
+
const newTurned = nowFlipped ? index + 1 : index;
|
|
256
|
+
if (queueStepRef.current?.index === index) {
|
|
257
|
+
setDisplayedTurned(newTurned);
|
|
258
|
+
setQueueStep(null);
|
|
259
|
+
} else {
|
|
260
|
+
setQueueStep(null);
|
|
261
|
+
setStepTime(void 0);
|
|
262
|
+
setDisplayedTurned(newTurned);
|
|
263
|
+
setFaceRef.current(pageIndex.turnedPagesToFace(newTurned));
|
|
264
|
+
}
|
|
265
|
+
}, []);
|
|
266
|
+
const riffleWarmHold = queueStep !== null && stepTime !== void 0 && Math.abs(turned - displayedTurned) > 2;
|
|
267
|
+
const pageStyles = getStyles("page");
|
|
268
|
+
const stablePageStyle = useShallowStableStyle(pageStyles.style);
|
|
269
|
+
const coverShift = withCover === true && total > 0 ? turned === 0 ? -(width ?? 0) / 2 : turned === total ? (width ?? 0) / 2 : 0 : 0;
|
|
270
|
+
return /* @__PURE__ */ React.createElement(Book_context.BookContext.Provider, { value: ctxValue }, /* @__PURE__ */ React.createElement(poolContext.CurlWebglPoolContext.Provider, { value: poolHolderRef.current }, /* @__PURE__ */ React.createElement(
|
|
271
|
+
core.Box,
|
|
272
|
+
{
|
|
273
|
+
ref,
|
|
274
|
+
role,
|
|
275
|
+
"aria-roledescription": ariaRoledescription,
|
|
276
|
+
"aria-label": ariaLabelledby ? ariaLabel : ariaLabel ?? "Book",
|
|
277
|
+
"aria-labelledby": ariaLabelledby,
|
|
278
|
+
tabIndex: tabIndex ?? (disabled ? -1 : 0),
|
|
279
|
+
onKeyDown: (event) => {
|
|
280
|
+
userOnKeyDown?.(event);
|
|
281
|
+
if (!event.defaultPrevented) {
|
|
282
|
+
handleKeyDown(event);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
...getStyles("root", {
|
|
286
|
+
style: withCover === true ? { transform: `translateX(${coverShift}px)` } : void 0
|
|
287
|
+
}),
|
|
288
|
+
...rest,
|
|
289
|
+
mod: [{ disabled }, mod]
|
|
290
|
+
},
|
|
291
|
+
/* @__PURE__ */ React.createElement(core.VisuallyHidden, { "aria-live": "polite", "aria-atomic": "true" }, announcement),
|
|
292
|
+
sheets.map((child, index) => {
|
|
293
|
+
const flipped = index < effectiveTurned;
|
|
294
|
+
const inFlight = queueStep?.index ?? foldingIndex;
|
|
295
|
+
const interactive = !disabled && (index === effectiveTurned || index === effectiveTurned - 1) && (inFlight === null || inFlight === index);
|
|
296
|
+
const isStep = queueStep?.index === index;
|
|
297
|
+
return /* @__PURE__ */ React.createElement(
|
|
298
|
+
BookSheet,
|
|
299
|
+
{
|
|
300
|
+
key: child.key ?? index,
|
|
301
|
+
child,
|
|
302
|
+
index,
|
|
303
|
+
width,
|
|
304
|
+
height,
|
|
305
|
+
flipped,
|
|
306
|
+
disabled: child.props.disabled || !interactive,
|
|
307
|
+
warm: !riffleWarmHold && (index === effectiveTurned || index === effectiveTurned - 1),
|
|
308
|
+
raised: inFlight === index,
|
|
309
|
+
total,
|
|
310
|
+
stepTime: isStep ? stepTime : void 0,
|
|
311
|
+
stepFlat: isStep && stepTime !== void 0,
|
|
312
|
+
hard: child.props.hard ?? (withCover === true && (index === 0 || index === total - 1)),
|
|
313
|
+
className: pageStyles.className,
|
|
314
|
+
style: stablePageStyle,
|
|
315
|
+
onFoldStep: handleFoldStep,
|
|
316
|
+
onFlipStep: handleFlipStep
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
})
|
|
320
|
+
)));
|
|
321
|
+
});
|
|
322
|
+
Book.classes = Book_module;
|
|
323
|
+
Book.displayName = "Book";
|
|
324
|
+
Book.Page = BookPage.BookPage;
|
|
325
|
+
|
|
326
|
+
exports.Book = Book;
|
|
327
|
+
//# sourceMappingURL=Book.cjs.map
|