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

unocss-transformer-template

v0.0.3

Published

UnoCSS transformer for creating reusable CSS templates, variants, and components using @template-content, @template-variant, @template-component directives and @for loops.

Readme

unocss-transformer-template

UnoCSS transformer for creating reusable CSS templates, variants and components with @template-content, @template-variant, @template-component directives and @for loops.

Install

npm i -D unocss-transformer-template
// uno.config.ts
import { defineConfig } from 'unocss'
import transformerTemplate from 'unocss-transformer-template'

export default defineConfig({
  // ...
  transformers: [
    transformerTemplate(),
  ],
})

Usage

@template-content

Defines a reusable content template with parameters.

@template-content accent (color) {
  --primary-color: var(--$[color]-primary);
  --secondary-color: var(--$[color]-secondary);
}

This template can be referenced by other directives and will be transformed to an empty string (it's a definition only).

@template-variant

Creates CSS selectors with dynamic parameters using template interpolation.

@template-variant accent (color) (&[data-color='accent:$[color]'],
  html:not(.mobile) &[data-color='hocus:accent:$[color]']:hover,
  html.mobile &[data-color='hocus:accent:$[color]']:active,
  &[data-color='hocus:accent:$[color]']:focus-visible);

When combined with @template-content, generates complete CSS rules:

@template-variant accent(pink) {
  @template-content accent(pink);
}

Will be transformed to:

&[data-color='accent:pink'],
  html:not(.mobile) &[data-color='hocus:accent:pink']:hover,
  html.mobile &[data-color='hocus:accent:pink']:active,
  &[data-color='hocus:accent:pink']:focus-visible{
  --primary-color: var(--pink-primary);
  --secondary-color: var(--pink-secondary);
}

@template-component

Combines a variant with content in a single directive for concise component definitions.

@template-component accent(yellow);

Will be transformed to:

&[data-color='accent:yellow'],
  html:not(.mobile) &[data-color='hocus:accent:yellow']:hover,
  html.mobile &[data-color='hocus:accent:yellow']:active,
  &[data-color='hocus:accent:yellow']:focus-visible {--primary-color: var(--yellow-primary);
  --secondary-color: var(--yellow-secondary);}

@for Loops

Generates multiple variants dynamically by iterating over arrays.

@for (color in [red, green, blue]) {
  /* Accent: $[color] */
  @template-component accent($[color]);
}

Will be transformed to:

/* Accent: blue */
  &[data-color='accent:blue'],
  html:not(.mobile) &[data-color='hocus:accent:blue']:hover,
  html.mobile &[data-color='hocus:accent:blue']:active,
  &[data-color='hocus:accent:blue']:focus-visible {--primary-color: var(--blue-primary);
  --secondary-color: var(--blue-secondary);}
/* Accent: green */
  &[data-color='accent:green'],
  html:not(.mobile) &[data-color='hocus:accent:green']:hover,
  html.mobile &[data-color='hocus:accent:green']:active,
  &[data-color='hocus:accent:green']:focus-visible {--primary-color: var(--green-primary);
  --secondary-color: var(--green-secondary);}
/* Accent: red */
  &[data-color='accent:red'],
  html:not(.mobile) &[data-color='hocus:accent:red']:hover,
  html.mobile &[data-color='hocus:accent:red']:active,
  &[data-color='hocus:accent:red']:focus-visible {--primary-color: var(--red-primary);
  --secondary-color: var(--red-secondary);}

Nested Templates and Variants

Templates can reference other templates for composition:

@template-content base-styles (theme) {
  background: var(--$[theme]-bg);
  color: var(--$[theme]-text);
}

@template-variant glass-effect {
  @template-content base-styles(glass);
  backdrop-filter: blur(10px);
}

Configuration Options

transformerTemplate({
  // Do not use a separate scope for each block of code.
  // Default: false
  weakScope: false,
  
  // Log syntax errors to console
  // Default: false
  showErrors: true,
})

weakScope

When set to false (default), each block of code gets its own isolated scope. When set to true, all definitions share the same scope.

showErrors

When true, syntax errors in your template directives will be logged to the console with detailed location information and code frames.

License

MIT License © 2025 Italo Almeida