next-flipbook 1.0.0 → 1.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.
Files changed (123) hide show
  1. package/README.md +30 -4
  2. package/dist/core/animation/curl.d.ts +139 -0
  3. package/dist/core/animation/curl.d.ts.map +1 -0
  4. package/dist/core/animation/curl.js +204 -0
  5. package/dist/core/animation/curl.js.map +1 -0
  6. package/dist/core/animation/turn.d.ts +9 -2
  7. package/dist/core/animation/turn.d.ts.map +1 -1
  8. package/dist/core/animation/turn.js +1 -0
  9. package/dist/core/animation/turn.js.map +1 -1
  10. package/dist/core/engine/FlipBookEngine.d.ts +20 -4
  11. package/dist/core/engine/FlipBookEngine.d.ts.map +1 -1
  12. package/dist/core/engine/FlipBookEngine.js +37 -5
  13. package/dist/core/engine/FlipBookEngine.js.map +1 -1
  14. package/dist/core/index.d.ts +7 -4
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/core/index.js +3 -2
  17. package/dist/core/index.js.map +1 -1
  18. package/dist/core/interaction/GestureRecognizer.d.ts +20 -4
  19. package/dist/core/interaction/GestureRecognizer.d.ts.map +1 -1
  20. package/dist/core/interaction/GestureRecognizer.js +33 -11
  21. package/dist/core/interaction/GestureRecognizer.js.map +1 -1
  22. package/dist/core/interaction/drag.d.ts +13 -0
  23. package/dist/core/interaction/drag.d.ts.map +1 -1
  24. package/dist/core/interaction/drag.js +20 -0
  25. package/dist/core/interaction/drag.js.map +1 -1
  26. package/dist/core/layout/sizing.d.ts +21 -7
  27. package/dist/core/layout/sizing.d.ts.map +1 -1
  28. package/dist/core/layout/sizing.js +31 -9
  29. package/dist/core/layout/sizing.js.map +1 -1
  30. package/dist/core/types.d.ts +7 -0
  31. package/dist/core/types.d.ts.map +1 -1
  32. package/dist/core/zoom/ZoomController.d.ts +2 -0
  33. package/dist/core/zoom/ZoomController.d.ts.map +1 -1
  34. package/dist/core/zoom/ZoomController.js +9 -3
  35. package/dist/core/zoom/ZoomController.js.map +1 -1
  36. package/dist/image/index.d.ts +3 -0
  37. package/dist/image/index.d.ts.map +1 -1
  38. package/dist/image/index.js +2 -0
  39. package/dist/image/index.js.map +1 -1
  40. package/dist/image/loader.d.ts +27 -0
  41. package/dist/image/loader.d.ts.map +1 -1
  42. package/dist/image/loader.js +63 -0
  43. package/dist/image/loader.js.map +1 -1
  44. package/dist/image/nextLoader.d.ts +27 -0
  45. package/dist/image/nextLoader.d.ts.map +1 -0
  46. package/dist/image/nextLoader.js +32 -0
  47. package/dist/image/nextLoader.js.map +1 -0
  48. package/dist/image/select.d.ts +80 -0
  49. package/dist/image/select.d.ts.map +1 -0
  50. package/dist/image/select.js +84 -0
  51. package/dist/image/select.js.map +1 -0
  52. package/dist/index.d.ts +3 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +2 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/react/components/FlipBook.d.ts.map +1 -1
  57. package/dist/react/components/FlipBook.js +27 -13
  58. package/dist/react/components/FlipBook.js.map +1 -1
  59. package/dist/react/components/FlipBookBackgroundControl.js +1 -1
  60. package/dist/react/components/FlipBookBackgroundControl.js.map +1 -1
  61. package/dist/react/components/FlipBookBookmarks.js +2 -2
  62. package/dist/react/components/FlipBookBookmarks.js.map +1 -1
  63. package/dist/react/components/FlipBookControls.d.ts.map +1 -1
  64. package/dist/react/components/FlipBookControls.js +4 -2
  65. package/dist/react/components/FlipBookControls.js.map +1 -1
  66. package/dist/react/components/FlipBookPageView.d.ts +6 -1
  67. package/dist/react/components/FlipBookPageView.d.ts.map +1 -1
  68. package/dist/react/components/FlipBookPageView.js +45 -16
  69. package/dist/react/components/FlipBookPageView.js.map +1 -1
  70. package/dist/react/components/FlipBookProvider.d.ts +0 -5
  71. package/dist/react/components/FlipBookProvider.d.ts.map +1 -1
  72. package/dist/react/components/FlipBookProvider.js +21 -3
  73. package/dist/react/components/FlipBookProvider.js.map +1 -1
  74. package/dist/react/components/FlipBookSearch.js +3 -3
  75. package/dist/react/components/FlipBookSearch.js.map +1 -1
  76. package/dist/react/components/FlipBookSidePanel.d.ts.map +1 -1
  77. package/dist/react/components/FlipBookSidePanel.js +5 -2
  78. package/dist/react/components/FlipBookSidePanel.js.map +1 -1
  79. package/dist/react/components/FlipBookStage.d.ts.map +1 -1
  80. package/dist/react/components/FlipBookStage.js +304 -70
  81. package/dist/react/components/FlipBookStage.js.map +1 -1
  82. package/dist/react/components/FlipBookTOC.js +2 -2
  83. package/dist/react/components/FlipBookTOC.js.map +1 -1
  84. package/dist/react/components/FlipBookThumbnails.js +1 -1
  85. package/dist/react/components/FlipBookThumbnails.js.map +1 -1
  86. package/dist/react/components/FlipBookToolbar.d.ts.map +1 -1
  87. package/dist/react/components/FlipBookToolbar.js +5 -2
  88. package/dist/react/components/FlipBookToolbar.js.map +1 -1
  89. package/dist/react/components/HotspotPopover.js +1 -1
  90. package/dist/react/components/HotspotPopover.js.map +1 -1
  91. package/dist/react/components/PasswordDialog.js +2 -2
  92. package/dist/react/components/PasswordDialog.js.map +1 -1
  93. package/dist/react/components/PdfPageView.js +1 -1
  94. package/dist/react/components/PdfPageView.js.map +1 -1
  95. package/dist/react/components/Thumbnail.d.ts.map +1 -1
  96. package/dist/react/components/Thumbnail.js +15 -4
  97. package/dist/react/components/Thumbnail.js.map +1 -1
  98. package/dist/react/context.d.ts +10 -2
  99. package/dist/react/context.d.ts.map +1 -1
  100. package/dist/react/context.js.map +1 -1
  101. package/dist/react/hooks/useGestures.d.ts +7 -2
  102. package/dist/react/hooks/useGestures.d.ts.map +1 -1
  103. package/dist/react/hooks/useGestures.js +19 -7
  104. package/dist/react/hooks/useGestures.js.map +1 -1
  105. package/dist/react/hooks/usePageAspect.d.ts.map +1 -1
  106. package/dist/react/hooks/usePageAspect.js +9 -3
  107. package/dist/react/hooks/usePageAspect.js.map +1 -1
  108. package/dist/react/index.d.ts +1 -0
  109. package/dist/react/index.d.ts.map +1 -1
  110. package/dist/react/index.js +1 -0
  111. package/dist/react/index.js.map +1 -1
  112. package/dist/react/styles.d.ts +21 -5
  113. package/dist/react/styles.d.ts.map +1 -1
  114. package/dist/react/styles.js +46 -10
  115. package/dist/react/styles.js.map +1 -1
  116. package/dist/react/theme.d.ts +27 -3
  117. package/dist/react/theme.d.ts.map +1 -1
  118. package/dist/react/theme.js +115 -15
  119. package/dist/react/theme.js.map +1 -1
  120. package/dist/styles.css +13 -0
  121. package/dist/types/index.d.ts +107 -6
  122. package/dist/types/index.d.ts.map +1 -1
  123. package/package.json +1 -1
