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

@opensky/style

v0.2.0

Published

Utilities for styling in svelte

Readme

@opensky/style

npm

A collection of utility functions for styling in Svelte applications with Tailwind CSS support.

Installation

npm install @opensky/style

Usage

import { createClass, preserveClass, createVariants } from '@opensky/style'
import type { ClassValue } from '@opensky/style'

The ClassValue type matches what createClass accepts (and is compatible with Svelte's ClassValue from svelte/elements) — useful for typing class props on components:

<script lang="ts">
	import { createClass, type ClassValue } from '@opensky/style'
	let { class: classProp }: { class?: ClassValue } = $props()
</script>

<div class={createClass('flex gap-2', classProp)}>...</div>

API

createClass(...inputs)

Merges and processes CSS class names using clsx and tailwind-merge.

Parameters:

  • inputs - Class values to merge (strings, objects, arrays)

Returns:

  • String of merged and processed class names

Example:

// Basic usage - Tailwind conflicts resolved
createClass('text-lg', 'text-sm')
// Returns: "text-sm" (last conflicting Tailwind class wins)

// Conditional classes
createClass('flex', isActive && 'bg-blue-500', { 'opacity-50': isLoading })
// Returns: "flex bg-blue-500 opacity-50" (if both conditions are true)

// Mix regular and preserved classes
createClass('flex bg-red-500', 'bg-blue-500', preserveClass('custom-animation'))
// Returns: "flex bg-blue-500 custom-animation"

preserveClass(classes)

Marks classes to be preserved without Tailwind conflict resolution.

Parameters:

  • classes - Class values to preserve

Returns:

  • Preserved class object for use with createClass

Example:

// Preserve custom animation class
createClass('bg-red-500', preserveClass('custom-fade-in'))
// Returns: "bg-red-500 custom-fade-in"

// Preserve multiple classes conditionally
createClass('flex', preserveClass(['animate-spin', isLoading && 'opacity-50']))
// Returns: "flex animate-spin opacity-50" (if isLoading is true)

createVariants(config)

Creates a typed variant function for a component. Define once at module scope, apply per render. The output is merged with tailwind-merge, so later sources win: base < variant groups (definition order) < compound rules.

Config:

  • base - Classes always applied (first, so variants can override them)
  • variants - Variant group definitions:
    • Object values create multi-option variants (size: { sm: '...', lg: '...' })
    • String values create boolean toggles (disabled: 'opacity-50')
    • classes and unstyled are reserved names
  • defaults - Default option per group when the prop is omitted (a defined key, or raw classes)
  • compound - { when, classes } rules: classes applies when every value in when matches the resolved variants
  • reset - Classes returned instead of everything else when unstyled: true is passed

Returns a function taking variant props and returning:

  • classes - Final merged class string
  • [group] - Resolved value per group, including applied defaults
  • unstyled - Whether the unstyled escape hatch was used
const button = createVariants({
	base: 'px-4 py-2 font-medium rounded',
	reset: 'p-0 bg-transparent',
	variants: {
		style: {
			primary: 'bg-blue-500 text-white',
			secondary: 'bg-gray-200 text-gray-800'
		},
		size: {
			sm: 'text-sm',
			md: 'text-base',
			lg: 'text-lg'
		},
		// String value = boolean toggle
		disabled: 'opacity-50 cursor-not-allowed'
	},
	defaults: { style: 'secondary', size: 'md' },
	compound: [{ when: { style: 'primary', size: 'lg' }, classes: 'shadow-lg hover:shadow-xl' }]
})

button({ style: 'primary', size: 'lg' })
// { classes: 'px-4 py-2 font-medium rounded bg-blue-500 text-white text-lg shadow-lg hover:shadow-xl',
//   style: 'primary', size: 'lg', disabled: false, unstyled: false }

button()
// defaults applied: style: 'secondary', size: 'md'

button({ style: 'bg-purple-500 underline' })
// raw pass-through: values that aren't defined keys are applied as classes verbatim

button({ unstyled: true })
// { classes: 'p-0 bg-transparent', style: undefined, size: undefined, ... }

Everything is inferred from the config — option names autocomplete and invalid values are compile errors. Use VariantProps to type your component's props from the definition:

<script lang="ts">
  import { createClass, createVariants, type VariantProps } from '@opensky/style'

  const button = createVariants({ /* ... */ })

  type Props = {
    children: Snippet
    class?: ClassValue
  } & VariantProps<typeof button>

  let { children, class: classProp, ...variantProps }: Props = $props()
  let variants = $derived(button(variantProps))
</script>

<button class={createClass(variants.classes, classProp)}>{@render children()}</button>

Dependencies

  • clsx - For conditional class handling
  • tailwind-merge - For Tailwind CSS class conflict resolution

License

MIT