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

@mizu-mizu/abstract-inputs

v1.0.0

Published

キーボードからのユーザー入力を管理する

Downloads

3

Readme

キーボード入力を一度バッファし、特定のフレーム処理時に正規化して解決します。 また、各キーの押下状態を記録し、任意のタイミングで確認したり、直近の入力履歴を確認します。

ゲームのように特定のメッセージループ内で入力を正規化して処理したい場合に活用できます。

使い方

(npm を利用する場合)

npm install --save @mizu-mizu/abstract-inputs
import { InputManager } from '@mizu-mizu/abstract-inputs'
const FPS = 1000 / 60
const inputManager = new InputManager()

document.addEventListener('DOMContentLoaded', () => {
  inputManager.mount(document.body)
  let frameCount = 0
  setInterval(() => {
    const keyState = inputManager.consume(frameCount++)
    console.log(keyState)
  }, FPS)
  window.addEventListener('blur', () => {
    inputManager.addResetInputs()
  })
})

InputManager を利用する上で大事なことは、 mount() で要素に紐づけることと、 一定終期で consume() を呼び出し続けることです。

これにより、InputManager インスタンスは入力イベントの監視を開始し、consume() 呼び出しのタイミングで 整理します。

API ドキュメント

InputManager#mount()

指定した要素にキーボードリスナを登録し、キーボード入力の受付を開始します。

const inputManager = new InputManager()
inputManager.mount(document.getElementById('targetEl'))

InputManager#unmount()

#mount() で監視を開始済みの対象要素に登録されたキーボードリスナを削除し、 キー入力受付を終了します。

inputManager.unmount(document.getElementById('targetEl'))

InputManager#consume()

呼び出し毎に、前回呼び出し(初回の場合は mount())以降に蓄積された入力をその呼び出し時点の フレーム内入力として整理します。

常にこのメソッドを一定間隔で呼び出すようにしてください。

const inputManager = new InputManager()
inputManager.mount(document.getElementById('targetEl'))
setInterval(() => {
  const keyState = inputManager.consume(frameCount++)
}, 1)

InputManager#reserve()

キー入力を指定フレーム番号で解決される入力として予約します。

キーを押し下げた入力を type: 'down' とし、キーを離す入力を type: 'up' として予約する必要があります。

const inputManager = new InputManager()
inputManager.reserve(1000, [{
  type: 'down',
  code: 'KeyA',
}])
inputManager.reserve(1001, [{
  type: 'up',
  code: 'KeyA',
}])

tokenize(), parseTokens()

指定されたフォーマットのコマンド文字列をトークン列に展開/トークン列からコマンドデータを作成します。

いずれの関数も、async iterable なオブジェクトを返します。

parseTokens() は、引数に配列と async iterable なオブジェクトのいずれも受け取ることができます。

import { tokenize, parseTokens } from '@mizu-mizu/abstract-inputs'
const text = '1000:dKeyA 1001:uKeyA'
for await (const { frameCount, inputEvents } of parseTokens(tokenize(value))) {
  inputManager.reserve(frameCount, inputEvents)
}

tokenizeSync()

この関数は、tokenize() の同期版です。コマンド文字列を引数に受け取り、トークンオブジェクトの配列を返します。

第二引数を省略した場合、与えられた入力は line:0, column:0 から始まるものとして処理されますが、 第二引数の指定によりこの値を変更することが出来ます。

import { tokenizeSync } from '@mizu-mizu/abstract-inputs'
const text = '1000:dKeyA'
console.log(tokenizeSync(text, { lineNoFrom: 2, columnNoFrom: 3 }))
  // -> [
  //   { lineNo: 2, column: 3, text: '1000' },
  //   { lineNo: 2, column: 7, text: ':' },
  //   { lineNo: 2, column: 8, text: 'dKeyA' }
  // ]