Skip to content

Commit ca348f0

Browse files
committed
update docs #116
1 parent c7f6ee7 commit ca348f0

File tree

230 files changed

+2948
-2828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+2948
-2828
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- [x] selector
1818
- [x] dashed ident (custom properties)
1919
- [x] css at-rule property
20-
- [x] css at-rule values
20+
- [x] css at-rule value
2121
- [x] keyframe animations
2222
- [x] grid
2323
- naming

README.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ $ deno add @tbela99/css-parser
2323
## Features
2424

2525
- no dependency
26-
- validate CSS based upon mdn-data
27-
- generate CSS module output
28-
- fault-tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
26+
- CSS validation based upon mdn-data
27+
- CSS modules support
28+
- fault-tolerant parser implementing the CSS syntax module 3 recommendations.
2929
- fast and efficient minification without unsafe transforms,
3030
see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
31-
- minify colors: color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and
31+
- colors minification: color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and
3232
relative color
33-
- generate nested css rules
34-
- convert nested css rules to legacy syntax
35-
- convert colors to any supported color format
36-
- generate sourcemap
37-
- compute css shorthands. see supported properties list below
38-
- minify css transform functions
39-
- evaluate math functions: calc(), clamp(), min(), max(), etc.
40-
- inline css variables
41-
- remove duplicate properties
42-
- flatten @import rules
33+
- color conversion to any supported color format
34+
- automatic nested css rules generation
35+
- nested css rules conversion to legacy syntax
36+
- sourcemap generation
37+
- css shorthands computation. see the supported properties list below
38+
- css transform functions minification
39+
- css math functions evaluation: calc(), clamp(), min(), max(), etc.
40+
- css variables inlining
41+
- duplicate properties removal
42+
- @import rules flattening
4343
- experimental CSS prefix removal
4444

4545
## Online documentation
@@ -54,7 +54,7 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
5454

5555
There are several ways to import the library into your application.
5656

57-
### Node exports
57+
### Node
5858

5959
import as a module
6060

@@ -65,7 +65,7 @@ import {transform} from '@tbela99/css-parser';
6565
// ...
6666
```
6767

68-
### Deno exports
68+
### Deno
6969

7070
import as a module
7171

@@ -85,7 +85,7 @@ const {transform} = require('@tbela99/css-parser/cjs');
8585
// ...
8686
```
8787

88-
### Web export
88+
### Web
8989

9090
Programmatic import
9191

@@ -163,19 +163,27 @@ Javascript umd module from cdn
163163
</script>
164164
```
165165

166-
## Transform
166+
## Exported functions
167167

168-
Parse and render css in a single pass.
168+
```ts
169169

170-
### Usage
171-
172-
```typescript
170+
/* parse and render css */
171+
transform(css: string | ReadableStream<string>, options?: TransformOptions = {}): Promise<TransformResult>
172+
/* parse css */
173+
parse(css: string | ReadableStream<string>, options?: ParseOptions = {}): Promise<ParseResult>;
174+
/* render ast */
175+
render(ast: AstNode, options?: RenderOptions = {}): RenderResult;
176+
/* parse and render css file or url */
177+
transformFile(filePathOrUrl: string, options?: TransformOptions = {}, asStream?: boolean): Promise<TransformResult>;
178+
/* parse css file or url */
179+
parseFile(filePathOrUrl: string, options?: ParseOptions = {}, asStream?: boolean): Promise<ParseResult>;
173180

174-
transform(css: string | ReadableStream<string>, transformOptions: TransformOptions = {}): TransformResult
175-
parse(css: string | ReadableStream<string>, parseOptions: ParseOptions = {}): ParseResult;
176-
render(ast: AstNode, renderOptions: RenderOptions = {}): RenderResult;
177181
```
178182

183+
## Transform
184+
185+
Parse and render css in a single pass.
186+
179187
### Example
180188

181189
```javascript
@@ -209,7 +217,7 @@ Include ParseOptions and RenderOptions
209217
> Minify Options
210218
211219
- minify: boolean, optional. default to _true_. optimize ast.
212-
- pass: number, optional. minification pass. default to 1
220+
- pass: number, optional. minification passes. default to 1
213221
- nestingRules: boolean, optional. automatically generated nested rules.
214222
- expandNestingRules: boolean, optional. convert nesting rules into separate rules. will automatically set nestingRules
215223
to false.
@@ -900,7 +908,7 @@ for (const {node, parent, root} of walk(ast)) {
900908

901909
Ast can be transformed using node visitors
902910

903-
### Exemple 1: Declaration
911+
### Example 1: Declaration
904912

905913
the visitor is called for any declaration encountered
906914

@@ -935,7 +943,7 @@ console.debug(result.code);
935943
// .foo{transform:scale(calc(40/3))}
936944
```
937945

