flipbookengine 0.6.5 → 1.0.2

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +115 -75
  2. package/README.md +429 -295
  3. package/dist/components/AnnotationPlacement.d.ts +5 -0
  4. package/dist/components/AnnotationPopover.d.ts +10 -0
  5. package/dist/components/App.d.ts +26 -0
  6. package/dist/components/HotspotLayer.d.ts +14 -0
  7. package/dist/components/NoteEditor.d.ts +13 -0
  8. package/dist/components/NotePlacementLayer.d.ts +11 -0
  9. package/dist/components/NotesPanel.d.ts +17 -0
  10. package/dist/components/PluginPanels.d.ts +5 -0
  11. package/dist/components/ReaderHelp.d.ts +3 -0
  12. package/dist/components/ReaderShortcuts.d.ts +16 -0
  13. package/dist/components/SearchPanel.d.ts +11 -0
  14. package/dist/components/TableOfContents.d.ts +1 -0
  15. package/dist/components/TextLayer.d.ts +8 -0
  16. package/dist/components/Toolbar.d.ts +7 -1
  17. package/dist/components/ToolbarMore.d.ts +6 -0
  18. package/dist/components/Viewer.d.ts +8 -0
  19. package/dist/core/LayoutManager.d.ts +1 -1
  20. package/dist/core/PdfRenderer.d.ts +11 -0
  21. package/dist/core/TextLayerLoader.d.ts +5 -0
  22. package/dist/core/domSignal.d.ts +2 -0
  23. package/dist/core-entry.d.ts +14 -0
  24. package/dist/core.d.ts +1 -0
  25. package/dist/embed.d.ts +80 -0
  26. package/dist/engine-DD5qEHLm.js +4657 -0
  27. package/dist/engine-DD5qEHLm.js.map +1 -0
  28. package/dist/engine.d.ts +124 -0
  29. package/dist/feature-Cicli9ie.js +17 -0
  30. package/dist/feature-Cicli9ie.js.map +1 -0
  31. package/dist/flipbook-engine.core.js +8 -0
  32. package/dist/flipbook-engine.core.js.map +1 -0
  33. package/dist/flipbook-engine.css +1 -1
  34. package/dist/flipbook-engine.iife.js +51 -55
  35. package/dist/flipbook-engine.iife.js.map +1 -1
  36. package/dist/flipbook-engine.js +10 -6
  37. package/dist/flipbook-engine.js.map +1 -1
  38. package/dist/flipbook-engine.plugins-annotations.js +14 -0
  39. package/dist/flipbook-engine.plugins-annotations.js.map +1 -0
  40. package/dist/flipbook-engine.plugins-bookmarks.js +16 -0
  41. package/dist/flipbook-engine.plugins-bookmarks.js.map +1 -0
  42. package/dist/flipbook-engine.plugins-deep-link.js +14 -0
  43. package/dist/flipbook-engine.plugins-deep-link.js.map +1 -0
  44. package/dist/flipbook-engine.plugins-hotspots.js +15 -0
  45. package/dist/flipbook-engine.plugins-hotspots.js.map +1 -0
  46. package/dist/flipbook-engine.plugins-notes.js +16 -0
  47. package/dist/flipbook-engine.plugins-notes.js.map +1 -0
  48. package/dist/flipbook-engine.plugins-search.js +15 -0
  49. package/dist/flipbook-engine.plugins-search.js.map +1 -0
  50. package/dist/flipbook-engine.plugins-share.js +13 -0
  51. package/dist/flipbook-engine.plugins-share.js.map +1 -0
  52. package/dist/flipbook-engine.plugins-toc.js +14 -0
  53. package/dist/flipbook-engine.plugins-toc.js.map +1 -0
  54. package/dist/flipbook-engine.plugins.js +5 -0
  55. package/dist/flipbook-engine.plugins.js.map +1 -0
  56. package/dist/flipbook-engine.react.js +1 -1
  57. package/dist/flipbook-engine.vue.js +1 -1
  58. package/dist/i18n/locales/en.d.ts +39 -0
  59. package/dist/i18n/locales/tr.d.ts +39 -0
  60. package/dist/i18n/service.d.ts +117 -0
  61. package/dist/index-BhTR2SK6.js +366 -0
  62. package/dist/index-BhTR2SK6.js.map +1 -0
  63. package/dist/index.d.ts +10 -0
  64. package/dist/model/annotations.d.ts +15 -0
  65. package/dist/model/backend.d.ts +8 -0
  66. package/dist/model/hotspots.d.ts +40 -0
  67. package/dist/model/note-editor.d.ts +22 -0
  68. package/dist/model/search.d.ts +25 -0
  69. package/dist/model/text-layer.d.ts +21 -0
  70. package/dist/plugins/annotations.d.ts +4 -0
  71. package/dist/plugins/bookmarks.d.ts +4 -0
  72. package/dist/plugins/deep-link.d.ts +4 -0
  73. package/dist/plugins/feature.d.ts +5 -0
  74. package/dist/plugins/hotspots.d.ts +4 -0
  75. package/dist/plugins/index.d.ts +65 -0
  76. package/dist/plugins/notes.d.ts +4 -0
  77. package/dist/plugins/search.d.ts +4 -0
  78. package/dist/plugins/share.d.ts +4 -0
  79. package/dist/plugins/toc.d.ts +4 -0
  80. package/dist/plugins-annotations.d.ts +1 -0
  81. package/dist/plugins-bookmarks.d.ts +1 -0
  82. package/dist/plugins-deep-link.d.ts +1 -0
  83. package/dist/plugins-hotspots.d.ts +1 -0
  84. package/dist/plugins-notes.d.ts +1 -0
  85. package/dist/plugins-search.d.ts +1 -0
  86. package/dist/plugins-share.d.ts +1 -0
  87. package/dist/plugins-toc.d.ts +1 -0
  88. package/dist/plugins.d.ts +1 -0
  89. package/dist/state/store.d.ts +35 -5
  90. package/dist/vue/index.d.ts +1 -1
  91. package/docs/api-reference.md +228 -0
  92. package/docs/backend-text-layers.md +40 -0
  93. package/docs/frameworks.md +73 -0
  94. package/docs/getting-started.md +128 -0
  95. package/docs/i18n.md +47 -0
  96. package/docs/migration-0.4.0.md +24 -0
  97. package/docs/migration-0.5.0.md +25 -0
  98. package/docs/migration-1.0.0.md +59 -0
  99. package/docs/plugin-architecture.md +103 -0
  100. package/docs/release-checklist.md +37 -0
  101. package/docs/theming.md +61 -0
  102. package/package.json +52 -1
  103. package/dist/engine-DhQ2zxpm.js +0 -3535
  104. package/dist/engine-DhQ2zxpm.js.map +0 -1
