@tbela99/css-parser 0.0.1-alpha3

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/.gitattributes ADDED
@@ -0,0 +1,19 @@
1
+ /test/ export-ignore
2
+ /docs/ export-ignore
3
+ /tools/ export-ignore
4
+ /package-lock.json export-ignore
5
+ /.gitignore export-ignore
6
+ /.gitattributes export-ignore
7
+ /rollup.config.mjs export-ignore
8
+ /tsconfig.json export-ignore
9
+ # exclude all files in test/ from stats
10
+ /test/** linguist-vendored
11
+ /docs/** linguist-vendored
12
+ /tools/** linguist-vendored
13
+ /dist/** linguist-vendored
14
+ #
15
+ # do not replace lf by crlf
16
+ *.css text
17
+ *.json text
18
+ text eol=lf
19
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Thierry Bela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # css-parser
2
+
3
+ CSS parser for node and the browser
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ $ npm install @tbela99/css-parser
9
+
10
+ ```
11
+
12
+ ## Transform
13
+
14
+ Parse and render css in a single pass.
15
+
16
+ ### Usage
17
+
18
+ ```javascript
19
+
20
+ transform(css, transformOptions = {})
21
+ ```
22
+
23
+ ### Example
24
+
25
+ ```javascript
26
+
27
+ import {transform} from '@tbela99/css-parser';
28
+
29
+ const {ast, code, errors, stats} = await transform(css, {compress: true, resolveImport: true, cwd: 'files/css'});
30
+ ```
31
+
32
+ ### TransformOptions
33
+
34
+ Include ParseOptions and RenderOptions
35
+
36
+ #### ParseOptions
37
+
38
+ - src: string, optional. css file location to be used with sourcemap.
39
+ - compress: boolean, optional. default to _true_. optimize ast and minify css.
40
+ - removeEmpty: boolean, remove empty nodes from the ast.
41
+ - location: boolean, optional. includes node location in the ast, required for sourcemap generation.
42
+ - cwd: string, optional. the current working directory. when specified url() are resolved using this value
43
+ - resolveImport: boolean, optional. replace @import node by the content of the referenced stylesheet.
44
+ - resolveUrls: boolean, optional. resolve css url() according to the parameters 'src' and 'cwd'
45
+
46
+ #### RenderOptions
47
+ - compress: boolean, optional. default to _true_. optimize ast and minify css.
48
+ - indent: string, optional. css indention string. uses space character by default.
49
+ - newLine: string, new line character.
50
+ - removeComments: boolean, remove comments in generated css.
51
+ - preserveLicense: boolean, force preserving comments starting with '/\*!' when compress is enabling.
52
+ - colorConvert: boolean, convert colors to hex.
53
+
54
+
55
+ ## Parsing
56
+
57
+ ```javascript
58
+ import {parse} from '@tbela99/css-parser';
59
+
60
+ const {ast, errors} = parse(css);
61
+ ```
62
+
63
+ ### Usage
64
+
65
+ ```javascript
66
+
67
+ parse(css, parseOptions = {})
68
+ ```
69
+
70
+ ### Example
71
+
72
+ ````javascript
73
+
74
+ const {ast, errors} = await parse(css);
75
+ ````
76
+
77
+ ## Rendering
78
+
79
+ ### Usage
80
+
81
+ ```javascript
82
+ render(ast, RenderOptions = {});
83
+ ```
84
+
85
+ ### Example
86
+
87
+ ```javascript
88
+ import {render} from '@tbela99/css-parser';
89
+
90
+ // minified
91
+ const {code} = render(ast, {compress: true});
92
+
93
+ console.log(code);
94
+ ```
95
+
96
+ ## Node Walker
97
+
98
+ ```javascript
99
+ import {walk} from '@tbela99/css-parser';
100
+
101
+ for (const {node, parent, root} of walk(ast)) {
102
+
103
+ // do somehting
104
+ }
105
+ ```
106
+
107
+ ## Exports
108
+
109
+ There are several ways to import the library into your application.
110
+
111
+ ### Node exports
112
+
113
+ import as a module
114
+
115
+ ```javascript
116
+
117
+ import {transform} from '@tbela99/css-parser';
118
+
119
+ // ...
120
+ ```
121
+ import as a CommonJS module
122
+
123
+ ```javascript
124
+
125
+ import {transform} from '@tbela99/css-parser/cjs';
126
+
127
+ // ...
128
+ ```
129
+
130
+ ### Web export
131
+
132
+ Programmatic import
133
+
134
+ ```javascript
135
+
136
+ import {transform} from '@tbela99/css-parser/web';
137
+
138
+ // ...
139
+ ```
140
+
141
+ Javascript module
142
+
143
+ ```javascript
144
+
145
+ <script src="dist/web/index.js" type="module"></script>
146
+ ```
147
+
148
+ Single JavaScript file
149
+
150
+ ```javascript
151
+
152
+ <script src="dist/index-umd-web.js"></script>
153
+ ```
154
+
155
+ ## AST
156
+
157
+ ### Comment
158
+
159
+ - typ: string 'Comment'
160
+ - val: string, the comment
161
+
162
+ ### Declaration
163
+
164
+ - typ: string 'Declaration'
165
+ - nam: string, declaration name
166
+ - val: array of tokens
167
+
168
+ ### Rule
169
+
170
+ - typ: string 'Rule'
171
+ - sel: string, css selector
172
+ - chi: array of children
173
+
174
+ ### AtRule
175
+
176
+ - typ: string 'AtRule'
177
+ - nam: string. AtRule name
178
+ - val: rule prelude
179
+
180
+ ### AtRuleStyleSheet
181
+
182
+ - typ: string 'Stylesheet'
183
+ - chi: array of children