Skip to content

Commit 89b94a0

Browse files
committed
Add scroll and navigation example to the snippet documentation
1 parent cfb204f commit 89b94a0

8 files changed

Lines changed: 432 additions & 23 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/plugin-scroll': minor
3+
---
4+
5+
Added `pageNumber` and `totalPages` properties to `LayoutReadyEvent`. This allows consumers to get the current page information immediately when the layout becomes ready, without needing to subscribe to a separate `onPageChange` event.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
'@embedpdf/snippet': minor
3+
---
4+
5+
Added comprehensive type exports for all plugin Capabilities and Scopes, enabling proper TypeScript support when using plugin APIs.
6+
7+
### New Type Exports
8+
9+
All plugins now export their `*Capability` and `*Scope` types, allowing developers to properly type variables when using `plugin.provides()` and `forDocument()`:
10+
11+
- **Viewport**: `ViewportCapability`, `ViewportScope`, `ViewportMetrics`
12+
- **Scroll**: `ScrollCapability`, `ScrollScope`, `ScrollMetrics`, `PageChangeEvent`, `ScrollEvent`, `LayoutChangeEvent`
13+
- **Spread**: `SpreadCapability`, `SpreadScope`
14+
- **Zoom**: `ZoomCapability`, `ZoomScope`, `ZoomLevel`, `ZoomChangeEvent`
15+
- **Rotate**: `RotateCapability`, `RotateScope`
16+
- **Tiling**: `TilingCapability`, `TilingScope`
17+
- **Thumbnail**: `ThumbnailCapability`, `ThumbnailScope`
18+
- **Annotation**: `AnnotationCapability`, `AnnotationScope`, `AnnotationEvent`
19+
- **Search**: `SearchCapability`, `SearchScope`
20+
- **Selection**: `SelectionCapability`, `SelectionScope`
21+
- **Capture**: `CaptureCapability`, `CaptureScope`
22+
- **Redaction**: `RedactionCapability`, `RedactionScope`, `RedactionMode`, `RedactionItem`
23+
- **UI**: `UIScope` (UICapability was already exported)
24+
- **I18n**: `I18nCapability`, `I18nScope`, `Locale`, `LocaleChangeEvent`
25+
- **Commands**: `CommandScope` (CommandsCapability was already exported)
26+
- **DocumentManager**: `DocumentManagerCapability`, `DocumentChangeEvent`, `LoadDocumentUrlOptions`, `LoadDocumentBufferOptions`
27+
- **Print**: `PrintCapability`, `PrintScope`
28+
- **Fullscreen**: `FullscreenCapability`
29+
- **Bookmark**: `BookmarkCapability`, `BookmarkScope`
30+
- **Export**: `ExportCapability`, `ExportScope`
31+
- **Pan**: `PanCapability`, `PanScope`
32+
- **History**: `HistoryCapability`, `HistoryScope`
33+
- **Attachment**: `AttachmentCapability`, `AttachmentScope`
34+
- **Render**: `RenderCapability`, `RenderScope`
35+
- **InteractionManager**: `InteractionManagerCapability`, `InteractionManagerScope`
36+
37+
### Usage Example
38+
39+
```typescript
40+
import {
41+
ScrollPlugin,
42+
type ScrollCapability,
43+
type ScrollScope,
44+
type PageChangeEvent,
45+
} from '@embedpdf/snippet';
46+
47+
// Type the capability returned by provides()
48+
const scroll: ScrollCapability = registry
49+
.getPlugin<ScrollPlugin>('scroll')
50+
?.provides();
51+
52+
// Type the scoped API for a specific document
53+
const doc: ScrollScope = scroll.forDocument('my-document');
54+
55+
// Type event callbacks
56+
scroll.onPageChange((event: PageChangeEvent) => {
57+
console.log(`Page ${event.pageNumber} of ${event.totalPages}`);
58+
});
59+
```

packages/plugin-scroll/src/lib/scroll-plugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ export class ScrollPlugin extends BasePlugin<
255255
const viewport = this.viewport.forDocument(documentId);
256256
viewport.scrollTo({ ...docState.scrollOffset, behavior: 'instant' });
257257

258-
this.layoutReady$.emit({ documentId, isInitial });
258+
this.layoutReady$.emit({
259+
documentId,
260+
isInitial,
261+
pageNumber: docState.currentPage,
262+
totalPages: docState.totalPages,
263+
});
259264
}
260265

