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

@aerofoil/rive-solid-canvas

v2.1.4

Published

unofficial solidjs wrapper around the rive-js library

Downloads

43

Readme

Rive-Solid-Canvas

npm version Known Vulnerabilities

This is an unofficial wrapper of the Rive Canvas Runtime for SolidJS. Syntactically it is designed to be similar to the official Rive Runtime for React; that being said it is not a 1 to 1 match. See the comparison section for more details.

  1. Getting Started
  2. Advanced Usage
  3. Documentation
  4. Comparison

Getting Started

  1. Install the dependency.
npm install @aerofoil/rive-solid-canvas
  1. Render a Rive component.

Rive-Solid-Canvas provides a basic component just like the official Rive React library. Just like the official library this is designed to be a simple usecase for simple animations.

import Rive from "@aerofoil/rive-solid-canvas";

export default function Simple() {
	return <Rive src="https://cdn.rive.app/animations/vehicles.riv" />;
}

Advanced Usage

More advanced cases should use createRive to create a custom component. This allows for more control over the animation, canvas, and underlying rive object.

import { createRive } from "@aerofoil/rive-solid-canvas";

export default function Advanced() {
	const { rive, RiveComponent } = createRive(() => ({
		src: "https://cdn.rive.app/animations/vehicles.riv",
		autoplay: false,
	}));

	return (
		<div
			onMouseEnter={() => rive() && rive().play()}
			onMouseLeave={() => rive() && rive().pause()}
		>
			<RiveComponent width="1000" height="500" />
		</div>
	);
}

Just like the official Rive React library, the createRive function will run once the dom is rendered as the the underlying <canvas> element needs to be present in the DOM.

Documentation

<Rive /> Component (Default Export)

A simple component for render simple rive animations on a canvas. In practice this is just a wrapper around createRive.

Props

  • src: string - the src of the rive file to load
  • artboard?: string - the name of the artboard to use
  • animations?: string | string[] - the name or list of names of animations to play
  • statateMachines?: string | string[] - the name or list of names of state machines to play
  • layout?: Layout - the layout object defining how animations are positioned on the canvas. see the official rive documentation for more info.
  • useOffscreenRenderer?: boolean - whether to use the offscreen renderer. see the official rive documentation for more info.
  • canvas props - any other props will be passed to the underlying <canvas> element

The typescript prop type for this component can be imported using

import type { RiveProps } from "@aerofoil/rive-solid-canvas";

createRive()

This function takes a single argument, a solidjs accessor returning all the RiveParameters from the official web rive library with the exception of canvas which is created and managed internally.

For convenience the type CreateRiveParameters and can be imported using

import type { CreateRiveParameters } from "@aerofoil/rive-solid-canvas";

The return value is an object with the following properties canvas - an accessor to the ref of the internal canvas element rive - an accessor to the rive object RiveComponent - a component that renders and manages the canvas element. Can use all the same props as the default <canvas> element, with the exception of ref.

createRiveInput()

This function is used to quickly get a rive input given the rive accessor generated by createRive.

Arguments

  • rive: rive accessor - the rive accessor generated by createRive
  • stateMachineName: string - the name of the state machine to get the input for
  • inputName: string - the name of the input to get

Returns an accessor to the StateMachineInput object. This accessor can be used to set the value of the input.

createRiveInputMap()

This function is used to quickly get a map of all rive inputs for a given state machine.

Arguments

  • rive: rive accessor - the rive accessor generated by createRive
  • stateMachineName: string - the name of the state machine to get the input for

Returns an accessor for a map with the keys being the input names and the values being the input accessors.

Comparison

| Name | Rive-Solid-Canvas | Official Rive React | | -------------------------------- | ----------------- | ------------------- | | Simple Component | ✅ | ✅ | | Advanced Usage | ✅ | ✅ | | StateMachine Input Accessor | ✅ | ✅ | | webGL support | ❌ | ✅ | | useDevicePixelRatio Option | ❌ | ✅ | | fitCanvasToArtboardHeight Option | ❌ | ✅ | | Bluk StateMachine Input Accessor | ✅ | ❌ |

Potential Roadmap

This is a quick project to serve our needs. There isn't much to go wrong or much to maintain. This should act more as a todo list; there is no given timeline for when these will be worked on

  • Add typesafety. Currently this relies on the typesafety of rive as it is, ideally it would be possible to define the available animations, state machines, statemachine inputs, etc. To prevent invalid names from being passed into input generators.

Credits

License

MIT