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

toggle-theme-circular

v1.1.0

Published

Framework-agnostic TypeScript theme switcher with circular View Transition reveals.

Readme

theme-toggle-circular

Framework-agnostic theme switching with a circular reveal animation driven by the View Transition API.

Description

theme-toggle-circular solves a common UI problem: switching between light and dark themes without a plain crossfade or a layout jump. It exists for applications that want a small, framework-neutral utility with a polished reveal effect that starts from the actual button click position.

Internally, the library updates the theme class, persists the choice, and uses the View Transition API plus a clip-path animation to reveal the new theme from the interaction point. When the API is unavailable, it falls back cleanly to a normal theme switch.

Features

  • Framework agnostic
  • TypeScript support
  • Zero runtime dependencies
  • Tailwind compatible
  • Circular reveal animation
  • Dark and light theme persistence
  • System preference support
  • Graceful fallback when View Transition API is unavailable

Installation

npm install theme-toggle-circular

Quick Start

import { createThemeToggle } from "theme-toggle-circular";

const theme = createThemeToggle();

button.addEventListener("click", (event) => {
   theme.toggle(event);
});

CSS Setup

The circular reveal relies on View Transition pseudo-elements. Import the package stylesheet once in your app:

import "theme-toggle-circular/style.css";

If you prefer to inline the required rules manually, this is the minimum setup:

::view-transition-old(root),
::view-transition-new(root) {
   animation: none;
}

API Documentation

createThemeToggle(options?)

Creates a theme controller with persistence and circular transitions.

ThemeToggle

  • toggle(origin?) toggles between light and dark themes
  • set(theme, origin?) sets a specific theme
  • current returns the active theme
  • destroy() removes internal listeners

Options

The library accepts both nested options and top-level aliases for convenience.

  • darkClass: class name applied to the root element when dark mode is active
  • storageKey: storage key used to persist the selected theme
  • duration: animation duration in milliseconds
  • easing: CSS easing function used by the reveal animation
  • followSystemOnStart: whether the initial theme should follow the system preference when nothing is stored

Nested forms are also supported:

  • theme.darkClass
  • theme.followSystemOnStart
  • storage.key
  • animation.duration
  • animation.easing

Framework Examples

Vanilla JavaScript

import "theme-toggle-circular/style.css";
import { createThemeToggle } from "theme-toggle-circular";

const theme = createThemeToggle();
const button = document.querySelector<HTMLButtonElement>("#theme-btn");

button?.addEventListener("click", (event) => {
   theme.toggle(event);
});

React

import { useEffect, useRef } from "react";
import { createThemeToggle } from "theme-toggle-circular";

export function ThemeButton() {
   const theme = useRef(createThemeToggle());

   useEffect(() => () => theme.current.destroy(), []);

   return <button onClick={(event) => theme.current.toggle(event.nativeEvent)}>Theme</button>;
}

Vue 3

<script setup lang="ts">
import { onBeforeUnmount } from "vue";
import { createThemeToggle } from "theme-toggle-circular";

const theme = createThemeToggle();

onBeforeUnmount(() => theme.destroy());
</script>

<template>
   <button @click="(event) => theme.toggle(event)">Theme</button>
</template>

Svelte

<script lang="ts">
   import { onDestroy } from "svelte";
   import { createThemeToggle } from "theme-toggle-circular";

   const theme = createThemeToggle();

   onDestroy(() => theme.destroy());
</script>

<button on:click={(event) => theme.toggle(event)}>Theme</button>

Browser Support

The circular reveal requires the View Transition API, which is currently supported in Chromium-based browsers. When the API is not available, the library still switches themes and persists the result, but without the animated reveal.

Architecture

  • browser/ contains DOM and browser capability helpers
  • core/ contains defaults, option resolution, and state management
  • types/ defines the public TypeScript API
  • utils/ contains shared math and utility helpers

Contributing

Contributions are welcome. Please read CONTRIBUTING.md before opening a pull request.

Local workflow:

npm ci
npm run typecheck
npm run lint
npm run test
npm run build

License

MIT