npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pdf.svelte

v0.5.4

Published

pdf.js in a fancy Svelte wrapper

Downloads

213

Readme

pdf.svelte

The problem: native PDF viewers are great, but they sometimes have subtle bugs which make cross-platform sites unreliable.

The solution: pdf.js wrapped in a component to abstract away all the low-level setup.

Getting Started

Installation

Using NPM:

npm install pdf.svelte

Usage

<script>
  import PDFViewer from 'pdf.svelte';

  // Required - the URL of your PDF, {data: pdfContents}, an ArrayBuffer or TypedArray (like Uint8Array), or a pdfjs DocumentInitParameters
  // This is passed straight to pdfjs.getDocument
  const pdf = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf";

  // These classes are set on the various elements
  const classes = {
    overall: null,
    controls: null,
    container: null
  };

  const options = {
    // paged - display a single page with controls
    // all - display all pages
    display: "paged",
    // dark - grey on darkgrey
    // light - grey on lightgrey
    // your own theme name - whatever you like
    theme: "dark",
    // allow double click/tap to zoom between 1 and 1.5x
    autoZoomEnabled: false,
    // baseline superscale resolution to render
    // larger means better zoom, but slower rendering
    upscale: 8,
    // horizontal - fit width
    // vertical - fit height
    // both - fit the smaller of width and height
    fit: "both"
  };

  // Control over the zoom level of the document
  // Zoom is > 0 and represents the zoom level (1 = 100% etc)
  // zoomIn and zoomOut move zoom through the following levels:
  // [0.1, 0.25, 0.5, 0.66, 0.8, 0.9, 1, 1.2, 1.5, 2, 3, 4, 5]
  // If zoom is between two levels, it will align to the nearest:
  // zoom >= 1 and < 2 will zoom in to 1.2
  // zoom > 1 and <= 2 will zoom out to 1
  let zoom = 1, zoomIn, zoomOut;

  // The current page number
  let currentPage;

  // To override the text between the forward and back buttons
  const pageNumberText = (currentPage, totalPages) => `${currentPage}/${totalPages}`;

  // To set your own theme colours without writing your own theme
  const borderColor = "grey";
  const backgroundColor = "darkgrey";
</script>

<PDFViewer {pdf} {classes} {options} {zoom} bind:zoomIn bind:zoomOut {pageNumberText} bind:currentPage --border-color={borderColor} --background-color={backgroundColor}></PDFViewer>

Theming

Just Border/Background

<script>
  const borderColor = "green";
  const backgroundColor = "red";
</script>
<PDFViewer --border-color={borderColor} --background-color={backgroundColor}>

Fully Custom

If we want to make a theme called wacky:

const options = {
  theme: "wacky"
};
.pdf-svelte.theme-wacky {
  /* The main window */
  --border-color: green;
  --background-color: red;
  /* existing styles: */
  position: relative;
  z-index: 1;
  overflow-y: auto;
  height: 100%;
  width: 100%;
}

.pdf-svelte.theme-wacky .viewer {
  /* The container for the pdf.js canvas(es) */
  /* existing style: */
  position: relative;
  z-index: 1;
  overflow-y: auto;
  height: 100%;
  width: 100%;
}

.pdf-svelte.theme-wacky .viewer canvas {
  /* The pdf.js canvas(es) */
  /* existing style: */
  display: block;
  margin: 0 auto;
  border: 1px solid var(--border-color);
}

.pdf-svelte.theme-wacky .controls {
  /* If you use the paged display mode, this is the controls */
  /* existing style: */
  position: absolute;
  width: 100%;
  bottom: 0;
  text-align: center;
  z-index: 2;
  border-radius: 50%;
}