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

@intrnl/stylx

v0.5.2

Published

CSS-in-JS library with near-zero runtime

Downloads

31

Readme

stylx

CSS-in-JS library with near-zero runtime.

Usage

import { createStyles } from '@intrnl/stylx';

const styles = createStyles({
	red: {
		color: 'red',
	},
	redEmboldened: {
		composes: ['$red'],
		fontWeight: 700,
	},
	underlinedOnHover: {
		'&:hover': {
			textDecoration: 'underline',
		},
	},
});

const App = () => {
	return (
		<div>
			<p className={styles.red}>This is red</p>
			<p className={styles.redEmboldened}>This is emboldened red</p>
		</div>
	);
};

Using the Babel plugin, this will generate...

const _red = 'm84tdn0 ',
	_redEmboldened = 'm84tdn1 m84tdn0 ',
	_underlinedOnHover = 'm84tdn2 ';

import * as _stylx from '@intrnl/stylx/runtime';

_stylx.inject(
	'm84tdn',
	'.m84tdn0{color:red;}.m84tdn1{font-weight:700;}.m84tdn2{&:hover{text-decoration:underline;}}',
);

const styles = {};

const App = () => {
	return (
		<div>
			<p className={_red}>This is red</p>
			<p className={_redEmboldened}>This is emboldened red</p>
		</div>
	);
};

By default, the styles object becomes empty to encourage writing code in a way that can be easily analyzed by the plugin. This can be disabled by setting loose: true in the plugin options.

Keyframes and CSS variables

Scoped keyframes and variables can be defined via createKeyframes and createVariables respectively.

const variables = createVariables({
	background: {},
});

const keyframes = createKeyframes({
	spin: {
		to: {
			transform: 'rotate(360deg)',
		},
	},
});

const styles = create({
	root: {
		background: `var(${variables.background})`,
		animation: `${keyframes.spin} 1s linear infinite`,
	},
	isHighlighted: {
		[variables.background]: 'yellow',
	},
});

Class name concatenation

stylx provides an optimized utility function for concatenation. Note that you can only reference variables that can be easily analyzed, as is the case with stylx' own styles.

const styles = createStyles({
	isBordered: {},
	root: {},

	isStandalone: {},
	isMultiple: {},
	item: {},
});

log(join(styles.root, !borderless && styles.isBordered));
log(join(styles.item, standalone ? styles.isStandalone : styles.isMultiple));

log(join('foo', 'bar'));

... where it would be generate...

log(_root + (!borderless ? _isBordered : ''));
log(_item + (standalone ? _isStandalone : _isMultiple));

log('foo' + ' ' + ('bar' + ' '));