@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.
Files changed (213) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +344 -0
  3. package/dist/browser/codexOverlay.d.ts +109 -0
  4. package/dist/browser/codexOverlay.d.ts.map +1 -0
  5. package/dist/browser/codexOverlay.js +256 -0
  6. package/dist/browser/codexOverlay.js.map +1 -0
  7. package/dist/browser/constants.d.ts +13 -0
  8. package/dist/browser/constants.d.ts.map +1 -0
  9. package/dist/browser/constants.js +13 -0
  10. package/dist/browser/constants.js.map +1 -0
  11. package/dist/browser/index.d.ts +211 -0
  12. package/dist/browser/index.d.ts.map +1 -0
  13. package/dist/browser/index.js +1190 -0
  14. package/dist/browser/index.js.map +1 -0
  15. package/dist/browser/pantone-gold.d.ts +59 -0
  16. package/dist/browser/pantone-gold.d.ts.map +1 -0
  17. package/dist/browser/pantone-gold.js +237 -0
  18. package/dist/browser/pantone-gold.js.map +1 -0
  19. package/dist/components/AnnotationCanvas.d.ts +27 -0
  20. package/dist/components/AnnotationCanvas.d.ts.map +1 -0
  21. package/dist/components/AnnotationCanvas.js +401 -0
  22. package/dist/components/AnnotationCanvas.js.map +1 -0
  23. package/dist/components/AnnotationNotesPanel.d.ts +15 -0
  24. package/dist/components/AnnotationNotesPanel.d.ts.map +1 -0
  25. package/dist/components/AnnotationNotesPanel.js +235 -0
  26. package/dist/components/AnnotationNotesPanel.js.map +1 -0
  27. package/dist/components/AnnotationThread.d.ts +18 -0
  28. package/dist/components/AnnotationThread.d.ts.map +1 -0
  29. package/dist/components/AnnotationThread.js +163 -0
  30. package/dist/components/AnnotationThread.js.map +1 -0
  31. package/dist/components/AnnotationToolbar.d.ts +39 -0
  32. package/dist/components/AnnotationToolbar.d.ts.map +1 -0
  33. package/dist/components/AnnotationToolbar.js +258 -0
  34. package/dist/components/AnnotationToolbar.js.map +1 -0
  35. package/dist/components/BoxOverlay.d.ts +20 -0
  36. package/dist/components/BoxOverlay.d.ts.map +1 -0
  37. package/dist/components/BoxOverlay.js +107 -0
  38. package/dist/components/BoxOverlay.js.map +1 -0
  39. package/dist/components/ColorPickerTool.d.ts +11 -0
  40. package/dist/components/ColorPickerTool.d.ts.map +1 -0
  41. package/dist/components/ColorPickerTool.js +220 -0
  42. package/dist/components/ColorPickerTool.js.map +1 -0
  43. package/dist/components/DensitometerTool.d.ts +25 -0
  44. package/dist/components/DensitometerTool.d.ts.map +1 -0
  45. package/dist/components/DensitometerTool.js +246 -0
  46. package/dist/components/DensitometerTool.js.map +1 -0
  47. package/dist/components/DielineInfoPanel.d.ts +27 -0
  48. package/dist/components/DielineInfoPanel.d.ts.map +1 -0
  49. package/dist/components/DielineInfoPanel.js +23 -0
  50. package/dist/components/DielineInfoPanel.js.map +1 -0
  51. package/dist/components/DielineOverlay.d.ts +10 -0
  52. package/dist/components/DielineOverlay.d.ts.map +1 -0
  53. package/dist/components/DielineOverlay.js +57 -0
  54. package/dist/components/DielineOverlay.js.map +1 -0
  55. package/dist/components/FindingsSidebar.d.ts +50 -0
  56. package/dist/components/FindingsSidebar.d.ts.map +1 -0
  57. package/dist/components/FindingsSidebar.js +78 -0
  58. package/dist/components/FindingsSidebar.js.map +1 -0
  59. package/dist/components/LayerCanvas.d.ts +30 -0
  60. package/dist/components/LayerCanvas.d.ts.map +1 -0
  61. package/dist/components/LayerCanvas.js +84 -0
  62. package/dist/components/LayerCanvas.js.map +1 -0
  63. package/dist/components/LayerPanel.d.ts +9 -0
  64. package/dist/components/LayerPanel.d.ts.map +1 -0
  65. package/dist/components/LayerPanel.js +144 -0
  66. package/dist/components/LayerPanel.js.map +1 -0
  67. package/dist/components/LensPDF.d.ts +61 -0
  68. package/dist/components/LensPDF.d.ts.map +1 -0
  69. package/dist/components/LensPDF.js +49 -0
  70. package/dist/components/LensPDF.js.map +1 -0
  71. package/dist/components/LensPDFDemo.d.ts +160 -0
  72. package/dist/components/LensPDFDemo.d.ts.map +1 -0
  73. package/dist/components/LensPDFDemo.js +1060 -0
  74. package/dist/components/LensPDFDemo.js.map +1 -0
  75. package/dist/components/LensPDFDemo.styles.d.ts +38 -0
  76. package/dist/components/LensPDFDemo.styles.d.ts.map +1 -0
  77. package/dist/components/LensPDFDemo.styles.js +282 -0
  78. package/dist/components/LensPDFDemo.styles.js.map +1 -0
  79. package/dist/components/LensPDFViewer.d.ts +79 -0
  80. package/dist/components/LensPDFViewer.d.ts.map +1 -0
  81. package/dist/components/LensPDFViewer.js +254 -0
  82. package/dist/components/LensPDFViewer.js.map +1 -0
  83. package/dist/components/MeasureTool.d.ts +16 -0
  84. package/dist/components/MeasureTool.d.ts.map +1 -0
  85. package/dist/components/MeasureTool.js +137 -0
  86. package/dist/components/MeasureTool.js.map +1 -0
  87. package/dist/components/MobileBottomSheet.d.ts +12 -0
  88. package/dist/components/MobileBottomSheet.d.ts.map +1 -0
  89. package/dist/components/MobileBottomSheet.js +113 -0
  90. package/dist/components/MobileBottomSheet.js.map +1 -0
  91. package/dist/components/MobileDrawer.d.ts +31 -0
  92. package/dist/components/MobileDrawer.d.ts.map +1 -0
  93. package/dist/components/MobileDrawer.js +67 -0
  94. package/dist/components/MobileDrawer.js.map +1 -0
  95. package/dist/components/PageCanvas.d.ts +33 -0
  96. package/dist/components/PageCanvas.d.ts.map +1 -0
  97. package/dist/components/PageCanvas.js +385 -0
  98. package/dist/components/PageCanvas.js.map +1 -0
  99. package/dist/components/PageNavigator.d.ts +18 -0
  100. package/dist/components/PageNavigator.d.ts.map +1 -0
  101. package/dist/components/PageNavigator.js +44 -0
  102. package/dist/components/PageNavigator.js.map +1 -0
  103. package/dist/components/SeparationCanvas.d.ts +12 -0
  104. package/dist/components/SeparationCanvas.d.ts.map +1 -0
  105. package/dist/components/SeparationCanvas.js +174 -0
  106. package/dist/components/SeparationCanvas.js.map +1 -0
  107. package/dist/components/TACHeatmapOverlay.d.ts +17 -0
  108. package/dist/components/TACHeatmapOverlay.d.ts.map +1 -0
  109. package/dist/components/TACHeatmapOverlay.js +119 -0
  110. package/dist/components/TACHeatmapOverlay.js.map +1 -0
  111. package/dist/components/ZoomControls.d.ts +11 -0
  112. package/dist/components/ZoomControls.d.ts.map +1 -0
  113. package/dist/components/ZoomControls.js +26 -0
  114. package/dist/components/ZoomControls.js.map +1 -0
  115. package/dist/components/defaultShellPlugins.d.ts +3 -0
  116. package/dist/components/defaultShellPlugins.d.ts.map +1 -0
  117. package/dist/components/defaultShellPlugins.js +273 -0
  118. package/dist/components/defaultShellPlugins.js.map +1 -0
  119. package/dist/components/index.d.ts +32 -0
  120. package/dist/components/index.d.ts.map +1 -0
  121. package/dist/components/index.js +32 -0
  122. package/dist/components/index.js.map +1 -0
  123. package/dist/components/presets.d.ts +8 -0
  124. package/dist/components/presets.d.ts.map +1 -0
  125. package/dist/components/presets.js +14 -0
  126. package/dist/components/presets.js.map +1 -0
  127. package/dist/components/shellPlugins.d.ts +105 -0
  128. package/dist/components/shellPlugins.d.ts.map +1 -0
  129. package/dist/components/shellPlugins.js +52 -0
  130. package/dist/components/shellPlugins.js.map +1 -0
  131. package/dist/components/useIsMobile.d.ts +16 -0
  132. package/dist/components/useIsMobile.d.ts.map +1 -0
  133. package/dist/components/useIsMobile.js +30 -0
  134. package/dist/components/useIsMobile.js.map +1 -0
  135. package/dist/fallback-pdfjs/index.d.ts +60 -0
  136. package/dist/fallback-pdfjs/index.d.ts.map +1 -0
  137. package/dist/fallback-pdfjs/index.js +163 -0
  138. package/dist/fallback-pdfjs/index.js.map +1 -0
  139. package/dist/host/LensPDFProvider.d.ts +36 -0
  140. package/dist/host/LensPDFProvider.d.ts.map +1 -0
  141. package/dist/host/LensPDFProvider.js +12 -0
  142. package/dist/host/LensPDFProvider.js.map +1 -0
  143. package/dist/host/index.d.ts +167 -0
  144. package/dist/host/index.d.ts.map +1 -0
  145. package/dist/host/index.js +173 -0
  146. package/dist/host/index.js.map +1 -0
  147. package/dist/host/pdfFallback.d.ts +50 -0
  148. package/dist/host/pdfFallback.d.ts.map +1 -0
  149. package/dist/host/pdfFallback.js +171 -0
  150. package/dist/host/pdfFallback.js.map +1 -0
  151. package/dist/host/pdfValidation.d.ts +45 -0
  152. package/dist/host/pdfValidation.d.ts.map +1 -0
  153. package/dist/host/pdfValidation.js +78 -0
  154. package/dist/host/pdfValidation.js.map +1 -0
  155. package/dist/host/shareLink.d.ts +80 -0
  156. package/dist/host/shareLink.d.ts.map +1 -0
  157. package/dist/host/shareLink.js +114 -0
  158. package/dist/host/shareLink.js.map +1 -0
  159. package/dist/host/useLensPDF.d.ts +73 -0
  160. package/dist/host/useLensPDF.d.ts.map +1 -0
  161. package/dist/host/useLensPDF.js +213 -0
  162. package/dist/host/useLensPDF.js.map +1 -0
  163. package/dist/index.d.ts +68 -0
  164. package/dist/index.d.ts.map +1 -0
  165. package/dist/index.js +62 -0
  166. package/dist/index.js.map +1 -0
  167. package/dist/plugin/context.d.ts +70 -0
  168. package/dist/plugin/context.d.ts.map +1 -0
  169. package/dist/plugin/context.js +16 -0
  170. package/dist/plugin/context.js.map +1 -0
  171. package/dist/plugin/findings-location.d.ts +53 -0
  172. package/dist/plugin/findings-location.d.ts.map +1 -0
  173. package/dist/plugin/findings-location.js +72 -0
  174. package/dist/plugin/findings-location.js.map +1 -0
  175. package/dist/plugin/index.d.ts +19 -0
  176. package/dist/plugin/index.d.ts.map +1 -0
  177. package/dist/plugin/index.js +16 -0
  178. package/dist/plugin/index.js.map +1 -0
  179. package/dist/plugin/registry.d.ts +61 -0
  180. package/dist/plugin/registry.d.ts.map +1 -0
  181. package/dist/plugin/registry.js +102 -0
  182. package/dist/plugin/registry.js.map +1 -0
  183. package/dist/plugin/services.d.ts +380 -0
  184. package/dist/plugin/services.d.ts.map +1 -0
  185. package/dist/plugin/services.js +104 -0
  186. package/dist/plugin/services.js.map +1 -0
  187. package/dist/plugin/types.d.ts +198 -0
  188. package/dist/plugin/types.d.ts.map +1 -0
  189. package/dist/plugin/types.js +24 -0
  190. package/dist/plugin/types.js.map +1 -0
  191. package/dist/types/index.d.ts +191 -0
  192. package/dist/types/index.d.ts.map +1 -0
  193. package/dist/types/index.js +95 -0
  194. package/dist/types/index.js.map +1 -0
  195. package/dist/units/index.d.ts +64 -0
  196. package/dist/units/index.d.ts.map +1 -0
  197. package/dist/units/index.js +98 -0
  198. package/dist/units/index.js.map +1 -0
  199. package/docs/architecture.md +90 -0
  200. package/docs/components.md +569 -0
  201. package/docs/contributing.md +78 -0
  202. package/docs/fallback.md +174 -0
  203. package/docs/lens-pdf-viewer.md +128 -0
  204. package/docs/licensing.md +78 -0
  205. package/docs/measurement-units.md +87 -0
  206. package/docs/plugins.md +256 -0
  207. package/docs/security.md +69 -0
  208. package/docs/server.md +212 -0
  209. package/docs/services.md +210 -0
  210. package/docs/share-links.md +111 -0
  211. package/docs/theming.md +164 -0
  212. package/docs/validation.md +83 -0
  213. package/package.json +139 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsMobile.js","sourceRoot":"","sources":["../../components/useIsMobile.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,UAAU,GAAG,GAAG;IAC1C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,eAAe,UAAU,KAAK,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,EAAE,CAAC;QACT,GAAG,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACvC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IACjB,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `@printwithsynergy/lens-pdf/fallback-pdfjs`