package/README.md CHANGED
@@ -80,6 +80,27 @@ import "next-flipbook/styles.css";
80
80
 
81
81
  The viewer draws nothing on the server. It measures its container in the browser first, so the server HTML is a small shell and there is no hydration mismatch or flash of the wrong layout.
82
82
 
83
+ ## Your design, a page curl, a notebook, smaller images
84
+
85
+ ```tsx
86
+ <FlipBook
87
+ pages={pages}
88
+ cover
89
+ // The look, in code: a built-in theme, or your own tokens.
90
+ theme={{ preset: "sepia", accent: "#0f766e", pageRadius: 6, bookShadow: "0 14px 30px rgba(0, 0, 0, 0.28)" }}
91
+ classNames={{ toolbar: "my-toolbar" }}
92
+ styles={{ root: { borderRadius: 16 } }}
93
+ // How a page moves: swung on its spine ("flat", the default) or folded from a corner.
94
+ flipStyle="curl"
95
+ // Which way pages turn: "vertical" is a notebook, bound along the top, whose pages flip upwards.
96
+ orientation="horizontal"
97
+ // Page images: the smallest file that is sharp at the size shown (Next.js optimizer here).
98
+ imageOptions={nextImages}
99
+ />
100
+ ```
101
+
102
+ Each has its own page: [making it look like yours](docs/customisation.md), [how a page turns](docs/flipping.md), [image pages and their size](docs/images.md). The demo has a page for each (`/design`, `/flips`, `/image-sizes`).
103
+
83
104
  ## Examples
84
105
 