package/README.md CHANGED
@@ -1,295 +1,429 @@
1
- # FlipbookEngine
2
-
3
- > **Release notice:** `flipbookengine@0.6.5` is the latest published release and includes the localized Table of Contents API.
4
- > **Development notice:** Version 0.6.5 adds automatic PDF A3 splitting, per-theme backgrounds, responsive viewer gutters, enlarged thumbnails, and mobile touch fixes.
5
-
6
- [![NPM Version](https://img.shields.io/npm/v/flipbookengine?style=flat-square&color=blue)](https://www.npmjs.com/package/flipbookengine)
7
- [![License](https://img.shields.io/npm/l/flipbookengine?style=flat-square)](https://github.com/Bizeka/flipbook-engine/blob/main/LICENSE)
8
- [![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/flipbookengine?style=flat-square)](https://www.npmjs.com/package/flipbookengine)
9
- [![NPM Downloads](https://img.shields.io/npm/dt/flipbookengine?style=flat-square)](https://www.npmjs.com/package/flipbookengine)
10
-
11
- **[Live Demo & Playground ↗](https://flipbookengine.com)**
12
-
13
- FlipbookEngine is a modern, lightweight, and embeddable HTML flipbook viewer for PDF-backed catalogs, brochures, and digital publications. Written in TypeScript, it features single-page and spread modes, a thumbnail rail, smooth zoom/pan, full internationalization (i18n), and robust theme customization.
14
-
15
- ## Highlights
16
-
17
- - **Dual-Mode Layout**: Seamlessly switches between single-page (mobile-optimized) and spread (book/catalog layout) modes.
18
- - **Rich Interaction**: Built-in thumbnail navigation rail, smooth zoom & pan, and HTML5 fullscreen support.
19
- - **Media & Autoplay**: Configurable page-flip sound effects and automated slideshow presentation with `Autoplay`.
20
- - **Theme Engine**: Styled with compiled CSS and CSS Custom Properties, featuring full support for light/dark modes (auto-responsive to Bootstrap 5 or tailorable per instance).
21
- - **Multi-Language (i18n)**: Out-of-the-box support for English (`en`) and Turkish (`tr`) with customizable overrides.
22
- - **Framework Wrappers**: Direct React and Vue wrapper exports for seamless modern integration.
23
- - **Progressive PDF Rendering**: PDF pages render on demand with bounded concurrency and an instance-local LRU cache, keeping large documents responsive.
24
-
25
- ## Installation
26
-
27
- Install via npm:
28
-
29
- ```bash
30
- npm install flipbookengine
31
- ```
32
-
33
- `pdfjs-dist` is a production dependency of FlipbookEngine. It is installed by npm, but is deliberately excluded from the FlipbookEngine bundle so applications can deduplicate, cache, and upgrade PDF.js independently.
34
-
35
- ## Quick Start
36
-
37
- ### npm and Bundlers
38
-
39
- Configure the PDF.js worker in the consuming application. The `?url` suffix is supported by Vite and other modern bundlers that emit imported assets.
40
-
41
- ```ts
42
- import { FlipbookEngine } from 'flipbookengine';
43
- import 'flipbookengine/styles.css';
44
- import pdfWorkerSrc from 'pdfjs-dist/build/pdf.worker.mjs?url';
45
-
46
- const engine = new FlipbookEngine('#viewer', {
47
- allowDownload: true,
48
- showThumbs: false,
49
- primaryColor: '#7367f0',
50
- theme: 'auto',
51
- locale: 'en',
52
- pdfWorkerSrc,
53
- pdfRenderCacheSize: 32,
54
- pdfPageMode: 'auto',
55
- background: {
56
- light: { color: '#f8fafc', image: '/branding/light.webp', size: 'cover' },
57
- dark: { color: '#0f172a', image: '/branding/dark.webp', size: 'cover' }
58
- }
59
- });
60
-
61
- await engine.init('/files/catalog.pdf');
62
- ```
63
-
64
- Passing `pages` remains optional. When omitted, FlipbookEngine creates the page structure from `pdfUrl`, renders the first page before `init` resolves, and prefetches the next page. Additional pages render as they become visible or are selected. In `pdfPageMode: 'auto'` (the default), ISO A3 landscape pages are normalized into two logical pages; use `'single'` to keep every PDF page intact or `'split'` to split every landscape PDF page.
65
-
66
- `pdfRenderCacheSize` controls the per-instance LRU cache (default `32`, set to `0` to disable it).
67
-
68
- ### Browser CDN
69
-
70
- Use the ESM build with an import map for PDF.js. The worker must be served from a URL your site permits in its Content Security Policy.
71
-
72
- ```html
73
- <link rel="stylesheet" href="https://unpkg.com/flipbookengine@0.6.5/dist/flipbook-engine.css" />
74
- <div id="viewer" style="width: 100%; height: 600px;"></div>
75
-
76
- <script type="importmap">
77
- {
78
- "imports": {
79
- "pdfjs-dist": "https://unpkg.com/pdfjs-dist@5.4.530/build/pdf.min.mjs"
80
- }
81
- }
82
- </script>
83
- <script type="module">
84
- import { FlipbookEngine } from 'https://unpkg.com/flipbookengine@0.6.5/dist/flipbook-engine.js';
85
-
86
- const engine = new FlipbookEngine('#viewer', {
87
- pdfWorkerSrc: 'https://unpkg.com/pdfjs-dist@5.4.530/build/pdf.worker.min.mjs'
88
- });
89
-
90
- await engine.init('/files/catalog.pdf');
91
- </script>
92
- ```
93
-
94
- ### React
95
-
96
- ```tsx
97
- import React, { useRef } from 'react';
98
- import { Flipbook, FlipbookRef } from 'flipbookengine/react';
99
- import 'flipbookengine/styles.css';
100
-
101
- function CatalogViewer() {
102
- const flipbookRef = useRef<FlipbookRef>(null);
103
-
104
- const handleNextPage = () => {
105
- flipbookRef.current?.goToPage(flipbookRef.current.getCurrentPage() + 1);
106
- };
107
-
108
- return (
109
- <Flipbook
110
- ref={flipbookRef}
111
- pdfUrl="/files/catalog.pdf"
112
- pages={[
113
- { kind: 'cover', pageNumber: 1, normal: '/img/1.jpg', low: '/img/1-low.jpg', thumb: '/img/1-thumb.jpg' },
114
- { kind: 'spread', pageNumbers: [2, 3], normal: '/img/2-3.jpg', low: '/img/2-3-low.jpg', thumb: '/img/2-3-thumb.jpg' }
115
- ]}
116
- allowDownload={true}
117
- showThumbs={true}
118
- primaryColor="#7367f0"
119
- />
120
- );
121
- }
122
- ```
123
-
124
- ### Vue 3
125
-
126
- ```vue
127
- <template>
128
- <Flipbook
129
- pdfUrl="/files/catalog.pdf"
130
- :pages="pages"
131
- :allowDownload="true"
132
- :showThumbs="true"
133
- primaryColor="#7367f0"
134
- />
135
- </template>
136
-
137
- <script setup>
138
- import { Flipbook } from 'flipbookengine/vue';
139
- import 'flipbookengine/styles.css';
140
-
141
- const pages = [
142
- { kind: 'cover', pageNumber: 1, normal: '/img/1.jpg', low: '/img/1-low.jpg', thumb: '/img/1-thumb.jpg' },
143
- { kind: 'spread', pageNumbers: [2, 3], normal: '/img/2-3.jpg', low: '/img/2-3-low.jpg', thumb: '/img/2-3-thumb.jpg' }
144
- ];
145
- </script>
146
- ```
147
-
148
- ## Migration Notes
149
-
150
- Upgrading from 0.3.x to 0.4.0 keeps the public engine methods intact. The release isolates state per engine instance, makes wrapper updates lifecycle-safe, and scopes viewer markup to its container. If host CSS or automation selected the former fixed viewer IDs, migrate those selectors to the instance classes documented in the theming guide. PDF-backed consumers should configure `pdfWorkerSrc`; image-only viewers do not expose a download control.
151
-
152
- For 0.5.0 behavior, see the [0.5.0 migration guide](./docs/migration-0.5.0.md). PDF-backed viewers now render on demand; callers should use `progress` and `error` events for rendering telemetry.
153
-
154
-
155
- ## Public API Reference
156
-
157
- The `FlipbookEngine` class exposes the following public methods:
158
-
159
- - **`init(pdfUrl: string, imageList?: FlipbookPageAsset[])`**: Initializes the viewer and loads the flipbook with pages.
160
- - **`goToPage(pageIndex: number)`**: Navigates programmatically to a 0-based page index.
161
- - **`getCurrentPage()`**: Returns the 0-based index of the currently active page.
162
- - **`getTotalPages()`**: Returns the total number of pages.
163
- - **`getZoom()`**: Returns the current zoom level (default is `1`).
164
- - **`setZoom(zoomLevel: number)`**: Programmatically sets the zoom level (accepts values between `0.5` and `5`).
165
- - **`setSingleMode(isSingle: boolean)`**: Programmatically toggles between single-page mode (`true`) and double-page spread mode (`false`).
166
- - **`toggleFullscreen()`**: Programmatically toggles fullscreen mode.
167
- - **`updateOptions(options: Partial<FlipbookEngineOptions>)`**: Updates instance options at runtime.
168
- - **`setLocale(locale: string, messages?: PartialFlipbookMessages | Record<string, PartialFlipbookMessages>)`**: Updates the locale programmatically and optionally overrides messages for that locale.
169
- - **`destroy(keepContainer = false)`**: Tears down the instance and listeners; when `true`, keeps the container markup for an immediate reinitialization.
170
-
171
- ### Subscribing to Events
172
-
173
- You can subscribe to events using `.on()`. PDF-backed initialization reports loading/rendering progress and emits a structured `error` event when loading or rendering fails:
174
-
175
- ```ts
176
- const unsubscribe = engine.on('pageChange', ({ currentPage, totalPages, isSingle }) => {
177
- console.log('Page Changed:', currentPage, 'Total:', totalPages);
178
- });
179
-
180
- // To unsubscribe:
181
- unsubscribe();
182
- ```
183
-
184
- Supported events: `init`, `progress`, `pageChange`, `zoomChange`, `singlePageModeChange`, `thumbsToggle`, `tocToggle`, `orientationChange`, `error`, `destroy`.
185
-
186
- | Option | Type | Default | Description |
187
- | :--- | :--- | :--- | :--- |
188
- | `showArrows` | `boolean` | `true` | Shows the previous/next navigation arrows. |
189
- | `showToc` | `boolean` | `false` | Shows the table of contents panel when `toc` entries are supplied. |
190
- | `toc` | `FlipbookTocEntry[]` | `[]` | Host-provided chapter/category entries with zero-based page indexes. |
191
- | `soundEnabled` | `boolean` | `true` | Enables page turning sound effect. |
192
- | `soundUrl` | `string` | `'https://.../page-flip.mp3'` | URL of the audio file. |
193
- | `autoPlayInterval`| `number` | `3000` | Autoplay page duration in milliseconds. |
194
- | `flippingTime` | `number` | `1000` | Duration of the page turn animation in milliseconds; automatically disabled when reduced motion is preferred. |
195
- | `maxShadowOpacity` | `number` | `0.5` | Maximum opacity of the shadow during page turn (0 to 1). |
196
- | `whiteLabel` | `boolean` | `false` | Hides the "Powered by FlipbookEngine" watermark. |
197
- | `pdfWorkerSrc` | `string` | - | URL of the PDF.js worker emitted or hosted by the consuming application. |
198
- | `pdfRenderConcurrency` | `number` | `3` | Maximum number of PDF pages rendered concurrently when on-demand pages are requested. |
199
- | `pdfRenderCacheSize` | `number` | `32` | Maximum number of rendered PDF page images retained per engine instance (LRU); `0` disables caching. |
200
- | `pdfPageMode` | `'auto' \| 'single' \| 'split'` | `'auto'` | Controls PDF page splitting: A3 landscape pages are split automatically, all landscape pages can be split explicitly, or splitting can be disabled. |
201
- | `background` | `FlipbookBackgrounds \| null` | `null` | Optional light/dark viewer backgrounds with color, image, size, position, and repeat settings. |
202
-
203
- ## PDF page formats
204
-
205
- PDF.js page dimensions are detected at runtime, so portrait A4, landscape A4, and other page ratios are supported without a fixed size preset. A3 landscape pages are split into left/right logical pages when `pdfPageMode` is `'auto'` or `'split'`; the halves are presented as an A4-like spread in double-page mode.
206
-
207
- ## Styling and Theming
208
-
209
- FlipbookEngine features fully custom-property-based styling compatible with modern styling systems.
210
-
211
- ### Global CSS Variables
212
-
213
- ```css
214
- :root {
215
- --mainbgcolor: #f3f6fb;
216
- --panelbgcolor: #172033;
217
- --flipbook-accent: #7367f0;
218
- --thumbrailbgcolor: #0f172a;
219
- }
220
- ```
221
-
222
- ## Performance & Bundle Metrics
223
-
224
- FlipbookEngine is designed for responsive rendering with hardware-accelerated CSS 3D transforms and a lightweight DOM update path.
225
-
226
- ### Package Size and PDF.js
227
-
228
- FlipbookEngine does not bundle PDF.js or its worker. `pdfjs-dist` remains a normal npm dependency, while the host application supplies `pdfWorkerSrc`. This keeps the FlipbookEngine package smaller and lets the application control PDF.js versioning, caching, CSP, and worker hosting.
229
-
230
- * **Core engine:** excludes PDF.js and the PDF worker.
231
- * **Styles:** distributed as `flipbookengine/styles.css`.
232
- * **PDF rendering:** enabled by configuring `pdfWorkerSrc` as shown above.
233
-
234
- ### Performance Highlights
235
- * **Hardware Accelerated:** Uses CSS-based 3D transformations (`transform: rotateY`, `translateZ`) without a WebGL runtime.
236
- * **Progressive Image Quality:** Loads low-quality page assets first and upgrades visible pages to their normal-quality source through `IntersectionObserver`.
237
- * **On-demand PDF Rendering:** Large PDFs create lightweight placeholders first; the current page and next page render before or during navigation.
238
- * **Bounded PDF Rendering:** PDF pages are rendered with configurable concurrency (`pdfRenderConcurrency`, default `3`) and can be cancelled when an initialization is superseded or destroyed.
239
- * **PDF Render Cache:** A bounded per-instance LRU cache (`pdfRenderCacheSize`, default `32`) avoids repeated canvas work while preventing unbounded memory growth.
240
-
241
- ## FlipbookEngine vs. The Industry
242
-
243
- When choosing a flipbook library, here is how we compare to other solutions:
244
-
245
- * **Legacy Libraries (e.g., Turn.js):** Turn.js is over a decade old, relies on jQuery, and lacks native PDF support. **FlipbookEngine** uses a modern framework-agnostic stack (Vanilla/React/Vue), TypeScript, and has built-in PDF.js integration.
246
- * **Heavy 3D Plugins (e.g., DearFlip, Real3D):** Many 3D plugins use WebGL, which can increase runtime overhead on mobile. **FlipbookEngine** uses StPageFlip with CSS 2D/3D transforms and no WebGL runtime.
247
- * **Closed SaaS Platforms (e.g., Issuu, Heyzine):** These charge high monthly fees and lock your data on their servers. **FlipbookEngine** gives you 100% control to host and embed directly in your own code (AGPL-3.0).
248
-
249
- ---
250
-
251
- ## Acknowledgments
252
-
253
- A special thanks to the incredible team behind **[Serenity](https://github.com/serenity-is/serenity)**. FlipbookEngine's reactive UI layer is powered by **[domwise](https://github.com/serenity-is/serenity/tree/master/packages/domwise)**. Coupled with `@preact/signals-core`, this keeps the UI update path small without requiring a traditional Virtual DOM runtime.
254
-
255
- ---
256
- ## Roadmap
257
-
258
- FlipbookEngine has two complementary targets: an AGPL open-source viewer package and a separate closed-source commercial backend edition.
259
-
260
- ### Open-source v1.0.0 (AGPL viewer)
261
-
262
- The npm package remains an embeddable, framework-agnostic PDF viewer. The open-source v1.0.0 target focuses on client-side reader capabilities:
263
-
264
- - **Table of Contents (Index):** Interactive navigation to chapters or product categories.
265
- - **Page Notes & Annotations:** Reader notes and bookmarks stored by the host application.
266
- - **Full-Text PDF Search:** Client-side text extraction and highlighting without blocking the viewer.
267
- - **Interactive Hotspots & Pop-ups:** Custom overlays for media, galleries, and commerce links.
268
- - **Deep Linking & Social Share:** URLs that address specific pages or spreads.
269
-
270
- The open-source viewer continues to use PDF.js as an external npm dependency and does not require a backend renderer.
271
-
272
- ### Commercial edition (closed-source backend)
273
-
274
- The commercial roadmap is separate from the AGPL package and is intended for a separate backend project. It will provide licensed server-side capabilities, including:
275
-
276
- - **Backend PDF rendering:** Secure, server-side rendering and caching for protected documents and high-volume workloads.
277
- - **Protected partial downloads:** Server-generated page selections and authorization-aware download policies.
278
- - **AI-assisted document features:** Backend indexing, catalog search, and Chat with Docs integrations.
279
- - **Enterprise identity and provenance:** OIDC, auditability, tenant controls, and deployment integration.
280
-
281
- These backend renderer and enterprise features will not be included in the public `flipbookengine` npm package; they will be delivered under the commercial license.
282
-
283
- ---
284
-
285
- ## Licensing
286
-
287
- FlipbookEngine is distributed under a dual-license model:
288
-
289
- - **Open Source**: GNU Affero General Public License v3.0 or later (see [LICENSE](./LICENSE)).
290
- - **Commercial**: For use in closed-source projects, proprietary SaaS platforms, or agency client deliveries (see [COMMERCIAL_LICENSE.md](./COMMERCIAL_LICENSE.md)).
291
-
292
- For commercial licenses and inquiries, contact: **murat.dogan@hotmail.com.tr**
293
-
294
-
295
-
1
+ # FlipbookEngine
2
+
3
+ > **Current release:** `flipbookengine@1.0.2` includes the localized Table of Contents API, backend text layers and coordinate notes.
4
+ > **1.0.0 scope:** Version 1.0.0 added the plugin contract, independent feature entrypoints, TOC runtime/embed APIs, and the complete open-source reader surface.
5
+
6
+ [![NPM Version](https://img.shields.io/npm/v/flipbookengine?style=flat-square&color=blue)](https://www.npmjs.com/package/flipbookengine)
7
+ [![License](https://img.shields.io/npm/l/flipbookengine?style=flat-square)](https://github.com/Bizeka/flipbook-engine/blob/main/LICENSE)
8
+ [![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/flipbookengine?style=flat-square)](https://www.npmjs.com/package/flipbookengine)
9
+ [![NPM Downloads](https://img.shields.io/npm/dt/flipbookengine?style=flat-square)](https://www.npmjs.com/package/flipbookengine)
10
+
11
+ **[Live Demo & Playground ↗](https://flipbookengine.com)**
12
+
13
+ FlipbookEngine is a modern, lightweight, and embeddable HTML flipbook viewer for PDF-backed catalogs, brochures, and digital publications. Written in TypeScript, it features single-page and spread modes, a thumbnail rail, smooth zoom/pan, full internationalization (i18n), and robust theme customization.
14
+
15
+ ## Highlights
16
+
17
+ - **Dual-Mode Layout**: Seamlessly switches between single-page (mobile-optimized) and spread (book/catalog layout) modes.
18
+ - **Rich Interaction**: Built-in thumbnail navigation rail, smooth zoom & pan, and HTML5 fullscreen support.
19
+ - **Media & Autoplay**: Configurable page-flip sound effects and automated slideshow presentation with `Autoplay`.
20
+ - **Theme Engine**: Styled with compiled CSS and CSS Custom Properties, featuring full support for light/dark modes (auto-responsive to Bootstrap 5 or tailorable per instance).
21
+ - **Multi-Language (i18n)**: Out-of-the-box support for English (`en`) and Turkish (`tr`) with customizable overrides.
22
+ - **Framework Wrappers**: Direct React and Vue wrapper exports for seamless modern integration.
23
+ - **Progressive PDF Rendering**: PDF pages render on demand with bounded concurrency and an instance-local LRU cache, keeping large documents responsive.
24
+ - **Localized Sharing**: The toolbar includes a Share control that opens the native share sheet or copies the current page URL; enable `deepLink: true` for shareable page navigation.
25
+ - **Host-Managed Bookmarks**: The toolbar can toggle the current page bookmark; hosts can initialize and persist zero-based bookmark indexes through the public API and `bookmarkChange` event.
26
+ - **Host-Managed Notes**: The localized notes toolbar opens an inline editor; hosts can initialize, update, and persist page notes through the public API and `noteChange` event without coupling the viewer to a storage backend.
27
+ - **Client-Side PDF Search**: Extracts and searches PDF text on demand with localized snippets and normalized text-rectangle highlighting.
28
+ - **Interactive Hotspots**: Adds normalized page overlays with accessible plain-text popups and optional links.
29
+
30
+ ## Backend text layers for image books
31
+
32
+ WebP/JPEG books can consume persistent text extracted by the host backend. Supply optional `textLayerProvider(pageIndex, signal)` alongside `searchProvider`. The reader loads at most the current page and its neighbors, validates normalized run coordinates, and overlays transparent selectable text without downloading the PDF. Enable **More actions > Select text**, or call `setTextSelection(true)`; Escape returns to navigation mode. Pointer selection is isolated from flip gestures and note long-press. Toolbar/keyboard page navigation stays available.
33
+
34
+ Extraction, OCR, indexing, authorization and persistence belong to the host, not the browser. A text layer is fixed-layout accessibility/selection data, not EPUB reflow. See [backend text layer contract](docs/backend-text-layers.md) and [API reference](docs/api-reference.md). These APIs are available from npm 1.0.2.
35
+
36
+ ## Installation
37
+
38
+ Install via npm:
39
+
40
+ ```bash
41
+ npm install flipbookengine
42
+ ```
43
+
44
+ `pdfjs-dist` is a production dependency of FlipbookEngine. It is installed by npm, but is deliberately excluded from the FlipbookEngine bundle so applications can deduplicate, cache, and upgrade PDF.js independently.
45
+
46
+ ## Quick Start
47
+
48
+ ### npm and Bundlers
49
+
50
+ Configure the PDF.js worker in the consuming application. The `?url` suffix is supported by Vite and other modern bundlers that emit imported assets.
51
+
52
+ ```ts
53
+ import { FlipbookEngine } from 'flipbookengine';
54
+ import 'flipbookengine/styles.css';
55
+ import pdfWorkerSrc from 'pdfjs-dist/build/pdf.worker.mjs?url';
56
+
57
+ const engine = new FlipbookEngine('#viewer', {
58
+ allowDownload: true,
59
+ showThumbs: false,
60
+ primaryColor: '#7367f0',
61
+ theme: 'auto',
62
+ locale: 'en',
63
+ pdfWorkerSrc,
64
+ pdfRenderCacheSize: 32,
65
+ pdfPageMode: 'auto',
66
+ background: {
67
+ light: { color: '#f8fafc', image: '/branding/light.webp', size: 'cover' },
68
+ dark: { color: '#0f172a', image: '/branding/dark.webp', size: 'cover' }
69
+ }
70
+ });
71
+
72
+ await engine.init('/files/catalog.pdf');
73
+ ```
74
+
75
+ Passing `pages` remains optional. When omitted, FlipbookEngine creates the page structure from `pdfUrl`, renders the first page before `init` resolves, and prefetches the next page. Additional pages render as they become visible or are selected. In `pdfPageMode: 'auto'` (the default), ISO A3 landscape pages are normalized into two logical pages; use `'single'` to keep every PDF page intact or `'split'` to split every landscape PDF page.
76
+
77
+ `pdfRenderCacheSize` controls the per-instance LRU cache (default `32`, set to `0` to disable it).
78
+
79
+ ### Browser CDN
80
+
81
+ Use the ESM build with an import map for PDF.js. The worker must be served from a URL your site permits in its Content Security Policy.
82
+
83
+ ```html
84
+ <link rel="stylesheet" href="https://unpkg.com/flipbookengine@1.0.2/dist/flipbook-engine.css" />
85
+ <div id="viewer" style="width: 100%; height: 600px;"></div>
86
+
87
+ <script type="importmap">
88
+ {
89
+ "imports": {
90
+ "pdfjs-dist": "https://unpkg.com/pdfjs-dist@5.4.530/build/pdf.min.mjs"
91
+ }
92
+ }
93
+ </script>
94
+ <script type="module">
95
+ import { FlipbookEngine } from 'https://unpkg.com/flipbookengine@1.0.2/dist/flipbook-engine.js';
96
+
97
+ const engine = new FlipbookEngine('#viewer', {
98
+ pdfWorkerSrc: 'https://unpkg.com/pdfjs-dist@5.4.530/build/pdf.worker.min.mjs'
99
+ });
100
+
101
+ await engine.init('/files/catalog.pdf');
102
+ </script>
103
+ ```
104
+
105
+ ### React
106
+
107
+ ```tsx
108
+ import React, { useRef } from 'react';
109
+ import { Flipbook, FlipbookRef } from 'flipbookengine/react';
110
+ import 'flipbookengine/styles.css';
111
+
112
+ function CatalogViewer() {
113
+ const flipbookRef = useRef<FlipbookRef>(null);
114
+
115
+ const handleNextPage = () => {
116
+ flipbookRef.current?.goToPage(flipbookRef.current.getCurrentPage() + 1);
117
+ };
118
+
119
+ return (
120
+ <Flipbook
121
+ ref={flipbookRef}
122
+ pdfUrl="/files/catalog.pdf"
123
+ pages={[
124
+ { kind: 'cover', pageNumber: 1, normal: '/img/1.jpg', low: '/img/1-low.jpg', thumb: '/img/1-thumb.jpg' },
125
+ { kind: 'spread', pageNumbers: [2, 3], normal: '/img/2-3.jpg', low: '/img/2-3-low.jpg', thumb: '/img/2-3-thumb.jpg' }
126
+ ]}
127
+ allowDownload={true}
128
+ showThumbs={true}
129
+ primaryColor="#7367f0"
130
+ />
131
+ );
132
+ }
133
+ ```
134
+
135
+ ### Vue 3
136
+
137
+ ```vue
138
+ <template>
139
+ <Flipbook
140
+ pdfUrl="/files/catalog.pdf"
141
+ :pages="pages"
142
+ :allowDownload="true"
143
+ :showThumbs="true"
144
+ primaryColor="#7367f0"
145
+ />
146
+ </template>
147
+
148
+ <script setup>
149
+ import { Flipbook } from 'flipbookengine/vue';
150
+ import 'flipbookengine/styles.css';
151
+
152
+ const pages = [
153
+ { kind: 'cover', pageNumber: 1, normal: '/img/1.jpg', low: '/img/1-low.jpg', thumb: '/img/1-thumb.jpg' },
154
+ { kind: 'spread', pageNumbers: [2, 3], normal: '/img/2-3.jpg', low: '/img/2-3-low.jpg', thumb: '/img/2-3-thumb.jpg' }
155
+ ];
156
+ </script>
157
+ ```
158
+
159
+
160
+
161
+ ## Iframe embedding
162
+
163
+ For a viewer hosted in an iframe, connect the bridge from the iframe document and allow only the parent origin:
164
+
165
+ ```javascript
166
+ const engine = new FlipbookEngine('#viewer', { showThumbs: false });
167
+ engine.connectEmbed({
168
+ allowedOrigins: ['https://catalog.example.com']
169
+ });
170
+ await engine.init('/files/catalog.pdf');
171
+ ```
172
+
173
+ From the parent page, use the controller exported by the package:
174
+
175
+ ```javascript
176
+ import { createFlipbookEmbedController } from 'flipbookengine';
177
+
178
+ const controller = createFlipbookEmbedController(
179
+ document.querySelector('#catalog-frame'),
180
+ { targetOrigin: 'https://viewer.example.com' }
181
+ );
182
+ await controller.goToPage(2);
183
+ ```
184
+
185
+ Always configure explicit origins for cross-origin embeds. The bridge supports page navigation, zoom, single mode, option updates, fullscreen, TOC read/update, search, state queries, and event forwarding.
186
+
187
+ ## Migration Notes
188
+
189
+ Upgrading from 0.3.x to 0.4.0 keeps the public engine methods intact. The release isolates state per engine instance, makes wrapper updates lifecycle-safe, and scopes viewer markup to its container. If host CSS or automation selected the former fixed viewer IDs, migrate those selectors to the instance classes documented in the theming guide. PDF-backed consumers should configure `pdfWorkerSrc`; image-only viewers do not expose a download control.
190
+
191
+ For 0.5.0 behavior, see the [0.5.0 migration guide](./docs/migration-0.5.0.md). PDF-backed viewers now render on demand; callers should use `progress` and `error` events for rendering telemetry.
192
+
193
+
194
+ For the 1.0.0 migration and the 0.x compatibility boundary, see the [1.0.0 migration guide](./docs/migration-1.0.0.md).
195
+
196
+ ## Public API Reference
197
+
198
+ The `FlipbookEngine` class exposes the following public methods:
199
+
200
+ - **`init(pdfUrl: string, imageList?: FlipbookPageAsset[])`**: Initializes the viewer and loads the flipbook with pages.
201
+ - **`goToPage(pageIndex: number)`**: Navigates programmatically to a 0-based page index.
202
+ - **`getCurrentPage()`**: Returns the 0-based index of the currently active page.
203
+ - **`getTotalPages()`**: Returns the total number of pages.
204
+ - **`getZoom()`**: Returns the current zoom level (default is `1`).
205
+ - **`setZoom(zoomLevel: number)`**: Programmatically sets the zoom level (accepts values between `0.5` and `5`).
206
+ - **`setSingleMode(isSingle: boolean)`**: Programmatically toggles between single-page mode (`true`) and double-page spread mode (`false`).
207
+ - **`toggleFullscreen()`**: Programmatically toggles fullscreen mode.
208
+ - **`updateOptions(options: Partial<FlipbookEngineOptions>)`**: Updates instance options at runtime.
209
+ - **`setLocale(locale: string, messages?: PartialFlipbookMessages | Record<string, PartialFlipbookMessages>)`**: Updates the locale programmatically and optionally overrides messages for that locale.
210
+ - **`getPageUrl(pageIndex = getCurrentPage())`**: Returns a shareable URL for a 0-based page index.
211
+ - **`sharePage(pageIndex = getCurrentPage())`**: Opens the native share dialog or copies the page URL to the clipboard. The toolbar exposes this behavior through a localized Share button.
212
+ - **`getBookmarkedPages()`**: Returns the sorted zero-based bookmark indexes.
213
+ - **`isBookmarked(pageIndex = getCurrentPage())`**: Checks whether a page is bookmarked.
214
+ - **`setBookmark(pageIndex, bookmarked)`** / **`toggleBookmark(pageIndex)`**: Updates bookmark state and emits `bookmarkChange`; hosts can persist the event payload.
215
+ - **`getNotes()`** / **`getNote(pageIndex)`**: Reads host-managed page notes.
216
+ - **`setNote(pageIndex, note)`** / **`clearNote(pageIndex)`**: Updates notes and emits `noteChange`; empty notes are removed. The toolbar editor is intentionally host-storage agnostic, so a backend can persist each event later.
217
+ - **`destroy(keepContainer = false)`**: Tears down the instance and listeners; when `true`, keeps the container markup for an immediate reinitialization.
218
+
219
+ ### Subscribing to Events
220
+
221
+ You can subscribe to events using `.on()`. PDF-backed initialization reports loading/rendering progress and emits a structured `error` event when loading or rendering fails:
222
+
223
+ ```ts
224
+ const unsubscribe = engine.on('pageChange', ({ currentPage, totalPages, isSingle }) => {
225
+ console.log('Page Changed:', currentPage, 'Total:', totalPages);
226
+ });
227
+
228
+ // To unsubscribe:
229
+ unsubscribe();
230
+ ```
231
+
232
+ Supported events: `init`, `progress`, `pageChange`, `zoomChange`, `singlePageModeChange`, `thumbsToggle`, `tocToggle`, `orientationChange`, `deepLinkChange`, `bookmarkChange`, `noteChange`, `searchChange`, `hotspotActivate`, `annotationActivate`, `error`, `destroy`.
233
+
234
+ | Option | Type | Default | Description |
235
+ | :--- | :--- | :--- | :--- |
236
+ | `showArrows` | `boolean` | `true` | Shows the previous/next navigation arrows. |
237
+ | `showToc` | `boolean` | `false` | Shows the table of contents panel when `toc` entries are supplied. |
238
+ | `toc` | `FlipbookTocEntry[]` | `[]` | Host-provided chapter/category entries with zero-based page indexes. |
239
+ | `soundEnabled` | `boolean` | `true` | Enables page turning sound effect. |
240
+ | `soundUrl` | `string` | `'https://.../page-flip.mp3'` | URL of the audio file. |
241
+ | `autoPlayInterval`| `number` | `3000` | Autoplay page duration in milliseconds. |
242
+ | `flippingTime` | `number` | `1000` | Duration of the page turn animation in milliseconds; automatically disabled when reduced motion is preferred. |
243
+ | `maxShadowOpacity` | `number` | `0.5` | Maximum opacity of the shadow during page turn (0 to 1). |
244
+ | `whiteLabel` | `boolean` | `false` | Hides the "Powered by FlipbookEngine" watermark. |
245
+ | `pdfWorkerSrc` | `string` | - | URL of the PDF.js worker emitted or hosted by the consuming application. |
246
+ | `pdfRenderConcurrency` | `number` | `3` | Maximum number of PDF pages rendered concurrently when on-demand pages are requested. |
247
+ | `pdfRenderCacheSize` | `number` | `32` | Maximum number of rendered PDF page images retained per engine instance (LRU); `0` disables caching. |
248
+ | `pdfPageMode` | `'auto' \| 'single' \| 'split'` | `'auto'` | Controls PDF page splitting: A3 landscape pages are split automatically, all landscape pages can be split explicitly, or splitting can be disabled. |
249
+ | `background` | `FlipbookBackgrounds \| null` | `null` | Optional light/dark viewer backgrounds with color, image, size, position, and repeat settings. |
250
+ | `deepLink` | `boolean` | `false` | Keeps the active page synchronized with a `?page=` URL parameter. The localized toolbar Share control uses this URL format. |
251
+ | `bookmarks` | `number[]` | `[]` | Initial zero-based bookmarked page indexes; the host owns persistence. |
252
+ | `notes` | `Record<number, string>` | `{}` | Initial page notes keyed by zero-based page index; the notes toolbar edits them while the host owns persistence. |
253
+ | `hotspots` | `FlipbookHotspot[]` | `[]` | Normalized (0..1) page overlays with info/media/gallery/commerce popup content and optional links. |
254
+ | `annotations` | `FlipbookAnnotation[]` | `[]` | Host-managed page note markers with normalized coordinates and plain-text popup content. |
255
+ | `onShare` | `(url: string) => void` | `null` | Optional callback invoked after the toolbar shares or copies the generated page URL. |
256
+
257
+
258
+ ## PDF page formats
259
+
260
+ PDF.js page dimensions are detected at runtime, so portrait A4, landscape A4, and other page ratios are supported without a fixed size preset. A3 landscape pages are split into left/right logical pages when `pdfPageMode` is `'auto'` or `'split'`; the halves are presented as an A4-like spread in double-page mode.
261
+
262
+ ## Styling and Theming
263
+
264
+ FlipbookEngine features fully custom-property-based styling compatible with modern styling systems.
265
+
266
+ ### Global CSS Variables
267
+
268
+ ```css
269
+ :root {
270
+ --mainbgcolor: #f3f6fb;
271
+ --panelbgcolor: #172033;
272
+ --flipbook-accent: #7367f0;
273
+ --thumbrailbgcolor: #0f172a;
274
+ }
275
+ ```
276
+
277
+ ## Performance & Bundle Metrics
278
+
279
+ FlipbookEngine is designed for responsive rendering with hardware-accelerated CSS 3D transforms and a lightweight DOM update path.
280
+
281
+ ### Package Size and PDF.js
282
+
283
+ FlipbookEngine does not bundle PDF.js or its worker. `pdfjs-dist` remains a normal npm dependency, while the host application supplies `pdfWorkerSrc`. This keeps the FlipbookEngine package smaller and lets the application control PDF.js versioning, caching, CSP, and worker hosting.
284
+
285
+ * **Core engine:** excludes PDF.js and the PDF worker.
286
+ * **Styles:** distributed as `flipbookengine/styles.css`.
287
+ * **PDF rendering:** enabled by configuring `pdfWorkerSrc` as shown above.
288
+
289
+ ### Performance Highlights
290
+ * **Hardware Accelerated:** Uses CSS-based 3D transformations (`transform: rotateY`, `translateZ`) without a WebGL runtime.
291
+ * **Progressive Image Quality:** Loads low-quality page assets first and upgrades visible pages to their normal-quality source through `IntersectionObserver`.
292
+ * **On-demand PDF Rendering:** Large PDFs create lightweight placeholders first; the current page and next page render before or during navigation.
293
+ * **Bounded PDF Rendering:** PDF pages are rendered with configurable concurrency (`pdfRenderConcurrency`, default `3`) and can be cancelled when an initialization is superseded or destroyed.
294
+ * **PDF Render Cache:** A bounded per-instance LRU cache (`pdfRenderCacheSize`, default `32`) avoids repeated canvas work while preventing unbounded memory growth.
295
+
296
+ ## FlipbookEngine vs. The Industry
297
+
298
+ When choosing a flipbook library, here is how we compare to other solutions:
299
+
300
+ * **Legacy Libraries (e.g., Turn.js):** Turn.js is over a decade old, relies on jQuery, and lacks native PDF support. **FlipbookEngine** uses a modern framework-agnostic stack (Vanilla/React/Vue), TypeScript, and has built-in PDF.js integration.
301
+ * **Heavy 3D Plugins (e.g., DearFlip, Real3D):** Many 3D plugins use WebGL, which can increase runtime overhead on mobile. **FlipbookEngine** uses StPageFlip with CSS 2D/3D transforms and no WebGL runtime.
302
+ * **Closed SaaS Platforms (e.g., Issuu, Heyzine):** These charge high monthly fees and lock your data on their servers. **FlipbookEngine** gives you 100% control to host and embed directly in your own code (AGPL-3.0).
303
+
304
+ ---
305
+
306
+ ## Acknowledgments
307
+
308
+ A special thanks to the incredible team behind **[Serenity](https://github.com/serenity-is/serenity)**. FlipbookEngine's reactive UI layer is powered by **[domwise](https://github.com/serenity-is/serenity/tree/master/packages/domwise)**. Coupled with `@preact/signals-core`, this keeps the UI update path small without requiring a traditional Virtual DOM runtime.
309
+
310
+ ---
311
+ ## Release scope
312
+
313
+ FlipbookEngine ships an AGPL open-source viewer package and maintains a separate closed-source commercial backend roadmap.
314
+
315
+ ### Open-source v1.0.0 (AGPL viewer)
316
+
317
+ The npm package is an embeddable, framework-agnostic PDF viewer. The following client-side reader capabilities are included in the open-source v1.0.0 release:
318
+
319
+ - **Table of Contents (Index):** Interactive navigation to chapters or product categories.
320
+ - **Page Notes & Annotations:** Reader notes and bookmarks stored by the host application.
321
+ - **Full-Text PDF Search:** Client-side text extraction and highlighting without blocking the viewer.
322
+ - **Interactive Hotspots & Pop-ups:** Custom overlays for media, galleries, and commerce links.
323
+ - **Deep Linking & Social Share:** URLs that address specific pages or spreads.
324
+
325
+ The open-source viewer continues to use PDF.js as an external npm dependency and does not require a backend renderer.
326
+
327
+ The v1.0.0 release also defines the framework-agnostic plugin contract. The rendering core stays small while TOC, notes, bookmarks, annotations, search, hotspots, and sharing can be installed as optional plugins. Analytics is not shipped as an official open-source plugin; hosts can consume the documented events or use a private commercial adapter. See [Plugin architecture](./docs/plugin-architecture.md).
328
+
329
+
330
+ ### Plugin usage and activation
331
+
332
+ Version 1.0.0 keeps the all-in-one entry point for existing applications and adds optional, tree-shakeable feature adapters. A plugin is active only when it is supplied in the constructor or installed at runtime. Omitting an adapter keeps it inactive.
333
+
334
+ ```ts
335
+ import { FlipbookEngine } from 'flipbookengine/core';
336
+ import { notesPlugin } from 'flipbookengine/plugins/notes';
337
+ import { bookmarksPlugin } from 'flipbookengine/plugins/bookmarks';
338
+
339
+ const engine = new FlipbookEngine('#viewer', {
340
+ plugins: [notesPlugin, bookmarksPlugin]
341
+ });
342
+
343
+ await engine.callPluginApi('notes', 'set', 0, 'Review this page');
344
+ console.log(engine.getPluginNames());
345
+ ```
346
+
347
+ Disable or remove a feature at runtime with `uninstallPlugin(name)`. This removes the plugin APIs, toolbar/panel contributions, event subscriptions, and cleanup callbacks. Re-enable it with `installPlugin(plugin)`:
348
+
349
+ ```ts
350
+ engine.uninstallPlugin('notes');
351
+ engine.installPlugin(notesPlugin);
352
+ ```
353
+
354
+ The official notes, bookmarks, TOC, search, annotations, hotspots, share, and deep-link adapters expose namespaced APIs. Their UI is still controlled by the host/all-in-one viewer options; custom plugins may additionally register toolbar buttons and panels through the plugin contract. Analytics is not included as an official open-source adapter.
355
+
356
+ ### 0.8.0 to 1.0.0 compatibility boundary
357
+
358
+ Version 1.0.0 is the first stable compatibility boundary. The 0.8.0 line was alpha/beta and does not provide a rollback or compatibility guarantee.
359
+
360
+ - The documented all-in-one import and engine options remain available.
361
+ - Imports from undocumented internal `src/*` or generated `dist/*` files are not supported; move to `flipbookengine/core`, `flipbookengine/plugins`, or the documented feature subpaths.
362
+ - Optional adapters are explicit: pass them through `plugins`, call `installPlugin()` to enable, and `uninstallPlugin()` to disable and clean up their APIs, UI contributions, and event listeners.
363
+ - TOC runtime/embed APIs and expanded hotspot media/gallery/commerce fields are new 1.0 APIs; existing host-managed data remains the source of truth.
364
+ - Image/WebP text search remains unsupported; PDF mode is required unless the host supplies server-generated text metadata.
365
+
366
+ See the complete [1.0.0 migration guide](./docs/migration-1.0.0.md) before upgrading from 0.8.0.
367
+
368
+ ### Commercial edition (closed-source backend)
369
+
370
+ The commercial roadmap is separate from the AGPL package and is intended for a separate backend project. It will provide licensed server-side capabilities, including:
371
+
372
+ - **Backend PDF rendering:** Secure, server-side rendering and caching for protected documents and high-volume workloads.
373
+ - **Protected partial downloads:** Server-generated page selections and authorization-aware download policies.
374
+ - **AI-assisted document features:** Backend indexing, catalog search, and Chat with Docs integrations.
375
+ - **Enterprise identity and provenance:** OIDC, auditability, tenant controls, and deployment integration.
376
+
377
+ These backend renderer and enterprise features will not be included in the public `flipbookengine` npm package; they will be delivered under the commercial license.
378
+
379
+ ---
380
+
381
+ ## Licensing
382
+
383
+ FlipbookEngine is distributed under a dual-license model:
384
+
385
+ - **Open Source**: GNU Affero General Public License v3.0 or later (see [LICENSE](./LICENSE)).
386
+ - **Commercial**: For use in closed-source projects, proprietary SaaS platforms, or agency client deliveries (see [COMMERCIAL_LICENSE.md](./COMMERCIAL_LICENSE.md)).
387
+
388
+ For commercial licenses and inquiries, contact: **murat.dogan@hotmail.com.tr**
389
+
390
+
391
+
392
+
393
+
394
+ ### Client-side PDF search
395
+
396
+ When initialized with a PDF URL, `search(query)` extracts text through PDF.js without rendering every page. It returns page-level matches and snippets, updates the search toolbar panel, and overlays precise normalized rectangles over matching text when PDF.js exposes text geometry. Search results use a zero-based `pageIndex` for API navigation and a one-based `pageNumber` for display.
397
+
398
+ ```ts
399
+ const results = await engine.search('catalog', { caseSensitive: false, maxResults: 50 });
400
+ engine.goToPage(results[0]?.pageIndex ?? 0);
401
+ engine.clearSearch();
402
+ ```
403
+
404
+ Search is unavailable for image-only page lists because those assets do not contain extractable PDF text or text geometry. For image mode, applications that need search/highlights should generate page text and normalized coordinates on the server and pass the resulting page metadata as a host-side feature; the open-source viewer does not OCR raster images. The iframe controller exposes the same operation with `search`, `clearSearch`, and `getSearchResults`.
405
+
406
+ ### Interactive hotspots
407
+
408
+ Hosts can provide normalized (0..1) page coordinates for lightweight links and pop-ups:
409
+
410
+ ```ts
411
+ const engine = new FlipbookEngine('#viewer', {
412
+ hotspots: [{ id: 'product-42', pageIndex: 3, x: 0.60, y: 0.25, width: 0.25, height: 0.18, label: 'Product details', content: 'Open the product details page.', href: '/products/42' }]
413
+ });
414
+ engine.on('hotspotActivate', ({ hotspot }) => console.log(hotspot.id));
415
+ ```
416
+
417
+ Hotspots support `kind: 'info' | 'media' | 'gallery' | 'commerce'`. A hotspot can render a single image/video/audio preview through `media`, a selectable image gallery through `gallery`, and a safe external/product destination through `href`. Content remains plain text; applications should sanitize server-provided URLs before passing them to the viewer. Use `activateHotspot(id)` and `closeHotspot()` for programmatic control.
418
+
419
+
420
+ ### Page annotations
421
+
422
+ Host uygulamaları, kullanıcı notunu sayfa üzerindeki normalize koordinata bağlamak için `annotations` seçeneğini kullanabilir. Marker tıklaması popup açar ve `annotationActivate` olayı yayınlanır. Bu sözleşme şimdilik host-managed'dir; annotation kayıtlarının backend koordinatlarına taşınması tüketici uygulamanın sorumluluğundadır.
423
+
424
+ ```ts
425
+ const engine = new FlipbookEngine('#viewer', {
426
+ annotations: [{ id: 'note-1', pageIndex: 4, x: .42, y: .36, text: 'Review pricing' }]
427
+ });
428
+ ```
429
+