seemore 1.8.2 → 1.8.3
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 +16 -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,24 @@ 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 Electron-based webviews (VS Code's
|
|
15
|
+
* preview included), which don'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, so `navigator.pdfViewerEnabled` — Chromium/Firefox's direct feature check — is used
|
|
18
|
+
* to catch the second by toggling the same fallback via a class instead of a media query.
|
|
17
19
|
*/
|
|
18
20
|
export function Pdf({ src, title, ...props }: ComponentProps<'embed'> & { src: string }) {
|
|
21
|
+
const [unsupported, setUnsupported] = useState(false);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if ('pdfViewerEnabled' in navigator && !navigator.pdfViewerEnabled) {
|
|
25
|
+
setUnsupported(true);
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
19
29
|
return (
|
|
20
|
-
<span className=
|
|
30
|
+
<span className={unsupported ? 'seemore-pdf seemore-pdf-unsupported' : 'seemore-pdf'}>
|
|
21
31
|
<embed src={src} type="application/pdf" title={title} {...props} />
|
|
22
32
|
<a className="seemore-pdf-fallback" href={src} download>
|
|
23
33
|
<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
|