85
106
  ```tsx
@@ -154,7 +175,8 @@ ref.current?.getCacheStats(); // what the viewer holds: cached pages, thumbnails
154
175
  | --- | --- | --- |
155
176
  | `licenseKey` | none | The key you were given for this website. Without a valid one the viewer shows a watermark and one console warning, and keeps working. `localhost` and private addresses need none. `<FlipBookLicenseProvider>` sets it for every viewer below it. See [docs/licensing.md](docs/licensing.md). |
156
177
  | `source` | none | A PDF: URL, `File`, `Blob`, `ArrayBuffer` or `Uint8Array`. Pass `source` or `pages`, not both. Keep it referentially stable: a new value loads a new document. |
157
- | `pages` | none | Strings (image URLs), `{ type: "image", src, alt?, width?, height? }`, `{ type: "custom", component? \| render? }` or `{ type: "pdf", source, page }`. |
178
+ | `pages` | none | Strings (image URLs), `{ type: "image", src, alt?, width?, height?, srcSet?, placeholder?, thumbnail? }`, `{ type: "custom", component? \| render? }` or `{ type: "pdf", source, page }`. |
179
+ | `imageOptions` | none | How image pages are sized and fetched: a `loader` for an image service, `widths`, `quality`, `maxPixelRatio`, `sharpenOnZoom`. `imageOptions={nextImages}` uses the Next.js optimizer. Pages with a `srcSet` need no service. See [docs/images.md](docs/images.md). |
158
180
  | `pdf` | none | `workerSrc`, `renderScale`, `maxCanvasPixels`, `maxCacheBytes`, `maxTextCacheBytes`, `cleanupAfterPages`, `password`, `withCredentials`, `httpHeaders`, `maxConcurrentRenders`, `documentParams`, `loadPdfjs`. See [docs/pdf.md](docs/pdf.md). |
159
181
  | `onPassword` | built-in dialog | `(answer, reason) => void`. Call `answer(password)` or `answer(null)` to give up. |
160
182
  | `cacheSize` | `10` | Rendered PDF pages kept in memory. Pages that would not fit alongside the visible ones are not prefetched, so a large `preloadPages` with a small `cacheSize` cannot thrash. |
@@ -169,7 +191,11 @@ ref.current?.getCacheStats(); // what the viewer holds: cached pages, thumbnails
169
191
  | `whileTurning` | `"queue"` | `"ignore"` drops navigation that arrives mid-turn. |
170
192
  | `shadow`, `shadowIntensity` | `true`, `0.5` | Dynamic shading during turns. |
171
193
  | `reducedMotion` | `"auto"` | Follows `prefers-reduced-motion`; page changes become instant. |
172
- | `theme` | none | `"light"` or `"dark"`. |
194
+ | `theme` | none | A built-in look (`"light"`, `"dark"`, `"sepia"`, `"midnight"`) or an object of your own: colours, page corners, a border, a shadow under the book, the crease at the spine, the font. See [docs/customisation.md](docs/customisation.md). |
195
+ | `classNames`, `styles` | none | A class and an inline style for each part of the viewer: `root`, `stage`, `book`, `page`, `toolbar`, `panel`, `notice`. |
196
+ | `flipStyle` | `"flat"` | `"flat"` swings the page on its spine; `"curl"` folds it from a corner, with the back of the paper and shadows, and follows a dragged corner. Our own implementation, no extra dependency. See [docs/flipping.md](docs/flipping.md). |
197
+ | `orientation` | `"horizontal"` | `"vertical"` is a notebook bound along the top: pages flip **upwards**, a double view stacks two pages, dragging up (or `ArrowDown`) goes forward. Works with both flip styles. |
198
+ | `toolbarPosition` | `"bottom"` | `"top"` puts the toolbar above the book. |
173
199
  | `background`, `backgroundControl`, `backgroundColors`, `onBackgroundChange` | theme | Any CSS background, including `"transparent"`; a toolbar button with a color picker; the colors it offers; a callback. Also `setBackground()` on the ref. |
174
200
  | `toolbar`, `navigation`, `keyboard` | `true` | The bottom bar; its previous/next/counter; arrow keys, Home, End, `+` `-` `0` zoom, `F` fullscreen, `B` bookmark. |
175
201
  | `fullscreen` | `true` | Button and `F`. Fills the window where the browser API is missing. |
@@ -201,7 +227,7 @@ ref.current?.getCacheStats(); // what the viewer holds: cached pages, thumbnails
201
227
 
202
228
  Errors arrive as `{ code, message, cause?, page? }`. Codes: `INVALID_PDF`, `PDF_NOT_FOUND`, `NETWORK_ERROR` (offline or blocked by CORS), `PASSWORD_REQUIRED`, `PDF_WORKER_FAILED`, `PAGE_RENDER_FAILED`, `IMAGE_LOAD_FAILED`, `UNSUPPORTED_SOURCE`, `INVALID_ARGUMENT`.
203
229
 
204
- Every value can be styled through CSS variables: `--flipbook-background`, `--flipbook-toolbar-background`, `--flipbook-toolbar-color`, `--flipbook-page-background`, `--flipbook-shadow`, `--flipbook-accent`.
230
+ Every colour can be set through CSS variables as well as the `theme` prop: `--flipbook-background`, `--flipbook-toolbar-background`, `--flipbook-toolbar-color`, `--flipbook-page-background`, `--flipbook-page-color`, `--flipbook-shadow`, `--flipbook-accent`, and `--flipbook-font`, `--flipbook-page-radius`, `--flipbook-page-border`, `--flipbook-book-filter`, `--flipbook-spine-opacity`, `--flipbook-spine-width`.
205
231
 
206
232
  ## How it stays fast
207
233
 
@@ -266,7 +292,7 @@ Only the pages near the reader are drawn and kept: the visible spread, `preloadP
266
292
  | 6 | Prefetch tuning, memory bounds and cleanup, benchmarks on 100 to 1000 page PDFs, cache statistics | **Done** |
