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

flipbook-viewer

v1.6.1

Published

Amazing Page Flip Animation for a (PDF/Image Collection) Flipbook viewer

Downloads

172

Readme

Flipbook Viewer

Amazing flip book component with animated pages.

demo

This is a tiny library that can show flip books from any source (including PDF’s, images, etc).

Advantages

  1. Tiny (18 Kb). For comparison, the amazing page-flip is 10 Mb (x1000 times bigger!).
  2. Can use any input as a book simply by plugging in a “book provider”. An example PDF book using the amazing pdfjs from Mozilla can be found in the test folder—book-pdf.js (referenced usage: test-pdf.js)
  3. Supports Panning, Zooming, Liking, Sharing, along with page turning effects.
  4. Raises events to track which pages are being viewed by user.

Usage

Below shows the flip book on the given div with the id div-id:

'use strict'

import { init as flipbook } from 'flipbook-viewer';

...

flipbook(book, 'div-id', (err, viewer) => {
  if(err) console.error(err);

  console.log('Number of pages: ' + viewer.page_count);
  viewer.on('seen', n => console.log('page number: ' + n));

  next.onclick = () => viewer.flip_forward();
  prev.onclick = () => viewer.flip_back();
  zoom.onclick = () => viewer.zoom();

});

The viewer can show any flip book. All you need to do is provide a book interface:

{
  numPages: () => {
    /* return number of pages */
  },
  getPage: (num, cb) => {
    /* return page number 'num'
     * in the callback 'cb'
     * as any CanvasImageSource:
     * (CSSImageValue, HTMLImageElement, 
     *  SVGImageElement, HTMLVideoElement,
     *  HTMLCanvasElement, ImageBitmap,
     *  OffscreenCanvas)
     */
  }
}

Options

An optional opts parameter can be passed in to change the UI:

const opts = {
  backgroundColor: "#353535",
  boxColor: "#353535",
  width: 800,
  height: 600,
}

flipbook(book, 'div-id', opts, (err, viewer) => ...

Events

You can listen on the viewer for which pages were seen:

viewer.on('seen', n => ...)

Programmatic API

The returned viewer can be used to programmatically control the viewer:

viewer.flip_forward()
viewer.flip_back()
viewer.zoom()

Single Page View

Finally, sometimes it makes sense to just show the book as a simple, scrollable view. To pass in only a singlepage:true option:

flipbook(book, 'div-id', {singlepage:true}, (err, viewer) => ...

This will generate a series of canvases with class="flipbook__page" and id="flipbook__pgnum_<n>" that you can style using CSS. The single page view will raise the same seen event that the flipbook viewer does for tracking which pages the user actually flips through.

The single page viewer is currently experimental and very simple. It should work for many PDF's but is not optimized for handling PDF's with a large number of pages.

Enjoy!