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

360-image-viewer

v1.0.1

Published

A standalone panorama WebGL image viewer for desktop and mobile. This uses [regl](https://www.npmjs.com/package/regl) as the WebGL wrapper, and comes in at a total of 140kb uglified, or 46kb gzipped. This is useful if you need a panorama viewer but don't

Downloads

1,590

Readme

360-image-viewer

A standalone panorama WebGL image viewer for desktop and mobile. This uses regl as the WebGL wrapper, and comes in at a total of 140kb uglified, or 46kb gzipped. This is useful if you need a panorama viewer but don't want to embed all of ThreeJS (which is around 500kb uglified).

Install

npm install 360-image-viewer --save

Live Demo

Click here to see a demo of this module in action. The source code is in demo/index.js.

Example

The code below sets up a full-screen 360 image viewer. For a more complete example, see demo/index.js.

const create360Viewer = require('360-image-viewer');
const canvasFit = require('canvas-fit');

// load your image
const image = new Image();
image.src = 'panosphere.jpg';

image.onload = () => {
  // when the image is loaded, setup the viewer
  const viewer = create360Viewer({
    image: image
  });

  // attach canvas to body
  document.body.appendChild(viewer.canvas);

  // setup fullscreen canvas sizing
  const fit = canvasFit(viewer.canvas, window, window.devicePixelRatio);
  window.addEventListener('resize', fit, false);
  fit();

  // start the render loop
  viewer.start();
};

Usage

viewer = create360Viewer([opt])

Creates and returns a new WebGL canvas viewer with the specified opt options object.

Options:

  • image — the HTMLImageElement, if not specified it can be set later
  • canvas — a <canvas> tag to use, otherwise creates a new one
  • fov — a field of view, in radians, defaults to 45 degrees
  • rotateSpeed — a scalar for the drag rotation speed, default 0.15
  • damping — a scalar for damping/spring, default 0.275
  • clearColor — a RGBA clear color, default [ 0, 0, 0, 0 ] (ie. transparent)

You can also pass orbit-controls options, for example phi as the initial rotation, or passing { rotate: fale } to ignore mouse/touch rotation.

The image should be a DOM Image or Video element, and should already be loaded.

viewer.start()

Start the requestAnimationFrame render loop.

viewer.stop()

Stop the requestAnimationFrame render loop.

viewer.render()

Render a single frame. This may be useful if, say, you change the canvas size when the requestAnimationFrame is not running.

viewer.enableControls()

Enable the input controls, attaching mouse/touch events to the canvas. Has no effect if the controls are already enabled.

viewer.disableControls()

Disable the input controls, detaching mouse/touch events from the canvas. Has no effect if the controls are already disabled.

viewer.texture(image)

Changes the current image to the specified DOM image. This can be an image, video, or an options object for regl#texture(). By default, min and mag filter will use 'linear' for smoother filtering.

viewer.destroy()

Stop the render loop, disable the input controls, and destroy the WebGL context. The viewer will no longer be usable after this point.

viewer.canvas

The canvas the viewer will render into.

viewer.fov

The current field of view of the perspective camera in radians. Can be altered at run-time.

viewer.phi

The current horizontal rotation angle in radians.

viewer.theta

The current vertical rotation angle in radians.

viewer.on('tick', fn)

Attach a frame listener to the viewer, where fn accepts the dt (delta time) parameter per frame. You can remove this with viewer.removeListener('tick', fn).

License

MIT, see LICENSE.md for details.