seemore 1.8.3 → 1.8.4
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/package.json +1 -1
- package/src/app/mdx/Pdf.tsx +11 -5
package/package.json
CHANGED
package/src/app/mdx/Pdf.tsx
CHANGED
|
@@ -11,17 +11,23 @@ import { FileText } from 'lucide-react';
|
|
|
11
11
|
*
|
|
12
12
|
* `pdfjs-dist` is roughly a megabyte, which is a poor trade for a docs site. The accepted
|
|
13
13
|
* cost is that some environments degrade `<embed>` to a blank box, since they don't support
|
|
14
|
-
* inline PDF plugins — most mobile browsers, but also
|
|
15
|
-
*
|
|
14
|
+
* inline PDF plugins — most mobile browsers, but also the VS Code extension's webview, whose
|
|
15
|
+
* bundled Electron/Chromium doesn't ship Chrome's PDF viewer extension despite reporting a
|
|
16
16
|
* fine pointer. The CSS `(pointer: coarse)` fallback in globals.css only catches the first
|
|
17
|
-
* group
|
|
18
|
-
* to catch the second
|
|
17
|
+
* group. `navigator.pdfViewerEnabled` (Chromium/Firefox's direct feature check) would be the
|
|
18
|
+
* clean way to catch the second, but the Electron build VS Code ships predates that API, so
|
|
19
|
+
* `'pdfViewerEnabled' in navigator` is false there too and never flips it. Instead this reuses
|
|
20
|
+
* the same signal `ExternalLinkBridge.ts` uses for the identical webview: the site only ever
|
|
21
|
+
* runs inside a nested, cross-origin iframe when the VS Code extension put it there (see
|
|
22
|
+
* `panelHtml.ts`), so `window.parent !== window` is a reliable stand-in.
|
|
19
23
|
*/
|
|
20
24
|
export function Pdf({ src, title, ...props }: ComponentProps<'embed'> & { src: string }) {
|
|
21
25
|
const [unsupported, setUnsupported] = useState(false);
|
|
22
26
|
|
|
23
27
|
useEffect(() => {
|
|
24
|
-
|
|
28
|
+
const noPdfViewerApi = 'pdfViewerEnabled' in navigator && !navigator.pdfViewerEnabled;
|
|
29
|
+
const embeddedWebview = window.parent !== window;
|
|
30
|
+
if (noPdfViewerApi || embeddedWebview) {
|
|
25
31
|
setUnsupported(true);
|
|
26
32
|
}
|
|
27
33
|
}, []);
|