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

@swan-io/css

v0.2.0

Published

A lightweight and performant atomic CSS-in-JS library

Readme

@swan-io/css

mit licence npm version bundlephobia

A lightweight and performant atomic CSS-in-JS library.

Installation

$ yarn add @swan-io/css
# --- or ---
$ npm install --save @swan-io/css

Quickstart

import { css, cx } from "@swan-io/css";

const sheet = css.make({
  box: {
    backgroundColor: "blue",
    padding: 16,
  },
  large: {
    padding: 24,
  },
  text: {
    color: "white",
    fontSize: 20,
    ":hover": {
      color: "gray",
    },
  },
});

const Component = ({ large }: { large: boolean }) => (
  <div className={cx(sheet.box, large && sheet.large)}>
    <span className={sheet.text}>Hello world</span>
  </div>
);

API

css.make

Create a new sheet object and inject the associated styles.

const sheet = css.make({
  box: {
    backgroundColor: "hotpink",
    paddingHorizontal: 16,

    // supports :hover, :focus and :active
    ":hover": { color: "red" },
    ":focus": { color: "green" },
    ":active": { color: "blue" },
  },
});

console.log(sheet.box); // a string list of generated classes
const sheet = css.make(({ keyframes }) => ({
  box: {
    animationDuration: "300ms",

    // inject a keyframes rule and generate a unique name for it
    animationName: keyframes({
      "0%": { opacity: 0 },
      "100%": { opacity: 1 },
    }),
  },
}));

[!NOTE] Styles prefixed with $ will be inserted as non-atomic CSS-in-JS, which is particularly useful for resetting the styles of an HTML element.

const sheet = css.make({
  // generates a single class, inserted before the rest
  $reset: {
    margin: 0,
    padding: 0,
  },
  // generates multiple classes
  input: {
    color: "grey",
    display: "flex",
  },
});

css.extend

import { css } from "@swan-io/css";

const input = css.extend({
  colors: {
    red: "#fa2c37",
    blue: "#2c7fff",
    green: "#00c950",
  },
});

type CustomInput = typeof input;

declare module "@swan-io/css" {
  export interface Input extends CustomInput {}
}
import "./theme";

import { createRoot } from "react-dom/client";
// …
const sheet = css.make(({ colors }) => ({
  box: {
    backgroundColor: colors.blue,
  },
}));

cx

Concatenate the generated classes from left to right, with subsequent styles overwriting the property values of earlier ones.

const sheet = css.make({
  box: {
    display: "flex",
    color: "red",
  },
  inline: {
    display: "inline-flex",
  },
});

// with inline={false}, applied style will be display: flex; color: red;
// with inline={true}, applied style will be display: inline-flex; color: red;
const Component = ({ inline }: { inline: boolean }) => (
  <div className={cx(sheet.box, inline && sheet.inline)} />
);

CSS extraction

import swanCss from "@swan-io/css/vite-plugin";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";

export default defineConfig(({ command }) => ({
  plugins: [react(), command === "build" && swanCss()],
}));

Links

🙌 Acknowledgements