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-before-after

v1.0.1

Published

A lightweight, accessible before/after image comparison slider for Svelte 5

Readme

svelte-before-after

npm license svelte-5

A lightweight, accessible before/after image comparison slider for Svelte 5.

Features

  • 🎚️ Draggable slider with mouse, touch, and pointer support
  • ⌨️ Full keyboard accessibility (arrow keys)
  • ♿ ARIA slider role with proper attributes
  • 🔄 Horizontal and vertical modes
  • 📐 ResizeObserver-based sizing — no stale layout bugs
  • 🏷️ Customizable labels via Svelte 5 snippets
  • 🔗 Two-way bindable offset prop
  • 🎨 CSS custom properties for easy theming
  • 📦 Typed with TypeScript
  • 🖥️ SSR-safe (all browser APIs inside $effect)

Installation

npm i svelte-before-after

Quick Start

<script>
  import { BeforeAfter } from 'svelte-before-after';
</script>

<BeforeAfter before="/before.jpg" after="/after.jpg" />

Props

| Prop | Type | Default | Description | | ------------- | --------- | ---------- | ---------------------------------- | | before | string | required | URL of the "before" image | | after | string | required | URL of the "after" image | | offset | number | 0.5 | Split position (0–1). Bindable. | | contain | boolean | false | If true, fills parent width/height | | overlay | boolean | true | Dark overlay on hover | | hideOnSlide | boolean | true | Fade labels/overlay while dragging | | beforeLabel | Snippet | — | Snippet for the before label | | afterLabel | Snippet | — | Snippet for the after label | | vertical | boolean | false | Top-to-bottom slider mode | | handleSize | number | 40 | Drag handle diameter in px | | class | string | "" | Additional CSS class on container |

Snippets (Labels)

Use Svelte 5 snippets to add custom label content:

<BeforeAfter before="/before.jpg" after="/after.jpg">
  {#snippet beforeLabel()}
    <span class="badge">Before</span>
  {/snippet}
  {#snippet afterLabel()}
    <span class="badge">After</span>
  {/snippet}
</BeforeAfter>

Two-Way Binding

The offset prop supports bind::

<script>
  import { BeforeAfter } from 'svelte-before-after';
  let offset = $state(0.5);
</script>

<BeforeAfter before="/before.jpg" after="/after.jpg" bind:offset />
<input type="range" min="0" max="1" step="0.01" bind:value={offset} />

Vertical Mode

<BeforeAfter before="/before.jpg" after="/after.jpg" vertical={true} />

CSS Custom Properties

Style the component using CSS custom properties on a parent or the component itself:

| Property | Default | Description | | ----------------------- | ----------------- | ----------------------------------- | | --handle-color | white | Handle border & divider color | | --handle-size | 40px | Handle diameter | | --overlay-color | rgba(0,0,0,0.5) | Hover overlay color | | --transition-duration | 0.35s | Transition speed for overlay/labels |

<div style="--handle-color: yellow; --overlay-color: rgba(0,0,0,0.3);">
  <BeforeAfter before="/before.jpg" after="/after.jpg" />
</div>

Keyboard Support

When the component is focused:

| Key | Action | | -------------------------- | --------------------- | | ArrowLeft / ArrowUp | Decrease offset by 1% | | ArrowRight / ArrowDown | Increase offset by 1% |

Accessibility

The component renders with the following ARIA attributes:

  • role="slider" — identifies it as a slider control
  • aria-valuemin="0" / aria-valuemax="100" — range boundaries
  • aria-valuenow — current percentage (0–100)
  • aria-label — descriptive label
  • tabindex="0" — keyboard focusable

SvelteKit Compatibility

This component is fully SSR-safe. All browser APIs (ResizeObserver, getBoundingClientRect, window event listeners) are used inside $effect blocks, which only execute client-side.

License

MIT