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

stylup

v0.0.0-alpha.6

Published

Write utility classes conveniently while optimising your CSS

Downloads

27

Readme

Stylup

NPM Version Build Status Support Chat

Stylup gives your markup super powers.

  • Automatically processes PostCSS in style tags <style> and inline styles style="".
  • Fully featured CSS can be used inside inline styles.
  • Support for functional class names with dynamic arguments.

Example

Write inteligent functional classes based on their arguments.

<div class="p-4,1,*"></div>

Transforms into styles based on your configuration.

<style>
.80YQhjgv {
  --pt: 4;
  --pr: 1;
  --pl: 1;
}
</style>
<div class="p 80YQhjgv"></div>

You can configure class functions to output whatever you like.

When used with a stylesheet it becomes very powerful, requiring minimal pre configuration to work with your design system.

.p {
  padding-top: calc(var(--pt, initial) * 1rem);
  padding-right: calc(var(--pr, initial) * 1rem);
  padding-bottom: calc(var(--pb, initial) * 1rem);
  padding-left: calc(var(--pl, initial) * 1rem);
}

Features

  • Supports PostCSS

    Add support for PostCSS by including a postcss.config.js file in your project.


  • Inline Styles

    Make use of all CSS features inline including hover states and media queries.

    <div style="&:hover { color: red; }"></div>

  • Functional Class Names

    Use inteligent functional class names. Seperate arguments with commas. Use a wildcard to skip arguments. See below for configuring class names.

    <div class="p-4 m-*,auto fl-wrap"></div>

  • Custom Syntax

    Customise the syntax used for functional classes by by overiding the default regex pattern. stylup.process(html, null, options);

    // Options
    let options = {
      regex: {
        property: /[^-\s]+/,
        number: /[0-9]*\.?[0-9]+|\*/,
        unit: /px|cm|mm|in|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax/,
        seperator: /,/,
        arg: /0*({{number}})({{unit}})?|(\w+)/,
        args: /(?:({{arg}}){{seperator}}?)+/,
        decl: /({{property}})(?:-({{args}}))?/
      	};
    }

Configure

By default stylup will look for a file called stylup.config.js at the root of your project.

// stylup.config.js
module.exports = {
  classes: [
    {
      class: 'p',
      children: [
        't',
        'r',
        'b',
        'l'
      ],
      style: ({ property, children, args, str }) => {

        if (args.length < 3) args.push(args[0])
        else args.push(args[1])

        for (let [i, side] of children.entries()) {
          str`--${property}${side}: ${args[i]};`
        }

        return str()
      }
    }
    // ...
  ]
}

Usage

Add stylup to your project:

npm install stylup --save-dev

Use stylup to process your HTML:

const stylup = require('stylup');

stylup.process(YOUR_HTML /*, processOptions, pluginOptions */);

Or use it as a pHTML plugin:

const phtml = require('phtml');
const stylup = require('stylup');

phtml([
  stylup(/* pluginOptions */)
]).process(YOUR_HTML /*, processOptions */);

Or to use with Svelte

const stylup = require('stylup');

export default [{
	// ...
    plugins: [
        svelte({
            preprocess:
                [{
                    markup({ content, filename }) {
                        content = content.replace(/(?<=\<[^>]*)=(\{[^{}]*\})/gmi, (match, p1) => {
                            return `="${p1}"`
                        })
                        return stylup.process(content, { from: filename }).then(result => ({ code: result.html, map: null }));
                    }
                }]
        }),
        // ...

Options

By default block styles also processed. Set this to false to avoid processing them. stylup.process(html, null, options).

// Options
let options = {
  processBlockStyles: false
}