html-flip-book-vanilla 0.0.0-alpha.35 → 0.0.0-alpha.37
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/dist/flip-book-options.d.ts +2 -0
- package/dist/flip-book-options.d.ts.map +1 -1
- package/dist/flipbook.d.ts +7 -2
- package/dist/flipbook.d.ts.map +1 -1
- package/dist/flipbook.js +133 -107
- package/dist/flipbook.js.map +1 -1
- package/dist/html-flip-book.css +1 -1
- package/dist/intl/locales/en-US.d.ts.map +1 -1
- package/dist/intl/locales/he-IL.d.ts.map +1 -1
- package/dist/intl.js +14 -10
- package/dist/intl.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ export interface FlipPageSemantic {
|
|
|
6
6
|
title: string;
|
|
7
7
|
}
|
|
8
8
|
export type PageFlipDirection = "forward" | "backward";
|
|
9
|
+
export type MouseMode = "turn" | "select";
|
|
9
10
|
export interface PageFlipParams {
|
|
10
11
|
leafIndex: number;
|
|
11
12
|
pageIndices: [number, number];
|
|
@@ -21,6 +22,7 @@ export interface FlipBookOptions {
|
|
|
21
22
|
leafAspectRatio?: AspectRatio;
|
|
22
23
|
coverAspectRatio?: AspectRatio;
|
|
23
24
|
direction?: "rtl" | "ltr";
|
|
25
|
+
mouseMode?: MouseMode;
|
|
24
26
|
padding?: number;
|
|
25
27
|
pageSemantics?: PageSemantics;
|
|
26
28
|
onPageChanged?: (pageIndex: number) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flip-book-options.d.ts","sourceRoot":"","sources":["../src/flip-book-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMtD,MAAM,WAAW,gBAAgB;IAChC,YAAY,EAAE,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AC;IAEtB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAE5C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAElD,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAMjD,aAAa,CAAC,EAAE,aAAa,CAAC;IAM9B,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAQ/B,YAAY,CAAC,EAAE,MAAM,CAAC;IAOtB,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAKrC,YAAY,CAAC,EAAE,MAAM,CAAC;IAOtB,cAAc,CAAC,EAAE,cAAc,CAAC;IAMhC,cAAc,CAAC,EAAE,OAAO,CAAC;IAKzB,UAAU,CAAC,EAAE,OAAO,CAAC;IAUrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B"}
|
package/dist/flipbook.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "./pages.scss";
|
|
2
2
|
import "./flipbook.scss";
|
|
3
|
+
import "./mouse-mode.scss";
|
|
3
4
|
import type { DownloadConfig } from "./download/types";
|
|
4
|
-
import type { FlipBookOptions } from "./flip-book-options";
|
|
5
|
+
import type { FlipBookOptions, MouseMode } from "./flip-book-options";
|
|
5
6
|
import type { PageSemantics } from "./page-semantics";
|
|
6
7
|
declare class FlipBook {
|
|
7
8
|
bookElement?: HTMLElement;
|
|
@@ -10,6 +11,7 @@ declare class FlipBook {
|
|
|
10
11
|
private readonly leafAspectRatio;
|
|
11
12
|
private readonly coverAspectRatio;
|
|
12
13
|
private readonly direction;
|
|
14
|
+
private mouseMode;
|
|
13
15
|
private readonly fastDeltaThreshold;
|
|
14
16
|
private readonly initialTurnedLeaves;
|
|
15
17
|
private readonly onPageChanged?;
|
|
@@ -54,6 +56,9 @@ declare class FlipBook {
|
|
|
54
56
|
constructor(options: FlipBookOptions);
|
|
55
57
|
private _tocPageIndex;
|
|
56
58
|
getTocPageIndex(): number;
|
|
59
|
+
getMouseMode(): MouseMode;
|
|
60
|
+
setMouseMode(mode: MouseMode): void;
|
|
61
|
+
private handlePageMouseDown;
|
|
57
62
|
getDownloadConfig(): DownloadConfig | undefined;
|
|
58
63
|
private buildCoverPageIndicesSet;
|
|
59
64
|
private recalculateSizes;
|
|
@@ -85,5 +90,5 @@ declare class FlipBook {
|
|
|
85
90
|
destroy(): void;
|
|
86
91
|
}
|
|
87
92
|
export { FlipBook, type PageSemantics };
|
|
88
|
-
export type { FlipPageSemantic, HistoryMapper, PageFlipDirection, PageFlipParams, } from "./flip-book-options";
|
|
93
|
+
export type { FlipPageSemantic, HistoryMapper, MouseMode, PageFlipDirection, PageFlipParams, } from "./flip-book-options";
|
|
89
94
|
//# sourceMappingURL=flipbook.d.ts.map
|
package/dist/flipbook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flipbook.d.ts","sourceRoot":"","sources":["../src/flipbook.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"flipbook.d.ts","sourceRoot":"","sources":["../src/flipbook.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;AACzB,OAAO,mBAAmB,CAAC;AAI3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EACX,eAAe,EAGf,SAAS,EAGT,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AA0CtD,cAAM,QAAQ;IACb,WAAW,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AC,gBAAgB;IAMxB,OAAO,CAAC,QAAQ;IA0BhB,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAKD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAKD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAKD,IAAI,UAAU,IAAI,OAAO,CAGxB;IAKD,OAAO,CAAC,4BAA4B;IAa9B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAgCzB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCzB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmClD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAiFnC,OAAO,CAAC,kBAAkB;IAQ1B,OAAO;CAgCP;AAED,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC;AACxC,YAAY,EACX,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,cAAc,GACd,MAAM,qBAAqB,CAAC"}
|
package/dist/flipbook.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { throttle as
|
|
3
|
-
import { setTocPageIndex as
|
|
4
|
-
var l = /* @__PURE__ */ ((
|
|
5
|
-
function
|
|
6
|
-
return typeof requestAnimationFrame < "u" ? requestAnimationFrame(
|
|
1
|
+
import L from "hammerjs";
|
|
2
|
+
import { throttle as T } from "throttle-debounce";
|
|
3
|
+
import { setTocPageIndex as M } from "./store/index.js";
|
|
4
|
+
var l = /* @__PURE__ */ ((u) => (u.Forward = "Forward", u.Backward = "Backward", u.None = "None", u))(l || {});
|
|
5
|
+
function b(u) {
|
|
6
|
+
return typeof requestAnimationFrame < "u" ? requestAnimationFrame(u) : setTimeout(() => u(performance.now()), 0);
|
|
7
7
|
}
|
|
8
8
|
const k = 1.1, C = 0.9;
|
|
9
9
|
class D {
|
|
@@ -64,45 +64,45 @@ class D {
|
|
|
64
64
|
}
|
|
65
65
|
async flipToPosition(e, t = 225) {
|
|
66
66
|
return this.currentAnimation && await this.currentAnimation, this.flipPosition === e ? Promise.resolve() : this.targetFlipPosition === e ? this.currentAnimation ?? Promise.resolve() : (this.targetFlipPosition = e, this.beginFlip(), this.currentAnimation = new Promise((i) => {
|
|
67
|
-
const s = this.flipPosition, n = Math.abs(e - s) * 180 / t * 1e3,
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
67
|
+
const s = this.flipPosition, n = Math.abs(e - s) * 180 / t * 1e3, r = performance.now(), a = (h) => {
|
|
68
|
+
const c = h - r;
|
|
69
|
+
if (c < 0) {
|
|
70
|
+
b(a);
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
const
|
|
74
|
-
this.applyTransform(
|
|
73
|
+
const p = Math.min(c / n, 1), d = s + p * (e - s);
|
|
74
|
+
this.applyTransform(d), this.flipPosition = Math.max(0, Math.min(1, d)), (this.flipPosition === 1 || this.flipPosition === 0) && this.onTurned(this.flipPosition === 1 ? l.Forward : l.Backward), p < 1 ? b(a) : (this.currentAnimation = null, this.targetFlipPosition = null, this.endFlip(), i());
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
b(a);
|
|
77
77
|
}), this.currentAnimation);
|
|
78
78
|
}
|
|
79
79
|
async efficientFlipToPosition(e, t = 2e4) {
|
|
80
|
-
return
|
|
80
|
+
return T(1, this.flipToPosition.bind(this))(e, t);
|
|
81
81
|
}
|
|
82
82
|
applyTransform(e) {
|
|
83
83
|
const t = Math.max(0, Math.min(1, e)), { pageShadow: i } = this.bookProperties;
|
|
84
84
|
let s = 0, o = 0;
|
|
85
85
|
if (i) {
|
|
86
|
-
const n = Math.sin(t * Math.PI),
|
|
87
|
-
s = Math.min(1,
|
|
86
|
+
const n = Math.sin(t * Math.PI), r = Math.max(n, this.hoverShadow);
|
|
87
|
+
s = Math.min(1, r * k), o = Math.min(1, r * C);
|
|
88
88
|
}
|
|
89
|
-
this.pages.forEach((n,
|
|
90
|
-
const
|
|
89
|
+
this.pages.forEach((n, r) => {
|
|
90
|
+
const a = this.bookProperties.isLTR;
|
|
91
91
|
if (!n) return;
|
|
92
|
-
const
|
|
93
|
-
if (n.style.transform = `translateX(${
|
|
94
|
-
const
|
|
95
|
-
n.style.setProperty("--inner-shadow-shadow", s.toFixed(3)), n.style.setProperty("--inner-shadow-highlight", o.toFixed(3)), n.style.setProperty("--inner-shadow-edge",
|
|
92
|
+
const h = r % 2 + 1 === 1, p = `${h ? a ? t > 0.5 ? 180 - t * 180 : -t * 180 : t > 0.5 ? -(180 - t * 180) : t * 180 : a ? t < 0.5 ? -t * 180 : 180 - t * 180 : t < 0.5 ? t * 180 : -(180 - t * 180)}deg`, d = `${h ? a ? "100%" : "-100%" : "0px"}`, f = h ? t > 0.5 ? -1 : 1 : t < 0.5 ? -1 : 1, m = h ? a ? "left" : "right" : a ? "right" : "left";
|
|
93
|
+
if (n.style.transform = `translateX(${d})rotateY(${p})scaleX(${f})`, n.style.transformOrigin = m, n.style.zIndex = `${t > 0.5 ? n.dataset.pageIndex : this.bookProperties.pagesCount - n.dataset.pageIndex}`, i) {
|
|
94
|
+
const g = m === "left" ? "right" : "left";
|
|
95
|
+
n.style.setProperty("--inner-shadow-shadow", s.toFixed(3)), n.style.setProperty("--inner-shadow-highlight", o.toFixed(3)), n.style.setProperty("--inner-shadow-edge", g);
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
class
|
|
100
|
+
class F {
|
|
101
101
|
constructor(e, t) {
|
|
102
102
|
this.width = e, this.height = t;
|
|
103
103
|
}
|
|
104
104
|
static from(e) {
|
|
105
|
-
return new
|
|
105
|
+
return new F(e.width, e.height);
|
|
106
106
|
}
|
|
107
107
|
get value() {
|
|
108
108
|
return this.width / this.height;
|
|
@@ -110,19 +110,19 @@ class w {
|
|
|
110
110
|
}
|
|
111
111
|
class v {
|
|
112
112
|
constructor(e, t) {
|
|
113
|
-
this.width = e, this.height = t, this.aspectRatio = new
|
|
113
|
+
this.width = e, this.height = t, this.aspectRatio = new F(e, t);
|
|
114
114
|
}
|
|
115
115
|
aspectRatio;
|
|
116
116
|
aspectRatioFit(e) {
|
|
117
|
-
const t =
|
|
117
|
+
const t = F.from(e).value;
|
|
118
118
|
return this.aspectRatio.value > t ? new v(this.height * t, this.height) : new v(this.width, this.width / t);
|
|
119
119
|
}
|
|
120
120
|
get asString() {
|
|
121
121
|
return `${this.width}x${this.height}`;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
const
|
|
125
|
-
class
|
|
124
|
+
const I = 500, x = 0.18, R = 0.12, A = 16;
|
|
125
|
+
class w {
|
|
126
126
|
bookElement;
|
|
127
127
|
pageElements = [];
|
|
128
128
|
pagesCount;
|
|
@@ -132,7 +132,8 @@ class P {
|
|
|
132
132
|
height: 3.15
|
|
133
133
|
};
|
|
134
134
|
direction = "ltr";
|
|
135
|
-
|
|
135
|
+
mouseMode = "turn";
|
|
136
|
+
fastDeltaThreshold = I;
|
|
136
137
|
initialTurnedLeaves = /* @__PURE__ */ new Set();
|
|
137
138
|
onPageChanged;
|
|
138
139
|
onPageFlipping;
|
|
@@ -176,7 +177,7 @@ class P {
|
|
|
176
177
|
resizeObserver;
|
|
177
178
|
static NO_FLIP_SELECTOR = "[data-flipbook-no-flip]";
|
|
178
179
|
isInsideNoFlipZone(e) {
|
|
179
|
-
return e instanceof Element && e.closest(
|
|
180
|
+
return e instanceof Element && e.closest(w.NO_FLIP_SELECTOR) != null;
|
|
180
181
|
}
|
|
181
182
|
getSemanticForPage(e) {
|
|
182
183
|
if (this.pageSemantics)
|
|
@@ -199,8 +200,8 @@ class P {
|
|
|
199
200
|
if (this.onPageFlipped && this.onPageFlipped(s), typeof window < "u" && this.historyMapper && !this._isRestoringFromHistory) {
|
|
200
201
|
const o = this.historyMapper.pageToRoute(t, i);
|
|
201
202
|
if (o == null) return;
|
|
202
|
-
const n = { route: o },
|
|
203
|
-
e || !this._historyInitialized ? (History.prototype.replaceState.call(window.history, n, "",
|
|
203
|
+
const n = { route: o }, r = o.startsWith("#") ? `${window.location.pathname}${window.location.search}${o}` : o;
|
|
204
|
+
e || !this._historyInitialized ? (History.prototype.replaceState.call(window.history, n, "", r), this._historyInitialized = !0) : History.prototype.pushState.call(window.history, n, "", r);
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
handlePopstate = () => {
|
|
@@ -230,13 +231,23 @@ class P {
|
|
|
230
231
|
return e === -1 ? [void 0, this.leaves[0]] : e === this.leaves.length ? [this.leaves[e - 1], void 0] : [this.leaves[e - 1], this.leaves[e]];
|
|
231
232
|
}
|
|
232
233
|
constructor(e) {
|
|
233
|
-
this.pagesCount = e.pagesCount, this.leafAspectRatio = e.leafAspectRatio || this.leafAspectRatio, this.coverAspectRatio = e.coverAspectRatio || this.coverAspectRatio, this.direction = e.direction || this.direction, this.fastDeltaThreshold = e.fastDeltaThreshold ?? this.fastDeltaThreshold, this.initialTurnedLeaves = new Set(e.initialTurnedLeaves ?? []), this.pageSemantics = e.pageSemantics, this.onPageChanged = e.onPageChanged, this.onPageFlipping = e.onPageFlipping, this.onPageFlipped = e.onPageFlipped, this.historyMapper = e.enableHistory !== !1 ? e.historyMapper : void 0, this.leavesBuffer = e.leavesBuffer, this.coverPageIndices = e.coverPageIndices, this.downloadConfig = e.enableDownload !== !1 ? e.downloadConfig : void 0, this.pageShadow = e.pageShadow ?? !0, this.snapshotDuringFlip = e.snapshotDuringFlip ?? !0, this._tocPageIndex = e.tocPageIndex ?? 4,
|
|
234
|
+
this.pagesCount = e.pagesCount, this.leafAspectRatio = e.leafAspectRatio || this.leafAspectRatio, this.coverAspectRatio = e.coverAspectRatio || this.coverAspectRatio, this.direction = e.direction || this.direction, this.mouseMode = e.mouseMode ?? "turn", this.fastDeltaThreshold = e.fastDeltaThreshold ?? this.fastDeltaThreshold, this.initialTurnedLeaves = new Set(e.initialTurnedLeaves ?? []), this.pageSemantics = e.pageSemantics, this.onPageChanged = e.onPageChanged, this.onPageFlipping = e.onPageFlipping, this.onPageFlipped = e.onPageFlipped, this.historyMapper = e.enableHistory !== !1 ? e.historyMapper : void 0, this.leavesBuffer = e.leavesBuffer, this.coverPageIndices = e.coverPageIndices, this.downloadConfig = e.enableDownload !== !1 ? e.downloadConfig : void 0, this.pageShadow = e.pageShadow ?? !0, this.snapshotDuringFlip = e.snapshotDuringFlip ?? !0, this._tocPageIndex = e.tocPageIndex ?? 4, M(this._tocPageIndex);
|
|
234
235
|
}
|
|
235
236
|
_tocPageIndex = 4;
|
|
236
237
|
/** Get the configured table of contents page index. */
|
|
237
238
|
getTocPageIndex() {
|
|
238
239
|
return this._tocPageIndex;
|
|
239
240
|
}
|
|
241
|
+
getMouseMode() {
|
|
242
|
+
return this.mouseMode;
|
|
243
|
+
}
|
|
244
|
+
setMouseMode(e) {
|
|
245
|
+
this.mouseMode = e, this.bookElement?.classList.toggle("flipbook--select-text", e === "select");
|
|
246
|
+
}
|
|
247
|
+
/** Keep mouse selection native by stopping the page's down event before Hammer sees it. */
|
|
248
|
+
handlePageMouseDown = (e) => {
|
|
249
|
+
this.mouseMode === "select" && e instanceof MouseEvent && e.button === 0 && (e.type !== "pointerdown" || e.pointerType === "mouse") && e.stopPropagation();
|
|
250
|
+
};
|
|
240
251
|
/** Download config (handlers and filename hints). Used by toolbar. */
|
|
241
252
|
getDownloadConfig() {
|
|
242
253
|
return this.downloadConfig;
|
|
@@ -265,32 +276,35 @@ class P {
|
|
|
265
276
|
this.bookElement.style.perspective = `${Math.min(i.width * 2, i.height) * 2}px`;
|
|
266
277
|
const s = this.bookElement.clientWidth, o = this.bookElement.clientHeight;
|
|
267
278
|
for (const n of this.pageElements) {
|
|
268
|
-
const
|
|
269
|
-
n.style.width = `${
|
|
279
|
+
const a = n.dataset.isCoverPage === "1" ? t : i;
|
|
280
|
+
n.style.width = `${a.width}px`, n.style.height = `${a.height}px`, n.style[this.isLTR ? "left" : "right"] = `${(s - 2 * a.width) / 2}px`, n.style.top = `${(o - a.height) / 2}px`;
|
|
270
281
|
}
|
|
271
282
|
}
|
|
272
283
|
render(e, t = !1) {
|
|
273
284
|
const i = document.querySelector(e);
|
|
274
285
|
if (!i)
|
|
275
286
|
throw new Error(`Couldn't find container with selector: ${e}`);
|
|
276
|
-
this.bookElement = i, this.bookElement.classList.contains("flipbook") || this.bookElement.classList.add("flipbook"), this.pageShadow || this.bookElement.classList.add("flipbook--no-page-shadow");
|
|
287
|
+
this.bookElement = i, this.setMouseMode(this.mouseMode), this.bookElement.classList.contains("flipbook") || this.bookElement.classList.add("flipbook"), this.pageShadow || this.bookElement.classList.add("flipbook--no-page-shadow");
|
|
277
288
|
const s = i.querySelectorAll(".page");
|
|
278
289
|
if (!s.length)
|
|
279
290
|
throw new Error("No pages found in flipbook");
|
|
280
|
-
this.pageElements = Array.from(s)
|
|
291
|
+
this.pageElements = Array.from(s);
|
|
292
|
+
for (const a of this.pageElements)
|
|
293
|
+
a.addEventListener("pointerdown", this.handlePageMouseDown), a.addEventListener("mousedown", this.handlePageMouseDown);
|
|
294
|
+
this.leaves.splice(0, this.leaves.length);
|
|
281
295
|
const o = Math.ceil(this.pagesCount / 2), n = this.buildCoverPageIndicesSet();
|
|
282
|
-
this.pageElements.forEach((
|
|
283
|
-
|
|
284
|
-
}), this.recalculateSizes(), this.pageElements.forEach((
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
296
|
+
this.pageElements.forEach((a, h) => {
|
|
297
|
+
a.dataset.pageIndex = h.toString(), a.dataset.pageSemanticName = this.pageSemantics?.indexToSemanticName(h) ?? "", a.dataset.pageTitle = this.pageSemantics?.indexToTitle(h) ?? "", a.dataset.isCoverPage = n.has(h) ? "1" : "";
|
|
298
|
+
}), this.recalculateSizes(), this.pageElements.forEach((a, h) => {
|
|
299
|
+
const c = Math.floor(h / 2), p = (h + 1) % 2 === 1, d = this.initialTurnedLeaves.has(c), f = this.initialTurnedLeaves.size > 0 ? Math.max(...this.initialTurnedLeaves) + 1 : 0, m = c === f || c === f - 1 && d;
|
|
300
|
+
if (a.classList.add(
|
|
287
301
|
p ? "odd" : "even",
|
|
288
|
-
...
|
|
302
|
+
...m ? ["current-page"] : []
|
|
289
303
|
), p)
|
|
290
|
-
this.leaves[
|
|
304
|
+
this.leaves[c] = new D(
|
|
305
|
+
c,
|
|
306
|
+
[a, void 0],
|
|
291
307
|
d,
|
|
292
|
-
[c, void 0],
|
|
293
|
-
f,
|
|
294
308
|
{
|
|
295
309
|
isLTR: this.isLTR,
|
|
296
310
|
leavesCount: o,
|
|
@@ -298,29 +312,34 @@ class P {
|
|
|
298
312
|
pageShadow: this.pageShadow,
|
|
299
313
|
snapshotDuringFlip: this.snapshotDuringFlip
|
|
300
314
|
},
|
|
301
|
-
(
|
|
302
|
-
const
|
|
303
|
-
if (this.prevVisiblePageIndices && this.prevVisiblePageIndices.length ===
|
|
315
|
+
(g) => {
|
|
316
|
+
const P = g === l.Forward ? h + 2 === this.pagesCount ? [h + 1] : [h + 1, h + 2] : h === 0 ? [h] : [h - 1, h];
|
|
317
|
+
if (this.prevVisiblePageIndices && this.prevVisiblePageIndices.length === P.length && P.every((S, E) => S === this.prevVisiblePageIndices?.[E]))
|
|
304
318
|
return;
|
|
305
|
-
const
|
|
306
|
-
this.prevVisiblePageIndices =
|
|
319
|
+
const y = this.prevVisiblePageIndices;
|
|
320
|
+
this.prevVisiblePageIndices = P, this.onTurned(P, y);
|
|
307
321
|
}
|
|
308
322
|
);
|
|
309
323
|
else {
|
|
310
|
-
this.leaves[
|
|
311
|
-
const
|
|
312
|
-
this.leaves[
|
|
324
|
+
this.leaves[c].pages[1] = a;
|
|
325
|
+
const g = d ? 1 : 0;
|
|
326
|
+
this.leaves[c].applyTransform(g);
|
|
313
327
|
}
|
|
314
328
|
});
|
|
315
|
-
const r =
|
|
316
|
-
if (r
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
329
|
+
const r = this.initialTurnedLeaves.size > 0 ? Math.max(...this.initialTurnedLeaves) : -1;
|
|
330
|
+
if (r < 0)
|
|
331
|
+
this.prevVisiblePageIndices = 1 < this.pagesCount ? [0, 1] : [0];
|
|
332
|
+
else {
|
|
333
|
+
const a = r * 2 + 1;
|
|
334
|
+
if (a >= this.pagesCount) {
|
|
335
|
+
const c = (Math.ceil(this.pagesCount / 2) - 1) * 2;
|
|
336
|
+
this.prevVisiblePageIndices = c + 1 < this.pagesCount ? [c, c + 1] : [c];
|
|
337
|
+
} else
|
|
338
|
+
this.prevVisiblePageIndices = a + 1 < this.pagesCount ? [a, a + 1] : [a];
|
|
339
|
+
}
|
|
321
340
|
typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => {
|
|
322
341
|
this.recalculateSizes();
|
|
323
|
-
}), this.resizeObserver.observe(this.bookElement)), this.hammer = new
|
|
342
|
+
}), this.resizeObserver.observe(this.bookElement)), this.hammer = new L(this.bookElement), this.hammer.get("pan").set({ direction: L.DIRECTION_HORIZONTAL }), this.hammer.on("panstart", this.onDragStart.bind(this)), this.hammer.on("panmove", this.onDragUpdate.bind(this)), this.hammer.on("panend", this.onDragEnd.bind(this)), this.bookElement.addEventListener("touchstart", this.handleTouchStart.bind(this), {
|
|
324
343
|
passive: !1
|
|
325
344
|
}), this.bookElement.addEventListener("touchmove", this.handleTouchMove.bind(this), {
|
|
326
345
|
passive: !1
|
|
@@ -343,16 +362,16 @@ class P {
|
|
|
343
362
|
return;
|
|
344
363
|
const e = this.leaves.length;
|
|
345
364
|
if (e === 0) return;
|
|
346
|
-
const [t, i] = this.currentOrTurningLeaves, s = i?.index ?? t?.index ?? 0, o = Math.max(0, s - this.leavesBuffer), n = Math.min(e - 1, s + this.leavesBuffer),
|
|
365
|
+
const [t, i] = this.currentOrTurningLeaves, s = i?.index ?? t?.index ?? 0, o = Math.max(0, s - this.leavesBuffer), n = Math.min(e - 1, s + this.leavesBuffer), r = /* @__PURE__ */ new Set();
|
|
347
366
|
if (this.coverPageIndices) {
|
|
348
|
-
const
|
|
349
|
-
for (const
|
|
350
|
-
|
|
367
|
+
const a = this.coverPageIndices === "auto" ? [0, this.pagesCount - 1] : this.coverPageIndices;
|
|
368
|
+
for (const h of a)
|
|
369
|
+
r.add(Math.floor(h / 2));
|
|
351
370
|
}
|
|
352
|
-
for (let
|
|
353
|
-
const
|
|
354
|
-
for (const f of
|
|
355
|
-
f && (f.style.display =
|
|
371
|
+
for (let a = 0; a < e; a++) {
|
|
372
|
+
const h = this.leaves[a], c = a >= o && a <= n, d = r.has(a) || c;
|
|
373
|
+
for (const f of h.pages)
|
|
374
|
+
f && (f.style.display = d ? "" : "none", f.style.contentVisibility = d ? "visible" : "hidden");
|
|
356
375
|
}
|
|
357
376
|
}
|
|
358
377
|
fillDebugBar() {
|
|
@@ -418,32 +437,32 @@ class P {
|
|
|
418
437
|
if (Math.abs(o) > s || o === 0) return;
|
|
419
438
|
const n = this.pendingFlipDirection !== l.None ? this.pendingFlipDirection : o > 0 ? l.Forward : l.Backward;
|
|
420
439
|
if (this.pendingFlipDirection === l.None && (this.pendingFlipDirection = n), !t) {
|
|
421
|
-
for (const
|
|
422
|
-
if (
|
|
440
|
+
for (const r of this.activeFlips.values())
|
|
441
|
+
if (r.isDuringAutoFlip && r.direction !== n)
|
|
423
442
|
return;
|
|
424
443
|
}
|
|
425
444
|
if (!t) {
|
|
426
|
-
const
|
|
427
|
-
if (!
|
|
428
|
-
|
|
429
|
-
leaf:
|
|
445
|
+
const r = this.getNextAvailableLeaf(n);
|
|
446
|
+
if (!r) return;
|
|
447
|
+
r.beginFlip(), this.pendingFlipStartingPos = i, o = 0, t = {
|
|
448
|
+
leaf: r,
|
|
430
449
|
direction: n,
|
|
431
450
|
startingPos: i,
|
|
432
451
|
delta: 0,
|
|
433
452
|
isDuringAutoFlip: !1
|
|
434
|
-
}, this.activeFlips.set(
|
|
453
|
+
}, this.activeFlips.set(r.index, t);
|
|
435
454
|
}
|
|
436
455
|
switch (t.delta = o, t.direction) {
|
|
437
456
|
case l.Forward: {
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
t.leaf.efficientFlipToPosition(
|
|
457
|
+
const r = o / s;
|
|
458
|
+
if (r > 1 || o < 0) return;
|
|
459
|
+
t.leaf.efficientFlipToPosition(r);
|
|
441
460
|
break;
|
|
442
461
|
}
|
|
443
462
|
case l.Backward: {
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
446
|
-
t.leaf.efficientFlipToPosition(
|
|
463
|
+
const r = 1 - Math.abs(o) / s;
|
|
464
|
+
if (r < 0 || o > 0) return;
|
|
465
|
+
t.leaf.efficientFlipToPosition(r);
|
|
447
466
|
break;
|
|
448
467
|
}
|
|
449
468
|
}
|
|
@@ -486,11 +505,11 @@ class P {
|
|
|
486
505
|
const t = e.touches[0], i = t.pageX - this.touchStartingPos.x, s = t.pageY - this.touchStartingPos.y;
|
|
487
506
|
if (this.touchDirectionLock === "none") {
|
|
488
507
|
const o = Math.abs(i), n = Math.abs(s);
|
|
489
|
-
(o >
|
|
508
|
+
(o > w.DIRECTION_LOCK_THRESHOLD || n > w.DIRECTION_LOCK_THRESHOLD) && (this.touchDirectionLock = o >= n ? "horizontal" : "vertical");
|
|
490
509
|
}
|
|
491
510
|
this.touchDirectionLock === "horizontal" && e.preventDefault();
|
|
492
511
|
};
|
|
493
|
-
handleMouseMove =
|
|
512
|
+
handleMouseMove = T(A, (e) => {
|
|
494
513
|
if (!this.bookElement) return;
|
|
495
514
|
if (this.isDragging || this.currentManualFlip || this.activeFlips.size > 0) {
|
|
496
515
|
this.clearHoverShadow();
|
|
@@ -498,18 +517,18 @@ class P {
|
|
|
498
517
|
}
|
|
499
518
|
const t = this.bookElement.getBoundingClientRect();
|
|
500
519
|
if (t.width <= 0) return;
|
|
501
|
-
const i = e.clientX - t.left, s = t.width *
|
|
520
|
+
const i = e.clientX - t.left, s = t.width * x, o = i <= s, n = i >= t.width - s;
|
|
502
521
|
if (!o && !n) {
|
|
503
522
|
this.clearHoverShadow();
|
|
504
523
|
return;
|
|
505
524
|
}
|
|
506
|
-
const
|
|
507
|
-
if (!
|
|
525
|
+
const r = this.isLTR ? n : o, a = r ? l.Forward : l.Backward, h = this.getNextAvailableLeaf(a);
|
|
526
|
+
if (!h) {
|
|
508
527
|
this.clearHoverShadow();
|
|
509
528
|
return;
|
|
510
529
|
}
|
|
511
|
-
const
|
|
512
|
-
this.hoveredLeaf && this.hoveredLeaf !==
|
|
530
|
+
const c = r ? this.isLTR ? t.width - i : i : this.isLTR ? i : t.width - i, d = (1 - Math.min(1, c / s)) * R;
|
|
531
|
+
this.hoveredLeaf && this.hoveredLeaf !== h && this.hoveredLeaf.setHoverShadow(0), this.hoveredLeaf = h, h.setHoverShadow(d);
|
|
513
532
|
});
|
|
514
533
|
handleMouseLeave = () => {
|
|
515
534
|
this.clearHoverShadow();
|
|
@@ -631,14 +650,17 @@ class P {
|
|
|
631
650
|
);
|
|
632
651
|
return;
|
|
633
652
|
}
|
|
634
|
-
const t = Math.floor(e / 2), i = Math.floor(this.currentPageIndex / 2);
|
|
653
|
+
const t = e <= 0 ? -1 : Math.floor((e - 1) / 2), i = this.currentPageIndex <= 0 ? -1 : Math.floor((this.currentPageIndex - 1) / 2);
|
|
635
654
|
if (t !== i)
|
|
636
|
-
if (t > i)
|
|
637
|
-
|
|
655
|
+
if (t > i) {
|
|
656
|
+
const s = t - i;
|
|
657
|
+
for (let o = 0; o < s; o++)
|
|
638
658
|
await this.flipNext();
|
|
639
|
-
else
|
|
640
|
-
|
|
659
|
+
} else {
|
|
660
|
+
const s = i - t;
|
|
661
|
+
for (let o = 0; o < s; o++)
|
|
641
662
|
await this.flipPrev();
|
|
663
|
+
}
|
|
642
664
|
}
|
|
643
665
|
/**
|
|
644
666
|
* Jump to a specific page instantly without animation.
|
|
@@ -655,8 +677,8 @@ class P {
|
|
|
655
677
|
let o;
|
|
656
678
|
e <= 0 ? o = -1 : s ? o = this.leaves.length - 1 : o = Math.floor((e - 1) / 2);
|
|
657
679
|
for (let n = 0; n < this.leaves.length; n++) {
|
|
658
|
-
const
|
|
659
|
-
|
|
680
|
+
const r = this.leaves[n], a = n <= o;
|
|
681
|
+
a && !r.isTurned ? (r.flipPosition = 1, this.applyLeafTransform(r, 1)) : !a && r.isTurned && (r.flipPosition = 0, this.applyLeafTransform(r, 0));
|
|
660
682
|
}
|
|
661
683
|
if (s)
|
|
662
684
|
this.prevVisiblePageIndices = [e];
|
|
@@ -667,8 +689,8 @@ class P {
|
|
|
667
689
|
this.prevVisiblePageIndices = n + 1 < this.pagesCount ? [n, n + 1] : [n];
|
|
668
690
|
}
|
|
669
691
|
for (let n = 0; n < this.pageElements.length; n++) {
|
|
670
|
-
const
|
|
671
|
-
this.prevVisiblePageIndices.includes(n) ?
|
|
692
|
+
const r = this.pageElements[n];
|
|
693
|
+
this.prevVisiblePageIndices.includes(n) ? r.classList.add("current-page") : r.classList.remove("current-page");
|
|
672
694
|
}
|
|
673
695
|
this.updateLeavesBufferVisibility(), this.syncHistoryAndNotifyFlipped(!1);
|
|
674
696
|
}
|
|
@@ -684,17 +706,21 @@ class P {
|
|
|
684
706
|
* Should be called when the FlipBook is no longer needed.
|
|
685
707
|
*/
|
|
686
708
|
destroy() {
|
|
687
|
-
typeof window < "u" && this._boundPopstate && (window.removeEventListener("popstate", this._boundPopstate), this._boundPopstate = void 0), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = void 0), this.hammer && (this.hammer.destroy(), this.hammer = void 0), this.bookElement
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
709
|
+
if (typeof window < "u" && this._boundPopstate && (window.removeEventListener("popstate", this._boundPopstate), this._boundPopstate = void 0), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = void 0), this.hammer && (this.hammer.destroy(), this.hammer = void 0), this.bookElement) {
|
|
710
|
+
for (const e of this.pageElements)
|
|
711
|
+
e.removeEventListener("pointerdown", this.handlePageMouseDown), e.removeEventListener("mousedown", this.handlePageMouseDown);
|
|
712
|
+
this.bookElement.removeEventListener("touchstart", this.handleTouchStart), this.bookElement.removeEventListener("touchmove", this.handleTouchMove), this.bookElement.removeEventListener(
|
|
713
|
+
"mousemove",
|
|
714
|
+
this.handleMouseMove
|
|
715
|
+
), this.bookElement.removeEventListener("mouseleave", this.handleMouseLeave), this.bookElement.removeEventListener(
|
|
716
|
+
"click",
|
|
717
|
+
this.handleClickAfterDrag,
|
|
718
|
+
!0
|
|
719
|
+
);
|
|
720
|
+
}
|
|
695
721
|
}
|
|
696
722
|
}
|
|
697
723
|
export {
|
|
698
|
-
|
|
724
|
+
w as FlipBook
|
|
699
725
|
};
|
|
700
726
|
//# sourceMappingURL=flipbook.js.map
|
package/dist/flipbook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flipbook.js","sources":["../src/flip-direction.ts","../src/leaf.ts","../src/aspect-ratio.ts","../src/size.ts","../src/flipbook.ts"],"sourcesContent":["export enum FlipDirection {\n\tForward = \"Forward\",\n\tBackward = \"Backward\",\n\tNone = \"None\",\n}\n","import { throttle } from \"throttle-debounce\";\nimport type { IntRange } from \"type-fest\";\nimport { FlipDirection } from \"./flip-direction\";\n\n/** Schedule a frame callback; fallback for test envs where requestAnimationFrame is missing. Called at invoke time so test mocks apply. */\nfunction scheduleFrame(cb: (timestamp: number) => void): number {\n\treturn typeof requestAnimationFrame !== \"undefined\"\n\t\t? requestAnimationFrame(cb)\n\t\t: (setTimeout(() => cb(performance.now()), 0) as unknown as number);\n}\n\n/** Multiplier for shadow intensity (slightly stronger than base) */\nconst SHADOW_STRENGTH_MULTIPLIER = 1.1;\n/** Multiplier for highlight intensity (slightly weaker than base) */\nconst HIGHLIGHT_STRENGTH_MULTIPLIER = 0.9;\n\n// number between 1 to infinity\nexport type DegreesPerSecond = IntRange<1, typeof Infinity>;\nexport type FlipPosition = IntRange<0, 2>;\nexport const FLIPPED = true;\nexport const NOT_FLIPPED = false;\nexport class Leaf {\n\tprivate currentAnimation: Promise<void> | null = null;\n\tprivate targetFlipPosition: FlipPosition | null = null;\n\tprivate wrappedFlipPosition: number;\n\tprivate hoverShadow = 0;\n\t/** Ref-count for nested beginFlip/endFlip pairs (drag wrapping animation). */\n\tprivate flipRefCount = 0;\n\n\tconstructor(\n\t\treadonly index: number,\n\t\treadonly pages: [HTMLElement, HTMLElement | undefined],\n\t\tisFlipped: boolean,\n\t\tprivate readonly bookProperties: {\n\t\t\tisLTR: boolean;\n\t\t\tpagesCount: number;\n\t\t\tleavesCount: number;\n\t\t\tpageShadow: boolean;\n\t\t\tsnapshotDuringFlip: boolean;\n\t\t},\n\t\tprivate readonly onTurned: (direction: FlipDirection) => void,\n\t) {\n\t\tthis.wrappedFlipPosition = isFlipped ? 1 : 0;\n\t\t// TODO: rethink this\n\t\t// if(isFlipped) {\n\t\t// // this.flipToPosition(1);\n\t\t// }\n\t}\n\n\tget isTurned(): boolean {\n\t\treturn this.flipPosition === 1;\n\t}\n\tget isTurning(): boolean {\n\t\treturn this.flipPosition !== 0;\n\t}\n\tget isCover(): boolean {\n\t\treturn this.isFirst || this.isLast;\n\t}\n\tget isFirst(): boolean {\n\t\treturn this.index === 0;\n\t}\n\tget isLast(): boolean {\n\t\treturn this.index === this.bookProperties.leavesCount - 1;\n\t}\n\tset flipPosition(value: number) {\n\t\tthis.wrappedFlipPosition = Math.max(0, Math.min(1, value)) as FlipPosition;\n\t}\n\tget flipPosition(): number {\n\t\treturn this.wrappedFlipPosition;\n\t}\n\n\tsetHoverShadow(progress: number): void {\n\t\tconst clamped = Math.max(0, Math.min(1, progress));\n\t\tif (this.hoverShadow === clamped) return;\n\t\tthis.hoverShadow = clamped;\n\t\tthis.applyTransform(this.flipPosition);\n\t}\n\n\t/**\n\t * Signal that a flip interaction is starting (drag or animation).\n\t * Ref-counted: the snapshot class is added on the first call and\n\t * removed only when every `beginFlip` has a matching `endFlip`.\n\t * This keeps the GPU layer and scrollbar/selection lockdown stable\n\t * across the full drag→release→animation cycle.\n\t */\n\tbeginFlip(): void {\n\t\tthis.flipRefCount++;\n\t\tif (this.flipRefCount !== 1) return; // already promoted\n\t\tfor (const page of this.pages) {\n\t\t\tif (!page) continue;\n\t\t\tpage.style.willChange = \"transform\";\n\t\t\tif (this.bookProperties.snapshotDuringFlip) {\n\t\t\t\tpage.classList.add(\"page--flipping\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Signal that a flip interaction finished (drag or animation).\n\t * Only releases the GPU layer when every `beginFlip` is balanced.\n\t */\n\tendFlip(): void {\n\t\tthis.flipRefCount = Math.max(0, this.flipRefCount - 1);\n\t\tif (this.flipRefCount !== 0) return; // still active\n\t\tfor (const page of this.pages) {\n\t\t\tif (!page) continue;\n\t\t\tpage.style.willChange = \"\";\n\t\t\tif (this.bookProperties.snapshotDuringFlip) {\n\t\t\t\tpage.classList.remove(\"page--flipping\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync flipToPosition(\n\t\tflipPosition: FlipPosition,\n\t\tvelocity: DegreesPerSecond = 225 as DegreesPerSecond,\n\t) {\n\t\tif (this.currentAnimation) {\n\t\t\tawait this.currentAnimation;\n\t\t}\n\n\t\tif (this.flipPosition === flipPosition) {\n\t\t\treturn Promise.resolve();\n\t\t}\n\n\t\tif (this.targetFlipPosition === flipPosition) {\n\t\t\treturn this.currentAnimation ?? Promise.resolve();\n\t\t}\n\n\t\tthis.targetFlipPosition = flipPosition;\n\t\t// Promote to GPU layer before animation starts for smooth compositing\n\t\tthis.beginFlip();\n\n\t\tthis.currentAnimation = new Promise<void>((resolve) => {\n\t\t\tconst currentFlipPosition = this.flipPosition;\n\t\t\tconst distance = Math.abs(flipPosition - currentFlipPosition);\n\t\t\tconst duration = ((distance * 180) / velocity) * 1000; // duration in milliseconds\n\n\t\t\tconst start = performance.now();\n\t\t\tconst step = (timestamp: number) => {\n\t\t\t\tconst elapsed = timestamp - start;\n\n\t\t\t\tif (elapsed < 0) {\n\t\t\t\t\tscheduleFrame(step);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst progress = Math.min(elapsed / duration, 1);\n\t\t\t\tconst newPosition = currentFlipPosition + progress * (flipPosition - currentFlipPosition);\n\n\t\t\t\tthis.applyTransform(newPosition);\n\n\t\t\t\t// Ensure the new position is within valid bounds [0, 1]\n\t\t\t\tthis.flipPosition = Math.max(0, Math.min(1, newPosition)) as FlipPosition;\n\t\t\t\tif (this.flipPosition === 1 || this.flipPosition === 0) {\n\t\t\t\t\tthis.onTurned(this.flipPosition === 1 ? FlipDirection.Forward : FlipDirection.Backward);\n\t\t\t\t}\n\n\t\t\t\tif (progress < 1) {\n\t\t\t\t\tscheduleFrame(step);\n\t\t\t\t} else {\n\t\t\t\t\tthis.currentAnimation = null;\n\t\t\t\t\tthis.targetFlipPosition = null;\n\t\t\t\t\t// Release GPU layer after animation completes\n\t\t\t\t\tthis.endFlip();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tscheduleFrame(step);\n\t\t});\n\n\t\treturn this.currentAnimation;\n\t}\n\n\tasync efficientFlipToPosition(\n\t\tflipPosition: FlipPosition,\n\t\tvelocity: DegreesPerSecond = 20000 as DegreesPerSecond,\n\t) {\n\t\treturn throttle(1, this.flipToPosition.bind(this))(flipPosition, velocity);\n\t}\n\n\tapplyTransform(position: number): void {\n\t\tconst clampedPosition = Math.max(0, Math.min(1, position));\n\t\tconst { pageShadow } = this.bookProperties;\n\n\t\t// Only compute shadow values when shadow is enabled — skipping these\n\t\t// saves CSS custom-property mutations per page per animation frame.\n\t\tlet shadowStrength = 0;\n\t\tlet highlightStrength = 0;\n\t\tif (pageShadow) {\n\t\t\tconst shadowFromFlip = Math.sin(clampedPosition * Math.PI);\n\t\t\tconst shadowProgress = Math.max(shadowFromFlip, this.hoverShadow);\n\t\t\tshadowStrength = Math.min(1, shadowProgress * SHADOW_STRENGTH_MULTIPLIER);\n\t\t\thighlightStrength = Math.min(1, shadowProgress * HIGHLIGHT_STRENGTH_MULTIPLIER);\n\t\t}\n\n\t\tthis.pages.forEach((page, index) => {\n\t\t\tconst isLTR = this.bookProperties.isLTR;\n\t\t\tif (!page) return;\n\n\t\t\tconst isOdd = (index % 2) + 1 === 1;\n\t\t\tconst degrees = isOdd\n\t\t\t\t? isLTR\n\t\t\t\t\t? clampedPosition > 0.5\n\t\t\t\t\t\t? 180 - clampedPosition * 180\n\t\t\t\t\t\t: -clampedPosition * 180\n\t\t\t\t\t: clampedPosition > 0.5\n\t\t\t\t\t\t? -(180 - clampedPosition * 180)\n\t\t\t\t\t\t: clampedPosition * 180\n\t\t\t\t: isLTR\n\t\t\t\t\t? clampedPosition < 0.5\n\t\t\t\t\t\t? -clampedPosition * 180\n\t\t\t\t\t\t: 180 - clampedPosition * 180\n\t\t\t\t\t: clampedPosition < 0.5\n\t\t\t\t\t\t? clampedPosition * 180\n\t\t\t\t\t\t: -(180 - clampedPosition * 180);\n\t\t\tconst rotateY = `${degrees}deg`;\n\t\t\tconst translateX = `${isOdd ? (isLTR ? \"100%\" : \"-100%\") : \"0px\"}`;\n\t\t\tconst scaleX = isOdd ? (clampedPosition > 0.5 ? -1 : 1) : clampedPosition < 0.5 ? -1 : 1;\n\t\t\tconst origin = isOdd ? (isLTR ? \"left\" : \"right\") : isLTR ? \"right\" : \"left\";\n\n\t\t\tpage.style.transform = `translateX(${translateX})rotateY(${rotateY})scaleX(${scaleX})`;\n\t\t\tpage.style.transformOrigin = origin;\n\t\t\tpage.style.zIndex = `${\n\t\t\t\tclampedPosition > 0.5\n\t\t\t\t\t? page.dataset.pageIndex\n\t\t\t\t\t: this.bookProperties.pagesCount - (page.dataset.pageIndex as unknown as number)\n\t\t\t}`;\n\n\t\t\tif (pageShadow) {\n\t\t\t\tconst edge = origin === \"left\" ? \"right\" : \"left\";\n\t\t\t\tpage.style.setProperty(\"--inner-shadow-shadow\", shadowStrength.toFixed(3));\n\t\t\t\tpage.style.setProperty(\"--inner-shadow-highlight\", highlightStrength.toFixed(3));\n\t\t\t\tpage.style.setProperty(\"--inner-shadow-edge\", edge);\n\t\t\t}\n\t\t});\n\t}\n}\n","export interface AspectRatio {\n\twidth: number;\n\theight: number;\n}\nexport class AspectRatioImpl implements AspectRatio {\n\tstatic from(aspectRatio: AspectRatio) {\n\t\treturn new AspectRatioImpl(aspectRatio.width, aspectRatio.height);\n\t}\n\tconstructor(\n\t\tpublic readonly width: number,\n\t\tpublic readonly height: number,\n\t) {}\n\tget value(): number {\n\t\treturn this.width / this.height;\n\t}\n}\n","import { type AspectRatio, AspectRatioImpl } from \"./aspect-ratio\";\n\nexport class Size {\n\taspectRatio: AspectRatioImpl;\n\taspectRatioFit(rhsAspectRatio: AspectRatio) {\n\t\tconst rhsAspectRatioValue = AspectRatioImpl.from(rhsAspectRatio).value;\n\t\treturn this.aspectRatio.value > rhsAspectRatioValue\n\t\t\t? new Size(this.height * rhsAspectRatioValue, this.height)\n\t\t\t: new Size(this.width, this.width / rhsAspectRatioValue);\n\t}\n\tconstructor(\n\t\tpublic readonly width: number,\n\t\tpublic readonly height: number,\n\t) {\n\t\tthis.aspectRatio = new AspectRatioImpl(width, height);\n\t}\n\tget asString(): string {\n\t\treturn `${this.width}x${this.height}`;\n\t}\n}\n","import \"./pages.scss\";\nimport \"./flipbook.scss\";\nimport Hammer from \"hammerjs\";\nimport { throttle } from \"throttle-debounce\";\nimport type { AspectRatio } from \"./aspect-ratio\";\nimport type { DownloadConfig } from \"./download/types\";\nimport type {\n\tFlipBookOptions,\n\tFlipPageSemantic,\n\tHistoryMapper,\n\tPageFlipDirection,\n\tPageFlipParams,\n} from \"./flip-book-options\";\nimport { FlipDirection } from \"./flip-direction\";\nimport { type FlipPosition, Leaf } from \"./leaf\";\nimport type { PageSemantics } from \"./page-semantics\";\nimport { Size } from \"./size\";\nimport { setTocPageIndex } from \"./store\";\n\n/** Default threshold for fast flip detection (in ms) */\nconst DEFAULT_FAST_DELTA = 500;\n\n/** Percentage of book width that triggers hover shadow effect */\nconst EDGE_ZONE_RATIO = 0.18;\n/** Maximum hover shadow strength (0-1) */\nconst HOVER_STRENGTH_MAX = 0.12;\n/** Throttle interval for mouse move handler in ms */\nconst MOUSE_MOVE_THROTTLE_MS = 16;\n\n/** State for a single flip operation - enables concurrent page flipping */\ninterface FlipState {\n\tleaf: Leaf;\n\tdirection: FlipDirection;\n\tstartingPos: number;\n\tdelta: number;\n\tisDuringAutoFlip: boolean;\n}\n\n/**\n * Core FlipBook class for creating realistic page-flip animations.\n *\n * @example\n * ```typescript\n * import { FlipBook } from 'html-flip-book-vanilla';\n *\n * const flipBook = new FlipBook({\n * pagesCount: 10,\n * direction: 'ltr',\n * });\n *\n * flipBook.render('#book-container');\n *\n * // Navigate programmatically\n * await flipBook.flipNext();\n * await flipBook.flipToPage(5);\n * ```\n */\nclass FlipBook {\n\tbookElement?: HTMLElement;\n\tprivate pageElements: HTMLElement[] = [];\n\tprivate readonly pagesCount: number;\n\tprivate readonly leafAspectRatio: AspectRatio = { width: 2, height: 3 };\n\tprivate readonly coverAspectRatio: AspectRatio = {\n\t\twidth: 2.15,\n\t\theight: 3.15,\n\t};\n\tprivate readonly direction: \"rtl\" | \"ltr\" = \"ltr\";\n\tprivate readonly fastDeltaThreshold: number = DEFAULT_FAST_DELTA;\n\tprivate readonly initialTurnedLeaves: Set<number> = new Set();\n\tprivate readonly onPageChanged?: (pageIndex: number) => void;\n\tprivate readonly onPageFlipping?: (params: PageFlipParams) => void;\n\tprivate readonly onPageFlipped?: (params: PageFlipParams) => void;\n\tprivate readonly historyMapper?: HistoryMapper;\n\tprivate lastFlipParams: PageFlipParams | undefined;\n\tprivate _historyInitialized = false;\n\tprivate _isRestoringFromHistory = false;\n\tprivate _boundPopstate: (() => void) | undefined;\n\tprivate readonly pageSemantics: PageSemantics | undefined;\n\tprivate readonly leavesBuffer?: number;\n\tprivate readonly coverPageIndices?: number[] | \"auto\";\n\tprivate readonly downloadConfig: DownloadConfig | undefined;\n\tprivate readonly pageShadow: boolean;\n\tprivate readonly snapshotDuringFlip: boolean;\n\tprivate leaves: Leaf[] = [];\n\t// flipping state - supports concurrent page flipping\n\tprivate activeFlips: Map<number, FlipState> = new Map();\n\tprivate pendingFlipStartingPos = 0;\n\tprivate pendingFlipDirection: FlipDirection = FlipDirection.None;\n\tprivate isDragging = false;\n\t/** Set after a drag ends; the next click event is suppressed so child buttons/links don't fire. */\n\tprivate _suppressNextClick = false;\n\tprivate hoveredLeaf: Leaf | undefined;\n\ttouchStartingPos = { x: 0, y: 0 };\n\t/** True when the current touch started inside a [data-flipbook-no-flip] element (e.g. carousel). */\n\tprivate touchStartedInNoFlipZone = false;\n\t/**\n\t * Direction lock for the current touch gesture.\n\t * Once the first significant movement (>5 px) determines the dominant axis,\n\t * the lock stays for the rest of the gesture. 'vertical' means native scroll\n\t * wins — Hammer pan events are rejected. 'horizontal' means every touchmove\n\t * gets preventDefault() so Hammer can drive the page flip.\n\t */\n\ttouchDirectionLock: \"none\" | \"vertical\" | \"horizontal\" = \"none\";\n\tprivate static readonly DIRECTION_LOCK_THRESHOLD = 5;\n\tprivate prevVisiblePageIndices: [number] | [number, number] | undefined;\n\t// Hammer instance for cleanup\n\tprivate hammer: HammerManager | undefined;\n\t// Resize observer for re-layout on container size changes\n\tprivate resizeObserver: ResizeObserver | undefined;\n\n\tprivate static readonly NO_FLIP_SELECTOR = \"[data-flipbook-no-flip]\";\n\n\tprivate isInsideNoFlipZone(el: EventTarget | null): boolean {\n\t\treturn el instanceof Element && el.closest(FlipBook.NO_FLIP_SELECTOR) != null;\n\t}\n\n\tprivate getSemanticForPage(pageIndex: number): FlipPageSemantic | undefined {\n\t\tif (!this.pageSemantics) return undefined;\n\t\treturn {\n\t\t\tsemanticName: this.pageSemantics.indexToSemanticName(pageIndex),\n\t\t\ttitle: this.pageSemantics.indexToTitle(pageIndex),\n\t\t};\n\t}\n\n\tprivate buildPageFlipParams(\n\t\tleftmostPageIndex: number,\n\t\tdirection: PageFlipDirection,\n\t): PageFlipParams {\n\t\tconst rightPageIndex = Math.min(leftmostPageIndex + 1, this.pagesCount - 1);\n\t\tconst pageIndices: [number, number] = [leftmostPageIndex, rightPageIndex];\n\t\tconst semantics: [FlipPageSemantic | undefined, FlipPageSemantic | undefined] = [\n\t\t\tthis.getSemanticForPage(leftmostPageIndex),\n\t\t\tthis.getSemanticForPage(rightPageIndex),\n\t\t];\n\t\tconst leafIndex = Math.floor(leftmostPageIndex / 2);\n\t\treturn { leafIndex, pageIndices, semantics, direction };\n\t}\n\n\tprivate syncHistoryAndNotifyFlipped(isInitial: boolean): void {\n\t\tconst pageIndex = this.currentPageIndex;\n\t\tconst semantic = this.getSemanticForPage(pageIndex);\n\t\tif (this.onPageChanged) this.onPageChanged(pageIndex);\n\t\tconst params = this.lastFlipParams ?? this.buildPageFlipParams(pageIndex, \"forward\");\n\t\tif (this.onPageFlipped) this.onPageFlipped(params);\n\t\tif (typeof window !== \"undefined\" && this.historyMapper && !this._isRestoringFromHistory) {\n\t\t\tconst route = this.historyMapper.pageToRoute(pageIndex, semantic);\n\t\t\t// When pageToRoute returns null the consumer signals \"this page has\n\t\t\t// no meaningful URL\" (e.g. cover, TOC). Skip the pushState entirely\n\t\t\t// to avoid framework-level routing side-effects.\n\t\t\tif (route == null) return;\n\t\t\tconst state = { route };\n\t\t\tconst url = route.startsWith(\"#\")\n\t\t\t\t? `${window.location.pathname}${window.location.search}${route}`\n\t\t\t\t: route;\n\t\t\t// Use the *native* History.prototype methods rather than\n\t\t\t// window.history.pushState/replaceState. Frameworks like Next.js\n\t\t\t// monkey-patch the instance methods to intercept URL changes and\n\t\t\t// trigger full soft navigations (RSC fetch + React re-render).\n\t\t\t// That is catastrophically expensive during rapid page flips.\n\t\t\t// Calling the prototype method bypasses the patch while still\n\t\t\t// updating the browser URL bar and history stack correctly.\n\t\t\tif (isInitial || !this._historyInitialized) {\n\t\t\t\tHistory.prototype.replaceState.call(window.history, state, \"\", url);\n\t\t\t\tthis._historyInitialized = true;\n\t\t\t} else {\n\t\t\t\tHistory.prototype.pushState.call(window.history, state, \"\", url);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handlePopstate = (): void => {\n\t\tif (!this.historyMapper || typeof window === \"undefined\") return;\n\t\tconst route =\n\t\t\t(typeof window.history.state === \"object\" && window.history.state?.route) ||\n\t\t\twindow.location.pathname + window.location.search + window.location.hash;\n\t\tconst pageIndex = this.historyMapper.routeToPage(route);\n\t\tif (pageIndex !== null && pageIndex >= 0 && pageIndex < this.pagesCount) {\n\t\t\tthis._isRestoringFromHistory = true;\n\t\t\ttry {\n\t\t\t\tthis.jumpToPage(pageIndex);\n\t\t\t} finally {\n\t\t\t\tthis._isRestoringFromHistory = false;\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate get isLTR(): boolean {\n\t\treturn this.direction === \"ltr\";\n\t}\n\n\tprivate get currentOrTurningLeaves(): [Leaf | undefined, Leaf | undefined] {\n\t\tlet secondLeafIndex = -1;\n\t\tfor (let i = this.leaves.length - 1; i >= 0; i--) {\n\t\t\tconst leaf = this.leaves[i];\n\t\t\tif (leaf.isTurned || leaf.isTurning) {\n\t\t\t\tsecondLeafIndex = leaf.index + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn secondLeafIndex === -1\n\t\t\t? [undefined, this.leaves[0]]\n\t\t\t: secondLeafIndex === this.leaves.length\n\t\t\t\t? [this.leaves[secondLeafIndex - 1], undefined]\n\t\t\t\t: [this.leaves[secondLeafIndex - 1], this.leaves[secondLeafIndex]];\n\t}\n\n\tconstructor(options: FlipBookOptions) {\n\t\tthis.pagesCount = options.pagesCount;\n\t\tthis.leafAspectRatio = options.leafAspectRatio || this.leafAspectRatio;\n\t\tthis.coverAspectRatio = options.coverAspectRatio || this.coverAspectRatio;\n\t\tthis.direction = options.direction || this.direction;\n\t\tthis.fastDeltaThreshold = options.fastDeltaThreshold ?? this.fastDeltaThreshold;\n\t\tthis.initialTurnedLeaves = new Set(options.initialTurnedLeaves ?? []);\n\t\tthis.pageSemantics = options.pageSemantics;\n\t\tthis.onPageChanged = options.onPageChanged;\n\t\tthis.onPageFlipping = options.onPageFlipping;\n\t\tthis.onPageFlipped = options.onPageFlipped;\n\t\tthis.historyMapper = options.enableHistory !== false ? options.historyMapper : undefined;\n\t\tthis.leavesBuffer = options.leavesBuffer;\n\t\tthis.coverPageIndices = options.coverPageIndices;\n\t\tthis.downloadConfig = options.enableDownload !== false ? options.downloadConfig : undefined;\n\t\tthis.pageShadow = options.pageShadow ?? true;\n\t\tthis.snapshotDuringFlip = options.snapshotDuringFlip ?? true;\n\t\tthis._tocPageIndex = options.tocPageIndex ?? 4;\n\t\t// Keep the module-level store in sync for backward-compat\n\t\tsetTocPageIndex(this._tocPageIndex);\n\t}\n\n\tprivate _tocPageIndex = 4;\n\n\t/** Get the configured table of contents page index. */\n\tgetTocPageIndex(): number {\n\t\treturn this._tocPageIndex;\n\t}\n\n\t/** Download config (handlers and filename hints). Used by toolbar. */\n\tgetDownloadConfig(): DownloadConfig | undefined {\n\t\treturn this.downloadConfig;\n\t}\n\n\t/** Build the set of page indices that use cover sizing. */\n\tprivate buildCoverPageIndicesSet(): Set<number> {\n\t\tconst coverPageIndicesSet = new Set<number>();\n\t\tif (this.coverPageIndices) {\n\t\t\tconst indices =\n\t\t\t\tthis.coverPageIndices === \"auto\" ? [0, this.pagesCount - 1] : this.coverPageIndices;\n\t\t\tfor (const pageIdx of indices) {\n\t\t\t\tcoverPageIndicesSet.add(pageIdx);\n\t\t\t}\n\t\t}\n\t\treturn coverPageIndicesSet;\n\t}\n\n\t/**\n\t * Recalculate page sizes from the current container dimensions and\n\t * re-apply width/height/position styles. Called during initial render\n\t * and automatically on container resize (e.g. entering fullscreen).\n\t */\n\tprivate recalculateSizes(): void {\n\t\tif (!this.bookElement || !this.pageElements.length) return;\n\n\t\tconst maxCoverSize = new Size(this.bookElement.clientWidth / 2, this.bookElement.clientHeight);\n\t\tconst coverSize = maxCoverSize.aspectRatioFit(this.coverAspectRatio);\n\t\tconst leafSize = new Size(\n\t\t\t(coverSize.width * this.leafAspectRatio.width) / this.coverAspectRatio.width,\n\t\t\t(coverSize.height * this.leafAspectRatio.height) / this.coverAspectRatio.height,\n\t\t);\n\t\tthis.bookElement.style.perspective = `${Math.min(leafSize.width * 2, leafSize.height) * 2}px`;\n\n\t\tconst containerWidth = this.bookElement.clientWidth;\n\t\tconst containerHeight = this.bookElement.clientHeight;\n\n\t\tfor (const pageElement of this.pageElements) {\n\t\t\tconst isCoverPage = pageElement.dataset.isCoverPage === \"1\";\n\t\t\tconst pageSize = isCoverPage ? coverSize : leafSize;\n\n\t\t\tpageElement.style.width = `${pageSize.width}px`;\n\t\t\tpageElement.style.height = `${pageSize.height}px`;\n\t\t\tpageElement.style[this.isLTR ? \"left\" : \"right\"] =\n\t\t\t\t`${(containerWidth - 2 * pageSize.width) / 2}px`;\n\t\t\tpageElement.style.top = `${(containerHeight - pageSize.height) / 2}px`;\n\t\t}\n\t}\n\n\trender(selector: string, debug = false) {\n\t\tconst bookElement = document.querySelector(selector);\n\t\tif (!bookElement) {\n\t\t\tthrow new Error(`Couldn't find container with selector: ${selector}`);\n\t\t}\n\t\tthis.bookElement = bookElement as HTMLElement;\n\t\tif (!this.bookElement.classList.contains(\"flipbook\")) {\n\t\t\tthis.bookElement.classList.add(\"flipbook\");\n\t\t}\n\t\tif (!this.pageShadow) {\n\t\t\tthis.bookElement.classList.add(\"flipbook--no-page-shadow\");\n\t\t}\n\n\t\tconst pageElements = bookElement.querySelectorAll(\".page\");\n\t\tif (!pageElements.length) {\n\t\t\tthrow new Error(\"No pages found in flipbook\");\n\t\t}\n\t\tthis.pageElements = Array.from(pageElements) as HTMLElement[];\n\t\tthis.leaves.splice(0, this.leaves.length);\n\t\tconst leavesCount = Math.ceil(this.pagesCount / 2);\n\n\t\t// Determine which specific pages are cover exteriors (use coverSize).\n\t\t// Interior sides of cover leaves use leafSize — physically, the endpaper is\n\t\t// glued to the inside of the board and matches the text-block page size.\n\t\tconst coverPageIndicesSet = this.buildCoverPageIndicesSet();\n\n\t\t// Set data attributes before recalculateSizes() so it can read dataset.isCoverPage\n\t\t// to apply the correct cover vs leaf dimensions on the very first layout pass.\n\t\tthis.pageElements.forEach((pageElement, pageIndex) => {\n\t\t\tpageElement.dataset.pageIndex = pageIndex.toString();\n\t\t\tpageElement.dataset.pageSemanticName =\n\t\t\t\tthis.pageSemantics?.indexToSemanticName(pageIndex) ?? \"\";\n\t\t\tpageElement.dataset.pageTitle = this.pageSemantics?.indexToTitle(pageIndex) ?? \"\";\n\t\t\tpageElement.dataset.isCoverPage = coverPageIndicesSet.has(pageIndex) ? \"1\" : \"\";\n\t\t});\n\n\t\t// Compute and apply sizes (also called on resize).\n\t\t// Must run after dataset.isCoverPage is set so covers get coverSize.\n\t\tthis.recalculateSizes();\n\n\t\tthis.pageElements.forEach((pageElement, pageIndex) => {\n\t\t\tconst leafIndex = Math.floor(pageIndex / 2);\n\n\t\t\tconst isOddPage = (pageIndex + 1) % 2 === 1;\n\t\t\tconst isInitiallyTurned = this.initialTurnedLeaves.has(leafIndex);\n\n\t\t\t// Determine current page based on initial turned leaves\n\t\t\t// Current pages are the first two visible pages after all initially turned leaves\n\t\t\tconst firstVisibleLeafIndex =\n\t\t\t\tthis.initialTurnedLeaves.size > 0 ? Math.max(...this.initialTurnedLeaves) + 1 : 0;\n\t\t\tconst isCurrentPage =\n\t\t\t\tleafIndex === firstVisibleLeafIndex ||\n\t\t\t\t(leafIndex === firstVisibleLeafIndex - 1 && isInitiallyTurned);\n\n\t\t\tpageElement.classList.add(\n\t\t\t\tisOddPage ? \"odd\" : \"even\",\n\t\t\t\t...(isCurrentPage ? [\"current-page\"] : []),\n\t\t\t);\n\t\t\tif (isOddPage) {\n\t\t\t\tthis.leaves[leafIndex] = new Leaf(\n\t\t\t\t\tleafIndex,\n\t\t\t\t\t[pageElement, undefined],\n\t\t\t\t\tisInitiallyTurned,\n\t\t\t\t\t{\n\t\t\t\t\t\tisLTR: this.isLTR,\n\t\t\t\t\t\tleavesCount: leavesCount,\n\t\t\t\t\t\tpagesCount: this.pagesCount,\n\t\t\t\t\t\tpageShadow: this.pageShadow,\n\t\t\t\t\t\tsnapshotDuringFlip: this.snapshotDuringFlip,\n\t\t\t\t\t},\n\t\t\t\t\t(direction: FlipDirection) => {\n\t\t\t\t\t\tconst currentVisiblePageIndices: [number] | [number, number] =\n\t\t\t\t\t\t\tdirection === FlipDirection.Forward\n\t\t\t\t\t\t\t\t? pageIndex + 2 === this.pagesCount\n\t\t\t\t\t\t\t\t\t? [pageIndex + 1]\n\t\t\t\t\t\t\t\t\t: [pageIndex + 1, pageIndex + 2]\n\t\t\t\t\t\t\t\t: pageIndex === 0\n\t\t\t\t\t\t\t\t\t? [pageIndex]\n\t\t\t\t\t\t\t\t\t: [pageIndex - 1, pageIndex];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis.prevVisiblePageIndices &&\n\t\t\t\t\t\t\tthis.prevVisiblePageIndices.length === currentVisiblePageIndices.length &&\n\t\t\t\t\t\t\tcurrentVisiblePageIndices.every((v, i) => v === this.prevVisiblePageIndices?.[i])\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst prevVisiblePageIndices = this.prevVisiblePageIndices;\n\t\t\t\t\t\tthis.prevVisiblePageIndices = currentVisiblePageIndices;\n\n\t\t\t\t\t\t// TODO expose to outside using https://github.com/open-draft/strict-event-emitter, and just be a consumer internally\n\t\t\t\t\t\tthis.onTurned(currentVisiblePageIndices, prevVisiblePageIndices);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Even page (back side of leaf) — attach to the leaf created above.\n\t\t\t\tthis.leaves[leafIndex].pages[1] = pageElement;\n\n\t\t\t\t// Both pages of the leaf are now available.\n\t\t\t\t// Use applyTransform to set the correct initial transform — this ensures\n\t\t\t\t// the transforms exactly match what applyTransform produces during flips.\n\t\t\t\t// Previously, hardcoded transforms used rotateY(±180deg) for turned pages,\n\t\t\t\t// which made them invisible due to backface-visibility: hidden.\n\t\t\t\tconst initialPosition = isInitiallyTurned ? 1 : 0;\n\t\t\t\tthis.leaves[leafIndex].applyTransform(initialPosition);\n\t\t\t}\n\t\t});\n\n\t\t// Set initial visible page indices based on initially turned leaves\n\t\tconst firstVisibleLeafIndex =\n\t\t\tthis.initialTurnedLeaves.size > 0 ? Math.max(...this.initialTurnedLeaves) + 1 : 0;\n\t\tconst firstVisiblePageIndex = firstVisibleLeafIndex * 2;\n\n\t\t// Handle edge case where all leaves are turned (showing last page only)\n\t\tif (firstVisiblePageIndex >= this.pagesCount) {\n\t\t\t// All leaves are turned - show the last page(s)\n\t\t\tconst lastLeafIndex = Math.ceil(this.pagesCount / 2) - 1;\n\t\t\tconst lastLeafFirstPage = lastLeafIndex * 2;\n\t\t\tthis.prevVisiblePageIndices =\n\t\t\t\tlastLeafFirstPage + 1 < this.pagesCount\n\t\t\t\t\t? [lastLeafFirstPage, lastLeafFirstPage + 1]\n\t\t\t\t\t: [lastLeafFirstPage];\n\t\t} else {\n\t\t\tthis.prevVisiblePageIndices =\n\t\t\t\tfirstVisiblePageIndex + 1 < this.pagesCount\n\t\t\t\t\t? [firstVisiblePageIndex, firstVisiblePageIndex + 1]\n\t\t\t\t\t: [firstVisiblePageIndex];\n\t\t}\n\n\t\t// Observe container size changes and re-layout automatically.\n\t\tif (typeof ResizeObserver !== \"undefined\") {\n\t\t\tthis.resizeObserver = new ResizeObserver(() => {\n\t\t\t\tthis.recalculateSizes();\n\t\t\t});\n\t\t\tthis.resizeObserver.observe(this.bookElement);\n\t\t}\n\n\t\tthis.hammer = new Hammer(this.bookElement);\n\t\t// Only recognise horizontal pans — vertical touch gestures must\n\t\t// remain native scroll events. Without this, a vertical scroll can\n\t\t// contaminate the pan state (wrong starting X) causing the next\n\t\t// flip to jump to a random position or get stuck.\n\t\tthis.hammer.get(\"pan\").set({ direction: Hammer.DIRECTION_HORIZONTAL });\n\t\tthis.hammer.on(\"panstart\", this.onDragStart.bind(this));\n\t\tthis.hammer.on(\"panmove\", this.onDragUpdate.bind(this));\n\t\tthis.hammer.on(\"panend\", this.onDragEnd.bind(this));\n\t\tthis.bookElement.addEventListener(\"touchstart\", this.handleTouchStart.bind(this), {\n\t\t\tpassive: false,\n\t\t});\n\t\tthis.bookElement.addEventListener(\"touchmove\", this.handleTouchMove.bind(this), {\n\t\t\tpassive: false,\n\t\t});\n\t\tthis.bookElement.addEventListener(\n\t\t\t\"mousemove\",\n\t\t\tthis.handleMouseMove as unknown as EventListener,\n\t\t);\n\t\tthis.bookElement.addEventListener(\"mouseleave\", this.handleMouseLeave as EventListener);\n\t\t// Suppress click events that fire immediately after a drag gesture.\n\t\t// This prevents child interactive elements (buttons, links) from\n\t\t// activating when the user was actually performing a page flip.\n\t\tthis.bookElement.addEventListener(\n\t\t\t\"click\",\n\t\t\tthis.handleClickAfterDrag as EventListener,\n\t\t\ttrue, // capture phase — intercept before the click reaches any child\n\t\t);\n\t\t// Apply initial leaves buffer visibility\n\t\tthis.updateLeavesBufferVisibility();\n\t\tif (debug) this.fillDebugBar();\n\n\t\t// History: initial replaceState and popstate listener\n\t\tif (typeof window !== \"undefined\" && this.historyMapper) {\n\t\t\tthis.syncHistoryAndNotifyFlipped(true);\n\t\t\tthis._boundPopstate = this.handlePopstate.bind(this);\n\t\t\twindow.addEventListener(\"popstate\", this._boundPopstate);\n\t\t}\n\t}\n\n\t/**\n\t * Update visibility of leaves based on the buffer setting.\n\t * Leaves outside the buffer range are hidden for performance.\n\t */\n\tprivate updateLeavesBufferVisibility(): void {\n\t\tif (this.leavesBuffer === undefined) {\n\t\t\treturn; // No buffer - all leaves stay visible\n\t\t}\n\n\t\tconst leavesCount = this.leaves.length;\n\t\tif (leavesCount === 0) return;\n\n\t\t// Find the current leaf index (the first non-turned leaf, or last leaf if all turned)\n\t\tconst [leftLeaf, rightLeaf] = this.currentOrTurningLeaves;\n\t\tconst currentLeafIndex = rightLeaf?.index ?? leftLeaf?.index ?? 0;\n\n\t\t// Calculate buffer range\n\t\tconst bufferStart = Math.max(0, currentLeafIndex - this.leavesBuffer);\n\t\tconst bufferEnd = Math.min(leavesCount - 1, currentLeafIndex + this.leavesBuffer);\n\n\t\t// Cover leaves must always stay visible — they are cover-sized and sit behind\n\t\t// all leaf-sized pages, acting as the physical book boards. Hiding them would\n\t\t// remove the realistic \"frame\" effect.\n\t\tconst coverLeafIndices = new Set<number>();\n\t\tif (this.coverPageIndices) {\n\t\t\tconst indices =\n\t\t\t\tthis.coverPageIndices === \"auto\" ? [0, this.pagesCount - 1] : this.coverPageIndices;\n\t\t\tfor (const pageIdx of indices) {\n\t\t\t\tcoverLeafIndices.add(Math.floor(pageIdx / 2));\n\t\t\t}\n\t\t}\n\n\t\t// Update visibility of all leaves\n\t\tfor (let i = 0; i < leavesCount; i++) {\n\t\t\tconst leaf = this.leaves[i];\n\t\t\tconst isWithinBuffer = i >= bufferStart && i <= bufferEnd;\n\t\t\tconst isCoverLeaf = coverLeafIndices.has(i);\n\n\t\t\t// Cover leaves are always visible; other leaves follow the buffer range.\n\t\t\tconst visible = isCoverLeaf || isWithinBuffer;\n\n\t\t\t// Update both pages of the leaf\n\t\t\tfor (const page of leaf.pages) {\n\t\t\t\tif (page) {\n\t\t\t\t\tpage.style.display = visible ? \"\" : \"none\";\n\t\t\t\t\t// Use content-visibility to skip rendering of off-screen pages.\n\t\t\t\t\t// \"hidden\" is more aggressive than display:none — the browser\n\t\t\t\t\t// also skips layout/paint entirely, reducing memory pressure.\n\t\t\t\t\tpage.style.contentVisibility = visible ? \"visible\" : \"hidden\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate fillDebugBar() {\n\t\tconst debugBar = document.createElement(\"div\");\n\t\tdebugBar.className = \"flipbook-debug-bar flipbook-debug-bar--hidden\";\n\t\tthis.bookElement?.appendChild(debugBar);\n\t\tsetInterval(() => {\n\t\t\t// Populate debug bar with relevant information (throttled to reduce flicker)\n\t\t\tconst activeFlipsInfo = Array.from(this.activeFlips.entries())\n\t\t\t\t.map(([idx, state]) => `${idx}:${state.leaf.flipPosition.toFixed(2)}`)\n\t\t\t\t.join(\", \");\n\t\t\tdebugBar.innerHTML = `\n <div>Direction: ${this.isLTR ? \"LTR\" : \"RTL\"}</div>\n <div>Active Flips: ${this.activeFlips.size} [${activeFlipsInfo}]</div>\n <div>Pending Flip dir: ${this.pendingFlipDirection}</div>\n `;\n\t\t}, 200);\n\t}\n\n\t/**\n\t * Get the current manually-controlled flip state (the one being dragged).\n\t * Returns undefined if no manual flip is in progress.\n\t */\n\tprivate get currentManualFlip(): FlipState | undefined {\n\t\tfor (const state of this.activeFlips.values()) {\n\t\t\tif (!state.isDuringAutoFlip) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Find the next available leaf for flipping in the given direction.\n\t * Excludes leaves that are already being flipped.\n\t */\n\tprivate getNextAvailableLeaf(direction: FlipDirection): Leaf | undefined {\n\t\tif (direction === FlipDirection.Forward) {\n\t\t\t// Find the rightmost leaf that's not already flipping\n\t\t\t// Start from the current right leaf and go forward\n\t\t\tconst [, rightLeaf] = this.currentOrTurningLeaves;\n\t\t\tif (!rightLeaf) return undefined;\n\n\t\t\t// Find a leaf that's not in activeFlips\n\t\t\tfor (let i = rightLeaf.index; i < this.leaves.length; i++) {\n\t\t\t\tconst leaf = this.leaves[i];\n\t\t\t\tif (!this.activeFlips.has(leaf.index) && !leaf.isTurned) {\n\t\t\t\t\treturn leaf;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} else if (direction === FlipDirection.Backward) {\n\t\t\t// Find the leftmost leaf that's not already flipping\n\t\t\tconst [leftLeaf] = this.currentOrTurningLeaves;\n\t\t\tif (!leftLeaf) return undefined;\n\n\t\t\t// Find a leaf that's not in activeFlips\n\t\t\tfor (let i = leftLeaf.index; i >= 0; i--) {\n\t\t\t\tconst leaf = this.leaves[i];\n\t\t\t\tif (!this.activeFlips.has(leaf.index) && (leaf.isTurned || leaf.isTurning)) {\n\t\t\t\t\treturn leaf;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate onDragStart(event: HammerInput) {\n\t\t// Reject pan events that belong to a touch gesture locked to vertical\n\t\t// (i.e. the user is scrolling, not flipping).\n\t\tif (this.touchDirectionLock === \"vertical\") {\n\t\t\treturn;\n\t\t}\n\t\t// Do not start flip when gesture begins inside a no-flip zone (e.g. horizontal carousel)\n\t\tif (this.isInsideNoFlipZone(event.srcEvent?.target ?? null)) {\n\t\t\treturn;\n\t\t}\n\t\t// Allow starting a new flip even if others are in auto-flip mode\n\t\t// Only block if we already have a manual flip in progress\n\t\tif (this.currentManualFlip) {\n\t\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t\t\tthis.pendingFlipStartingPos = 0;\n\t\t\treturn;\n\t\t}\n\t\tthis.isDragging = true;\n\t\tthis.clearHoverShadow();\n\t\tthis.pendingFlipStartingPos = event.center.x;\n\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t}\n\n\tprivate onDragUpdate(event: HammerInput) {\n\t\t// Reject pan events that belong to a touch gesture locked to vertical.\n\t\tif (this.touchDirectionLock === \"vertical\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create the current manual flip state\n\t\tlet flipState = this.currentManualFlip;\n\n\t\tconst currentPos = event.center.x;\n\t\tconst bookWidth = this.bookElement?.clientWidth ?? 0;\n\n\t\t// Calculate delta\n\t\tlet delta = this.isLTR\n\t\t\t? this.pendingFlipStartingPos - currentPos\n\t\t\t: currentPos - this.pendingFlipStartingPos;\n\n\t\tif (Math.abs(delta) > bookWidth) return;\n\t\tif (delta === 0) return;\n\n\t\t// Determine direction on first meaningful movement\n\t\tconst direction =\n\t\t\tthis.pendingFlipDirection !== FlipDirection.None\n\t\t\t\t? this.pendingFlipDirection\n\t\t\t\t: delta > 0\n\t\t\t\t\t? FlipDirection.Forward\n\t\t\t\t\t: FlipDirection.Backward;\n\n\t\t// Lock in direction for this flip\n\t\tif (this.pendingFlipDirection === FlipDirection.None) {\n\t\t\tthis.pendingFlipDirection = direction;\n\t\t}\n\n\t\t// Block starting a new flip in opposite direction while auto-flip is in progress\n\t\t// This prevents visual glitches when swiping backward while a forward flip is animating\n\t\tif (!flipState) {\n\t\t\tfor (const state of this.activeFlips.values()) {\n\t\t\t\tif (state.isDuringAutoFlip && state.direction !== direction) {\n\t\t\t\t\t// There's an auto-flip in the opposite direction - block this new flip\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If we don't have a flip state yet, create one\n\t\tif (!flipState) {\n\t\t\tconst leaf = this.getNextAvailableLeaf(direction);\n\t\t\tif (!leaf) return;\n\n\t\t\t// Acquire the flip lock for the full drag cycle; the matching\n\t\t\t// endFlip() is deferred until the release animation completes\n\t\t\t// in onDragEnd, so the snapshot/scrollbar lockdown stays stable.\n\t\t\tleaf.beginFlip();\n\n\t\t\t// Snap the starting position to the current finger position so\n\t\t\t// the first rendered frame has delta ≈ 0 and the page begins at\n\t\t\t// its resting position (0 for forward, 1 for backward) instead\n\t\t\t// of jumping to an intermediate value.\n\t\t\tthis.pendingFlipStartingPos = currentPos;\n\t\t\tdelta = 0;\n\n\t\t\tflipState = {\n\t\t\t\tleaf,\n\t\t\t\tdirection,\n\t\t\t\tstartingPos: currentPos,\n\t\t\t\tdelta: 0,\n\t\t\t\tisDuringAutoFlip: false,\n\t\t\t};\n\t\t\tthis.activeFlips.set(leaf.index, flipState);\n\t\t}\n\n\t\t// Update delta\n\t\tflipState.delta = delta;\n\n\t\t// Calculate and apply flip position\n\t\tswitch (flipState.direction) {\n\t\t\tcase FlipDirection.Forward: {\n\t\t\t\tconst posForward = (delta / bookWidth) as FlipPosition;\n\t\t\t\tif (posForward > 1 || delta < 0) return;\n\t\t\t\tflipState.leaf.efficientFlipToPosition(posForward);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase FlipDirection.Backward: {\n\t\t\t\tconst posBackward = (1 - Math.abs(delta) / bookWidth) as FlipPosition;\n\t\t\t\tif (posBackward < 0 || delta > 0) return;\n\t\t\t\tflipState.leaf.efficientFlipToPosition(posBackward);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onDragEnd(event: HammerInput) {\n\t\t// Suppress the click that the browser fires after pointerup following a drag.\n\t\tthis._suppressNextClick = true;\n\n\t\tconst flipState = this.currentManualFlip;\n\t\tif (!flipState) {\n\t\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t\t\tthis.pendingFlipStartingPos = 0;\n\t\t\tthis.isDragging = false;\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst ppsX = event.velocityX * 1000; // pixels per second\n\t\tlet flipTo: FlipPosition;\n\n\t\tswitch (flipState.direction) {\n\t\t\tcase FlipDirection.Forward:\n\t\t\t\tif (\n\t\t\t\t\t(this.isLTR ? ppsX < -this.fastDeltaThreshold : ppsX > this.fastDeltaThreshold) ||\n\t\t\t\t\tflipState.leaf.flipPosition >= 0.5\n\t\t\t\t) {\n\t\t\t\t\tflipTo = 1;\n\t\t\t\t} else {\n\t\t\t\t\tflipTo = 0;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase FlipDirection.Backward:\n\t\t\t\tif (\n\t\t\t\t\t(this.isLTR ? ppsX > this.fastDeltaThreshold : ppsX < -this.fastDeltaThreshold) ||\n\t\t\t\t\tflipState.leaf.flipPosition <= 0.5\n\t\t\t\t) {\n\t\t\t\t\tflipTo = 0;\n\t\t\t\t} else {\n\t\t\t\t\tflipTo = 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// Safety: release the drag-level flip lock if direction is unexpected.\n\t\t\t\tflipState.leaf.endFlip();\n\t\t\t\treturn;\n\t\t}\n\n\t\t// Mark as auto-flip and reset pending state\n\t\tflipState.isDuringAutoFlip = true;\n\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t\tthis.pendingFlipStartingPos = 0;\n\t\tthis.isDragging = false;\n\n\t\tconst targetPageIndex =\n\t\t\tflipTo === 1 ? 2 * (flipState.leaf.index + 1) : 2 * flipState.leaf.index;\n\t\tconst direction: PageFlipDirection = flipTo === 1 ? \"forward\" : \"backward\";\n\t\tthis.lastFlipParams = this.buildPageFlipParams(targetPageIndex, direction);\n\t\tif (this.onPageFlipping) this.onPageFlipping(this.lastFlipParams);\n\n\t\t// Complete the flip asynchronously - don't block new flips!\n\t\tflipState.leaf.flipToPosition(flipTo).then(() => {\n\t\t\t// Release the drag-level flip lock acquired in onDragUpdate.\n\t\t\t// The animation's own beginFlip/endFlip is ref-counted inside, so\n\t\t\t// the snapshot stays active until this final endFlip() zeroes it.\n\t\t\tflipState.leaf.endFlip();\n\t\t\tthis.activeFlips.delete(flipState.leaf.index);\n\t\t});\n\t}\n\n\tprivate handleTouchStart = (e: TouchEvent) => {\n\t\tif (e.touches.length > 1) {\n\t\t\treturn;\n\t\t}\n\t\tconst touch = e.touches[0];\n\t\tthis.touchStartingPos = { x: touch.pageX, y: touch.pageY };\n\t\tthis.touchStartedInNoFlipZone = this.isInsideNoFlipZone(e.target);\n\t\tthis.touchDirectionLock = \"none\";\n\t};\n\n\tprivate handleTouchMove = (e: TouchEvent) => {\n\t\tif (e.touches.length > 1) {\n\t\t\treturn;\n\t\t}\n\t\t// Allow horizontal scroll (e.g. carousel) when touch started inside a no-flip zone\n\t\tif (this.touchStartedInNoFlipZone) {\n\t\t\treturn;\n\t\t}\n\t\tconst touch = e.touches[0];\n\t\tconst deltaX = touch.pageX - this.touchStartingPos.x;\n\t\tconst deltaY = touch.pageY - this.touchStartingPos.y;\n\n\t\t// Lock direction on the first significant movement. Once locked the\n\t\t// decision is final for the rest of this gesture — prevents the old\n\t\t// bug where accumulated vertical delta kept overruling a late\n\t\t// horizontal change-of-direction within the same gesture.\n\t\tif (this.touchDirectionLock === \"none\") {\n\t\t\tconst absDx = Math.abs(deltaX);\n\t\t\tconst absDy = Math.abs(deltaY);\n\t\t\tif (absDx > FlipBook.DIRECTION_LOCK_THRESHOLD || absDy > FlipBook.DIRECTION_LOCK_THRESHOLD) {\n\t\t\t\tthis.touchDirectionLock = absDx >= absDy ? \"horizontal\" : \"vertical\";\n\t\t\t}\n\t\t}\n\n\t\tif (this.touchDirectionLock === \"horizontal\") {\n\t\t\te.preventDefault();\n\t\t}\n\t\t// 'vertical' or 'none' → let the browser handle native scroll\n\t};\n\n\tprivate handleMouseMove = throttle(MOUSE_MOVE_THROTTLE_MS, (event: MouseEvent) => {\n\t\tif (!this.bookElement) return;\n\t\tif (this.isDragging || this.currentManualFlip || this.activeFlips.size > 0) {\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst rect = this.bookElement.getBoundingClientRect();\n\t\tif (rect.width <= 0) return;\n\n\t\tconst x = event.clientX - rect.left;\n\t\tconst edgeZone = rect.width * EDGE_ZONE_RATIO;\n\t\tconst isLeftEdge = x <= edgeZone;\n\t\tconst isRightEdge = x >= rect.width - edgeZone;\n\n\t\tif (!isLeftEdge && !isRightEdge) {\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isForward = this.isLTR ? isRightEdge : isLeftEdge;\n\t\tconst direction = isForward ? FlipDirection.Forward : FlipDirection.Backward;\n\t\tconst leaf = this.getNextAvailableLeaf(direction);\n\t\tif (!leaf) {\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst distanceFromEdge = isForward\n\t\t\t? this.isLTR\n\t\t\t\t? rect.width - x\n\t\t\t\t: x\n\t\t\t: this.isLTR\n\t\t\t\t? x\n\t\t\t\t: rect.width - x;\n\t\tconst edgeProgress = 1 - Math.min(1, distanceFromEdge / edgeZone);\n\t\tconst hoverStrength = edgeProgress * HOVER_STRENGTH_MAX;\n\n\t\tif (this.hoveredLeaf && this.hoveredLeaf !== leaf) {\n\t\t\tthis.hoveredLeaf.setHoverShadow(0);\n\t\t}\n\t\tthis.hoveredLeaf = leaf;\n\t\tleaf.setHoverShadow(hoverStrength);\n\t});\n\n\tprivate handleMouseLeave = () => {\n\t\tthis.clearHoverShadow();\n\t};\n\n\t/**\n\t * Capture-phase click handler that suppresses clicks fired by the browser\n\t * immediately after a drag gesture ends. Without this, releasing the pointer\n\t * on an interactive element (button, link) inside a page would trigger both\n\t * the flip animation AND the element's click handler.\n\t */\n\tprivate handleClickAfterDrag = (e: Event) => {\n\t\tif (this._suppressNextClick) {\n\t\t\tthis._suppressNextClick = false;\n\t\t\te.stopPropagation();\n\t\t\te.preventDefault();\n\t\t}\n\t};\n\n\tprivate clearHoverShadow() {\n\t\tif (this.hoveredLeaf) {\n\t\t\tthis.hoveredLeaf.setHoverShadow(0);\n\t\t\tthis.hoveredLeaf = undefined;\n\t\t}\n\t}\n\tprivate onTurned(\n\t\tcurrentVisiblePageIndices: [number] | [number, number],\n\t\tprevVisibilePageIndices?: [number] | [number, number],\n\t) {\n\t\tfor (let i = 0; i < this.pageElements.length; i++) {\n\t\t\tconst pageElement = this.pageElements[i];\n\t\t\tconst inCurrent = currentVisiblePageIndices.includes(i);\n\t\t\tconst inPrev = prevVisibilePageIndices?.includes(i);\n\t\t\tconst action = inCurrent\n\t\t\t\t? pageElement.classList.add\n\t\t\t\t: !prevVisibilePageIndices || !inPrev\n\t\t\t\t\t? () => null\n\t\t\t\t\t: pageElement.classList.remove;\n\t\t\taction.bind(pageElement.classList)(\"current-page\");\n\t\t}\n\t\t// Update leaves buffer visibility after turn completes\n\t\tthis.updateLeavesBufferVisibility();\n\t\t// Notify React/consumer and sync history\n\t\tthis.syncHistoryAndNotifyFlipped(false);\n\t\t// TODO expose to outside using https://github.com/open-draft/strict-event-emitter, and just be a consumer internally.\n\t\t// TODO: set prev-page / next-page classes for prev/next pages as accordingally\n\t}\n\t/**\n\t * Get the index of the current (leftmost visible) page.\n\t * Returns 0 if no pages are visible.\n\t */\n\tget currentPageIndex(): number {\n\t\treturn this.prevVisiblePageIndices?.[0] ?? 0;\n\t}\n\n\t/**\n\t * Get the total number of pages in the flipbook.\n\t */\n\tget totalPages(): number {\n\t\treturn this.pagesCount;\n\t}\n\n\t/**\n\t * Check if the book is currently showing the first page(s).\n\t */\n\tget isFirstPage(): boolean {\n\t\treturn this.currentPageIndex === 0;\n\t}\n\n\t/**\n\t * Check if the book is currently showing the last page(s).\n\t */\n\tget isLastPage(): boolean {\n\t\tconst lastPageIndex = this.pagesCount - 1;\n\t\treturn this.prevVisiblePageIndices?.includes(lastPageIndex) ?? false;\n\t}\n\n\t/**\n\t * Check if there's an active auto-flip in the given direction.\n\t */\n\tprivate hasActiveAutoFlipInDirection(direction: FlipDirection): boolean {\n\t\tfor (const state of this.activeFlips.values()) {\n\t\t\tif (state.isDuringAutoFlip && state.direction === direction) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Animate flip to the next page.\n\t * @returns Promise that resolves when the flip animation completes\n\t */\n\tasync flipNext(): Promise<void> {\n\t\t// Block if there's an active auto-flip in the opposite direction\n\t\tif (this.hasActiveAutoFlipInDirection(FlipDirection.Backward)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst leaf = this.getNextAvailableLeaf(FlipDirection.Forward);\n\t\tif (!leaf) return;\n\n\t\tconst flipState: FlipState = {\n\t\t\tleaf,\n\t\t\tdirection: FlipDirection.Forward,\n\t\t\tstartingPos: 0,\n\t\t\tdelta: 0,\n\t\t\tisDuringAutoFlip: true,\n\t\t};\n\t\tthis.activeFlips.set(leaf.index, flipState);\n\t\tconst targetPageIndex = this.currentPageIndex + 2;\n\t\tthis.lastFlipParams = this.buildPageFlipParams(targetPageIndex, \"forward\");\n\t\tif (this.onPageFlipping) this.onPageFlipping(this.lastFlipParams);\n\n\t\ttry {\n\t\t\tawait leaf.flipToPosition(1);\n\t\t} finally {\n\t\t\tthis.activeFlips.delete(leaf.index);\n\t\t}\n\t}\n\n\t/**\n\t * Animate flip to the previous page.\n\t * @returns Promise that resolves when the flip animation completes\n\t */\n\tasync flipPrev(): Promise<void> {\n\t\t// Block if there's an active auto-flip in the opposite direction\n\t\tif (this.hasActiveAutoFlipInDirection(FlipDirection.Forward)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst leaf = this.getNextAvailableLeaf(FlipDirection.Backward);\n\t\tif (!leaf) return;\n\n\t\tconst flipState: FlipState = {\n\t\t\tleaf,\n\t\t\tdirection: FlipDirection.Backward,\n\t\t\tstartingPos: 0,\n\t\t\tdelta: 0,\n\t\t\tisDuringAutoFlip: true,\n\t\t};\n\t\tthis.activeFlips.set(leaf.index, flipState);\n\t\tconst targetPageIndex = this.currentPageIndex - 2;\n\t\tthis.lastFlipParams = this.buildPageFlipParams(Math.max(0, targetPageIndex), \"backward\");\n\t\tif (this.onPageFlipping) this.onPageFlipping(this.lastFlipParams);\n\n\t\ttry {\n\t\t\tawait leaf.flipToPosition(0);\n\t\t} finally {\n\t\t\tthis.activeFlips.delete(leaf.index);\n\t\t}\n\t}\n\n\t/**\n\t * Animate to a specific page index.\n\t * Flips through pages sequentially to reach the target.\n\t * @param pageIndex - The target page index (0-based)\n\t * @returns Promise that resolves when all flip animations complete\n\t */\n\tasync flipToPage(pageIndex: number): Promise<void> {\n\t\tif (pageIndex < 0 || pageIndex >= this.pagesCount) {\n\t\t\tconsole.warn(\n\t\t\t\t`flipToPage: Invalid page index ${pageIndex}. Must be between 0 and ${this.pagesCount - 1}.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst targetLeafIndex = Math.floor(pageIndex / 2);\n\t\tconst currentLeafIndex = Math.floor(this.currentPageIndex / 2);\n\n\t\tif (targetLeafIndex === currentLeafIndex) {\n\t\t\treturn; // Already at the target page\n\t\t}\n\n\t\tif (targetLeafIndex > currentLeafIndex) {\n\t\t\t// Flip forward\n\t\t\tfor (let i = currentLeafIndex; i < targetLeafIndex; i++) {\n\t\t\t\tawait this.flipNext();\n\t\t\t}\n\t\t} else {\n\t\t\t// Flip backward\n\t\t\tfor (let i = currentLeafIndex; i > targetLeafIndex; i--) {\n\t\t\t\tawait this.flipPrev();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Jump to a specific page instantly without animation.\n\t * @param pageIndex - The target page index (0-based)\n\t */\n\tjumpToPage(pageIndex: number): void {\n\t\tif (pageIndex < 0 || pageIndex >= this.pagesCount) {\n\t\t\tconsole.warn(\n\t\t\t\t`jumpToPage: Invalid page index ${pageIndex}. Must be between 0 and ${this.pagesCount - 1}.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst isLastPage = pageIndex === this.pagesCount - 1;\n\t\tconst isOddPage = pageIndex % 2 === 1;\n\t\t// If targeting the last page and it's odd (back of leaf), close the book reversed\n\t\tconst closeBookReversed = isLastPage && isOddPage;\n\n\t\t// Determine which leaf should be the last one turned.\n\t\t// A leaf's pages are visible as follows:\n\t\t// - At position 0 (not turned): its even page (front) is visible\n\t\t// - At position 1 (turned): its odd page (back) is visible\n\t\t// The visible spread after turning leaf k is [2k+1, 2k+2]:\n\t\t// back of leaf k (odd) + front of leaf k+1 (even).\n\t\t// For page 0, no leaves need to be turned (initial spread [0, 1]).\n\t\tlet lastTurnedLeafIndex: number;\n\t\tif (pageIndex <= 0) {\n\t\t\tlastTurnedLeafIndex = -1; // No leaves turned\n\t\t} else if (closeBookReversed) {\n\t\t\tlastTurnedLeafIndex = this.leaves.length - 1; // All leaves turned\n\t\t} else {\n\t\t\tlastTurnedLeafIndex = Math.floor((pageIndex - 1) / 2);\n\t\t}\n\n\t\t// Set all leaves up to lastTurnedLeafIndex as turned, all after as not turned\n\t\tfor (let i = 0; i < this.leaves.length; i++) {\n\t\t\tconst leaf = this.leaves[i];\n\t\t\tconst shouldBeTurned = i <= lastTurnedLeafIndex;\n\n\t\t\tif (shouldBeTurned && !leaf.isTurned) {\n\t\t\t\t// Turn this leaf instantly\n\t\t\t\tleaf.flipPosition = 1;\n\t\t\t\tthis.applyLeafTransform(leaf, 1);\n\t\t\t} else if (!shouldBeTurned && leaf.isTurned) {\n\t\t\t\t// Unturn this leaf instantly\n\t\t\t\tleaf.flipPosition = 0;\n\t\t\t\tthis.applyLeafTransform(leaf, 0);\n\t\t\t}\n\t\t}\n\n\t\t// Update visible page indices\n\t\tif (closeBookReversed) {\n\t\t\t// Closed reversed: only show the last page\n\t\t\tthis.prevVisiblePageIndices = [pageIndex];\n\t\t} else if (lastTurnedLeafIndex < 0) {\n\t\t\t// No leaves turned: initial spread\n\t\t\tthis.prevVisiblePageIndices = 1 < this.pagesCount ? [0, 1] : [0];\n\t\t} else {\n\t\t\tconst firstVisiblePageIndex = lastTurnedLeafIndex * 2 + 1;\n\t\t\tthis.prevVisiblePageIndices =\n\t\t\t\tfirstVisiblePageIndex + 1 < this.pagesCount\n\t\t\t\t\t? [firstVisiblePageIndex, firstVisiblePageIndex + 1]\n\t\t\t\t\t: [firstVisiblePageIndex];\n\t\t}\n\n\t\t// Update current-page classes\n\t\tfor (let i = 0; i < this.pageElements.length; i++) {\n\t\t\tconst pageElement = this.pageElements[i];\n\t\t\tif (this.prevVisiblePageIndices.includes(i)) {\n\t\t\t\tpageElement.classList.add(\"current-page\");\n\t\t\t} else {\n\t\t\t\tpageElement.classList.remove(\"current-page\");\n\t\t\t}\n\t\t}\n\n\t\t// Update leaves buffer visibility\n\t\tthis.updateLeavesBufferVisibility();\n\n\t\t// Notify callback and sync history\n\t\tthis.syncHistoryAndNotifyFlipped(false);\n\t}\n\n\t/**\n\t * Apply transform styles to a leaf's pages for a given flip position.\n\t * Used for instant positioning (jumpToPage).\n\t */\n\tprivate applyLeafTransform(leaf: Leaf, position: number): void {\n\t\tleaf.applyTransform(position);\n\t}\n\n\t/**\n\t * Clean up event listeners and Hammer instance.\n\t * Should be called when the FlipBook is no longer needed.\n\t */\n\tdestroy() {\n\t\tif (typeof window !== \"undefined\" && this._boundPopstate) {\n\t\t\twindow.removeEventListener(\"popstate\", this._boundPopstate);\n\t\t\tthis._boundPopstate = undefined;\n\t\t}\n\t\tif (this.resizeObserver) {\n\t\t\tthis.resizeObserver.disconnect();\n\t\t\tthis.resizeObserver = undefined;\n\t\t}\n\t\tif (this.hammer) {\n\t\t\tthis.hammer.destroy();\n\t\t\tthis.hammer = undefined;\n\t\t}\n\t\tif (this.bookElement) {\n\t\t\tthis.bookElement.removeEventListener(\"touchstart\", this.handleTouchStart as EventListener);\n\t\t\tthis.bookElement.removeEventListener(\"touchmove\", this.handleTouchMove as EventListener);\n\t\t\tthis.bookElement.removeEventListener(\n\t\t\t\t\"mousemove\",\n\t\t\t\tthis.handleMouseMove as unknown as EventListener,\n\t\t\t);\n\t\t\tthis.bookElement.removeEventListener(\"mouseleave\", this.handleMouseLeave as EventListener);\n\t\t\tthis.bookElement.removeEventListener(\n\t\t\t\t\"click\",\n\t\t\t\tthis.handleClickAfterDrag as EventListener,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport { FlipBook, type PageSemantics };\nexport type {\n\tFlipPageSemantic,\n\tHistoryMapper,\n\tPageFlipDirection,\n\tPageFlipParams,\n} from \"./flip-book-options\";\n"],"names":["FlipDirection","scheduleFrame","cb","SHADOW_STRENGTH_MULTIPLIER","HIGHLIGHT_STRENGTH_MULTIPLIER","Leaf","index","pages","isFlipped","bookProperties","onTurned","value","progress","clamped","page","flipPosition","velocity","resolve","currentFlipPosition","duration","start","step","timestamp","elapsed","newPosition","throttle","position","clampedPosition","pageShadow","shadowStrength","highlightStrength","shadowFromFlip","shadowProgress","isLTR","isOdd","rotateY","translateX","scaleX","origin","edge","AspectRatioImpl","width","height","aspectRatio","Size","rhsAspectRatio","rhsAspectRatioValue","DEFAULT_FAST_DELTA","EDGE_ZONE_RATIO","HOVER_STRENGTH_MAX","MOUSE_MOVE_THROTTLE_MS","FlipBook","el","pageIndex","leftmostPageIndex","direction","rightPageIndex","pageIndices","semantics","isInitial","semantic","params","route","state","url","secondLeafIndex","i","leaf","options","setTocPageIndex","coverPageIndicesSet","indices","pageIdx","coverSize","leafSize","containerWidth","containerHeight","pageElement","pageSize","selector","debug","bookElement","pageElements","leavesCount","leafIndex","isOddPage","isInitiallyTurned","firstVisibleLeafIndex","isCurrentPage","currentVisiblePageIndices","v","prevVisiblePageIndices","initialPosition","firstVisiblePageIndex","lastLeafFirstPage","Hammer","leftLeaf","rightLeaf","currentLeafIndex","bufferStart","bufferEnd","coverLeafIndices","isWithinBuffer","visible","debugBar","activeFlipsInfo","idx","event","flipState","currentPos","bookWidth","delta","posForward","posBackward","ppsX","flipTo","targetPageIndex","touch","deltaX","deltaY","absDx","absDy","rect","x","edgeZone","isLeftEdge","isRightEdge","isForward","distanceFromEdge","hoverStrength","prevVisibilePageIndices","inCurrent","inPrev","lastPageIndex","targetLeafIndex","isLastPage","closeBookReversed","lastTurnedLeafIndex","shouldBeTurned"],"mappings":";;;AAAO,IAAKA,sBAAAA,OACXA,EAAA,UAAU,WACVA,EAAA,WAAW,YACXA,EAAA,OAAO,QAHIA,IAAAA,KAAA,CAAA,CAAA;ACKZ,SAASC,EAAcC,GAAyC;AAC/D,SAAO,OAAO,wBAA0B,MACrC,sBAAsBA,CAAE,IACvB,WAAW,MAAMA,EAAG,YAAY,IAAA,CAAK,GAAG,CAAC;AAC9C;AAGA,MAAMC,IAA6B,KAE7BC,IAAgC;AAO/B,MAAMC,EAAK;AAAA,EAQjB,YACUC,GACAC,GACTC,GACiBC,GAOAC,GAChB;AAXQ,SAAA,QAAAJ,GACA,KAAA,QAAAC,GAEQ,KAAA,iBAAAE,GAOA,KAAA,WAAAC,GAEjB,KAAK,sBAAsBF,IAAY,IAAI;AAAA,EAK5C;AAAA,EAzBQ,mBAAyC;AAAA,EACzC,qBAA0C;AAAA,EAC1C;AAAA,EACA,cAAc;AAAA;AAAA,EAEd,eAAe;AAAA,EAsB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S,SAEX,KAAK,gBACR,KAAK,YAAY,oBAAoB,cAAc,KAAK,gBAAiC,GACzF,KAAK,YAAY,oBAAoB,aAAa,KAAK,eAAgC,GACvF,KAAK,YAAY;AAAA,MAChB;AAAA,MACA,KAAK;AAAA,IAAA,GAEN,KAAK,YAAY,oBAAoB,cAAc,KAAK,gBAAiC,GACzF,KAAK,YAAY;AAAA,MAChB;AAAA,MACA,KAAK;AAAA,MACL;AAAA,IAAA;AAAA,EAGH;AACD;"}
|
|
1
|
+
{"version":3,"file":"flipbook.js","sources":["../src/flip-direction.ts","../src/leaf.ts","../src/aspect-ratio.ts","../src/size.ts","../src/flipbook.ts"],"sourcesContent":["export enum FlipDirection {\n\tForward = \"Forward\",\n\tBackward = \"Backward\",\n\tNone = \"None\",\n}\n","import { throttle } from \"throttle-debounce\";\nimport type { IntRange } from \"type-fest\";\nimport { FlipDirection } from \"./flip-direction\";\n\n/** Schedule a frame callback; fallback for test envs where requestAnimationFrame is missing. Called at invoke time so test mocks apply. */\nfunction scheduleFrame(cb: (timestamp: number) => void): number {\n\treturn typeof requestAnimationFrame !== \"undefined\"\n\t\t? requestAnimationFrame(cb)\n\t\t: (setTimeout(() => cb(performance.now()), 0) as unknown as number);\n}\n\n/** Multiplier for shadow intensity (slightly stronger than base) */\nconst SHADOW_STRENGTH_MULTIPLIER = 1.1;\n/** Multiplier for highlight intensity (slightly weaker than base) */\nconst HIGHLIGHT_STRENGTH_MULTIPLIER = 0.9;\n\n// number between 1 to infinity\nexport type DegreesPerSecond = IntRange<1, typeof Infinity>;\nexport type FlipPosition = IntRange<0, 2>;\nexport const FLIPPED = true;\nexport const NOT_FLIPPED = false;\nexport class Leaf {\n\tprivate currentAnimation: Promise<void> | null = null;\n\tprivate targetFlipPosition: FlipPosition | null = null;\n\tprivate wrappedFlipPosition: number;\n\tprivate hoverShadow = 0;\n\t/** Ref-count for nested beginFlip/endFlip pairs (drag wrapping animation). */\n\tprivate flipRefCount = 0;\n\n\tconstructor(\n\t\treadonly index: number,\n\t\treadonly pages: [HTMLElement, HTMLElement | undefined],\n\t\tisFlipped: boolean,\n\t\tprivate readonly bookProperties: {\n\t\t\tisLTR: boolean;\n\t\t\tpagesCount: number;\n\t\t\tleavesCount: number;\n\t\t\tpageShadow: boolean;\n\t\t\tsnapshotDuringFlip: boolean;\n\t\t},\n\t\tprivate readonly onTurned: (direction: FlipDirection) => void,\n\t) {\n\t\tthis.wrappedFlipPosition = isFlipped ? 1 : 0;\n\t\t// TODO: rethink this\n\t\t// if(isFlipped) {\n\t\t// // this.flipToPosition(1);\n\t\t// }\n\t}\n\n\tget isTurned(): boolean {\n\t\treturn this.flipPosition === 1;\n\t}\n\tget isTurning(): boolean {\n\t\treturn this.flipPosition !== 0;\n\t}\n\tget isCover(): boolean {\n\t\treturn this.isFirst || this.isLast;\n\t}\n\tget isFirst(): boolean {\n\t\treturn this.index === 0;\n\t}\n\tget isLast(): boolean {\n\t\treturn this.index === this.bookProperties.leavesCount - 1;\n\t}\n\tset flipPosition(value: number) {\n\t\tthis.wrappedFlipPosition = Math.max(0, Math.min(1, value)) as FlipPosition;\n\t}\n\tget flipPosition(): number {\n\t\treturn this.wrappedFlipPosition;\n\t}\n\n\tsetHoverShadow(progress: number): void {\n\t\tconst clamped = Math.max(0, Math.min(1, progress));\n\t\tif (this.hoverShadow === clamped) return;\n\t\tthis.hoverShadow = clamped;\n\t\tthis.applyTransform(this.flipPosition);\n\t}\n\n\t/**\n\t * Signal that a flip interaction is starting (drag or animation).\n\t * Ref-counted: the snapshot class is added on the first call and\n\t * removed only when every `beginFlip` has a matching `endFlip`.\n\t * This keeps the GPU layer and scrollbar/selection lockdown stable\n\t * across the full drag→release→animation cycle.\n\t */\n\tbeginFlip(): void {\n\t\tthis.flipRefCount++;\n\t\tif (this.flipRefCount !== 1) return; // already promoted\n\t\tfor (const page of this.pages) {\n\t\t\tif (!page) continue;\n\t\t\tpage.style.willChange = \"transform\";\n\t\t\tif (this.bookProperties.snapshotDuringFlip) {\n\t\t\t\tpage.classList.add(\"page--flipping\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Signal that a flip interaction finished (drag or animation).\n\t * Only releases the GPU layer when every `beginFlip` is balanced.\n\t */\n\tendFlip(): void {\n\t\tthis.flipRefCount = Math.max(0, this.flipRefCount - 1);\n\t\tif (this.flipRefCount !== 0) return; // still active\n\t\tfor (const page of this.pages) {\n\t\t\tif (!page) continue;\n\t\t\tpage.style.willChange = \"\";\n\t\t\tif (this.bookProperties.snapshotDuringFlip) {\n\t\t\t\tpage.classList.remove(\"page--flipping\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync flipToPosition(\n\t\tflipPosition: FlipPosition,\n\t\tvelocity: DegreesPerSecond = 225 as DegreesPerSecond,\n\t) {\n\t\tif (this.currentAnimation) {\n\t\t\tawait this.currentAnimation;\n\t\t}\n\n\t\tif (this.flipPosition === flipPosition) {\n\t\t\treturn Promise.resolve();\n\t\t}\n\n\t\tif (this.targetFlipPosition === flipPosition) {\n\t\t\treturn this.currentAnimation ?? Promise.resolve();\n\t\t}\n\n\t\tthis.targetFlipPosition = flipPosition;\n\t\t// Promote to GPU layer before animation starts for smooth compositing\n\t\tthis.beginFlip();\n\n\t\tthis.currentAnimation = new Promise<void>((resolve) => {\n\t\t\tconst currentFlipPosition = this.flipPosition;\n\t\t\tconst distance = Math.abs(flipPosition - currentFlipPosition);\n\t\t\tconst duration = ((distance * 180) / velocity) * 1000; // duration in milliseconds\n\n\t\t\tconst start = performance.now();\n\t\t\tconst step = (timestamp: number) => {\n\t\t\t\tconst elapsed = timestamp - start;\n\n\t\t\t\tif (elapsed < 0) {\n\t\t\t\t\tscheduleFrame(step);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst progress = Math.min(elapsed / duration, 1);\n\t\t\t\tconst newPosition = currentFlipPosition + progress * (flipPosition - currentFlipPosition);\n\n\t\t\t\tthis.applyTransform(newPosition);\n\n\t\t\t\t// Ensure the new position is within valid bounds [0, 1]\n\t\t\t\tthis.flipPosition = Math.max(0, Math.min(1, newPosition)) as FlipPosition;\n\t\t\t\tif (this.flipPosition === 1 || this.flipPosition === 0) {\n\t\t\t\t\tthis.onTurned(this.flipPosition === 1 ? FlipDirection.Forward : FlipDirection.Backward);\n\t\t\t\t}\n\n\t\t\t\tif (progress < 1) {\n\t\t\t\t\tscheduleFrame(step);\n\t\t\t\t} else {\n\t\t\t\t\tthis.currentAnimation = null;\n\t\t\t\t\tthis.targetFlipPosition = null;\n\t\t\t\t\t// Release GPU layer after animation completes\n\t\t\t\t\tthis.endFlip();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tscheduleFrame(step);\n\t\t});\n\n\t\treturn this.currentAnimation;\n\t}\n\n\tasync efficientFlipToPosition(\n\t\tflipPosition: FlipPosition,\n\t\tvelocity: DegreesPerSecond = 20000 as DegreesPerSecond,\n\t) {\n\t\treturn throttle(1, this.flipToPosition.bind(this))(flipPosition, velocity);\n\t}\n\n\tapplyTransform(position: number): void {\n\t\tconst clampedPosition = Math.max(0, Math.min(1, position));\n\t\tconst { pageShadow } = this.bookProperties;\n\n\t\t// Only compute shadow values when shadow is enabled — skipping these\n\t\t// saves CSS custom-property mutations per page per animation frame.\n\t\tlet shadowStrength = 0;\n\t\tlet highlightStrength = 0;\n\t\tif (pageShadow) {\n\t\t\tconst shadowFromFlip = Math.sin(clampedPosition * Math.PI);\n\t\t\tconst shadowProgress = Math.max(shadowFromFlip, this.hoverShadow);\n\t\t\tshadowStrength = Math.min(1, shadowProgress * SHADOW_STRENGTH_MULTIPLIER);\n\t\t\thighlightStrength = Math.min(1, shadowProgress * HIGHLIGHT_STRENGTH_MULTIPLIER);\n\t\t}\n\n\t\tthis.pages.forEach((page, index) => {\n\t\t\tconst isLTR = this.bookProperties.isLTR;\n\t\t\tif (!page) return;\n\n\t\t\tconst isOdd = (index % 2) + 1 === 1;\n\t\t\tconst degrees = isOdd\n\t\t\t\t? isLTR\n\t\t\t\t\t? clampedPosition > 0.5\n\t\t\t\t\t\t? 180 - clampedPosition * 180\n\t\t\t\t\t\t: -clampedPosition * 180\n\t\t\t\t\t: clampedPosition > 0.5\n\t\t\t\t\t\t? -(180 - clampedPosition * 180)\n\t\t\t\t\t\t: clampedPosition * 180\n\t\t\t\t: isLTR\n\t\t\t\t\t? clampedPosition < 0.5\n\t\t\t\t\t\t? -clampedPosition * 180\n\t\t\t\t\t\t: 180 - clampedPosition * 180\n\t\t\t\t\t: clampedPosition < 0.5\n\t\t\t\t\t\t? clampedPosition * 180\n\t\t\t\t\t\t: -(180 - clampedPosition * 180);\n\t\t\tconst rotateY = `${degrees}deg`;\n\t\t\tconst translateX = `${isOdd ? (isLTR ? \"100%\" : \"-100%\") : \"0px\"}`;\n\t\t\tconst scaleX = isOdd ? (clampedPosition > 0.5 ? -1 : 1) : clampedPosition < 0.5 ? -1 : 1;\n\t\t\tconst origin = isOdd ? (isLTR ? \"left\" : \"right\") : isLTR ? \"right\" : \"left\";\n\n\t\t\tpage.style.transform = `translateX(${translateX})rotateY(${rotateY})scaleX(${scaleX})`;\n\t\t\tpage.style.transformOrigin = origin;\n\t\t\tpage.style.zIndex = `${\n\t\t\t\tclampedPosition > 0.5\n\t\t\t\t\t? page.dataset.pageIndex\n\t\t\t\t\t: this.bookProperties.pagesCount - (page.dataset.pageIndex as unknown as number)\n\t\t\t}`;\n\n\t\t\tif (pageShadow) {\n\t\t\t\tconst edge = origin === \"left\" ? \"right\" : \"left\";\n\t\t\t\tpage.style.setProperty(\"--inner-shadow-shadow\", shadowStrength.toFixed(3));\n\t\t\t\tpage.style.setProperty(\"--inner-shadow-highlight\", highlightStrength.toFixed(3));\n\t\t\t\tpage.style.setProperty(\"--inner-shadow-edge\", edge);\n\t\t\t}\n\t\t});\n\t}\n}\n","export interface AspectRatio {\n\twidth: number;\n\theight: number;\n}\nexport class AspectRatioImpl implements AspectRatio {\n\tstatic from(aspectRatio: AspectRatio) {\n\t\treturn new AspectRatioImpl(aspectRatio.width, aspectRatio.height);\n\t}\n\tconstructor(\n\t\tpublic readonly width: number,\n\t\tpublic readonly height: number,\n\t) {}\n\tget value(): number {\n\t\treturn this.width / this.height;\n\t}\n}\n","import { type AspectRatio, AspectRatioImpl } from \"./aspect-ratio\";\n\nexport class Size {\n\taspectRatio: AspectRatioImpl;\n\taspectRatioFit(rhsAspectRatio: AspectRatio) {\n\t\tconst rhsAspectRatioValue = AspectRatioImpl.from(rhsAspectRatio).value;\n\t\treturn this.aspectRatio.value > rhsAspectRatioValue\n\t\t\t? new Size(this.height * rhsAspectRatioValue, this.height)\n\t\t\t: new Size(this.width, this.width / rhsAspectRatioValue);\n\t}\n\tconstructor(\n\t\tpublic readonly width: number,\n\t\tpublic readonly height: number,\n\t) {\n\t\tthis.aspectRatio = new AspectRatioImpl(width, height);\n\t}\n\tget asString(): string {\n\t\treturn `${this.width}x${this.height}`;\n\t}\n}\n","import \"./pages.scss\";\nimport \"./flipbook.scss\";\nimport \"./mouse-mode.scss\";\nimport Hammer from \"hammerjs\";\nimport { throttle } from \"throttle-debounce\";\nimport type { AspectRatio } from \"./aspect-ratio\";\nimport type { DownloadConfig } from \"./download/types\";\nimport type {\n\tFlipBookOptions,\n\tFlipPageSemantic,\n\tHistoryMapper,\n\tMouseMode,\n\tPageFlipDirection,\n\tPageFlipParams,\n} from \"./flip-book-options\";\nimport { FlipDirection } from \"./flip-direction\";\nimport { type FlipPosition, Leaf } from \"./leaf\";\nimport type { PageSemantics } from \"./page-semantics\";\nimport { Size } from \"./size\";\nimport { setTocPageIndex } from \"./store\";\n\n/** Default threshold for fast flip detection (in ms) */\nconst DEFAULT_FAST_DELTA = 500;\n\n/** Percentage of book width that triggers hover shadow effect */\nconst EDGE_ZONE_RATIO = 0.18;\n/** Maximum hover shadow strength (0-1) */\nconst HOVER_STRENGTH_MAX = 0.12;\n/** Throttle interval for mouse move handler in ms */\nconst MOUSE_MOVE_THROTTLE_MS = 16;\n\n/** State for a single flip operation - enables concurrent page flipping */\ninterface FlipState {\n\tleaf: Leaf;\n\tdirection: FlipDirection;\n\tstartingPos: number;\n\tdelta: number;\n\tisDuringAutoFlip: boolean;\n}\n\n/**\n * Core FlipBook class for creating realistic page-flip animations.\n *\n * @example\n * ```typescript\n * import { FlipBook } from 'html-flip-book-vanilla';\n *\n * const flipBook = new FlipBook({\n * pagesCount: 10,\n * direction: 'ltr',\n * });\n *\n * flipBook.render('#book-container');\n *\n * // Navigate programmatically\n * await flipBook.flipNext();\n * await flipBook.flipToPage(5);\n * ```\n */\nclass FlipBook {\n\tbookElement?: HTMLElement;\n\tprivate pageElements: HTMLElement[] = [];\n\tprivate readonly pagesCount: number;\n\tprivate readonly leafAspectRatio: AspectRatio = { width: 2, height: 3 };\n\tprivate readonly coverAspectRatio: AspectRatio = {\n\t\twidth: 2.15,\n\t\theight: 3.15,\n\t};\n\tprivate readonly direction: \"rtl\" | \"ltr\" = \"ltr\";\n\tprivate mouseMode: MouseMode = \"turn\";\n\tprivate readonly fastDeltaThreshold: number = DEFAULT_FAST_DELTA;\n\tprivate readonly initialTurnedLeaves: Set<number> = new Set();\n\tprivate readonly onPageChanged?: (pageIndex: number) => void;\n\tprivate readonly onPageFlipping?: (params: PageFlipParams) => void;\n\tprivate readonly onPageFlipped?: (params: PageFlipParams) => void;\n\tprivate readonly historyMapper?: HistoryMapper;\n\tprivate lastFlipParams: PageFlipParams | undefined;\n\tprivate _historyInitialized = false;\n\tprivate _isRestoringFromHistory = false;\n\tprivate _boundPopstate: (() => void) | undefined;\n\tprivate readonly pageSemantics: PageSemantics | undefined;\n\tprivate readonly leavesBuffer?: number;\n\tprivate readonly coverPageIndices?: number[] | \"auto\";\n\tprivate readonly downloadConfig: DownloadConfig | undefined;\n\tprivate readonly pageShadow: boolean;\n\tprivate readonly snapshotDuringFlip: boolean;\n\tprivate leaves: Leaf[] = [];\n\t// flipping state - supports concurrent page flipping\n\tprivate activeFlips: Map<number, FlipState> = new Map();\n\tprivate pendingFlipStartingPos = 0;\n\tprivate pendingFlipDirection: FlipDirection = FlipDirection.None;\n\tprivate isDragging = false;\n\t/** Set after a drag ends; the next click event is suppressed so child buttons/links don't fire. */\n\tprivate _suppressNextClick = false;\n\tprivate hoveredLeaf: Leaf | undefined;\n\ttouchStartingPos = { x: 0, y: 0 };\n\t/** True when the current touch started inside a [data-flipbook-no-flip] element (e.g. carousel). */\n\tprivate touchStartedInNoFlipZone = false;\n\t/**\n\t * Direction lock for the current touch gesture.\n\t * Once the first significant movement (>5 px) determines the dominant axis,\n\t * the lock stays for the rest of the gesture. 'vertical' means native scroll\n\t * wins — Hammer pan events are rejected. 'horizontal' means every touchmove\n\t * gets preventDefault() so Hammer can drive the page flip.\n\t */\n\ttouchDirectionLock: \"none\" | \"vertical\" | \"horizontal\" = \"none\";\n\tprivate static readonly DIRECTION_LOCK_THRESHOLD = 5;\n\tprivate prevVisiblePageIndices: [number] | [number, number] | undefined;\n\t// Hammer instance for cleanup\n\tprivate hammer: HammerManager | undefined;\n\t// Resize observer for re-layout on container size changes\n\tprivate resizeObserver: ResizeObserver | undefined;\n\n\tprivate static readonly NO_FLIP_SELECTOR = \"[data-flipbook-no-flip]\";\n\n\tprivate isInsideNoFlipZone(el: EventTarget | null): boolean {\n\t\treturn el instanceof Element && el.closest(FlipBook.NO_FLIP_SELECTOR) != null;\n\t}\n\n\tprivate getSemanticForPage(pageIndex: number): FlipPageSemantic | undefined {\n\t\tif (!this.pageSemantics) return undefined;\n\t\treturn {\n\t\t\tsemanticName: this.pageSemantics.indexToSemanticName(pageIndex),\n\t\t\ttitle: this.pageSemantics.indexToTitle(pageIndex),\n\t\t};\n\t}\n\n\tprivate buildPageFlipParams(\n\t\tleftmostPageIndex: number,\n\t\tdirection: PageFlipDirection,\n\t): PageFlipParams {\n\t\tconst rightPageIndex = Math.min(leftmostPageIndex + 1, this.pagesCount - 1);\n\t\tconst pageIndices: [number, number] = [leftmostPageIndex, rightPageIndex];\n\t\tconst semantics: [FlipPageSemantic | undefined, FlipPageSemantic | undefined] = [\n\t\t\tthis.getSemanticForPage(leftmostPageIndex),\n\t\t\tthis.getSemanticForPage(rightPageIndex),\n\t\t];\n\t\tconst leafIndex = Math.floor(leftmostPageIndex / 2);\n\t\treturn { leafIndex, pageIndices, semantics, direction };\n\t}\n\n\tprivate syncHistoryAndNotifyFlipped(isInitial: boolean): void {\n\t\tconst pageIndex = this.currentPageIndex;\n\t\tconst semantic = this.getSemanticForPage(pageIndex);\n\t\tif (this.onPageChanged) this.onPageChanged(pageIndex);\n\t\tconst params = this.lastFlipParams ?? this.buildPageFlipParams(pageIndex, \"forward\");\n\t\tif (this.onPageFlipped) this.onPageFlipped(params);\n\t\tif (typeof window !== \"undefined\" && this.historyMapper && !this._isRestoringFromHistory) {\n\t\t\tconst route = this.historyMapper.pageToRoute(pageIndex, semantic);\n\t\t\t// When pageToRoute returns null the consumer signals \"this page has\n\t\t\t// no meaningful URL\" (e.g. cover, TOC). Skip the pushState entirely\n\t\t\t// to avoid framework-level routing side-effects.\n\t\t\tif (route == null) return;\n\t\t\tconst state = { route };\n\t\t\tconst url = route.startsWith(\"#\")\n\t\t\t\t? `${window.location.pathname}${window.location.search}${route}`\n\t\t\t\t: route;\n\t\t\t// Use the *native* History.prototype methods rather than\n\t\t\t// window.history.pushState/replaceState. Frameworks like Next.js\n\t\t\t// monkey-patch the instance methods to intercept URL changes and\n\t\t\t// trigger full soft navigations (RSC fetch + React re-render).\n\t\t\t// That is catastrophically expensive during rapid page flips.\n\t\t\t// Calling the prototype method bypasses the patch while still\n\t\t\t// updating the browser URL bar and history stack correctly.\n\t\t\tif (isInitial || !this._historyInitialized) {\n\t\t\t\tHistory.prototype.replaceState.call(window.history, state, \"\", url);\n\t\t\t\tthis._historyInitialized = true;\n\t\t\t} else {\n\t\t\t\tHistory.prototype.pushState.call(window.history, state, \"\", url);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handlePopstate = (): void => {\n\t\tif (!this.historyMapper || typeof window === \"undefined\") return;\n\t\tconst route =\n\t\t\t(typeof window.history.state === \"object\" && window.history.state?.route) ||\n\t\t\twindow.location.pathname + window.location.search + window.location.hash;\n\t\tconst pageIndex = this.historyMapper.routeToPage(route);\n\t\tif (pageIndex !== null && pageIndex >= 0 && pageIndex < this.pagesCount) {\n\t\t\tthis._isRestoringFromHistory = true;\n\t\t\ttry {\n\t\t\t\tthis.jumpToPage(pageIndex);\n\t\t\t} finally {\n\t\t\t\tthis._isRestoringFromHistory = false;\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate get isLTR(): boolean {\n\t\treturn this.direction === \"ltr\";\n\t}\n\n\tprivate get currentOrTurningLeaves(): [Leaf | undefined, Leaf | undefined] {\n\t\tlet secondLeafIndex = -1;\n\t\tfor (let i = this.leaves.length - 1; i >= 0; i--) {\n\t\t\tconst leaf = this.leaves[i];\n\t\t\tif (leaf.isTurned || leaf.isTurning) {\n\t\t\t\tsecondLeafIndex = leaf.index + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn secondLeafIndex === -1\n\t\t\t? [undefined, this.leaves[0]]\n\t\t\t: secondLeafIndex === this.leaves.length\n\t\t\t\t? [this.leaves[secondLeafIndex - 1], undefined]\n\t\t\t\t: [this.leaves[secondLeafIndex - 1], this.leaves[secondLeafIndex]];\n\t}\n\n\tconstructor(options: FlipBookOptions) {\n\t\tthis.pagesCount = options.pagesCount;\n\t\tthis.leafAspectRatio = options.leafAspectRatio || this.leafAspectRatio;\n\t\tthis.coverAspectRatio = options.coverAspectRatio || this.coverAspectRatio;\n\t\tthis.direction = options.direction || this.direction;\n\t\tthis.mouseMode = options.mouseMode ?? \"turn\";\n\t\tthis.fastDeltaThreshold = options.fastDeltaThreshold ?? this.fastDeltaThreshold;\n\t\tthis.initialTurnedLeaves = new Set(options.initialTurnedLeaves ?? []);\n\t\tthis.pageSemantics = options.pageSemantics;\n\t\tthis.onPageChanged = options.onPageChanged;\n\t\tthis.onPageFlipping = options.onPageFlipping;\n\t\tthis.onPageFlipped = options.onPageFlipped;\n\t\tthis.historyMapper = options.enableHistory !== false ? options.historyMapper : undefined;\n\t\tthis.leavesBuffer = options.leavesBuffer;\n\t\tthis.coverPageIndices = options.coverPageIndices;\n\t\tthis.downloadConfig = options.enableDownload !== false ? options.downloadConfig : undefined;\n\t\tthis.pageShadow = options.pageShadow ?? true;\n\t\tthis.snapshotDuringFlip = options.snapshotDuringFlip ?? true;\n\t\tthis._tocPageIndex = options.tocPageIndex ?? 4;\n\t\t// Keep the module-level store in sync for backward-compat\n\t\tsetTocPageIndex(this._tocPageIndex);\n\t}\n\n\tprivate _tocPageIndex = 4;\n\n\t/** Get the configured table of contents page index. */\n\tgetTocPageIndex(): number {\n\t\treturn this._tocPageIndex;\n\t}\n\n\tgetMouseMode(): MouseMode {\n\t\treturn this.mouseMode;\n\t}\n\n\tsetMouseMode(mode: MouseMode): void {\n\t\tthis.mouseMode = mode;\n\t\tthis.bookElement?.classList.toggle(\"flipbook--select-text\", mode === \"select\");\n\t}\n\n\t/** Keep mouse selection native by stopping the page's down event before Hammer sees it. */\n\tprivate handlePageMouseDown = (event: Event): void => {\n\t\tif (\n\t\t\tthis.mouseMode === \"select\" &&\n\t\t\tevent instanceof MouseEvent &&\n\t\t\tevent.button === 0 &&\n\t\t\t(event.type !== \"pointerdown\" || (event as PointerEvent).pointerType === \"mouse\")\n\t\t) {\n\t\t\tevent.stopPropagation();\n\t\t}\n\t};\n\n\t/** Download config (handlers and filename hints). Used by toolbar. */\n\tgetDownloadConfig(): DownloadConfig | undefined {\n\t\treturn this.downloadConfig;\n\t}\n\n\t/** Build the set of page indices that use cover sizing. */\n\tprivate buildCoverPageIndicesSet(): Set<number> {\n\t\tconst coverPageIndicesSet = new Set<number>();\n\t\tif (this.coverPageIndices) {\n\t\t\tconst indices =\n\t\t\t\tthis.coverPageIndices === \"auto\" ? [0, this.pagesCount - 1] : this.coverPageIndices;\n\t\t\tfor (const pageIdx of indices) {\n\t\t\t\tcoverPageIndicesSet.add(pageIdx);\n\t\t\t}\n\t\t}\n\t\treturn coverPageIndicesSet;\n\t}\n\n\t/**\n\t * Recalculate page sizes from the current container dimensions and\n\t * re-apply width/height/position styles. Called during initial render\n\t * and automatically on container resize (e.g. entering fullscreen).\n\t */\n\tprivate recalculateSizes(): void {\n\t\tif (!this.bookElement || !this.pageElements.length) return;\n\n\t\tconst maxCoverSize = new Size(this.bookElement.clientWidth / 2, this.bookElement.clientHeight);\n\t\tconst coverSize = maxCoverSize.aspectRatioFit(this.coverAspectRatio);\n\t\tconst leafSize = new Size(\n\t\t\t(coverSize.width * this.leafAspectRatio.width) / this.coverAspectRatio.width,\n\t\t\t(coverSize.height * this.leafAspectRatio.height) / this.coverAspectRatio.height,\n\t\t);\n\t\tthis.bookElement.style.perspective = `${Math.min(leafSize.width * 2, leafSize.height) * 2}px`;\n\n\t\tconst containerWidth = this.bookElement.clientWidth;\n\t\tconst containerHeight = this.bookElement.clientHeight;\n\n\t\tfor (const pageElement of this.pageElements) {\n\t\t\tconst isCoverPage = pageElement.dataset.isCoverPage === \"1\";\n\t\t\tconst pageSize = isCoverPage ? coverSize : leafSize;\n\n\t\t\tpageElement.style.width = `${pageSize.width}px`;\n\t\t\tpageElement.style.height = `${pageSize.height}px`;\n\t\t\tpageElement.style[this.isLTR ? \"left\" : \"right\"] =\n\t\t\t\t`${(containerWidth - 2 * pageSize.width) / 2}px`;\n\t\t\tpageElement.style.top = `${(containerHeight - pageSize.height) / 2}px`;\n\t\t}\n\t}\n\n\trender(selector: string, debug = false) {\n\t\tconst bookElement = document.querySelector(selector);\n\t\tif (!bookElement) {\n\t\t\tthrow new Error(`Couldn't find container with selector: ${selector}`);\n\t\t}\n\t\tthis.bookElement = bookElement as HTMLElement;\n\t\tthis.setMouseMode(this.mouseMode);\n\t\tif (!this.bookElement.classList.contains(\"flipbook\")) {\n\t\t\tthis.bookElement.classList.add(\"flipbook\");\n\t\t}\n\t\tif (!this.pageShadow) {\n\t\t\tthis.bookElement.classList.add(\"flipbook--no-page-shadow\");\n\t\t}\n\n\t\tconst pageElements = bookElement.querySelectorAll(\".page\");\n\t\tif (!pageElements.length) {\n\t\t\tthrow new Error(\"No pages found in flipbook\");\n\t\t}\n\t\tthis.pageElements = Array.from(pageElements) as HTMLElement[];\n\t\tfor (const page of this.pageElements) {\n\t\t\tpage.addEventListener(\"pointerdown\", this.handlePageMouseDown);\n\t\t\tpage.addEventListener(\"mousedown\", this.handlePageMouseDown);\n\t\t}\n\t\tthis.leaves.splice(0, this.leaves.length);\n\t\tconst leavesCount = Math.ceil(this.pagesCount / 2);\n\n\t\t// Determine which specific pages are cover exteriors (use coverSize).\n\t\t// Interior sides of cover leaves use leafSize — physically, the endpaper is\n\t\t// glued to the inside of the board and matches the text-block page size.\n\t\tconst coverPageIndicesSet = this.buildCoverPageIndicesSet();\n\n\t\t// Set data attributes before recalculateSizes() so it can read dataset.isCoverPage\n\t\t// to apply the correct cover vs leaf dimensions on the very first layout pass.\n\t\tthis.pageElements.forEach((pageElement, pageIndex) => {\n\t\t\tpageElement.dataset.pageIndex = pageIndex.toString();\n\t\t\tpageElement.dataset.pageSemanticName =\n\t\t\t\tthis.pageSemantics?.indexToSemanticName(pageIndex) ?? \"\";\n\t\t\tpageElement.dataset.pageTitle = this.pageSemantics?.indexToTitle(pageIndex) ?? \"\";\n\t\t\tpageElement.dataset.isCoverPage = coverPageIndicesSet.has(pageIndex) ? \"1\" : \"\";\n\t\t});\n\n\t\t// Compute and apply sizes (also called on resize).\n\t\t// Must run after dataset.isCoverPage is set so covers get coverSize.\n\t\tthis.recalculateSizes();\n\n\t\tthis.pageElements.forEach((pageElement, pageIndex) => {\n\t\t\tconst leafIndex = Math.floor(pageIndex / 2);\n\n\t\t\tconst isOddPage = (pageIndex + 1) % 2 === 1;\n\t\t\tconst isInitiallyTurned = this.initialTurnedLeaves.has(leafIndex);\n\n\t\t\t// Determine current page based on initial turned leaves\n\t\t\t// Current pages are the first two visible pages after all initially turned leaves\n\t\t\tconst firstVisibleLeafIndex =\n\t\t\t\tthis.initialTurnedLeaves.size > 0 ? Math.max(...this.initialTurnedLeaves) + 1 : 0;\n\t\t\tconst isCurrentPage =\n\t\t\t\tleafIndex === firstVisibleLeafIndex ||\n\t\t\t\t(leafIndex === firstVisibleLeafIndex - 1 && isInitiallyTurned);\n\n\t\t\tpageElement.classList.add(\n\t\t\t\tisOddPage ? \"odd\" : \"even\",\n\t\t\t\t...(isCurrentPage ? [\"current-page\"] : []),\n\t\t\t);\n\t\t\tif (isOddPage) {\n\t\t\t\tthis.leaves[leafIndex] = new Leaf(\n\t\t\t\t\tleafIndex,\n\t\t\t\t\t[pageElement, undefined],\n\t\t\t\t\tisInitiallyTurned,\n\t\t\t\t\t{\n\t\t\t\t\t\tisLTR: this.isLTR,\n\t\t\t\t\t\tleavesCount: leavesCount,\n\t\t\t\t\t\tpagesCount: this.pagesCount,\n\t\t\t\t\t\tpageShadow: this.pageShadow,\n\t\t\t\t\t\tsnapshotDuringFlip: this.snapshotDuringFlip,\n\t\t\t\t\t},\n\t\t\t\t\t(direction: FlipDirection) => {\n\t\t\t\t\t\tconst currentVisiblePageIndices: [number] | [number, number] =\n\t\t\t\t\t\t\tdirection === FlipDirection.Forward\n\t\t\t\t\t\t\t\t? pageIndex + 2 === this.pagesCount\n\t\t\t\t\t\t\t\t\t? [pageIndex + 1]\n\t\t\t\t\t\t\t\t\t: [pageIndex + 1, pageIndex + 2]\n\t\t\t\t\t\t\t\t: pageIndex === 0\n\t\t\t\t\t\t\t\t\t? [pageIndex]\n\t\t\t\t\t\t\t\t\t: [pageIndex - 1, pageIndex];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis.prevVisiblePageIndices &&\n\t\t\t\t\t\t\tthis.prevVisiblePageIndices.length === currentVisiblePageIndices.length &&\n\t\t\t\t\t\t\tcurrentVisiblePageIndices.every((v, i) => v === this.prevVisiblePageIndices?.[i])\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst prevVisiblePageIndices = this.prevVisiblePageIndices;\n\t\t\t\t\t\tthis.prevVisiblePageIndices = currentVisiblePageIndices;\n\n\t\t\t\t\t\t// TODO expose to outside using https://github.com/open-draft/strict-event-emitter, and just be a consumer internally\n\t\t\t\t\t\tthis.onTurned(currentVisiblePageIndices, prevVisiblePageIndices);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Even page (back side of leaf) — attach to the leaf created above.\n\t\t\t\tthis.leaves[leafIndex].pages[1] = pageElement;\n\n\t\t\t\t// Both pages of the leaf are now available.\n\t\t\t\t// Use applyTransform to set the correct initial transform — this ensures\n\t\t\t\t// the transforms exactly match what applyTransform produces during flips.\n\t\t\t\t// Previously, hardcoded transforms used rotateY(±180deg) for turned pages,\n\t\t\t\t// which made them invisible due to backface-visibility: hidden.\n\t\t\t\tconst initialPosition = isInitiallyTurned ? 1 : 0;\n\t\t\t\tthis.leaves[leafIndex].applyTransform(initialPosition);\n\t\t\t}\n\t\t});\n\n\t\t// Set initial visible page indices based on initially turned leaves.\n\t\t// Must match the post-flip model: the visible spread is the back of\n\t\t// the last turned leaf (odd page) and the front of the next un-turned\n\t\t// leaf (even page) → [lastTurnedLeaf*2+1, lastTurnedLeaf*2+2].\n\t\tconst lastTurnedLeafIndex =\n\t\t\tthis.initialTurnedLeaves.size > 0 ? Math.max(...this.initialTurnedLeaves) : -1;\n\n\t\tif (lastTurnedLeafIndex < 0) {\n\t\t\tthis.prevVisiblePageIndices = 1 < this.pagesCount ? [0, 1] : [0];\n\t\t} else {\n\t\t\tconst firstVisiblePageIndex = lastTurnedLeafIndex * 2 + 1;\n\t\t\tif (firstVisiblePageIndex >= this.pagesCount) {\n\t\t\t\t// All leaves are turned — show the last page(s)\n\t\t\t\tconst lastLeafIndex = Math.ceil(this.pagesCount / 2) - 1;\n\t\t\t\tconst lastLeafFirstPage = lastLeafIndex * 2;\n\t\t\t\tthis.prevVisiblePageIndices =\n\t\t\t\t\tlastLeafFirstPage + 1 < this.pagesCount\n\t\t\t\t\t\t? [lastLeafFirstPage, lastLeafFirstPage + 1]\n\t\t\t\t\t\t: [lastLeafFirstPage];\n\t\t\t} else {\n\t\t\t\tthis.prevVisiblePageIndices =\n\t\t\t\t\tfirstVisiblePageIndex + 1 < this.pagesCount\n\t\t\t\t\t\t? [firstVisiblePageIndex, firstVisiblePageIndex + 1]\n\t\t\t\t\t\t: [firstVisiblePageIndex];\n\t\t\t}\n\t\t}\n\n\t\t// Observe container size changes and re-layout automatically.\n\t\tif (typeof ResizeObserver !== \"undefined\") {\n\t\t\tthis.resizeObserver = new ResizeObserver(() => {\n\t\t\t\tthis.recalculateSizes();\n\t\t\t});\n\t\t\tthis.resizeObserver.observe(this.bookElement);\n\t\t}\n\n\t\tthis.hammer = new Hammer(this.bookElement);\n\t\t// Only recognise horizontal pans — vertical touch gestures must\n\t\t// remain native scroll events. Without this, a vertical scroll can\n\t\t// contaminate the pan state (wrong starting X) causing the next\n\t\t// flip to jump to a random position or get stuck.\n\t\tthis.hammer.get(\"pan\").set({ direction: Hammer.DIRECTION_HORIZONTAL });\n\t\tthis.hammer.on(\"panstart\", this.onDragStart.bind(this));\n\t\tthis.hammer.on(\"panmove\", this.onDragUpdate.bind(this));\n\t\tthis.hammer.on(\"panend\", this.onDragEnd.bind(this));\n\t\tthis.bookElement.addEventListener(\"touchstart\", this.handleTouchStart.bind(this), {\n\t\t\tpassive: false,\n\t\t});\n\t\tthis.bookElement.addEventListener(\"touchmove\", this.handleTouchMove.bind(this), {\n\t\t\tpassive: false,\n\t\t});\n\t\tthis.bookElement.addEventListener(\n\t\t\t\"mousemove\",\n\t\t\tthis.handleMouseMove as unknown as EventListener,\n\t\t);\n\t\tthis.bookElement.addEventListener(\"mouseleave\", this.handleMouseLeave as EventListener);\n\t\t// Suppress click events that fire immediately after a drag gesture.\n\t\t// This prevents child interactive elements (buttons, links) from\n\t\t// activating when the user was actually performing a page flip.\n\t\tthis.bookElement.addEventListener(\n\t\t\t\"click\",\n\t\t\tthis.handleClickAfterDrag as EventListener,\n\t\t\ttrue, // capture phase — intercept before the click reaches any child\n\t\t);\n\t\t// Apply initial leaves buffer visibility\n\t\tthis.updateLeavesBufferVisibility();\n\t\tif (debug) this.fillDebugBar();\n\n\t\t// History: initial replaceState and popstate listener\n\t\tif (typeof window !== \"undefined\" && this.historyMapper) {\n\t\t\tthis.syncHistoryAndNotifyFlipped(true);\n\t\t\tthis._boundPopstate = this.handlePopstate.bind(this);\n\t\t\twindow.addEventListener(\"popstate\", this._boundPopstate);\n\t\t}\n\t}\n\n\t/**\n\t * Update visibility of leaves based on the buffer setting.\n\t * Leaves outside the buffer range are hidden for performance.\n\t */\n\tprivate updateLeavesBufferVisibility(): void {\n\t\tif (this.leavesBuffer === undefined) {\n\t\t\treturn; // No buffer - all leaves stay visible\n\t\t}\n\n\t\tconst leavesCount = this.leaves.length;\n\t\tif (leavesCount === 0) return;\n\n\t\t// Find the current leaf index (the first non-turned leaf, or last leaf if all turned)\n\t\tconst [leftLeaf, rightLeaf] = this.currentOrTurningLeaves;\n\t\tconst currentLeafIndex = rightLeaf?.index ?? leftLeaf?.index ?? 0;\n\n\t\t// Calculate buffer range\n\t\tconst bufferStart = Math.max(0, currentLeafIndex - this.leavesBuffer);\n\t\tconst bufferEnd = Math.min(leavesCount - 1, currentLeafIndex + this.leavesBuffer);\n\n\t\t// Cover leaves must always stay visible — they are cover-sized and sit behind\n\t\t// all leaf-sized pages, acting as the physical book boards. Hiding them would\n\t\t// remove the realistic \"frame\" effect.\n\t\tconst coverLeafIndices = new Set<number>();\n\t\tif (this.coverPageIndices) {\n\t\t\tconst indices =\n\t\t\t\tthis.coverPageIndices === \"auto\" ? [0, this.pagesCount - 1] : this.coverPageIndices;\n\t\t\tfor (const pageIdx of indices) {\n\t\t\t\tcoverLeafIndices.add(Math.floor(pageIdx / 2));\n\t\t\t}\n\t\t}\n\n\t\t// Update visibility of all leaves\n\t\tfor (let i = 0; i < leavesCount; i++) {\n\t\t\tconst leaf = this.leaves[i];\n\t\t\tconst isWithinBuffer = i >= bufferStart && i <= bufferEnd;\n\t\t\tconst isCoverLeaf = coverLeafIndices.has(i);\n\n\t\t\t// Cover leaves are always visible; other leaves follow the buffer range.\n\t\t\tconst visible = isCoverLeaf || isWithinBuffer;\n\n\t\t\t// Update both pages of the leaf\n\t\t\tfor (const page of leaf.pages) {\n\t\t\t\tif (page) {\n\t\t\t\t\tpage.style.display = visible ? \"\" : \"none\";\n\t\t\t\t\t// Use content-visibility to skip rendering of off-screen pages.\n\t\t\t\t\t// \"hidden\" is more aggressive than display:none — the browser\n\t\t\t\t\t// also skips layout/paint entirely, reducing memory pressure.\n\t\t\t\t\tpage.style.contentVisibility = visible ? \"visible\" : \"hidden\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate fillDebugBar() {\n\t\tconst debugBar = document.createElement(\"div\");\n\t\tdebugBar.className = \"flipbook-debug-bar flipbook-debug-bar--hidden\";\n\t\tthis.bookElement?.appendChild(debugBar);\n\t\tsetInterval(() => {\n\t\t\t// Populate debug bar with relevant information (throttled to reduce flicker)\n\t\t\tconst activeFlipsInfo = Array.from(this.activeFlips.entries())\n\t\t\t\t.map(([idx, state]) => `${idx}:${state.leaf.flipPosition.toFixed(2)}`)\n\t\t\t\t.join(\", \");\n\t\t\tdebugBar.innerHTML = `\n <div>Direction: ${this.isLTR ? \"LTR\" : \"RTL\"}</div>\n <div>Active Flips: ${this.activeFlips.size} [${activeFlipsInfo}]</div>\n <div>Pending Flip dir: ${this.pendingFlipDirection}</div>\n `;\n\t\t}, 200);\n\t}\n\n\t/**\n\t * Get the current manually-controlled flip state (the one being dragged).\n\t * Returns undefined if no manual flip is in progress.\n\t */\n\tprivate get currentManualFlip(): FlipState | undefined {\n\t\tfor (const state of this.activeFlips.values()) {\n\t\t\tif (!state.isDuringAutoFlip) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Find the next available leaf for flipping in the given direction.\n\t * Excludes leaves that are already being flipped.\n\t */\n\tprivate getNextAvailableLeaf(direction: FlipDirection): Leaf | undefined {\n\t\tif (direction === FlipDirection.Forward) {\n\t\t\t// Find the rightmost leaf that's not already flipping\n\t\t\t// Start from the current right leaf and go forward\n\t\t\tconst [, rightLeaf] = this.currentOrTurningLeaves;\n\t\t\tif (!rightLeaf) return undefined;\n\n\t\t\t// Find a leaf that's not in activeFlips\n\t\t\tfor (let i = rightLeaf.index; i < this.leaves.length; i++) {\n\t\t\t\tconst leaf = this.leaves[i];\n\t\t\t\tif (!this.activeFlips.has(leaf.index) && !leaf.isTurned) {\n\t\t\t\t\treturn leaf;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} else if (direction === FlipDirection.Backward) {\n\t\t\t// Find the leftmost leaf that's not already flipping\n\t\t\tconst [leftLeaf] = this.currentOrTurningLeaves;\n\t\t\tif (!leftLeaf) return undefined;\n\n\t\t\t// Find a leaf that's not in activeFlips\n\t\t\tfor (let i = leftLeaf.index; i >= 0; i--) {\n\t\t\t\tconst leaf = this.leaves[i];\n\t\t\t\tif (!this.activeFlips.has(leaf.index) && (leaf.isTurned || leaf.isTurning)) {\n\t\t\t\t\treturn leaf;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate onDragStart(event: HammerInput) {\n\t\t// Reject pan events that belong to a touch gesture locked to vertical\n\t\t// (i.e. the user is scrolling, not flipping).\n\t\tif (this.touchDirectionLock === \"vertical\") {\n\t\t\treturn;\n\t\t}\n\t\t// Do not start flip when gesture begins inside a no-flip zone (e.g. horizontal carousel)\n\t\tif (this.isInsideNoFlipZone(event.srcEvent?.target ?? null)) {\n\t\t\treturn;\n\t\t}\n\t\t// Allow starting a new flip even if others are in auto-flip mode\n\t\t// Only block if we already have a manual flip in progress\n\t\tif (this.currentManualFlip) {\n\t\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t\t\tthis.pendingFlipStartingPos = 0;\n\t\t\treturn;\n\t\t}\n\t\tthis.isDragging = true;\n\t\tthis.clearHoverShadow();\n\t\tthis.pendingFlipStartingPos = event.center.x;\n\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t}\n\n\tprivate onDragUpdate(event: HammerInput) {\n\t\t// Reject pan events that belong to a touch gesture locked to vertical.\n\t\tif (this.touchDirectionLock === \"vertical\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create the current manual flip state\n\t\tlet flipState = this.currentManualFlip;\n\n\t\tconst currentPos = event.center.x;\n\t\tconst bookWidth = this.bookElement?.clientWidth ?? 0;\n\n\t\t// Calculate delta\n\t\tlet delta = this.isLTR\n\t\t\t? this.pendingFlipStartingPos - currentPos\n\t\t\t: currentPos - this.pendingFlipStartingPos;\n\n\t\tif (Math.abs(delta) > bookWidth) return;\n\t\tif (delta === 0) return;\n\n\t\t// Determine direction on first meaningful movement\n\t\tconst direction =\n\t\t\tthis.pendingFlipDirection !== FlipDirection.None\n\t\t\t\t? this.pendingFlipDirection\n\t\t\t\t: delta > 0\n\t\t\t\t\t? FlipDirection.Forward\n\t\t\t\t\t: FlipDirection.Backward;\n\n\t\t// Lock in direction for this flip\n\t\tif (this.pendingFlipDirection === FlipDirection.None) {\n\t\t\tthis.pendingFlipDirection = direction;\n\t\t}\n\n\t\t// Block starting a new flip in opposite direction while auto-flip is in progress\n\t\t// This prevents visual glitches when swiping backward while a forward flip is animating\n\t\tif (!flipState) {\n\t\t\tfor (const state of this.activeFlips.values()) {\n\t\t\t\tif (state.isDuringAutoFlip && state.direction !== direction) {\n\t\t\t\t\t// There's an auto-flip in the opposite direction - block this new flip\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If we don't have a flip state yet, create one\n\t\tif (!flipState) {\n\t\t\tconst leaf = this.getNextAvailableLeaf(direction);\n\t\t\tif (!leaf) return;\n\n\t\t\t// Acquire the flip lock for the full drag cycle; the matching\n\t\t\t// endFlip() is deferred until the release animation completes\n\t\t\t// in onDragEnd, so the snapshot/scrollbar lockdown stays stable.\n\t\t\tleaf.beginFlip();\n\n\t\t\t// Snap the starting position to the current finger position so\n\t\t\t// the first rendered frame has delta ≈ 0 and the page begins at\n\t\t\t// its resting position (0 for forward, 1 for backward) instead\n\t\t\t// of jumping to an intermediate value.\n\t\t\tthis.pendingFlipStartingPos = currentPos;\n\t\t\tdelta = 0;\n\n\t\t\tflipState = {\n\t\t\t\tleaf,\n\t\t\t\tdirection,\n\t\t\t\tstartingPos: currentPos,\n\t\t\t\tdelta: 0,\n\t\t\t\tisDuringAutoFlip: false,\n\t\t\t};\n\t\t\tthis.activeFlips.set(leaf.index, flipState);\n\t\t}\n\n\t\t// Update delta\n\t\tflipState.delta = delta;\n\n\t\t// Calculate and apply flip position\n\t\tswitch (flipState.direction) {\n\t\t\tcase FlipDirection.Forward: {\n\t\t\t\tconst posForward = (delta / bookWidth) as FlipPosition;\n\t\t\t\tif (posForward > 1 || delta < 0) return;\n\t\t\t\tflipState.leaf.efficientFlipToPosition(posForward);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase FlipDirection.Backward: {\n\t\t\t\tconst posBackward = (1 - Math.abs(delta) / bookWidth) as FlipPosition;\n\t\t\t\tif (posBackward < 0 || delta > 0) return;\n\t\t\t\tflipState.leaf.efficientFlipToPosition(posBackward);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onDragEnd(event: HammerInput) {\n\t\t// Suppress the click that the browser fires after pointerup following a drag.\n\t\tthis._suppressNextClick = true;\n\n\t\tconst flipState = this.currentManualFlip;\n\t\tif (!flipState) {\n\t\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t\t\tthis.pendingFlipStartingPos = 0;\n\t\t\tthis.isDragging = false;\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst ppsX = event.velocityX * 1000; // pixels per second\n\t\tlet flipTo: FlipPosition;\n\n\t\tswitch (flipState.direction) {\n\t\t\tcase FlipDirection.Forward:\n\t\t\t\tif (\n\t\t\t\t\t(this.isLTR ? ppsX < -this.fastDeltaThreshold : ppsX > this.fastDeltaThreshold) ||\n\t\t\t\t\tflipState.leaf.flipPosition >= 0.5\n\t\t\t\t) {\n\t\t\t\t\tflipTo = 1;\n\t\t\t\t} else {\n\t\t\t\t\tflipTo = 0;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase FlipDirection.Backward:\n\t\t\t\tif (\n\t\t\t\t\t(this.isLTR ? ppsX > this.fastDeltaThreshold : ppsX < -this.fastDeltaThreshold) ||\n\t\t\t\t\tflipState.leaf.flipPosition <= 0.5\n\t\t\t\t) {\n\t\t\t\t\tflipTo = 0;\n\t\t\t\t} else {\n\t\t\t\t\tflipTo = 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// Safety: release the drag-level flip lock if direction is unexpected.\n\t\t\t\tflipState.leaf.endFlip();\n\t\t\t\treturn;\n\t\t}\n\n\t\t// Mark as auto-flip and reset pending state\n\t\tflipState.isDuringAutoFlip = true;\n\t\tthis.pendingFlipDirection = FlipDirection.None;\n\t\tthis.pendingFlipStartingPos = 0;\n\t\tthis.isDragging = false;\n\n\t\tconst targetPageIndex =\n\t\t\tflipTo === 1 ? 2 * (flipState.leaf.index + 1) : 2 * flipState.leaf.index;\n\t\tconst direction: PageFlipDirection = flipTo === 1 ? \"forward\" : \"backward\";\n\t\tthis.lastFlipParams = this.buildPageFlipParams(targetPageIndex, direction);\n\t\tif (this.onPageFlipping) this.onPageFlipping(this.lastFlipParams);\n\n\t\t// Complete the flip asynchronously - don't block new flips!\n\t\tflipState.leaf.flipToPosition(flipTo).then(() => {\n\t\t\t// Release the drag-level flip lock acquired in onDragUpdate.\n\t\t\t// The animation's own beginFlip/endFlip is ref-counted inside, so\n\t\t\t// the snapshot stays active until this final endFlip() zeroes it.\n\t\t\tflipState.leaf.endFlip();\n\t\t\tthis.activeFlips.delete(flipState.leaf.index);\n\t\t});\n\t}\n\n\tprivate handleTouchStart = (e: TouchEvent) => {\n\t\tif (e.touches.length > 1) {\n\t\t\treturn;\n\t\t}\n\t\tconst touch = e.touches[0];\n\t\tthis.touchStartingPos = { x: touch.pageX, y: touch.pageY };\n\t\tthis.touchStartedInNoFlipZone = this.isInsideNoFlipZone(e.target);\n\t\tthis.touchDirectionLock = \"none\";\n\t};\n\n\tprivate handleTouchMove = (e: TouchEvent) => {\n\t\tif (e.touches.length > 1) {\n\t\t\treturn;\n\t\t}\n\t\t// Allow horizontal scroll (e.g. carousel) when touch started inside a no-flip zone\n\t\tif (this.touchStartedInNoFlipZone) {\n\t\t\treturn;\n\t\t}\n\t\tconst touch = e.touches[0];\n\t\tconst deltaX = touch.pageX - this.touchStartingPos.x;\n\t\tconst deltaY = touch.pageY - this.touchStartingPos.y;\n\n\t\t// Lock direction on the first significant movement. Once locked the\n\t\t// decision is final for the rest of this gesture — prevents the old\n\t\t// bug where accumulated vertical delta kept overruling a late\n\t\t// horizontal change-of-direction within the same gesture.\n\t\tif (this.touchDirectionLock === \"none\") {\n\t\t\tconst absDx = Math.abs(deltaX);\n\t\t\tconst absDy = Math.abs(deltaY);\n\t\t\tif (absDx > FlipBook.DIRECTION_LOCK_THRESHOLD || absDy > FlipBook.DIRECTION_LOCK_THRESHOLD) {\n\t\t\t\tthis.touchDirectionLock = absDx >= absDy ? \"horizontal\" : \"vertical\";\n\t\t\t}\n\t\t}\n\n\t\tif (this.touchDirectionLock === \"horizontal\") {\n\t\t\te.preventDefault();\n\t\t}\n\t\t// 'vertical' or 'none' → let the browser handle native scroll\n\t};\n\n\tprivate handleMouseMove = throttle(MOUSE_MOVE_THROTTLE_MS, (event: MouseEvent) => {\n\t\tif (!this.bookElement) return;\n\t\tif (this.isDragging || this.currentManualFlip || this.activeFlips.size > 0) {\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst rect = this.bookElement.getBoundingClientRect();\n\t\tif (rect.width <= 0) return;\n\n\t\tconst x = event.clientX - rect.left;\n\t\tconst edgeZone = rect.width * EDGE_ZONE_RATIO;\n\t\tconst isLeftEdge = x <= edgeZone;\n\t\tconst isRightEdge = x >= rect.width - edgeZone;\n\n\t\tif (!isLeftEdge && !isRightEdge) {\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst isForward = this.isLTR ? isRightEdge : isLeftEdge;\n\t\tconst direction = isForward ? FlipDirection.Forward : FlipDirection.Backward;\n\t\tconst leaf = this.getNextAvailableLeaf(direction);\n\t\tif (!leaf) {\n\t\t\tthis.clearHoverShadow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst distanceFromEdge = isForward\n\t\t\t? this.isLTR\n\t\t\t\t? rect.width - x\n\t\t\t\t: x\n\t\t\t: this.isLTR\n\t\t\t\t? x\n\t\t\t\t: rect.width - x;\n\t\tconst edgeProgress = 1 - Math.min(1, distanceFromEdge / edgeZone);\n\t\tconst hoverStrength = edgeProgress * HOVER_STRENGTH_MAX;\n\n\t\tif (this.hoveredLeaf && this.hoveredLeaf !== leaf) {\n\t\t\tthis.hoveredLeaf.setHoverShadow(0);\n\t\t}\n\t\tthis.hoveredLeaf = leaf;\n\t\tleaf.setHoverShadow(hoverStrength);\n\t});\n\n\tprivate handleMouseLeave = () => {\n\t\tthis.clearHoverShadow();\n\t};\n\n\t/**\n\t * Capture-phase click handler that suppresses clicks fired by the browser\n\t * immediately after a drag gesture ends. Without this, releasing the pointer\n\t * on an interactive element (button, link) inside a page would trigger both\n\t * the flip animation AND the element's click handler.\n\t */\n\tprivate handleClickAfterDrag = (e: Event) => {\n\t\tif (this._suppressNextClick) {\n\t\t\tthis._suppressNextClick = false;\n\t\t\te.stopPropagation();\n\t\t\te.preventDefault();\n\t\t}\n\t};\n\n\tprivate clearHoverShadow() {\n\t\tif (this.hoveredLeaf) {\n\t\t\tthis.hoveredLeaf.setHoverShadow(0);\n\t\t\tthis.hoveredLeaf = undefined;\n\t\t}\n\t}\n\tprivate onTurned(\n\t\tcurrentVisiblePageIndices: [number] | [number, number],\n\t\tprevVisibilePageIndices?: [number] | [number, number],\n\t) {\n\t\tfor (let i = 0; i < this.pageElements.length; i++) {\n\t\t\tconst pageElement = this.pageElements[i];\n\t\t\tconst inCurrent = currentVisiblePageIndices.includes(i);\n\t\t\tconst inPrev = prevVisibilePageIndices?.includes(i);\n\t\t\tconst action = inCurrent\n\t\t\t\t? pageElement.classList.add\n\t\t\t\t: !prevVisibilePageIndices || !inPrev\n\t\t\t\t\t? () => null\n\t\t\t\t\t: pageElement.classList.remove;\n\t\t\taction.bind(pageElement.classList)(\"current-page\");\n\t\t}\n\t\t// Update leaves buffer visibility after turn completes\n\t\tthis.updateLeavesBufferVisibility();\n\t\t// Notify React/consumer and sync history\n\t\tthis.syncHistoryAndNotifyFlipped(false);\n\t\t// TODO expose to outside using https://github.com/open-draft/strict-event-emitter, and just be a consumer internally.\n\t\t// TODO: set prev-page / next-page classes for prev/next pages as accordingally\n\t}\n\t/**\n\t * Get the index of the current (leftmost visible) page.\n\t * Returns 0 if no pages are visible.\n\t */\n\tget currentPageIndex(): number {\n\t\treturn this.prevVisiblePageIndices?.[0] ?? 0;\n\t}\n\n\t/**\n\t * Get the total number of pages in the flipbook.\n\t */\n\tget totalPages(): number {\n\t\treturn this.pagesCount;\n\t}\n\n\t/**\n\t * Check if the book is currently showing the first page(s).\n\t */\n\tget isFirstPage(): boolean {\n\t\treturn this.currentPageIndex === 0;\n\t}\n\n\t/**\n\t * Check if the book is currently showing the last page(s).\n\t */\n\tget isLastPage(): boolean {\n\t\tconst lastPageIndex = this.pagesCount - 1;\n\t\treturn this.prevVisiblePageIndices?.includes(lastPageIndex) ?? false;\n\t}\n\n\t/**\n\t * Check if there's an active auto-flip in the given direction.\n\t */\n\tprivate hasActiveAutoFlipInDirection(direction: FlipDirection): boolean {\n\t\tfor (const state of this.activeFlips.values()) {\n\t\t\tif (state.isDuringAutoFlip && state.direction === direction) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Animate flip to the next page.\n\t * @returns Promise that resolves when the flip animation completes\n\t */\n\tasync flipNext(): Promise<void> {\n\t\t// Block if there's an active auto-flip in the opposite direction\n\t\tif (this.hasActiveAutoFlipInDirection(FlipDirection.Backward)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst leaf = this.getNextAvailableLeaf(FlipDirection.Forward);\n\t\tif (!leaf) return;\n\n\t\tconst flipState: FlipState = {\n\t\t\tleaf,\n\t\t\tdirection: FlipDirection.Forward,\n\t\t\tstartingPos: 0,\n\t\t\tdelta: 0,\n\t\t\tisDuringAutoFlip: true,\n\t\t};\n\t\tthis.activeFlips.set(leaf.index, flipState);\n\t\tconst targetPageIndex = this.currentPageIndex + 2;\n\t\tthis.lastFlipParams = this.buildPageFlipParams(targetPageIndex, \"forward\");\n\t\tif (this.onPageFlipping) this.onPageFlipping(this.lastFlipParams);\n\n\t\ttry {\n\t\t\tawait leaf.flipToPosition(1);\n\t\t} finally {\n\t\t\tthis.activeFlips.delete(leaf.index);\n\t\t}\n\t}\n\n\t/**\n\t * Animate flip to the previous page.\n\t * @returns Promise that resolves when the flip animation completes\n\t */\n\tasync flipPrev(): Promise<void> {\n\t\t// Block if there's an active auto-flip in the opposite direction\n\t\tif (this.hasActiveAutoFlipInDirection(FlipDirection.Forward)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst leaf = this.getNextAvailableLeaf(FlipDirection.Backward);\n\t\tif (!leaf) return;\n\n\t\tconst flipState: FlipState = {\n\t\t\tleaf,\n\t\t\tdirection: FlipDirection.Backward,\n\t\t\tstartingPos: 0,\n\t\t\tdelta: 0,\n\t\t\tisDuringAutoFlip: true,\n\t\t};\n\t\tthis.activeFlips.set(leaf.index, flipState);\n\t\tconst targetPageIndex = this.currentPageIndex - 2;\n\t\tthis.lastFlipParams = this.buildPageFlipParams(Math.max(0, targetPageIndex), \"backward\");\n\t\tif (this.onPageFlipping) this.onPageFlipping(this.lastFlipParams);\n\n\t\ttry {\n\t\t\tawait leaf.flipToPosition(0);\n\t\t} finally {\n\t\t\tthis.activeFlips.delete(leaf.index);\n\t\t}\n\t}\n\n\t/**\n\t * Animate to a specific page index.\n\t * Flips through pages sequentially to reach the target.\n\t * @param pageIndex - The target page index (0-based)\n\t * @returns Promise that resolves when all flip animations complete\n\t */\n\tasync flipToPage(pageIndex: number): Promise<void> {\n\t\tif (pageIndex < 0 || pageIndex >= this.pagesCount) {\n\t\t\tconsole.warn(\n\t\t\t\t`flipToPage: Invalid page index ${pageIndex}. Must be between 0 and ${this.pagesCount - 1}.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// Compute the last-turned-leaf index that makes pageIndex visible,\n\t\t// using the same formula as jumpToPage.\n\t\tconst targetLastTurned = pageIndex <= 0 ? -1 : Math.floor((pageIndex - 1) / 2);\n\t\tconst currentLastTurned =\n\t\t\tthis.currentPageIndex <= 0 ? -1 : Math.floor((this.currentPageIndex - 1) / 2);\n\n\t\tif (targetLastTurned === currentLastTurned) {\n\t\t\treturn; // Already at the target spread\n\t\t}\n\n\t\tif (targetLastTurned > currentLastTurned) {\n\t\t\tconst steps = targetLastTurned - currentLastTurned;\n\t\t\tfor (let i = 0; i < steps; i++) {\n\t\t\t\tawait this.flipNext();\n\t\t\t}\n\t\t} else {\n\t\t\tconst steps = currentLastTurned - targetLastTurned;\n\t\t\tfor (let i = 0; i < steps; i++) {\n\t\t\t\tawait this.flipPrev();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Jump to a specific page instantly without animation.\n\t * @param pageIndex - The target page index (0-based)\n\t */\n\tjumpToPage(pageIndex: number): void {\n\t\tif (pageIndex < 0 || pageIndex >= this.pagesCount) {\n\t\t\tconsole.warn(\n\t\t\t\t`jumpToPage: Invalid page index ${pageIndex}. Must be between 0 and ${this.pagesCount - 1}.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst isLastPage = pageIndex === this.pagesCount - 1;\n\t\tconst isOddPage = pageIndex % 2 === 1;\n\t\t// If targeting the last page and it's odd (back of leaf), close the book reversed\n\t\tconst closeBookReversed = isLastPage && isOddPage;\n\n\t\t// Determine which leaf should be the last one turned.\n\t\t// A leaf's pages are visible as follows:\n\t\t// - At position 0 (not turned): its even page (front) is visible\n\t\t// - At position 1 (turned): its odd page (back) is visible\n\t\t// The visible spread after turning leaf k is [2k+1, 2k+2]:\n\t\t// back of leaf k (odd) + front of leaf k+1 (even).\n\t\t// For page 0, no leaves need to be turned (initial spread [0, 1]).\n\t\tlet lastTurnedLeafIndex: number;\n\t\tif (pageIndex <= 0) {\n\t\t\tlastTurnedLeafIndex = -1; // No leaves turned\n\t\t} else if (closeBookReversed) {\n\t\t\tlastTurnedLeafIndex = this.leaves.length - 1; // All leaves turned\n\t\t} else {\n\t\t\tlastTurnedLeafIndex = Math.floor((pageIndex - 1) / 2);\n\t\t}\n\n\t\t// Set all leaves up to lastTurnedLeafIndex as turned, all after as not turned\n\t\tfor (let i = 0; i < this.leaves.length; i++) {\n\t\t\tconst leaf = this.leaves[i];\n\t\t\tconst shouldBeTurned = i <= lastTurnedLeafIndex;\n\n\t\t\tif (shouldBeTurned && !leaf.isTurned) {\n\t\t\t\t// Turn this leaf instantly\n\t\t\t\tleaf.flipPosition = 1;\n\t\t\t\tthis.applyLeafTransform(leaf, 1);\n\t\t\t} else if (!shouldBeTurned && leaf.isTurned) {\n\t\t\t\t// Unturn this leaf instantly\n\t\t\t\tleaf.flipPosition = 0;\n\t\t\t\tthis.applyLeafTransform(leaf, 0);\n\t\t\t}\n\t\t}\n\n\t\t// Update visible page indices\n\t\tif (closeBookReversed) {\n\t\t\t// Closed reversed: only show the last page\n\t\t\tthis.prevVisiblePageIndices = [pageIndex];\n\t\t} else if (lastTurnedLeafIndex < 0) {\n\t\t\t// No leaves turned: initial spread\n\t\t\tthis.prevVisiblePageIndices = 1 < this.pagesCount ? [0, 1] : [0];\n\t\t} else {\n\t\t\tconst firstVisiblePageIndex = lastTurnedLeafIndex * 2 + 1;\n\t\t\tthis.prevVisiblePageIndices =\n\t\t\t\tfirstVisiblePageIndex + 1 < this.pagesCount\n\t\t\t\t\t? [firstVisiblePageIndex, firstVisiblePageIndex + 1]\n\t\t\t\t\t: [firstVisiblePageIndex];\n\t\t}\n\n\t\t// Update current-page classes\n\t\tfor (let i = 0; i < this.pageElements.length; i++) {\n\t\t\tconst pageElement = this.pageElements[i];\n\t\t\tif (this.prevVisiblePageIndices.includes(i)) {\n\t\t\t\tpageElement.classList.add(\"current-page\");\n\t\t\t} else {\n\t\t\t\tpageElement.classList.remove(\"current-page\");\n\t\t\t}\n\t\t}\n\n\t\t// Update leaves buffer visibility\n\t\tthis.updateLeavesBufferVisibility();\n\n\t\t// Notify callback and sync history\n\t\tthis.syncHistoryAndNotifyFlipped(false);\n\t}\n\n\t/**\n\t * Apply transform styles to a leaf's pages for a given flip position.\n\t * Used for instant positioning (jumpToPage).\n\t */\n\tprivate applyLeafTransform(leaf: Leaf, position: number): void {\n\t\tleaf.applyTransform(position);\n\t}\n\n\t/**\n\t * Clean up event listeners and Hammer instance.\n\t * Should be called when the FlipBook is no longer needed.\n\t */\n\tdestroy() {\n\t\tif (typeof window !== \"undefined\" && this._boundPopstate) {\n\t\t\twindow.removeEventListener(\"popstate\", this._boundPopstate);\n\t\t\tthis._boundPopstate = undefined;\n\t\t}\n\t\tif (this.resizeObserver) {\n\t\t\tthis.resizeObserver.disconnect();\n\t\t\tthis.resizeObserver = undefined;\n\t\t}\n\t\tif (this.hammer) {\n\t\t\tthis.hammer.destroy();\n\t\t\tthis.hammer = undefined;\n\t\t}\n\t\tif (this.bookElement) {\n\t\t\tfor (const page of this.pageElements) {\n\t\t\t\tpage.removeEventListener(\"pointerdown\", this.handlePageMouseDown);\n\t\t\t\tpage.removeEventListener(\"mousedown\", this.handlePageMouseDown);\n\t\t\t}\n\t\t\tthis.bookElement.removeEventListener(\"touchstart\", this.handleTouchStart as EventListener);\n\t\t\tthis.bookElement.removeEventListener(\"touchmove\", this.handleTouchMove as EventListener);\n\t\t\tthis.bookElement.removeEventListener(\n\t\t\t\t\"mousemove\",\n\t\t\t\tthis.handleMouseMove as unknown as EventListener,\n\t\t\t);\n\t\t\tthis.bookElement.removeEventListener(\"mouseleave\", this.handleMouseLeave as EventListener);\n\t\t\tthis.bookElement.removeEventListener(\n\t\t\t\t\"click\",\n\t\t\t\tthis.handleClickAfterDrag as EventListener,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport { FlipBook, type PageSemantics };\nexport type {\n\tFlipPageSemantic,\n\tHistoryMapper,\n\tMouseMode,\n\tPageFlipDirection,\n\tPageFlipParams,\n} from \"./flip-book-options\";\n"],"names":["FlipDirection","scheduleFrame","cb","SHADOW_STRENGTH_MULTIPLIER","HIGHLIGHT_STRENGTH_MULTIPLIER","Leaf","index","pages","isFlipped","bookProperties","onTurned","value","progress","clamped","page","flipPosition","velocity","resolve","currentFlipPosition","duration","start","step","timestamp","elapsed","newPosition","throttle","position","clampedPosition","pageShadow","shadowStrength","highlightStrength","shadowFromFlip","shadowProgress","isLTR","isOdd","rotateY","translateX","scaleX","origin","edge","AspectRatioImpl","width","height","aspectRatio","Size","rhsAspectRatio","rhsAspectRatioValue","DEFAULT_FAST_DELTA","EDGE_ZONE_RATIO","HOVER_STRENGTH_MAX","MOUSE_MOVE_THROTTLE_MS","FlipBook","el","pageIndex","leftmostPageIndex","direction","rightPageIndex","pageIndices","semantics","isInitial","semantic","params","route","state","url","secondLeafIndex","i","leaf","options","setTocPageIndex","mode","event","coverPageIndicesSet","indices","pageIdx","coverSize","leafSize","containerWidth","containerHeight","pageElement","pageSize","selector","debug","bookElement","pageElements","leavesCount","leafIndex","isOddPage","isInitiallyTurned","firstVisibleLeafIndex","isCurrentPage","currentVisiblePageIndices","v","prevVisiblePageIndices","initialPosition","lastTurnedLeafIndex","firstVisiblePageIndex","lastLeafFirstPage","Hammer","leftLeaf","rightLeaf","currentLeafIndex","bufferStart","bufferEnd","coverLeafIndices","isWithinBuffer","visible","debugBar","activeFlipsInfo","idx","flipState","currentPos","bookWidth","delta","posForward","posBackward","ppsX","flipTo","targetPageIndex","touch","deltaX","deltaY","absDx","absDy","rect","x","edgeZone","isLeftEdge","isRightEdge","isForward","distanceFromEdge","hoverStrength","prevVisibilePageIndices","inCurrent","inPrev","lastPageIndex","targetLastTurned","currentLastTurned","steps","isLastPage","closeBookReversed","shouldBeTurned"],"mappings":";;;AAAO,IAAKA,sBAAAA,OACXA,EAAA,UAAU,WACVA,EAAA,WAAW,YACXA,EAAA,OAAO,QAHIA,IAAAA,KAAA,CAAA,CAAA;ACKZ,SAASC,EAAcC,GAAyC;AAC/D,SAAO,OAAO,wBAA0B,MACrC,sBAAsBA,CAAE,IACvB,WAAW,MAAMA,EAAG,YAAY,IAAA,CAAK,GAAG,CAAC;AAC9C;AAGA,MAAMC,IAA6B,KAE7BC,IAAgC;AAO/B,MAAMC,EAAK;AAAA,EAQjB,YACUC,GACAC,GACTC,GACiBC,GAOAC,GAChB;AAXQ,SAAA,QAAAJ,GACA,KAAA,QAAAC,GAEQ,KAAA,iBAAAE,GAOA,KAAA,WAAAC,GAEjB,KAAK,sBAAsBF,IAAY,IAAI;AAAA,EAK5C;AAAA,EAzBQ,mBAAyC;AAAA,EACzC,qBAA0C;AAAA,EAC1C;AAAA,EACA,cAAc;AAAA;AAAA,EAEd,eAAe;AAAA,EAsBvB,IAAI,WAAoB;AACvB,WAAO,KAAK,iBAAiB;AAAA,EAC9B;AAAA,EACA,IAAI,YAAqB;AACxB,WAAO,KAAK,iBAAiB;AAAA,EAC9B;AAAA,EACA,IAAI,UAAmB;AACtB,WAAO,KAAK,WAAW,KAAK;AAAA,EAC7B;AAAA,EACA,IAAI,UAAmB;AACtB,WAAO,KAAK,UAAU;AAAA,EACvB;AAA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AMa,IAAc,KAAK,aAAab,CAAC;AACvC,MAAI,KAAK,uBAAuB,SAASA,CAAC,IACzCa,EAAY,UAAU,IAAI,cAAc,IAExCA,EAAY,UAAU,OAAO,cAAc;AAAA,IAE7C;AAGA,SAAK,6BAAA,GAGL,KAAK,4BAA4B,EAAK;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,mBAAmBZ,GAAYzC,GAAwB;AAC9D,IAAAyC,EAAK,eAAezC,CAAQ;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU;AAaT,QAZI,OAAO,SAAW,OAAe,KAAK,mBACzC,OAAO,oBAAoB,YAAY,KAAK,cAAc,GAC1D,KAAK,iBAAiB,SAEnB,KAAK,mBACR,KAAK,eAAe,WAAA,GACpB,KAAK,iBAAiB,SAEnB,KAAK,WACR,KAAK,OAAO,QAAA,GACZ,KAAK,SAAS,SAEX,KAAK,aAAa;AACrB,iBAAWZ,KAAQ,KAAK;AACvB,QAAAA,EAAK,oBAAoB,eAAe,KAAK,mBAAmB,GAChEA,EAAK,oBAAoB,aAAa,KAAK,mBAAmB;AAE/D,WAAK,YAAY,oBAAoB,cAAc,KAAK,gBAAiC,GACzF,KAAK,YAAY,oBAAoB,aAAa,KAAK,eAAgC,GACvF,KAAK,YAAY;AAAA,QAChB;AAAA,QACA,KAAK;AAAA,MAAA,GAEN,KAAK,YAAY,oBAAoB,cAAc,KAAK,gBAAiC,GACzF,KAAK,YAAY;AAAA,QAChB;AAAA,QACA,KAAK;AAAA,QACL;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACD;"}
|
package/dist/html-flip-book.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.page{position:absolute;backface-visibility:hidden;transform-style:preserve-3d;background:#fff;contain:layout style paint;--inner-shadow-shadow: 0;--inner-shadow-highlight: 0;--inner-shadow-edge: right}.page:before,.page:after{content:"";position:absolute;inset:0;pointer-events:none;backface-visibility:hidden;transition:opacity .12s ease;will-change:opacity}.page:before{background:linear-gradient(to var(--inner-shadow-edge),rgba(0,0,0,calc(.35 * var(--inner-shadow-shadow))) 0%,rgba(0,0,0,0) 40%);opacity:var(--inner-shadow-shadow);mix-blend-mode:multiply}.page:after{background:linear-gradient(to var(--inner-shadow-edge),rgba(255,255,255,calc(.4 * var(--inner-shadow-highlight))) 0%,rgba(255,255,255,0) 45%);opacity:var(--inner-shadow-highlight)}.flipbook--no-page-shadow .page:before,.flipbook--no-page-shadow .page:after{opacity:0!important}.page--flipping{contain:strict;-webkit-user-select:none;user-select:none;scrollbar-color:transparent transparent}.page--flipping::-webkit-scrollbar{display:none}.page--flipping *{scrollbar-color:transparent transparent!important}.page--flipping *::-webkit-scrollbar{display:none!important}.page>*{max-width:100%;max-height:100%;height:100%;width:100%;box-sizing:border-box}.flipbook{height:100%;width:100%;overflow:hidden}.flipbook-debug-bar{position:absolute;bottom:0;left:0;width:100%;min-height:48px;background-color:#00000080;color:#fff;padding:10px;box-sizing:border-box;display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;z-index:9999}.flipbook-debug-bar--hidden{display:none!important}.page--cover-interior{overflow:hidden}.page--cover-interior-inset{padding-top:var(--cover-inset, 5%);padding-bottom:var(--cover-inset, 5%);padding-left:var(--cover-inset-left, var(--cover-inset, 5%));padding-right:var(--cover-inset-right, var(--cover-inset, 5%));background:#fffef8;background-clip:content-box}
|
|
1
|
+
.page{position:absolute;backface-visibility:hidden;transform-style:preserve-3d;background:#fff;contain:layout style paint;--inner-shadow-shadow: 0;--inner-shadow-highlight: 0;--inner-shadow-edge: right}.page:before,.page:after{content:"";position:absolute;inset:0;pointer-events:none;backface-visibility:hidden;transition:opacity .12s ease;will-change:opacity}.page:before{background:linear-gradient(to var(--inner-shadow-edge),rgba(0,0,0,calc(.35 * var(--inner-shadow-shadow))) 0%,rgba(0,0,0,0) 40%);opacity:var(--inner-shadow-shadow);mix-blend-mode:multiply}.page:after{background:linear-gradient(to var(--inner-shadow-edge),rgba(255,255,255,calc(.4 * var(--inner-shadow-highlight))) 0%,rgba(255,255,255,0) 45%);opacity:var(--inner-shadow-highlight)}.flipbook--no-page-shadow .page:before,.flipbook--no-page-shadow .page:after{opacity:0!important}.page--flipping{contain:strict;-webkit-user-select:none;user-select:none;scrollbar-color:transparent transparent}.page--flipping::-webkit-scrollbar{display:none}.page--flipping *{scrollbar-color:transparent transparent!important}.page--flipping *::-webkit-scrollbar{display:none!important}.page>*{max-width:100%;max-height:100%;height:100%;width:100%;box-sizing:border-box}.flipbook{height:100%;width:100%;overflow:hidden}.flipbook-debug-bar{position:absolute;bottom:0;left:0;width:100%;min-height:48px;background-color:#00000080;color:#fff;padding:10px;box-sizing:border-box;display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;z-index:9999}.flipbook-debug-bar--hidden{display:none!important}.page--cover-interior{overflow:hidden}.page--cover-interior-inset{padding-top:var(--cover-inset, 5%);padding-bottom:var(--cover-inset, 5%);padding-left:var(--cover-inset-left, var(--cover-inset, 5%));padding-right:var(--cover-inset-right, var(--cover-inset, 5%));background:#fffef8;background-clip:content-box}.flipbook--select-text .page:not(.page--flipping){-webkit-user-select:text;user-select:text}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en-US.d.ts","sourceRoot":"","sources":["../../../src/intl/locales/en-US.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,QAAA,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"en-US.d.ts","sourceRoot":"","sources":["../../../src/intl/locales/en-US.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,QAAA,MAAM,IAAI,EAAE,YAuBX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"he-IL.d.ts","sourceRoot":"","sources":["../../../src/intl/locales/he-IL.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,QAAA,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"he-IL.d.ts","sourceRoot":"","sources":["../../../src/intl/locales/he-IL.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,QAAA,MAAM,IAAI,EAAE,YAuBX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/dist/intl.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const r = {
|
|
2
2
|
align: "left",
|
|
3
3
|
direction: "ltr",
|
|
4
4
|
translations: {
|
|
@@ -17,9 +17,11 @@ const d = {
|
|
|
17
17
|
"command.toggleFullscreenDesc": "Enter or exit fullscreen mode",
|
|
18
18
|
"command.toggleDebug": "Toggle debug toolbar",
|
|
19
19
|
"command.toggleDebugDesc": "Show or hide the debug toolbar (Ctrl+Alt+D)",
|
|
20
|
-
"toolbarItem.goToPage": "Go to page"
|
|
20
|
+
"toolbarItem.goToPage": "Go to page",
|
|
21
|
+
"toolbarItem.selectText": "Select text with mouse",
|
|
22
|
+
"toolbarItem.selectionLetters": "Aa"
|
|
21
23
|
}
|
|
22
|
-
},
|
|
24
|
+
}, d = {
|
|
23
25
|
align: "right",
|
|
24
26
|
direction: "rtl",
|
|
25
27
|
translations: {
|
|
@@ -38,11 +40,13 @@ const d = {
|
|
|
38
40
|
"command.toggleFullscreenDesc": "כניסה או יציאה ממסך מלא",
|
|
39
41
|
"command.toggleDebug": "סרגל כלים לדיבוג",
|
|
40
42
|
"command.toggleDebugDesc": "הצג או הסתר סרגל הדיבוג (Ctrl+Alt+D)",
|
|
41
|
-
"toolbarItem.goToPage": "מעבר לעמוד"
|
|
43
|
+
"toolbarItem.goToPage": "מעבר לעמוד",
|
|
44
|
+
"toolbarItem.selectText": "בחירת טקסט עם העכבר",
|
|
45
|
+
"toolbarItem.selectionLetters": "אב"
|
|
42
46
|
}
|
|
43
|
-
},
|
|
44
|
-
"en-US":
|
|
45
|
-
"he-IL":
|
|
47
|
+
}, a = {
|
|
48
|
+
"en-US": r,
|
|
49
|
+
"he-IL": d
|
|
46
50
|
}, n = "en-US", g = {
|
|
47
51
|
"toolbarItem.download": "Download",
|
|
48
52
|
"toolbarItem.downloadPageRange": "Download page range…",
|
|
@@ -62,7 +66,7 @@ const d = {
|
|
|
62
66
|
"toolbarItem.goToPage": "Go to page"
|
|
63
67
|
};
|
|
64
68
|
function l(o) {
|
|
65
|
-
return
|
|
69
|
+
return a[o] ?? a[n];
|
|
66
70
|
}
|
|
67
71
|
function c(o) {
|
|
68
72
|
return l(o).direction === "rtl";
|
|
@@ -73,8 +77,8 @@ function u(o) {
|
|
|
73
77
|
function i(o, m) {
|
|
74
78
|
const e = l(m).translations[o];
|
|
75
79
|
if (e !== void 0 && e !== "") return e;
|
|
76
|
-
const
|
|
77
|
-
return
|
|
80
|
+
const t = a[n].translations[o];
|
|
81
|
+
return t !== void 0 && t !== "" ? t : g[o] ?? o;
|
|
78
82
|
}
|
|
79
83
|
export {
|
|
80
84
|
n as defaultLocale,
|
package/dist/intl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.js","sources":["../src/intl/locales/en-US.ts","../src/intl/locales/he-IL.ts","../src/intl/index.ts"],"sourcesContent":["/**\n * en-US locale: LTR, with actual English translation values.\n */\nimport type { LocaleConfig } from \"../types\";\n\nconst enUS: LocaleConfig = {\n\talign: \"left\",\n\tdirection: \"ltr\",\n\ttranslations: {\n\t\t\"toolbarItem.download\": \"Download\",\n\t\t\"toolbarItem.downloadPageRange\": \"Download page range…\",\n\t\t\"toolbarItem.download.from\": \"From\",\n\t\t\"toolbarItem.download.to\": \"To\",\n\t\t\"toolbarItem.download.download\": \"Download\",\n\t\t\"command.downloadEntireBook\": \"Download entire book\",\n\t\t\"command.jumpToToc\": \"Table of contents\",\n\t\t\"command.jumpToFirstPage\": \"First page\",\n\t\t\"command.jumpToLastPage\": \"Last page\",\n\t\t\"command.jumpToPrevPage\": \"Previous page\",\n\t\t\"command.jumpToNextPage\": \"Next page\",\n\t\t\"command.toggleFullscreen\": \"Toggle fullscreen\",\n\t\t\"command.toggleFullscreenDesc\": \"Enter or exit fullscreen mode\",\n\t\t\"command.toggleDebug\": \"Toggle debug toolbar\",\n\t\t\"command.toggleDebugDesc\": \"Show or hide the debug toolbar (Ctrl+Alt+D)\",\n\t\t\"toolbarItem.goToPage\": \"Go to page\",\n\t},\n};\n\nexport default enUS;\n","/**\n * he-IL locale: RTL, Hebrew translations.\n */\nimport type { LocaleConfig } from \"../types\";\n\nconst heIL: LocaleConfig = {\n\talign: \"right\",\n\tdirection: \"rtl\",\n\ttranslations: {\n\t\t\"toolbarItem.download\": \"הורדה\",\n\t\t\"toolbarItem.downloadPageRange\": \"הורד טווח עמודים…\",\n\t\t\"toolbarItem.download.from\": \"מ\",\n\t\t\"toolbarItem.download.to\": \"עד\",\n\t\t\"toolbarItem.download.download\": \"הורד\",\n\t\t\"command.downloadEntireBook\": \"הורד את כל הספר\",\n\t\t\"command.jumpToToc\": \"תוכן העניינים\",\n\t\t\"command.jumpToFirstPage\": \"עמוד ראשון\",\n\t\t\"command.jumpToLastPage\": \"עמוד אחרון\",\n\t\t\"command.jumpToPrevPage\": \"עמוד קודם\",\n\t\t\"command.jumpToNextPage\": \"עמוד הבא\",\n\t\t\"command.toggleFullscreen\": \"מסך מלא\",\n\t\t\"command.toggleFullscreenDesc\": \"כניסה או יציאה ממסך מלא\",\n\t\t\"command.toggleDebug\": \"סרגל כלים לדיבוג\",\n\t\t\"command.toggleDebugDesc\": \"הצג או הסתר סרגל הדיבוג (Ctrl+Alt+D)\",\n\t\t\"toolbarItem.goToPage\": \"מעבר לעמוד\",\n\t},\n};\n\nexport default heIL;\n","/**\n * Intl at base level: locale config (align + translations) and helpers.\n * One file per locale: en-US (default), he-IL.\n */\nimport enUS from \"./locales/en-US\";\nimport heIL from \"./locales/he-IL\";\nimport type { Locale, LocaleConfig } from \"./types\";\n\nexport type { Locale, LocaleConfig } from \"./types\";\n\nconst configs: Record<Locale, LocaleConfig> = {\n\t\"en-US\": enUS,\n\t\"he-IL\": heIL,\n};\n\n/** Default locale. Used to derive default direction (LTR). */\nexport const defaultLocale: Locale = \"en-US\";\n\n/** Fallback when a key is missing (use en-US or key). */\nconst enFallbacks: Record<string, string> = {\n\t\"toolbarItem.download\": \"Download\",\n\t\"toolbarItem.downloadPageRange\": \"Download page range…\",\n\t\"toolbarItem.download.from\": \"From\",\n\t\"toolbarItem.download.to\": \"To\",\n\t\"toolbarItem.download.download\": \"Download\",\n\t\"command.downloadEntireBook\": \"Download entire book\",\n\t\"command.jumpToToc\": \"Table of contents\",\n\t\"command.jumpToFirstPage\": \"First page\",\n\t\"command.jumpToLastPage\": \"Last page\",\n\t\"command.jumpToPrevPage\": \"Previous page\",\n\t\"command.jumpToNextPage\": \"Next page\",\n\t\"command.toggleFullscreen\": \"Toggle fullscreen\",\n\t\"command.toggleFullscreenDesc\": \"Enter or exit fullscreen mode\",\n\t\"command.toggleDebug\": \"Toggle debug toolbar\",\n\t\"command.toggleDebugDesc\": \"Show or hide the debug toolbar (Ctrl+Alt+D)\",\n\t\"toolbarItem.goToPage\": \"Go to page\",\n};\n\nexport function getConfig(locale: Locale): LocaleConfig {\n\treturn configs[locale] ?? configs[defaultLocale];\n}\n\n/** Whether the locale is RTL (e.g. he-IL). */\nexport function isRtl(locale: Locale): boolean {\n\treturn getConfig(locale).direction === \"rtl\";\n}\n\n/** Resolve direction from locale. Default from intl. */\nexport function directionFromLocale(locale: Locale): \"ltr\" | \"rtl\" {\n\treturn isRtl(locale) ? \"rtl\" : \"ltr\";\n}\n\n/**\n * Translate key for locale. Returns config translation or fallback to en-US, then key.\n */\nexport function t(key: string, locale: Locale): string {\n\tconst cfg = getConfig(locale);\n\tconst value = cfg.translations[key];\n\tif (value !== undefined && value !== \"\") return value;\n\tconst en = configs[defaultLocale].translations[key];\n\tif (en !== undefined && en !== \"\") return en;\n\treturn enFallbacks[key] ?? key;\n}\n"],"names":["enUS","heIL","configs","defaultLocale","enFallbacks","getConfig","locale","isRtl","directionFromLocale","t","key","value","en"],"mappings":"AAKA,MAAMA,IAAqB;AAAA,EAC1B,OAAO;AAAA,EACP,WAAW;AAAA,EACX,cAAc;AAAA,IACb,wBAAwB;AAAA,IACxB,iCAAiC;AAAA,IACjC,6BAA6B;AAAA,IAC7B,2BAA2B;AAAA,IAC3B,iCAAiC;AAAA,IACjC,8BAA8B;AAAA,IAC9B,qBAAqB;AAAA,IACrB,2BAA2B;AAAA,IAC3B,0BAA0B;AAAA,IAC1B,0BAA0B;AAAA,IAC1B,0BAA0B;AAAA,IAC1B,4BAA4B;AAAA,IAC5B,gCAAgC;AAAA,IAChC,uBAAuB;AAAA,IACvB,2BAA2B;AAAA,IAC3B,wBAAwB;AAAA,EAAA;
|
|
1
|
+
{"version":3,"file":"intl.js","sources":["../src/intl/locales/en-US.ts","../src/intl/locales/he-IL.ts","../src/intl/index.ts"],"sourcesContent":["/**\n * en-US locale: LTR, with actual English translation values.\n */\nimport type { LocaleConfig } from \"../types\";\n\nconst enUS: LocaleConfig = {\n\talign: \"left\",\n\tdirection: \"ltr\",\n\ttranslations: {\n\t\t\"toolbarItem.download\": \"Download\",\n\t\t\"toolbarItem.downloadPageRange\": \"Download page range…\",\n\t\t\"toolbarItem.download.from\": \"From\",\n\t\t\"toolbarItem.download.to\": \"To\",\n\t\t\"toolbarItem.download.download\": \"Download\",\n\t\t\"command.downloadEntireBook\": \"Download entire book\",\n\t\t\"command.jumpToToc\": \"Table of contents\",\n\t\t\"command.jumpToFirstPage\": \"First page\",\n\t\t\"command.jumpToLastPage\": \"Last page\",\n\t\t\"command.jumpToPrevPage\": \"Previous page\",\n\t\t\"command.jumpToNextPage\": \"Next page\",\n\t\t\"command.toggleFullscreen\": \"Toggle fullscreen\",\n\t\t\"command.toggleFullscreenDesc\": \"Enter or exit fullscreen mode\",\n\t\t\"command.toggleDebug\": \"Toggle debug toolbar\",\n\t\t\"command.toggleDebugDesc\": \"Show or hide the debug toolbar (Ctrl+Alt+D)\",\n\t\t\"toolbarItem.goToPage\": \"Go to page\",\n\t\t\"toolbarItem.selectText\": \"Select text with mouse\",\n\t\t\"toolbarItem.selectionLetters\": \"Aa\",\n\t},\n};\n\nexport default enUS;\n","/**\n * he-IL locale: RTL, Hebrew translations.\n */\nimport type { LocaleConfig } from \"../types\";\n\nconst heIL: LocaleConfig = {\n\talign: \"right\",\n\tdirection: \"rtl\",\n\ttranslations: {\n\t\t\"toolbarItem.download\": \"הורדה\",\n\t\t\"toolbarItem.downloadPageRange\": \"הורד טווח עמודים…\",\n\t\t\"toolbarItem.download.from\": \"מ\",\n\t\t\"toolbarItem.download.to\": \"עד\",\n\t\t\"toolbarItem.download.download\": \"הורד\",\n\t\t\"command.downloadEntireBook\": \"הורד את כל הספר\",\n\t\t\"command.jumpToToc\": \"תוכן העניינים\",\n\t\t\"command.jumpToFirstPage\": \"עמוד ראשון\",\n\t\t\"command.jumpToLastPage\": \"עמוד אחרון\",\n\t\t\"command.jumpToPrevPage\": \"עמוד קודם\",\n\t\t\"command.jumpToNextPage\": \"עמוד הבא\",\n\t\t\"command.toggleFullscreen\": \"מסך מלא\",\n\t\t\"command.toggleFullscreenDesc\": \"כניסה או יציאה ממסך מלא\",\n\t\t\"command.toggleDebug\": \"סרגל כלים לדיבוג\",\n\t\t\"command.toggleDebugDesc\": \"הצג או הסתר סרגל הדיבוג (Ctrl+Alt+D)\",\n\t\t\"toolbarItem.goToPage\": \"מעבר לעמוד\",\n\t\t\"toolbarItem.selectText\": \"בחירת טקסט עם העכבר\",\n\t\t\"toolbarItem.selectionLetters\": \"אב\",\n\t},\n};\n\nexport default heIL;\n","/**\n * Intl at base level: locale config (align + translations) and helpers.\n * One file per locale: en-US (default), he-IL.\n */\nimport enUS from \"./locales/en-US\";\nimport heIL from \"./locales/he-IL\";\nimport type { Locale, LocaleConfig } from \"./types\";\n\nexport type { Locale, LocaleConfig } from \"./types\";\n\nconst configs: Record<Locale, LocaleConfig> = {\n\t\"en-US\": enUS,\n\t\"he-IL\": heIL,\n};\n\n/** Default locale. Used to derive default direction (LTR). */\nexport const defaultLocale: Locale = \"en-US\";\n\n/** Fallback when a key is missing (use en-US or key). */\nconst enFallbacks: Record<string, string> = {\n\t\"toolbarItem.download\": \"Download\",\n\t\"toolbarItem.downloadPageRange\": \"Download page range…\",\n\t\"toolbarItem.download.from\": \"From\",\n\t\"toolbarItem.download.to\": \"To\",\n\t\"toolbarItem.download.download\": \"Download\",\n\t\"command.downloadEntireBook\": \"Download entire book\",\n\t\"command.jumpToToc\": \"Table of contents\",\n\t\"command.jumpToFirstPage\": \"First page\",\n\t\"command.jumpToLastPage\": \"Last page\",\n\t\"command.jumpToPrevPage\": \"Previous page\",\n\t\"command.jumpToNextPage\": \"Next page\",\n\t\"command.toggleFullscreen\": \"Toggle fullscreen\",\n\t\"command.toggleFullscreenDesc\": \"Enter or exit fullscreen mode\",\n\t\"command.toggleDebug\": \"Toggle debug toolbar\",\n\t\"command.toggleDebugDesc\": \"Show or hide the debug toolbar (Ctrl+Alt+D)\",\n\t\"toolbarItem.goToPage\": \"Go to page\",\n};\n\nexport function getConfig(locale: Locale): LocaleConfig {\n\treturn configs[locale] ?? configs[defaultLocale];\n}\n\n/** Whether the locale is RTL (e.g. he-IL). */\nexport function isRtl(locale: Locale): boolean {\n\treturn getConfig(locale).direction === \"rtl\";\n}\n\n/** Resolve direction from locale. Default from intl. */\nexport function directionFromLocale(locale: Locale): \"ltr\" | \"rtl\" {\n\treturn isRtl(locale) ? \"rtl\" : \"ltr\";\n}\n\n/**\n * Translate key for locale. Returns config translation or fallback to en-US, then key.\n */\nexport function t(key: string, locale: Locale): string {\n\tconst cfg = getConfig(locale);\n\tconst value = cfg.translations[key];\n\tif (value !== undefined && value !== \"\") return value;\n\tconst en = configs[defaultLocale].translations[key];\n\tif (en !== undefined && en !== \"\") return en;\n\treturn enFallbacks[key] ?? key;\n}\n"],"names":["enUS","heIL","configs","defaultLocale","enFallbacks","getConfig","locale","isRtl","directionFromLocale","t","key","value","en"],"mappings":"AAKA,MAAMA,IAAqB;AAAA,EAC1B,OAAO;AAAA,EACP,WAAW;AAAA,EACX,cAAc;AAAA,IACb,wBAAwB;AAAA,IACxB,iCAAiC;AAAA,IACjC,6BAA6B;AAAA,IAC7B,2BAA2B;AAAA,IAC3B,iCAAiC;AAAA,IACjC,8BAA8B;AAAA,IAC9B,qBAAqB;AAAA,IACrB,2BAA2B;AAAA,IAC3B,0BAA0B;AAAA,IAC1B,0BAA0B;AAAA,IAC1B,0BAA0B;AAAA,IAC1B,4BAA4B;AAAA,IAC5B,gCAAgC;AAAA,IAChC,uBAAuB;AAAA,IACvB,2BAA2B;AAAA,IAC3B,wBAAwB;AAAA,IACxB,0BAA0B;AAAA,IAC1B,gCAAgC;AAAA,EAAA;AAElC,GCvBMC,IAAqB;AAAA,EAC1B,OAAO;AAAA,EACP,WAAW;AAAA,EACX,cAAc;AAAA,IACb,wBAAwB;AAAA,IACxB,iCAAiC;AAAA,IACjC,6BAA6B;AAAA,IAC7B,2BAA2B;AAAA,IAC3B,iCAAiC;AAAA,IACjC,8BAA8B;AAAA,IAC9B,qBAAqB;AAAA,IACrB,2BAA2B;AAAA,IAC3B,0BAA0B;AAAA,IAC1B,0BAA0B;AAAA,IAC1B,0BAA0B;AAAA,IAC1B,4BAA4B;AAAA,IAC5B,gCAAgC;AAAA,IAChC,uBAAuB;AAAA,IACvB,2BAA2B;AAAA,IAC3B,wBAAwB;AAAA,IACxB,0BAA0B;AAAA,IAC1B,gCAAgC;AAAA,EAAA;AAElC,GClBMC,IAAwC;AAAA,EAC7C,SAASF;AAAA,EACT,SAASC;AACV,GAGaE,IAAwB,SAG/BC,IAAsC;AAAA,EAC3C,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACj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