@triiiceratops/plugin-pdf-export 1.0.0-rc.1
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/dist/catalog.d.ts +15 -0
- package/dist/contextKey.d.ts +18 -0
- package/dist/exportPdf.d.ts +124 -0
- package/dist/icons.d.ts +9 -0
- package/dist/iife.d.ts +26 -0
- package/dist/iife.js +160 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +4111 -0
- package/dist/plugin.d.ts +31 -0
- package/dist/reportError.d.ts +15 -0
- package/dist/styles.d.ts +16 -0
- package/dist/types.d.ts +28 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Flood
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LocaleCatalog } from '@triiiceratops/plugin-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* The plugin's package-owned localization catalog (CONTEXT.md **Active
|
|
4
|
+
* locale**). These strings previously lived in core's `messages/en.json` /
|
|
5
|
+
* `messages/de.json` under the `pdf_export_*` keys; migrating the plugin out of
|
|
6
|
+
* core moves them here so the catalog ships with (and evolves with) the plugin,
|
|
7
|
+
* and core's catalogs carry no plugin keys. `en` is the required fallback; a
|
|
8
|
+
* missing key resolves to `en` and then to the key itself.
|
|
9
|
+
*
|
|
10
|
+
* The `{param}` placeholders are substituted by the SDK locale service's `t`.
|
|
11
|
+
* The progress/error strings are passed through `t` and handed to
|
|
12
|
+
* `exportCanvasRangeAsPdf` as its `messages` builders (the pure export logic
|
|
13
|
+
* itself carries no i18n runtime).
|
|
14
|
+
*/
|
|
15
|
+
export declare const catalog: LocaleCatalog;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PluginContext } from '@triiiceratops/plugin-sdk';
|
|
2
|
+
import type { PdfExportConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Shared key for handing the SDK {@link PluginContext} (plus this activation's
|
|
5
|
+
* consumer config) to the panel through Svelte's component-context map.
|
|
6
|
+
* `getContext` returns a plain (non-reactive) value, which is exactly right
|
|
7
|
+
* here: the activation context and config are stable for the lifetime of a mount
|
|
8
|
+
* (a fresh mount gets a fresh context), so they must not be treated as reactive
|
|
9
|
+
* state.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PLUGIN_CONTEXT_KEY: unique symbol;
|
|
12
|
+
/** What `view.mount` passes to the panel through the context map. */
|
|
13
|
+
export interface PanelContext {
|
|
14
|
+
/** The SDK activation context (viewer state, selectors, services). */
|
|
15
|
+
readonly context: PluginContext;
|
|
16
|
+
/** The consumer configuration this plugin instance was created with. */
|
|
17
|
+
readonly config: PdfExportConfig;
|
|
18
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type ResolvedCanvasImage } from 'triiiceratops/image-export';
|
|
2
|
+
/**
|
|
3
|
+
* Progress + error strings `exportCanvasRangeAsPdf` emits. In core this logic
|
|
4
|
+
* imported the Svelte i18n runtime (`m.pdf_export_*`); a framework-neutral,
|
|
5
|
+
* package-owned plugin must not, so the strings are injected instead. Callers
|
|
6
|
+
* (the plugin panel) pass builders resolved from the SDK per-viewer locale
|
|
7
|
+
* service over this package's catalog; the module ships English defaults so the
|
|
8
|
+
* pure logic — and its moved unit tests — run without a locale service.
|
|
9
|
+
*/
|
|
10
|
+
export interface PdfExportMessages {
|
|
11
|
+
errorNoCanvases(): string;
|
|
12
|
+
errorNotAvailable(): string;
|
|
13
|
+
errorNoCanvasesExported(): string;
|
|
14
|
+
progressCoverSheet(): string;
|
|
15
|
+
progressCanvas(params: {
|
|
16
|
+
current: number;
|
|
17
|
+
total: number;
|
|
18
|
+
label: string;
|
|
19
|
+
}): string;
|
|
20
|
+
progressDownload(params: {
|
|
21
|
+
filename: string;
|
|
22
|
+
}): string;
|
|
23
|
+
}
|
|
24
|
+
/** English fallbacks — the same strings core shipped in `messages/en.json`. */
|
|
25
|
+
export declare const DEFAULT_PDF_EXPORT_MESSAGES: PdfExportMessages;
|
|
26
|
+
type NormalizeCanvasRangeResult = {
|
|
27
|
+
startIndex: number;
|
|
28
|
+
endIndex: number;
|
|
29
|
+
indices: number[];
|
|
30
|
+
};
|
|
31
|
+
export type PdfCoverSheetField = {
|
|
32
|
+
label: string;
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
export type PdfCoverSheetConfig = {
|
|
36
|
+
title?: string;
|
|
37
|
+
fields: PdfCoverSheetField[];
|
|
38
|
+
};
|
|
39
|
+
export type PdfImageRequestConfig = Pick<RequestInit, 'credentials' | 'headers' | 'mode' | 'referrerPolicy'>;
|
|
40
|
+
export type PdfImageLoaderParams = {
|
|
41
|
+
canvas: any;
|
|
42
|
+
canvasId: string;
|
|
43
|
+
imageUrl: string;
|
|
44
|
+
manifestId: string | null;
|
|
45
|
+
targetWidth: number;
|
|
46
|
+
imageRequest: RequestInit;
|
|
47
|
+
resolvedImage: ResolvedCanvasImage | null;
|
|
48
|
+
};
|
|
49
|
+
export type PdfImageLoader = (params: PdfImageLoaderParams) => Promise<Blob> | Blob;
|
|
50
|
+
export type PdfTextOverlay = {
|
|
51
|
+
text: string;
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
coordinateSpace?: 'canvas' | 'image';
|
|
57
|
+
};
|
|
58
|
+
export type PdfExportOcrProviderContext = {
|
|
59
|
+
manifestId: string | null;
|
|
60
|
+
canvasId: string;
|
|
61
|
+
canvas: any;
|
|
62
|
+
canvasIndex: number;
|
|
63
|
+
};
|
|
64
|
+
export type PdfCanvasOcrOverlayProvider = (context: PdfExportOcrProviderContext) => Promise<PdfTextOverlay[] | null | undefined> | PdfTextOverlay[] | null | undefined;
|
|
65
|
+
export type PdfExportFilenameProviderContext = {
|
|
66
|
+
manifestId: string | null;
|
|
67
|
+
manifestLabel?: string | null;
|
|
68
|
+
startIndex: number;
|
|
69
|
+
endIndex: number;
|
|
70
|
+
indices: number[];
|
|
71
|
+
canvases: any[];
|
|
72
|
+
exportedCount: number;
|
|
73
|
+
failedCanvases: string[];
|
|
74
|
+
defaultFilename: string;
|
|
75
|
+
};
|
|
76
|
+
export type PdfExportFilenameProvider = (context: PdfExportFilenameProviderContext) => Promise<string | null | undefined> | string | null | undefined;
|
|
77
|
+
export type PdfOcrPlacementMode = 'fit-box' | 'word-anchor';
|
|
78
|
+
export type PdfOcrSizingMode = 'fit-box' | 'height-only';
|
|
79
|
+
export type PdfOcrVisibilityMode = 'transparent' | 'invisible' | 'debug';
|
|
80
|
+
type ExportCanvasRangeAsPdfParams = {
|
|
81
|
+
canvases: any[];
|
|
82
|
+
startIndex: number;
|
|
83
|
+
endIndex: number;
|
|
84
|
+
targetWidth: number;
|
|
85
|
+
manifestId: string | null;
|
|
86
|
+
manifestLabel?: string | null;
|
|
87
|
+
getSelectedChoice?: (canvasId: string) => string | undefined;
|
|
88
|
+
getCanvasOcrOverlays?: PdfCanvasOcrOverlayProvider;
|
|
89
|
+
getCanvasAnnotations?: (canvasId: string) => Promise<any[]> | any[];
|
|
90
|
+
imageRequest?: PdfImageRequestConfig;
|
|
91
|
+
loadImageBlob?: PdfImageLoader;
|
|
92
|
+
ocrPlacementMode?: PdfOcrPlacementMode;
|
|
93
|
+
ocrSizingMode?: PdfOcrSizingMode;
|
|
94
|
+
ocrVisibilityMode?: PdfOcrVisibilityMode;
|
|
95
|
+
filename?: string;
|
|
96
|
+
getFilename?: PdfExportFilenameProvider;
|
|
97
|
+
coverSheet?: PdfCoverSheetConfig;
|
|
98
|
+
createdAt?: Date;
|
|
99
|
+
currentUrl?: string | null;
|
|
100
|
+
onProgress?: (message: string) => void;
|
|
101
|
+
/** Localized progress/error strings; defaults to English. */
|
|
102
|
+
messages?: PdfExportMessages;
|
|
103
|
+
};
|
|
104
|
+
type ExportCanvasRangeAsPdfResult = {
|
|
105
|
+
exportedCount: number;
|
|
106
|
+
failedCanvases: string[];
|
|
107
|
+
filename: string;
|
|
108
|
+
};
|
|
109
|
+
type CoverSheetRuntimeValues = {
|
|
110
|
+
createdAt: Date;
|
|
111
|
+
currentUrl: string | null;
|
|
112
|
+
};
|
|
113
|
+
export declare function buildCoverSheetFields(coverSheet: PdfCoverSheetConfig, runtimeValues: CoverSheetRuntimeValues): PdfCoverSheetField[];
|
|
114
|
+
export declare function buildPdfFilename(params: {
|
|
115
|
+
manifestId: string | null;
|
|
116
|
+
manifestLabel?: string | null;
|
|
117
|
+
startIndex: number;
|
|
118
|
+
endIndex: number;
|
|
119
|
+
}): string;
|
|
120
|
+
export declare function normalizeCanvasRange(startIndex: number, endIndex: number, canvasCount: number): NormalizeCanvasRangeResult | null;
|
|
121
|
+
export declare function extractOcrTextOverlays(annotations: any[]): PdfTextOverlay[];
|
|
122
|
+
export declare function buildImageRequestInit(imageRequest?: PdfImageRequestConfig): RequestInit;
|
|
123
|
+
export declare function exportCanvasRangeAsPdf({ canvases, startIndex, endIndex, targetWidth, manifestId, manifestLabel, getSelectedChoice, getCanvasOcrOverlays, getCanvasAnnotations, imageRequest, loadImageBlob, ocrPlacementMode, ocrSizingMode, ocrVisibilityMode, filename, getFilename, coverSheet, createdAt, currentUrl, onProgress, messages, }: ExportCanvasRangeAsPdfParams): Promise<ExportCanvasRangeAsPdfResult>;
|
|
124
|
+
export {};
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IconDescriptor } from '@triiiceratops/plugin-sdk';
|
|
2
|
+
/** The toolbar icon descriptor (the file-pdf glyph), validated by `svgIcon`. */
|
|
3
|
+
export declare const FILE_PDF_ICON: IconDescriptor;
|
|
4
|
+
/** Inner SVG markup for the in-panel glyphs (trusted static paths). */
|
|
5
|
+
export declare const GLYPHS: {
|
|
6
|
+
readonly viewBox: "0 0 256 256";
|
|
7
|
+
readonly filePdf: "<path d=\"M224,152a8,8,0,0,1-8,8H192v16h16a8,8,0,0,1,0,16H192v16a8,8,0,0,1-16,0V152a8,8,0,0,1,8-8h32A8,8,0,0,1,224,152ZM92,172a28,28,0,0,1-28,28H56v8a8,8,0,0,1-16,0V152a8,8,0,0,1,8-8H64A28,28,0,0,1,92,172Zm-16,0a12,12,0,0,0-12-12H56v24h8A12,12,0,0,0,76,172Zm88,8a36,36,0,0,1-36,36H112a8,8,0,0,1-8-8V152a8,8,0,0,1,8-8h16A36,36,0,0,1,164,180Zm-16,0a20,20,0,0,0-20-20h-8v40h8A20,20,0,0,0,148,180ZM40,112V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0ZM160,80h28.69L160,51.31Z\"/>";
|
|
8
|
+
readonly download: "<path d=\"M224,144v64a8,8,0,0,1-8,8H40a8,8,0,0,1-8-8V144a8,8,0,0,1,16,0v56H208V144a8,8,0,0,1,16,0Zm-101.66,5.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0-11.32-11.32L136,124.69V32a8,8,0,0,0-16,0v92.69L93.66,98.34a8,8,0,0,0-11.32,11.32Z\"/>";
|
|
9
|
+
};
|
package/dist/iife.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained IIFE entry — loadable from a `<script>` tag with no bundler.
|
|
3
|
+
*
|
|
4
|
+
* Loading this bundle bootstraps the `window.Triiiceratops` namespace if absent
|
|
5
|
+
* and registers the plugin factory into `window.Triiiceratops.plugins` (SPEC.md
|
|
6
|
+
* "Browser IIFEs register package-qualified factories in one `window.Triiiceratops`
|
|
7
|
+
* namespace"). It does NOT activate anything — activation is explicit and per
|
|
8
|
+
* viewer:
|
|
9
|
+
*
|
|
10
|
+
* ```html
|
|
11
|
+
* <script src="triiiceratops-element.iife.js"></script>
|
|
12
|
+
* <script src="triiiceratops-plugin-pdf-export.iife.js"></script>
|
|
13
|
+
* <script>
|
|
14
|
+
* const viewer = document.querySelector('triiiceratops-viewer');
|
|
15
|
+
* viewer.plugins = [
|
|
16
|
+
* window.Triiiceratops.plugins.get('@triiiceratops/plugin-pdf-export'),
|
|
17
|
+
* ];
|
|
18
|
+
* </script>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The plugin script may load before OR after core: the registry is bootstrapped
|
|
22
|
+
* order-independently, so both script orders work. This bundle carries its own
|
|
23
|
+
* `pdf-lib` (bundled in), so no bundler and no separate dependency install is
|
|
24
|
+
* required for the no-bundler path.
|
|
25
|
+
*/
|
|
26
|
+
export {};
|