3d-pro-flipbook 1.0.2 → 1.2.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/README.md CHANGED
@@ -15,15 +15,33 @@ A lightweight, professional, and responsive 3D PDF Flipbook library for the web.
15
15
 
16
16
  Install the package via NPM:
17
17
 
18
- ```bash
18
+ =================================
19
+ #### 1. Installation
20
+
21
+ First, add the library to your project via your package manager:Bash
22
+ ```
19
23
  npm install 3d-pro-flipbook
24
+ ```
25
+ ### or
20
26
 
21
- =================================
22
- 1. InstallationFirst, add the library to your project via your package manager:Bashnpm install 3d-pro-flipbook
23
- # or
27
+ ```bash
24
28
  yarn add 3d-pro-flipbook
25
- 2. The Universal "Golden Rule"No matter which framework you use, the logic is always the same:Import the class and the CSS.Create a container div with a unique ID (e.g., #my-book).Initialize the book inside your framework's "Mounted" lifecycle hook (this ensures the HTML exists before the code runs).3. Framework Examples⚛️ React / Next.jsSince this library interacts with the DOM (browser), you must use a Client Component and the useEffect hook.components/Flipbook.jsJavaScript'use client'; // Required for Next.js 13+
29
+ ```
30
+ ###
31
+ #### 2. The Universal "Golden Rule"No matter which framework you use, the logic is always the same:
32
+ Import the class and the CSS.
33
+ Create a container div with a unique ID
34
+
35
+ (e.g., #my-book).Initialize the book inside your framework's "Mounted" lifecycle hook (this ensures the HTML exists before the code runs).
36
+
37
+ #### 3. Framework Examples
38
+
39
+ ### ⚛️ React / Next.js
40
+ Since this library interacts with the DOM (browser), you must use a Client Component and the useEffect hook. components/Flipbook.js
26
41
 
42
+ 'use client'; // Required for Next.js 13+
43
+
44
+ ```bash
27
45
  import { useEffect } from 'react';
28
46
  import { ProFlipbook } from '3d-pro-flipbook';
29
47
  import '3d-pro-flipbook/style.css'; // Import styles
@@ -32,15 +50,22 @@ export default function Flipbook({ pdfUrl }) {
32
50
  useEffect(() => {
33
51
  // Init inside useEffect to ensure DOM is ready
34
52
  new ProFlipbook('#my-book', pdfUrl, {
35
- brandText: 'My React Book'
53
+ brandText: '3D Flip Book',
54
+ backgroundColor: '#333',
55
+ brandLogo: "https://lh3.googleusercontent.com/a/ACg8ocJvulN68pLx-O-bP4k-dR2pWWBqSaJwMbCrWQ4iue63h80EXyU=s360-c-no"
36
56
  });
37
57
  }, [pdfUrl]);
38
58
 
39
59
  return (
40
- <div id="my-book" style={{ width: '100%', height: '100vh' }}></div>
60
+ <div id="my-book" style="width: 1200px; height: 80vh;"></div>
41
61
  );
42
62
  }
43
- 🟢 Vue.js / NuxtUse the onMounted hook to initialize the library.HTML<script setup>
63
+ ```
64
+
65
+ ### 🟢 Vue.js / Nuxt:
66
+ Use the onMounted hook to initialize the library.HTML
67
+ ```bash
68
+ <script setup>
44
69
  import { onMounted } from 'vue';
45
70
  import { ProFlipbook } from '3d-pro-flipbook';
46
71
  import '3d-pro-flipbook/style.css';
@@ -49,46 +74,71 @@ const pdfSource = '/book.pdf';
49
74
 
50
75
  onMounted(() => {
51
76
  new ProFlipbook('#vue-book', pdfSource, {
52
- brandText: 'Vue Book',
53
- backgroundColor: '#333'
77
+ brandText: '3D Flip Book',
78
+ backgroundColor: '#333',
79
+ brandLogo: "https://lh3.googleusercontent.com/a/ACg8ocJvulN68pLx-O-bP4k-dR2pWWBqSaJwMbCrWQ4iue63h80EXyU=s360-c-no"
54
80
  });
55
81
  });
56
82
  </script>
57
83
 
58
84
  <template>
59
- <div id="vue-book" style="width: 100%; height: 100vh;"></div>
85
+ <div id="vue-book" style="width: 1200px; height: 80vh;"></div>
60
86
  </template>
61
- 🔴 AngularInitialize the library inside the ngAfterViewInit lifecycle method.book.component.tsTypeScriptimport { Component, AfterViewInit } from '@angular/core';
87
+ ```
88
+
89
+ ### 🔴 Angular:
90
+ Initialize the library inside the ngAfterViewInit lifecycle method.book.component.ts
91
+ TypeScript
92
+ ```bash
93
+ import { Component, AfterViewInit } from '@angular/core';
62
94
  import { ProFlipbook } from '3d-pro-flipbook';
63
95
  // Ensure style.css is added to your angular.json styles array or imported in CSS
64
96
 
65
97
  @Component({
66
98
  selector: 'app-book',
67
- template: '<div id="ng-book" style="width: 100%; height: 100vh;"></div>'
99
+ template: '<div id="ng-book" style="width: 1200px; height: 80vh;"></div>'
68
100
  })
69
101
  export class BookComponent implements AfterViewInit {
70
102
  ngAfterViewInit() {
71
103
  new ProFlipbook('#ng-book', 'assets/book.pdf', {
72
- brandText: 'Angular Book'
104
+ brandText: '3D Flip Book',
105
+ backgroundColor: '#333',
106
+ brandLogo: "https://lh3.googleusercontent.com/a/ACg8ocJvulN68pLx-O-bP4k-dR2pWWBqSaJwMbCrWQ4iue63h80EXyU=s360-c-no"
73
107
  });
74
108
  }
75
109
  }
76
- 🟠 Svelte / SvelteKitUse the onMount function.HTML<script>
110
+ ```
111
+
112
+ ### 🟠 Svelte / SvelteKit
113
+ Use the onMount function.
114
+
115
+ HTML
116
+ ```bash
117
+ <script>
77
118
  import { onMount } from 'svelte';
78
119
  import { ProFlipbook } from '3d-pro-flipbook';
79
120
  import '3d-pro-flipbook/style.css';
80
121
 
81
122
  onMount(() => {
82
123
  new ProFlipbook('#svelte-book', '/book.pdf', {
83
- brandText: 'Svelte Book'
124
+ brandText: '3D Flip Book',
125
+ backgroundColor: '#333',
126
+ brandLogo: "https://lh3.googleusercontent.com/a/ACg8ocJvulN68pLx-O-bP4k-dR2pWWBqSaJwMbCrWQ4iue63h80EXyU=s360-c-no"
84
127
  });
85
128
  });
86
129
  </script>
130
+ <div id="svelte-book" style="width: 1200px; height: 80vh;"></div>
131
+ ```
87
132
 
88
- <div id="svelte-book" style="width: 100%; height: 100vh;"></div>
89
- 🌐 Vanilla HTML (No Framework)If you aren't using a bundler, you can use the CDN links directly.HTML<link rel="stylesheet" href="https://unpkg.com/3d-pro-flipbook@latest/dist/style.css">
133
+ ### 🌐 Vanilla HTML (No Framework)
134
+ If you aren't using a bundler, you can use the CDN links directly.
90
135
 
91
- <div id="book-container" style="width: 100%; height: 100vh;"></div>
136
+ HTML
137
+
138
+ ```bash
139
+ <link rel="stylesheet" href="https://unpkg.com/3d-pro-flipbook@latest/dist/style.css">
140
+
141
+ <div id="book-container" style="width: 1200px; height: 80vh;"></div>
92
142
 
93
143
  <script src="https://unpkg.com/3d-pro-flipbook@latest/dist/pro-flipbook.umd.js"></script>
94
144
 
@@ -96,12 +146,36 @@ export class BookComponent implements AfterViewInit {
96
146
  // Access via the global object 'ProFlipbook.ProFlipbook'
97
147
  document.addEventListener('DOMContentLoaded', () => {
98
148
  new ProFlipbook.ProFlipbook('#book-container', 'book.pdf', {
99
- brandText: "My HTML Book"
149
+ brandText: '3D Flip Book',
150
+ backgroundColor: '#333',
151
+ brandLogo: "https://lh3.googleusercontent.com/a/ACg8ocJvulN68pLx-O-bP4k-dR2pWWBqSaJwMbCrWQ4iue63h80EXyU=s360-c-no"
100
152
  });
101
153
  });
102
154
  </script>
103
- 4. Configuration OptionsYou can pass an options object as the third argument.OptionTypeDefaultDescriptionbrandTextString"Pro Flipbook"The text shown on the loader and book spine.backgroundColorString"#333"The background color of the viewer area.workerUrlStringCDN Link(Advanced) Custom path to PDF.js worker.JavaScriptnew ProFlipbook('#id', 'file.pdf', {
104
- brandText: "My Company",
105
- backgroundColor: "#ff0000"
155
+ ```
156
+
157
+ ### Configuration Options:
158
+ You can pass an options object as the third argument.
159
+
160
+ ```bash
161
+ new ProFlipbook("#id", "file.pdf", {
162
+ brandText: "3D Flip Book", // This text shown on the loader and book last page
163
+ backgroundColor: "#333", // The background color of the viewer area
164
+ brandFontColor: "#fff", // The brand title color in last page
165
+ pageBackgroundColor: "#5f5e5e", // This will apply to last page background color
166
+ pageFontColor: "#ffffff", // This will apply to loading text
167
+ brandLogo: "https://lh3.googleusercontent.com/a/ACg8ocJvulN68pLx-O-bP4k-dR2pWWBqSaJwMbCrWQ4iue63h80EXyU=s360-c-no" // The logo will be used in generated last page for Odd count files
106
168
  });
107
- ⚠️ Common Issues & Troubleshooting1. "Window is not defined" (Next.js / Nuxt / SSR)This happens because the library tries to access the browser window during Server Side Rendering.Fix: Ensure you are initializing the code inside useEffect (React), onMounted (Vue), or ensure the component is client-side only ('use client').2. "Container not found"The code ran before the HTML div was created.Fix: Double-check your ID matches (#my-book vs id="my-book") and that you are using the correct lifecycle hook (e.g., useEffect with an empty dependency array []).3. PDF CORS ErrorThe PDF fails to load from a remote URL.Fix: If loading a PDF from a different domain (e.g., AWS S3), ensure that server has CORS headers enabled (Access-Control-Allow-Origin: *).
169
+ ```
170
+
171
+ ### ⚠️ Common Issues & Troubleshooting
172
+ #### 1. "Window is not defined" (Next.js / Nuxt / SSR)This happens because the library tries to access the browser window during Server Side Rendering.
173
+
174
+ **Fix:** Ensure you are initializing the code inside useEffect (React), onMounted (Vue), or ensure the component is client-side only ('use client').
175
+
176
+ #### 2. "Container not found"The code ran before the HTML div was created.
177
+
178
+ **Fix:** Double-check your ID matches (#my-book vs id="my-book") and that you are using the correct lifecycle hook (e.g., useEffect with an empty dependency array []).
179
+ #### 3. PDF CORS ErrorThe PDF fails to load from a remote URL.
180
+
181
+ **Fix:** If loading a PDF from a different domain (e.g., AWS S3), ensure that server has CORS headers enabled (Access-Control-Allow-Origin: *).