Skip to content

Commit fbe89ba

Browse files
authored
Merge pull request #44 from tbela99/prefix_removal
fix merging rules, css selector validation, experimental prefix removal #43
2 parents 24798a2 + c4e7d90 commit fbe89ba

File tree

116 files changed

+223424
-379
lines changed

Some content is hidden

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

116 files changed

+223424
-379
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
/errors.txt
22
/syntax.txt
33
/ROADMAP.draft.md
4+
/.idea
5+
/.DS_Store
6+
/ROADMAP.md
7+
/docs
8+
/package-lock.json
9+
test/*.ts
10+
test/*.js
11+
test/*.css
12+
test/*.html
13+
test/*.json
14+
test/*.md
415

516
# Logs
617
logs

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
/.gitattributes
1919
/Writerside
2020
/validator
21-
/sw.js
21+
/sw.js
22+
/jsr.json

CHANGELOG.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# Changelog
22

3+
#v0.7.0
4+
5+
- [x] fix merging rules
6+
- [ ] experimental CSS prefix removal
7+
- [x] declaration name
8+
- [ ] declaration value
9+
- [ ] exclude -webkit-* gradients
10+
- [x] css selector validation
11+
- [x] pseudo element
12+
- [x] partial pseudo class validation. does not validate parameters
13+
- [x] attribute selector
14+
- [x] combinator
15+
- [x] simple selector
16+
- [x] nested selector
17+
- [x] strict vs permissive validation: allow unknown items such as pseudo classes
18+
- [x] allow unknown pseudo classes
19+
- [x] allow unknown attribute selectors
20+
- [x] strip universal selector when possible
21+
322
# v0.6.0
23+
424
- [x] light-dark() color
525
- [x] system color
626

@@ -58,15 +78,16 @@ CSS color level 4 & 5
5878
- [x] gap
5979

6080
### Other
81+
6182
- [x] renamed RenderOptions.colorConvert to RenderOptions.convertColor
6283
- [x] support none keyword in color
6384
- [x] css relative color syntax for rgb(), hsl() and hwb() colors https://www.w3.org/TR/css-color-5/#relative-colors
64-
- [x] rgb
65-
- [x] hex
66-
- [x] hsl
67-
- [x] hwb
68-
- [x] calc()
69-
- [x] calc() and inline var()
85+
- [x] rgb
86+
- [x] hex
87+
- [x] hsl
88+
- [x] hwb
89+
- [x] calc()
90+
- [x] calc() and inline var()
7091

7192
## v0.2.0
7293

@@ -93,7 +114,7 @@ CSS color level 4 & 5
93114
## v0.1.0
94115

95116
- [x] sourcemap generation
96-
- [x] reduce calc():
117+
- [x] reduce calc():
97118
- [x] inline css variables
98119
- [x] configure duplicate declarations removal
99120
- [x] configure shorthand properties computation
@@ -104,7 +125,7 @@ CSS color level 4 & 5
104125

105126
- [x] merge identical rules
106127
- [x] merge adjacent rules
107-
- [x] minify colors
128+
- [x] minify colors
108129
- [x] minify numbers and Dimensions tokens
109130
- [x] compute shorthand: see the list below
110131
- [x] remove redundant declarations
@@ -113,12 +134,14 @@ CSS color level 4 & 5
113134
- [x] conditionally unwrap :is()
114135
- [x] automatic css nesting
115136
- [x] automatically wrap selectors using :is()
116-
- [x] multi-level shorthand properties (border - [border-width, border-color, border-style, etc.]) https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
137+
- [x] multi-level shorthand properties (
138+
border - [border-width, border-color, border-style, etc.]) https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
117139
- [x] avoid reparsing (declarations, selectors, at-rule)
118140
- [x] node and browser versions
119141
- [x] decode and replace utf-8 escape sequence
120142

121143
### Computed shorthands
144+
122145
- [x] background
123146
- [x] border
124147
- [x] border-bottom

README.md

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $ npm install @tbela99/css-parser
2525
- inline css variables
2626
- remove duplicate properties
2727
- flatten @import rules
28+
- partial css validation: only css selector is validated
2829

2930
## Playground
3031

@@ -145,17 +146,21 @@ Include ParseOptions and RenderOptions
145146
- inlineCssVariables: boolean, optional. replace some css variables with their actual value. they must be declared once in the :root {} or html {} rule.
146147
- removeEmpty: boolean, optional. remove empty rule lists from the ast.
147148

149+
> Minify Options
150+
151+
- validation: boolean, optional. enable strict css validation using (mdn data)[https://github.com/mdn/data]. only the selector is validated at this time.
152+
148153
> Sourcemap Options
149154
150-
- src: string, optional. original css file location to be used with sourcemap.
155+
- src: string, optional. original css file location to be used with sourcemap, also used to resolve url().
151156
- sourcemap: boolean, optional. preserve node location data.
152157

153158
> Misc Options
154159
155160
- resolveUrls: boolean, optional. resolve css 'url()' according to the parameters 'src' and 'cwd'
156161
- resolveImport: boolean, optional. replace @import rule by the content of its referenced stylesheet.
157162
- removeCharset: boolean, optional. remove @charset.
158-
- cwd: string, optional. the current working directory. when specified url() are resolved using this value
163+
- cwd: string, optional. destination directory used to resolve url().
159164
- visitor: VisitorNodeMap, optional. node visitor used to transform the ast.
160165
- signal: AbortSignal, optional. abort parsing.
161166

@@ -179,7 +184,7 @@ Include ParseOptions and RenderOptions
179184
- indent: string, optional. css indention string. uses space character by default.
180185
- newLine: string, optional. new line character.
181186
- output: string, optional. file where to store css. url() are resolved according to the specified value. no file is created though.
182-
- cwd: string, optional. value used as current working directory. when output is not provided, urls are resolved according to this value.
187+
- cwd: string, optional. destination directory used to resolve url().
183188

184189
## Parsing
185190

@@ -316,6 +321,104 @@ table.colortable {
316321
}
317322
```
318323

324+
### CSS Validation
325+
326+
CSS
327+
328+
```css
329+
330+
#404 {
331+
--animate-duration: 1s;
332+
}
333+
334+
.s, #404 {
335+
--animate-duration: 1s;
336+
}
337+
338+
.s [type="text" {
339+
--animate-duration: 1s;
340+
}
341+
342+
.s [type="text"]] {
343+
--animate-duration: 1s;
344+
}
345+
346+
.s [type="text"] {
347+
--animate-duration: 1s;
348+
}
349+
350+
.s [type="text" i] {
351+
--animate-duration: 1s;
352+
}
353+
354+
.s [type="text" s] {
355+
--animate-duration: 1s;
356+
}
357+
358+
.s [type="text" b] {
359+
--animate-duration: 1s;
360+
}
361+
362+
.s [type="text" b], {
363+
--animate-duration: 1s;
364+
}
365+
366+
.s [type="text" b]+ {
367+
--animate-duration: 1s;
368+
}
369+
370+
.s [type="text" b]+ b {
371+
--animate-duration: 1s;
372+
}
373+
374+
.s [type="text" i]+ b {
375+
--animate-duration: 1s;
376+
}
377+
378+
379+
.s [type="text"())] {
380+
--animate-duration: 1s;
381+
}
382+
.s() {
383+
--animate-duration: 1s;
384+
}
385+
.s:focus {
386+
--animate-duration: 1s;
387+
}
388+
```
389+
390+
with validation enabled
391+
392+
```javascript
393+
import {parse, render} from '@tbela99/css-parser';
394+
const options = {minify: true, validate: true};
395+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
396+
//
397+
console.debug(code);
398+
```
399+
400+
```css
401+
.s:is([type=text],[type=text i],[type=text s],[type=text i]+b,:focus) {
402+
--animate-duration: 1s
403+
}
404+
```
405+
406+
with validation disabled
407+
408+
```javascript
409+
import {parse, render} from '@tbela99/css-parser';
410+
const options = {minify: true, validate: false};
411+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
412+
//
413+
console.debug(code);
414+
```
415+
416+
```css
417+
.s:is([type=text],[type=text i],[type=text s],[type=text b],[type=text b]+b,[type=text i]+b,:focus) {
418+
--animate-duration: 1s
419+
}
420+
```
421+
319422
### Nested CSS Expansion
320423

321424
CSS

dist/config.json.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ var map = {
450450
transition: {
451451
shorthand: "transition",
452452
multiple: true,
453-
separator: ",",
453+
separator: {
454+
typ: "Comma"
455+
},
454456
pattern: "transition-property transition-duration transition-timing-function transition-delay transition-behavior",
455457
keywords: [
456458
"none",

0 commit comments

Comments
 (0)