with-style 5.0.180 → 5.0.182
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/example.js +107 -1963
- package/lib/css/bnf.js +2 -2
- package/lib/style/declaration.js +38 -24
- package/lib/style/declarations.js +10 -16
- package/lib/style/media.js +3 -3
- package/lib/style/medias.js +3 -3
- package/lib/style/ruleSet.js +3 -3
- package/lib/style/ruleSets.js +3 -3
- package/lib/utilities/styles.js +2 -1
- package/package.json +2 -2
- package/src/css/bnf.js +21 -33
- package/src/style/declaration.js +41 -29
- package/src/style/declarations.js +7 -24
- package/src/style/media.js +1 -1
- package/src/style/medias.js +1 -1
- package/src/style/ruleSet.js +1 -1
- package/src/style/ruleSets.js +1 -1
- package/src/utilities/styles.js +6 -4
package/src/css/bnf.js
CHANGED
|
@@ -2,45 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
const bnf = `
|
|
4
4
|
|
|
5
|
+
stylesheet ::= ( media | ruleSet | declaration | error )+ ;
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
stylesheet ::= ( media | ruleSet | declaration | error )+ ;
|
|
8
8
|
|
|
9
|
+
media ::= "@media" mediaQueries "{" ( ruleSet | declaration )* "}" ;
|
|
10
|
+
|
|
11
|
+
ruleSet ::= selectors "{" declaration* "}" ;
|
|
12
|
+
|
|
13
|
+
declaration ::= propertyName ":" propertyValues important? ";" ;
|
|
9
14
|
|
|
15
|
+
error! ::= . ;
|
|
10
16
|
|
|
11
17
|
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
propertyValues ::= propertyValue ( "," propertyValue )* ;
|
|
20
|
+
|
|
21
|
+
|
|
16
22
|
mediaQueries ::= mediaQuery ( "," mediaQuery )* ;
|
|
17
23
|
|
|
18
24
|
|
|
25
|
+
selectors ::= selector ( "," selector )* ;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
19
29
|
mediaQuery ::= "not"? ( "only"? mediaType "and" )? mediaExpression ( "and" mediaExpression )* ;
|
|
20
30
|
|
|
21
31
|
|
|
22
32
|
mediaType ::= "all" | "print" | "screen" | "speech" ;
|
|
23
33
|
|
|
24
34
|
|
|
25
|
-
mediaExpression ::= "(" [identifier] ( ":"
|
|
35
|
+
mediaExpression ::= "(" [identifier] ( ":" propertyValue )? ")" ;
|
|
26
36
|
|
|
27
37
|
|
|
28
38
|
|
|
39
|
+
propertyValue ::= term ( ","? term )* ;
|
|
29
40
|
|
|
30
41
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
selectors ::= selector ( "," selector )* ;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
selector ::= ( class | pseudoClass | pseudoElement | attribute )+ ;
|
|
42
|
+
propertyName ::= [identifier] ;
|
|
38
43
|
|
|
39
44
|
|
|
45
|
+
important ::= "!important" ;
|
|
40
46
|
|
|
41
47
|
|
|
48
|
+
selector ::= ( class | pseudoClass | pseudoElement | attribute )+ ;
|
|
42
49
|
|
|
43
|
-
declaration ::= property ":" expression ( "," expression )* priority? ";" ;
|
|
44
50
|
|
|
45
51
|
|
|
46
52
|
class ::= "."<NO_WHITESPACE>[identifier] parenthesisedSelector? ;
|
|
@@ -55,6 +61,7 @@ const bnf = `
|
|
|
55
61
|
parenthesisedSelector ::= <NO_WHITESPACE>"(" selector <NO_WHITESPACE>")" ;
|
|
56
62
|
|
|
57
63
|
|
|
64
|
+
|
|
58
65
|
attribute ::= "["
|
|
59
66
|
|
|
60
67
|
[identifier]
|
|
@@ -72,17 +79,6 @@ const bnf = `
|
|
|
72
79
|
;
|
|
73
80
|
|
|
74
81
|
|
|
75
|
-
property ::= [identifier] ;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
expression ::= term ( ","? term )* ;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
priority ::= "!important" ;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
82
|
|
|
87
83
|
term ::= [arithmetic-operator]?
|
|
88
84
|
|
|
@@ -118,15 +114,7 @@ const bnf = `
|
|
|
118
114
|
uri ::= "url"<NO_WHITESPACE>"(" [string-literal] ")" ;
|
|
119
115
|
|
|
120
116
|
|
|
121
|
-
function ::= [identifier]<NO_WHITESPACE>"("
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
error! ::= . ;
|
|
128
|
-
|
|
129
|
-
|
|
117
|
+
function ::= [identifier]<NO_WHITESPACE>"(" propertyValue ")" ;
|
|
130
118
|
|
|
131
119
|
`;
|
|
132
120
|
|
package/src/style/declaration.js
CHANGED
|
@@ -1,39 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { Query } from "occam-
|
|
3
|
+
import { Query } from "occam-query";
|
|
4
4
|
|
|
5
5
|
import { EMPTY_STRING } from "../constants";
|
|
6
6
|
import { contentFromQueryNodeAndTokens } from "../utilities/content";
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const importantQuery = Query.fromExpression("/*/important"),
|
|
9
|
+
propertyNameQuery = Query.fromExpression("/*/propertyName"),
|
|
10
|
+
propertyValuesQuery = Query.fromExpression("/*/propertyValues");
|
|
11
11
|
|
|
12
12
|
export default class Declaration {
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
13
|
+
constructor(propertyValues, propertyName, important) {
|
|
14
|
+
this.propertyValues = propertyValues;
|
|
15
|
+
this.propertyName = propertyName;
|
|
16
|
+
this.important = important;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
return this.
|
|
19
|
+
getPropertyValues() {
|
|
20
|
+
return this.propertyValues;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
return this.
|
|
23
|
+
getNameProperty() {
|
|
24
|
+
return this.propertyName;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
return this.
|
|
27
|
+
getImportant() {
|
|
28
|
+
return this.important;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
matchPropertyName(propertyName) {
|
|
32
|
+
const matches = (this.propertyName === propertyName);
|
|
33
|
+
|
|
34
|
+
return matches;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
matchDeclaration(declaration) {
|
|
38
|
+
const propertyName = declaration.getPropertyName(),
|
|
39
|
+
matches = this.matchPropertyName(propertyName); ///
|
|
40
|
+
|
|
41
|
+
return matches;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
matchDeclarations(declarations) {
|
|
32
45
|
const matches = declarations.some((declaration) => {
|
|
33
|
-
const
|
|
34
|
-
propertiesMatch = (property === this.property);
|
|
46
|
+
const matches = this.matchDeclaration(declaration);
|
|
35
47
|
|
|
36
|
-
if (
|
|
48
|
+
if (matches) {
|
|
37
49
|
return true;
|
|
38
50
|
}
|
|
39
51
|
});
|
|
@@ -43,22 +55,22 @@ export default class Declaration {
|
|
|
43
55
|
|
|
44
56
|
asCSS(indent, last) {
|
|
45
57
|
const css = last ?
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
`${indent}${this.propertyName}: ${this.propertyValues}${this.important};` :
|
|
59
|
+
`${indent}${this.propertyName}: ${this.propertyValues}${this.important};\n`;
|
|
48
60
|
|
|
49
61
|
return css;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
static fromNodeAndTokens(node, tokens) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
declaration = new Declaration(
|
|
65
|
+
const propertyValuesContent = contentFromQueryNodeAndTokens(propertyValuesQuery, node, tokens),
|
|
66
|
+
propertyNameContent = contentFromQueryNodeAndTokens(propertyNameQuery, node, tokens),
|
|
67
|
+
importantContent = contentFromQueryNodeAndTokens(importantQuery, node, tokens),
|
|
68
|
+
propertyValues = propertyValuesContent, ///
|
|
69
|
+
propertyName = propertyNameContent, ///
|
|
70
|
+
important = (importantContent === null) ?
|
|
71
|
+
EMPTY_STRING :
|
|
72
|
+
` ${importantContent}`,
|
|
73
|
+
declaration = new Declaration(propertyValues, propertyName, important);
|
|
62
74
|
|
|
63
75
|
return declaration;
|
|
64
76
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { Query } from "occam-
|
|
3
|
+
import { Query } from "occam-query";
|
|
4
|
+
import { arrayUtilities } from "necessary";
|
|
4
5
|
|
|
5
6
|
import Declaration from "./declaration";
|
|
6
7
|
|
|
7
8
|
import { EMPTY_STRING } from "../constants";
|
|
8
9
|
|
|
10
|
+
const { forwardsForEach, backwardsForEach } = arrayUtilities;
|
|
11
|
+
|
|
9
12
|
const declarationQuery = Query.fromExpression("/*/declaration");
|
|
10
13
|
|
|
11
14
|
export default class Declarations {
|
|
@@ -13,33 +16,13 @@ export default class Declarations {
|
|
|
13
16
|
this.array = array;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
forwardsForEach(callback) {
|
|
17
|
-
const length = this.array.length,
|
|
18
|
-
firstIndex = 0,
|
|
19
|
-
lastIndex = length - 1;
|
|
20
|
-
|
|
21
|
-
for (let index = firstIndex; index <= lastIndex; index++) {
|
|
22
|
-
const declaration = this.array[index];
|
|
23
|
-
|
|
24
|
-
callback(declaration, index);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
19
|
+
forwardsForEach(callback) { forwardsForEach(this.array, callback); }
|
|
27
20
|
|
|
28
|
-
backwardsForEach(callback) {
|
|
29
|
-
const length = this.array.length,
|
|
30
|
-
firstIndex = 0,
|
|
31
|
-
lastIndex = length - 1;
|
|
32
|
-
|
|
33
|
-
for (let index = lastIndex; index >= firstIndex; index--) {
|
|
34
|
-
const declaration = this.array[index];
|
|
35
|
-
|
|
36
|
-
callback(declaration, index);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
21
|
+
backwardsForEach(callback) { backwardsForEach(this.array, callback); }
|
|
39
22
|
|
|
40
23
|
unshift(declarations) {
|
|
41
24
|
declarations.backwardsForEach((declaration) => {
|
|
42
|
-
const matches = declaration.
|
|
25
|
+
const matches = declaration.matchDeclarations(this); ///
|
|
43
26
|
|
|
44
27
|
if (!matches) {
|
|
45
28
|
this.array.unshift(declaration);
|
package/src/style/media.js
CHANGED
package/src/style/medias.js
CHANGED
package/src/style/ruleSet.js
CHANGED
package/src/style/ruleSets.js
CHANGED
package/src/utilities/styles.js
CHANGED
|
@@ -27,6 +27,8 @@ ${style}`;
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
headDOMElement.appendChild(styleDOMElement);
|
|
30
|
+
|
|
31
|
+
return styleDOMElement;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
function renderStyles() {
|
|
@@ -51,11 +53,11 @@ function generateStyle(args, className, superStyle = null) {
|
|
|
51
53
|
node = cssParser.parse(tokens),
|
|
52
54
|
style = Style.fromNodeAndTokens(node, tokens);
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if (superStyle !== null) {
|
|
57
|
+
style.extends(superStyle);
|
|
58
|
+
}
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
styleMap[className] = style;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function retrieveStyle(className) {
|