html-flip-book-react 0.0.0-alpha.23 → 0.0.0-alpha.24

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.
@@ -1,6 +1,6 @@
1
- import { jsx as n, jsxs as E } from "react/jsx-runtime";
2
- import { createContext as K, useContext as W, useMemo as D, useCallback as f, useEffect as $, useState as y, useRef as H } from "react";
3
- const ee = {
1
+ import { jsx as o, jsxs as L, Fragment as oe } from "react/jsx-runtime";
2
+ import { createContext as _, useContext as Q, useMemo as J, useCallback as w, useEffect as W, useState as C, useRef as K, useLayoutEffect as ne } from "react";
3
+ const re = {
4
4
  flipNext: [
5
5
  { key: "ArrowRight" },
6
6
  { key: "PageDown" },
@@ -12,7 +12,7 @@ const ee = {
12
12
  goToLast: [{ key: "End" }],
13
13
  goToToc: [{ key: "t" }],
14
14
  toggleFullscreen: [{ key: "f" }]
15
- }, te = [
15
+ }, ae = [
16
16
  {
17
17
  id: "flipNext",
18
18
  name: "Next Page",
@@ -52,14 +52,14 @@ const ee = {
52
52
  {
53
53
  id: "goToToc",
54
54
  name: "Table of Contents",
55
- description: "Jump to the table of contents",
55
+ description: "Go to the table of contents (with flip)",
56
56
  execute: ({ flipBookRef: e, data: t }) => {
57
- const o = t?.tocPageIndex ?? 4;
58
- e.current?.jumpToPage(o);
57
+ const n = t?.tocPageIndex ?? 4;
58
+ e.current?.goToPage(n);
59
59
  },
60
60
  canExecute: ({ currentPage: e, data: t }) => {
61
- const o = t?.tocPageIndex ?? 4;
62
- return e !== o;
61
+ const n = t?.tocPageIndex ?? 4;
62
+ return e !== n;
63
63
  }
64
64
  },
65
65
  {
@@ -71,108 +71,108 @@ const ee = {
71
71
  document.fullscreenElement ? document.exitFullscreen().catch(console.warn) : (t?.current ?? document.documentElement).requestFullscreen().catch(console.warn);
72
72
  }
73
73
  }
74
- ], O = K(null);
75
- function ne(e, t) {
74
+ ], Z = _(null);
75
+ function le(e, t) {
76
76
  if (t.key !== e.key) return !1;
77
- const o = e.modifiers ?? {};
78
- return !(!!o.ctrl !== t.ctrlKey || !!o.shift !== t.shiftKey || !!o.alt !== t.altKey || !!o.meta !== t.metaKey);
77
+ const n = e.modifiers ?? {};
78
+ return !(!!n.ctrl !== t.ctrlKey || !!n.shift !== t.shiftKey || !!n.alt !== t.altKey || !!n.meta !== t.metaKey);
79
79
  }
80
- const oe = ({
80
+ const se = ({
81
81
  flipBookRef: e,
82
82
  currentPage: t,
83
- totalPages: o,
84
- direction: l = "ltr",
85
- commands: s = [],
86
- commandOptions: u = {},
87
- disableHotkeys: h = !1,
88
- children: g
83
+ totalPages: n,
84
+ direction: r = "ltr",
85
+ commands: i = [],
86
+ commandOptions: d = {},
87
+ disableHotkeys: g = !1,
88
+ children: m
89
89
  }) => {
90
- const r = D(() => {
91
- const i = {};
92
- for (const a of te)
93
- i[a.id] = {
94
- command: a,
95
- options: u[a.id] ?? {}
90
+ const c = J(() => {
91
+ const a = {};
92
+ for (const l of ae)
93
+ a[l.id] = {
94
+ command: l,
95
+ options: d[l.id] ?? {}
96
96
  };
97
- for (const a of s)
98
- i[a.id] = {
99
- command: a,
100
- options: u[a.id] ?? {}
97
+ for (const l of i)
98
+ a[l.id] = {
99
+ command: l,
100
+ options: d[l.id] ?? {}
101
101
  };
102
- return i;
103
- }, [s, u]), x = f(
104
- (i) => {
105
- const a = r[i]?.options ?? {};
102
+ return a;
103
+ }, [i, d]), p = w(
104
+ (a) => {
105
+ const l = c[a]?.options ?? {};
106
106
  return {
107
107
  flipBookRef: e,
108
108
  currentPage: t,
109
- totalPages: o,
110
- direction: l,
111
- data: a.data
109
+ totalPages: n,
110
+ direction: r,
111
+ data: l.data
112
112
  };
113
113
  },
114
- [e, t, o, l, r]
115
- ), m = f(
116
- (i) => {
117
- const a = r[i];
118
- if (!a) {
119
- console.warn(`Command "${i}" not found`);
114
+ [e, t, n, r, c]
115
+ ), h = w(
116
+ (a) => {
117
+ const l = c[a];
118
+ if (!l) {
119
+ console.warn(`Command "${a}" not found`);
120
120
  return;
121
121
  }
122
- const d = x(i);
123
- a.command.canExecute && !a.command.canExecute(d) || a.command.execute(d);
122
+ const b = p(a);
123
+ l.command.canExecute && !l.command.canExecute(b) || l.command.execute(b);
124
124
  },
125
- [r, x]
126
- ), p = f(
127
- (i) => {
128
- const a = r[i];
129
- if (!a) return !1;
130
- const d = x(i);
131
- return a.command.canExecute ? a.command.canExecute(d) : !0;
125
+ [c, p]
126
+ ), P = w(
127
+ (a) => {
128
+ const l = c[a];
129
+ if (!l) return !1;
130
+ const b = p(a);
131
+ return l.command.canExecute ? l.command.canExecute(b) : !0;
132
132
  },
133
- [r, x]
134
- ), k = f(
135
- (i) => r[i]?.command,
136
- [r]
137
- ), b = f(
138
- () => Object.values(r).map((i) => i.command),
139
- [r]
140
- ), w = f(
141
- (i) => {
142
- const a = i.target;
143
- if (!(a.tagName === "INPUT" || a.tagName === "TEXTAREA" || a.isContentEditable))
144
- for (const [d, F] of Object.entries(r)) {
145
- if (F.options.disableHotkeys) continue;
146
- const z = F.options.hotkeys ?? ee[d] ?? [];
147
- for (const j of z)
148
- if (ne(j, i)) {
149
- i.preventDefault(), m(d);
133
+ [c, p]
134
+ ), y = w(
135
+ (a) => c[a]?.command,
136
+ [c]
137
+ ), N = w(
138
+ () => Object.values(c).map((a) => a.command),
139
+ [c]
140
+ ), x = w(
141
+ (a) => {
142
+ const l = a.target;
143
+ if (!(l.tagName === "INPUT" || l.tagName === "TEXTAREA" || l.isContentEditable))
144
+ for (const [b, v] of Object.entries(c)) {
145
+ if (v.options.disableHotkeys) continue;
146
+ const I = v.options.hotkeys ?? re[b] ?? [];
147
+ for (const R of I)
148
+ if (le(R, a)) {
149
+ a.preventDefault(), h(b);
150
150
  return;
151
151
  }
152
152
  }
153
153
  },
154
- [r, m]
154
+ [c, h]
155
155
  );
156
- $(() => {
157
- if (!h)
158
- return document.addEventListener("keydown", w), () => document.removeEventListener("keydown", w);
159
- }, [h, w]);
160
- const P = D(
156
+ W(() => {
157
+ if (!g)
158
+ return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
159
+ }, [g, x]);
160
+ const E = J(
161
161
  () => ({
162
- executeCommand: m,
163
- canExecute: p,
164
- getCommand: k,
165
- getAllCommands: b
162
+ executeCommand: h,
163
+ canExecute: P,
164
+ getCommand: y,
165
+ getAllCommands: N
166
166
  }),
167
- [m, p, k, b]
167
+ [h, P, y, N]
168
168
  );
169
- return /* @__PURE__ */ n(O.Provider, { value: P, children: g });
170
- }, ue = () => {
171
- const e = W(O);
169
+ return /* @__PURE__ */ o(Z.Provider, { value: E, children: m });
170
+ }, ve = () => {
171
+ const e = Q(Z);
172
172
  if (!e)
173
173
  throw new Error("useCommands must be used within a CommandProvider");
174
174
  return e;
175
- }, C = { size: 24 }, q = ({ size: e = C.size, className: t }) => /* @__PURE__ */ n(
175
+ }, $ = { size: 24 }, ie = ({ size: e = $.size, className: t }) => /* @__PURE__ */ o(
176
176
  "svg",
177
177
  {
178
178
  xmlns: "http://www.w3.org/2000/svg",
@@ -186,9 +186,9 @@ const oe = ({
186
186
  strokeLinejoin: "round",
187
187
  className: t,
188
188
  "aria-hidden": "true",
189
- children: /* @__PURE__ */ n("path", { d: "m15 18-6-6 6-6" })
189
+ children: /* @__PURE__ */ o("path", { d: "m15 18-6-6 6-6" })
190
190
  }
191
- ), V = ({ size: e = C.size, className: t }) => /* @__PURE__ */ n(
191
+ ), ce = ({ size: e = $.size, className: t }) => /* @__PURE__ */ o(
192
192
  "svg",
193
193
  {
194
194
  xmlns: "http://www.w3.org/2000/svg",
@@ -202,9 +202,9 @@ const oe = ({
202
202
  strokeLinejoin: "round",
203
203
  className: t,
204
204
  "aria-hidden": "true",
205
- children: /* @__PURE__ */ n("path", { d: "m9 18 6-6-6-6" })
205
+ children: /* @__PURE__ */ o("path", { d: "m9 18 6-6-6-6" })
206
206
  }
207
- ), J = ({ size: e = C.size, className: t }) => /* @__PURE__ */ E(
207
+ ), de = ({ size: e = $.size, className: t }) => /* @__PURE__ */ L(
208
208
  "svg",
209
209
  {
210
210
  xmlns: "http://www.w3.org/2000/svg",
@@ -219,11 +219,11 @@ const oe = ({
219
219
  className: t,
220
220
  "aria-hidden": "true",
221
221
  children: [
222
- /* @__PURE__ */ n("path", { d: "m17 18-6-6 6-6" }),
223
- /* @__PURE__ */ n("path", { d: "M7 6v12" })
222
+ /* @__PURE__ */ o("path", { d: "m17 18-6-6 6-6" }),
223
+ /* @__PURE__ */ o("path", { d: "M7 6v12" })
224
224
  ]
225
225
  }
226
- ), U = ({ size: e = C.size, className: t }) => /* @__PURE__ */ E(
226
+ ), ue = ({ size: e = $.size, className: t }) => /* @__PURE__ */ L(
227
227
  "svg",
228
228
  {
229
229
  xmlns: "http://www.w3.org/2000/svg",
@@ -238,11 +238,11 @@ const oe = ({
238
238
  className: t,
239
239
  "aria-hidden": "true",
240
240
  children: [
241
- /* @__PURE__ */ n("path", { d: "m7 18 6-6-6-6" }),
242
- /* @__PURE__ */ n("path", { d: "M17 6v12" })
241
+ /* @__PURE__ */ o("path", { d: "m7 18 6-6-6-6" }),
242
+ /* @__PURE__ */ o("path", { d: "M17 6v12" })
243
243
  ]
244
244
  }
245
- ), re = ({ size: e = C.size, className: t }) => /* @__PURE__ */ E(
245
+ ), ge = ({ size: e = $.size, className: t }) => /* @__PURE__ */ L(
246
246
  "svg",
247
247
  {
248
248
  xmlns: "http://www.w3.org/2000/svg",
@@ -257,13 +257,13 @@ const oe = ({
257
257
  className: t,
258
258
  "aria-hidden": "true",
259
259
  children: [
260
- /* @__PURE__ */ n("path", { d: "M8 3H5a2 2 0 0 0-2 2v3" }),
261
- /* @__PURE__ */ n("path", { d: "M21 8V5a2 2 0 0 0-2-2h-3" }),
262
- /* @__PURE__ */ n("path", { d: "M3 16v3a2 2 0 0 0 2 2h3" }),
263
- /* @__PURE__ */ n("path", { d: "M16 21h3a2 2 0 0 0 2-2v-3" })
260
+ /* @__PURE__ */ o("path", { d: "M8 3H5a2 2 0 0 0-2 2v3" }),
261
+ /* @__PURE__ */ o("path", { d: "M21 8V5a2 2 0 0 0-2-2h-3" }),
262
+ /* @__PURE__ */ o("path", { d: "M3 16v3a2 2 0 0 0 2 2h3" }),
263
+ /* @__PURE__ */ o("path", { d: "M16 21h3a2 2 0 0 0 2-2v-3" })
264
264
  ]
265
265
  }
266
- ), ie = ({ size: e = C.size, className: t }) => /* @__PURE__ */ E(
266
+ ), he = ({ size: e = $.size, className: t }) => /* @__PURE__ */ L(
267
267
  "svg",
268
268
  {
269
269
  xmlns: "http://www.w3.org/2000/svg",
@@ -278,16 +278,16 @@ const oe = ({
278
278
  className: t,
279
279
  "aria-hidden": "true",
280
280
  children: [
281
- /* @__PURE__ */ n("path", { d: "M8 3v3a2 2 0 0 1-2 2H3" }),
282
- /* @__PURE__ */ n("path", { d: "M21 8h-3a2 2 0 0 1-2-2V3" }),
283
- /* @__PURE__ */ n("path", { d: "M3 16h3a2 2 0 0 1 2 2v3" }),
284
- /* @__PURE__ */ n("path", { d: "M16 21v-3a2 2 0 0 1 2-2h3" })
281
+ /* @__PURE__ */ o("path", { d: "M8 3v3a2 2 0 0 1-2 2H3" }),
282
+ /* @__PURE__ */ o("path", { d: "M21 8h-3a2 2 0 0 1-2-2V3" }),
283
+ /* @__PURE__ */ o("path", { d: "M3 16h3a2 2 0 0 1 2 2v3" }),
284
+ /* @__PURE__ */ o("path", { d: "M16 21v-3a2 2 0 0 1 2-2h3" })
285
285
  ]
286
286
  }
287
- ), ae = ({
288
- size: e = C.size,
287
+ ), me = ({
288
+ size: e = $.size,
289
289
  className: t
290
- }) => /* @__PURE__ */ E(
290
+ }) => /* @__PURE__ */ L(
291
291
  "svg",
292
292
  {
293
293
  xmlns: "http://www.w3.org/2000/svg",
@@ -302,15 +302,15 @@ const oe = ({
302
302
  className: t,
303
303
  "aria-hidden": "true",
304
304
  children: [
305
- /* @__PURE__ */ n("path", { d: "M16 5H3" }),
306
- /* @__PURE__ */ n("path", { d: "M16 12H3" }),
307
- /* @__PURE__ */ n("path", { d: "M16 19H3" }),
308
- /* @__PURE__ */ n("path", { d: "M21 5h.01" }),
309
- /* @__PURE__ */ n("path", { d: "M21 12h.01" }),
310
- /* @__PURE__ */ n("path", { d: "M21 19h.01" })
305
+ /* @__PURE__ */ o("path", { d: "M16 5H3" }),
306
+ /* @__PURE__ */ o("path", { d: "M16 12H3" }),
307
+ /* @__PURE__ */ o("path", { d: "M16 19H3" }),
308
+ /* @__PURE__ */ o("path", { d: "M21 5h.01" }),
309
+ /* @__PURE__ */ o("path", { d: "M21 12h.01" }),
310
+ /* @__PURE__ */ o("path", { d: "M21 19h.01" })
311
311
  ]
312
312
  }
313
- ), de = ({ size: e = C.size, className: t }) => /* @__PURE__ */ E(
313
+ ), Pe = ({ size: e = $.size, className: t }) => /* @__PURE__ */ L(
314
314
  "svg",
315
315
  {
316
316
  xmlns: "http://www.w3.org/2000/svg",
@@ -325,314 +325,537 @@ const oe = ({
325
325
  className: t,
326
326
  "aria-hidden": "true",
327
327
  children: [
328
- /* @__PURE__ */ n("path", { d: "M3 21h18" }),
329
- /* @__PURE__ */ n("rect", { x: "4", y: "7", width: "3", height: "14", rx: "0.5" }),
330
- /* @__PURE__ */ n("rect", { x: "8", y: "5", width: "3", height: "16", rx: "0.5" }),
331
- /* @__PURE__ */ n("rect", { x: "12", y: "9", width: "3", height: "12", rx: "0.5" }),
332
- /* @__PURE__ */ n("rect", { x: "16", y: "6", width: "4", height: "15", rx: "0.5" })
328
+ /* @__PURE__ */ o("path", { d: "M3 21h18" }),
329
+ /* @__PURE__ */ o("rect", { x: "4", y: "7", width: "3", height: "14", rx: "0.5" }),
330
+ /* @__PURE__ */ o("rect", { x: "8", y: "5", width: "3", height: "16", rx: "0.5" }),
331
+ /* @__PURE__ */ o("rect", { x: "12", y: "9", width: "3", height: "12", rx: "0.5" }),
332
+ /* @__PURE__ */ o("rect", { x: "16", y: "6", width: "4", height: "15", rx: "0.5" })
333
333
  ]
334
334
  }
335
- ), L = ({
335
+ ), fe = ({ size: e = $.size, className: t }) => /* @__PURE__ */ L(
336
+ "svg",
337
+ {
338
+ xmlns: "http://www.w3.org/2000/svg",
339
+ width: e,
340
+ height: e,
341
+ viewBox: "0 0 24 24",
342
+ fill: "none",
343
+ stroke: "currentColor",
344
+ strokeWidth: "2",
345
+ strokeLinecap: "round",
346
+ strokeLinejoin: "round",
347
+ className: t,
348
+ "aria-hidden": "true",
349
+ children: [
350
+ /* @__PURE__ */ o("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
351
+ /* @__PURE__ */ o("polyline", { points: "7 10 12 15 17 10" }),
352
+ /* @__PURE__ */ o("line", { x1: "12", x2: "12", y1: "15", y2: "3" })
353
+ ]
354
+ }
355
+ ), z = ({
336
356
  onClick: e,
337
357
  ariaLabel: t,
338
- disabled: o = !1,
339
- children: l,
340
- className: s = "",
341
- title: u
342
- }) => /* @__PURE__ */ n(
358
+ disabled: n = !1,
359
+ children: r,
360
+ className: i = "",
361
+ title: d
362
+ }) => /* @__PURE__ */ o(
343
363
  "button",
344
364
  {
345
365
  type: "button",
346
366
  onClick: e,
347
367
  "aria-label": t,
348
- disabled: o,
349
- title: u ?? t,
350
- className: `flipbook-toolbar-button ${s}`.trim(),
351
- children: l
368
+ disabled: n,
369
+ title: d ?? t,
370
+ className: `flipbook-toolbar-button ${i}`.trim(),
371
+ children: r
352
372
  }
353
- ), he = ({
373
+ ), Ce = ({
354
374
  onClick: e,
355
375
  ariaLabel: t,
356
- children: o,
357
- disabled: l = !1,
358
- className: s
359
- }) => /* @__PURE__ */ n(
360
- L,
376
+ children: n,
377
+ disabled: r = !1,
378
+ className: i
379
+ }) => /* @__PURE__ */ o(
380
+ z,
361
381
  {
362
382
  onClick: e,
363
383
  ariaLabel: t,
364
- disabled: l,
365
- className: `flipbook-toolbar-action ${s ?? ""}`.trim(),
366
- children: o
384
+ disabled: r,
385
+ className: `flipbook-toolbar-action ${i ?? ""}`.trim(),
386
+ children: n
367
387
  }
368
- ), G = K(null);
369
- function N() {
370
- const e = W(G);
388
+ ), X = {
389
+ en: {
390
+ "toolbar.download": "Download",
391
+ "toolbar.downloadEntireBook": "Download entire book",
392
+ "toolbar.downloadPageRange": "Download page range…",
393
+ "toolbar.toc": "Table of contents",
394
+ "toolbar.firstPage": "First page",
395
+ "toolbar.lastPage": "Last page",
396
+ "toolbar.prevPage": "Previous page",
397
+ "toolbar.nextPage": "Next page",
398
+ "toolbar.goToPage": "Go to page",
399
+ "download.from": "From",
400
+ "download.to": "To",
401
+ "download.download": "Download"
402
+ },
403
+ "he-IL": {
404
+ "toolbar.download": "הורדה",
405
+ "toolbar.downloadEntireBook": "הורד את כל הספר",
406
+ "toolbar.downloadPageRange": "הורד טווח עמודים…",
407
+ "toolbar.toc": "תוכן העניינים",
408
+ "toolbar.firstPage": "עמוד ראשון",
409
+ "toolbar.lastPage": "עמוד אחרון",
410
+ "toolbar.prevPage": "עמוד קודם",
411
+ "toolbar.nextPage": "עמוד הבא",
412
+ "toolbar.goToPage": "מעבר לעמוד",
413
+ "download.from": "מ",
414
+ "download.to": "עד",
415
+ "download.download": "הורד"
416
+ }
417
+ };
418
+ function D(e, t = "en") {
419
+ return X[t]?.[e] ?? X.en[e] ?? e;
420
+ }
421
+ function pe(e) {
422
+ return e === "he-IL";
423
+ }
424
+ const ee = _(null);
425
+ function S() {
426
+ const e = Q(ee);
371
427
  if (!e)
372
428
  throw new Error("Toolbar components must be used within a Toolbar");
373
429
  return e;
374
430
  }
375
- const me = ({ children: e, className: t }) => {
376
- const { flipBookRef: o, isFirstPage: l, direction: s } = N(), u = () => {
377
- o.current?.jumpToPage(0);
378
- }, h = s === "rtl" ? /* @__PURE__ */ n(U, { size: 18 }) : /* @__PURE__ */ n(J, { size: 18 });
379
- return /* @__PURE__ */ n(
380
- L,
431
+ function Y(e, t) {
432
+ try {
433
+ const n = atob(e.data), r = new Uint8Array(n.length);
434
+ for (let m = 0; m < n.length; m++)
435
+ r[m] = n.charCodeAt(m);
436
+ const i = new Blob([r]), d = URL.createObjectURL(i), g = document.createElement("a");
437
+ g.href = d, g.download = `${t}.${e.ext}`, g.click(), URL.revokeObjectURL(d);
438
+ } catch (n) {
439
+ console.error("Download failed:", n);
440
+ }
441
+ }
442
+ function be(e, t) {
443
+ const n = [];
444
+ for (let r = 0; r < e; r++) {
445
+ const i = t?.indexToSemanticName(r) ?? String(r + 1), d = t?.indexToTitle(r) ?? `Page ${r + 1}`;
446
+ n.push({ pageIndex: r, semanticName: i, title: d });
447
+ }
448
+ return n;
449
+ }
450
+ const ye = ({
451
+ onDownloadSefer: e,
452
+ onDownloadPageRange: t,
453
+ downloadContext: n,
454
+ ariaLabel: r = "Download",
455
+ entireBookFilename: i = "book",
456
+ rangeFilename: d = "pages",
457
+ className: g
458
+ }) => {
459
+ const { totalPages: m, pageSemantics: c, locale: p } = S(), [h, P] = C(!1), [y, N] = C(!1), [x, E] = C(0), [a, l] = C(0), [b, v] = C(null), [I, R] = C(!1), k = K(null), H = K(null), B = be(m, c), j = !!e, A = !!t, q = j || A, F = w(() => {
460
+ P(!1), N(!1);
461
+ }, []);
462
+ ne(() => {
463
+ if (!h || !H.current || !k.current) return;
464
+ const s = H.current, M = k.current.querySelector(".flipbook-toolbar-download-trigger"), U = () => {
465
+ const f = M?.getBoundingClientRect();
466
+ if (!f) return;
467
+ const T = s.getBoundingClientRect().height, te = window.innerHeight - f.bottom;
468
+ R(te < T + 8);
469
+ };
470
+ U();
471
+ const u = new ResizeObserver(U);
472
+ return u.observe(s), () => u.disconnect();
473
+ }, [h]), W(() => {
474
+ if (!h) return;
475
+ const s = (M) => {
476
+ k.current && !k.current.contains(M.target) && F();
477
+ };
478
+ return document.addEventListener("mousedown", s), () => document.removeEventListener("mousedown", s);
479
+ }, [h, F]);
480
+ const O = w(async () => {
481
+ if (e) {
482
+ v("sefer");
483
+ try {
484
+ const s = await e();
485
+ s && Y(s, i), F();
486
+ } finally {
487
+ v(null);
488
+ }
489
+ }
490
+ }, [e, i, F]), V = w(() => {
491
+ E(0), l(Math.max(0, m - 1)), N(!0), P(!0);
492
+ }, [m]), G = w(async () => {
493
+ if (!t) return;
494
+ const s = Math.min(x, a), M = Math.max(x, a), U = [], u = [];
495
+ for (let f = s; f <= M; f++) {
496
+ U.push(f);
497
+ const T = B[f];
498
+ T && u.push(T);
499
+ }
500
+ v("range");
501
+ try {
502
+ const f = await t(U, u, n);
503
+ f && Y(f, `${d}-${s + 1}-${M + 1}`), F();
504
+ } finally {
505
+ v(null);
506
+ }
507
+ }, [
508
+ t,
509
+ x,
510
+ a,
511
+ B,
512
+ n,
513
+ d,
514
+ F
515
+ ]);
516
+ return q ? /* @__PURE__ */ L("div", { className: `flipbook-toolbar-download-wrap ${g ?? ""}`.trim(), ref: k, children: [
517
+ /* @__PURE__ */ o(
518
+ "button",
519
+ {
520
+ type: "button",
521
+ className: "flipbook-toolbar-button flipbook-toolbar-download-trigger",
522
+ onClick: () => P((s) => !s),
523
+ "aria-label": r ?? D("toolbar.download", p),
524
+ "aria-expanded": h,
525
+ "aria-haspopup": "true",
526
+ disabled: b !== null,
527
+ children: /* @__PURE__ */ o(fe, { size: 18 })
528
+ }
529
+ ),
530
+ h && /* @__PURE__ */ L(
531
+ "div",
532
+ {
533
+ ref: H,
534
+ className: `flipbook-toolbar-download-menu ${I ? "flipbook-toolbar-download-menu--open-up" : ""}`.trim(),
535
+ role: "menu",
536
+ dir: pe(p) ? "rtl" : "ltr",
537
+ children: [
538
+ j && /* @__PURE__ */ o(
539
+ "button",
540
+ {
541
+ type: "button",
542
+ role: "menuitem",
543
+ className: "flipbook-toolbar-download-menuitem",
544
+ onClick: O,
545
+ disabled: b !== null,
546
+ children: b === "sefer" ? "…" : D("toolbar.downloadEntireBook", p)
547
+ }
548
+ ),
549
+ A && /* @__PURE__ */ L(oe, { children: [
550
+ /* @__PURE__ */ o(
551
+ "button",
552
+ {
553
+ type: "button",
554
+ role: "menuitem",
555
+ className: "flipbook-toolbar-download-menuitem",
556
+ onClick: V,
557
+ disabled: b !== null,
558
+ children: D("toolbar.downloadPageRange", p)
559
+ }
560
+ ),
561
+ y && /* @__PURE__ */ L("div", { className: "flipbook-toolbar-download-range", children: [
562
+ /* @__PURE__ */ L("label", { className: "flipbook-toolbar-download-range-label", children: [
563
+ D("download.from", p),
564
+ /* @__PURE__ */ o(
565
+ "select",
566
+ {
567
+ value: x,
568
+ onChange: (s) => E(Number(s.target.value)),
569
+ className: "flipbook-toolbar-download-range-select",
570
+ children: B.map((s) => /* @__PURE__ */ o("option", { value: s.pageIndex, children: s.semanticName || s.title || `Page ${s.pageIndex + 1}` }, s.pageIndex))
571
+ }
572
+ )
573
+ ] }),
574
+ /* @__PURE__ */ L("label", { className: "flipbook-toolbar-download-range-label", children: [
575
+ D("download.to", p),
576
+ /* @__PURE__ */ o(
577
+ "select",
578
+ {
579
+ value: a,
580
+ onChange: (s) => l(Number(s.target.value)),
581
+ className: "flipbook-toolbar-download-range-select",
582
+ children: B.map((s) => /* @__PURE__ */ o("option", { value: s.pageIndex, children: s.semanticName || s.title || `Page ${s.pageIndex + 1}` }, s.pageIndex))
583
+ }
584
+ )
585
+ ] }),
586
+ /* @__PURE__ */ o(
587
+ "button",
588
+ {
589
+ type: "button",
590
+ className: "flipbook-toolbar-download-range-download",
591
+ onClick: G,
592
+ disabled: b !== null,
593
+ children: b === "range" ? "…" : D("download.download", p)
594
+ }
595
+ )
596
+ ] })
597
+ ] })
598
+ ]
599
+ }
600
+ )
601
+ ] }) : null;
602
+ }, Le = ({ children: e, className: t }) => {
603
+ const { flipBookRef: n, isFirstPage: r } = S(), i = () => {
604
+ n.current?.jumpToPage(0);
605
+ }, d = /* @__PURE__ */ o(de, { size: 18 });
606
+ return /* @__PURE__ */ o(
607
+ z,
381
608
  {
382
- onClick: u,
609
+ onClick: i,
383
610
  ariaLabel: "First page",
384
- disabled: l,
611
+ disabled: r,
385
612
  className: `flipbook-toolbar-first ${t ?? ""}`.trim(),
386
- children: e ?? h
613
+ children: e ?? d
387
614
  }
388
615
  );
389
- }, ge = ({
616
+ }, Te = ({
390
617
  targetRef: e,
391
618
  enterIcon: t,
392
- exitIcon: o,
393
- ariaLabelEnter: l = "Enter fullscreen",
394
- ariaLabelExit: s = "Exit fullscreen",
395
- className: u
619
+ exitIcon: n,
620
+ ariaLabelEnter: r = "Enter fullscreen",
621
+ ariaLabelExit: i = "Exit fullscreen",
622
+ className: d
396
623
  }) => {
397
- const [h, g] = y(!1), r = f(() => {
398
- g(!!document.fullscreenElement);
624
+ const [g, m] = C(!1), c = w(() => {
625
+ m(!!document.fullscreenElement);
399
626
  }, []);
400
- $(() => (document.addEventListener("fullscreenchange", r), () => {
401
- document.removeEventListener("fullscreenchange", r);
402
- }), [r]);
403
- const x = async () => {
627
+ W(() => (document.addEventListener("fullscreenchange", c), () => {
628
+ document.removeEventListener("fullscreenchange", c);
629
+ }), [c]);
630
+ const p = async () => {
404
631
  try {
405
- h ? await document.exitFullscreen() : await (e?.current ?? document.documentElement).requestFullscreen();
406
- } catch (k) {
407
- console.warn("Fullscreen request failed:", k);
632
+ g ? await document.exitFullscreen() : await (e?.current ?? document.documentElement).requestFullscreen();
633
+ } catch (y) {
634
+ console.warn("Fullscreen request failed:", y);
408
635
  }
409
- }, m = h ? s : l, p = h ? o ?? /* @__PURE__ */ n(ie, { size: 18 }) : t ?? /* @__PURE__ */ n(re, { size: 18 });
410
- return /* @__PURE__ */ n(
411
- L,
636
+ }, h = g ? i : r, P = g ? n ?? /* @__PURE__ */ o(he, { size: 18 }) : t ?? /* @__PURE__ */ o(ge, { size: 18 });
637
+ return /* @__PURE__ */ o(
638
+ z,
412
639
  {
413
- onClick: x,
414
- ariaLabel: m,
415
- className: `flipbook-toolbar-fullscreen ${h ? "flipbook-toolbar-fullscreen--active" : ""} ${u ?? ""}`.trim(),
416
- children: p
640
+ onClick: p,
641
+ ariaLabel: h,
642
+ className: `flipbook-toolbar-fullscreen ${g ? "flipbook-toolbar-fullscreen--active" : ""} ${d ?? ""}`.trim(),
643
+ children: P
417
644
  }
418
645
  );
419
- }, fe = ({ children: e, className: t }) => {
420
- const { flipBookRef: o, isLastPage: l, totalPages: s, direction: u } = N(), h = () => {
421
- o.current?.jumpToPage(s - 1);
422
- }, g = u === "rtl" ? /* @__PURE__ */ n(J, { size: 18 }) : /* @__PURE__ */ n(U, { size: 18 });
423
- return /* @__PURE__ */ n(
424
- L,
646
+ }, Ne = ({ children: e, className: t }) => {
647
+ const { flipBookRef: n, isLastPage: r, totalPages: i } = S(), d = () => {
648
+ n.current?.jumpToPage(i - 1);
649
+ }, g = /* @__PURE__ */ o(ue, { size: 18 });
650
+ return /* @__PURE__ */ o(
651
+ z,
425
652
  {
426
- onClick: h,
653
+ onClick: d,
427
654
  ariaLabel: "Last page",
428
- disabled: l,
655
+ disabled: r,
429
656
  className: `flipbook-toolbar-last ${t ?? ""}`.trim(),
430
657
  children: e ?? g
431
658
  }
432
659
  );
433
- }, pe = ({ children: e, className: t }) => {
434
- const { flipBookRef: o, isLastPage: l, direction: s } = N(), u = () => {
435
- o.current?.flipNext();
436
- }, h = s === "rtl" ? "Previous page" : "Next page", g = s === "rtl" ? /* @__PURE__ */ n(q, { size: 20 }) : /* @__PURE__ */ n(V, { size: 20 });
437
- return /* @__PURE__ */ n(
438
- L,
660
+ }, Ee = ({ children: e, className: t }) => {
661
+ const { flipBookRef: n, isLastPage: r, direction: i } = S(), d = () => {
662
+ n.current?.flipNext();
663
+ }, g = i === "rtl" ? "Previous page" : "Next page", m = /* @__PURE__ */ o(ce, { size: 20 });
664
+ return /* @__PURE__ */ o(
665
+ z,
439
666
  {
440
- onClick: u,
441
- ariaLabel: h,
442
- disabled: l,
667
+ onClick: d,
668
+ ariaLabel: g,
669
+ disabled: r,
443
670
  className: `flipbook-toolbar-next ${t ?? ""}`.trim(),
444
- children: e ?? g
671
+ children: e ?? m
445
672
  }
446
673
  );
447
- }, xe = ({
674
+ }, Ie = ({
448
675
  mode: e,
449
676
  showTotal: t = !0,
450
- placeholder: o = "—",
451
- editable: l,
452
- className: s,
453
- ariaLabel: u = "Go to page",
454
- maxLength: h = 10
677
+ placeholder: n = "—",
678
+ editable: r,
679
+ className: i,
680
+ ariaLabel: d = "Go to page",
681
+ maxLength: g = 10
455
682
  }) => {
456
- const { flipBookRef: g, pageSemantics: r, direction: x, currentPage: m, totalPages: p } = N(), k = e ?? (r ? "semantic" : "index"), b = l ?? (k === "semantic" && !!r), [w, P] = y(""), [i, a] = y(!1), d = H(!1), F = H(m), z = m, j = m + 1 < p ? m + 1 : null, S = f(
457
- (c) => k === "semantic" && r ? r.indexToSemanticName(c) || "" : String(c + 1),
458
- [k, r]
459
- ), I = S(z), B = j != null ? S(j) : "", R = f(() => {
460
- if (k === "semantic" && r) {
461
- for (let c = p - 1; c >= 0; c--) {
462
- const v = r.indexToSemanticName(c);
463
- if (v) return v;
464
- }
465
- return String(p);
466
- }
467
- return String(p);
468
- }, [k, r, p]), X = f(() => {
469
- const c = x === "rtl" ? B : I, v = x === "rtl" ? I : B;
683
+ const { flipBookRef: m, pageSemantics: c, direction: p, currentPage: h, totalPages: P, of: y } = S(), N = e ?? (c ? "semantic" : "index"), x = r ?? (N === "semantic" && !!c), [E, a] = C(""), [l, b] = C(!1), v = K(!1), I = K(h), R = h, k = h + 1 < P ? h + 1 : null, H = w(
684
+ (u) => N === "semantic" && c ? c.indexToSemanticName(u) || "" : String(u + 1),
685
+ [N, c]
686
+ ), B = H(R), j = k != null ? H(k) : "", A = w(() => String(y), [y]), q = w(() => {
687
+ const u = B, f = j;
470
688
  let T;
471
- return !c && !v ? T = o : c ? v ? c === v ? T = c : T = `${c} - ${v}` : T = c : T = v, t ? `${T} / ${R()}` : T;
472
- }, [x, I, B, o, t, R]), A = x === "rtl" ? B || I : I || B, M = X();
473
- $(() => {
474
- const c = m !== F.current;
475
- F.current = m, c && (d.current = !1), !i && !d.current && P(M);
476
- }, [M, i, m]);
477
- const Y = f(
478
- (c) => {
479
- b && (a(!0), P(A), d.current = !1, requestAnimationFrame(() => c.target.select()));
689
+ return !u && !f ? T = n : u ? f ? u === f ? T = u : T = `${u} - ${f}` : T = u : T = f, t ? `${T} / ${A()}` : T;
690
+ }, [B, j, n, t, A]), F = p === "rtl" ? j || B : B || j, O = q();
691
+ W(() => {
692
+ const u = h !== I.current;
693
+ I.current = h, u && (v.current = !1), !l && !v.current && a(O);
694
+ }, [O, l, h]);
695
+ const V = w(
696
+ (u) => {
697
+ x && (b(!0), a(F), v.current = !1, requestAnimationFrame(() => u.target.select()));
480
698
  },
481
- [b, A]
482
- ), _ = f(() => {
483
- a(!1), d.current || P(M);
484
- }, [M]), Q = f(
485
- (c) => {
486
- if (c.key === "Enter") {
487
- if (r && w.trim()) {
488
- const v = r.semanticNameToIndex(w.trim());
489
- v != null && v >= 0 && v < p && (g.current?.jumpToPage(v), d.current = !0);
699
+ [x, F]
700
+ ), G = w(() => {
701
+ b(!1), v.current || a(O);
702
+ }, [O]), s = w(
703
+ (u) => {
704
+ if (u.key === "Enter") {
705
+ if (c && E.trim()) {
706
+ const f = c.semanticNameToIndex(E.trim());
707
+ f != null && f >= 0 && f < P && (m.current?.jumpToPage(f), v.current = !0);
490
708
  }
491
- c.currentTarget.blur();
492
- } else c.key === "Escape" && c.currentTarget.blur();
709
+ u.currentTarget.blur();
710
+ } else u.key === "Escape" && u.currentTarget.blur();
493
711
  },
494
- [w, r, p, g]
495
- ), Z = f((c) => {
496
- P(c.target.value);
712
+ [E, c, P, m]
713
+ ), M = w((u) => {
714
+ a(u.target.value);
497
715
  }, []);
498
- return b ? /* @__PURE__ */ n(
716
+ return x ? /* @__PURE__ */ o(
499
717
  "input",
500
718
  {
501
719
  type: "text",
502
- className: `flipbook-toolbar-indicator ${i ? "flipbook-toolbar-indicator--editing" : ""} ${s ?? ""}`.trim(),
503
- value: w,
504
- onFocus: Y,
505
- onBlur: _,
506
- onKeyDown: Q,
507
- onChange: Z,
508
- "aria-label": u,
720
+ className: `flipbook-toolbar-indicator ${l ? "flipbook-toolbar-indicator--editing" : ""} ${i ?? ""}`.trim(),
721
+ value: E,
722
+ onFocus: V,
723
+ onBlur: G,
724
+ onKeyDown: s,
725
+ onChange: M,
726
+ "aria-label": d,
509
727
  "aria-live": "polite",
510
728
  "aria-atomic": "true",
511
- maxLength: h,
512
- readOnly: !b
729
+ maxLength: g,
730
+ readOnly: !x
513
731
  }
514
- ) : /* @__PURE__ */ n(
732
+ ) : /* @__PURE__ */ o(
515
733
  "span",
516
734
  {
517
- className: `flipbook-toolbar-indicator ${s ?? ""}`.trim(),
735
+ className: `flipbook-toolbar-indicator ${i ?? ""}`.trim(),
518
736
  "aria-live": "polite",
519
737
  "aria-atomic": "true",
520
- children: M
738
+ children: O
521
739
  }
522
740
  );
523
- }, ke = ({ children: e, className: t }) => {
524
- const { flipBookRef: o, isFirstPage: l, direction: s } = N(), u = () => {
525
- o.current?.flipPrev();
526
- }, h = s === "rtl" ? "Next page" : "Previous page", g = s === "rtl" ? /* @__PURE__ */ n(V, { size: 20 }) : /* @__PURE__ */ n(q, { size: 20 });
527
- return /* @__PURE__ */ n(
528
- L,
741
+ }, Be = ({ children: e, className: t }) => {
742
+ const { flipBookRef: n, isFirstPage: r, direction: i } = S(), d = () => {
743
+ n.current?.flipPrev();
744
+ }, g = i === "rtl" ? "Next page" : "Previous page", m = /* @__PURE__ */ o(ie, { size: 20 });
745
+ return /* @__PURE__ */ o(
746
+ z,
529
747
  {
530
- onClick: u,
531
- ariaLabel: h,
532
- disabled: l,
748
+ onClick: d,
749
+ ariaLabel: g,
750
+ disabled: r,
533
751
  className: `flipbook-toolbar-prev ${t ?? ""}`.trim(),
534
- children: e ?? g
752
+ children: e ?? m
535
753
  }
536
754
  );
537
- }, ve = ({
755
+ }, Fe = ({
538
756
  tocPageIndex: e = 4,
539
757
  children: t,
540
- ariaLabel: o = "Table of contents",
541
- className: l
758
+ ariaLabel: n,
759
+ className: r
542
760
  }) => {
543
- const { flipBookRef: s, currentPage: u } = N();
544
- return /* @__PURE__ */ n(
545
- L,
761
+ const { flipBookRef: i, currentPage: d, locale: g } = S(), m = n ?? D("toolbar.toc", g);
762
+ return /* @__PURE__ */ o(
763
+ z,
546
764
  {
547
765
  onClick: () => {
548
- s.current?.jumpToPage(e);
766
+ i.current?.goToPage(e);
549
767
  },
550
- ariaLabel: o,
551
- disabled: u === e,
552
- className: `flipbook-toolbar-toc ${l ?? ""}`.trim(),
553
- children: t ?? /* @__PURE__ */ n(ae, { size: 18 })
768
+ ariaLabel: m,
769
+ disabled: d === e,
770
+ className: `flipbook-toolbar-toc ${r ?? ""}`.trim(),
771
+ children: t ?? /* @__PURE__ */ o(me, { size: 18 })
554
772
  }
555
773
  );
556
- }, we = ({
774
+ }, $e = ({
557
775
  flipBookRef: e,
558
776
  direction: t = "ltr",
559
- pageSemantics: o,
560
- className: l = "",
561
- children: s,
562
- enableHotkeys: u = !0,
563
- commands: h,
564
- commandOptions: g
777
+ locale: n,
778
+ pageSemantics: r,
779
+ className: i = "",
780
+ children: d,
781
+ enableHotkeys: g = !0,
782
+ commands: m,
783
+ commandOptions: c
565
784
  }) => {
566
- const [r, x] = y(0), [m, p] = y(0), [k, b] = y(!0), [w, P] = y(!1), i = f(() => {
567
- const d = e.current;
568
- d && (x(d.getCurrentPageIndex()), p(d.getTotalPages()), b(d.isFirstPage()), P(d.isLastPage()));
785
+ const p = n ?? (t === "rtl" ? "he-IL" : "en"), [h, P] = C(0), [y, N] = C(0), [x, E] = C(0), [a, l] = C(!0), [b, v] = C(!1), I = w(() => {
786
+ const k = e.current;
787
+ k && (P(k.getCurrentPageIndex()), N(k.getTotalPages()), E(k.getOf()), l(k.isFirstPage()), v(k.isLastPage()));
569
788
  }, [e]);
570
- $(() => {
571
- i();
572
- const d = setInterval(i, 100);
573
- return () => clearInterval(d);
574
- }, [i]);
575
- const a = /* @__PURE__ */ n(
576
- G.Provider,
789
+ W(() => {
790
+ I();
791
+ const k = setInterval(I, 200);
792
+ return () => clearInterval(k);
793
+ }, [I]);
794
+ const R = /* @__PURE__ */ o(
795
+ ee.Provider,
577
796
  {
578
797
  value: {
579
798
  flipBookRef: e,
580
799
  direction: t,
581
- pageSemantics: o,
582
- currentPage: r,
583
- totalPages: m,
584
- isFirstPage: k,
585
- isLastPage: w
800
+ locale: p,
801
+ pageSemantics: r,
802
+ currentPage: h,
803
+ totalPages: y,
804
+ of: x,
805
+ isFirstPage: a,
806
+ isLastPage: b
586
807
  },
587
- children: /* @__PURE__ */ n(
808
+ children: /* @__PURE__ */ o(
588
809
  "div",
589
810
  {
590
- className: `flipbook-toolbar ${l}`.trim(),
811
+ className: `flipbook-toolbar ${t === "rtl" ? "flipbook-toolbar--rtl" : ""} ${i}`.trim(),
591
812
  role: "toolbar",
592
813
  "aria-label": "FlipBook navigation",
593
814
  dir: t,
594
- children: s
815
+ children: d
595
816
  }
596
817
  )
597
818
  }
598
819
  );
599
- return /* @__PURE__ */ n(
600
- oe,
820
+ return /* @__PURE__ */ o(
821
+ se,
601
822
  {
602
823
  flipBookRef: e,
603
- currentPage: r,
604
- totalPages: m,
824
+ currentPage: h,
825
+ totalPages: y,
605
826
  direction: t,
606
- commands: h,
607
- commandOptions: g,
608
- disableHotkeys: !u,
609
- children: a
827
+ commands: m,
828
+ commandOptions: c,
829
+ disableHotkeys: !g,
830
+ children: R
610
831
  }
611
832
  );
612
833
  };
613
834
  export {
614
- he as ActionButton,
615
- de as BookshelfIcon,
616
- J as ChevronFirstIcon,
617
- U as ChevronLastIcon,
618
- q as ChevronLeftIcon,
619
- V as ChevronRightIcon,
620
- ee as DEFAULT_HOTKEYS,
621
- me as FirstPageButton,
622
- ge as FullscreenButton,
623
- fe as LastPageButton,
624
- re as MaximizeIcon,
625
- ie as MinimizeIcon,
626
- pe as NextButton,
627
- xe as PageIndicator,
628
- ke as PrevButton,
629
- xe as SemanticPageIndicator,
630
- ae as TableOfContentsIcon,
631
- ve as TocButton,
632
- we as Toolbar,
633
- L as ToolbarButton,
634
- te as defaultCommands,
635
- ue as useCommands,
636
- N as useToolbar
835
+ Ce as ActionButton,
836
+ Pe as BookshelfIcon,
837
+ de as ChevronFirstIcon,
838
+ ue as ChevronLastIcon,
839
+ ie as ChevronLeftIcon,
840
+ ce as ChevronRightIcon,
841
+ re as DEFAULT_HOTKEYS,
842
+ ye as DownloadDropdown,
843
+ fe as DownloadIcon,
844
+ Le as FirstPageButton,
845
+ Te as FullscreenButton,
846
+ Ne as LastPageButton,
847
+ ge as MaximizeIcon,
848
+ he as MinimizeIcon,
849
+ Ee as NextButton,
850
+ Ie as PageIndicator,
851
+ Be as PrevButton,
852
+ Ie as SemanticPageIndicator,
853
+ me as TableOfContentsIcon,
854
+ Fe as TocButton,
855
+ $e as Toolbar,
856
+ z as ToolbarButton,
857
+ ae as defaultCommands,
858
+ ve as useCommands,
859
+ S as useToolbar
637
860
  };
638
861
  //# sourceMappingURL=index.js.map