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 🙏

© 2024 – Pkg Stats / Ryan Hefner

catom

v1.3.0

Published

0 runtime CSS in JS tool

Downloads

53

Readme

Catom

A 0 runtime css in ~~js~~ css tool

Stage: Pre Alpha (Caveats)

Catom allows you to write CSS in your javascript/typescript file and creates highly optimized CSS out of it.

Each rule creates a unique class definition out of it and it gives you 100% freedom about where to put your generated css bundle.

Your javascript code has 0 references to any styles and all that's left is are the compiled hashed clasnames as a string.

It's framework agnostic as it emits pure CSS and leaves out just the classnames

Example

somewhere in our App.js

import { css } from "catom";

const styledButton = css({
  color: "#ff0000",
  borderRadius: "5px",
  padding: "4px",
});
const styledDiv = css({ color: "blue", borderRadius: "5px", padding: "4px" });

function App() {
  return (
    <div className={styledDiv}>
      <button className={styledButton}>Hi</button>
    </div>
  );
}

Css generated:

._6da32 {
  color: #ff0000;
}
.quva1q {
  border-radius: 5px;
}
._2rlxtj {
  padding: 4px;
}
._14ksm7b {
  color: blue;
}

App.js:

const styledButton = "_6da32 quva1q _2rlxtj";
const styledDiv = "_14ksm7b quva1q _2rlxtj";
....

As we had only 4 unique rules, catom generated only 4 classes.

Catom also supports media queries and pseudo properties passing them in an object

const mediaQuery = css({
  media: { "only screen and (max-width:500px)": { color: "red" } },
});
const pseudoQuery = css({ pseudo: { ":hover": { color: "green" } } });

Installation and Usage

Install using npm or yarn

npm i catom -D

In your babel config:

{
    "plugins": [
        "catom/babelPlugin"
        `....
    ]

}

As catom doesn't really interact with your build tool at all, it's your job to inject the generated style.

Here's an example of how you can use it with HTMLWebpackPlugin.

webpack.confg.js

const { emitCSS } = require("catom/css");
// ...
module.exports = {
  plugins: [
    new HtmlWebpackPlugin({
      templateParameters: async function templateParametersGenerator(
        compilation,
        files,
        tags,
        options
      ) {
        return {
          compilation,
          webpackConfig: compilation.options,
          htmlWebpackPlugin: {
            tags,
            files,
            options: Object.assign(options, {
              emitCSS,
            }),
          },
        };
      },
    }),
  ],
};

and then inject it using a template parameter.

<head>
  <style>
    <%= htmlWebpackPlugin.options.emitCSS() %>
  </style>
</head>

it also allows you to use postCSS plugins by importing the transformCSS and/or autoPrefixCSS functions

0 Runtime

Catom ships with 0 js code in your bundle. In fact the first thing the babel transform does, is to remove all imports of the css function from your code.

Caveats

  • It's just something I threw together because I wanted it for a project
  • Not even close to production ready
  • Since it works with AST, it does not allow you to use variable in the values (In work)
  • No support for keyframes as of now