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

resonare

v0.0.4

Published

Resonare

Readme

Resonare Version

A configuration-based theme store for building deeply personal user interface.

Features

  • Define and manage multi-dimensional themes, eg:
    • Color scheme: system, light, dark
    • Contrast preference: standard, high
    • Spacing: compact, comfortable, spacious
    • etc
  • Framework-agnostic
  • Prevent theme flicker on page load
  • Honor system preferences
  • Create sections with independent theming
  • Sync theme selection across tabs and windows
  • Flexible persistence options, defaulting to localStorage
  • SSR-friendly

Demo

Installation

To install:

npm i resonare
# or
yarn add resonare
# or
pnpm add resonare

Basic Usage

It's recommended to initialize Resonare in a synchronous script to avoid theme flicker on page load. If your project's bundler supports importing static asset as string, you can inline the minified version of Resonare to reduce the number of HTTP requests. Check out the demo for example of this pattern with Vite.

<script src="https://unpkg.com/resonare"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/resonare"></script>

<script>
  ;(async () => {
    const themeStore = window.resonare.createThemeStore({
      config: {
        colorScheme: {
          options: [
            {
              value: 'system',
              media: ['(prefers-color-scheme: dark)', 'dark', 'light'],
            },
            'light',
            'dark',
          ]
        },
      },
    })

    themeStore.subscribe(({ resolvedThemes }) => {
      for (const [theme, optionKey] of Object.entries(resolvedThemes)) {
        document.documentElement.dataset[theme] = optionKey
      }
    })

    await themeStore.restore()
    themeStore.sync()
  })()
</script>

If you are using TypeScript, add node_modules/resonare/global.d.ts to include in tsconfig.json.

{
  "include": [
    "node_modules/resonare/global.d.ts",
    // ...
  ]
}

API

createThemeStore

import { createThemeStore, type ThemeConfig, type ThemeStore } from 'resonare'

const config = {
  colorScheme: {
    options: [
      {
        value: 'system',
        media: ['(prefers-color-scheme: dark)', 'dark', 'light'],
      },
      'light',
      'dark',
    ]
  },
  contrast: {
    options: [
      {
        value: 'system',
        media: [
          '(prefers-contrast: more) and (forced-colors: none)',
          'high',
          'standard',
        ],
      },
      'standard',
      'high',
    ],
    defaultOption: 'standard',
  }
} as const satisfies ThemeConfig

declare module 'resonare' {
  interface ThemeStoreRegistry {
    resonare: ThemeStore<typeof config>
  }
}


const themeStore = createThemeStore({
  // optional, default 'resonare'
  // should be unique, also used as client storage key
  key: 'resonare',

  // required, specify theme and options
  config,

  // optional, useful for SSR
  initialState: {
    themes: {
      colorScheme: 'dark',
      contrast: 'high',
    },
  },

  // optional, specify your own client storage
  // localStorage is used by default
  storage: ({ abortController }) => ({
    getItem: (key: string) => {
      return JSON.parse(localStorage.getItem(key) || 'null')
    },

    setItem: (key: string, value: object) => {
      localStorage.setItem(key, JSON.stringify(value))
    },

    watch: (cb: (key: string, value: unknown) => void) => {
      const controller = new AbortController()

      window.addEventListener(
        'storage',
        (e) => {
          if (e.storageArea !== localStorage) return

          cb(e.key, JSON.parse(e.newValue!))
        },
        {
          signal: AbortSignal.any([
            abortController.signal,
            controller.signal,
          ]),
        },
      )

      return () => {
        controller.abort()
      }
    },
  })
})

getThemeStore

import { getThemeStore } from 'resonare'

// Get an existing theme store by key
const themeStore = getThemeStore('resonare') 

destroyThemeStore

import { destroyThemeStore } from 'resonare'

// Get an existing theme store by key
const themeStore = destroyThemeStore('resonare') 

ThemeStore Methods

interface ThemeStore<T> {
  // get current theme selection
  getThemes(): Record<string, string>

  // get resolved theme selection (after media queries)
  getResolvedThemes(): Record<string, string>

  // update theme
  setThemes(themes: Partial<Record<string, string>>): Promise<void>

  // get state to persist, useful for server-side persistence
  // to restore, pass the returned object to initialState
  getStateToPersist(): object

  // restore persisted theme selection from client storage
  restore(): Promise<void>

  // sync theme selection across tabs/windows
  sync(): () => void

  // subscribe to theme changes
  subscribe(
    callback: ({
      themes,
      resolvedThemes,
    }: {
      themes: Record<string, string>
      resolvedThemes: Record<string, string>
    }) => void,
    options?: { immediate?: boolean }
  ): () => void
}

React Integration

Ensure that you have initialized Resonare as per instructions under Basic Usage.

import * as React from 'react'
import { getThemesAndOptions } from 'resonare'
import { useResonare } from 'resonare/react'

function ThemeSelect() {
  const { themes, setThemes } = useResonare(() =>
    window.resonare.getThemeStore(),
  )

  return getThemesAndOptions(config).map(([theme, options]) => (
    <div key={theme}>
      <label htmlFor={theme}>{theme}</label>
      <select
        id={theme}
        name={theme}
        onChange={(e) => {
          setThemes({ [theme]: e.target.value })
        }}
        value={themes[theme]}
      >
        {options.map((option) => (
          <option key={option} value={option}>
            {option}
          </option>
        ))}
      </select>
    </div>
  ))
}

Server-side persistence

If you are storing theme selection on the server, you can choose to use memoryStorageAdapter to avoid storing any data client-side. There's no need to initialize Resonare in a synchronous script. Ensure you pass the persisted theme selection when initializing Resonare as initialState.

import {
  createThemeStore,
  getThemesAndOptions,
  memoryStorageAdapter,
  type ThemeConfig,
  type Themes,
} from 'resonare'
import { useResonare } from 'resonare/react'
import * as React from 'react'

const config = {
  colorScheme: {
    options: ['light', 'dark'],
  },
  contrast: {
    options: ['standard', 'high'],
  },
} as const satisfies ThemeConfig

export function ThemeSelect({
  persistedServerThemes,
}: { persistedServerThemes: Themes<typeof config> }) {
  const [themeStore] = React.useState(() =>
    createThemeStore({
      config,
      initialState: {
        themes: persistedServerThemes,
      },
      storage: memoryStorageAdapter(),
    }),
  )

  const { themes, setThemes } = useResonare(() => themeStore, {
    initOnMount: true,
  })

  return getThemesAndOptions(config).map(([theme, options]) => (
    <div key={theme}>
      <label htmlFor={theme}>{theme}</label>
      <select
        id={theme}
        name={theme}
        onChange={(e) => {
          setThemes({ [theme]: e.target.value })
        }}
        value={themes[theme]}
      >
        {options.map((option) => (
          <option key={option} value={option}>
            {option}
          </option>
        ))}
      </select>
    </div>
  ))
}