Skip to Content
Liquid Glass UI
Blocks

File Preview

Preview almost any file in the browser — images, video, PDF, Office, archives, e-mail, CAD, 3D models, maps and code — with a Liquid Glass toolbar and an all-viewer dialog. Every format library loads on demand.

FilePreview is a block (registry:block) built on open-file-viewer:

  • Formats: images (incl. HEIC, PSD, TIFF), video (incl. HLS), audio, PDF, Word / Excel / PowerPoint, OFD, EPUB, XPS, archives (ZIP and friends), e-mail (.eml / .msg), drawings (draw.io, Visio, EMF), XMind, CAD (DWG / DXF), 3D models, GIS data (GeoJSON, KML, GPX), Markdown and source code. Anything else, or any file that fails, shows a download card.
  • Dynamic imports all the way down: the viewer itself is a React.lazy chunk fetched the first time a preview renders, and each format's library (pdf.js, mammoth, the PPTX renderer, the CAD engine…) is a further import() fetched only when a file of that format opens. A page that shows only PDFs never downloads the Office or CAD code. This works unchanged with output: 'export': dynamic imports are split into static chunks at build time.
  • Liquid Glass surface: inline, the viewer is a glass panel like Card (medium material); document pages stay paper-white and the glass shows around them. glass={false} renders it 100% opaque.
  • Liquid Glass toolbar: previous / next, zoom, rotate, text search with a match count, download and print, drawn from the viewer's state — controls a format doesn't support are hidden.
  • PreviewDialog: a dialog that is all viewer. Maximize and close are the last toolbar buttons; maximize fills the viewport, also on iPhone where the Fullscreen API is unavailable.
apple-liquid-ui/preview/file-preview-demo
MacBook · 16:10

Supported formats

Built on @open-file-viewer/core with 6 major format families and 110+ extensions — every format parser loads lazily on demand:

PDF / Office

22

Business documents

pdfdocdocxdocmdotdotxdotmrtfodtxlsxlsxxlsmxlsbodscsvtsvpptxpptmodpofdepubxps

Image / Media

21

Native and enhanced

FLV and M2TS require optional mpegts.js in the host app; otherwise a download fallback is shown.

jpgjpegpnggifwebpavifjxlsvgbmpicoheicheifmp4webmm3u8flvm2tsmp3wavflacmidi

Text / Code

26

Highlight and editor mode

txtmdjsonjsoncjson5ipynbyamltomliniprotohcltexgvhttpjstsvuereactcsshtmlpygorsrbswiftkt

Engineering

24

Engineering, layout and structure

dxfdwgstepifcgdsgdsiioasoasisgltfglbobjstlfbxdae3mfusdzgeojsonkmlkmzgpxshpdrawioexcalidrawxmind

Archive / Email

11

Structure, body and attachments

ziprar7ztargztgzbz2xzemlmsgmbox

Assets / Data

12

Structure parsing and safe summaries

ttfotfwoffwoff2psdaiepssqlitewasmparquetavrowebarchive

Installation (Shadcn Registry)

npx shadcn@latest add @apple-liquid/file-preview

Next.js setup

pdfjs-dist installs @napi-rs/canvas (a native Node addon) as an optional dependency, and the EMF / WMF converter imports it as a Node-only fallback. Point it at the bundled stub so it stays out of the browser bundle:

next.config.mjs
const config = {
  turbopack: {
    resolveAlias: {
      '@napi-rs/canvas': './components/blocks/file-preview/browser-canvas.ts',
    },
  },
};

With webpack, use webpack: (config) => { config.resolve.alias['@napi-rs/canvas'] = false; return config; } instead. Vite and other bundlers need the same alias.

In a dialog

apple-liquid-ui/preview/preview-dialog-demo
MacBook · 16:10
'use client';

import * as React from 'react';
import { FilePreview, PreviewDialog } from '@/components/blocks/file-preview';

export function Attachment({ url, name, mimeType }: { url: string; name: string; mimeType: string }) {
  const [open, setOpen] = React.useState(false);
  return (
    <>
      <button onClick={() => setOpen(true)}>{name}</button>
      <PreviewDialog open={open} onOpenChange={setOpen} title={name}>
        <FilePreview bare source={url} name={name} mimeType={mimeType} />
      </PreviewDialog>
    </>
  );
}

Sources and CORS

  • source accepts http(s):, blob: and same-origin paths; any other scheme is refused, even as a download link.
  • Files on another origin (object storage, a CDN) must send Access-Control-Allow-Origin for your site. When a request fails the preview shows the download card and calls onError; pass notice to PreviewDialog to offer a "Refresh link" action for expiring signed URLs.
  • A local File works through URL.createObjectURL(file) (remember to revoke it).

Leaving formats out

All plugins are registered by default. excludePlugins drops format families — they fall back to the download card:

<FilePreview source={url} name={name} mimeType={mimeType} excludePlugins={['cad', 'model3d', 'gis']} />

Plugin names: image, video, audio, pdf, office, ofd, epub, xps, archive, email, drawing, xmind, cad, model3d, gis, asset, text, fallback.

Excluded plugins never load their libraries, but the plugin code itself stays in the viewer chunk. For full control, build your own list with open-file-viewer's plugin factories and pass it as plugins — create it once at module level, since a new array recreates the viewer.

Externally hosted assets

Two assets come from jsDelivr by default so that nothing has to be copied into public/:

  • pdf.js worker — pdfjs-dist@<version>/build/pdf.worker.mjs.
  • CAD (LibreDWG WASM + worker) — @mlightcad/libredwg-web@0.7.4. Self-host it with cadAssets={{ wasmBaseUrl, workerModuleUrl }}.

Props API

FilePreview

PropTypeDefaultDescription
sourcestring—http(s):, blob: or same-origin path
namestring—File name; shown in the fallback, helps detect the format
mimeTypestring—MIME type of the file
onError(error: Error) => void—Load error, 120 s timeout or unsupported format
excludePluginsFilePreviewPluginName[][]Format families to leave out
cadAssets{ wasmBaseUrl, workerModuleUrl }jsDelivrLibreDWG assets for the CAD plugin
pluginsPreviewPlugin[]allReplaces the plugin list (advanced)
viewerLocale'zh-CN' | 'en-US'from <html lang>Language of the viewer's own panels
barebooleanfalseBorderless and filling its parent (inside PreviewDialog)
glassbooleantrueLiquid Glass surface (medium material, like Card) and toolbar; glass={false} is 100% opaque. Document pages stay white
localeLiquidGlassLocaleInputGlobal localeUI language of this instance; overrides <LiquidGlassProvider locale>
messagesPartial<FilePreviewMessages>Built-in textText overrides, deep-merged over the built-in text and the global messages.filePreview

PreviewDialog

PropTypeDefaultDescription
open / onOpenChangeboolean / (open) => void—Controlled open state
titleReactNode—For screen readers only
noticeReactNode—Shown under the viewer, e.g. a "Refresh link" action
glassbooleantrueGlass dialog surface; glass={false} is 100% opaque
childrenReactNode—Usually <FilePreview bare … />

On this page