267
293
  | 7 | ESLint, Playwright end-to-end, accessibility and visual tests, a playground, CI, release workflow | **Done**, except a docs site and the first npm publish |
268
294
 
269
- Not yet in the API, on purpose: `hardPages`, `pageCurl`, `autoplay`, `sound`, plugins, annotations, OCR and a selectable text layer.
295
+ Not yet in the API, on purpose: `hardPages`, `autoplay`, `sound`, plugins, annotations, OCR and a selectable text layer.
270
296
 
271
297
  ## Development
272
298
 
@@ -0,0 +1,139 @@
1
+ import type { FlipBookDirection, FlipBookOrientation } from "../types.js";
2
+ /**
3
+ * Page-curl geometry.
4
+ *
5
+ * A turning page is folded flat along a straight crease, and the folded part
6
+ * shows the back of the paper. Everything here is plain 2D maths with no DOM,
7
+ * so it is tested on its own and the renderer only has to draw what it is told.
8
+ *
9
+ * Paper coordinates: `u` runs along the turn axis from the hinge (0) to the
10
+ * free edge (`length`), and `v` runs across it, from 0 to `breadth`. One
11
+ * corner of the free edge is held (`P0`) and the fold carries it to a point
12
+ * `T`; the crease is the perpendicular bisector of `P0` and `T`, so folding
13
+ * is the reflection that swaps them. The part of the page on `P0`'s side of
14
+ * the crease is the flap, and it lands on `T`'s side.
15
+ *
16
+ * `T` follows a half circle from the free edge round to the mirror image of
17
+ * the page on the far side of the hinge, with a sideways lift that rises and
18
+ * falls on the way. Without a lift the crease stays parallel to the hinge and
19
+ * the page folds like a flat sheet; with one the crease tilts and the page
20
+ * peels from its corner, as paper does under a finger.
21
+ */
22
+ export type Point2 = readonly [number, number];
23
+ /** An affine map in the order of CSS `matrix(a, b, c, d, e, f)`: x' = ax + cy + e, y' = bx + dy + f. */
24
+ export type Matrix = readonly [number, number, number, number, number, number];
25
+ export declare const IDENTITY: Matrix;
26
+ /** `multiply(m, n)` applies `n` first and `m` second. */
27
+ export declare function multiply(m: Matrix, n: Matrix): Matrix;
28
+ export declare function transformPoint(m: Matrix, p: Point2): Point2;
29
+ export declare function invertMatrix(m: Matrix): Matrix;
30
+ /** The CSS `matrix()` for a map, with numbers short enough to write into a style every frame. */
31
+ export declare function matrixToCss(m: Matrix): string;
32
+ /** A polygon as a CSS `clip-path` value. An empty polygon clips everything away. */
33
+ export declare function polygonToCss(points: readonly Point2[]): string;
34
+ /** Which end of the free edge is held: the one at `v = 0` or the one at `v = breadth`. */
35
+ export type CurlCorner = "start" | "end";
36
+ export interface CurlInput {
37
+ /** Size of the page along the turn axis, in pixels. */
38
+ length: number;
39
+ /** Size of the page across the turn axis, in pixels. */
40
+ breadth: number;
41
+ /** How far the page has turned, 0 (flat on its own side) to 1 (flat on the other side). */
42
+ fold: number;
43
+ corner: CurlCorner;
44
+ /** How far the held corner is drawn towards the middle of the page, in pixels. At least 0. */
45
+ lift: number;
46
+ }
47
+ export interface CurlCrease {
48
+ /** A point on the crease. */
49
+ point: Point2;
50
+ /** Unit vector across the crease, pointing at the lifted side. */
51
+ normal: Point2;
52
+ }
53
+ export interface CurlFrame {
54
+ /** The part of the front that still lies flat. */
55
+ flat: Point2[];
56
+ /** The part that has been lifted, drawn where it has landed. */
57
+ flap: Point2[];
58
+ /** The part of the page underneath that the lifted part has uncovered. */
59
+ revealed: Point2[];
60
+ /** Where the flap casts a shadow: the flat side of the crease, out to one page past the hinge. */
61
+ receiver: Point2[];
62
+ /** Maps a point of the paper to where the fold has put it. */
63
+ reflection: Matrix;
64
+ /** `null` while nothing has been lifted. */
65
+ crease: CurlCrease | null;
66
+ /** How far the flap reaches from the crease. */
67
+ flapDepth: number;
68
+ }
69
+ /** The part of a convex polygon with `keep * ((p - point) . normal) >= 0` (Sutherland-Hodgman, one edge). */
70
+ export declare function clipHalfPlane(polygon: readonly Point2[], point: Point2, normal: Point2, keep: 1 | -1): Point2[];
71
+ /** Unsigned area of a simple polygon. */
72
+ export declare function polygonArea(polygon: readonly Point2[]): number;
73
+ /**
74
+ * The fold of one page at one moment.
75
+ *
76
+ * `lift` is limited to `length`. Within that limit the folded corner is never
77
+ * further from either end of the hinge than the corner it came from, which is
78
+ * what a sheet that cannot stretch allows, so the hinge stays on the flat side.
79
+ */
80
+ export declare function computeCurl(input: CurlInput): CurlFrame;
81
+ /**
82
+ * Maps paper coordinates (hinge at `u = 0`) to pixels in the leaf's box (the
83
+ * page's own rectangle, top left at 0, 0). The hinge is the left edge in a
84
+ * left-to-right book, the right edge in a right-to-left one, and the top edge
85
+ * when the book turns upwards.
86
+ */
87
+ export declare function paperToBox(orientation: FlipBookOrientation, direction: FlipBookDirection, width: number): Matrix;
88
+ /**
89
+ * Maps a point of the page printed on the back of the leaf to the leaf's box
90
+ * as it lies flat, face down: mirrored along the turn axis, as in the flat
91
+ * turn, where the back face is the front rotated half a turn about the hinge.
92
+ */
93
+ export declare function backToBox(orientation: FlipBookOrientation, width: number, height: number): Matrix;
94
+ export interface CurlBox {
95
+ flat: Point2[];
96
+ flap: Point2[];
97
+ revealed: Point2[];
98
+ receiver: Point2[];
99
+ /** Places the back page, as an element of the page's size at the box origin, where the fold has put it. */
100
+ flapMatrix: Matrix;
101
+ /** The crease in box coordinates, with the normal pointing at the lifted side. `null` while flat. */
102
+ crease: CurlCrease | null;
103
+ flapDepth: number;
104
+ }
105
+ export interface CurlBoxInput {
106
+ /** Page size in pixels. */
107
+ width: number;
108
+ height: number;
109
+ orientation: FlipBookOrientation;
110
+ direction: FlipBookDirection;
111
+ fold: number;
112
+ corner: CurlCorner;
113
+ lift: number;
114
+ }
115
+ /** One frame of the curl for a page of a given size and orientation, in the page's own pixels. */
116
+ export declare function computeCurlBox(input: CurlBoxInput): CurlBox;
117
+ export interface CurlShading {
118
+ /** Darkness of the shadow on the page that was uncovered, strongest at the crease. */
119
+ revealOpacity: number;
120
+ /** How far that shadow reaches from the crease, in pixels. */
121
+ revealLength: number;
122
+ /** Darkness at the crease of the lifted part, which is turned away from the light there. */
123
+ flapDark: number;
124
+ /** A faint highlight just past the crease, where the paper bends towards the light. */
125
+ flapLight: number;
126
+ /** Darkness of the shadow the lifted part casts on the page it lies on. */
127
+ castOpacity: number;
128
+ /** Softness of that shadow, in pixels. */
129
+ castBlur: number;
130
+ /** How far the shadow is pushed away from the crease, in pixels. */
131
+ castOffset: number;
132
+ }
133
+ /** Shadow values for a fold. `strength` is 0 for none, 1 for the strongest. */
134
+ export declare function computeCurlShading(input: {
135
+ fold: number;
136
+ length: number;
137
+ strength: number;
138
+ }): CurlShading;
139
+ //# sourceMappingURL=curl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../src/core/animation/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG1E;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C,wGAAwG;AACxG,MAAM,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/E,eAAO,MAAM,QAAQ,EAAE,MAA2B,CAAC;AAEnD,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CASrD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ9C;AAED,iGAAiG;AACjG,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,C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AAoE;IACpE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,WAAW,CAYd"}
@@ -0,0 +1,204 @@
1
+ import { clamp01 } from "./easing.js";
2
+ export const IDENTITY = [1, 0, 0, 1, 0, 0];
3
+ /** `multiply(m, n)` applies `n` first and `m` second. */
4
+ export function multiply(m, n) {
5
+ return [
6
+ m[0] * n[0] + m[2] * n[1],
7
+ m[1] * n[0] + m[3] * n[1],
8
+ m[0] * n[2] + m[2] * n[3],
9
+ m[1] * n[2] + m[3] * n[3],
10
+ m[0] * n[4] + m[2] * n[5] + m[4],
11
+ m[1] * n[4] + m[3] * n[5] + m[5],
12
+ ];
13
+ }
14
+ export function transformPoint(m, p) {
15
+ return [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
16
+ }
17
+ export function invertMatrix(m) {
18
+ const det = m[0] * m[3] - m[1] * m[2];
19
+ if (det === 0)
20
+ return IDENTITY;
21
+ const a = m[3] / det;
22
+ const b = -m[1] / det;
23
+ const c = -m[2] / det;
24
+ const d = m[0] / det;
25
+ return [a, b, c, d, -(a * m[4] + c * m[5]), -(b * m[4] + d * m[5])];
26
+ }
27
+ /** The CSS `matrix()` for a map, with numbers short enough to write into a style every frame. */
28
+ export function matrixToCss(m) {
29
+ return `matrix(${m.map(round).join(", ")})`;
30
+ }
31
+ /** A polygon as a CSS `clip-path` value. An empty polygon clips everything away. */
32
+ export function polygonToCss(points) {
33
+ if (points.length < 3)
34
+ return "polygon(0px 0px, 0px 0px, 0px 0px)";
35
+ return `polygon(${points.map((p) => `${round(p[0])}px ${round(p[1])}px`).join(", ")})`;
36
+ }
37
+ const round = (value) => String(Math.round(value * 1000) / 1000 + 0);
38
+ const EPSILON = 1e-6;
39
+ /** Smaller than this, in pixels, the held corner has not moved and the page is flat. */
40
+ const FLAT_BELOW = 0.25;
41
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1];
42
+ const sub = (a, b) => [a[0] - b[0], a[1] - b[1]];
43
+ /** The part of a convex polygon with `keep * ((p - point) . normal) >= 0` (Sutherland-Hodgman, one edge). */
44
+ export function clipHalfPlane(polygon, point, normal, keep) {
45
+ const out = [];
46
+ const side = (p) => keep * dot(sub(p, point), normal);
47
+ for (let i = 0; i < polygon.length; i += 1) {
48
+ const current = polygon[i];
49
+ const next = polygon[(i + 1) % polygon.length];
50
+ const a = side(current);
51
+ const b = side(next);
52
+ if (a >= 0)
53
+ out.push(current);
54
+ if ((a > 0 && b < 0) || (a < 0 && b > 0)) {
55
+ const t = a / (a - b);
56
+ out.push([current[0] + (next[0] - current[0]) * t, current[1] + (next[1] - current[1]) * t]);
57
+ }
58
+ }
59
+ return polygonArea(out) < EPSILON ? [] : out;
60
+ }
61
+ /** Unsigned area of a simple polygon. */
62
+ export function polygonArea(polygon) {
63
+ let sum = 0;
64
+ for (let i = 0; i < polygon.length; i += 1) {
65
+ const a = polygon[i];
66
+ const b = polygon[(i + 1) % polygon.length];
67
+ sum += a[0] * b[1] - b[0] * a[1];
68
+ }
69
+ return Math.abs(sum) / 2;
70
+ }
71
+ /**
72
+ * The fold of one page at one moment.
73
+ *
74
+ * `lift` is limited to `length`. Within that limit the folded corner is never
75
+ * further from either end of the hinge than the corner it came from, which is
76
+ * what a sheet that cannot stretch allows, so the hinge stays on the flat side.
77
+ */
78
+ export function computeCurl(input) {
79
+ const length = Math.max(0, input.length);
80
+ const breadth = Math.max(0, input.breadth);
81
+ const fold = clamp01(input.fold);
82
+ const lift = Math.min(Math.max(0, input.lift), length);
83
+ const sheet = [
84
+ [0, 0],
85
+ [length, 0],
86
+ [length, breadth],
87
+ [0, breadth],
88
+ ];
89
+ const flatSheet = {
90
+ flat: sheet,
91
+ flap: [],
92
+ revealed: [],
93
+ receiver: [],
94
+ reflection: IDENTITY,
95
+ crease: null,
96
+ flapDepth: 0,
97
+ };
98
+ if (length === 0 || breadth === 0)
99
+ return flatSheet;
100
+ const held = [length, input.corner === "start" ? 0 : breadth];
101
+ const inward = input.corner === "start" ? 1 : -1;
102
+ const angle = Math.PI * fold;
103
+ const target = [length * Math.cos(angle), held[1] + inward * lift * Math.sin(angle)];
104
+ const dx = held[0] - target[0];
105
+ const dy = held[1] - target[1];
106
+ const gap = Math.hypot(dx, dy);
107
+ if (gap < FLAT_BELOW)
108
+ return flatSheet;
109
+ const normal = [dx / gap, dy / gap];
110
+ const point = [(held[0] + target[0]) / 2, (held[1] + target[1]) / 2];
111
+ const crease = { point, normal };
112
+ // p - 2((p - point) . normal) normal, written as a matrix.
113
+ const offset = 2 * dot(point, normal);
114
+ const reflection = [
115
+ 1 - 2 * normal[0] * normal[0],
116
+ -2 * normal[0] * normal[1],
117
+ -2 * normal[0] * normal[1],
118
+ 1 - 2 * normal[1] * normal[1],
119
+ offset * normal[0],
120
+ offset * normal[1],
121
+ ];
122
+ const revealed = clipHalfPlane(sheet, point, normal, 1);
123
+ const flat = clipHalfPlane(sheet, point, normal, -1);
124
+ const flap = revealed.map((p) => transformPoint(reflection, p));
125
+ // Out to one page past the hinge on every side: what the flap can land on.
126
+ const reach = [
127
+ [-length, -breadth],
128
+ [length, -breadth],
129
+ [length, 2 * breadth],
130
+ [-length, 2 * breadth],
131
+ ];
132
+ const receiver = clipHalfPlane(reach, point, normal, -1);
133
+ let flapDepth = 0;
134
+ for (const p of revealed)
135
+ flapDepth = Math.max(flapDepth, dot(sub(p, point), normal));
136
+ return { flat, flap, revealed, receiver, reflection, crease, flapDepth };
137
+ }
138
+ // ---- from paper to the page's box ----------------------------------------------------------------
139
+ /**
140
+ * Maps paper coordinates (hinge at `u = 0`) to pixels in the leaf's box (the
141
+ * page's own rectangle, top left at 0, 0). The hinge is the left edge in a
142
+ * left-to-right book, the right edge in a right-to-left one, and the top edge
143
+ * when the book turns upwards.
144
+ */
145
+ export function paperToBox(orientation, direction, width) {
146
+ if (orientation === "vertical")
147
+ return [0, 1, 1, 0, 0, 0];
148
+ return direction === "ltr" ? IDENTITY : [-1, 0, 0, 1, width, 0];
149
+ }
150
+ /**
151
+ * Maps a point of the page printed on the back of the leaf to the leaf's box
152
+ * as it lies flat, face down: mirrored along the turn axis, as in the flat
153
+ * turn, where the back face is the front rotated half a turn about the hinge.
154
+ */
155
+ export function backToBox(orientation, width, height) {
156
+ return orientation === "vertical" ? [1, 0, 0, -1, 0, height] : [-1, 0, 0, 1, width, 0];
157
+ }
158
+ /** One frame of the curl for a page of a given size and orientation, in the page's own pixels. */
159
+ export function computeCurlBox(input) {
160
+ const { width, height, orientation, direction } = input;
161
+ const vertical = orientation === "vertical";
162
+ const frame = computeCurl({
163
+ length: vertical ? height : width,
164
+ breadth: vertical ? width : height,
165
+ fold: input.fold,
166
+ corner: input.corner,
167
+ lift: input.lift,
168
+ });
169
+ const toBox = paperToBox(orientation, direction, width);
170
+ const toPaper = invertMatrix(toBox);
171
+ const map = (points) => points.map((p) => transformPoint(toBox, p));
172
+ const turnPoint = (p) => transformPoint(toBox, p);
173
+ const turnDirection = (n) => [
174
+ toBox[0] * n[0] + toBox[2] * n[1],
175
+ toBox[1] * n[0] + toBox[3] * n[1],
176
+ ];
177
+ const flapMatrix = multiply(toBox, multiply(frame.reflection, multiply(toPaper, backToBox(orientation, width, height))));
178
+ return {
179
+ flat: map(frame.flat),
180
+ flap: map(frame.flap),
181
+ revealed: map(frame.revealed),
182
+ receiver: map(frame.receiver),
183
+ flapMatrix,
184
+ crease: frame.crease
185
+ ? { point: turnPoint(frame.crease.point), normal: turnDirection(frame.crease.normal) }
186
+ : null,
187
+ flapDepth: frame.flapDepth,
188
+ };
189
+ }
190
+ /** Shadow values for a fold. `strength` is 0 for none, 1 for the strongest. */
191
+ export function computeCurlShading(input) {
192
+ const strength = clamp01(input.strength);
193
+ const arc = Math.sin(Math.PI * clamp01(input.fold));
194
+ return {
195
+ revealOpacity: 0.5 * strength * Math.pow(arc, 0.6),
196
+ revealLength: input.length * (0.12 + 0.2 * arc),
197
+ flapDark: 0.34 * strength * (0.4 + 0.6 * arc),
198
+ flapLight: 0.2 * strength * arc,
199
+ castOpacity: 0.4 * strength * Math.min(1, arc * 2.5),
200
+ castBlur: 6 + 8 * arc,
201
+ castOffset: 3 + 4 * arc,
202
+ };
203
+ }
204
+ //# sourceMappingURL=curl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curl.js","sourceRoot":"","sources":["../../../src/core/animation/curl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA4BtC,MAAM,CAAC,MAAM,QAAQ,GAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnD,yDAAyD;AACzD,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO;QACL,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG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QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;QAC7C,SAAS,EAAE,GAAG,GAAG,QAAQ,GAAG,GAAG;QAC/B,WAAW,EAAE,GAAG,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;QACpD,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG;QACrB,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG;KACxB,CAAC;AACJ,CAAC"}
@@ -1,9 +1,11 @@
1
- import type { FlipBookDirection } from "../types.js";
1
+ import type { FlipBookDirection, FlipBookOrientation } from "../types.js";
2
2
  export interface TurnVisualsInput {
3
3
  forward: boolean;
4
4
  /** Eased progress, 0..1. */
5
5
  progress: number;
6
6
  direction: FlipBookDirection;
7
+ /** Defaults to `"horizontal"`. */
8
+ orientation?: FlipBookOrientation;
7
9
  /** 0 disables shading, 1 is the strongest. */
8
10
  shadowIntensity: number;
9
11
  /** Book shift at the start and end of the turn, in page widths. */
@@ -13,8 +15,13 @@ export interface TurnVisualsInput {
13
15
  export interface TurnVisuals {
14
16
  /** How far the leaf has swung away from the recto side, 0..180 degrees. */
15
17
  angle: number;
16
- /** Signed CSS `rotateY` value for the leaf. */
18
+ /** Signed CSS `rotateY` value for the leaf (the horizontal turn). */
17
19
  rotateY: number;
20
+ /**
21
+ * Signed rotation in degrees for the leaf's own axis: `rotateY` when the book turns sideways,
22
+ * and `rotateX` when it turns upwards.
23
+ */
24
+ rotate: number;
18
25
  /** Darkening on the leaf's front face (visible below 90 degrees). */
19
26
  frontShade: number;
20
27
  /** Darkening on the leaf's back face (visible above 90 degrees). */
@@ -1 +1 @@
1
- {"version":3,"file":"turn.d.ts","sourceRoot":"","sources":["../../../src/core/animation/turn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,MAA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IACrE,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,WAAW,CA0BvE"}
@@ -17,6 +17,7 @@ export function computeTurnVisuals(input) {
17
17
  return {
18
18
  angle,
19
19
  rotateY: input.direction === "ltr" ? -angle : angle,
20
+ rotate: input.orientation === "vertical" ? angle : input.direction === "ltr" ? -angle : angle,
20
21
  frontShade,
21
22
  backShade,
22
23
  revealShade,
@@ -1 +1 @@
1
- {"version":3,"file":"turn.js","sourceRoot":"","sources":["../../../src/core/animation/turn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA+BtC;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAuB;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAEhD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,GAAG,CAAC;IACpE,MAAM,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IAExC,MAAM,UAAU,GAAG,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,IAAI,G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CAAC,KAAK;QACnD,MAAM,EAAE,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;QAC7F,UAAU;QACV,SAAS;QACT,WAAW;QACX,SAAS;QACT,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,QAAQ;KACtE,CAAC;AACJ,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import { type Spread } from "../layout/spreads.js";
2
2
  import type { EngineConfigPatch, EngineEventMap, EngineOptions, EngineState, FlipBookNavigation } from "../types.js";
3
3
  type Listener = () => void;
4
- type FrameListener = (progress: number) => void;
4
+ /** `lift` (0..1) is how far a held page is drawn up from its corner. It only matters to a curling page. */
5
+ type FrameListener = (progress: number, lift: number) => void;
6
+ /** Which end of a page's free edge a turn is held by. See `getTurnCorner`. */
7
+ export type TurnCorner = "start" | "end";
5
8
  /**
6
9
  * Framework-agnostic flipbook state machine.
7
10
  *
@@ -31,6 +34,8 @@ export declare class FlipBookEngine implements FlipBookNavigation {
31
34
  private spreadIndex;
32
35
  private turn;
33
36
  private progress;
37
+ private lift;
38
+ private corner;
34
39
  private dragging;
35
40
  private settling;
36
41
  private pending;
@@ -45,6 +50,13 @@ export declare class FlipBookEngine implements FlipBookNavigation {
45
50
  readonly getState: () => EngineState;
46
51
  /** Progress (0..1, eased) of the running turn, or 0 when idle. */
47
52
  getTurnProgress(): number;
53
+ /** How far the running turn is drawn up from its corner, 0..1. Scripted turns use 1. */
54
+ getTurnLift(): number;
55
+ /**
56
+ * The end of the page's free edge that the running turn holds. A scripted turn takes the `"end"`
57
+ * corner (the bottom of an upright page); a drag takes the one that was pressed.
58
+ */
59
+ getTurnCorner(): TurnCorner;
48
60
  /** The spread at `index`, using the current layout. */
49
61
  getSpreadAt(index: number): Spread;
50
62
  getCurrentPage(): number;
@@ -69,9 +81,13 @@ export declare class FlipBookEngine implements FlipBookNavigation {
69
81
  * Lifts the page at the edge of the current spread so a pointer can turn
70
82
  * it. Returns false when there is nothing to turn to or a turn is running.
71
83
  */
72
- beginDrag(direction: "forward" | "backward"): boolean;
73
- /** Moves the held page. 0 is where the turn began and 1 is fully turned. */
74
- dragTo(progress: number): void;
84
+ beginDrag(direction: "forward" | "backward", corner?: TurnCorner): boolean;
85
+ /**
86
+ * Moves the held page. 0 is where the turn began and 1 is fully turned.
87
+ * `lift` (0..1) is how far the corner is drawn up towards the middle of the page; a flat
88
+ * turn ignores it and a curling one tilts its crease with it.
89
+ */
90
+ dragTo(progress: number, lift?: number): void;
75
91
  /**
76
92
  * Lets go of the page. `complete` finishes the turn; otherwise the page
77
93
  * springs back and the reader stays where they were.
@@ -1 +1 @@
1
- {"version":3,"file":"FlipBookEngine.d.ts","sourceRoot":"","sources":["../../../src/core/engine/FlipBookEngine.ts"],"names":[],"mappings":"AAGA,OAAO,EAOL,KAAK,MAAM,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,WAAW,EACX,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAErB,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAC3B,KAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAe,YAAW,kBAAkB;IACvD,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,IAAI,CAA0B;IACtC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC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