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

gif-end-detector

v0.0.1

Published

A library for detecting GIF animation end events, based on libgif.js

Readme

gif-end-detector

GIFアニメーションの終了イベントを検知するための軽量ライブラリです。libgif.jsをベースにしており、GIFアニメーションの制御やフレーム単位での操作を可能にします。

特徴

  • GIFアニメーションの終了イベント検知
  • フレームごとの描画をカスタマイズ可能
  • HTTP経由のGIFファイル読み込みサポート
  • giflerに似た使用感と拡張機能
  • TypeScript対応

インストール

# npmを使用
npm install gif-end-detector

# yarnを使用
yarn add gif-end-detector

依存関係

このライブラリは以下のライブラリに依存しています:

  • libgif.js - GIFアニメーションの解析と描画

重要: libgif.jsはnpmパッケージとして提供されていないため、HTMLで直接読み込む必要があります。

基本的な使用方法

まず、HTMLにlibgif.jsを読み込みます(必須):

<script src="https://cdnjs.cloudflare.com/ajax/libs/libgif-js/3.0.3/libgif.js"></script>

ブラウザ直接読み込み

<!-- libgif.jsを先に読み込む -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/libgif-js/3.0.3/libgif.js"></script>
<!-- 次にgif-end-detectorを読み込む -->
<script src="https://unpkg.com/[email protected]/dist/gifEndDetector.js"></script>

<script>
  // GIFファイルのURL
  const gifUrl = 'path/to/animation.gif';

  // GIFを読み込む
  gifEndDetector(gifUrl).load(function(detector) {
    // Canvasを取得してDOMに追加
    const canvas = detector.getCanvas();
    document.getElementById('container').appendChild(canvas);
    
    // 終了イベントリスナーを追加
    detector.onEnd(function() {
      console.log('アニメーション終了!');
      // 終了時の処理
    });
    
    // アニメーション再生開始
    detector.play();
  });
</script>

モジュールバンドラー使用時(webpack, Rollup, Vite等)

モジュールバンドラーを使用する場合でも、HTMLでlibgif.jsを読み込む必要があります。

<!-- HTMLファイルでlibgif.jsを読み込む -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/libgif-js/3.0.3/libgif.js"></script>
// JavaScriptファイル
import gifEndDetector from 'gif-end-detector';

// GIFファイルのURL
const gifUrl = 'path/to/animation.gif';

// GIFを読み込む
gifEndDetector(gifUrl).load(function(detector) {
  // 処理
});

CDNの利用

CDNから直接ライブラリを使用することもできます:

<!-- libgif.jsを先に読み込む -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/libgif-js/3.0.3/libgif.js"></script>

<!-- unpkgから -->
<script src="https://unpkg.com/gif-end-detector"></script>

<!-- または jsDelivrから -->
<script src="https://cdn.jsdelivr.net/npm/gif-end-detector"></script>

詳細なAPI

gifEndDetector(source)

  • source {String} - GIFファイルのパスまたはURL
  • 戻り値: {Object} - GifEndDetectorインスタンス

メソッド

load(callback)

GIFファイルを読み込み、準備完了後にコールバックを実行します。

  • callback {Function} - 準備完了後に実行されるコールバック関数
  • 戻り値: {Object} - チェーン用のインスタンス

onEnd(callback)

アニメーション終了時に実行されるコールバックを追加します。

  • callback {Function} - 終了時に実行されるコールバック関数
  • 戻り値: {Object} - チェーン用のインスタンス

onFrame(callback)

フレーム描画時に実行されるコールバックを追加します。

  • callback {Function} - フレーム描画時に実行されるコールバック関数
    • 引数: frameIndex {Number} - 現在のフレーム番号
    • 引数: totalFrames {Number} - 総フレーム数
  • 戻り値: {Object} - チェーン用のインスタンス

onError(callback)

エラー発生時に実行されるコールバックを追加します。

  • callback {Function} - エラー時に実行されるコールバック関数
  • 戻り値: {Object} - チェーン用のインスタンス

setOnDrawFrame(drawFunction)

各フレームの描画処理をカスタマイズします。

  • drawFunction {Function} - カスタム描画関数
    • 引数: ctx {CanvasRenderingContext2D} - Canvasのコンテキスト
    • 引数: frameIndex {Number} - 現在のフレーム番号
    • 引数: totalFrames {Number} - 総フレーム数
  • 戻り値: {Object} - チェーン用のインスタンス

play()

アニメーションを開始します。

  • 戻り値: {Object} - チェーン用のインスタンス

pause()

アニメーションを一時停止します。

  • 戻り値: {Object} - チェーン用のインスタンス

reset()

アニメーションを最初のフレームにリセットします。

  • 戻り値: {Object} - チェーン用のインスタンス

moveToFrame(frameIndex)

特定のフレームに移動します。

  • frameIndex {Number} - 移動先のフレーム番号
  • 戻り値: {Object} - チェーン用のインスタンス

getCanvas()

GIFが描画されているCanvas要素を取得します。

  • 戻り値: {HTMLCanvasElement} - Canvas要素

getTotalFrames()

GIFの総フレーム数を取得します。

  • 戻り値: {Number} - 総フレーム数

getCurrentFrame()

現在表示中のフレーム番号を取得します。

  • 戻り値: {Number} - 現在のフレーム番号

CORS対応

外部サーバーのGIFファイルにアクセスする場合、CORS制限にぶつかることがあります。以下の方法で対応できます:

// Blobを経由してCORS制限を回避
fetch('https://example.com/animation.gif', { mode: 'cors' })
  .then(response => response.blob())
  .then(blob => {
    // BlobからローカルURLを作成
    const localUrl = URL.createObjectURL(blob);
    
    // gifEndDetectorでロード
    gifEndDetector(localUrl).load(function(detector) {
      // BlobURLを解放(重要)
      URL.revokeObjectURL(localUrl);
      
      // 以降、通常の使用方法と同じ
      detector.play();
    });
  });

サンプル

examples/ディレクトリに様々な使用例があります:

  • example.html: 基本的な使用例
  • gifler-style-example.html: giflerに似たAPIの使用例
  • http-example.html: HTTP経由でのGIF取得例
  • cors-proxy-example.html: CORS制限回避の例
  • custom-example.html: カスタム実装例

ライセンス

MIT

謝辞

このライブラリはlibgif.jsgiflerにインスピレーションを受けています。