pdf-flipbook 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pdf-flipbook.esm.js
CHANGED
|
@@ -21209,7 +21209,7 @@ if (typeof window !== "undefined") {
|
|
|
21209
21209
|
__webpack_exports__GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${__webpack_exports__version}/pdf.worker.min.mjs`;
|
|
21210
21210
|
}
|
|
21211
21211
|
var DEFAULTS = {
|
|
21212
|
-
flippingTime:
|
|
21212
|
+
flippingTime: 700,
|
|
21213
21213
|
toolbar: true,
|
|
21214
21214
|
theme: "dark",
|
|
21215
21215
|
maxDpr: 3,
|
|
@@ -21252,6 +21252,8 @@ var PdfFlipbook = class {
|
|
|
21252
21252
|
cancelAnimationFrame(this._raf);
|
|
21253
21253
|
window.removeEventListener("keydown", this._onKey);
|
|
21254
21254
|
window.removeEventListener("resize", this._onResize);
|
|
21255
|
+
window.removeEventListener("mousemove", this._onMouseMove);
|
|
21256
|
+
window.removeEventListener("mouseup", this._onMouseUp);
|
|
21255
21257
|
this._el.innerHTML = "";
|
|
21256
21258
|
}
|
|
21257
21259
|
async _init() {
|
|
@@ -21274,7 +21276,6 @@ var PdfFlipbook = class {
|
|
|
21274
21276
|
<canvas class="pfb__canvas"></canvas>
|
|
21275
21277
|
<button class="pfb__btn pfb__btn--prev">←</button>
|
|
21276
21278
|
<button class="pfb__btn pfb__btn--next">→</button>
|
|
21277
|
-
<button class="pfb__btn--fs" aria-label="Fullscreen">⛶</button>
|
|
21278
21279
|
<div class="pfb__loader"><div class="pfb__spinner"></div><span class="pfb__loader-text">Loading\u2026</span></div>
|
|
21279
21280
|
<div class="pfb__error" hidden></div>
|
|
21280
21281
|
</div>
|
|
@@ -21321,28 +21322,32 @@ var PdfFlipbook = class {
|
|
|
21321
21322
|
this._loader.hidden = true;
|
|
21322
21323
|
this._updateUI();
|
|
21323
21324
|
}
|
|
21324
|
-
// ── Layout ────────────────────────────────────────────────────────────────
|
|
21325
21325
|
_bookLayout() {
|
|
21326
21326
|
const cW = this._canvas.width;
|
|
21327
21327
|
const cH = this._canvas.height;
|
|
21328
21328
|
const mob = cW < 560;
|
|
21329
21329
|
const arrowPad = mob ? 48 : 64;
|
|
21330
21330
|
const maxW = cW - arrowPad * 2;
|
|
21331
|
-
let pH
|
|
21332
|
-
|
|
21333
|
-
if (!mob && pW * 2 > maxW) {
|
|
21334
|
-
pW = Math.floor(maxW / 2);
|
|
21335
|
-
pH = Math.floor(pW * this._aspect);
|
|
21336
|
-
}
|
|
21337
|
-
if (mob && pW > maxW) {
|
|
21331
|
+
let pW, pH;
|
|
21332
|
+
if (mob) {
|
|
21338
21333
|
pW = maxW;
|
|
21339
21334
|
pH = Math.floor(pW * this._aspect);
|
|
21335
|
+
if (pH > cH - 8) {
|
|
21336
|
+
pH = cH - 8;
|
|
21337
|
+
pW = Math.floor(pH / this._aspect);
|
|
21338
|
+
}
|
|
21339
|
+
} else {
|
|
21340
|
+
pW = Math.floor(maxW / 2);
|
|
21341
|
+
pH = Math.floor(pW * this._aspect);
|
|
21342
|
+
if (pH > cH - 8) {
|
|
21343
|
+
pH = cH - 8;
|
|
21344
|
+
pW = Math.floor(pH / this._aspect);
|
|
21345
|
+
}
|
|
21340
21346
|
}
|
|
21341
21347
|
const bx = Math.floor((cW - (mob ? pW : pW * 2)) / 2);
|
|
21342
21348
|
const by = Math.floor((cH - pH) / 2);
|
|
21343
21349
|
return { bx, by, pW, pH, mob };
|
|
21344
21350
|
}
|
|
21345
|
-
// ── Render loop ───────────────────────────────────────────────────────────
|
|
21346
21351
|
_loop() {
|
|
21347
21352
|
this._draw();
|
|
21348
21353
|
this._raf = requestAnimationFrame(() => this._loop());
|
|
@@ -21351,56 +21356,48 @@ var PdfFlipbook = class {
|
|
|
21351
21356
|
const ctx = this._ctx;
|
|
21352
21357
|
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
|
21353
21358
|
if (!this._total) return;
|
|
21354
|
-
const
|
|
21355
|
-
if (mob) {
|
|
21356
|
-
this._blitPage(ctx, this._pages[this._spread]
|
|
21359
|
+
const L = this._bookLayout();
|
|
21360
|
+
if (L.mob) {
|
|
21361
|
+
this._blitPage(ctx, this._pages[this._spread], L.bx, L.by, L.pW, L.pH);
|
|
21357
21362
|
return;
|
|
21358
21363
|
}
|
|
21359
21364
|
if (!this._flip) {
|
|
21360
|
-
this._drawSpread(ctx, this._spread,
|
|
21365
|
+
this._drawSpread(ctx, this._spread, L);
|
|
21361
21366
|
} else {
|
|
21362
|
-
this._drawFlip(ctx,
|
|
21367
|
+
this._drawFlip(ctx, L);
|
|
21363
21368
|
}
|
|
21364
21369
|
}
|
|
21365
|
-
|
|
21366
|
-
|
|
21370
|
+
_drawSpread(ctx, spread, L) {
|
|
21371
|
+
const { bx, by, pW, pH } = L;
|
|
21367
21372
|
this._blitPage(ctx, this._pages[spread] || null, bx, by, pW, pH);
|
|
21368
21373
|
this._blitPage(ctx, this._pages[spread + 1] || null, bx + pW, by, pW, pH);
|
|
21369
21374
|
this._drawSpineAndShadow(ctx, bx, by, pW, pH);
|
|
21370
21375
|
}
|
|
21371
21376
|
_blitPage(ctx, cvs, x, y, w, h) {
|
|
21372
|
-
ctx.fillStyle = "#
|
|
21377
|
+
ctx.fillStyle = "#fff";
|
|
21373
21378
|
ctx.fillRect(x, y, w, h);
|
|
21374
21379
|
if (cvs) ctx.drawImage(cvs, x, y, w, h);
|
|
21375
21380
|
}
|
|
21376
21381
|
_drawSpineAndShadow(ctx, bx, by, pW, pH) {
|
|
21377
21382
|
const sx = bx + pW;
|
|
21378
|
-
|
|
21379
|
-
|
|
21380
|
-
sg.addColorStop(0.35, "rgba(0,0,0,0.12)");
|
|
21381
|
-
sg.addColorStop(0.5, "rgba(0,0,0,0.18)");
|
|
21382
|
-
sg.addColorStop(0.65, "rgba(0,0,0,0.12)");
|
|
21383
|
-
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21384
|
-
ctx.fillStyle = sg;
|
|
21385
|
-
ctx.fillRect(sx - 18, by, 36, pH);
|
|
21383
|
+
ctx.fillStyle = "rgba(0,0,0,0.3)";
|
|
21384
|
+
ctx.fillRect(sx - 1, by, 2, pH);
|
|
21386
21385
|
const dg = ctx.createLinearGradient(0, by + pH - 4, 0, by + pH + 38);
|
|
21387
|
-
dg.addColorStop(0, "rgba(0,0,0,0.
|
|
21386
|
+
dg.addColorStop(0, "rgba(0,0,0,0.35)");
|
|
21388
21387
|
dg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21389
21388
|
ctx.fillStyle = dg;
|
|
21390
21389
|
ctx.fillRect(bx - 16, by + pH - 4, pW * 2 + 32, 42);
|
|
21391
21390
|
}
|
|
21392
|
-
|
|
21393
|
-
_drawFlip(ctx, bx, by, pW, pH) {
|
|
21391
|
+
_drawFlip(ctx, L) {
|
|
21394
21392
|
const f = this._flip;
|
|
21395
21393
|
const t = easeInOut(f.progress);
|
|
21396
21394
|
const dir = f.dir;
|
|
21397
|
-
const
|
|
21398
|
-
const destSpread = f.dest;
|
|
21399
|
-
const srcL = this._pages[srcSpread] || null;
|
|
21400
|
-
const srcR = this._pages[srcSpread + 1] || null;
|
|
21401
|
-
const dstL = this._pages[destSpread] || null;
|
|
21402
|
-
const dstR = this._pages[destSpread + 1] || null;
|
|
21395
|
+
const { bx, by, pW, pH } = L;
|
|
21403
21396
|
const spine = bx + pW;
|
|
21397
|
+
const srcL = this._pages[f.src] || null;
|
|
21398
|
+
const srcR = this._pages[f.src + 1] || null;
|
|
21399
|
+
const dstL = this._pages[f.dest] || null;
|
|
21400
|
+
const dstR = this._pages[f.dest + 1] || null;
|
|
21404
21401
|
if (dir === 1) {
|
|
21405
21402
|
this._blitPage(ctx, dstR, spine, by, pW, pH);
|
|
21406
21403
|
this._blitPage(ctx, srcL, bx, by, pW, pH);
|
|
@@ -21417,16 +21414,13 @@ var PdfFlipbook = class {
|
|
|
21417
21414
|
}
|
|
21418
21415
|
const shadowW = Math.min(80, pW * 0.3) * (1 - frontT);
|
|
21419
21416
|
if (shadowW > 0) {
|
|
21420
|
-
const
|
|
21421
|
-
|
|
21422
|
-
sg.addColorStop(0, "rgba(0,0,0,0.38)");
|
|
21423
|
-
sg.addColorStop(0.5, "rgba(0,0,0,0.12)");
|
|
21417
|
+
const sg = ctx.createLinearGradient(spine, 0, spine - shadowW, 0);
|
|
21418
|
+
sg.addColorStop(0, "rgba(0,0,0,0.35)");
|
|
21424
21419
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21425
21420
|
ctx.fillStyle = sg;
|
|
21426
|
-
ctx.fillRect(
|
|
21421
|
+
ctx.fillRect(spine - shadowW, by, shadowW, pH);
|
|
21427
21422
|
}
|
|
21428
|
-
|
|
21429
|
-
this._drawCrease(ctx, cx, by, pH, "right");
|
|
21423
|
+
this._drawCrease(ctx, spine + frontW, by, pH, "right");
|
|
21430
21424
|
} else {
|
|
21431
21425
|
const backT = (t - 0.5) * 2;
|
|
21432
21426
|
const backW = Math.floor(pW * backT);
|
|
@@ -21440,22 +21434,20 @@ var PdfFlipbook = class {
|
|
|
21440
21434
|
ctx.translate(spine, by);
|
|
21441
21435
|
ctx.scale(-1, 1);
|
|
21442
21436
|
this._blitPage(ctx, dstL, 0, 0, pW, pH);
|
|
21443
|
-
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.
|
|
21437
|
+
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.1 * backT})`;
|
|
21444
21438
|
ctx.fillRect(0, 0, pW, pH);
|
|
21445
21439
|
ctx.restore();
|
|
21446
21440
|
ctx.restore();
|
|
21447
21441
|
}
|
|
21448
21442
|
const shadowW = Math.min(80, pW * 0.3) * (1 - backT);
|
|
21449
21443
|
if (shadowW > 0) {
|
|
21450
|
-
const
|
|
21451
|
-
|
|
21452
|
-
sg.addColorStop(0, "rgba(0,0,0,0.3)");
|
|
21444
|
+
const sg = ctx.createLinearGradient(spine - backW, 0, spine - backW - shadowW, 0);
|
|
21445
|
+
sg.addColorStop(0, "rgba(0,0,0,0.28)");
|
|
21453
21446
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21454
21447
|
ctx.fillStyle = sg;
|
|
21455
|
-
ctx.fillRect(Math.max(bx,
|
|
21448
|
+
ctx.fillRect(Math.max(bx, spine - backW - shadowW), by, Math.min(shadowW, spine - backW - bx), pH);
|
|
21456
21449
|
}
|
|
21457
|
-
|
|
21458
|
-
this._drawCrease(ctx, cx, by, pH, "left");
|
|
21450
|
+
this._drawCrease(ctx, spine - backW, by, pH, "left");
|
|
21459
21451
|
}
|
|
21460
21452
|
} else {
|
|
21461
21453
|
this._blitPage(ctx, dstL, bx, by, pW, pH);
|
|
@@ -21475,19 +21467,17 @@ var PdfFlipbook = class {
|
|
|
21475
21467
|
const shadowW = Math.min(80, pW * 0.3) * (1 - frontT);
|
|
21476
21468
|
if (shadowW > 0) {
|
|
21477
21469
|
const sg = ctx.createLinearGradient(spine, 0, spine + shadowW, 0);
|
|
21478
|
-
sg.addColorStop(0, "rgba(0,0,0,0.
|
|
21479
|
-
sg.addColorStop(0.5, "rgba(0,0,0,0.12)");
|
|
21470
|
+
sg.addColorStop(0, "rgba(0,0,0,0.35)");
|
|
21480
21471
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21481
21472
|
ctx.fillStyle = sg;
|
|
21482
21473
|
ctx.fillRect(spine, by, shadowW, pH);
|
|
21483
21474
|
}
|
|
21484
|
-
|
|
21485
|
-
this._drawCrease(ctx, cx, by, pH, "left");
|
|
21475
|
+
this._drawCrease(ctx, spine - frontW, by, pH, "left");
|
|
21486
21476
|
} else {
|
|
21487
21477
|
const backT = (t - 0.5) * 2;
|
|
21488
21478
|
const backW = Math.floor(pW * backT);
|
|
21489
|
-
const backX = spine;
|
|
21490
21479
|
if (backW > 0) {
|
|
21480
|
+
const backX = spine;
|
|
21491
21481
|
ctx.save();
|
|
21492
21482
|
ctx.beginPath();
|
|
21493
21483
|
ctx.rect(backX, by, backW, pH);
|
|
@@ -21497,44 +21487,41 @@ var PdfFlipbook = class {
|
|
|
21497
21487
|
ctx.scale(-1, 1);
|
|
21498
21488
|
ctx.translate(-pW, 0);
|
|
21499
21489
|
this._blitPage(ctx, dstR, 0, 0, pW, pH);
|
|
21500
|
-
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.
|
|
21490
|
+
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.1 * backT})`;
|
|
21501
21491
|
ctx.fillRect(0, 0, pW, pH);
|
|
21502
21492
|
ctx.restore();
|
|
21503
21493
|
ctx.restore();
|
|
21504
21494
|
}
|
|
21505
21495
|
const shadowW = Math.min(80, pW * 0.3) * (1 - backT);
|
|
21506
21496
|
if (shadowW > 0) {
|
|
21507
|
-
const
|
|
21508
|
-
|
|
21509
|
-
sg.addColorStop(0, "rgba(0,0,0,0.3)");
|
|
21497
|
+
const sg = ctx.createLinearGradient(spine + backW, 0, spine + backW + shadowW, 0);
|
|
21498
|
+
sg.addColorStop(0, "rgba(0,0,0,0.28)");
|
|
21510
21499
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21511
21500
|
ctx.fillStyle = sg;
|
|
21512
21501
|
ctx.fillRect(spine + backW, by, Math.min(shadowW, bx + pW * 2 - spine - backW), pH);
|
|
21513
21502
|
}
|
|
21514
|
-
|
|
21515
|
-
this._drawCrease(ctx, cx, by, pH, "right");
|
|
21503
|
+
this._drawCrease(ctx, spine + backW, by, pH, "right");
|
|
21516
21504
|
}
|
|
21517
21505
|
}
|
|
21518
21506
|
this._drawSpineAndShadow(ctx, bx, by, pW, pH);
|
|
21519
21507
|
}
|
|
21520
|
-
_drawCrease(ctx, cx, by, pH,
|
|
21508
|
+
_drawCrease(ctx, cx, by, pH, side) {
|
|
21521
21509
|
const w = 10;
|
|
21522
21510
|
const g = ctx.createLinearGradient(cx - w, 0, cx + w, 0);
|
|
21523
|
-
if (
|
|
21511
|
+
if (side === "right") {
|
|
21524
21512
|
g.addColorStop(0, "rgba(0,0,0,0)");
|
|
21525
|
-
g.addColorStop(0.35, "rgba(0,0,0,0.
|
|
21526
|
-
g.addColorStop(0.55, "rgba(255,255,255,0.
|
|
21513
|
+
g.addColorStop(0.35, "rgba(0,0,0,0.25)");
|
|
21514
|
+
g.addColorStop(0.55, "rgba(255,255,255,0.2)");
|
|
21527
21515
|
g.addColorStop(1, "rgba(0,0,0,0)");
|
|
21528
21516
|
} else {
|
|
21529
21517
|
g.addColorStop(0, "rgba(0,0,0,0)");
|
|
21530
|
-
g.addColorStop(0.45, "rgba(255,255,255,0.
|
|
21531
|
-
g.addColorStop(0.65, "rgba(0,0,0,0.
|
|
21518
|
+
g.addColorStop(0.45, "rgba(255,255,255,0.2)");
|
|
21519
|
+
g.addColorStop(0.65, "rgba(0,0,0,0.25)");
|
|
21532
21520
|
g.addColorStop(1, "rgba(0,0,0,0)");
|
|
21533
21521
|
}
|
|
21534
21522
|
ctx.fillStyle = g;
|
|
21535
21523
|
ctx.fillRect(cx - w, by, w * 2, pH);
|
|
21536
21524
|
}
|
|
21537
|
-
// ── Flip state ────────────────────────────────────────────────────────────
|
|
21538
21525
|
_startFlip(dir, dest) {
|
|
21539
21526
|
if (this._flip || !this._total) return;
|
|
21540
21527
|
const target = dest !== void 0 ? dest : this._spread + dir * 2;
|
|
@@ -21556,20 +21543,9 @@ var PdfFlipbook = class {
|
|
|
21556
21543
|
};
|
|
21557
21544
|
requestAnimationFrame(step);
|
|
21558
21545
|
}
|
|
21559
|
-
// ── Events ────────────────────────────────────────────────────────────────
|
|
21560
21546
|
_bindEvents() {
|
|
21561
21547
|
this._el.querySelectorAll(".pfb__btn--prev, .pfb__tb-prev").forEach((b) => b.addEventListener("click", () => this.prev()));
|
|
21562
21548
|
this._el.querySelectorAll(".pfb__btn--next, .pfb__tb-next").forEach((b) => b.addEventListener("click", () => this.next()));
|
|
21563
|
-
const fsBtn = this._el.querySelector(".pfb__btn--fs");
|
|
21564
|
-
if (fsBtn) {
|
|
21565
|
-
fsBtn.addEventListener("click", () => {
|
|
21566
|
-
if (!document.fullscreenElement) {
|
|
21567
|
-
this._el.requestFullscreen?.() || this._el.webkitRequestFullscreen?.();
|
|
21568
|
-
} else {
|
|
21569
|
-
document.exitFullscreen?.() || document.webkitExitFullscreen?.();
|
|
21570
|
-
}
|
|
21571
|
-
});
|
|
21572
|
-
}
|
|
21573
21549
|
this._onKey = (e) => {
|
|
21574
21550
|
if (["ArrowRight", "ArrowDown"].includes(e.key)) this.next();
|
|
21575
21551
|
if (["ArrowLeft", "ArrowUp"].includes(e.key)) this.prev();
|
|
@@ -21584,7 +21560,7 @@ var PdfFlipbook = class {
|
|
|
21584
21560
|
if (this._flip) return;
|
|
21585
21561
|
const cx = getCanvasX(clientX);
|
|
21586
21562
|
const half = this._canvas.width / 2;
|
|
21587
|
-
dragStart = { x: clientX,
|
|
21563
|
+
dragStart = { x: clientX, side: cx < half ? "left" : "right" };
|
|
21588
21564
|
};
|
|
21589
21565
|
const onDragEnd = (clientX) => {
|
|
21590
21566
|
if (!dragStart) return;
|
|
@@ -21593,22 +21569,17 @@ var PdfFlipbook = class {
|
|
|
21593
21569
|
if (absDx > 30) {
|
|
21594
21570
|
if (dragStart.side === "right" && dx < 0) this.next();
|
|
21595
21571
|
else if (dragStart.side === "left" && dx > 0) this.prev();
|
|
21596
|
-
else if (dx < 0) this.next();
|
|
21597
|
-
else this.prev();
|
|
21598
21572
|
}
|
|
21599
21573
|
dragStart = null;
|
|
21600
21574
|
};
|
|
21601
21575
|
this._canvas.addEventListener("mousedown", (e) => onDragStart(e.clientX));
|
|
21602
|
-
this.
|
|
21603
|
-
|
|
21604
|
-
|
|
21605
|
-
|
|
21606
|
-
|
|
21607
|
-
|
|
21608
|
-
|
|
21609
|
-
this._canvas.addEventListener("touchend", (e) => {
|
|
21610
|
-
onDragEnd(e.changedTouches[0].clientX);
|
|
21611
|
-
}, { passive: true });
|
|
21576
|
+
this._onMouseMove = () => {
|
|
21577
|
+
};
|
|
21578
|
+
this._onMouseUp = (e) => onDragEnd(e.clientX);
|
|
21579
|
+
window.addEventListener("mousemove", this._onMouseMove);
|
|
21580
|
+
window.addEventListener("mouseup", this._onMouseUp);
|
|
21581
|
+
this._canvas.addEventListener("touchstart", (e) => onDragStart(e.touches[0].clientX), { passive: true });
|
|
21582
|
+
this._canvas.addEventListener("touchend", (e) => onDragEnd(e.changedTouches[0].clientX), { passive: true });
|
|
21612
21583
|
this._onResize = () => this._resizeCanvas();
|
|
21613
21584
|
window.addEventListener("resize", this._onResize);
|
|
21614
21585
|
}
|