261266
public clearLayoutReady(documentId: string): void {

packages/plugin-scroll/src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ export interface LayoutReadyEvent {
139139
documentId: string;
140140
/** True only on the first layout ready after document load, false on subsequent (e.g., tab switches) */
141141
isInitial: boolean;
142+
pageNumber: number;
143+
totalPages: number;
142144
}
143145

144146
// Scoped scroll capability

viewers/snippet/src/embedpdf.ts

Lines changed: 149 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,99 @@ import { PDFViewerConfig } from './components/app';
1111
export const version: string = '__EMBEDPDF_VERSION__';
1212

1313
// ============================================================================
14-
// Plugin Classes - for use with registry.getPlugin<T>()
14+
// Plugin Classes, Capabilities & Scopes - for use with registry.getPlugin<T>()
1515
// ============================================================================
16-
export { ViewportPlugin, type ViewportPluginConfig } from '@embedpdf/plugin-viewport/preact';
16+
export {
17+
ViewportPlugin,
18+
type ViewportPluginConfig,
19+
type ViewportCapability,
20+
type ViewportScope,
21+
type ViewportMetrics,
22+
} from '@embedpdf/plugin-viewport/preact';
1723
export {
1824
ScrollPlugin,
1925
ScrollStrategy,
2026
type ScrollPluginConfig,
27+
type ScrollCapability,
28+
type ScrollScope,
29+
type ScrollMetrics,
30+
type PageChangeEvent,
31+
type ScrollEvent,
32+
type LayoutChangeEvent,
2133
} from '@embedpdf/plugin-scroll/preact';
22-
export { SpreadPlugin, SpreadMode, type SpreadPluginConfig } from '@embedpdf/plugin-spread/preact';
23-
export { ZoomPlugin, ZoomMode, type ZoomPluginConfig } from '@embedpdf/plugin-zoom/preact';
24-
export { RotatePlugin, type RotatePluginConfig } from '@embedpdf/plugin-rotate/preact';
25-
export { TilingPlugin, type TilingPluginConfig } from '@embedpdf/plugin-tiling/preact';
26-
export { ThumbnailPlugin, type ThumbnailPluginConfig } from '@embedpdf/plugin-thumbnail/preact';
27-
export { AnnotationPlugin, type AnnotationPluginConfig } from '@embedpdf/plugin-annotation/preact';
28-
export { SearchPlugin, type SearchPluginConfig } from '@embedpdf/plugin-search/preact';
29-
export { SelectionPlugin, type SelectionPluginConfig } from '@embedpdf/plugin-selection/preact';
30-
export { CapturePlugin, type CapturePluginConfig } from '@embedpdf/plugin-capture/preact';
31-
export { RedactionPlugin, type RedactionPluginConfig } from '@embedpdf/plugin-redaction/preact';
32-
export { UIPlugin, type UIPluginConfig, type UICapability } from '@embedpdf/plugin-ui/preact';
34+
export {
35+
SpreadPlugin,
36+
SpreadMode,
37+
type SpreadPluginConfig,
38+
type SpreadCapability,
39+
type SpreadScope,
40+
} from '@embedpdf/plugin-spread/preact';
41+
export {
42+
ZoomPlugin,
43+
ZoomMode,
44+
type ZoomPluginConfig,
45+
type ZoomCapability,
46+
type ZoomScope,
47+
type ZoomLevel,
48+
type ZoomChangeEvent,
49+
} from '@embedpdf/plugin-zoom/preact';
50+
export {
51+
RotatePlugin,
52+
type RotatePluginConfig,
53+
type RotateCapability,
54+
type RotateScope,
55+
} from '@embedpdf/plugin-rotate/preact';
56+
export {
57+
TilingPlugin,
58+
type TilingPluginConfig,
59+
type TilingCapability,
60+
type TilingScope,
61+
} from '@embedpdf/plugin-tiling/preact';
62+
export {
63+
ThumbnailPlugin,
64+
type ThumbnailPluginConfig,
65+
type ThumbnailCapability,
66+
type ThumbnailScope,
67+
} from '@embedpdf/plugin-thumbnail/preact';
68+
export {
69+
AnnotationPlugin,
70+
type AnnotationPluginConfig,
71+
type AnnotationCapability,
72+
type AnnotationScope,
73+
type AnnotationEvent,
74+
} from '@embedpdf/plugin-annotation/preact';
75+
export {
76+
SearchPlugin,
77+
type SearchPluginConfig,
78+
type SearchCapability,
79+
type SearchScope,
80+
} from '@embedpdf/plugin-search/preact';
81+
export {
82+
SelectionPlugin,
83+
type SelectionPluginConfig,
84+
type SelectionCapability,
85+
type SelectionScope,
86+
} from '@embedpdf/plugin-selection/preact';
87+
export {
88+
CapturePlugin,
89+
type CapturePluginConfig,
90+
type CaptureCapability,
91+
type CaptureScope,
92+
} from '@embedpdf/plugin-capture/preact';
93+
export {
94+
RedactionPlugin,
95+
RedactionMode,
96+
type RedactionPluginConfig,
97+
type RedactionCapability,
98+
type RedactionScope,
99+
type RedactionItem,
100+
} from '@embedpdf/plugin-redaction/preact';
101+
export {
102+
UIPlugin,
103+
type UIPluginConfig,
104+
type UICapability,
105+
type UIScope,
106+
} from '@embedpdf/plugin-ui/preact';
33107

34108
// UI Schema Types - for customizing toolbars, menus, sidebars, etc.
35109
export type {
@@ -87,29 +161,82 @@ export type {
87161
// Utility types
88162
VisibilityDependency,
89163
} from '@embedpdf/plugin-ui/preact';
90-
export { I18nPlugin, type I18nPluginConfig } from '@embedpdf/plugin-i18n/preact';
164+
export {
165+
I18nPlugin,
166+
type I18nPluginConfig,
167+
type I18nCapability,
168+
type I18nScope,
169+
type Locale,
170+
type LocaleChangeEvent,
171+
} from '@embedpdf/plugin-i18n/preact';
91172
export {
92173
CommandsPlugin,
93174
type CommandsPluginConfig,
94175
type Command,
95176
type ResolvedCommand,
96177
type CommandsCapability,
178+
type CommandScope,
97179
} from '@embedpdf/plugin-commands/preact';
98180
export {
99181
DocumentManagerPlugin,
100182
type DocumentManagerPluginConfig,
183+
type DocumentManagerCapability,
184+
type DocumentChangeEvent,
185+
type LoadDocumentUrlOptions,
186+
type LoadDocumentBufferOptions,
101187
} from '@embedpdf/plugin-document-manager/preact';
102-
export { PrintPlugin, type PrintPluginConfig } from '@embedpdf/plugin-print/preact';
103-
export { FullscreenPlugin, type FullscreenPluginConfig } from '@embedpdf/plugin-fullscreen/preact';
104-
export { BookmarkPlugin, type BookmarkPluginConfig } from '@embedpdf/plugin-bookmark/preact';
105-
export { ExportPlugin, type ExportPluginConfig } from '@embedpdf/plugin-export/preact';
106-
export { PanPlugin, type PanPluginConfig } from '@embedpdf/plugin-pan/preact';
107-
export { HistoryPlugin, type HistoryPluginConfig } from '@embedpdf/plugin-history/preact';
108-
export { AttachmentPlugin, type AttachmentPluginConfig } from '@embedpdf/plugin-attachment/preact';
109-
export { RenderPlugin, type RenderPluginConfig } from '@embedpdf/plugin-render/preact';
188+
export {
189+
PrintPlugin,
190+
type PrintPluginConfig,
191+
type PrintCapability,
192+
type PrintScope,
193+
} from '@embedpdf/plugin-print/preact';
194+
export {
195+
FullscreenPlugin,
196+
type FullscreenPluginConfig,
197+
type FullscreenCapability,
198+
} from '@embedpdf/plugin-fullscreen/preact';
199+
export {
200+
BookmarkPlugin,
201+
type BookmarkPluginConfig,
202+
type BookmarkCapability,
203+
type BookmarkScope,
204+
} from '@embedpdf/plugin-bookmark/preact';
205+
export {
206+
ExportPlugin,
207+
type ExportPluginConfig,
208+
type ExportCapability,
209+
type ExportScope,
210+
} from '@embedpdf/plugin-export/preact';
211+
export {
212+
PanPlugin,
213+
type PanPluginConfig,
214+
type PanCapability,
215+
type PanScope,
216+
} from '@embedpdf/plugin-pan/preact';
217+
export {
218+
HistoryPlugin,
219+
type HistoryPluginConfig,
220+
type HistoryCapability,
221+
type HistoryScope,
222+
} from '@embedpdf/plugin-history/preact';
223+
export {
224+
AttachmentPlugin,
225+
type AttachmentPluginConfig,
226+
type AttachmentCapability,
227+
type AttachmentScope,
228+
} from '@embedpdf/plugin-attachment/preact';
229+
export {
230+
RenderPlugin,
231+
type RenderPluginConfig,
232+
type RenderCapability,
233+
type RenderScope,
234+
} from '@embedpdf/plugin-render/preact';
110235
export {
111236
InteractionManagerPlugin,
112237
type InteractionManagerPluginConfig,
238+
type InteractionManagerCapability,
239+
type InteractionManagerScope,
113240
} from '@embedpdf/plugin-interaction-manager/preact';
114241

115242
// Re-export from models

website/src/components/navbar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default function Navbar() {
1818
setScrolled(window.scrollY > 10)
1919
}
2020

21+
// Check initial scroll position on mount
22+
handleScroll()
23+
2124
window.addEventListener('scroll', handleScroll)
2225
return () => window.removeEventListener('scroll', handleScroll)
2326
}, [])

0 commit comments

Comments
 (0)