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

@weareglow/story-unit

v0.0.4

Published

Downloads

3

Readme

Story Unit

An Instagram Story inspired component.

Usage

Add your markup. Start by creating a single element which will contain each chapter of your story. A chapter can be a video element or an image element. Make to include the appropriate video attribtues on your video elements. When using an image element, specify how long the image should be displayed with the data-duration attribute on your img element. Defaults to 1 second. See Below.

<div id="chapters">
  <video muted playsinline src="video.mp4"></video>
  <img data-duration="2" src="image.jpg" alt="" />
  <video muted playsinline src="video.mp4"></video>
  <video muted playsinline src="video.mp4" type="video/mp4"></video>
</div>

Now initialize your story by providing it with an options object.

var story = Story({
  el: '#chapters',
  animate: false // defaults to true. set to false if you want to handle chapter animations yourself.
})

Your story will now have a few methods you can call to get things rolling.

| Method | Description | | ------ | :-------------------------: | | play | begins the story | | end | jumps to end of story | | replay | starts story from beginning |

Now you probably want to know when the story's state changes, right? Get notified of story updates by subscribing to the following events:

| Event | Description | Payload | | ------------ | :-----------------------------------------------: | :-----------------: | | start | fires when the story begins playing. | {current, previous} | | update | fires when the story's active chapter changes. | {current, previous} | | last-chapter | fires at the start of the last chapter | {current, previous} | | end | fires when the entire story has completed. | {current, previous} | | skip-to-end | fires when the user skips to the end of the story | {current, previous} |

Event payloads

Each emitted event will send a payload that includes an object with current and previous properties. The current and previous properties each respectively have a ref property which is the DOM element of that chapter. This is useful if you want to handle animations on your own.

So lets subscribe to some events!


story.on('start', function(payload) {
 // payload.current.ref
 // payload.previous.ref
}

story.on('update', function(payload) {
 // payload.current.ref
 // payload.previous.ref
}

story.on('last-chapter', function(payload) {
 // payload.current.ref
 // payload.previous.ref
}

story.on('end', function(payload) {
 // payload.current.ref
 // payload.previous.ref
}

story.on('skip-to-end', function(payload) {
 // payload.current.ref
 // payload.previous.ref
}

So you've subscribed to some events...nice! How about allowing a user to initiate some actions themselves like, replaying the story, or skipping to the end? Easy!

var replayBtn = document.getElementById('replay-btn')
var skipBtn = document.getElementById('skip-btn')

replayBtn.addEventListener('click', story.replay.bind(story)) // notice we're binding our this context to the story, important!

skipBtn.addEventListener('click', story.end.bind(story))

You'll notice we have to bind our DOM event listeners this context to the story like story.replay.bind(this). This is important, as if you don't, the story won't have access to it's methods and properties.

FINALLY. Play the story!

story.play()