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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fiveid/scenes

v0.0.4

Published

Minimalist scene switching with vanilla JS

Readme

Scenes

Minimalist scene-switcher module in vanilla JS.

Basic usage

Scenes toggles the active classname of elements. In the simple example below, clicking the "Next" or "Previous" buttons will switch visibility between the two scenes.

  • index.html
<div class="scene active">
  <p>This is scene 1</p>
  <button class="scene__next">Next</button>
</div>
<div class="scene">
  <p>This is scene 2</p>
  <button class="scene__prev">Previous</button>
</div>
  • style.css
.scene {
  display: none;
}

.scene {
  display: block;
}
  • main.js
import { Scenes } from "@fiveid/scenes";

const scenes = new Scenes();

Options

Customise Scenes behaviour by passing an options object on initialisation.

| Option key | Description | | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- | | selectors | An object containing the DOM selectors that trigger certain actions (see below) | | activeClass | The classname that designates a scene element as "active" (default: active) | | dataKey | The HTML data attribute used to identify which scene index to set as active, in JS format (default: sceneIndex) | | initialIndex | The index of the active scene on load (default: 0) | | preTransition | A function that is called before changing active state. This can be used to alter the next active scene (see full example below) | | postTransition | A function that is called after changing active state (see full example below) |

Selectors

Override default DOM selectors in options.

State changes are triggered when users click on DOM elements. The selectors that trigger these actions can be configured (or you can keep the default values).

| Key | Description | Default | | ----- | ------------------------------------------------------------------------------------------------ | --------------- | | scene | The element that will be set as active or not | .scene | | next | Sets the subsequent adjacent scene element to active | .scene__next | | prev | Sets the previous adjacent scene element to active | .scene_prev | | reset | Sets the scene element at the initial index to active | .scene__reset | | goto | Goes to a scene element at an index specified by a HTML data attribute (e.g. data-scene-index) | .scene__goto | | pop | Sets the previously active scene element as active | .scene__pop |

Example custom selectors:

const mySelectors = {
  scene: ".block",
  next: ".block__next",
  prev: ".block__prev",
  reset: ".block__reset",
  goto: ".block__goto",
  pop: ".block__pop"
};

Pre-transition

You can trigger a side effect or alter the typical state change behaviour by passing a function to the preTransition option.

The function has three parameters:

  • state: an object containing currentIndex and nextIndex
  • callback: a function that needs to be called to trigger the state change. You can optionally pass a nextIndex value to the callback to determine which scene will next be set as active
  • event: if the transition was triggered by a JS event, the event object will be passed to the preTransition function

Example:

const preTransition = (state, callback, event) => {
  if (
    state.nextIndex === RESTRICTED_SCENE &&
    userIsAllowedRestrictedScene === false
  ) {
    return callback(state.currentIndex);
  }

  callback();
};

Post-transition

You can trigger a side effect after changing active state by passing a function to the postTransition option.

The function has two parameters:

  • state: an object containing currentIndex and prevIndex
  • event: if the transition was triggered by a JS event, the event object will be passed to the preTransition function

Example:

const postTransition = (state, event) => {
  lazyLoadContentOfActiveScene(state.currentIndex);
  disableMediaContentOfPreviousScene(state.prevIndex);
};

Instance properties and methods

Some potentially useful instance methods and properties are exposed.

activeIndex

The index of the currently active scene.

Returns:

  • : number

transitionTo

A function that sets the scene at index as active. (Note: calling transitionTo will still trigger the preTransition and postTransition functions).

Parameters:

  • index: number - the target scene index (default: 0)

Example:

const scenes = new Scenes();

fetchDataFromSomewhere().then(done => {
  if (done.ok) {
    scenes.transitionTo(1); // success scene
  } else {
    scenes.transitionTo(2); // error scene
  }
});