JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 25
  • Score
    100M100P100Q62043F
  • License WTFPL

Inline-Style-as-a-Class CSS utility

Package Exports

  • isaaccss
  • isaaccss/lib/bundle.browser.js
  • isaaccss/lib/index.node.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (isaaccss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

isaaccss: Inline-Style-as-a-Class CSS utility

A CSS class DSL like inline styles.

<button class="--hue:210 padding:4px_8px @width>=768px/padding:8px_16px border-radius:8px color:white border:3px_solid_hsl(var(--hue),100%,80%) background:hsl(var(--hue),100%,50%) :hover/background:hsl(var(--hue),100%,60%) :active/background:hsl(var(--hue),100%,40%)* @hover:hover/:hover/scale:1.1">
  Submit
</button>

Or using some replacements:

<button class="--hue:210 p:4px_8px @w>=768px/p:8px_16px b-radius:8px c:white b:3px_solid_hsl($hue,100%,80%) bg:hsl($hue,100%,50%) :hover/bg:hsl($hue,100%,60%) :active/bg:hsl($hue,100%,40%)* @hover:hover/:hover/scale:1.1">
  Submit
</button>
  • Unlike inline styles:
    • Media queries and selectors (combinators, pseudo-class, pseudo-elements) can be described
    • Specificity can be adjusted
    • Short aliases can be used
    • Content-Security-Policy: no need style-src 'unsafe-inline' or style-src 'nonce-a682b15c'
  • Unlike Tailwind CSS and Windi CSS:
    • This is a class name description rule, not a predefined property set, therefore:
      • Less to remember
      • Simple and flexible: any media, any selector, any property and any value can be described as is
    • High specificity (ID-specificity = 1) by default to override styles from other CSS libraries
    • Specificity can be adjusted
  • Unlike Linaria:
    • Short aliases can be used

Class Format

[@media/][selectors/]property:value[*][!][?]
  • Optional @media/ indicates media queries
    • @foo/... generates @media foo {...}
    • Tokens are parenthesized where necessary
  • Optional selectors/ indicates additional selectors
  • Required property indicates the property name
  • Required value indicates the property value
    • $bar will be replaced with var(--bar)
      • Custom property set libraries, such as Open Props, can help with design themes
  • Optional trailing * increases ID-specificity, more than one can be specified
    • For example, add * to the preferred style between :hover and :active
  • Optional trailing ! indicates !important
    • For example, add ? to the components in a component library, so that applications using it can override the properties
  • Optional trailing ? generates unnamed @layer{}
  • An underscore _ will be replaced with a whitespace and can be escaped with a backslash (\_ will be replaced with _)

Installation

npm i -D isaaccss

Usage

CLI

isaaccss [-c config.js] [-o output.css] [--pretty] [target...]

  --config, -c      Configuration script filename.
                    If unspecified, "isaaccss.config.js" of the current directory is used.
  --output, -o      Output css filename. Console if unspecified.
  --pretty          Pretty print.
  target            Glob pattern with /\\.html?$/ or /\\.[cm]?[jt]sx?$/ extension.
                    Interactive mode if unspecified.

Example configuration script:

import { defaultReplacements } from "isaaccss";

export default {
  // Whether to pretty-print. Default is `false`.
  pretty: true,

  // Replacements. Default is `defaultReplacements`.
  // But if specified, it will be overwritten.
  replacements: [
    // Custom replacements.
    {
      media: [
        [/\bdark\b/g, "prefers-color-scheme:dark"],
        [/\blight\b/g, "prefers-color-scheme:light"],
      ],
      selector: [
        [/(^|\b)::a\b/g, "::after"],
        [/(^|\b)::b\b/g, "::before"],
        [/(^|\b):h\b/g, ":hover"],
        [/(^|\b):f\b/g, ":focus"],
      ],
      property: [
        [/^ff$/, "font-family"],
        [/^fw$/, "font-weight"],
      ],
      value: [
        [/^abs$/, "absolute"],
        [/^rel$/, "relative"],
      ],
    },

    // If you want to extend the default, pass `defaultReplacements`.
    defaultReplacements,
  ],
};

See src/replacements/default.ts for defaultReplacements.

esbuild

import esbuild from "esbuild";
import isaaccss from "isaaccss/lib/esbuild";
import { defaultReplacements } from "isaaccss";

esbuild.build({
  entryPoints: ["src/index.ts"],
  outdir: "dist",
  bundle: true,
  // Inject `isaaccss.inject`.
  inject: [isaaccss.inject],
  plugins: [
    isaaccss.plugin({
      // Optional filename filter. Default is following.
      filter: /\.[cm][jt]x?$/,

      // Optional isaaccss config.
      // See example configuration scripts in the CLI section above.
      config: {
        pretty: true,
        replacements: [
          {
            // Custom replacements...
          },
          defaultReplacements,
        ],
      },
    }),
  ],
});

Rollup

// rollup.config.js
import isaaccss from "isaaccss/lib/rollup";
import { defaultReplacements } from "isaaccss";

export default {
  input: "src/index.js",
  output: { file: "dist/index.js" },
  plugins: [
    isaaccss({
      // Optional include filter. By default, all bundled scripts are included.
      include: ["**/*.js"],

      // Optional exclude filter. By default, nothing is excluded.
      exclude: ["node_modules/**"],

      // Optional output filename.
      // Default is the output script filename with extension ".css".
      output: "styles.js",

      // Optional isaaccss config.
      // See example configuration scripts in the CLI section above.
      config: {
        pretty: true,
        replacements: [
          {
            // Custom replacements...
          },
          defaultReplacements,
        ],
      },
    }),
  ],
};

When you want to merge other CSS files with isaaccss CSS, use rollup-plugin-import-css instead of rollup-plugin-css-only.

// rollup.config.js
import css from "rollup-plugin-import-css";
import isaaccss from "isaaccss/lib/rollup";

export default {
  input: "src/index.js",
  output: { file: "dist/index.js" },
  plugins: [css(), isaaccss()],
};

License

WTFPL