StyleQ Atomic CSS Runtime

0.2.1 · active · verified Sun Apr 19

styleQ is a compact and efficient JavaScript runtime designed for merging HTML class names generated by Atomic CSS compilers. It provides high-performance merging capabilities for initial renders, incorporates built-in memoization to optimize updates, and seamlessly handles both static compiled styles and dynamic inline styles. The library is currently at version 0.2.1 and is actively maintained, though specific release cadence (e.g., weekly, monthly) is not explicitly stated but typically follows an as-needed pattern for utility libraries. Its key differentiators include its small gzipped size (0.7 KB), robust support for various CSS compiler designs, and its focus on performance for critical render paths. It contrasts with traditional CSS-in-JS solutions by operating on pre-compiled class names, acting as a final merging step.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `styleq` to merge atomic CSS class names and inline styles, including dynamic and conditional styles, and shows how to use `styleq.factory` for custom configurations.

import { styleq } from 'styleq';

// Example compiled styles from an Atomic CSS compiler
const compiledStyles = {
  root: {
    $$css: true, // Required for production compiled styles
    display: 'display-flex-class',
    alignItems: 'alignItems-center-class',
    justifyContent: 'justifyContent-spaceBetween-class',
  },
  button: {
    $$css: 'button.ts:15', // String for dev debugging
    backgroundColor: 'bg-blue-500-class',
    padding: 'p-4-class',
    borderRadius: 'rounded-md-class',
  },
};

// Example inline styles (without $$css)
const dynamicStyles = {
  opacity: 0.8,
  color: 'red',
};

// Merge compiled and inline styles
const [className, inlineStyle] = styleq(
  compiledStyles.root,
  compiledStyles.button,
  dynamicStyles,
  // Conditional styles
  true && { cursor: 'pointer' },
  false && { display: 'none' }
);

console.log('Generated className:', className);
console.log('Generated inlineStyle:', inlineStyle);

// Using styleq.factory for custom configurations
const styleqNoCache = styleq.factory({ disableCache: true });
const [classNameNoCache, inlineStyleNoCache] = styleqNoCache(compiledStyles.root);

console.log('Generated className (no cache):', classNameNoCache);

view raw JSON →