forked from thysultan/stylis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
100% test coverage, middleware revamp, optimizations, add root property to AST allowing both horizontal and vertical traversal.
- Loading branch information
Showing
14 changed files
with
589 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,90 @@ | ||
## Experimental rewrite | ||
# STYLIS | ||
|
||
The idea is experiment with going full-on with shipping es modules with the lessons learned, and see how small, how fast, and how modular we can go. | ||
[](https://github.com/thysultan/stylis.js) | ||
|
||
Currently the rewrite sits comfortably just under 2kb, with a theoratical performance improvement(haven't test anything yet). This estimate includes the prefixer so excluded this would sit within the low-range ballpark of around ~1kb. | ||
A Light–weight CSS Preprocessor. | ||
|
||
In comparision the current version sits around ~4kb. | ||
[](https://coveralls.io/github/thysultan/stylis.js) | ||
[](https://bundlephobia.com/result?p=stylis) | ||
[](https://github.com/dyo/dyo/blob/master/LICENSE.md) | ||
[](https://www.npmjs.com/package/dyo) | ||
|
||
### Example: | ||
## Installation | ||
|
||
```js | ||
import {compile, serialize, stringify} from 'stylis' | ||
* Use a Direct Download: `<script src=stylis.js></script>` | ||
* Use a CDN: `<script src=unpkg.com/stylis></script>` | ||
* Use NPM: `npm install stylis --save` | ||
|
||
serialize(compile(`...`), stringify) | ||
``` | ||
## Features | ||
|
||
- nesting `a { &:hover {} }` | ||
- selector namespacing | ||
- vendor prefixing (flex-box, etc...) | ||
- minification | ||
- esm module compatible | ||
- tree-shaking-able | ||
|
||
## Abstract Syntax Structure | ||
|
||
```js | ||
const comment = { | ||
value: '/*! Lorem ipsum dolor sit. */', | ||
type: 'comment', | ||
props: '!', | ||
children: 'Lorem ipsum dolor sit.', | ||
line: 1, | ||
column: 1, | ||
caret: 2 | ||
} | ||
|
||
const declaration = { | ||
value: 'color:red', | ||
value: 'color:red;', | ||
type: 'declaration', | ||
props: 'color', | ||
children: 'red', | ||
line: 1, | ||
column: 1, | ||
caret: 2 | ||
line: 1, column: 1 | ||
} | ||
|
||
const ruleset = { | ||
value: "h1,h2", | ||
type: "rule", | ||
value: 'h1,h2', | ||
type: 'rule', | ||
props: ['h1', 'h2'], | ||
children: [...], | ||
line: 1, | ||
column: 1, | ||
caret: 2 | ||
line: 1, column: 1 | ||
} | ||
|
||
const atruleset = { | ||
value: "@media (max-width:100), (min-width:100)", | ||
type: "@media", | ||
value: '@media (max-width:100), (min-width:100)', | ||
type: '@media', | ||
props: ['(max-width:100)', '(min-width:100)'], | ||
children: [...], | ||
line: 1, | ||
column: 1, | ||
caret: 2 | ||
line: 1, column: 1 | ||
} | ||
``` | ||
|
||
## Example: | ||
|
||
```js | ||
import {compile, serialize, stringify} from 'stylis' | ||
|
||
serialize(compile(`...`), stringify) | ||
``` | ||
|
||
### Compile | ||
|
||
```js | ||
compile(`h1{all:unset}`) === {value: 'h1', type: 'ruleset', props: ['h1'], children: [...]} | ||
compile(`--varb:unset;`) === {value: '--foo:unset;', type: 'declaration', props: '--foo', children: 'unset'} | ||
``` | ||
|
||
### Serialize | ||
|
||
```js | ||
serialize(compile(`h1{all:unset}`), stringify) | ||
``` | ||
|
||
### Middleware | ||
|
||
```js | ||
serialize(compile(`h1{all:unset}`), middleware((element, index, children) => console.log(element), stringify)) | ||
``` | ||
|
||
### Tokenize | ||
|
||
```js | ||
tokenize(`h1 h2 h3 [h4 h5] fn(args) "a b c"`) === ['h1', 'h2', 'h3', '[h4 h5]', 'fn', '(args)', '"a b c"'] | ||
``` | ||
|
||
## Benchmark | ||
|
||
Stylis is at-least 2X faster than it's predecesor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export * from './src/Enum.js' | ||
export * from './src/Utility.js' | ||
export * from './src/Parser.js' | ||
export * from './src/Prefixer.js' | ||
export * from './src/Tokenizer.js' | ||
export * from './src/Serializer.js' | ||
export * from './src/Middleware.js' | ||
export * from './src/Tokenizer.js' | ||
export * from './src/Utility.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "stylis", | ||
"version": "4.0.0", | ||
"license": "MIT", | ||
"description": "Stylis is a light – weight css preprocessor", | ||
"description": "A Light–weight CSS Preprocessor", | ||
"homepage": "https://github.com/thysultan/stylis.js", | ||
"author": "Sultan Tarimo <[email protected]>", | ||
"repository": "https://github.com/thysultan/stylis.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.