@qrcommunication/gigapdf-lib 0.1.0 → 0.7.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.
@@ -0,0 +1,144 @@
1
+ import { GigaPdfEngine, GigaPdfDoc, HtmlFont } from './index.cjs';
2
+
3
+ /**
4
+ * `@qrcommunication/gigapdf-lib/viewer` — a zero-dependency document **viewer**
5
+ * built entirely on the WASM engine. It opens PDF, Office (docx/xlsx/pptx +
6
+ * legacy/ODF) and HTML — converting non-PDF inputs to PDF in-engine — renders
7
+ * pages with {@link GigaPdfDoc.renderPage}, detects each page's orientation and
8
+ * adapts, and offers navigation, zoom, a thumbnail rail and a **fullscreen
9
+ * presentation mode**. No third-party libraries (no pdf.js); browser-only (DOM).
10
+ *
11
+ * ```ts
12
+ * const giga = await GigaPdfEngine.load(wasmUrl);
13
+ * const viewer = new GigaPdfViewer(giga, document.getElementById("app")!);
14
+ * await viewer.open({ kind: "auto", bytes }); // pdf / office / html auto-detected
15
+ * viewer.present(); // fullscreen slideshow
16
+ * ```
17
+ */
18
+
19
+ /** A document to open. `auto` sniffs the format from magic bytes. */
20
+ type ViewerSource = {
21
+ kind: "pdf";
22
+ bytes: Uint8Array;
23
+ } | {
24
+ kind: "office";
25
+ bytes: Uint8Array;
26
+ } | {
27
+ kind: "html";
28
+ html: string;
29
+ fonts?: HtmlFont[];
30
+ } | {
31
+ kind: "auto";
32
+ bytes: Uint8Array;
33
+ };
34
+ interface ViewerOptions {
35
+ /** CSS zoom multiplier applied to the page boxes (default 1). */
36
+ scale?: number;
37
+ /** Raster scale for crisp rendering (default 2 ≈ retina). */
38
+ renderScale?: number;
39
+ /** Show the thumbnail rail (default true). */
40
+ thumbnails?: boolean;
41
+ /** Show the toolbar (default true). */
42
+ toolbar?: boolean;
43
+ /** Gutter background colour (default `#525659`). */
44
+ background?: string;
45
+ }
46
+ /** Page orientation derived from the rendered raster. */
47
+ type Orientation = "portrait" | "landscape";
48
+ declare class GigaPdfViewer {
49
+ protected engine: GigaPdfEngine;
50
+ private options;
51
+ protected doc: GigaPdfDoc | null;
52
+ protected count: number;
53
+ protected current: number;
54
+ protected cssScale: number;
55
+ protected renderScale: number;
56
+ /** Active auto-fit mode; re-applied on resize and page change. */
57
+ protected fitMode: "none" | "width" | "page";
58
+ private presenting;
59
+ private resizeObs;
60
+ protected urls: (string | null)[];
61
+ protected sizes: ({
62
+ w: number;
63
+ h: number;
64
+ } | null)[];
65
+ protected root: HTMLElement;
66
+ private bar;
67
+ private body;
68
+ private thumbs;
69
+ protected pages: HTMLElement;
70
+ private pageInput;
71
+ private zoomReadout;
72
+ private zoomSelect;
73
+ protected pageEls: (HTMLElement | null)[];
74
+ private onKey;
75
+ private onFsChange;
76
+ constructor(engine: GigaPdfEngine, container: HTMLElement, options?: ViewerOptions);
77
+ /** Number of pages currently open. */
78
+ get pageCount(): number;
79
+ /** The page currently in view (1-based). */
80
+ get currentPage(): number;
81
+ /** Orientation of `page` (after open). */
82
+ orientation(page: number): Orientation;
83
+ /** The current document as PDF bytes (including any applied edits). */
84
+ save(): Uint8Array;
85
+ /** Open a document; Office/HTML are converted to PDF in-engine. Returns the page count. */
86
+ open(src: ViewerSource): Promise<number>;
87
+ private toPdf;
88
+ private detectAndConvert;
89
+ protected renderPageRaster(page: number): {
90
+ url: string;
91
+ w: number;
92
+ h: number;
93
+ };
94
+ /** The page's width / height in PDF points (raster pixels ÷ render scale). */
95
+ protected pageWidthPt(page: number): number;
96
+ protected pageHeightPt(page: number): number;
97
+ /** Re-raster a page after its content changed (drops the cached image). */
98
+ protected reRenderPage(page: number): void;
99
+ /** Hook for subclasses (the editor) to attach per-page overlays. */
100
+ protected afterRender(): void;
101
+ private renderAllPages;
102
+ private buildThumbs;
103
+ private highlightThumb;
104
+ /** Scroll/jump to `page` (clamped to range). */
105
+ goTo(page: number): void;
106
+ next(): void;
107
+ prev(): void;
108
+ /** Current CSS zoom multiplier (1 = 100%). */
109
+ get zoom(): number;
110
+ /** Resize the page boxes to the current `cssScale` (no re-raster). */
111
+ private applyScale;
112
+ /** Set an explicit zoom multiplier (cancels any auto-fit mode). */
113
+ setZoom(scale: number): void;
114
+ /** Set zoom as a percentage (e.g. `125`). */
115
+ setZoomPercent(pct: number): void;
116
+ /** Reset to 100 % (actual size). */
117
+ actualSize(): void;
118
+ zoomIn(): void;
119
+ zoomOut(): void;
120
+ /** Fit the current page's **width** to the viewport (sticks across resizes). */
121
+ fitWidth(): void;
122
+ /** Fit the **whole** current page (width *and* height) to the viewport. */
123
+ fitPage(): void;
124
+ /** Recompute the zoom for the active fit mode against the current page. */
125
+ protected applyFitMode(): void;
126
+ /** Hook for subclasses (the editor) to react to zoom changes. */
127
+ protected onZoomChange(): void;
128
+ private updateZoomReadout;
129
+ /** Enter fullscreen single-page presentation mode. */
130
+ present(): void;
131
+ /** Leave presentation mode. */
132
+ exitPresent(): void;
133
+ private syncPresentClass;
134
+ private handleKey;
135
+ private isActive;
136
+ private buildChrome;
137
+ private trackScroll;
138
+ /** Close the current document and free its rendered pages. */
139
+ close(): void;
140
+ /** Destroy the viewer: close the document and detach listeners. */
141
+ destroy(): void;
142
+ }
143
+
144
+ export { GigaPdfViewer, type Orientation, type ViewerOptions, type ViewerSource };
@@ -0,0 +1,144 @@
1
+ import { GigaPdfEngine, GigaPdfDoc, HtmlFont } from './index.js';
2
+
3
+ /**
4
+ * `@qrcommunication/gigapdf-lib/viewer` — a zero-dependency document **viewer**
5
+ * built entirely on the WASM engine. It opens PDF, Office (docx/xlsx/pptx +
6
+ * legacy/ODF) and HTML — converting non-PDF inputs to PDF in-engine — renders
7
+ * pages with {@link GigaPdfDoc.renderPage}, detects each page's orientation and
8
+ * adapts, and offers navigation, zoom, a thumbnail rail and a **fullscreen
9
+ * presentation mode**. No third-party libraries (no pdf.js); browser-only (DOM).
10
+ *
11
+ * ```ts
12
+ * const giga = await GigaPdfEngine.load(wasmUrl);
13
+ * const viewer = new GigaPdfViewer(giga, document.getElementById("app")!);
14
+ * await viewer.open({ kind: "auto", bytes }); // pdf / office / html auto-detected
15
+ * viewer.present(); // fullscreen slideshow
16
+ * ```
17
+ */
18
+
19
+ /** A document to open. `auto` sniffs the format from magic bytes. */
20
+ type ViewerSource = {
21
+ kind: "pdf";
22
+ bytes: Uint8Array;
23
+ } | {
24
+ kind: "office";
25
+ bytes: Uint8Array;
26
+ } | {
27
+ kind: "html";
28
+ html: string;
29
+ fonts?: HtmlFont[];
30
+ } | {
31
+ kind: "auto";
32
+ bytes: Uint8Array;
33
+ };
34
+ interface ViewerOptions {
35
+ /** CSS zoom multiplier applied to the page boxes (default 1). */
36
+ scale?: number;
37
+ /** Raster scale for crisp rendering (default 2 ≈ retina). */
38
+ renderScale?: number;
39
+ /** Show the thumbnail rail (default true). */
40
+ thumbnails?: boolean;
41
+ /** Show the toolbar (default true). */
42
+ toolbar?: boolean;
43
+ /** Gutter background colour (default `#525659`). */
44
+ background?: string;
45
+ }
46
+ /** Page orientation derived from the rendered raster. */
47
+ type Orientation = "portrait" | "landscape";
48
+ declare class GigaPdfViewer {
49
+ protected engine: GigaPdfEngine;
50
+ private options;
51
+ protected doc: GigaPdfDoc | null;
52
+ protected count: number;
53
+ protected current: number;
54
+ protected cssScale: number;
55
+ protected renderScale: number;
56
+ /** Active auto-fit mode; re-applied on resize and page change. */
57
+ protected fitMode: "none" | "width" | "page";
58
+ private presenting;
59
+ private resizeObs;
60
+ protected urls: (string | null)[];
61
+ protected sizes: ({
62
+ w: number;
63
+ h: number;
64
+ } | null)[];
65
+ protected root: HTMLElement;
66
+ private bar;
67
+ private body;
68
+ private thumbs;
69
+ protected pages: HTMLElement;
70
+ private pageInput;
71
+ private zoomReadout;
72
+ private zoomSelect;
73
+ protected pageEls: (HTMLElement | null)[];
74
+ private onKey;
75
+ private onFsChange;
76
+ constructor(engine: GigaPdfEngine, container: HTMLElement, options?: ViewerOptions);
77
+ /** Number of pages currently open. */
78
+ get pageCount(): number;
79
+ /** The page currently in view (1-based). */
80
+ get currentPage(): number;
81
+ /** Orientation of `page` (after open). */
82
+ orientation(page: number): Orientation;
83
+ /** The current document as PDF bytes (including any applied edits). */
84
+ save(): Uint8Array;
85
+ /** Open a document; Office/HTML are converted to PDF in-engine. Returns the page count. */
86
+ open(src: ViewerSource): Promise<number>;
87
+ private toPdf;
88
+ private detectAndConvert;
89
+ protected renderPageRaster(page: number): {
90
+ url: string;
91
+ w: number;
92
+ h: number;
93
+ };
94
+ /** The page's width / height in PDF points (raster pixels ÷ render scale). */
95
+ protected pageWidthPt(page: number): number;
96
+ protected pageHeightPt(page: number): number;
97
+ /** Re-raster a page after its content changed (drops the cached image). */
98
+ protected reRenderPage(page: number): void;
99
+ /** Hook for subclasses (the editor) to attach per-page overlays. */
100
+ protected afterRender(): void;
101
+ private renderAllPages;
102
+ private buildThumbs;
103
+ private highlightThumb;
104
+ /** Scroll/jump to `page` (clamped to range). */
105
+ goTo(page: number): void;
106
+ next(): void;
107
+ prev(): void;
108
+ /** Current CSS zoom multiplier (1 = 100%). */
109
+ get zoom(): number;
110
+ /** Resize the page boxes to the current `cssScale` (no re-raster). */
111
+ private applyScale;
112
+ /** Set an explicit zoom multiplier (cancels any auto-fit mode). */
113
+ setZoom(scale: number): void;
114
+ /** Set zoom as a percentage (e.g. `125`). */
115
+ setZoomPercent(pct: number): void;
116
+ /** Reset to 100 % (actual size). */
117
+ actualSize(): void;
118
+ zoomIn(): void;
119
+ zoomOut(): void;
120
+ /** Fit the current page's **width** to the viewport (sticks across resizes). */
121
+ fitWidth(): void;
122
+ /** Fit the **whole** current page (width *and* height) to the viewport. */
123
+ fitPage(): void;
124
+ /** Recompute the zoom for the active fit mode against the current page. */
125
+ protected applyFitMode(): void;
126
+ /** Hook for subclasses (the editor) to react to zoom changes. */
127
+ protected onZoomChange(): void;
128
+ private updateZoomReadout;
129
+ /** Enter fullscreen single-page presentation mode. */
130
+ present(): void;
131
+ /** Leave presentation mode. */
132
+ exitPresent(): void;
133
+ private syncPresentClass;
134
+ private handleKey;
135
+ private isActive;
136
+ private buildChrome;
137
+ private trackScroll;
138
+ /** Close the current document and free its rendered pages. */
139
+ close(): void;
140
+ /** Destroy the viewer: close the document and detach listeners. */
141
+ destroy(): void;
142
+ }
143
+
144
+ export { GigaPdfViewer, type Orientation, type ViewerOptions, type ViewerSource };