@tbela99/css-parser 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +53 -6
- package/dist/index-umd-web.js +5503 -5037
- package/dist/index.cjs +5510 -5044
- package/dist/index.d.ts +148 -41
- package/dist/lib/ast/expand.js +81 -65
- package/dist/lib/ast/features/calc.js +14 -36
- package/dist/lib/ast/features/inlinecssvariables.js +6 -17
- package/dist/lib/ast/features/prefix.js +22 -19
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +17 -2
- package/dist/lib/ast/math/expression.js +74 -172
- package/dist/lib/ast/math/math.js +24 -22
- package/dist/lib/ast/minify.js +249 -199
- package/dist/lib/ast/transform/compute.js +18 -41
- package/dist/lib/ast/transform/matrix.js +36 -36
- package/dist/lib/ast/transform/minify.js +37 -59
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +13 -13
- package/dist/lib/ast/transform/scale.js +8 -8
- package/dist/lib/ast/transform/skew.js +4 -4
- package/dist/lib/ast/transform/translate.js +8 -8
- package/dist/lib/ast/transform/utils.js +80 -28
- package/dist/lib/ast/types.js +122 -2
- package/dist/lib/fs/resolve.js +1 -14
- package/dist/lib/parser/declaration/list.js +1 -1
- package/dist/lib/parser/declaration/map.js +1 -1
- package/dist/lib/parser/declaration/set.js +3 -3
- package/dist/lib/parser/parse.js +53 -107
- package/dist/lib/parser/tokenize.js +29 -53
- package/dist/lib/parser/utils/declaration.js +1 -1
- package/dist/lib/parser/utils/type.js +2 -2
- package/dist/lib/renderer/render.js +79 -194
- package/dist/lib/{renderer → syntax}/color/a98rgb.js +2 -2
- package/dist/lib/syntax/color/cmyk.js +104 -0
- package/dist/lib/{renderer → syntax}/color/color-mix.js +31 -33
- package/dist/lib/syntax/color/color.js +581 -0
- package/dist/lib/syntax/color/hex.js +179 -0
- package/dist/lib/syntax/color/hsl.js +201 -0
- package/dist/lib/syntax/color/hwb.js +204 -0
- package/dist/lib/syntax/color/lab.js +262 -0
- package/dist/lib/syntax/color/lch.js +194 -0
- package/dist/lib/syntax/color/oklab.js +237 -0
- package/dist/lib/syntax/color/oklch.js +166 -0
- package/dist/lib/{renderer → syntax}/color/p3.js +3 -3
- package/dist/lib/{renderer → syntax}/color/rec2020.js +11 -11
- package/dist/lib/{renderer → syntax}/color/relativecolor.js +54 -41
- package/dist/lib/syntax/color/rgb.js +140 -0
- package/dist/lib/{renderer → syntax}/color/srgb.js +58 -46
- package/dist/lib/syntax/color/utils/components.js +46 -0
- package/dist/lib/{renderer → syntax}/color/utils/constants.js +6 -33
- package/dist/lib/syntax/color/utils/distance.js +40 -0
- package/dist/lib/{renderer → syntax}/color/xyz.js +27 -14
- package/dist/lib/{renderer → syntax}/color/xyzd50.js +8 -8
- package/dist/lib/syntax/syntax.js +78 -77
- package/dist/lib/syntax/utils.js +70 -0
- package/dist/lib/validation/at-rules/container.js +1 -1
- package/dist/lib/validation/at-rules/counter-style.js +1 -1
- package/dist/lib/validation/at-rules/custom-media.js +1 -1
- package/dist/lib/validation/at-rules/document.js +2 -2
- package/dist/lib/validation/at-rules/font-feature-values.js +2 -2
- package/dist/lib/validation/at-rules/import.js +5 -5
- package/dist/lib/validation/at-rules/keyframes.js +3 -13
- package/dist/lib/validation/at-rules/layer.js +1 -1
- package/dist/lib/validation/at-rules/media.js +1 -1
- package/dist/lib/validation/at-rules/namespace.js +1 -1
- package/dist/lib/validation/at-rules/page-margin-box.js +1 -1
- package/dist/lib/validation/at-rules/page.js +1 -1
- package/dist/lib/validation/at-rules/supports.js +7 -7
- package/dist/lib/validation/at-rules/when.js +1 -1
- package/dist/lib/validation/atrule.js +2 -2
- package/dist/lib/validation/config.js +0 -3
- package/dist/lib/validation/config.json.js +1 -1
- package/dist/lib/validation/parser/parse.js +8 -11
- package/dist/lib/validation/selector.js +1 -9
- package/dist/lib/validation/syntax.js +67 -137
- package/dist/lib/validation/syntaxes/complex-selector-list.js +2 -19
- package/dist/lib/validation/syntaxes/complex-selector.js +1 -1
- package/dist/lib/validation/syntaxes/compound-selector.js +5 -24
- package/dist/lib/validation/syntaxes/family-name.js +5 -40
- package/dist/lib/validation/syntaxes/keyframe-selector.js +3 -22
- package/dist/lib/validation/syntaxes/layer-name.js +1 -1
- package/dist/lib/validation/syntaxes/relative-selector-list.js +1 -25
- package/dist/lib/validation/syntaxes/relative-selector.js +1 -1
- package/dist/lib/validation/syntaxes/url.js +3 -34
- package/dist/lib/validation/utils/list.js +2 -9
- package/dist/lib/validation/utils/whitespace.js +1 -1
- package/dist/node/index.js +4 -2
- package/dist/web/index.js +4 -2
- package/package.json +4 -4
- package/.editorconfig +0 -484
- package/dist/lib/ast/transform/convert.js +0 -33
- package/dist/lib/ast/utils/utils.js +0 -104
- package/dist/lib/renderer/color/color.js +0 -654
- package/dist/lib/renderer/color/hex.js +0 -105
- package/dist/lib/renderer/color/hsl.js +0 -125
- package/dist/lib/renderer/color/hwb.js +0 -103
- package/dist/lib/renderer/color/lab.js +0 -148
- package/dist/lib/renderer/color/lch.js +0 -90
- package/dist/lib/renderer/color/oklab.js +0 -131
- package/dist/lib/renderer/color/oklch.js +0 -75
- package/dist/lib/renderer/color/rgb.js +0 -50
- package/dist/lib/renderer/color/utils/components.js +0 -34
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +0 -28
- package/dist/lib/{renderer → syntax}/color/hsv.js +0 -0
- package/dist/lib/{renderer → syntax}/color/prophotorgb.js +1 -1
- /package/dist/lib/{renderer → syntax}/color/utils/matrix.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.3.0
|
|
4
|
+
|
|
5
|
+
- [x] numerical and dimension tokens use numbers instead of string
|
|
6
|
+
- [x] fix bug when inlineCssVariables is disabled and computeCalcExpression is enabled
|
|
7
|
+
|
|
8
|
+
## V1.2.0
|
|
9
|
+
|
|
10
|
+
- [x] convert color to any supported color space #94
|
|
11
|
+
- [x] dead code removal #93
|
|
12
|
+
- [x] validation syntax update #92
|
|
13
|
+
|
|
3
14
|
## v1.1.1
|
|
4
15
|
|
|
5
16
|
- [x] fix bug when css nesting is disabled #89
|
package/README.md
CHANGED
|
@@ -31,9 +31,10 @@ $ deno add @tbela99/css-parser
|
|
|
31
31
|
relative color
|
|
32
32
|
- generate nested css rules
|
|
33
33
|
- convert nested css rules to legacy syntax
|
|
34
|
+
- convert colors to any supported color format
|
|
34
35
|
- generate sourcemap
|
|
35
36
|
- compute css shorthands. see supported properties list below
|
|
36
|
-
- css transform functions
|
|
37
|
+
- minify css transform functions
|
|
37
38
|
- evaluate math functions: calc(), clamp(), min(), max(), etc.
|
|
38
39
|
- inline css variables
|
|
39
40
|
- remove duplicate properties
|
|
@@ -96,7 +97,7 @@ Javascript module from cdn
|
|
|
96
97
|
|
|
97
98
|
<script type="module">
|
|
98
99
|
|
|
99
|
-
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.
|
|
100
|
+
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.0/web';
|
|
100
101
|
|
|
101
102
|
|
|
102
103
|
const css = `
|
|
@@ -210,7 +211,26 @@ Include ParseOptions and RenderOptions
|
|
|
210
211
|
- expandNestingRules: boolean, optional. expand nesting rules.
|
|
211
212
|
- preserveLicense: boolean, force preserving comments starting with '/\*!' when minify is enabled.
|
|
212
213
|
- removeComments: boolean, remove comments in generated css.
|
|
213
|
-
- convertColor: boolean, convert colors to
|
|
214
|
+
- convertColor: boolean | ColorType, convert colors to the specified color. default to ColorType.HEX. supported values are:
|
|
215
|
+
- true: same as ColorType.HEX
|
|
216
|
+
- false: no color conversion
|
|
217
|
+
- ColorType.HEX
|
|
218
|
+
- ColorType.RGB/ColorType.RGBA
|
|
219
|
+
- ColorType.HSL
|
|
220
|
+
- ColorType.HWB
|
|
221
|
+
- ColorType.CMYK/ColorType.DEVICE_CMYK
|
|
222
|
+
- ColorType.SRGB
|
|
223
|
+
- ColorType.SRGB_LINEAR
|
|
224
|
+
- ColorType.DISPLAY_P3
|
|
225
|
+
- ColorType.PROPHOTO_RGB
|
|
226
|
+
- ColorType.A98_RGB
|
|
227
|
+
- ColorType.REC2020
|
|
228
|
+
- ColorType.XYZ/ColorType.XYZ_D65
|
|
229
|
+
- ColorType.XYZ_D50
|
|
230
|
+
- ColorType.LAB
|
|
231
|
+
- ColorType.LCH
|
|
232
|
+
- ColorType.OKLAB
|
|
233
|
+
- ColorType.OKLCH
|
|
214
234
|
|
|
215
235
|
> Sourcemap Options
|
|
216
236
|
|
|
@@ -279,6 +299,32 @@ console.debug(render(result.ast.chi[0].chi[1].chi[1], {withParents: true}));
|
|
|
279
299
|
|
|
280
300
|
```
|
|
281
301
|
|
|
302
|
+
### Convert colors
|
|
303
|
+
|
|
304
|
+
```javascript
|
|
305
|
+
import {transform, ColorType} from '@tbela99/css-parser';
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
const css = `
|
|
309
|
+
.hsl { color: #b3222280; }
|
|
310
|
+
`;
|
|
311
|
+
const result: TransformResult = await transform(css, {
|
|
312
|
+
beautify: true,
|
|
313
|
+
convertColor: ColorType.SRGB
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
console.log(result.css);
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
result
|
|
321
|
+
|
|
322
|
+
```css
|
|
323
|
+
.hsl {
|
|
324
|
+
color: color(srgb .7019607843137254 .13333333333333333 .13333333333333333/50%)
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
282
328
|
### Merge similar rules
|
|
283
329
|
|
|
284
330
|
CSS
|
|
@@ -716,15 +762,15 @@ for (const {node, parent, root} of walk(ast)) {
|
|
|
716
762
|
## Minification
|
|
717
763
|
|
|
718
764
|
- [x] minify keyframes
|
|
719
|
-
- [x] minify transform
|
|
765
|
+
- [x] minify transform functions
|
|
720
766
|
- [x] evaluate math functions calc(), clamp(), min(), max(), round(), mod(), rem(), sin(), cos(), tan(), asin(),
|
|
721
767
|
acos(), atan(), atan2(), pow(), sqrt(), hypot(), log(), exp(), abs(), sign()
|
|
768
|
+
- [x] minify colors
|
|
769
|
+
- [x] minify numbers and Dimensions tokens
|
|
722
770
|
- [x] multi-pass minification
|
|
723
771
|
- [x] inline css variables
|
|
724
772
|
- [x] merge identical rules
|
|
725
773
|
- [x] merge adjacent rules
|
|
726
|
-
- [x] minify colors
|
|
727
|
-
- [x] minify numbers and Dimensions tokens
|
|
728
774
|
- [x] compute shorthand: see the list below
|
|
729
775
|
- [x] remove redundant declarations
|
|
730
776
|
- [x] conditionally unwrap :is()
|
|
@@ -733,6 +779,7 @@ for (const {node, parent, root} of walk(ast)) {
|
|
|
733
779
|
- [x] avoid reparsing (declarations, selectors, at-rule)
|
|
734
780
|
- [x] node and browser versions
|
|
735
781
|
- [x] decode and replace utf-8 escape sequence
|
|
782
|
+
- [x] experimental CSS prefix removal
|
|
736
783
|
|
|
737
784
|
## Computed shorthands properties
|
|
738
785
|
|