hic-pageflip 1.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/LICENSE +21 -0
- package/README.md +322 -0
- package/components/hic-pageflip-page.js +43 -0
- package/components/hic-pageflip.js +339 -0
- package/core/engines/engine-2d.js +470 -0
- package/core/engines/engine-3d.js +699 -0
- package/core/engines/engine-base.js +73 -0
- package/core/pageflip.js +657 -0
- package/core/utils/math.js +186 -0
- package/index.js +8 -0
- package/package.json +33 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Pageflip Engine (BaseEngine)
|
|
3
|
+
* Shared state, viewport management, and coordinate mapping for 2D and 3D HTML-in-Canvas engines.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export class BaseEngine {
|
|
7
|
+
constructor(canvas, slides = []) {
|
|
8
|
+
this.canvas = canvas;
|
|
9
|
+
this.slides = slides;
|
|
10
|
+
|
|
11
|
+
// Page dimensions (initialized from canvas attributes if present, updated dynamically via setDimensions)
|
|
12
|
+
const attrPw = parseInt(this.canvas.getAttribute('data-pageflip-width') || this.canvas.dataset?.pageflipWidth, 10);
|
|
13
|
+
const attrPh = parseInt(this.canvas.getAttribute('data-pageflip-height') || this.canvas.dataset?.pageflipHeight, 10);
|
|
14
|
+
this.pw = attrPw || 1024;
|
|
15
|
+
this.ph = attrPh || 768;
|
|
16
|
+
this.devicePixelRatio = window.devicePixelRatio || 1;
|
|
17
|
+
|
|
18
|
+
// Viewport transformations
|
|
19
|
+
this.viewportWidth = this.pw;
|
|
20
|
+
this.viewportHeight = this.ph;
|
|
21
|
+
this.scale = 1;
|
|
22
|
+
this.zoom = 1;
|
|
23
|
+
this.panX = 0;
|
|
24
|
+
this.panY = 0;
|
|
25
|
+
this.offsetX = this.pw / 2;
|
|
26
|
+
this.offsetY = this.ph / 2;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
updateDimensionsFromAttributes() {
|
|
30
|
+
const pw = parseInt(this.canvas.getAttribute('data-pageflip-width') || this.canvas.dataset?.pageflipWidth, 10) || 1024;
|
|
31
|
+
const ph = parseInt(this.canvas.getAttribute('data-pageflip-height') || this.canvas.dataset?.pageflipHeight, 10) || 768;
|
|
32
|
+
this.pw = pw;
|
|
33
|
+
this.ph = ph;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setDimensions(pw, ph) {
|
|
37
|
+
this.pw = pw;
|
|
38
|
+
this.ph = ph;
|
|
39
|
+
this.resize();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
screenToBook(screenX, screenY) {
|
|
43
|
+
const relX = screenX - (this.offsetX + this.panX);
|
|
44
|
+
const relY = screenY - (this.offsetY + this.panY);
|
|
45
|
+
const scale = this.scale * this.zoom;
|
|
46
|
+
return {
|
|
47
|
+
x: relX / scale,
|
|
48
|
+
y: relY / scale
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bookToScreen(bookX, bookY) {
|
|
53
|
+
const scale = this.scale * this.zoom;
|
|
54
|
+
return {
|
|
55
|
+
x: (bookX * scale) + this.offsetX + this.panX,
|
|
56
|
+
y: (bookY * scale) + this.offsetY + this.panY
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
requestRender(callback) {
|
|
61
|
+
if (this._rafId) return;
|
|
62
|
+
this._rafId = requestAnimationFrame(() => {
|
|
63
|
+
this._rafId = null;
|
|
64
|
+
if (callback) callback();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
clearCache() {}
|
|
69
|
+
|
|
70
|
+
resize() {}
|
|
71
|
+
|
|
72
|
+
render(state) {}
|
|
73
|
+
}
|