seemore 1.8.2 → 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 +22 -6
- package/src/app/styles/globals.css +16 -1
package/package.json
CHANGED
package/src/app/mdx/Pdf.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useEffect, useState, type ComponentProps } from 'react';
|
|
2
2
|
import { FileText } from 'lucide-react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -10,14 +10,30 @@ import { FileText } from 'lucide-react';
|
|
|
10
10
|
* on a `<span>` gets the same layout with none of that.
|
|
11
11
|
*
|
|
12
12
|
* `pdfjs-dist` is roughly a megabyte, which is a poor trade for a docs site. The accepted
|
|
13
|
-
* cost is that
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `(pointer: coarse)`
|
|
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 the VS Code extension's webview, whose
|
|
15
|
+
* bundled Electron/Chromium doesn't ship Chrome's PDF viewer extension despite reporting a
|
|
16
|
+
* fine pointer. The CSS `(pointer: coarse)` fallback in globals.css only catches the first
|
|
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.
|
|
17
23
|
*/
|
|
18
24
|
export function Pdf({ src, title, ...props }: ComponentProps<'embed'> & { src: string }) {
|
|
25
|
+
const [unsupported, setUnsupported] = useState(false);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const noPdfViewerApi = 'pdfViewerEnabled' in navigator && !navigator.pdfViewerEnabled;
|
|
29
|
+
const embeddedWebview = window.parent !== window;
|
|
30
|
+
if (noPdfViewerApi || embeddedWebview) {
|
|
31
|
+
setUnsupported(true);
|
|
32
|
+
}
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
19
35
|
return (
|
|
20
|
-
<span className=
|
|
36
|
+
<span className={unsupported ? 'seemore-pdf seemore-pdf-unsupported' : 'seemore-pdf'}>
|
|
21
37
|
<embed src={src} type="application/pdf" title={title} {...props} />
|
|
22
38
|
<a className="seemore-pdf-fallback" href={src} download>
|
|
23
39
|
<FileText className="seemore-pdf-fallback-icon" aria-hidden="true" />
|
|
@@ -438,7 +438,10 @@
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
/* Most touch browsers can't render `<embed type="application/pdf">` at all, so the box
|
|
441
|
-
above sits blank. Hide it there and promote the download link into the primary UI.
|
|
441
|
+
above sits blank. Hide it there and promote the download link into the primary UI.
|
|
442
|
+
`.seemore-pdf-unsupported` is the same fallback, applied via JS (see Pdf.tsx) for
|
|
443
|
+
environments — Electron webviews included — that fail the same way despite a fine
|
|
444
|
+
pointer, so both selectors share these rules. */
|
|
442
445
|
@media (pointer: coarse) {
|
|
443
446
|
.seemore-pdf embed {
|
|
444
447
|
@apply hidden;
|
|
@@ -452,6 +455,18 @@
|
|
|
452
455
|
@apply size-6;
|
|
453
456
|
}
|
|
454
457
|
}
|
|
458
|
+
|
|
459
|
+
.seemore-pdf-unsupported embed {
|
|
460
|
+
@apply hidden;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
.seemore-pdf-unsupported .seemore-pdf-fallback {
|
|
464
|
+
@apply mt-0 flex-col items-start gap-1 rounded-lg border border-fd-border bg-fd-card px-4 py-4 hover:border-fd-primary/60;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
.seemore-pdf-unsupported .seemore-pdf-fallback-icon {
|
|
468
|
+
@apply size-6;
|
|
469
|
+
}
|
|
455
470
|
}
|
|
456
471
|
|
|
457
472
|
/* Unlayered, deliberately: fumadocs' `max-h-[460px]` utility lives in Tailwind's utilities
|