@@ -15,6 +15,7 @@ import { downloadFile } from "../lib/utils/download";
1515import { Button } from "./ui/button" ;
1616import ShareButton from "./ShareButton" ;
1717import ReportButton from "./ReportButton" ;
18+ import { useTheme } from "next-themes" ;
1819
1920interface ControlProps {
2021 documentId : string ;
@@ -29,6 +30,12 @@ interface ControlProps {
2930interface PdfViewerProps {
3031 url : string ;
3132 name : string ;
33+ className ?: string ;
34+ height ?: string ;
35+ hideControls ?: boolean ;
36+ backgroundColor ?: string ;
37+ hideScrollbar ?: boolean ;
38+ isolateFromTheme ?: boolean ;
3239}
3340
3441interface WheelZoomProps {
@@ -328,25 +335,48 @@ const LOADING_MESSAGES = [
328335 "Almost there" ,
329336] ;
330337
331- export function Loader ( ) {
338+ export function Loader ( {
339+ backgroundColor = "#070114" ,
340+ textColor = "rgba(255,255,255,0.5)" ,
341+ } : {
342+ backgroundColor ?: string ;
343+ textColor ?: string ;
344+ } ) {
332345 const { message, visible } = useLoadingMessage ( LOADING_MESSAGES ) ;
333346 return (
334- < div className = "flex flex-col items-center justify-center gap-3 h-dvh w-full bg-[#070114]" >
347+ < div
348+ className = "flex h-dvh w-full flex-col items-center justify-center gap-3"
349+ style = { { backgroundColor } }
350+ >
335351 < div className = "w-7 h-7 rounded-full border-2 border-white/10 border-t-white animate-spin" />
336352 < span
337- className = "text-white/50 text- sm tracking-wide transition-opacity duration-400"
338- style = { { opacity : visible ? 1 : 0 } }
353+ className = "text-sm tracking-wide transition-opacity duration-400"
354+ style = { { opacity : visible ? 1 : 0 , color : textColor } }
339355 >
340356 { message }
341357 </ span >
342358 </ div >
343359 ) ;
344360}
345- export default function PDFViewer ( { url, name } : PdfViewerProps ) {
361+ export default function PDFViewer ( {
362+ url,
363+ name,
364+ className,
365+ height = "100dvh" ,
366+ hideControls = false ,
367+ backgroundColor,
368+ hideScrollbar = false ,
369+ isolateFromTheme = true ,
370+ } : PdfViewerProps ) {
346371 const { engine, isLoading } = usePdfiumEngine ( ) ;
347- const { isMobile, isSmall} = useBreakpoint ( ) ;
372+ const { isMobile, isSmall } = useBreakpoint ( ) ;
373+ const { resolvedTheme } = useTheme ( ) ;
348374 const [ isFullscreen , setIsFullscreen ] = useState ( false ) ;
349375 const viewerRef = useRef < HTMLDivElement > ( null ) ;
376+ const effectiveBackgroundColor =
377+ backgroundColor ?? ( resolvedTheme === "light" ? "#F3F5FF" : "#070114" ) ;
378+ const loaderTextColor =
379+ resolvedTheme === "light" ? "rgba(17,24,39,0.6)" : "rgba(255,255,255,0.5)" ;
350380
351381 const handleDownload = useCallback ( async ( ) => {
352382 window . dataLayer ?. push ( {
@@ -389,21 +419,67 @@ export default function PDFViewer({ url, name }: PdfViewerProps) {
389419
390420if ( isLoading || ! engine ) {
391421 return (
392- < Loader />
422+ < Loader
423+ backgroundColor = { effectiveBackgroundColor }
424+ textColor = { loaderTextColor }
425+ />
393426 ) ;
394427}
395428
396429 return (
397- < div
398- ref = { viewerRef }
399- style = { { height : "100dvh" , width : "100%" , position : "relative" , backgroundColor : "#070114" , display : "flex" , flexDirection : "column" } }
400- >
401- < EmbedPDF engine = { engine } plugins = { plugins } >
430+ < >
431+ { hideScrollbar && (
432+ < style jsx global > { `
433+ [data-pdf-viewer-scrollbars="hidden"] *,
434+ [data-pdf-viewer-scrollbars="hidden"] {
435+ scrollbar-width: none;
436+ -ms-overflow-style: none;
437+ }
438+
439+ [data-pdf-viewer-scrollbars="hidden"] ::-webkit-scrollbar {
440+ display: none;
441+ width: 0;
442+ height: 0;
443+ }
444+ ` } </ style >
445+ ) }
446+ { isolateFromTheme && (
447+ < style jsx global > { `
448+ [data-pdf-viewer-theme="light"] {
449+ color-scheme: light;
450+ forced-color-adjust: none;
451+ }
452+
453+ [data-pdf-viewer-theme="light"] canvas,
454+ [data-pdf-viewer-theme="light"] img,
455+ [data-pdf-viewer-theme="light"] svg {
456+ filter: none !important;
457+ forced-color-adjust: none;
458+ }
459+ ` } </ style >
460+ ) }
461+ < div
462+ ref = { viewerRef }
463+ data-pdf-viewer-theme = { isolateFromTheme ? "light" : "inherited" }
464+ data-pdf-viewer-scrollbars = { hideScrollbar ? "hidden" : "visible" }
465+ className = { className }
466+ style = { {
467+ height,
468+ width : "100%" ,
469+ position : "relative" ,
470+ backgroundColor : effectiveBackgroundColor ,
471+ display : "flex" ,
472+ flexDirection : "column" ,
473+ colorScheme : isolateFromTheme ? "light" : undefined ,
474+ forcedColorAdjust : isolateFromTheme ? "none" : undefined ,
475+ } }
476+ >
477+ < EmbedPDF engine = { engine } plugins = { plugins } >
402478 { ( { activeDocumentId } ) =>
403479 activeDocumentId && (
404480 < >
405481 < WheelZoom documentId = { activeDocumentId } viewerRef = { viewerRef } />
406- { ( isMobile && ! isFullscreen ) &&
482+ { ! hideControls && ( isMobile && ! isFullscreen ) &&
407483 < Controls
408484 documentId = { activeDocumentId }
409485 toggleFullscreen = { toggleFullscreen }
@@ -421,19 +497,29 @@ if (isLoading || !engine) {
421497 style = { {
422498 opacity : isLoaded ? 0 : 1 ,
423499 pointerEvents : isLoaded ? "none" : "auto" ,
424- transition : "opacity 0.3s"
500+ transition : "opacity 0.3s" ,
501+ backgroundColor : effectiveBackgroundColor ,
425502 } }
426503 >
427- < Loader />
504+ < Loader
505+ backgroundColor = { effectiveBackgroundColor }
506+ textColor = { loaderTextColor }
507+ />
428508 </ div >
429509 < Viewport
430510 documentId = { activeDocumentId }
431- style = { { backgroundColor : "#070114" , visibility : isLoaded ? "visible" : "hidden" } }
511+ style = { {
512+ backgroundColor : effectiveBackgroundColor ,
513+ visibility : isLoaded ? "visible" : "hidden" ,
514+ } }
432515 >
433516 < Scroller
434517 documentId = { activeDocumentId }
435518 renderPage = { ( { width, height, pageIndex } ) => (
436- < div style = { { width, height } } >
519+ < div
520+ style = { { width, height } }
521+ onClick = { ( e ) => e . stopPropagation ( ) }
522+ >
437523 < RenderLayer documentId = { activeDocumentId } pageIndex = { pageIndex } />
438524 </ div >
439525 ) }
@@ -443,7 +529,7 @@ if (isLoading || !engine) {
443529 ) }
444530</ DocumentContent >
445531
446- { ( ! isMobile || isFullscreen ) && (
532+ { ! hideControls && ( ! isMobile || isFullscreen ) && (
447533 < Controls
448534 documentId = { activeDocumentId }
449535 toggleFullscreen = { toggleFullscreen }
@@ -457,7 +543,8 @@ if (isLoading || !engine) {
457543 </ >
458544 )
459545 }
460- </ EmbedPDF >
461- </ div >
546+ </ EmbedPDF >
547+ </ div >
548+ </ >
462549 ) ;
463- }
550+ }
0 commit comments