@printwithsynergy/lens-pdf 0.3.0-beta.81
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 +661 -0
- package/README.md +344 -0
- package/dist/browser/codexOverlay.d.ts +109 -0
- package/dist/browser/codexOverlay.d.ts.map +1 -0
- package/dist/browser/codexOverlay.js +256 -0
- package/dist/browser/codexOverlay.js.map +1 -0
- package/dist/browser/constants.d.ts +13 -0
- package/dist/browser/constants.d.ts.map +1 -0
- package/dist/browser/constants.js +13 -0
- package/dist/browser/constants.js.map +1 -0
- package/dist/browser/index.d.ts +211 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +1190 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/pantone-gold.d.ts +59 -0
- package/dist/browser/pantone-gold.d.ts.map +1 -0
- package/dist/browser/pantone-gold.js +237 -0
- package/dist/browser/pantone-gold.js.map +1 -0
- package/dist/components/AnnotationCanvas.d.ts +27 -0
- package/dist/components/AnnotationCanvas.d.ts.map +1 -0
- package/dist/components/AnnotationCanvas.js +401 -0
- package/dist/components/AnnotationCanvas.js.map +1 -0
- package/dist/components/AnnotationNotesPanel.d.ts +15 -0
- package/dist/components/AnnotationNotesPanel.d.ts.map +1 -0
- package/dist/components/AnnotationNotesPanel.js +235 -0
- package/dist/components/AnnotationNotesPanel.js.map +1 -0
- package/dist/components/AnnotationThread.d.ts +18 -0
- package/dist/components/AnnotationThread.d.ts.map +1 -0
- package/dist/components/AnnotationThread.js +163 -0
- package/dist/components/AnnotationThread.js.map +1 -0
- package/dist/components/AnnotationToolbar.d.ts +39 -0
- package/dist/components/AnnotationToolbar.d.ts.map +1 -0
- package/dist/components/AnnotationToolbar.js +258 -0
- package/dist/components/AnnotationToolbar.js.map +1 -0
- package/dist/components/BoxOverlay.d.ts +20 -0
- package/dist/components/BoxOverlay.d.ts.map +1 -0
- package/dist/components/BoxOverlay.js +107 -0
- package/dist/components/BoxOverlay.js.map +1 -0
- package/dist/components/ColorPickerTool.d.ts +11 -0
- package/dist/components/ColorPickerTool.d.ts.map +1 -0
- package/dist/components/ColorPickerTool.js +220 -0
- package/dist/components/ColorPickerTool.js.map +1 -0
- package/dist/components/DensitometerTool.d.ts +25 -0
- package/dist/components/DensitometerTool.d.ts.map +1 -0
- package/dist/components/DensitometerTool.js +246 -0
- package/dist/components/DensitometerTool.js.map +1 -0
- package/dist/components/DielineInfoPanel.d.ts +27 -0
- package/dist/components/DielineInfoPanel.d.ts.map +1 -0
- package/dist/components/DielineInfoPanel.js +23 -0
- package/dist/components/DielineInfoPanel.js.map +1 -0
- package/dist/components/DielineOverlay.d.ts +10 -0
- package/dist/components/DielineOverlay.d.ts.map +1 -0
- package/dist/components/DielineOverlay.js +57 -0
- package/dist/components/DielineOverlay.js.map +1 -0
- package/dist/components/FindingsSidebar.d.ts +50 -0
- package/dist/components/FindingsSidebar.d.ts.map +1 -0
- package/dist/components/FindingsSidebar.js +78 -0
- package/dist/components/FindingsSidebar.js.map +1 -0
- package/dist/components/LayerCanvas.d.ts +30 -0
- package/dist/components/LayerCanvas.d.ts.map +1 -0
- package/dist/components/LayerCanvas.js +84 -0
- package/dist/components/LayerCanvas.js.map +1 -0
- package/dist/components/LayerPanel.d.ts +9 -0
- package/dist/components/LayerPanel.d.ts.map +1 -0
- package/dist/components/LayerPanel.js +144 -0
- package/dist/components/LayerPanel.js.map +1 -0
- package/dist/components/LensPDF.d.ts +61 -0
- package/dist/components/LensPDF.d.ts.map +1 -0
- package/dist/components/LensPDF.js +49 -0
- package/dist/components/LensPDF.js.map +1 -0
- package/dist/components/LensPDFDemo.d.ts +160 -0
- package/dist/components/LensPDFDemo.d.ts.map +1 -0
- package/dist/components/LensPDFDemo.js +1060 -0
- package/dist/components/LensPDFDemo.js.map +1 -0
- package/dist/components/LensPDFDemo.styles.d.ts +38 -0
- package/dist/components/LensPDFDemo.styles.d.ts.map +1 -0
- package/dist/components/LensPDFDemo.styles.js +282 -0
- package/dist/components/LensPDFDemo.styles.js.map +1 -0
- package/dist/components/LensPDFViewer.d.ts +79 -0
- package/dist/components/LensPDFViewer.d.ts.map +1 -0
- package/dist/components/LensPDFViewer.js +254 -0
- package/dist/components/LensPDFViewer.js.map +1 -0
- package/dist/components/MeasureTool.d.ts +16 -0
- package/dist/components/MeasureTool.d.ts.map +1 -0
- package/dist/components/MeasureTool.js +137 -0
- package/dist/components/MeasureTool.js.map +1 -0
- package/dist/components/MobileBottomSheet.d.ts +12 -0
- package/dist/components/MobileBottomSheet.d.ts.map +1 -0
- package/dist/components/MobileBottomSheet.js +113 -0
- package/dist/components/MobileBottomSheet.js.map +1 -0
- package/dist/components/MobileDrawer.d.ts +31 -0
- package/dist/components/MobileDrawer.d.ts.map +1 -0
- package/dist/components/MobileDrawer.js +67 -0
- package/dist/components/MobileDrawer.js.map +1 -0
- package/dist/components/PageCanvas.d.ts +33 -0
- package/dist/components/PageCanvas.d.ts.map +1 -0
- package/dist/components/PageCanvas.js +385 -0
- package/dist/components/PageCanvas.js.map +1 -0
- package/dist/components/PageNavigator.d.ts +18 -0
- package/dist/components/PageNavigator.d.ts.map +1 -0
- package/dist/components/PageNavigator.js +44 -0
- package/dist/components/PageNavigator.js.map +1 -0
- package/dist/components/SeparationCanvas.d.ts +12 -0
- package/dist/components/SeparationCanvas.d.ts.map +1 -0
- package/dist/components/SeparationCanvas.js +174 -0
- package/dist/components/SeparationCanvas.js.map +1 -0
- package/dist/components/TACHeatmapOverlay.d.ts +17 -0
- package/dist/components/TACHeatmapOverlay.d.ts.map +1 -0
- package/dist/components/TACHeatmapOverlay.js +119 -0
- package/dist/components/TACHeatmapOverlay.js.map +1 -0
- package/dist/components/ZoomControls.d.ts +11 -0
- package/dist/components/ZoomControls.d.ts.map +1 -0
- package/dist/components/ZoomControls.js +26 -0
- package/dist/components/ZoomControls.js.map +1 -0
- package/dist/components/defaultShellPlugins.d.ts +3 -0
- package/dist/components/defaultShellPlugins.d.ts.map +1 -0
- package/dist/components/defaultShellPlugins.js +273 -0
- package/dist/components/defaultShellPlugins.js.map +1 -0
- package/dist/components/index.d.ts +32 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +32 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/presets.d.ts +8 -0
- package/dist/components/presets.d.ts.map +1 -0
- package/dist/components/presets.js +14 -0
- package/dist/components/presets.js.map +1 -0
- package/dist/components/shellPlugins.d.ts +105 -0
- package/dist/components/shellPlugins.d.ts.map +1 -0
- package/dist/components/shellPlugins.js +52 -0
- package/dist/components/shellPlugins.js.map +1 -0
- package/dist/components/useIsMobile.d.ts +16 -0
- package/dist/components/useIsMobile.d.ts.map +1 -0
- package/dist/components/useIsMobile.js +30 -0
- package/dist/components/useIsMobile.js.map +1 -0
- package/dist/fallback-pdfjs/index.d.ts +60 -0
- package/dist/fallback-pdfjs/index.d.ts.map +1 -0
- package/dist/fallback-pdfjs/index.js +163 -0
- package/dist/fallback-pdfjs/index.js.map +1 -0
- package/dist/host/LensPDFProvider.d.ts +36 -0
- package/dist/host/LensPDFProvider.d.ts.map +1 -0
- package/dist/host/LensPDFProvider.js +12 -0
- package/dist/host/LensPDFProvider.js.map +1 -0
- package/dist/host/index.d.ts +167 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +173 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/pdfFallback.d.ts +50 -0
- package/dist/host/pdfFallback.d.ts.map +1 -0
- package/dist/host/pdfFallback.js +171 -0
- package/dist/host/pdfFallback.js.map +1 -0
- package/dist/host/pdfValidation.d.ts +45 -0
- package/dist/host/pdfValidation.d.ts.map +1 -0
- package/dist/host/pdfValidation.js +78 -0
- package/dist/host/pdfValidation.js.map +1 -0
- package/dist/host/shareLink.d.ts +80 -0
- package/dist/host/shareLink.d.ts.map +1 -0
- package/dist/host/shareLink.js +114 -0
- package/dist/host/shareLink.js.map +1 -0
- package/dist/host/useLensPDF.d.ts +73 -0
- package/dist/host/useLensPDF.d.ts.map +1 -0
- package/dist/host/useLensPDF.js +213 -0
- package/dist/host/useLensPDF.js.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/context.d.ts +70 -0
- package/dist/plugin/context.d.ts.map +1 -0
- package/dist/plugin/context.js +16 -0
- package/dist/plugin/context.js.map +1 -0
- package/dist/plugin/findings-location.d.ts +53 -0
- package/dist/plugin/findings-location.d.ts.map +1 -0
- package/dist/plugin/findings-location.js +72 -0
- package/dist/plugin/findings-location.js.map +1 -0
- package/dist/plugin/index.d.ts +19 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +16 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/registry.d.ts +61 -0
- package/dist/plugin/registry.d.ts.map +1 -0
- package/dist/plugin/registry.js +102 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/plugin/services.d.ts +380 -0
- package/dist/plugin/services.d.ts.map +1 -0
- package/dist/plugin/services.js +104 -0
- package/dist/plugin/services.js.map +1 -0
- package/dist/plugin/types.d.ts +198 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/plugin/types.js +24 -0
- package/dist/plugin/types.js.map +1 -0
- package/dist/types/index.d.ts +191 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +95 -0
- package/dist/types/index.js.map +1 -0
- package/dist/units/index.d.ts +64 -0
- package/dist/units/index.d.ts.map +1 -0
- package/dist/units/index.js +98 -0
- package/dist/units/index.js.map +1 -0
- package/docs/architecture.md +90 -0
- package/docs/components.md +569 -0
- package/docs/contributing.md +78 -0
- package/docs/fallback.md +174 -0
- package/docs/lens-pdf-viewer.md +128 -0
- package/docs/licensing.md +78 -0
- package/docs/measurement-units.md +87 -0
- package/docs/plugins.md +256 -0
- package/docs/security.md +69 -0
- package/docs/server.md +212 -0
- package/docs/services.md +210 -0
- package/docs/share-links.md +111 -0
- package/docs/theming.md +164 -0
- package/docs/validation.md +83 -0
- package/package.json +139 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-browser PDF fallback adapter built on pdf.js.
|
|
3
|
+
*
|
|
4
|
+
* Provides "minimum data" for the fallback-capable tools (PageCanvas,
|
|
5
|
+
* PageNavigator, MeasureTool, LayerPanel, ColorPickerTool) when a host
|
|
6
|
+
* hasn't wired richer services. Hosts pass the returned adapter as
|
|
7
|
+
* ``pdfFallback`` on the host context.
|
|
8
|
+
*
|
|
9
|
+
* pdf.js is loaded lazily via dynamic ``import("pdfjs-dist")`` so it
|
|
10
|
+
* stays out of the bundle for hosts that don't use this fallback. Add
|
|
11
|
+
* ``pdfjs-dist`` to your app's dependencies (it's an optional peer dep
|
|
12
|
+
* of ``@printwithsynergy/lens-pdf``).
|
|
13
|
+
*
|
|
14
|
+
* **Security**: this adapter fetches whatever URL the host hands it.
|
|
15
|
+
* Sign / scope / expire the URL the same way you would any other PDF
|
|
16
|
+
* download — the viewer is a pure renderer and trusts the host to
|
|
17
|
+
* enforce access control upstream.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
import type { PdfFallbackAdapter } from "../plugin/services";
|
|
22
|
+
interface PdfJsFallbackOptions {
|
|
23
|
+
/** Raw PDF URL. Must be reachable from the user's browser. */
|
|
24
|
+
pdfUrl: string;
|
|
25
|
+
/**
|
|
26
|
+
* Optional override for the pdf.js worker URL. When omitted, the
|
|
27
|
+
* adapter assumes the bundler / host has already configured
|
|
28
|
+
* ``GlobalWorkerOptions.workerSrc``.
|
|
29
|
+
*/
|
|
30
|
+
workerSrc?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a {@link PdfFallbackAdapter} backed by pdf.js. The returned
|
|
34
|
+
* adapter caches the parsed document and per-page rasters so repeated
|
|
35
|
+
* calls don't re-parse or re-render.
|
|
36
|
+
*
|
|
37
|
+
* @deprecated Use ``createPdfJsFallback`` from
|
|
38
|
+
* ``@printwithsynergy/lens-pdf/fallback-pdfjs`` instead. The
|
|
39
|
+
* subpath imports pdfjs-dist statically so bundlers trace it
|
|
40
|
+
* correctly without consumers having to side-effect-import the
|
|
41
|
+
* dep. This `/host` export uses a dynamic ``await import("...")``
|
|
42
|
+
* that bundlers don't trace; works at runtime only when
|
|
43
|
+
* pdfjs-dist is also installed and resolvable from the consuming
|
|
44
|
+
* app's module graph. New code should not use this entry point.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare function createPdfJsFallback(opts: PdfJsFallbackOptions): PdfFallbackAdapter;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=pdfFallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfFallback.d.ts","sourceRoot":"","sources":["../../host/pdfFallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAwC7D,UAAU,oBAAoB;IAC5B,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,GAAG,kBAAkB,CAwHlF"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-browser PDF fallback adapter built on pdf.js.
|
|
3
|
+
*
|
|
4
|
+
* Provides "minimum data" for the fallback-capable tools (PageCanvas,
|
|
5
|
+
* PageNavigator, MeasureTool, LayerPanel, ColorPickerTool) when a host
|
|
6
|
+
* hasn't wired richer services. Hosts pass the returned adapter as
|
|
7
|
+
* ``pdfFallback`` on the host context.
|
|
8
|
+
*
|
|
9
|
+
* pdf.js is loaded lazily via dynamic ``import("pdfjs-dist")`` so it
|
|
10
|
+
* stays out of the bundle for hosts that don't use this fallback. Add
|
|
11
|
+
* ``pdfjs-dist`` to your app's dependencies (it's an optional peer dep
|
|
12
|
+
* of ``@printwithsynergy/lens-pdf``).
|
|
13
|
+
*
|
|
14
|
+
* **Security**: this adapter fetches whatever URL the host hands it.
|
|
15
|
+
* Sign / scope / expire the URL the same way you would any other PDF
|
|
16
|
+
* download — the viewer is a pure renderer and trusts the host to
|
|
17
|
+
* enforce access control upstream.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
async function loadPdfJs() {
|
|
22
|
+
// Dynamic import keeps pdfjs-dist out of the bundle for hosts that
|
|
23
|
+
// don't use the fallback. The string literal is split so bundlers
|
|
24
|
+
// that try to statically resolve the spec don't fail loudly when
|
|
25
|
+
// pdfjs-dist isn't installed.
|
|
26
|
+
const spec = "pdfjs" + "-dist";
|
|
27
|
+
let mod;
|
|
28
|
+
try {
|
|
29
|
+
mod = (await import(/* @vite-ignore */ spec));
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw new Error("[lens-pdf] createPdfJsFallback requires `pdfjs-dist` to be installed. " +
|
|
33
|
+
"Add it to your app's dependencies, or omit `pdfFallback` from the host context.", { cause: err });
|
|
34
|
+
}
|
|
35
|
+
const api = (mod.default ?? mod);
|
|
36
|
+
if (!api.getDocument) {
|
|
37
|
+
throw new Error("[lens-pdf] Loaded `pdfjs-dist` does not expose getDocument.");
|
|
38
|
+
}
|
|
39
|
+
return api;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a {@link PdfFallbackAdapter} backed by pdf.js. The returned
|
|
43
|
+
* adapter caches the parsed document and per-page rasters so repeated
|
|
44
|
+
* calls don't re-parse or re-render.
|
|
45
|
+
*
|
|
46
|
+
* @deprecated Use ``createPdfJsFallback`` from
|
|
47
|
+
* ``@printwithsynergy/lens-pdf/fallback-pdfjs`` instead. The
|
|
48
|
+
* subpath imports pdfjs-dist statically so bundlers trace it
|
|
49
|
+
* correctly without consumers having to side-effect-import the
|
|
50
|
+
* dep. This `/host` export uses a dynamic ``await import("...")``
|
|
51
|
+
* that bundlers don't trace; works at runtime only when
|
|
52
|
+
* pdfjs-dist is also installed and resolvable from the consuming
|
|
53
|
+
* app's module graph. New code should not use this entry point.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export function createPdfJsFallback(opts) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
let docPromise = null;
|
|
60
|
+
const renderCache = new Map();
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
async function getDoc() {
|
|
63
|
+
if (!docPromise) {
|
|
64
|
+
docPromise = (async () => {
|
|
65
|
+
const api = await loadPdfJs();
|
|
66
|
+
if (opts.workerSrc)
|
|
67
|
+
api.GlobalWorkerOptions.workerSrc = opts.workerSrc;
|
|
68
|
+
return api.getDocument({ url: opts.pdfUrl }).promise;
|
|
69
|
+
})();
|
|
70
|
+
}
|
|
71
|
+
return docPromise;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
async getPageCount() {
|
|
75
|
+
const doc = await getDoc();
|
|
76
|
+
return doc.numPages;
|
|
77
|
+
},
|
|
78
|
+
async getPageDimensions(pageNum) {
|
|
79
|
+
const doc = await getDoc();
|
|
80
|
+
const page = await doc.getPage(pageNum);
|
|
81
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
82
|
+
return { widthPts: viewport.width, heightPts: viewport.height };
|
|
83
|
+
},
|
|
84
|
+
async renderPageToUrl({ pageNum, dpi }) {
|
|
85
|
+
const cacheKey = `${pageNum}@${dpi}`;
|
|
86
|
+
const cached = renderCache.get(cacheKey);
|
|
87
|
+
if (cached)
|
|
88
|
+
return cached;
|
|
89
|
+
const doc = await getDoc();
|
|
90
|
+
const page = await doc.getPage(pageNum);
|
|
91
|
+
const scale = dpi / 72;
|
|
92
|
+
const viewport = page.getViewport({ scale });
|
|
93
|
+
const canvas = document.createElement("canvas");
|
|
94
|
+
canvas.width = Math.ceil(viewport.width);
|
|
95
|
+
canvas.height = Math.ceil(viewport.height);
|
|
96
|
+
const ctx = canvas.getContext("2d");
|
|
97
|
+
if (!ctx)
|
|
98
|
+
throw new Error("[lens-pdf] 2D context unavailable for fallback render.");
|
|
99
|
+
await page.render({ canvasContext: ctx, viewport }).promise;
|
|
100
|
+
const url = canvas.toDataURL("image/png");
|
|
101
|
+
renderCache.set(cacheKey, url);
|
|
102
|
+
return url;
|
|
103
|
+
},
|
|
104
|
+
async listLayers() {
|
|
105
|
+
const doc = await getDoc();
|
|
106
|
+
// pdf.js exposes OCGs through the OptionalContentConfig. Older
|
|
107
|
+
// versions / RGB-only PDFs simply have no groups → empty list.
|
|
108
|
+
let config;
|
|
109
|
+
try {
|
|
110
|
+
config = await doc.getOptionalContentConfig();
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
const groups = (config?.getGroups?.() ?? {});
|
|
116
|
+
const ids = Object.keys(groups);
|
|
117
|
+
return ids.map((id, index) => ({
|
|
118
|
+
name: groups[id]?.name ?? `Layer ${index + 1}`,
|
|
119
|
+
ocg_index: index,
|
|
120
|
+
default_on: config.isVisible(id) ?? true,
|
|
121
|
+
}));
|
|
122
|
+
},
|
|
123
|
+
async sampleColorAt({ pageNum, pdfX, pdfY, dpi = 150 }) {
|
|
124
|
+
const doc = await getDoc();
|
|
125
|
+
const page = await doc.getPage(pageNum);
|
|
126
|
+
const ptsToPx = dpi / 72;
|
|
127
|
+
const viewport = page.getViewport({ scale: ptsToPx });
|
|
128
|
+
// Render the whole page once per (page, dpi) and cache the
|
|
129
|
+
// canvas — repeated sampling is then a single getImageData call.
|
|
130
|
+
const canvasKey = `${pageNum}@${dpi}`;
|
|
131
|
+
let canvas = sampleCanvases.get(canvasKey);
|
|
132
|
+
if (!canvas) {
|
|
133
|
+
canvas = document.createElement("canvas");
|
|
134
|
+
canvas.width = Math.ceil(viewport.width);
|
|
135
|
+
canvas.height = Math.ceil(viewport.height);
|
|
136
|
+
const renderCtx = canvas.getContext("2d", { willReadFrequently: true });
|
|
137
|
+
if (!renderCtx)
|
|
138
|
+
return null;
|
|
139
|
+
await page.render({ canvasContext: renderCtx, viewport }).promise;
|
|
140
|
+
sampleCanvases.set(canvasKey, canvas);
|
|
141
|
+
}
|
|
142
|
+
// pdfX/pdfY use PDF-point coords with origin lower-left; canvas
|
|
143
|
+
// pixels use origin upper-left.
|
|
144
|
+
const pageHeightPts = viewport.height / ptsToPx;
|
|
145
|
+
const pxX = Math.max(0, Math.min(canvas.width - 1, Math.round(pdfX * ptsToPx)));
|
|
146
|
+
const pxY = Math.max(0, Math.min(canvas.height - 1, Math.round((pageHeightPts - pdfY) * ptsToPx)));
|
|
147
|
+
const ctx = canvas.getContext("2d");
|
|
148
|
+
if (!ctx)
|
|
149
|
+
return null;
|
|
150
|
+
const data = ctx.getImageData(pxX, pxY, 1, 1).data;
|
|
151
|
+
const r = data[0] ?? 0;
|
|
152
|
+
const g = data[1] ?? 0;
|
|
153
|
+
const b = data[2] ?? 0;
|
|
154
|
+
const hex = "#" +
|
|
155
|
+
[r, g, b]
|
|
156
|
+
.map((v) => v.toString(16).padStart(2, "0"))
|
|
157
|
+
.join("");
|
|
158
|
+
const sample = {
|
|
159
|
+
x: pdfX,
|
|
160
|
+
y: pdfY,
|
|
161
|
+
rgb: [r, g, b],
|
|
162
|
+
hex,
|
|
163
|
+
// pdf.js renders to RGB only — no real ink coverage available.
|
|
164
|
+
tac: null,
|
|
165
|
+
};
|
|
166
|
+
return sample;
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const sampleCanvases = new Map();
|
|
171
|
+
//# sourceMappingURL=pdfFallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfFallback.js","sourceRoot":"","sources":["../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AAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side PDF validation utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides quick checks (magic bytes, MIME type, file size) before
|
|
5
|
+
* handing a file to the viewer or pdf.js fallback. These run entirely
|
|
6
|
+
* in the browser — no server round-trip required.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/** Result of a PDF validation check. */
|
|
11
|
+
export interface PdfValidationResult {
|
|
12
|
+
/** Whether the file passed all checks. */
|
|
13
|
+
valid: boolean;
|
|
14
|
+
/** Human-readable error message when `valid` is false. */
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validate a `File` object before loading it into the viewer.
|
|
19
|
+
*
|
|
20
|
+
* Checks (in order):
|
|
21
|
+
* 1. MIME type is `application/pdf` (or empty — some browsers don't
|
|
22
|
+
* populate it for drag-dropped files).
|
|
23
|
+
* 2. First 5 bytes match the PDF magic signature `%PDF-`.
|
|
24
|
+
* 3. File size is within the allowed limit.
|
|
25
|
+
*
|
|
26
|
+
* @param file - The `File` to validate.
|
|
27
|
+
* @param maxBytes - Maximum allowed size in bytes. Default: 50 MB.
|
|
28
|
+
* @returns A promise resolving to the validation result.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare function validatePdfFile(file: File, maxBytes?: number): Promise<PdfValidationResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Validate a PDF URL string before loading it into the viewer.
|
|
35
|
+
*
|
|
36
|
+
* This is a **synchronous** surface-level check — it validates URL
|
|
37
|
+
* format only. It does not fetch the URL or inspect response headers.
|
|
38
|
+
*
|
|
39
|
+
* @param url - The URL string to validate.
|
|
40
|
+
* @returns The validation result.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare function validatePdfUrl(url: string): PdfValidationResult;
|
|
45
|
+
//# sourceMappingURL=pdfValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfValidation.d.ts","sourceRoot":"","sources":["../../host/pdfValidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,KAAK,EAAE,OAAO,CAAC;IACf,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAQD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,QAAQ,GAAE,MAA0B,GACnC,OAAO,CAAC,mBAAmB,CAAC,CAuB9B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAgB/D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side PDF validation utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides quick checks (magic bytes, MIME type, file size) before
|
|
5
|
+
* handing a file to the viewer or pdf.js fallback. These run entirely
|
|
6
|
+
* in the browser — no server round-trip required.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/** Default maximum file size: 50 MB. */
|
|
11
|
+
const DEFAULT_MAX_BYTES = 50 * 1024 * 1024;
|
|
12
|
+
/** PDF magic bytes: `%PDF-` (hex 25 50 44 46 2D). */
|
|
13
|
+
const PDF_MAGIC = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2d]);
|
|
14
|
+
/**
|
|
15
|
+
* Validate a `File` object before loading it into the viewer.
|
|
16
|
+
*
|
|
17
|
+
* Checks (in order):
|
|
18
|
+
* 1. MIME type is `application/pdf` (or empty — some browsers don't
|
|
19
|
+
* populate it for drag-dropped files).
|
|
20
|
+
* 2. First 5 bytes match the PDF magic signature `%PDF-`.
|
|
21
|
+
* 3. File size is within the allowed limit.
|
|
22
|
+
*
|
|
23
|
+
* @param file - The `File` to validate.
|
|
24
|
+
* @param maxBytes - Maximum allowed size in bytes. Default: 50 MB.
|
|
25
|
+
* @returns A promise resolving to the validation result.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export async function validatePdfFile(file, maxBytes = DEFAULT_MAX_BYTES) {
|
|
30
|
+
// MIME check (allow empty — some browsers omit MIME for drag-drop)
|
|
31
|
+
if (file.type && file.type !== "application/pdf") {
|
|
32
|
+
return { valid: false, error: "File is not a PDF. Expected MIME type application/pdf." };
|
|
33
|
+
}
|
|
34
|
+
// Size check
|
|
35
|
+
if (file.size > maxBytes) {
|
|
36
|
+
const maxMb = Math.round(maxBytes / (1024 * 1024));
|
|
37
|
+
return { valid: false, error: `File is too large. Maximum size is ${maxMb} MB.` };
|
|
38
|
+
}
|
|
39
|
+
// Magic bytes check
|
|
40
|
+
try {
|
|
41
|
+
const header = new Uint8Array(await file.slice(0, 5).arrayBuffer());
|
|
42
|
+
if (header.length < 5 || !PDF_MAGIC.every((b, i) => header[i] === b)) {
|
|
43
|
+
return { valid: false, error: "File does not appear to be a valid PDF (missing %PDF- header)." };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { valid: false, error: "Could not read file header." };
|
|
48
|
+
}
|
|
49
|
+
return { valid: true };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validate a PDF URL string before loading it into the viewer.
|
|
53
|
+
*
|
|
54
|
+
* This is a **synchronous** surface-level check — it validates URL
|
|
55
|
+
* format only. It does not fetch the URL or inspect response headers.
|
|
56
|
+
*
|
|
57
|
+
* @param url - The URL string to validate.
|
|
58
|
+
* @returns The validation result.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export function validatePdfUrl(url) {
|
|
63
|
+
const trimmed = url.trim();
|
|
64
|
+
if (!trimmed) {
|
|
65
|
+
return { valid: false, error: "URL is empty." };
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const parsed = new URL(trimmed);
|
|
69
|
+
if (!["http:", "https:", "blob:"].includes(parsed.protocol)) {
|
|
70
|
+
return { valid: false, error: "URL must use http://, https://, or blob: protocol." };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return { valid: false, error: "Invalid URL format." };
|
|
75
|
+
}
|
|
76
|
+
return { valid: true };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=pdfValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfValidation.js","sourceRoot":"","sources":["../../host/pdfValidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,wCAAwC;AACxC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,qDAAqD;AACrD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAU,EACV,WAAmB,iBAAiB;IAEpC,mEAAmE;IACnE,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;QACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,wDAAwD,EAAE,CAAC;IAC3F,CAAC;IAED,aAAa;IACb,IAAI,IAAI,CAAC,IAAI,GAAG,QAAQ,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;QACnD,OAAO,EAAE,KAA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EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC;IACxD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shareable viewer link utilities.
|
|
3
|
+
*
|
|
4
|
+
* {@link generateShareLink} builds a URL that opens a LensPDF viewer
|
|
5
|
+
* with a specific PDF pre-loaded and settings applied.
|
|
6
|
+
* {@link parseShareParams} parses those query params back into props.
|
|
7
|
+
*
|
|
8
|
+
* URL format:
|
|
9
|
+
* ```
|
|
10
|
+
* https://lenspdf.com/demo?url=<encoded>&fullscreen=true&zoom=150&page=1&mode=single&theme=dark
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
import type { ThemeTokens } from "../plugin/services";
|
|
16
|
+
/** Options for {@link generateShareLink}. */
|
|
17
|
+
export interface ShareLinkOptions {
|
|
18
|
+
/** Base URL of the host's demo/viewer page (e.g. `https://lenspdf.com/demo`). */
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
/** PDF URL to pre-load. */
|
|
21
|
+
pdfUrl: string;
|
|
22
|
+
/** Open in fullscreen mode (no site chrome). Default: false. */
|
|
23
|
+
fullscreen?: boolean;
|
|
24
|
+
/** Initial zoom percentage. */
|
|
25
|
+
zoom?: number;
|
|
26
|
+
/** Initial page number. */
|
|
27
|
+
page?: number;
|
|
28
|
+
/** Viewer scroll mode. */
|
|
29
|
+
mode?: "scroll" | "single";
|
|
30
|
+
/** Tools to enable (encoded as comma-separated in URL). */
|
|
31
|
+
tools?: string[];
|
|
32
|
+
/** Theme: preset name or inline token overrides. */
|
|
33
|
+
theme?: "light" | "dark" | Partial<ThemeTokens>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build a shareable viewer URL with query params.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* const link = generateShareLink({
|
|
40
|
+
* baseUrl: "https://lenspdf.com/demo",
|
|
41
|
+
* pdfUrl: "https://cdn.example.com/proof.pdf",
|
|
42
|
+
* fullscreen: true,
|
|
43
|
+
* zoom: 150,
|
|
44
|
+
* });
|
|
45
|
+
* // → "https://lenspdf.com/demo?url=https%3A%2F%2Fcdn.example.com%2Fproof.pdf&fullscreen=true&zoom=150"
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateShareLink(opts: ShareLinkOptions): string;
|
|
51
|
+
/** Parsed share parameters returned by {@link parseShareParams}. */
|
|
52
|
+
export interface ParsedShareParams {
|
|
53
|
+
/** PDF URL to pre-load, or undefined if not specified. */
|
|
54
|
+
pdfUrl?: string;
|
|
55
|
+
/** Whether to open in fullscreen mode. */
|
|
56
|
+
fullscreen: boolean;
|
|
57
|
+
/** Initial zoom percentage, or undefined. */
|
|
58
|
+
zoom?: number;
|
|
59
|
+
/** Initial page number, or undefined. */
|
|
60
|
+
page?: number;
|
|
61
|
+
/** Viewer mode, or undefined. */
|
|
62
|
+
mode?: "scroll" | "single";
|
|
63
|
+
/** Tools to enable, or undefined. */
|
|
64
|
+
tools?: string[];
|
|
65
|
+
/** Theme preset name or inline tokens, or undefined. */
|
|
66
|
+
theme?: "light" | "dark" | Partial<ThemeTokens>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parse query params from a shareable viewer URL back into props.
|
|
70
|
+
* Use this in the host's page component to read URL state:
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* const params = parseShareParams(new URLSearchParams(window.location.search));
|
|
74
|
+
* <LensPDFDemo initialPdfUrl={params.pdfUrl} fullscreen={params.fullscreen} />
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare function parseShareParams(searchParams: URLSearchParams): ParsedShareParams;
|
|
80
|
+
//# sourceMappingURL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AAO,CAAC,WAAW,CAAC,CAAC;CACjD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,eAAe,GAAG,iBAAiB,CA2CjF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shareable viewer link utilities.
|
|
3
|
+
*
|
|
4
|
+
* {@link generateShareLink} builds a URL that opens a LensPDF viewer
|
|
5
|
+
* with a specific PDF pre-loaded and settings applied.
|
|
6
|
+
* {@link parseShareParams} parses those query params back into props.
|
|
7
|
+
*
|
|
8
|
+
* URL format:
|
|
9
|
+
* ```
|
|
10
|
+
* https://lenspdf.com/demo?url=<encoded>&fullscreen=true&zoom=150&page=1&mode=single&theme=dark
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Build a shareable viewer URL with query params.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const link = generateShareLink({
|
|
20
|
+
* baseUrl: "https://lenspdf.com/demo",
|
|
21
|
+
* pdfUrl: "https://cdn.example.com/proof.pdf",
|
|
22
|
+
* fullscreen: true,
|
|
23
|
+
* zoom: 150,
|
|
24
|
+
* });
|
|
25
|
+
* // → "https://lenspdf.com/demo?url=https%3A%2F%2Fcdn.example.com%2Fproof.pdf&fullscreen=true&zoom=150"
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export function generateShareLink(opts) {
|
|
31
|
+
const url = new URL(opts.baseUrl);
|
|
32
|
+
url.searchParams.set("url", opts.pdfUrl);
|
|
33
|
+
if (opts.fullscreen) {
|
|
34
|
+
url.searchParams.set("fullscreen", "true");
|
|
35
|
+
}
|
|
36
|
+
if (opts.zoom !== undefined) {
|
|
37
|
+
url.searchParams.set("zoom", String(opts.zoom));
|
|
38
|
+
}
|
|
39
|
+
if (opts.page !== undefined) {
|
|
40
|
+
url.searchParams.set("page", String(opts.page));
|
|
41
|
+
}
|
|
42
|
+
if (opts.mode && opts.mode !== "scroll") {
|
|
43
|
+
url.searchParams.set("mode", opts.mode);
|
|
44
|
+
}
|
|
45
|
+
if (opts.tools && opts.tools.length > 0) {
|
|
46
|
+
url.searchParams.set("tools", opts.tools.join(","));
|
|
47
|
+
}
|
|
48
|
+
if (opts.theme) {
|
|
49
|
+
if (typeof opts.theme === "string") {
|
|
50
|
+
url.searchParams.set("theme", opts.theme);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Inline tokens are encoded as JSON.
|
|
54
|
+
url.searchParams.set("theme", JSON.stringify(opts.theme));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return url.toString();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse query params from a shareable viewer URL back into props.
|
|
61
|
+
* Use this in the host's page component to read URL state:
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const params = parseShareParams(new URLSearchParams(window.location.search));
|
|
65
|
+
* <LensPDFDemo initialPdfUrl={params.pdfUrl} fullscreen={params.fullscreen} />
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export function parseShareParams(searchParams) {
|
|
71
|
+
const result = {
|
|
72
|
+
fullscreen: false,
|
|
73
|
+
};
|
|
74
|
+
const url = searchParams.get("url");
|
|
75
|
+
if (url)
|
|
76
|
+
result.pdfUrl = url;
|
|
77
|
+
const fullscreen = searchParams.get("fullscreen");
|
|
78
|
+
if (fullscreen === "true" || fullscreen === "1")
|
|
79
|
+
result.fullscreen = true;
|
|
80
|
+
const zoom = searchParams.get("zoom");
|
|
81
|
+
if (zoom) {
|
|
82
|
+
const parsed = parseInt(zoom, 10);
|
|
83
|
+
if (!isNaN(parsed) && parsed > 0)
|
|
84
|
+
result.zoom = parsed;
|
|
85
|
+
}
|
|
86
|
+
const page = searchParams.get("page");
|
|
87
|
+
if (page) {
|
|
88
|
+
const parsed = parseInt(page, 10);
|
|
89
|
+
if (!isNaN(parsed) && parsed > 0)
|
|
90
|
+
result.page = parsed;
|
|
91
|
+
}
|
|
92
|
+
const mode = searchParams.get("mode");
|
|
93
|
+
if (mode === "scroll" || mode === "single")
|
|
94
|
+
result.mode = mode;
|
|
95
|
+
const tools = searchParams.get("tools");
|
|
96
|
+
if (tools)
|
|
97
|
+
result.tools = tools.split(",").filter(Boolean);
|
|
98
|
+
const theme = searchParams.get("theme");
|
|
99
|
+
if (theme) {
|
|
100
|
+
if (theme === "light" || theme === "dark") {
|
|
101
|
+
result.theme = theme;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
try {
|
|
105
|
+
result.theme = JSON.parse(theme);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Invalid JSON — ignore.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=shareLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shareLink.js","sourceRoot":"","sources":["../../host/shareLink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA4BH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAsB;IACtD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAElC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAEzC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,M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QACV,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YAC1C,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC;gBACH,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAyB,CAAC;YAC3D,CAAC;YAAC,MAAM,CAAC;gBACP,yBAAyB;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useLensPDF` — React hook that manages all viewer state.
|
|
3
|
+
*
|
|
4
|
+
* Returns everything a consumer needs to render a viewer: context
|
|
5
|
+
* values, fallback adapter, page/zoom/layer/tool state, and
|
|
6
|
+
* computed canvas dimensions. Pass the return value to
|
|
7
|
+
* {@link LensPDFProvider} (or spread into `<LensPDFViewer>`) and
|
|
8
|
+
* you're done — no manual context wiring required.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
import type { PdfFallbackAdapter, ThemeTokens, ViewerServices } from "../plugin/services";
|
|
13
|
+
import type { PageInfo } from "../types";
|
|
14
|
+
import type { ViewerHostContextValue } from "./index";
|
|
15
|
+
/** Options for {@link useLensPDF}. */
|
|
16
|
+
export interface UseLensPDFOptions {
|
|
17
|
+
/** Theme tokens. Merged onto defaults. */
|
|
18
|
+
tokens?: Partial<ThemeTokens>;
|
|
19
|
+
/** Partial wired services — unwired fields auto-filled with no-op defaults. */
|
|
20
|
+
services?: Partial<ViewerServices>;
|
|
21
|
+
/** Initial zoom percentage. Default 100. */
|
|
22
|
+
initialZoom?: number;
|
|
23
|
+
/** Viewer mode. Default "scroll". */
|
|
24
|
+
mode?: "scroll" | "single";
|
|
25
|
+
/** Override pdf.js worker URL. Uses CDN default when omitted. */
|
|
26
|
+
workerSrc?: string;
|
|
27
|
+
/** Initial page number (1-indexed). Default 1. */
|
|
28
|
+
initialPage?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Full viewer state returned by {@link useLensPDF}. */
|
|
31
|
+
export interface UseLensPDFReturn {
|
|
32
|
+
hostValue: ViewerHostContextValue;
|
|
33
|
+
servicesValue: ViewerServices;
|
|
34
|
+
fallback: PdfFallbackAdapter | undefined;
|
|
35
|
+
pageCount: number | null;
|
|
36
|
+
currentPage: number;
|
|
37
|
+
setCurrentPage: (n: number) => void;
|
|
38
|
+
currentPageInfo: PageInfo;
|
|
39
|
+
pages: PageInfo[];
|
|
40
|
+
pageDims: Map<number, {
|
|
41
|
+
widthPts: number;
|
|
42
|
+
heightPts: number;
|
|
43
|
+
}>;
|
|
44
|
+
zoom: number;
|
|
45
|
+
setZoom: (z: number) => void;
|
|
46
|
+
canvasWidth: number;
|
|
47
|
+
canvasHeight: number;
|
|
48
|
+
enabledLayers: Set<number>;
|
|
49
|
+
toggleLayer: (ocgIndex: number) => void;
|
|
50
|
+
setAllLayers: (enabled: boolean) => void;
|
|
51
|
+
hasLayers: boolean;
|
|
52
|
+
activeTool: "none" | "color-picker" | "measure";
|
|
53
|
+
setActiveTool: (t: "none" | "color-picker" | "measure") => void;
|
|
54
|
+
error: string | null;
|
|
55
|
+
setError: (e: string | null) => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Manages all LensPDF viewer state. Pair with `<LensPDFProvider>`
|
|
59
|
+
* or `<LensPDFViewer>` for rendering.
|
|
60
|
+
*
|
|
61
|
+
* ```tsx
|
|
62
|
+
* const viewer = useLensPDF("https://cdn.example.com/proof.pdf");
|
|
63
|
+
* return (
|
|
64
|
+
* <LensPDFProvider value={viewer}>
|
|
65
|
+
* <PageCanvas page={viewer.currentPageInfo} zoom={viewer.zoom} ... />
|
|
66
|
+
* </LensPDFProvider>
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export declare function useLensPDF(pdfUrl: string | undefined, opts?: UseLensPDFOptions): UseLensPDFReturn;
|
|
73
|
+
//# sourceMappingURL=useLensPDF.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLensPDF.d.ts","sourceRoot":"","sources":["../../host/useLensPDF.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE1F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAMtD,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACnC,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC3B,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAMD,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAE/B,SAAS,EAAE,sBAAsB,CAAC;IAClC,aAAa,EAAE,cAAc,CAAC;IAG9B,QAAQ,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAGzC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,eAAe,EAAE,QAAQ,CAAC;IAC1B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,E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