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

@svgaplus/core

v2.0.2

Published

Enhanced SVGA Player.

Downloads

11

Readme

SVGAPlus

npm version SVGAPlus

logo

Enhanced SVGA Player for Web.

Feature

  • Vanilla canvas drawing by default, no 3rd-part rendering libs included.
  • Pixi.js renderer available.
  • Provide more useful information and more customizable options, such as adjustable framerate.
  • No strange resizing behavior, act like a HTML image.
  • Better API design for playing control.

Quick Start

import { SVGAPlus } from 'svgaplus'

async function main () {
  // Load SVGA file into array buffer.
  const buffer = await SVGAPlus.loadSvgaFile('/your-svga-file-url.svga')

  // Or you can just prepare a copy of arary buffer.
  const buffer = new ArrayBuffer(...)
  
  // Create SVGAPlus.
  const sprite = new SVGAPlus({
    element: document.querySelector('#my-svga-canvas') as HTMLCanvasElement,
    buffer
  })

  // Initialize SVGAPlus instance.
  await sprite.init()

  // Feel free to add a listener.
  sprite.onPlay(() => {
    console.log('current frame:', sprite.frame)
  })

  // Play whole animation in loop.
  sprite.play()

  // Play frame 1 - 5 in loop.
  sprite.play(0, 4)  

  // Play frame 1 - 15 once.
  await sprite.playOnce(0, 14)

  // Reverse frame 10 to 1.
  await sprite.playOnce(9, 0)
}

Initialize several SVGAs

Initialize several SVGAs will cause some performance problem usually.

Avoid doing other works during SVGA initialization as far as you can.

Let's see this shit here:

const list = [
  { url: './static/background.svga', element: '#background' },
  { url: './static/hex.svga', element: '#hex' },
  { url: './static/explosion.svga', element: '#explosion' },
  { url: './static/22.svga', element: '#sprite-22' },
  { url: './static/22-text.svga', element: '#text-22' },
  { url: './static/33.svga', element: '#sprite-33' },
  { url: './static/33-text.svga', element: '#text-33' }
]

This is the most efficient way as far as I know:

// Load all SVGA files into buffers.
const buffers = await Promise.all(
  // You can use SVGAPlus.loadSvgaFile or your own function.
  list.map(item => SVGAPlus.loadSvgaFile(item.url))
)

// Transform buffers into SVGAPlus.
const svgas = await Promise.all(buffers.map((buffer, index) => {
  const element = list[index].element
  return new SVGAPlus({
    element: document.querySelector(element) as HTMLCanvasElement,
    buffer: new Uint8Array(buffer)
  })
}))

// Parsing.
await Promise.all(svgas.map(item => item.init()))

// Play.
svgas.forEach(item => item.play())

Compatibility

It should support browsers those have canvas such like IE11+.

Adjustable frame rate

Set fpsOverride: number to achieve customized framerate. However it probably won't reach that kind of speed such as 999.

Use PIXI.js

Check out the documentation for PixiRenderer.

API

Package Exports

  • SVGAPlus: SVGAPlus
  • SVGAParser: SVGAParser

SVGAPlus

SVGAPlus Props

  • readonly isInPlay: boolean
  • readonly fps: number
  • readonly frame: number
  • readonly frameCount: number
  • readonly maxFrame: number
  • readonly fpsOverride: number

SVGAPlus Methods

  • init: () => Promise<void>
  • play: (from?: number, to?: number) => void
  • playOnce: (from: number, to: number) => Promise<void>
  • pause: () => void
  • stop: (stopAt?: number) => void
  • seek: (frame: number) => void
  • onPlay: (handler: () => void) => void
  • offOnPlay: (handler: () => void) => void
  • destroy: () => void

SVGAPlus Static Methods

  • loadSvgaFile: (url: string) => Promise<ArrayBuffer>

SVGAPlus Constructor

constructor: (param: ISVGAPlus)

interface ISVGAPlus {
  element: HTMLCanvasElement
  buffer: ArrayBuffer
  fpsOverride?: number
  renderer?: typeof SVGAPlusRenderer
}

SVGAParser

SVGAParser Static Methods

  • parse: (svgaBuffer: ArrayBuffer) => Promise<IProtoMovieEntity>

Renderer

SVGAPlusRenderer

class SVGAPlusRenderer {
  startTick: () => void
  stopTick: () => void
  tickFrame: (param?: ISVGAPlusRendererTickFrameParam) => void
  destroy: () => void
}

interface ISVGAPlusRendererTickFrameParam {
  forceTick?: boolean
}