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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sveltersect

v0.1.3

Published

sveltersect is an ultra-lightweight library that lets you effortlessly animate elements when they come in/out of view. Use built-in Svelte transitions, CSS classes, or custom callbacks to create stunning effects with minimal effort.

Readme

sveltersect

sveltersect is an ultra-lightweight library that lets you effortlessly animate elements when they come in/out of view. Use built-in Svelte transitions, CSS classes, or custom callbacks to create stunning effects with minimal effort.

View Demo

Other uses:

  • Lazy loading images/components/scripts
  • Infinite scrolling

Installation

npm i -D sveltersect

Usage

sveltersect has three main ways to animate elements:

  1. Svelte Transitions

Use the built-in Svelte transitions. You can use any of the built-in transitions or create your own.

<script>
  import { fade } from 'svelte/transition';
  import { reveal } from 'sveltersect';
</script>
<div use:reveal={{ transition: { animation: fade, threshold: 0.3 } }}>
  This element will fade in when it enters the viewport and fade out when it exits.
</div>

sveltersect will automatically apply the correct transition in each state; mount, unmount, enter, and exit.

  1. CSS Classes

Prefer CSS? Simply pass a class (or classes) to tie it into the observer.

<div use:reveal={{ class: 'fade-in-out', transition: { threshold: 0.5 } }}>
  This element will fade in when it enters the viewport and fade out when it exits.
</div>
<style>
  div {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
  }
  .fade-in-out {
    opacity: 1;
  }
</style>

—just remember to set the initial state in your CSS.

  1. Custom Callbacks You can also pass callback functions, and trigger your own side-effects.
<div use:reveal={{ callbacks: { 
  enter: () => console.log('enter'),
  exit: () => console.log('exit')
}}}>
  This element will log to the console when it enters and exits the viewport.
</div>

Lastly, you can also use separate parameters for entering and exiting transitions:

<div use:reveal={{
  in: { animation: fly, params: { y: 100 }, threshold: 0.5 },
  out: { animation: fade, params: { duration: 200 }, threshold: 0.5 }
}}>
  This element will fade in when it enters the viewport and fade out when it exits.
</div>

For an extensive list of options, check out the type declarations.

Use with Third-Party Libraries

Third party libraries are tricky; you need to tickle just the right spots to get the desired effect. Because of this, there is no one-size-fits-all solution. Here's an exampel using number-flow:

<script>
  import NumberFlow from '@number-flow/svelte';
  
  let value = $state(123);
  function setValue() {
    value = 123;
  };
  function resetValue() {
    value = 0;
  };
</script>

<div use:reveal={{
    callbacks: {
        enter: setValue,
        exit: resetValue,
    },
    transition: {
        threshold: 0.3,
    },
}}>
  <NumberFlow {value} duration={1000} />
</div>

This will create the following effect

  • On mount:
    • If in view, nothing will happen
    • If out of view, the number will transition to 0
  • On enter, the number will transition to 123
  • On exit, the number will transition to 0

You can change the mounting behavior just by changing the initial value. For example, using let value = $state(0);, we get the following:

  • On mount:
    • If in view, the number will transition to 123
    • If out of view, the number will transition to 0

You may need to also set initial: true, which will cause setValue to be called on mount.

Manual Typing

To use the generic type for reveal options, do the following:

const config = {
  in: {
    animation: fade,
    params: { duration: 800 },
  },
  out: {
    animation: fly,
    params: { duration: 800, x: 0 },
  },
} satisfies SveltersectOptions<typeof fade, typeof fly>;

—or use the helper function to avoid the generic:

const config2 = defineRevealOptions({
  in: {
    animation: fade,
    params: { duration: 800 },
  },
  out: {
    animation: fly,
    params: { duration: 800, x: 0 },
  },
})

Component Wrapper

Use the <Reveal> Svelte component to wrap any content:

<script>
  import { fade } from 'svelte/transition';

  const opts = defineRevealOptions({
    transition: { animation: blur, threshold: 0.3 },
    initial: true,
  });
</script>

<Reveal {...opts}>
  <p>Component demo</p>
</Reveal>

Advantages:

  • Hides content in SSR (no exit animations on mount)
  • No layout shifts!
  • Supports the same options as the reveal action

Why is Sveltersect Different?

Sveltersect was created amongst many other libraries that do the same thing. My main goal was to create library that is:

  • Compatible with Svelte's built-in transitions
  • Extensible (actions, components, callbacks, etc.)
  • Takes care of the small details (if you've used transitions or IntersectionObserver, you know)

That aside, Sveltersect should be capable of doing everything the other libraries can do, and more. If you find a bug or have a feature request, please open an issue.