938-
### Exemple 2: Declaration
946+
### Example 2: Declaration
939947

940948
the visitor is called only on 'height' declarations
941949

@@ -990,7 +998,7 @@ console.debug(result.code);
990998

991999
```
9921000

993-
### Exemple 3: At-Rule
1001+
### Example 3: At-Rule
9941002

9951003
the visitor is called on any at-rule
9961004

@@ -1032,7 +1040,7 @@ console.debug(result.code);
10321040

10331041
```
10341042

1035-
### Exemple 4: At-Rule
1043+
### Example 4: At-Rule
10361044

10371045
the visitor is called only for at-rule media
10381046

@@ -1074,7 +1082,7 @@ console.debug(result.code);
10741082

10751083
```
10761084

1077-
### Exemple 5: Rule
1085+
### Example 5: Rule
10781086

10791087
the visitor is called on any Rule
10801088

@@ -1110,7 +1118,7 @@ console.debug(result.code);
11101118

11111119
```
11121120

1113-
### Exemple 6: Rule
1121+
### Example 6: Rule
11141122

11151123
Adding declarations to any rule
11161124

dist/index-umd-web.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,19 +677,19 @@
677677
exports.ModuleCaseTransformEnum = void 0;
678678
(function (ModuleCaseTransformEnum) {
679679
/**
680-
* export as-is
680+
* export class names as-is
681681
*/
682682
ModuleCaseTransformEnum[ModuleCaseTransformEnum["IgnoreCase"] = 1] = "IgnoreCase";
683683
/**
684-
* transform class names and mapping key name
684+
* transform mapping key name
685685
*/
686686
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCase"] = 2] = "CamelCase";
687687
/**
688688
* transform class names and mapping key name
689689
*/
690690
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCaseOnly"] = 4] = "CamelCaseOnly";
691691
/**
692-
* transform class names and mapping key name
692+
* transform mapping key name
693693
*/
694694
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCase"] = 8] = "DashCase";
695695
/**
@@ -10985,7 +10985,10 @@
1098510985
syntax: "none | discard-before || discard-after || discard-inner"
1098610986
},
1098710987
composes: {
10988-
syntax: "<composes-selector>"
10988+
syntax: "<composes-selector>#"
10989+
},
10990+
"composes-selector": {
10991+
syntax: "<ident>+ [from [global&&<string>]]?"
1098910992
}
1099010993
};
1099110994
var functions = {
@@ -11011,7 +11014,7 @@
1101111014
syntax: "atan2( <calc-sum>, <calc-sum> )"
1101211015
},
1101311016
attr: {
11014-
syntax: "attr( <attr-name> <type-or-unit>? [, <attr-fallback> ]? )"
11017+
syntax: "attr( <attr-name> <attr-type>? , <declaration-value>? )"
1101511018
},
1101611019
blur: {
1101711020
syntax: "blur( <length>? )"
@@ -11364,14 +11367,17 @@
1136411367
syntax: "scroll | fixed | local"
1136511368
},
1136611369
"attr()": {
11367-
syntax: "attr( <attr-name> <type-or-unit>? [, <attr-fallback> ]? )"
11370+
syntax: "attr( <attr-name> <attr-type>? , <declaration-value>? )"
1136811371
},
1136911372
"attr-matcher": {
1137011373
syntax: "[ '~' | '|' | '^' | '$' | '*' ]? '='"
1137111374
},
1137211375
"attr-modifier": {
1137311376
syntax: "i | s"
1137411377
},
11378+
"attr-type": {
11379+
syntax: "type( <syntax> ) | raw-string | number | <attr-unit>"
11380+
},
1137511381
"attribute-selector": {
1137611382
syntax: "'[' <wq-name> ']' | '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'"
1137711383
},
@@ -18004,6 +18010,7 @@
1800418010
* @param iter
1800518011
* @param options
1800618012
*
18013+
* @throws Error
1800718014
* @private
1800818015
*/
1800918016
async function doParse(iter, options = {}) {

dist/index.cjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -678,19 +678,19 @@ exports.ColorType = void 0;
678678
exports.ModuleCaseTransformEnum = void 0;
679679
(function (ModuleCaseTransformEnum) {
680680
/**
681-
* export as-is
681+
* export class names as-is
682682
*/
683683
ModuleCaseTransformEnum[ModuleCaseTransformEnum["IgnoreCase"] = 1] = "IgnoreCase";
684684
/**
685-
* transform class names and mapping key name
685+
* transform mapping key name
686686
*/
687687
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCase"] = 2] = "CamelCase";
688688
/**
689689
* transform class names and mapping key name
690690
*/
691691
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCaseOnly"] = 4] = "CamelCaseOnly";
692692
/**
693-
* transform class names and mapping key name
693+
* transform mapping key name
694694
*/
695695
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCase"] = 8] = "DashCase";
696696
/**
@@ -10986,7 +10986,10 @@ var declarations = {
1098610986
syntax: "none | discard-before || discard-after || discard-inner"
1098710987
},
1098810988
composes: {
10989-
syntax: "<composes-selector>"
10989+
syntax: "<composes-selector>#"
10990+
},
10991+
"composes-selector": {
10992+
syntax: "<ident>+ [from [global&&<string>]]?"
1099010993
}
1099110994
};
1099210995
var functions = {
@@ -11012,7 +11015,7 @@ var functions = {
1101211015
syntax: "atan2( <calc-sum>, <calc-sum> )"
1101311016
},
1101411017
attr: {
11015-
syntax: "attr( <attr-name> <type-or-unit>? [, <attr-fallback> ]? )"
11018+
syntax: "attr( <attr-name> <attr-type>? , <declaration-value>? )"
1101611019
},
1101711020
blur: {
1101811021
syntax: "blur( <length>? )"
@@ -11365,14 +11368,17 @@ var syntaxes = {
1136511368
syntax: "scroll | fixed | local"
1136611369
},
1136711370
"attr()": {
11368-
syntax: "attr( <attr-name> <type-or-unit>? [, <attr-fallback> ]? )"
11371+
syntax: "attr( <attr-name> <attr-type>? , <declaration-value>? )"
1136911372
},
1137011373
"attr-matcher": {
1137111374
syntax: "[ '~' | '|' | '^' | '$' | '*' ]? '='"
1137211375
},
1137311376
"attr-modifier": {
1137411377
syntax: "i | s"
1137511378
},
11379+
"attr-type": {
11380+
syntax: "type( <syntax> ) | raw-string | number | <attr-unit>"
11381+
},
1137611382
"attribute-selector": {
1137711383
syntax: "'[' <wq-name> ']' | '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'"
1137811384
},
@@ -18144,6 +18150,7 @@ async function generateScopedName(localName, filePath, pattern, hashLength = 5)
1814418150
* @param iter
1814518151
* @param options
1814618152
*
18153+
* @throws Error
1814718154
* @private
1814818155
*/
1814918156
async function doParse(iter, options = {}) {

dist/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,19 +662,19 @@ declare enum ColorType {
662662
}
663663
declare enum ModuleCaseTransformEnum {
664664
/**
665-
* export as-is
665+
* export class names as-is
666666
*/
667667
IgnoreCase = 1,
668668
/**
669-
* transform class names and mapping key name
669+
* transform mapping key name
670670
*/
671671
CamelCase = 2,
672672
/**
673673
* transform class names and mapping key name
674674
*/
675675
CamelCaseOnly = 4,
676676
/**
677-
* transform class names and mapping key name
677+
* transform mapping key name
678678
*/
679679
DashCase = 8,
680680
/**
@@ -3385,7 +3385,7 @@ export declare interface ModuleOptions {
33853385
hashLength?: number;
33863386

33873387
/**
3388-
* the pattern use to generate scoped names. the supported placeholders are:
3388+
* the pattern used to generate scoped names. the supported placeholders are:
33893389
* - name: the file base name without the extension
33903390
* - hash: the file path hash
33913391
* - local: the local name
@@ -3476,8 +3476,8 @@ export declare interface ModuleOptions {
34763476
* optional function to generate scoped name
34773477
* @param localName
34783478
* @param filePath
3479-
* @param hashLength
34803479
* @param pattern see {@link ModuleOptions.pattern}
3480+
* @param hashLength
34813481
*/
34823482
generateScopedName?: (
34833483
localName: string,

dist/lib/ast/types.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,19 +671,19 @@ var ColorType;
671671
var ModuleCaseTransformEnum;
672672
(function (ModuleCaseTransformEnum) {
673673
/**
674-
* export as-is
674+
* export class names as-is
675675
*/
676676
ModuleCaseTransformEnum[ModuleCaseTransformEnum["IgnoreCase"] = 1] = "IgnoreCase";
677677
/**
678-
* transform class names and mapping key name
678+
* transform mapping key name
679679
*/
680680
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCase"] = 2] = "CamelCase";
681681
/**
682682
* transform class names and mapping key name
683683
*/
684684
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCaseOnly"] = 4] = "CamelCaseOnly";
685685
/**
686-
* transform class names and mapping key name
686+
* transform mapping key name
687687
*/
688688
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCase"] = 8] = "DashCase";
689689
/**

dist/lib/parser/parse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ async function generateScopedName(localName, filePath, pattern, hashLength = 5)
171171
* @param iter
172172
* @param options
173173
*
174+
* @throws Error
174175
* @private
175176
*/
176177
async function doParse(iter, options = {}) {

0 commit comments

Comments
 (0)