Skip to content

Commit 4dfae65

Browse files
committed
flattened, max 2-values tuples
added COMPOUND_SELECTOR_START added COMPOUND_SELECTOR_END added COMPOUND_VALUE_START added COMPOUND_VALUE_END added FUNCTION_START added FUNCTION_END
1 parent 69f9aa5 commit 4dfae65

File tree

1 file changed

+134
-42
lines changed

1 file changed

+134
-42
lines changed

readme.md

Lines changed: 134 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
## Interoperable CSSinJS format.
1+
## Interoperable CSSinJS standard format.
22

33
The biggest issue at scale we currently have with all CSSinJS implementations is that they are not sharable without the runtime.
44

55
We can define a format that is easy to parse and supports all the needs of the current CSSinJS implementations on top of CSS.
66

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.
88

99
## First draft
1010

@@ -20,15 +20,20 @@ const RULE_END = 1
2020
const RULE_NAME = 2
2121
const SELECTOR = 3
2222
const PARENT_SELECTOR = 4
23+
const COMPOUND_SELECTOR_START = 5
24+
const COMPOUND_SELECTOR_END = 6
2325
const SPACE_COMBINATOR = 5
2426
const DOUBLED_CHILD_COMBINATOR = 6
2527
const CHILD_COMBINATOR = 7
2628
const NEXT_SIBLING_COMBINATOR = 8
2729
const SUBSEQUENT_SIBLING_COMBINATOR = 9
2830
const PROPERTY = 10
2931
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
3237
```
3338

3439
#### Rule start
@@ -76,51 +81,94 @@ We rely on the JavaScript module scope. Name should be unique within that module
7681

7782
#### Selector
7883

79-
`[SELECTOR, ...<selector>]`
84+
`[SELECTOR, <selector>]`
8085

81-
Marker `SELECTOR` specifies a selector or selector compound.
86+
Marker `SELECTOR` specifies a selector.
8287

8388
Selector e.g. `.foo` => `[SELECTOR, '.foo']`
8489

85-
Selector compound e.g. `.foo.bar` => `[SELECTOR, '.foo', '.bar']`
86-
8790
Selector list e.g. `.foo, .bar` => `[SELECTOR, '.foo'], [SELECTOR, '.bar']`
8891

89-
#### Parent selector
92+
#### Compound selector
9093

91-
`[PARENT_SELECTOR, ...<selector>]`
94+
`[COMPOUND_SELECTOR_START], [SELECTOR, <selector>]+, [*COMBINATOR]?, [COMPOUND_SELECTOR_END]`
9295

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` =>
95108

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
97128

98-
#### Combinators
129+
`[PARENT_SELECTOR]`
99130

100-
`[ANY_COMBINATOR]`
131+
Marker `PARENT_SELECTOR` specifies a selector, which is a reference to the parent selector.
132+
Useful for nesting.
101133

102-
Combinator constants denote 5 [CSS combinators](https://drafts.csswg.org/selectors/#combinators).
134+
E.g.: `&:hover` =>
103135

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+
```
106142

107143
#### Property name
108144

109145
`[PROPERTY, <property>]`
110146

111-
Marker `PROPERTY` specifies a property name e.g.: `[PROPERTY, 'color']`.
147+
Marker `PROPERTY` specifies a property name e.g.: `color` => `[PROPERTY, 'color']`.
112148

113-
#### Property value
149+
#### Simple value
114150

115151
`[VALUE, <value>]`
116152

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
118156

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']`.
120158

121-
Comma separated values e.g.: `red, green` => `[VALUE, 'red'], [VALUE, 'green']`.
122159

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
124172

125173
`[CONDITION, <condition>]`
126174

@@ -130,14 +178,32 @@ E.g. `@media all` => `[RULE_START, 4], [CONDITION, 'all']`
130178

131179
#### Function
132180

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).
134184

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+
```
137196

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)` =>
139198

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+
```
141207

142208
## Examples
143209

@@ -202,7 +268,7 @@ body, .foo {
202268
```css
203269
.foo {
204270
color: red;
205-
color: linear-gradient(to right, red 0%, green 100%);
271+
color: palevioletred;
206272
}
207273
```
208274

@@ -213,7 +279,7 @@ body, .foo {
213279
[PROPERTY, 'color'],
214280
[VALUE, 'red'],
215281
[PROPERTY, 'color'],
216-
[VALUE, 'linear-gradient(to right, red 0%, green 100%)'],
282+
[VALUE, 'palevioletred'],
217283
[RULE_END]
218284
]
219285
```
@@ -231,7 +297,7 @@ body, .foo {
231297
```js
232298
[
233299
[RULE_START, 1],
234-
[CONDITION, 'all'],
300+
[CONDITION, 'all'],
235301
[RULE_START, 1],
236302
[SELECTOR, '.foo'],
237303
[PROPERTY, 'color'],
@@ -259,7 +325,10 @@ body, .foo {
259325
[PROPERTY, 'color'],
260326
[VALUE, 'red'],
261327
[RULE_START, 1],
262-
[PARENT_SELECTOR, ':hover'],
328+
[COMPOUND_SELECTOR_START],
329+
[PARENT_SELECTOR],
330+
[SELECTOR, ':hover'],
331+
[COMPOUND_SELECTOR_END],
263332
[PROPERTY, 'color'],
264333
[VALUE, 'green'],
265334
[RULE_END],
@@ -285,7 +354,13 @@ body, .foo {
285354
[PROPERTY, 'color'],
286355
[VALUE, 'red'],
287356
[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],
289364
[PROPERTY, 'color'],
290365
[VALUE, 'green'],
291366
[RULE_END],
@@ -322,9 +397,13 @@ body, .foo {
322397
```js
323398
[
324399
[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],
328407
[PROPERTY, 'color'],
329408
[VALUE, 'red']
330409
[RULE_END]
@@ -336,7 +415,7 @@ body, .foo {
336415
```css
337416
.foo {
338417
background: url(http://www.example.org/image);
339-
color: rgb(100, 200, 50 );
418+
color: rgb(100, 200, 50);
340419
content: counter(list-item) ". ";
341420
width: calc(50% - 2em);
342421
}
@@ -347,13 +426,26 @@ body, .foo {
347426
[RULE_START, 1],
348427
[SELECTOR, '.foo'],
349428
[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],
351432
[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],
353438
[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],
355445
[PROPERTY, 'width'],
356-
[VALUE, [FUNCTION, 'calc', '50% - 2em']]
446+
[FUNCTION_START, 'calc'],
447+
[VALUE, '50% - 2em'],
448+
[FUNCTION_END],
357449
[RULE_END]
358450
]
359451
```

0 commit comments

Comments
 (0)