Binary Viewer

Binary content viewer web component: images with their size, PDFs in the browser's PDF viewer, and a hex dump with a Download button for anything else.

  • 7.4 KB gzipped
  • @lit-material/binary-viewer 1.8.0
  • Renders on the server

Example

Install

npm install @lit-material/binary-viewer @lit-material/tokens
import "@lit-material/binary-viewer";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-binary-viewer>

Shows binary content, like a response body or an uploaded file, by its content type:

Properties

PropertyAttributeTypeDefaultDescription
dataproperty onlyBinaryData | nullnullThe content: bytes or a Blob. Property only.
contentTypecontent-typestring""Its content type, e.g. image/png (parameters such as ; charset are ignored). Default: a Blob's own type.
filenamefilenamestring""The file name Download saves as, and the name the views use.
maxBytesmax-bytesnumber4096How many bytes the hex dump shows (rounded up to whole rows of 16).
typeproperty onlystringnoneThe content type in use: content-type, else a Blob's own type.
viewproperty onlyBinaryViewnoneThe view the content gets.

Events

EventDescription
downloadDownload was pressed; detail: {blob, filename}, cancelable.

CSS parts

PartDescription
factsThe line saying what the content is, with the Download button.
imageThe <img>.
frameThe PDF viewer (<object>).
dumpThe hex dump's scrolling box.

CSS custom properties

PropertyDescription
--lit-material-binary-viewer-max-heightThe tallest the image, frame or hex dump gets (default 480px).

Source on GitHub npm