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

fast-image-viewer

v0.0.3

Published

Viewer optimized to use huge Image files

Downloads

9

Readme

Fast Image Viewer Build Status

Fast Image Viewer (FIV) allows you to Render Really big big, huge, files into a canvas and manipulate those images as if they were a Visualization tool in browser, all of this, simply embeded into any DOM Element.

FIV was mainly created to render Huge SVG files, and navigate them in a browser, at 60fps, always keeping a low (RAM/VRAM) memory footprint.

Under the hood, fast image viewer, uses WebGL. It creates a Grid of the original image and renders it into several Quads. FIV will smartly identify the size of the current device and start with a texture matching the highest dimension between the width and the height (or the closest power of two dimension). As you get closer to the Image, FIV will start subdividing the Grid into smaller pieces, while doubling the size of each Quadrant into the GRID to keep a low memory footprint, but a high resolution.

How to Install

npm install fast-image-viewer

How to Implement

FIV provides you with the base Handler which runs the Image (PNG, PDF, SVG, etc) lifecycle. The Handler will first create a Canvas as a container used to Generate each of the GRIDS, and then call the load function which will, as defined for the implementer, load the resources into the class. Once the file has been loaded (Sync), the draw function will be called. The draw function is in charge of drawing to the Canvas the desired resources. After draw function exit, the Canvas should contain the final image that will then, be displayed into the viewer.

class SVGHandler extends FastSvgViewer.Handler {

            /**
             * [load description]
             * @return {Promise} [description]
             */
            load (BASE_URL) {
                let request = new XMLHttpRequest();
                let $this = this;

                request.open('GET', BASE_URL, false);
                request.send(null);

                const documentFragment = document.createDocumentFragment();
                const div = document.createElement('div');
                documentFragment.appendChild(div);
                div.innerHTML = request.responseText;
                $this.viewBox = div
                    .getElementsByTagName('svg')[0]
                    .getAttribute('viewBox')
                    .split(' ')
                    .map(Number);

                const paths = div.getElementsByTagName('path');
                $this.data = [];
                for (let i = 0; i < paths.length; i++) {
                    $this.data[i] = {
                        path: new Path2D(paths[i].getAttribute('d')),
                        fill: paths[i].getAttribute('fill')
                    }
                }
            }

            /**
             * [Draw imageData]
             * @return {Promise}
             */
            draw () {
                this.context.lineWidth = 20;
                this.context.strokeStyle = "#444";

                for (let i = 0; i < this.data.length; i++) {
                    this.context.fillStyle = this.data[i].fill;
                    this.context.fill(this.data[i].path);
                }
            }

            /**
             * [Clear all references]
             * @return {[type]} [description]
             */
            clear () {
                super.clear();
                this.data = null;
            }

        }

        FastSvgViewer.register({
            'svg': SVGHandler
        });

        const div = document.getElementById('viewer-container');
        const instance = new FastSvgViewer.default(div, 'assets/icon-github.svg');

Base Handler

class Handler {

    /**
     * Receives a URL
     * Creates the main canvas
     * Calls the load function defined by the implementer
     * Calls the draw function defined by the implementer
     * If you extend the constructor remember to call super
     */
    constructor (url) {}

	// YOU SHOULD NOT USE THIS FUNCTION
    /**
     * Creates a canvas with the active Size
     * Size should not be modified directly by the implementer
     */
    __createCanvas () {}

	// YOU SHOULD NOT USE THIS FUNCTION
    /**
     * Deletes the current instance of the canvas
     */
    __deleteCanvas () {}

	// YOU SHOULD NOT USE THIS FUNCTION
    /**
     * Resize the current canvas to the desired size
     * @param  {[int]} scale [size]
     */
    __resize (scale) {}

	// YOU SHOULD NOT USE THIS FUNCTION
    /**
     * Get a square from the canvas matching the provided coordinates
     * @param  {Number} x [coordinate x of canvas slice to redraw]
     * @param  {Number} y [coordinate y of canvas slice to redraw]
     * @return {ImageData}  [New ImageData from canvas slice]
     */
    __getAt (x, y) {}

	// YOU SHOULD NOT USE THIS FUNCTION
    /**
     * Returns the transparency map of the current canvas
     * @return {ImageData} [New ImageData from canvas slice]
     * @private
     */
    __getTransparencyMap () {}

    /**
     * This function should be extended by the implementer
     * Beeing in charge of loading all the necesary resources
     * To display the image in the viewer
     */
    load (BASE_URL) {}

    /**
     * This method should be extended by the implementer
     * Beeing in charge of defining a way of drawing the
     * Resources into the Canvas
     */
    draw () {}

    /**
     * This Function should be extended by the implementer
     * Beeing in charge of calling the super.clear() method
     * and clearing all of the resources loaded in the load()
     * function or any other defined function
     */
    clear () {}

}