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

@alphardex/spine-viewer

v1.0.4

Published

A custom HTML element for displaying Spine animations using PIXI.js

Downloads

33

Readme

Spine Viewer

一个用于在网页中显示 Spine 动画的自定义 HTML 元素,基于 PIXI.js 构建。

注:支持 Spine 4.1 及以下版本,4.2 暂不支持。

安装

npm install @alphardex/spine-viewer

依赖

确保你的项目中已安装以下依赖:

npm install [email protected] pixi-spine

使用方法

1. 导入组件

import "@alphardex/spine-viewer";

2. 在 HTML 中使用

<spine-viewer
  src="/path/to/your/animation.skel"
  animation-name="idle"
  scale="0.6"
>
</spine-viewer>

3. 通过 JavaScript 控制

const viewer = document.querySelector("spine-viewer");

// 设置动画
viewer.setAnimation("walk", true);

// 设置缩放
viewer.setScale(0.8);

// 获取所有动画列表
const animations = viewer.getAnimations();
console.log("可用动画:", animations);

属性

| 属性 | 类型 | 默认值 | 描述 | | ---------------- | ------ | ------ | ------------------------------ | | src | string | - | Spine .skel 文件的路径(必需) | | animation-name | string | 'idle' | 要播放的动画名称 | | scale | number | 0.6 | 缩放比例 |

API 方法

setAnimation(animationName, loop)

设置要播放的动画。

  • animationName (string): 动画名称
  • loop (boolean): 是否循环播放,默认为 true

getAnimations()

返回所有可用的动画名称数组。

setScale(scale)

设置动画的缩放比例。

  • scale (number): 缩放比例

样式

你可以通过 CSS 来设置 spine-viewer 元素的大小和样式:

spine-viewer {
  width: 800px;
  height: 400px;
}

文件结构要求

确保你的 Spine 动画文件按以下结构组织:

animations/
├── character.skel
├── character.atlas
└── character.png

所有文件必须具有相同的基础名称(如 character),组件会自动查找对应的 .atlas.png 文件。

示例

基础示例

<!DOCTYPE html>
<html>
  <head>
    <script type="module">
      import "@alphardex/spine-viewer";
    </script>
    <style>
      spine-viewer {
        width: 800px;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <spine-viewer
      src="/animations/character.skel"
      animation-name="idle"
      scale="0.6"
    >
    </spine-viewer>
  </body>
</html>

动态控制示例

<spine-viewer id="myViewer" src="/animations/character.skel"></spine-viewer>

<button onclick="changeAnimation('walk')">走路</button>
<button onclick="changeAnimation('run')">跑步</button>
<input
  type="range"
  min="0.1"
  max="1.0"
  step="0.1"
  value="0.6"
  onchange="changeScale(this.value)"
/>

<script>
  const viewer = document.getElementById("myViewer");

  function changeAnimation(name) {
    viewer.setAnimation(name, true);
  }

  function changeScale(scale) {
    viewer.setScale(parseFloat(scale));
  }
</script>

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

1.0.0

  • 初始版本
  • 支持基础 Spine 动画播放
  • 支持动态动画切换和缩放