All Projects → thysultan → Stylis.js

thysultan / Stylis.js

Licence: mit
light – weight css preprocessor

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Stylis.js

xcc
Toy C compiler for x86-64
Stars: ✭ 19 (-98.4%)
Mutual labels:  preprocessor
Wgtcc
A small C11 compiler
Stars: ✭ 580 (-51.05%)
Mutual labels:  preprocessor
Solpp
A solidity preprocessor and flattener CLI and library
Stars: ✭ 44 (-96.29%)
Mutual labels:  preprocessor
Docpad
Empower your website frontends with layouts, meta-data, pre-processors (markdown, jade, coffeescript, etc.), partials, skeletons, file watching, querying, and an amazing plugin system. DocPad will streamline your web development process allowing you to craft powerful static sites quicker than ever before.
Stars: ✭ 3,035 (+156.12%)
Mutual labels:  preprocessor
Css Crush
CSS preprocessor. Written in PHP
Stars: ✭ 539 (-54.51%)
Mutual labels:  preprocessor
Layla
A CSS language
Stars: ✭ 6 (-99.49%)
Mutual labels:  preprocessor
svelte-typescript
Typescript monorepo for Svelte v3 (preprocess, template, types)
Stars: ✭ 214 (-81.94%)
Mutual labels:  preprocessor
Stylable
Stylable - CSS for components
Stars: ✭ 1,109 (-6.41%)
Mutual labels:  preprocessor
Yay
Yay is a high level PHP preprocessor
Stars: ✭ 553 (-53.33%)
Mutual labels:  preprocessor
Manifold
Manifold plugs into Java to supplement it with powerful features, from Type-safe Metaprogramming (direct access to GraphQL, JSON, XML, etc.), Extension Methods, Operator Overloading, and Unit Expressions to an integrated Template Engine and a Preprocessor. All fully supported in IntelliJ IDEA and Android Studio. Simply add Manifold to your project and begin taking advantage of it.
Stars: ✭ 993 (-16.2%)
Mutual labels:  preprocessor
Babel Plugin Css Modules Transform
Extract css class names from required css module files, so we can render it on server.
Stars: ✭ 318 (-73.16%)
Mutual labels:  preprocessor
Vim Colortemplate
The Toolkit for Vim Color Scheme Designers!
Stars: ✭ 535 (-54.85%)
Mutual labels:  preprocessor
Slang
A small, flexible and extensible front-end for GLSL.
Stars: ✭ 10 (-99.16%)
Mutual labels:  preprocessor
Poststylus
PostCSS adapter for Stylus
Stars: ✭ 279 (-76.46%)
Mutual labels:  preprocessor
I8086.js
16bit Intel 8086 / 80186 + X87 emulator written in TypeScript with REPL assembly compiler and tiny C compiler
Stars: ✭ 54 (-95.44%)
Mutual labels:  preprocessor
dmr c
dmr_C is a C parser and JIT compiler with LLVM, Eclipse OMR and NanoJIT backends
Stars: ✭ 45 (-96.2%)
Mutual labels:  preprocessor
Cloak
A mini-preprocessor library to demostrate the recursive capabilites of the preprocessor
Stars: ✭ 709 (-40.17%)
Mutual labels:  preprocessor
Immutable Styles
A library for styling web interfaces with a focus on predictability and robustness. It uses immutability to remove side effects often tied to CSS, allowing UI bugs to be caught ahead of time!
Stars: ✭ 69 (-94.18%)
Mutual labels:  preprocessor
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-95.11%)
Mutual labels:  preprocessor
Pre Short Closures
Stars: ✭ 36 (-96.96%)
Mutual labels:  preprocessor

STYLIS

stylis

A Light–weight CSS Preprocessor.

Coverage Size Licence NPM

Installation

  • Use a Direct Download: <script src=stylis.js></script>
  • Use a CDN: <script src=unpkg.com/stylis></script>
  • Use NPM: npm install stylis --save

Features

  • nesting a { &:hover {} }
  • selector namespacing
  • vendor prefixing (flex-box, etc...)
  • minification
  • esm module compatible
  • tree-shaking-able

Abstract Syntax Structure

const declaration = {
	value: 'color:red;',
	type: 'decl',
	props: 'color',
	children: 'red',
	line: 1, column: 1
}

const comment = {
	value: '/*@noflip*/',
	type: 'comm',
	props: '/',
	children: '@noflip',
	line: 1, column: 1
}

const ruleset = {
	value: 'h1,h2',
	type: 'rule',
	props: ['h1', 'h2'],
	children: [/* ... */],
	line: 1, column: 1
}

const atruleset = {
	value: '@media (max-width:100), (min-width:100)',
	type: '@media',
	props: ['(max-width:100)', '(min-width:100)'],
	children: [/* ... */],
	line: 1, column: 1
}

Example:

import {compile, serialize, stringify} from 'stylis'

serialize(compile(`h1{all:unset}`), stringify)

Compile

compile('h1{all:unset}') === [{value: 'h1', type: 'rule', props: ['h1'], children: [/* ... */]}]
compile('--foo:unset;') === [{value: '--foo:unset;', type: 'decl', props: '--foo', children: 'unset'}]

Tokenize

tokenize('h1 h2 h3 [h4 h5] fn(args) "a b c"') === ['h1', 'h2', 'h3', '[h4 h5]', 'fn', '(args)', '"a b c"']

Serialize

serialize(compile('h1{all:unset}'), stringify)

Middleware

The middleware helper is a convenient helper utility, that for all intents and purposes you can do without if you intend to implement your own traversal logic. The stringify middleware is one such middleware that can be used in conjunction with it.

Elements passed to middlewares have a root property that is the immediate root/parent of the current element in the compiled output, so it references the parent in the already expanded CSS-like structure. Elements have also parent property that is the immediate parent of the current element from the input structure (structure representing the input string).

Traversal

serialize(compile('h1{all:unset}'), middleware([(element, index, children) => {
	assert(children === element.root.children && children[index] === element.children)
}, stringify])) === 'h1{all:unset;}'

The abstract syntax tree also includes an additional return property for more niche uses.

Prefixing

serialize(compile('h1{all:unset}'), middleware([(element, index, children, callback) => {
	if (element.type === 'decl' && element.props === 'all' && element.children === 'unset')
		element.return = 'color:red;' + element.value
}, stringify])) === 'h1{color:red;all:unset;}'
serialize(compile('h1{all:unset}'), middleware([(element, index, children, callback) => {
	if (element.type === 'rule' && element.props.indexOf('h1') > -1)
		return serialize([{...element, props: ['h2', 'h3']}], callback)
}, stringify])) === 'h2,h3{all:unset;}h1{all:unset;}'

Reading

serialize(compile('h1{all:unset}'), middleware([stringify, (element, index, children) => {
	assert(element.return === 'h1{all:unset;}')
}])) === 'h1{all:unset;color:red;}'

The middlewares in src/Middleware.js dive into tangible examples of how you might implement a middleware, alternatively you could also create your own middleware system as compile returns all the nessessary structure to fork from.

Benchmark

Stylis is at-least 2X faster than its predecesor.

License

Stylis is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].