3
+ *
4
+ * In-browser PDF fallback adapter built on pdf.js. Provides "minimum
5
+ * data" (page count, dimensions, page rasters, OCG layers, RGB color
6
+ * sampling) for the fallback-capable tools when a host hasn't wired
7
+ * richer services.
8
+ *
9
+ * Distinct from the deprecated `createPdfJsFallback` re-export in
10
+ * `/host`: this subpath imports `pdfjs-dist` statically, so bundlers
11
+ * trace it correctly without the host having to side-effect-import
12
+ * the dep themselves. Hosts that never use the fallback never import
13
+ * this subpath and never pay the bundle cost.
14
+ *
15
+ * ```ts
16
+ * import { createPdfJsFallback } from "@printwithsynergy/lens-pdf/fallback-pdfjs";
17
+ * const fallback = createPdfJsFallback({ pdfUrl: "/proofs/abc.pdf" });
18
+ * ```
19
+ *
20
+ * Usually you don't import this directly — `<LensPDFViewer>` uses
21
+ * it internally and is the one-liner most hosts want.
22
+ *
23
+ * **Security**: this adapter fetches whatever URL the host hands it.
24
+ * Sign / scope / expire the URL the same way you would any other PDF
25
+ * download — the viewer is a pure renderer and trusts the host to
26
+ * enforce access control upstream.
27
+ *
28
+ * @public
29
+ */
30
+ import type { PdfFallbackAdapter } from "../plugin/services";
31
+ /**
32
+ * Default URL for the pdf.js worker, served via unpkg pinned to the
33
+ * exact `pdfjs-dist` version this package was built against. Hosts
34
+ * that don't want a runtime CDN dep can override via the
35
+ * `workerSrc` option, set `pdfjs.GlobalWorkerOptions.workerSrc`
36
+ * directly before constructing the adapter, or self-host the file.
37
+ *
38
+ * @public
39
+ */
40
+ export declare const defaultPdfWorkerSrc: string;
41
+ interface PdfJsFallbackOptions {
42
+ /** Raw PDF URL. Must be reachable from the user's browser. */
43
+ pdfUrl: string;
44
+ /**
45
+ * Optional override for the pdf.js worker URL. Default:
46
+ * {@link defaultPdfWorkerSrc}, an unpkg URL pinned to the bundled
47
+ * pdfjs-dist version.
48
+ */
49
+ workerSrc?: string;
50
+ }
51
+ /**
52
+ * Build a {@link PdfFallbackAdapter} backed by pdf.js. The returned
53
+ * adapter caches the parsed document and per-page rasters so
54
+ * repeated calls don't re-parse or re-render.
55
+ *
56
+ * @public
57
+ */
58
+ export declare function createPdfJsFallback(opts: PdfJsFallbackOptions): PdfFallbackAdapter;
59
+ export {};
60
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../fallback-pdfjs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,QAA2E,CAAC;AAE5G,UAAU,oBAAoB;IAC5B,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,GAAG,kBAAkB,CA2HlF"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * `@printwithsynergy/lens-pdf/fallback-pdfjs`
3
+ *
4
+ * In-browser PDF fallback adapter built on pdf.js. Provides "minimum
5
+ * data" (page count, dimensions, page rasters, OCG layers, RGB color
6
+ * sampling) for the fallback-capable tools when a host hasn't wired
7
+ * richer services.
8
+ *
9
+ * Distinct from the deprecated `createPdfJsFallback` re-export in
10
+ * `/host`: this subpath imports `pdfjs-dist` statically, so bundlers
11
+ * trace it correctly without the host having to side-effect-import
12
+ * the dep themselves. Hosts that never use the fallback never import
13
+ * this subpath and never pay the bundle cost.
14
+ *
15
+ * ```ts
16
+ * import { createPdfJsFallback } from "@printwithsynergy/lens-pdf/fallback-pdfjs";
17
+ * const fallback = createPdfJsFallback({ pdfUrl: "/proofs/abc.pdf" });
18
+ * ```
19
+ *
20
+ * Usually you don't import this directly — `<LensPDFViewer>` uses
21
+ * it internally and is the one-liner most hosts want.
22
+ *
23
+ * **Security**: this adapter fetches whatever URL the host hands it.
24
+ * Sign / scope / expire the URL the same way you would any other PDF
25
+ * download — the viewer is a pure renderer and trusts the host to
26
+ * enforce access control upstream.
27
+ *
28
+ * @public
29
+ */
30
+ import * as pdfjs from "pdfjs-dist";
31
+ /**
32
+ * Default URL for the pdf.js worker, served via unpkg pinned to the
33
+ * exact `pdfjs-dist` version this package was built against. Hosts
34
+ * that don't want a runtime CDN dep can override via the
35
+ * `workerSrc` option, set `pdfjs.GlobalWorkerOptions.workerSrc`
36
+ * directly before constructing the adapter, or self-host the file.
37
+ *
38
+ * @public
39
+ */
40
+ export const defaultPdfWorkerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
41
+ const sampleCanvases = new Map();
42
+ /**
43
+ * Build a {@link PdfFallbackAdapter} backed by pdf.js. The returned
44
+ * adapter caches the parsed document and per-page rasters so
45
+ * repeated calls don't re-parse or re-render.
46
+ *
47
+ * @public
48
+ */
49
+ export function createPdfJsFallback(opts) {
50
+ // Configure the worker once. Idempotent — repeated calls with the
51
+ // same value are no-ops.
52
+ const workerSrc = opts.workerSrc ?? defaultPdfWorkerSrc;
53
+ if (pdfjs.GlobalWorkerOptions.workerSrc !== workerSrc) {
54
+ pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
55
+ }
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ let docPromise = null;
58
+ const renderCache = new Map();
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ async function getDoc() {
61
+ if (!docPromise) {
62
+ docPromise = pdfjs.getDocument({ url: opts.pdfUrl }).promise;
63
+ }
64
+ return docPromise;
65
+ }
66
+ return {
67
+ async getPageCount() {
68
+ const doc = await getDoc();
69
+ return doc.numPages;
70
+ },
71
+ async getPageDimensions(pageNum) {
72
+ const doc = await getDoc();
73
+ const page = await doc.getPage(pageNum);
74
+ const viewport = page.getViewport({ scale: 1 });
75
+ return { widthPts: viewport.width, heightPts: viewport.height };
76
+ },
77
+ async renderPageToUrl({ pageNum, dpi }) {
78
+ const cacheKey = `${pageNum}@${dpi}`;
79
+ const cached = renderCache.get(cacheKey);
80
+ if (cached)
81
+ return cached;
82
+ const doc = await getDoc();
83
+ const page = await doc.getPage(pageNum);
84
+ const scale = dpi / 72;
85
+ const viewport = page.getViewport({ scale });
86
+ const canvas = document.createElement("canvas");
87
+ canvas.width = Math.ceil(viewport.width);
88
+ canvas.height = Math.ceil(viewport.height);
89
+ const ctx = canvas.getContext("2d");
90
+ if (!ctx)
91
+ throw new Error("[lens-pdf] 2D context unavailable for fallback render.");
92
+ await page.render({ canvasContext: ctx, viewport }).promise;
93
+ const url = canvas.toDataURL("image/png");
94
+ renderCache.set(cacheKey, url);
95
+ return url;
96
+ },
97
+ async listLayers() {
98
+ const doc = await getDoc();
99
+ // pdf.js exposes OCGs through the OptionalContentConfig. Older
100
+ // versions / RGB-only PDFs simply have no groups → empty list.
101
+ let config;
102
+ try {
103
+ config = await doc.getOptionalContentConfig();
104
+ }
105
+ catch {
106
+ return [];
107
+ }
108
+ const groups = (config?.getGroups?.() ?? {});
109
+ const ids = Object.keys(groups);
110
+ return ids.map((id, index) => ({
111
+ name: groups[id]?.name ?? `Layer ${index + 1}`,
112
+ ocg_index: index,
113
+ default_on: config.isVisible(id) ?? true,
114
+ }));
115
+ },
116
+ async sampleColorAt({ pageNum, pdfX, pdfY, dpi = 150 }) {
117
+ const doc = await getDoc();
118
+ const page = await doc.getPage(pageNum);
119
+ const ptsToPx = dpi / 72;
120
+ const viewport = page.getViewport({ scale: ptsToPx });
121
+ // Render the whole page once per (page, dpi) and cache the
122
+ // canvas — repeated sampling is then a single getImageData call.
123
+ const canvasKey = `${pageNum}@${dpi}`;
124
+ let canvas = sampleCanvases.get(canvasKey);
125
+ if (!canvas) {
126
+ canvas = document.createElement("canvas");
127
+ canvas.width = Math.ceil(viewport.width);
128
+ canvas.height = Math.ceil(viewport.height);
129
+ const renderCtx = canvas.getContext("2d", { willReadFrequently: true });
130
+ if (!renderCtx)
131
+ return null;
132
+ await page.render({ canvasContext: renderCtx, viewport }).promise;
133
+ sampleCanvases.set(canvasKey, canvas);
134
+ }
135
+ // pdfX/pdfY use PDF-point coords with origin lower-left; canvas
136
+ // pixels use origin upper-left.
137
+ const pageHeightPts = viewport.height / ptsToPx;
138
+ const pxX = Math.max(0, Math.min(canvas.width - 1, Math.round(pdfX * ptsToPx)));
139
+ const pxY = Math.max(0, Math.min(canvas.height - 1, Math.round((pageHeightPts - pdfY) * ptsToPx)));
140
+ const ctx = canvas.getContext("2d");
141
+ if (!ctx)
142
+ return null;
143
+ const data = ctx.getImageData(pxX, pxY, 1, 1).data;
144
+ const r = data[0] ?? 0;
145
+ const g = data[1] ?? 0;
146
+ const b = data[2] ?? 0;
147
+ const hex = "#" +
148
+ [r, g, b]
149
+ .map((v) => v.toString(16).padStart(2, "0"))
150
+ .join("");
151
+ const sample = {
152
+ x: pdfX,
153
+ y: pdfY,
154
+ rgb: [r, g, b],
155
+ hex,
156
+ // pdf.js renders to RGB only — no real ink coverage available.
157
+ tac: null,
158
+ };
159
+ return sample;
160
+ },
161
+ };
162
+ }
163
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../fallback-pdfjs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAIpC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,gCAAgC,KAAK,CAAC,OAAO,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,IAAI,CAAC,CAAC;YACvB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACvB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACvB,MAAM,GAAG,GACP,GAAG;gBACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;qBACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;qBAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;YACd,MAAM,MAAM,GAAgB;gBAC1B,CAAC,EAAE,IAAI;gBACP,CAAC,EAAE,IAAI;gBACP,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gBACd,GAAG;gBACH,+DAA+D;gBAC/D,GAAG,EAAE,IAAI;aACV,CAAC;YACF,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * `<LensPDFProvider>` — thin context wrapper that mounts both
3
+ * `ViewerHostContext` and `ViewerServicesContext` from a
4
+ * {@link UseLensPDFReturn} value.
5
+ *
6
+ * Pair with {@link useLensPDF} for the "full custom" tier:
7
+ *
8
+ * ```tsx
9
+ * const viewer = useLensPDF(url, { tokens });
10
+ * return (
11
+ * <LensPDFProvider value={viewer}>
12
+ * <MyCustomShell>
13
+ * <PageCanvas ... />
14
+ * </MyCustomShell>
15
+ * </LensPDFProvider>
16
+ * );
17
+ * ```
18
+ *
19
+ * @public
20
+ */
21
+ import type { ReactNode } from "react";
22
+ import type { UseLensPDFReturn } from "./useLensPDF";
23
+ /** Props for {@link LensPDFProvider}. */
24
+ export interface LensPDFProviderProps {
25
+ /** The return value from {@link useLensPDF}. */
26
+ value: UseLensPDFReturn;
27
+ children: ReactNode;
28
+ }
29
+ /**
30
+ * Mounts both `ViewerHostContext` and `ViewerServicesContext` from a
31
+ * `useLensPDF()` return value.
32
+ *
33
+ * @public
34
+ */
35
+ export declare function LensPDFProvider({ value, children }: LensPDFProviderProps): import("react/jsx-runtime").JSX.Element;
36
+ //# sourceMappingURL=LensPDFProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LensPDFProvider.d.ts","sourceRoot":"","sources":["../../host/LensPDFProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,oBAAoB,2CAQxE"}
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ViewerHostContext, ViewerServicesContext } from "./index.js";
3
+ /**
4
+ * Mounts both `ViewerHostContext` and `ViewerServicesContext` from a
5
+ * `useLensPDF()` return value.
6
+ *
7
+ * @public
8
+ */
9
+ export function LensPDFProvider({ value, children }) {
10
+ return (_jsx(ViewerHostContext.Provider, { value: value.hostValue, children: _jsx(ViewerServicesContext.Provider, { value: value.servicesValue, children: children }) }));
11
+ }
12
+ //# sourceMappingURL=LensPDFProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LensPDFProvider.js","sourceRoot":"","sources":["../../host/LensPDFProvider.tsx"],"names":[],"mappings":";AAsBA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAUnE;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAwB;IACvE,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,SAAS,YAChD,KAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,aAAa,YACvD,QAAQ,GACsB,GACN,CAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Viewer host context — the bridge between an embedding application
3
+ * and the core viewer components. Two contexts live here:
4
+ *
5
+ * - {@link ViewerHostContext}: cross-cutting host config (API base
6
+ * paths, read-only flag, debug toggle, optional pdf.js fallback).
7
+ * - {@link ViewerServicesContext}: the {@link ViewerServices} object
8
+ * carrying all the data-source protocols (page images, layers,
9
+ * separations, annotations, etc.). Components read services via
10
+ * {@link useViewerServices}; components decide between wired,
11
+ * fallback, and hidden render modes via {@link useFallbackMode}.
12
+ *
13
+ * Hosts mount a `<ViewerHostContext.Provider>` at the root of their
14
+ * app and supply concrete values; the no-op defaults exported below
15
+ * keep an unwired viewer renderable but quiet.
16
+ *
17
+ * @public
18
+ */
19
+ import type { PdfFallbackAdapter, ViewerServices } from "../plugin/services";
20
+ /**
21
+ * Values the host application supplies to the viewer's core
22
+ * components. Cross-cutting toggles, base API paths, and the
23
+ * optional PDF fallback adapter live here; per-feature data sources
24
+ * are on {@link ViewerServices}.
25
+ *
26
+ * @public
27
+ */
28
+ export interface ViewerHostContextValue {
29
+ /**
30
+ * Base path for viewer API calls (no trailing slash). The viewer
31
+ * itself never builds URLs from this — it's plumbed through for
32
+ * host-side service implementations that want a single source of
33
+ * truth (e.g. a host's `getPageImageUrl` returning
34
+ * ``${apiBase}/page/${n}.png``). Leave empty if your services
35
+ * compose URLs differently.
36
+ */
37
+ apiBase: string;
38
+ /**
39
+ * Base path for job-level API calls (findings, reports, etc.).
40
+ * Same plumbing convention as {@link apiBase}.
41
+ */
42
+ jobApiBase: string;
43
+ /**
44
+ * When true, hides write-only UI (annotations, verdict, comparison
45
+ * initiation). Public-token / share-link viewers run with this on.
46
+ */
47
+ readOnly: boolean;
48
+ /**
49
+ * When true, components log a one-shot ``console.info`` whenever
50
+ * they self-hide because their backing service is unwired. Off by
51
+ * default so production embeds stay quiet. Hosts typically derive
52
+ * this from an environment flag (``import.meta.env.DEV``,
53
+ * ``process.env.NODE_ENV !== "production"``, etc.).
54
+ */
55
+ debug?: boolean;
56
+ /**
57
+ * Optional URL to the raw PDF file. Consumed by the pdf.js fallback
58
+ * adapter (see ``createPdfJsFallback``) and by base components when
59
+ * no service is wired.
60
+ *
61
+ * **Security**: this is a pure renderer. Whatever URL the host puts
62
+ * here is fetched by the user's browser as-is — sign it, scope it,
63
+ * and expire it like any other PDF download link. Never point this
64
+ * at an unauthenticated path that exposes documents the viewer's
65
+ * user shouldn't see.
66
+ */
67
+ pdfUrl?: string;
68
+ /**
69
+ * Optional in-browser fallback adapter used when a richer service
70
+ * is unwired. See {@link PdfFallbackAdapter}. Hosts that don't set
71
+ * this get hide-on-unwired behaviour for every fallback-capable
72
+ * tool; hosts that set it (e.g. via ``createPdfJsFallback``) get
73
+ * graceful degradation instead.
74
+ */
75
+ pdfFallback?: PdfFallbackAdapter;
76
+ }
77
+ /**
78
+ * React context object. Default value is intentionally empty so a
79
+ * misconfigured viewer renders nothing surprising — components that
80
+ * read `apiBase` should treat the empty string as "no host wired up".
81
+ *
82
+ * @public
83
+ */
84
+ export declare const ViewerHostContext: import("react").Context<ViewerHostContextValue>;
85
+ /**
86
+ * Hook for reading the current `ViewerHostContextValue`. Returns the
87
+ * default empty values when no provider is mounted.
88
+ *
89
+ * @public
90
+ */
91
+ export declare function useViewerHost(): ViewerHostContextValue;
92
+ /**
93
+ * No-op default services. URL builders return empty strings; the
94
+ * other protocols are filled with the no-op stubs already defined
95
+ * in `core/plugin/services`. Hosts that supply a partial
96
+ * `ViewerServices` in their provider override only the fields they
97
+ * actually have.
98
+ *
99
+ * Choosing empty-string for URL builders (rather than throwing)
100
+ * keeps the boundary forgiving — a misconfigured viewer renders
101
+ * blank tiles, but doesn't crash.
102
+ */
103
+ declare const defaultViewerServices: ViewerServices;
104
+ /**
105
+ * React context carrying the active `ViewerServices` instance.
106
+ * `<ViewerServicesContext.Provider value={...}>` mounts a host's
107
+ * concrete implementation; downstream plugin packs typically expose
108
+ * a factory like `createMyHostViewerServices(...)` that returns one.
109
+ *
110
+ * @public
111
+ */
112
+ export declare const ViewerServicesContext: import("react").Context<ViewerServices>;
113
+ /**
114
+ * Hook for reading the active `ViewerServices`. Returns the no-op
115
+ * defaults when no provider is mounted.
116
+ *
117
+ * @public
118
+ */
119
+ export declare function useViewerServices(): ViewerServices;
120
+ /**
121
+ * One-shot ``console.info`` for components that self-hide because
122
+ * their backing service is unwired. Silent unless ``host.debug`` is
123
+ * on, and deduped per-component-name so a thousand re-renders don't
124
+ * spam the console.
125
+ *
126
+ * @public
127
+ */
128
+ export declare function logUnwiredHide(componentName: string, serviceName: string): void;
129
+ /**
130
+ * Helper hook used by fallback-capable components. Returns a stable
131
+ * tuple describing how the component should render its data source:
132
+ *
133
+ * - ``mode: "wired"`` — host provided the dedicated service; use it.
134
+ * - ``mode: "fallback"`` — service unwired but ``pdfFallback`` is
135
+ * present; use the fallback adapter.
136
+ * - ``mode: "hidden"`` — neither is available; render ``null``.
137
+ *
138
+ * Components are responsible for calling {@link logUnwiredHide} from
139
+ * an effect when they choose to hide; this hook deliberately doesn't
140
+ * log on its own so callers control the message.
141
+ *
142
+ * @public
143
+ */
144
+ export declare function useFallbackMode(service: object | null | undefined): "wired" | "fallback" | "hidden";
145
+ /**
146
+ * Pre-built services where every protocol is a no-op default tagged
147
+ * with the unwired marker. Hosts that only need a partial override
148
+ * can spread this and replace the fields they've wired:
149
+ *
150
+ * ```ts
151
+ * const services = { ...defaultUnwiredServices, pageImages: myPageImages };
152
+ * ```
153
+ *
154
+ * @public
155
+ */
156
+ export { defaultViewerServices as defaultUnwiredServices };
157
+ export { createPdfJsFallback } from "./pdfFallback";
158
+ export { isUnwired, markUnwired } from "../plugin/services";
159
+ export { validatePdfFile, validatePdfUrl } from "./pdfValidation";
160
+ export type { PdfValidationResult } from "./pdfValidation";
161
+ export { generateShareLink, parseShareParams } from "./shareLink";
162
+ export type { ShareLinkOptions, ParsedShareParams } from "./shareLink";
163
+ export { useLensPDF } from "./useLensPDF";
164
+ export type { UseLensPDFOptions, UseLensPDFReturn } from "./useLensPDF";
165
+ export { LensPDFProvider } from "./LensPDFProvider";
166
+ export type { LensPDFProviderProps } from "./LensPDFProvider";
167
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../host/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAS7E;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,iDAI5B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,sBAAsB,CAEtD;AAMD;;;;;;;;;;GAUG;AACH,QAAA,MAAM,qBAAqB,EAAE,cAoC5B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,yCAEjC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAElD;AAQD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAS/E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACjC,OAAO,GAAG,UAAU,GAAG,QAAQ,CAKjC;AAED;;;;;;;;;;GAUG;AACH,OAAO,EAAE,qBAAqB,IAAI,sBAAsB,EAAE,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAClE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAClE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Viewer host context — the bridge between an embedding application
3
+ * and the core viewer components. Two contexts live here:
4
+ *
5
+ * - {@link ViewerHostContext}: cross-cutting host config (API base
6
+ * paths, read-only flag, debug toggle, optional pdf.js fallback).
7
+ * - {@link ViewerServicesContext}: the {@link ViewerServices} object
8
+ * carrying all the data-source protocols (page images, layers,
9
+ * separations, annotations, etc.). Components read services via
10
+ * {@link useViewerServices}; components decide between wired,
11
+ * fallback, and hidden render modes via {@link useFallbackMode}.
12
+ *
13
+ * Hosts mount a `<ViewerHostContext.Provider>` at the root of their
14
+ * app and supply concrete values; the no-op defaults exported below
15
+ * keep an unwired viewer renderable but quiet.
16
+ *
17
+ * @public
18
+ */
19
+ import { createContext, useContext } from "react";
20
+ import { defaultThemeTokens, isUnwired, markUnwired, noopI18n, noopTelemetry, } from "../plugin/services.js";
21
+ /**
22
+ * React context object. Default value is intentionally empty so a
23
+ * misconfigured viewer renders nothing surprising — components that
24
+ * read `apiBase` should treat the empty string as "no host wired up".
25
+ *
26
+ * @public
27
+ */
28
+ export const ViewerHostContext = createContext({
29
+ apiBase: "",
30
+ jobApiBase: "",
31
+ readOnly: false,
32
+ });
33
+ /**
34
+ * Hook for reading the current `ViewerHostContextValue`. Returns the
35
+ * default empty values when no provider is mounted.
36
+ *
37
+ * @public
38
+ */
39
+ export function useViewerHost() {
40
+ return useContext(ViewerHostContext);
41
+ }
42
+ // ---------------------------------------------------------------------------
43
+ // ViewerServices context
44
+ // ---------------------------------------------------------------------------
45
+ /**
46
+ * No-op default services. URL builders return empty strings; the
47
+ * other protocols are filled with the no-op stubs already defined
48
+ * in `core/plugin/services`. Hosts that supply a partial
49
+ * `ViewerServices` in their provider override only the fields they
50
+ * actually have.
51
+ *
52
+ * Choosing empty-string for URL builders (rather than throwing)
53
+ * keeps the boundary forgiving — a misconfigured viewer renders
54
+ * blank tiles, but doesn't crash.
55
+ */
56
+ const defaultViewerServices = {
57
+ pageImages: markUnwired({
58
+ getPageImageUrl: () => "",
59
+ }),
60
+ layers: markUnwired({
61
+ getLayerImageUrl: () => "",
62
+ listLayers: async () => [],
63
+ }),
64
+ separations: markUnwired({
65
+ getChannelImageUrl: () => "",
66
+ }),
67
+ tacHeatmap: markUnwired({
68
+ getHeatmapImageUrl: () => "",
69
+ listRuns: async () => [],
70
+ }),
71
+ colorSample: markUnwired({
72
+ sampleAt: async () => null,
73
+ }),
74
+ densitometer: markUnwired({
75
+ sampleAt: async () => {
76
+ throw new Error("No separations available for this page.");
77
+ },
78
+ }),
79
+ annotations: markUnwired({
80
+ list: async () => [],
81
+ getForPage: async () => null,
82
+ saveForPage: async () => { },
83
+ remove: async () => { },
84
+ }),
85
+ reports: markUnwired({
86
+ getHtmlReportUrl: () => "",
87
+ getPdfDownloadUrl: () => "",
88
+ }),
89
+ telemetry: noopTelemetry,
90
+ i18n: noopI18n,
91
+ tokens: defaultThemeTokens,
92
+ };
93
+ /**
94
+ * React context carrying the active `ViewerServices` instance.
95
+ * `<ViewerServicesContext.Provider value={...}>` mounts a host's
96
+ * concrete implementation; downstream plugin packs typically expose
97
+ * a factory like `createMyHostViewerServices(...)` that returns one.
98
+ *
99
+ * @public
100
+ */
101
+ export const ViewerServicesContext = createContext(defaultViewerServices);
102
+ /**
103
+ * Hook for reading the active `ViewerServices`. Returns the no-op
104
+ * defaults when no provider is mounted.
105
+ *
106
+ * @public
107
+ */
108
+ export function useViewerServices() {
109
+ return useContext(ViewerServicesContext);
110
+ }
111
+ // ---------------------------------------------------------------------------
112
+ // Debug logging
113
+ // ---------------------------------------------------------------------------
114
+ const loggedHideOnce = new Set();
115
+ /**
116
+ * One-shot ``console.info`` for components that self-hide because
117
+ * their backing service is unwired. Silent unless ``host.debug`` is
118
+ * on, and deduped per-component-name so a thousand re-renders don't
119
+ * spam the console.
120
+ *
121
+ * @public
122
+ */
123
+ export function logUnwiredHide(componentName, serviceName) {
124
+ const key = `${componentName}:${serviceName}`;
125
+ if (loggedHideOnce.has(key))
126
+ return;
127
+ loggedHideOnce.add(key);
128
+ // eslint-disable-next-line no-console
129
+ console.info(`[lens-pdf] ${componentName} hidden — host did not wire \`services.${serviceName}\`. ` +
130
+ `Provide an implementation, or set \`pdfFallback\` on the host context to use the in-browser PDF fallback.`);
131
+ }
132
+ /**
133
+ * Helper hook used by fallback-capable components. Returns a stable
134
+ * tuple describing how the component should render its data source:
135
+ *
136
+ * - ``mode: "wired"`` — host provided the dedicated service; use it.
137
+ * - ``mode: "fallback"`` — service unwired but ``pdfFallback`` is
138
+ * present; use the fallback adapter.
139
+ * - ``mode: "hidden"`` — neither is available; render ``null``.
140
+ *
141
+ * Components are responsible for calling {@link logUnwiredHide} from
142
+ * an effect when they choose to hide; this hook deliberately doesn't
143
+ * log on its own so callers control the message.
144
+ *
145
+ * @public
146
+ */
147
+ export function useFallbackMode(service) {
148
+ const { pdfFallback } = useViewerHost();
149
+ if (!isUnwired(service))
150
+ return "wired";
151
+ if (pdfFallback)
152
+ return "fallback";
153
+ return "hidden";
154
+ }
155
+ /**
156
+ * Pre-built services where every protocol is a no-op default tagged
157
+ * with the unwired marker. Hosts that only need a partial override
158
+ * can spread this and replace the fields they've wired:
159
+ *
160
+ * ```ts
161
+ * const services = { ...defaultUnwiredServices, pageImages: myPageImages };
162
+ * ```
163
+ *
164
+ * @public
165
+ */
166
+ export { defaultViewerServices as defaultUnwiredServices };
167
+ export { createPdfJsFallback } from "./pdfFallback.js";
168
+ export { isUnwired, markUnwired } from "../plugin/services.js";
169
+ export { validatePdfFile, validatePdfUrl } from "./pdfValidation.js";
170
+ export { generateShareLink, parseShareParams } from "./shareLink.js";
171
+ export { useLensPDF } from "./useLensPDF.js";
172
+ export { LensPDFProvider } from "./LensPDFProvider.js";
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../host/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,QAAQ,EACR,aAAa,GACd,MAAM,oBAAoB,CAAC;AA4D5B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAyB;IACrE,OAAO,EAAE,EAAE;IACX,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE,KAAK;CAChB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,UAAU,CAAC,iBAAiB,CAAC,C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