Skip to content

Commit 37d4a64

Browse files
authored
Merge pull request #117 from tbela99/css-modules
- [x] implement css modules support #116 - [x] fix \<integer\> syntax validation #115
2 parents 9dd5377 + 750cc92 commit 37d4a64

File tree

314 files changed

+38547
-28603
lines changed

Some content is hidden

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

314 files changed

+38547
-28603
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/errors.txt
22
/syntax.txt
3+
/deno.lock
4+
/.repl_history
35
/ROADMAP.draft.md
46
/.idea
57
/.DS_Store

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# Changelog
22

3+
## v1.4.0
4+
5+
### CSS Module support
6+
7+
- [x] scoped name generation
8+
- composes:
9+
- [x] compose from local selector
10+
- [x] compose from other files
11+
- [x] compose from global selector
12+
- [x] comma separated compose list
13+
- [x] :local
14+
- [x] :global
15+
- [x] :local()
16+
- [x] :global()
17+
- [x] selector
18+
- [x] dashed ident (custom properties)
19+
- [x] css at-rule property
20+
- [x] css at-rule value
21+
- [x] keyframe animations
22+
- [x] grid
23+
- naming
24+
- [x] ignore
25+
- [x] camelCase
26+
- [x] camelCaseOnly
27+
- [x] dashCase
28+
- [x] dashCaseOnly
29+
- default mode
30+
- [x] global
31+
- [x] local
32+
- [x] pure(at least one class or id)
33+
- icss
34+
- [x] :import
35+
- [x] :export
36+
37+
### Bug Fixes
38+
- [x] fix \<integer\> syntax validation #115
39+
340
## v1.3.4
441

542
- [x] make streaming optional #109

README.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@ $ deno add @tbela99/css-parser
2424

2525
- no dependency
2626
- CSS validation based upon mdn-data
27-
- fault-tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
27+
- CSS modules support
28+
- fault-tolerant parser implementing the CSS syntax module 3 recommendations.
2829
- fast and efficient minification without unsafe transforms,
2930
see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
30-
- 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
3132
relative color
32-
- generate nested css rules
33-
- convert nested css rules to legacy syntax
34-
- convert colors to any supported color format
35-
- generate sourcemap
36-
- compute css shorthands. see supported properties list below
37-
- minify css transform functions
38-
- evaluate math functions: calc(), clamp(), min(), max(), etc.
39-
- inline css variables
40-
- remove duplicate properties
41-
- 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
4243
- experimental CSS prefix removal
4344

4445
## Online documentation
@@ -49,11 +50,11 @@ See the full documentation at the [CSS Parser](https://tbela99.github.io/css-par
4950

5051
Try it [online](https://tbela99.github.io/css-parser/playground/)
5152

52-
## Exports
53+
## Import
5354

5455
There are several ways to import the library into your application.
5556

56-
### Node exports
57+
### Node
5758

5859
import as a module
5960

@@ -64,7 +65,7 @@ import {transform} from '@tbela99/css-parser';
6465
// ...
6566
```
6667

67-
### Deno exports
68+
### Deno
6869

6970
import as a module
7071

@@ -84,7 +85,7 @@ const {transform} = require('@tbela99/css-parser/cjs');
8485
// ...
8586
```
8687

87-
### Web export
88+
### Web
8889

8990
Programmatic import
9091

@@ -162,19 +163,27 @@ Javascript umd module from cdn
162163
</script>
163164
```
164165

165-
## Transform
166-
167-
Parse and render css in a single pass.
166+
## Exported functions
168167

169-
### Usage
168+
```ts
170169

171-
```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>;
172180

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

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

180189
```javascript
@@ -208,7 +217,7 @@ Include ParseOptions and RenderOptions
208217
> Minify Options
209218
210219
- minify: boolean, optional. default to _true_. optimize ast.
211-
- pass: number, optional. minification pass. default to 1
220+
- pass: number, optional. minification passes. default to 1
212221
- nestingRules: boolean, optional. automatically generated nested rules.
213222
- expandNestingRules: boolean, optional. convert nesting rules into separate rules. will automatically set nestingRules
214223
to false.
@@ -220,6 +229,10 @@ Include ParseOptions and RenderOptions
220229
in the :root {} or html {} rule.
221230
- removeEmpty: boolean, optional. remove empty rule lists from the ast.
222231

232+
> CSS modules Options
233+
234+
- module: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions | ModuleOptions, optional. css modules options.
235+
223236
> CSS Prefix Removal Options
224237
225238
- removePrefix: boolean, optional. remove CSS prefixes.
@@ -895,7 +908,7 @@ for (const {node, parent, root} of walk(ast)) {
895908

896909
Ast can be transformed using node visitors
897910

898-
### Exemple 1: Declaration
911+
### Example 1: Declaration
899912

900913
the visitor is called for any declaration encountered
901914

@@ -930,7 +943,7 @@ console.debug(result.code);
930943
// .foo{transform:scale(calc(40/3))}
931944
```
932945

933-
### Exemple 2: Declaration
946+
### Example 2: Declaration
934947

935948
the visitor is called only on 'height' declarations
936949

@@ -985,7 +998,7 @@ console.debug(result.code);
985998

986999
```
9871000

988-
### Exemple 3: At-Rule
1001+
### Example 3: At-Rule
9891002

9901003
the visitor is called on any at-rule
9911004

@@ -1027,7 +1040,7 @@ console.debug(result.code);
10271040

10281041
```
10291042

1030-
### Exemple 4: At-Rule
1043+
### Example 4: At-Rule
10311044

10321045
the visitor is called only for at-rule media
10331046

@@ -1069,7 +1082,7 @@ console.debug(result.code);
10691082

10701083
```
10711084

1072-
### Exemple 5: Rule
1085+
### Example 5: Rule
10731086

10741087
the visitor is called on any Rule
10751088

@@ -1105,7 +1118,7 @@ console.debug(result.code);
11051118

11061119
```
11071120

1108-
### Exemple 6: Rule
1121+
### Example 6: Rule
11091122

11101123
Adding declarations to any rule
11111124

dist/config.json.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ var map = {
562562
},
563563
animation: {
564564
shorthand: "animation",
565+
separator: {
566+
typ: "Comma"
567+
},
565568
pattern: "animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-fill-mode animation-play-state animation-timeline",
566569
"default": [
567570
"1",

0 commit comments

Comments
 (0)