1
- ## Interoperable CSSinJS format.
1
+ ## Interoperable CSSinJS standard format.
2
2
3
3
The biggest issue at scale we currently have with all CSSinJS implementations is that they are not sharable without the runtime.
4
4
5
5
We can define a format that is easy to parse and supports all the needs of the current CSSinJS implementations on top of CSS.
6
6
7
- Package maintainers will be able to publish JavaScript files to NPM with this format inside instead of plain CSS.
7
+ Package maintainers will be able to publish JavaScript files to NPM using this format instead of plain CSS or any variation of objects notation .
8
8
9
9
## First draft
10
10
@@ -20,15 +20,20 @@ const RULE_END = 1
20
20
const RULE_NAME = 2
21
21
const SELECTOR = 3
22
22
const PARENT_SELECTOR = 4
23
+ const COMPOUND_SELECTOR_START = 5
24
+ const COMPOUND_SELECTOR_END = 6
23
25
const SPACE_COMBINATOR = 5
24
26
const DOUBLED_CHILD_COMBINATOR = 6
25
27
const CHILD_COMBINATOR = 7
26
28
const NEXT_SIBLING_COMBINATOR = 8
27
29
const SUBSEQUENT_SIBLING_COMBINATOR = 9
28
30
const PROPERTY = 10
29
31
const VALUE = 11
30
- const CONDITION = 12
31
- const FUNCTION = 13
32
+ const COMPOUND_VALUE_START = 12
33
+ const COMPOUND_VALUE_END = 13
34
+ const CONDITION = 14
35
+ const FUNCTION_START = 15
36
+ const FUNCTION_END = 16
32
37
```
33
38
34
39
#### Rule start
@@ -76,51 +81,94 @@ We rely on the JavaScript module scope. Name should be unique within that module
76
81
77
82
#### Selector
78
83
79
- ` [SELECTOR, ... <selector>] `
84
+ ` [SELECTOR, <selector>] `
80
85
81
- Marker ` SELECTOR ` specifies a selector or selector compound .
86
+ Marker ` SELECTOR ` specifies a selector.
82
87
83
88
Selector e.g. ` .foo ` => ` [SELECTOR, '.foo'] `
84
89
85
- Selector compound e.g. ` .foo.bar ` => ` [SELECTOR, '.foo', '.bar'] `
86
-
87
90
Selector list e.g. ` .foo, .bar ` => ` [SELECTOR, '.foo'], [SELECTOR, '.bar'] `
88
91
89
- #### Parent selector
92
+ #### Compound selector
90
93
91
- ` [PARENT_SELECTOR, ... <selector>] `
94
+ ` [COMPOUND_SELECTOR_START], [SELECTOR, <selector>]+, [*COMBINATOR]?, [COMPOUND_SELECTOR_END ] `
92
95
93
- Marker ` PARENT_SELECTOR ` specifies a selector, which is a reference to the parent selector.
94
- Useful for nesting.
96
+ [ Compound] ( https://drafts.csswg.org/selectors/#compound ) selector consists of simple selectors which might be separated by [ combinators] ( https://drafts.csswg.org/selectors/#combinators ) .
97
+
98
+ Selector compound without combinators e.g. ` .foo.bar ` =>
99
+
100
+ ```
101
+ [SELECTOR_COMPOUND_START],
102
+ [SELECTOR, '.foo'],
103
+ [SELECTOR, '.bar'],
104
+ [SELECTOR_COMPOUND_END]
105
+ ```
106
+
107
+ Selector compound with space combinator e.g. ` .foo .bar ` =>
95
108
96
- E.g.: ` &:hover ` => ` [PARENT_SELECTOR, ':hover'] `
109
+ ```
110
+ [SELECTOR_COMPOUND_START],
111
+ [SELECTOR, '.foo'],
112
+ [SPACE_COMBINATOR],
113
+ [SELECTOR, '.bar'],
114
+ [SELECTOR_COMPOUND_END]
115
+ ```
116
+
117
+ Selector compound with next sibling combinator e.g. ` .foo + .bar ` =>
118
+
119
+ ```
120
+ [SELECTOR_COMPOUND_START],
121
+ [SELECTOR, '.foo'],
122
+ [NEXT_SIBLING_COMBINATOR],
123
+ [SELECTOR, '.bar'],
124
+ [SELECTOR_COMPOUND_END]
125
+ ```
126
+
127
+ #### Parent selector
97
128
98
- #### Combinators
129
+ ` [PARENT_SELECTOR] `
99
130
100
- ` [ANY_COMBINATOR] `
131
+ Marker ` PARENT_SELECTOR ` specifies a selector, which is a reference to the parent selector.
132
+ Useful for nesting.
101
133
102
- Combinator constants denote 5 [ CSS combinators ] ( https://drafts.csswg.org/selectors/#combinators ) .
134
+ E.g.: ` &:hover ` =>
103
135
104
- E.g.: ` .foo .bar ` => ` [SELECTOR, '.foo', SPACE_COMBINATOR, '.bar'] `
105
- or ` .foo + .bar ` => ` [SELECTOR, '.foo', NEXT_SIBLING_COMBINATOR, '.bar'] `
136
+ ```
137
+ [COMPOUND_SELECTOR_START]
138
+ [PARENT_SELECTOR],
139
+ [SELECTOR, ':hover'],
140
+ [COMPOUND_SELECTOR_END]
141
+ ```
106
142
107
143
#### Property name
108
144
109
145
` [PROPERTY, <property>] `
110
146
111
- Marker ` PROPERTY ` specifies a property name e.g.: ` [PROPERTY, 'color'] ` .
147
+ Marker ` PROPERTY ` specifies a property name e.g.: ` color ` => ` [PROPERTY, 'color'] ` .
112
148
113
- #### Property value
149
+ #### Simple value
114
150
115
151
` [VALUE, <value>] `
116
152
117
- Marker ` VALUE ` specifies a property value e.g.: ` [VALUE, 'red'] ` .
153
+ Marker ` VALUE ` specifies a property value e.g.: ` red ` => ` [VALUE, 'red'] ` .
154
+
155
+ #### Values list
118
156
119
- Space separated values e.g.: ` red green ` => ` [VALUE, 'red', 'green'] ` .
157
+ A comma separated list of simple values e.g.: ` red, green ` => ` [VALUE, 'red'], [VALUE , 'green'] ` .
120
158
121
- Comma separated values e.g.: ` red, green ` => ` [VALUE, 'red'], [VALUE, 'green'] ` .
122
159
123
- #### Condition
160
+ #### Compound value
161
+
162
+ A value that consists of multiple space separated simple values: e.g.: ` 10px 20px ` =>
163
+
164
+ ```
165
+ [COMPOUND_VALUE_START],
166
+ [VALUE, '10px'],
167
+ [VALUE, '20px'],
168
+ [COMPOUND_VALUE_END]
169
+ ```
170
+
171
+ ### Condition
124
172
125
173
` [CONDITION, <condition>] `
126
174
@@ -130,14 +178,32 @@ E.g. `@media all` => `[RULE_START, 4], [CONDITION, 'all']`
130
178
131
179
#### Function
132
180
133
- ` [FUNCTION, <name>, ...<arguments>] `
181
+ ` [FUNCTION_START, <name>], [SELECTOR|VALUE, <argument>], [FUNCTION_END] `
182
+
183
+ Function specifies [ functional pseudo class] ( https://drafts.csswg.org/selectors/#functional-pseudo-class ) as well as [ functional notation] ( https://drafts.csswg.org/css-values-4/#functional-notation ) .
134
184
135
- Marker ` FUNCTION ` specifies [ functional pseudo class] ( https://drafts.csswg.org/selectors/#functional-pseudo-class ) as well as [ functional notation] ( https://drafts.csswg.org/css-values-4/#functional-notation ) .
136
- After the FUNCTION marker follows the function name and each argument as a separate entry.
185
+ Functional pseudo class e.g. ` .foo:matches(:hover, :focus) ` =>
186
+
187
+ ```
188
+ [SELECTOR_COMPOUND_START],
189
+ [SELECTOR, '.foo'],
190
+ [FUNCTION_START, ':matches'],
191
+ [SELECTOR, ':hover'],
192
+ [SELECTOR, ':focus'],
193
+ [FUNCTION_END],
194
+ [SELECTOR_COMPOUND_END]
195
+ ```
137
196
138
- Functional pseudo class e.g. ` .foo:matches(:hover, :focus )` => ` [SELECTOR, '.foo', [FUNCTION, ':matches', ':hover', ':focus']] `
197
+ Functional value notation e.g.: ` color: rgb(100, 200, 50 )` =>
139
198
140
- Functional value notation e.g.: ` color: rgb(100, 200, 50) ` => ` [PROPERTY, 'color'], [VALUE, [FUNCTION, 'rgb', 100, 200, 50]] `
199
+ ```
200
+ [PROPERTY, 'color'],
201
+ [FUNCTION_START, 'rgb'],
202
+ [VALUE, 100],
203
+ [VALUE, 200],
204
+ [VALUE, 50],
205
+ [FUNCTION_END]
206
+ ```
141
207
142
208
## Examples
143
209
@@ -202,7 +268,7 @@ body, .foo {
202
268
``` css
203
269
.foo {
204
270
color : red ;
205
- color : linear-gradient ( to right , red 0 % , green 100 % ) ;
271
+ color : palevioletred ;
206
272
}
207
273
```
208
274
@@ -213,7 +279,7 @@ body, .foo {
213
279
[PROPERTY , ' color' ],
214
280
[VALUE , ' red' ],
215
281
[PROPERTY , ' color' ],
216
- [VALUE , ' linear-gradient(to right, red 0%, green 100%) ' ],
282
+ [VALUE , ' palevioletred ' ],
217
283
[RULE_END ]
218
284
]
219
285
```
@@ -231,7 +297,7 @@ body, .foo {
231
297
``` js
232
298
[
233
299
[RULE_START , 1 ],
234
- [CONDITION , ' all' ],
300
+ [CONDITION , ' all' ],
235
301
[RULE_START , 1 ],
236
302
[SELECTOR , ' .foo' ],
237
303
[PROPERTY , ' color' ],
@@ -259,7 +325,10 @@ body, .foo {
259
325
[PROPERTY , ' color' ],
260
326
[VALUE , ' red' ],
261
327
[RULE_START , 1 ],
262
- [PARENT_SELECTOR , ' :hover' ],
328
+ [COMPOUND_SELECTOR_START ],
329
+ [PARENT_SELECTOR ],
330
+ [SELECTOR , ' :hover' ],
331
+ [COMPOUND_SELECTOR_END ],
263
332
[PROPERTY , ' color' ],
264
333
[VALUE , ' green' ],
265
334
[RULE_END ],
@@ -285,7 +354,13 @@ body, .foo {
285
354
[PROPERTY , ' color' ],
286
355
[VALUE , ' red' ],
287
356
[RULE_START , 1 ],
288
- [PARENT_SELECTOR , ' .bar' , ' .baz' , SPACE_COMBINATOR , ' .bla' ],
357
+ [COMPOUND_SELECTOR_START ],
358
+ [PARENT_SELECTOR ],
359
+ [SELECTOR , ' .bar' ],
360
+ [SELECTOR , ' .baz' ],
361
+ [SPACE_COMBINATOR ],
362
+ [SELECTOR , ' .bla' ],
363
+ [COMPOUND_SELECTOR_END ],
289
364
[PROPERTY , ' color' ],
290
365
[VALUE , ' green' ],
291
366
[RULE_END ],
@@ -322,9 +397,13 @@ body, .foo {
322
397
``` js
323
398
[
324
399
[RULE_START , 1 ],
325
- [SELECTOR , ' .foo' , [
326
- FUNCTION , ' :matches' , ' :hover' , ' :focus'
327
- ]],
400
+ [COMPOUND_SELECTOR_START ],
401
+ [SELECTOR , ' .foo' ],
402
+ [FUNCTION_START , ' :matches' ],
403
+ [SELECTOR , ' :hover' ],
404
+ [SELECTOR , ' :focus' ],
405
+ [FUNCTION_END ],
406
+ [COMPOUND_SELECTOR_END ],
328
407
[PROPERTY , ' color' ],
329
408
[VALUE , ' red' ]
330
409
[RULE_END ]
@@ -336,7 +415,7 @@ body, .foo {
336
415
``` css
337
416
.foo {
338
417
background : url (http://www.example.org/image );
339
- color : rgb (100 , 200 , 50 );
418
+ color : rgb (100 , 200 , 50 );
340
419
content : counter (list-item ) " . " ;
341
420
width : calc (50% - 2em );
342
421
}
@@ -347,13 +426,26 @@ body, .foo {
347
426
[RULE_START , 1 ],
348
427
[SELECTOR , ' .foo' ],
349
428
[PROPERTY , ' background' ],
350
- [VALUE , [FUNCTION , ' url' , ' http://www.example.org/image' ]],
429
+ [FUNCTION_START , ' url' ],
430
+ [VALUE , ' http://www.example.org/image' ]
431
+ [FUNCTION_END ],
351
432
[PROPERTY , ' color' ],
352
- [VALUE , [FUNCTION , ' rgb' , 100 , 200 , 50 ]],
433
+ [FUNCTION_START , ' rgb' ],
434
+ [VALUE , 100 ],
435
+ [VALUE , 200 ],
436
+ [VALUE , 50 ]
437
+ [FUNCTION_END ],
353
438
[PROPERTY , ' content' ],
354
- [VALUE , [FUNCTION , ' counter' , ' list-item' ], ' ". "' ],
439
+ [COMPOUND_VALUE_START ],
440
+ [FUNCTION_START , ' counter' ],
441
+ [VALUE , ' list-item' ]
442
+ [FUNCTION_END ],
443
+ [VALUE , ' ". "' ]
444
+ [COMPOUND_VALUE_END ],
355
445
[PROPERTY , ' width' ],
356
- [VALUE , [FUNCTION , ' calc' , ' 50% - 2em' ]]
446
+ [FUNCTION_START , ' calc' ],
447
+ [VALUE , ' 50% - 2em' ],
448
+ [FUNCTION_END ],
357
449
[RULE_END ]
358
450
]
359
451
```
0 commit comments