pdf-flipbook 2.0.3 → 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.umd.js
CHANGED
|
@@ -21238,7 +21238,7 @@ var PdfFlipbook = (() => {
|
|
|
21238
21238
|
__webpack_exports__GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${__webpack_exports__version}/pdf.worker.min.mjs`;
|
|
21239
21239
|
}
|
|
21240
21240
|
var DEFAULTS = {
|
|
21241
|
-
flippingTime:
|
|
21241
|
+
flippingTime: 700,
|
|
21242
21242
|
toolbar: true,
|
|
21243
21243
|
theme: "dark",
|
|
21244
21244
|
maxDpr: 3,
|
|
@@ -21281,6 +21281,8 @@ var PdfFlipbook = (() => {
|
|
|
21281
21281
|
cancelAnimationFrame(this._raf);
|
|
21282
21282
|
window.removeEventListener("keydown", this._onKey);
|
|
21283
21283
|
window.removeEventListener("resize", this._onResize);
|
|
21284
|
+
window.removeEventListener("mousemove", this._onMouseMove);
|
|
21285
|
+
window.removeEventListener("mouseup", this._onMouseUp);
|
|
21284
21286
|
this._el.innerHTML = "";
|
|
21285
21287
|
}
|
|
21286
21288
|
async _init() {
|
|
@@ -21303,7 +21305,6 @@ var PdfFlipbook = (() => {
|
|
|
21303
21305
|
<canvas class="pfb__canvas"></canvas>
|
|
21304
21306
|
<button class="pfb__btn pfb__btn--prev">←</button>
|
|
21305
21307
|
<button class="pfb__btn pfb__btn--next">→</button>
|
|
21306
|
-
<button class="pfb__btn--fs" aria-label="Fullscreen">⛶</button>
|
|
21307
21308
|
<div class="pfb__loader"><div class="pfb__spinner"></div><span class="pfb__loader-text">Loading\u2026</span></div>
|
|
21308
21309
|
<div class="pfb__error" hidden></div>
|
|
21309
21310
|
</div>
|
|
@@ -21350,28 +21351,32 @@ var PdfFlipbook = (() => {
|
|
|
21350
21351
|
this._loader.hidden = true;
|
|
21351
21352
|
this._updateUI();
|
|
21352
21353
|
}
|
|
21353
|
-
// ── Layout ────────────────────────────────────────────────────────────────
|
|
21354
21354
|
_bookLayout() {
|
|
21355
21355
|
const cW = this._canvas.width;
|
|
21356
21356
|
const cH = this._canvas.height;
|
|
21357
21357
|
const mob = cW < 560;
|
|
21358
21358
|
const arrowPad = mob ? 48 : 64;
|
|
21359
21359
|
const maxW = cW - arrowPad * 2;
|
|
21360
|
-
let pH
|
|
21361
|
-
|
|
21362
|
-
if (!mob && pW * 2 > maxW) {
|
|
21363
|
-
pW = Math.floor(maxW / 2);
|
|
21364
|
-
pH = Math.floor(pW * this._aspect);
|
|
21365
|
-
}
|
|
21366
|
-
if (mob && pW > maxW) {
|
|
21360
|
+
let pW, pH;
|
|
21361
|
+
if (mob) {
|
|
21367
21362
|
pW = maxW;
|
|
21368
21363
|
pH = Math.floor(pW * this._aspect);
|
|
21364
|
+
if (pH > cH - 8) {
|
|
21365
|
+
pH = cH - 8;
|
|
21366
|
+
pW = Math.floor(pH / this._aspect);
|
|
21367
|
+
}
|
|
21368
|
+
} else {
|
|
21369
|
+
pW = Math.floor(maxW / 2);
|
|
21370
|
+
pH = Math.floor(pW * this._aspect);
|
|
21371
|
+
if (pH > cH - 8) {
|
|
21372
|
+
pH = cH - 8;
|
|
21373
|
+
pW = Math.floor(pH / this._aspect);
|
|
21374
|
+
}
|
|
21369
21375
|
}
|
|
21370
21376
|
const bx = Math.floor((cW - (mob ? pW : pW * 2)) / 2);
|
|
21371
21377
|
const by = Math.floor((cH - pH) / 2);
|
|
21372
21378
|
return { bx, by, pW, pH, mob };
|
|
21373
21379
|
}
|
|
21374
|
-
// ── Render loop ───────────────────────────────────────────────────────────
|
|
21375
21380
|
_loop() {
|
|
21376
21381
|
this._draw();
|
|
21377
21382
|
this._raf = requestAnimationFrame(() => this._loop());
|
|
@@ -21380,56 +21385,48 @@ var PdfFlipbook = (() => {
|
|
|
21380
21385
|
const ctx = this._ctx;
|
|
21381
21386
|
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
|
21382
21387
|
if (!this._total) return;
|
|
21383
|
-
const
|
|
21384
|
-
if (mob) {
|
|
21385
|
-
this._blitPage(ctx, this._pages[this._spread]
|
|
21388
|
+
const L = this._bookLayout();
|
|
21389
|
+
if (L.mob) {
|
|
21390
|
+
this._blitPage(ctx, this._pages[this._spread], L.bx, L.by, L.pW, L.pH);
|
|
21386
21391
|
return;
|
|
21387
21392
|
}
|
|
21388
21393
|
if (!this._flip) {
|
|
21389
|
-
this._drawSpread(ctx, this._spread,
|
|
21394
|
+
this._drawSpread(ctx, this._spread, L);
|
|
21390
21395
|
} else {
|
|
21391
|
-
this._drawFlip(ctx,
|
|
21396
|
+
this._drawFlip(ctx, L);
|
|
21392
21397
|
}
|
|
21393
21398
|
}
|
|
21394
|
-
|
|
21395
|
-
|
|
21399
|
+
_drawSpread(ctx, spread, L) {
|
|
21400
|
+
const { bx, by, pW, pH } = L;
|
|
21396
21401
|
this._blitPage(ctx, this._pages[spread] || null, bx, by, pW, pH);
|
|
21397
21402
|
this._blitPage(ctx, this._pages[spread + 1] || null, bx + pW, by, pW, pH);
|
|
21398
21403
|
this._drawSpineAndShadow(ctx, bx, by, pW, pH);
|
|
21399
21404
|
}
|
|
21400
21405
|
_blitPage(ctx, cvs, x, y, w, h) {
|
|
21401
|
-
ctx.fillStyle = "#
|
|
21406
|
+
ctx.fillStyle = "#fff";
|
|
21402
21407
|
ctx.fillRect(x, y, w, h);
|
|
21403
21408
|
if (cvs) ctx.drawImage(cvs, x, y, w, h);
|
|
21404
21409
|
}
|
|
21405
21410
|
_drawSpineAndShadow(ctx, bx, by, pW, pH) {
|
|
21406
21411
|
const sx = bx + pW;
|
|
21407
|
-
|
|
21408
|
-
|
|
21409
|
-
sg.addColorStop(0.35, "rgba(0,0,0,0.12)");
|
|
21410
|
-
sg.addColorStop(0.5, "rgba(0,0,0,0.18)");
|
|
21411
|
-
sg.addColorStop(0.65, "rgba(0,0,0,0.12)");
|
|
21412
|
-
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21413
|
-
ctx.fillStyle = sg;
|
|
21414
|
-
ctx.fillRect(sx - 18, by, 36, pH);
|
|
21412
|
+
ctx.fillStyle = "rgba(0,0,0,0.3)";
|
|
21413
|
+
ctx.fillRect(sx - 1, by, 2, pH);
|
|
21415
21414
|
const dg = ctx.createLinearGradient(0, by + pH - 4, 0, by + pH + 38);
|
|
21416
|
-
dg.addColorStop(0, "rgba(0,0,0,0.
|
|
21415
|
+
dg.addColorStop(0, "rgba(0,0,0,0.35)");
|
|
21417
21416
|
dg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21418
21417
|
ctx.fillStyle = dg;
|
|
21419
21418
|
ctx.fillRect(bx - 16, by + pH - 4, pW * 2 + 32, 42);
|
|
21420
21419
|
}
|
|
21421
|
-
|
|
21422
|
-
_drawFlip(ctx, bx, by, pW, pH) {
|
|
21420
|
+
_drawFlip(ctx, L) {
|
|
21423
21421
|
const f = this._flip;
|
|
21424
21422
|
const t = easeInOut(f.progress);
|
|
21425
21423
|
const dir = f.dir;
|
|
21426
|
-
const
|
|
21427
|
-
const destSpread = f.dest;
|
|
21428
|
-
const srcL = this._pages[srcSpread] || null;
|
|
21429
|
-
const srcR = this._pages[srcSpread + 1] || null;
|
|
21430
|
-
const dstL = this._pages[destSpread] || null;
|
|
21431
|
-
const dstR = this._pages[destSpread + 1] || null;
|
|
21424
|
+
const { bx, by, pW, pH } = L;
|
|
21432
21425
|
const spine = bx + pW;
|
|
21426
|
+
const srcL = this._pages[f.src] || null;
|
|
21427
|
+
const srcR = this._pages[f.src + 1] || null;
|
|
21428
|
+
const dstL = this._pages[f.dest] || null;
|
|
21429
|
+
const dstR = this._pages[f.dest + 1] || null;
|
|
21433
21430
|
if (dir === 1) {
|
|
21434
21431
|
this._blitPage(ctx, dstR, spine, by, pW, pH);
|
|
21435
21432
|
this._blitPage(ctx, srcL, bx, by, pW, pH);
|
|
@@ -21446,16 +21443,13 @@ var PdfFlipbook = (() => {
|
|
|
21446
21443
|
}
|
|
21447
21444
|
const shadowW = Math.min(80, pW * 0.3) * (1 - frontT);
|
|
21448
21445
|
if (shadowW > 0) {
|
|
21449
|
-
const
|
|
21450
|
-
|
|
21451
|
-
sg.addColorStop(0, "rgba(0,0,0,0.38)");
|
|
21452
|
-
sg.addColorStop(0.5, "rgba(0,0,0,0.12)");
|
|
21446
|
+
const sg = ctx.createLinearGradient(spine, 0, spine - shadowW, 0);
|
|
21447
|
+
sg.addColorStop(0, "rgba(0,0,0,0.35)");
|
|
21453
21448
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21454
21449
|
ctx.fillStyle = sg;
|
|
21455
|
-
ctx.fillRect(
|
|
21450
|
+
ctx.fillRect(spine - shadowW, by, shadowW, pH);
|
|
21456
21451
|
}
|
|
21457
|
-
|
|
21458
|
-
this._drawCrease(ctx, cx, by, pH, "right");
|
|
21452
|
+
this._drawCrease(ctx, spine + frontW, by, pH, "right");
|
|
21459
21453
|
} else {
|
|
21460
21454
|
const backT = (t - 0.5) * 2;
|
|
21461
21455
|
const backW = Math.floor(pW * backT);
|
|
@@ -21469,22 +21463,20 @@ var PdfFlipbook = (() => {
|
|
|
21469
21463
|
ctx.translate(spine, by);
|
|
21470
21464
|
ctx.scale(-1, 1);
|
|
21471
21465
|
this._blitPage(ctx, dstL, 0, 0, pW, pH);
|
|
21472
|
-
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.
|
|
21466
|
+
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.1 * backT})`;
|
|
21473
21467
|
ctx.fillRect(0, 0, pW, pH);
|
|
21474
21468
|
ctx.restore();
|
|
21475
21469
|
ctx.restore();
|
|
21476
21470
|
}
|
|
21477
21471
|
const shadowW = Math.min(80, pW * 0.3) * (1 - backT);
|
|
21478
21472
|
if (shadowW > 0) {
|
|
21479
|
-
const
|
|
21480
|
-
|
|
21481
|
-
sg.addColorStop(0, "rgba(0,0,0,0.3)");
|
|
21473
|
+
const sg = ctx.createLinearGradient(spine - backW, 0, spine - backW - shadowW, 0);
|
|
21474
|
+
sg.addColorStop(0, "rgba(0,0,0,0.28)");
|
|
21482
21475
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21483
21476
|
ctx.fillStyle = sg;
|
|
21484
|
-
ctx.fillRect(Math.max(bx,
|
|
21477
|
+
ctx.fillRect(Math.max(bx, spine - backW - shadowW), by, Math.min(shadowW, spine - backW - bx), pH);
|
|
21485
21478
|
}
|
|
21486
|
-
|
|
21487
|
-
this._drawCrease(ctx, cx, by, pH, "left");
|
|
21479
|
+
this._drawCrease(ctx, spine - backW, by, pH, "left");
|
|
21488
21480
|
}
|
|
21489
21481
|
} else {
|
|
21490
21482
|
this._blitPage(ctx, dstL, bx, by, pW, pH);
|
|
@@ -21504,19 +21496,17 @@ var PdfFlipbook = (() => {
|
|
|
21504
21496
|
const shadowW = Math.min(80, pW * 0.3) * (1 - frontT);
|
|
21505
21497
|
if (shadowW > 0) {
|
|
21506
21498
|
const sg = ctx.createLinearGradient(spine, 0, spine + shadowW, 0);
|
|
21507
|
-
sg.addColorStop(0, "rgba(0,0,0,0.
|
|
21508
|
-
sg.addColorStop(0.5, "rgba(0,0,0,0.12)");
|
|
21499
|
+
sg.addColorStop(0, "rgba(0,0,0,0.35)");
|
|
21509
21500
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21510
21501
|
ctx.fillStyle = sg;
|
|
21511
21502
|
ctx.fillRect(spine, by, shadowW, pH);
|
|
21512
21503
|
}
|
|
21513
|
-
|
|
21514
|
-
this._drawCrease(ctx, cx, by, pH, "left");
|
|
21504
|
+
this._drawCrease(ctx, spine - frontW, by, pH, "left");
|
|
21515
21505
|
} else {
|
|
21516
21506
|
const backT = (t - 0.5) * 2;
|
|
21517
21507
|
const backW = Math.floor(pW * backT);
|
|
21518
|
-
const backX = spine;
|
|
21519
21508
|
if (backW > 0) {
|
|
21509
|
+
const backX = spine;
|
|
21520
21510
|
ctx.save();
|
|
21521
21511
|
ctx.beginPath();
|
|
21522
21512
|
ctx.rect(backX, by, backW, pH);
|
|
@@ -21526,44 +21516,41 @@ var PdfFlipbook = (() => {
|
|
|
21526
21516
|
ctx.scale(-1, 1);
|
|
21527
21517
|
ctx.translate(-pW, 0);
|
|
21528
21518
|
this._blitPage(ctx, dstR, 0, 0, pW, pH);
|
|
21529
|
-
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.
|
|
21519
|
+
ctx.fillStyle = `rgba(0,0,0,${0.08 + 0.1 * backT})`;
|
|
21530
21520
|
ctx.fillRect(0, 0, pW, pH);
|
|
21531
21521
|
ctx.restore();
|
|
21532
21522
|
ctx.restore();
|
|
21533
21523
|
}
|
|
21534
21524
|
const shadowW = Math.min(80, pW * 0.3) * (1 - backT);
|
|
21535
21525
|
if (shadowW > 0) {
|
|
21536
|
-
const
|
|
21537
|
-
|
|
21538
|
-
sg.addColorStop(0, "rgba(0,0,0,0.3)");
|
|
21526
|
+
const sg = ctx.createLinearGradient(spine + backW, 0, spine + backW + shadowW, 0);
|
|
21527
|
+
sg.addColorStop(0, "rgba(0,0,0,0.28)");
|
|
21539
21528
|
sg.addColorStop(1, "rgba(0,0,0,0)");
|
|
21540
21529
|
ctx.fillStyle = sg;
|
|
21541
21530
|
ctx.fillRect(spine + backW, by, Math.min(shadowW, bx + pW * 2 - spine - backW), pH);
|
|
21542
21531
|
}
|
|
21543
|
-
|
|
21544
|
-
this._drawCrease(ctx, cx, by, pH, "right");
|
|
21532
|
+
this._drawCrease(ctx, spine + backW, by, pH, "right");
|
|
21545
21533
|
}
|
|
21546
21534
|
}
|
|
21547
21535
|
this._drawSpineAndShadow(ctx, bx, by, pW, pH);
|
|
21548
21536
|
}
|
|
21549
|
-
_drawCrease(ctx, cx, by, pH,
|
|
21537
|
+
_drawCrease(ctx, cx, by, pH, side) {
|
|
21550
21538
|
const w = 10;
|
|
21551
21539
|
const g = ctx.createLinearGradient(cx - w, 0, cx + w, 0);
|
|
21552
|
-
if (
|
|
21540
|
+
if (side === "right") {
|
|
21553
21541
|
g.addColorStop(0, "rgba(0,0,0,0)");
|
|
21554
|
-
g.addColorStop(0.35, "rgba(0,0,0,0.
|
|
21555
|
-
g.addColorStop(0.55, "rgba(255,255,255,0.
|
|
21542
|
+
g.addColorStop(0.35, "rgba(0,0,0,0.25)");
|
|
21543
|
+
g.addColorStop(0.55, "rgba(255,255,255,0.2)");
|
|
21556
21544
|
g.addColorStop(1, "rgba(0,0,0,0)");
|
|
21557
21545
|
} else {
|
|
21558
21546
|
g.addColorStop(0, "rgba(0,0,0,0)");
|
|
21559
|
-
g.addColorStop(0.45, "rgba(255,255,255,0.
|
|
21560
|
-
g.addColorStop(0.65, "rgba(0,0,0,0.
|
|
21547
|
+
g.addColorStop(0.45, "rgba(255,255,255,0.2)");
|
|
21548
|
+
g.addColorStop(0.65, "rgba(0,0,0,0.25)");
|
|
21561
21549
|
g.addColorStop(1, "rgba(0,0,0,0)");
|
|
21562
21550
|
}
|
|
21563
21551
|
ctx.fillStyle = g;
|
|
21564
21552
|
ctx.fillRect(cx - w, by, w * 2, pH);
|
|
21565
21553
|
}
|
|
21566
|
-
// ── Flip state ────────────────────────────────────────────────────────────
|
|
21567
21554
|
_startFlip(dir, dest) {
|
|
21568
21555
|
if (this._flip || !this._total) return;
|
|
21569
21556
|
const target = dest !== void 0 ? dest : this._spread + dir * 2;
|
|
@@ -21585,20 +21572,9 @@ var PdfFlipbook = (() => {
|
|
|
21585
21572
|
};
|
|
21586
21573
|
requestAnimationFrame(step);
|
|
21587
21574
|
}
|
|
21588
|
-
// ── Events ────────────────────────────────────────────────────────────────
|
|
21589
21575
|
_bindEvents() {
|
|
21590
21576
|
this._el.querySelectorAll(".pfb__btn--prev, .pfb__tb-prev").forEach((b) => b.addEventListener("click", () => this.prev()));
|
|
21591
21577
|
this._el.querySelectorAll(".pfb__btn--next, .pfb__tb-next").forEach((b) => b.addEventListener("click", () => this.next()));
|
|
21592
|
-
const fsBtn = this._el.querySelector(".pfb__btn--fs");
|
|
21593
|
-
if (fsBtn) {
|
|
21594
|
-
fsBtn.addEventListener("click", () => {
|
|
21595
|
-
if (!document.fullscreenElement) {
|
|
21596
|
-
this._el.requestFullscreen?.() || this._el.webkitRequestFullscreen?.();
|
|
21597
|
-
} else {
|
|
21598
|
-
document.exitFullscreen?.() || document.webkitExitFullscreen?.();
|
|
21599
|
-
}
|
|
21600
|
-
});
|
|
21601
|
-
}
|
|
21602
21578
|
this._onKey = (e) => {
|
|
21603
21579
|
if (["ArrowRight", "ArrowDown"].includes(e.key)) this.next();
|
|
21604
21580
|
if (["ArrowLeft", "ArrowUp"].includes(e.key)) this.prev();
|
|
@@ -21613,7 +21589,7 @@ var PdfFlipbook = (() => {
|
|
|
21613
21589
|
if (this._flip) return;
|
|
21614
21590
|
const cx = getCanvasX(clientX);
|
|
21615
21591
|
const half = this._canvas.width / 2;
|
|
21616
|
-
dragStart = { x: clientX,
|
|
21592
|
+
dragStart = { x: clientX, side: cx < half ? "left" : "right" };
|
|
21617
21593
|
};
|
|
21618
21594
|
const onDragEnd = (clientX) => {
|
|
21619
21595
|
if (!dragStart) return;
|
|
@@ -21622,22 +21598,17 @@ var PdfFlipbook = (() => {
|
|
|
21622
21598
|
if (absDx > 30) {
|
|
21623
21599
|
if (dragStart.side === "right" && dx < 0) this.next();
|
|
21624
21600
|
else if (dragStart.side === "left" && dx > 0) this.prev();
|
|
21625
|
-
else if (dx < 0) this.next();
|
|
21626
|
-
else this.prev();
|
|
21627
21601
|
}
|
|
21628
21602
|
dragStart = null;
|
|
21629
21603
|
};
|
|
21630
21604
|
this._canvas.addEventListener("mousedown", (e) => onDragStart(e.clientX));
|
|
21631
|
-
this.
|
|
21632
|
-
|
|
21633
|
-
|
|
21634
|
-
|
|
21635
|
-
|
|
21636
|
-
|
|
21637
|
-
|
|
21638
|
-
this._canvas.addEventListener("touchend", (e) => {
|
|
21639
|
-
onDragEnd(e.changedTouches[0].clientX);
|
|
21640
|
-
}, { passive: true });
|
|
21605
|
+
this._onMouseMove = () => {
|
|
21606
|
+
};
|
|
21607
|
+
this._onMouseUp = (e) => onDragEnd(e.clientX);
|
|
21608
|
+
window.addEventListener("mousemove", this._onMouseMove);
|
|
21609
|
+
window.addEventListener("mouseup", this._onMouseUp);
|
|
21610
|
+
this._canvas.addEventListener("touchstart", (e) => onDragStart(e.touches[0].clientX), { passive: true });
|
|
21611
|
+
this._canvas.addEventListener("touchend", (e) => onDragEnd(e.changedTouches[0].clientX), { passive: true });
|
|
21641
21612
|
this._onResize = () => this._resizeCanvas();
|
|
21642
21613
|
window.addEventListener("resize", this._onResize);
|
|
21643
21614
|
}
|