@aerofoil/rive-solid-canvas

中文文档
2.1.4发布于 2023/08/13MITTypeScriptESM + CJS近 30 天下载 3606

unofficial solidjs wrapper around the rive-js library

原始使用文档
文档目录11 节
  1. Getting Started
  2. Advanced Usage
  3. Documentation
  4. <Rive /> Component (Default Export)
  5. createRive()
  6. createRiveInput()
  7. createRiveInputMap()
  8. Comparison
  9. Potential Roadmap
  10. Credits
  11. License

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

NameRive-Solid-CanvasOfficial 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

版本与发布记录

@aerofoil/rive-solid-canvas 共发布 17 个版本,首次发布于 2023/02/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.4latest2023/08/133 年前
1.1.32023/03/063 年前
1.1.22023/02/213 年前
1.1.12023/02/213 年前
1.1.02023/02/213 年前
1.0.102023/02/213 年前

关于 @aerofoil/rive-solid-canvas 的常见问题

@aerofoil/rive-solid-canvas 是什么?

unofficial solidjs wrapper around the rive-js library

如何安装 @aerofoil/rive-solid-canvas?

在项目目录运行 npm install @aerofoil/rive-solid-canvas,或使用 pnpm add / yarn add / bun add。

@aerofoil/rive-solid-canvas 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aerofoil/rive-solid-canvas 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aerofoil/rive-solid-canvas 可以商用吗?

@aerofoil/rive-solid-canvas 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aerofoil/rive-solid-canvas 的下载量有多少?

根据 npm 官方下载统计,@aerofoil/rive-solid-canvas 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,606 次,日均约 120 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aerofoil/rive-solid-canvas 还在维护吗?

最新版本 2.1.4 发布于 2023/08/13(3 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。