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

svelte-input-system

v0.1.1

Published

A simple input system for interactive web apps, built on Svelte 5 runes.

Downloads

5

Readme

Svelte Input System

A simple input system for interactive web apps, built on Svelte 5 runes.

Usage

Create an InputSet to define keybindings for any action you want to handle.

import { InputSet } from 'svelte-input-system';

export const ExampleInputSet = InputSet.stateful({
	actions: {
		undo: [
			{ logicalKey: 'Undo' }, // Some keyboards have a designated "Undo" button
			{ logicalKey: 'Z', modifiers: { ctrl: true, shift: false } }
		],

		redo: [
			{ logicalKey: 'Redo' }, // Some keyboards have a designated "Redo" button
			{ logicalKey: 'Z', modifiers: { ctrl: true, shift: true } },
			{ logicalKey: 'Y', modifiers: { ctrl: true } }
		],

		sayHi: [
			{ logicalKey: ' ' } // Space bar
		]
	}
});

Then, access the states of your registered actions in a Svelte component (or anywhere in your code, really).

<script lang="ts">
	import { ExampleInputSet } from './example-input-set.js';

	const actions = ExampleInputSet.state.actions;

	const isPressingUndoOrRedo = $derived(actions.undo.isPressed || actions.redo.isPressed);

	actions.sayHi.handleDown(() => {
		console.log('Hi!');
	});
</script>

<p>Is pressing "undo": {actions.undo.isPressed}</p>
<p>Is pressing "redo": {actions.redo.isPressed}</p>

<p>Is pressing either: {isPressingUndoOrRedo}</p>

You can use the isPressed property of an action like any other $state or $derived(...) variable - if it changes, Svelte will know what to do.

By using the handleDown(...) and handleUp(...) functions from one of your actions, your component can react to events while mounted and automatically dispose your callback once unmounted.

[!NOTE] When listening to the handleDown(...) or handleUp(...) hooks, preventDefault() is automatically called on the event that triggered it.

Bypassing Input Events

You can "filter" the state of your inputs, so that handleDown(...), handleUp(...) and isPressed all require a custom pre-condition. This is useful for ignoring events while an HTML <input> or <textarea> is focused.

<script lang="ts">
	import { ExampleInputSet } from './example-input-set.js';

	let activeElement = $state<Element | null>();

	const inputs = ExampleInputSet.state.conditional(() => {
		if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {
			// Bypass input events if an input element is currently focused
			return false;
		}

		return true;
	});

	inputs.actions.sayHi.handleDown(() => {
		console.log('Hi!');
	});
</script>

<svelte:document bind:activeElement />

Condition Parameters

For more fine-grained control over what inputs to enable/disable, use the predicate parameters input and actions for evaluating a condition separately for each of your inputs.

let canCurrentlySayHi = $derived(isCharacterOnScreen);

const inputs = ExampleInputSet.state.conditional(({ input, actions }) => {
	switch (input) {
		case actions.undo:
		case actions.redo:
			return true;

		case actions.sayHi:
			return canCurrentlySayHi;
	}
});