with-style 5.0.190 → 5.0.191
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 +44 -39
- package/lib/constants.js +2 -4
- package/lib/css/bnf.js +2 -2
- package/lib/css/entries.js +1 -1
- package/lib/example.js +2 -2
- package/lib/style/declaration.js +4 -3
- package/lib/style/declarations.js +6 -19
- package/lib/style/media.js +10 -6
- package/lib/style/medias.js +3 -3
- package/lib/style/ruleSet.js +3 -3
- package/lib/style.js +3 -2
- package/lib/utilities/string.js +12 -0
- package/lib/utilities/styles.js +4 -4
- package/package.json +1 -1
- package/src/constants.js +0 -1
- package/src/css/bnf.js +0 -8
- package/src/css/entries.js +51 -35
- package/src/example.js +10 -0
- package/src/style/declaration.js +5 -5
- package/src/style/declarations.js +9 -27
- package/src/style/media.js +14 -8
- package/src/style/medias.js +2 -2
- package/src/style/ruleSet.js +2 -3
- package/src/style.js +6 -3
- package/src/utilities/string.js +9 -0
- package/src/utilities/styles.js +7 -7
package/src/css/entries.js
CHANGED
|
@@ -1,41 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const entries = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
|
|
4
|
+
{
|
|
5
|
+
"media": "^@media"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"colour": "^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"important": "^!important"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"percentage": "^(?:[0-9]+|[0-9]*\\.[0-9]+)%"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"frequency": "^(?:[0-9]+|[0-9]*\\.[0-9]+)(?:hz|khz)"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"fraction": "^[1-9][0-9]*?fr"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"length": "^(?:[0-9]+|[0-9]*\\.[0-9]+)(?:px|cm|mm|in|pt|pc)"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"angle": "^(?:[0-9]+|[0-9]*\\.[0-9]+)(?:deg|rad|grad)"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"time": "^(?:[0-9]+|[0-9]*\\.[0-9]+)(?:s|ms)"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"rems": "^(?:[0-9]+|[0-9]*\\.[0-9]+)rem"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"ems": "^(?:[0-9]+|[0-9]*\\.[0-9]+)em"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"number": "^[0-9]+|[0-9]*\\.[0-9]+"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"special": "^;|::|:|\\.|,|\\|=|~=|=|>|\\{|\\}|\\(|\\)|\\[|\\]"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"identifier": "^[_a-zA-Z0-9-]+"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"logical-operator": "^^(?:and|not)$"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"plus-or-minus": "^\\+|-"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"unassigned": "^[^\\s]+"
|
|
54
|
+
}
|
|
39
55
|
];
|
|
40
56
|
|
|
41
57
|
export default entries;
|
package/src/example.js
CHANGED
package/src/style/declaration.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Query } from "occam-query";
|
|
4
4
|
|
|
5
|
-
import { EMPTY_STRING } from "../constants";
|
|
5
|
+
import { EMPTY_STRING, TWO_SPACES } from "../constants";
|
|
6
6
|
import { contentFromQueryNodeAndTokens } from "../utilities/content";
|
|
7
7
|
|
|
8
8
|
const importantQuery = Query.fromExpression("/*/important"),
|
|
@@ -53,10 +53,10 @@ export default class Declaration {
|
|
|
53
53
|
return matches;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
asCSS(indent
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
asCSS(indent) {
|
|
57
|
+
indent = indent + TWO_SPACES;
|
|
58
|
+
|
|
59
|
+
const css = `${indent}${this.propertyName}: ${this.propertyValues}${this.important};\n`;
|
|
60
60
|
|
|
61
61
|
return css;
|
|
62
62
|
}
|
|
@@ -33,37 +33,19 @@ export default class Declarations {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
asCSS(className, indent) {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const declarationsCSS = this.array.reduce((declarationsCSS, declaration) => {
|
|
37
|
+
const declarationCSS = declaration.asCSS(indent);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
}
|
|
39
|
+
declarationsCSS += declarationCSS;
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
declarationsCSS = this.array.reduce((declarationsCSS, declaration, index) => {
|
|
49
|
-
const last = (index === lastIndex),
|
|
50
|
-
declarationCSS = declaration.asCSS(indent, last);
|
|
51
|
-
|
|
52
|
-
declarationsCSS += declarationCSS;
|
|
53
|
-
|
|
54
|
-
return declarationsCSS;
|
|
55
|
-
}, EMPTY_STRING);
|
|
56
|
-
|
|
57
|
-
if (className === null) {
|
|
58
|
-
css = declarationsCSS; ///
|
|
59
|
-
} else {
|
|
60
|
-
css = `.${className} {
|
|
61
|
-
${declarationsCSS}
|
|
62
|
-
}
|
|
41
|
+
return declarationsCSS;
|
|
42
|
+
}, EMPTY_STRING),
|
|
43
|
+
css = (className === null) ?
|
|
44
|
+
declarationsCSS : ///
|
|
45
|
+
`${indent}.${className} {
|
|
46
|
+
${declarationsCSS}${indent}}
|
|
63
47
|
|
|
64
48
|
`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
49
|
|
|
68
50
|
return css;
|
|
69
51
|
}
|
package/src/style/media.js
CHANGED
|
@@ -5,7 +5,8 @@ import { Query } from "occam-query";
|
|
|
5
5
|
import RuleSets from "./ruleSets";
|
|
6
6
|
import Declarations from "./declarations";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { trim } from "../utilities/string";
|
|
9
|
+
import { TWO_SPACES, EMPTY_STRING } from "../constants";
|
|
9
10
|
import { contentFromQueryNodeAndTokens } from "../utilities/content";
|
|
10
11
|
|
|
11
12
|
const queriesQuery = Query.fromExpression("/media/mediaQueries"); ///
|
|
@@ -29,16 +30,21 @@ export default class Media {
|
|
|
29
30
|
return this.queries;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
asCSS(className) {
|
|
33
|
-
|
|
33
|
+
asCSS(className, indent) {
|
|
34
|
+
indent = indent + TWO_SPACES;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
let css = EMPTY_STRING;
|
|
37
|
+
|
|
38
|
+
const ruleSetsCSS = this.ruleSets.asCSS(className, indent),
|
|
39
|
+
declarationsCSS = this.declarations.asCSS(className, indent);
|
|
40
|
+
|
|
41
|
+
let ruleSetsDeclarationsCSS = `${declarationsCSS}${ruleSetsCSS}`;
|
|
42
|
+
|
|
43
|
+
if (ruleSetsDeclarationsCSS !== EMPTY_STRING) {
|
|
44
|
+
ruleSetsDeclarationsCSS = trim(ruleSetsDeclarationsCSS);
|
|
37
45
|
|
|
38
|
-
if ((ruleSetsCSS !== null) || (declarationsCSS !== null)) {
|
|
39
46
|
css = `@media ${this.queries} {
|
|
40
|
-
${
|
|
41
|
-
}
|
|
47
|
+
${ruleSetsDeclarationsCSS}}
|
|
42
48
|
|
|
43
49
|
`;
|
|
44
50
|
}
|
package/src/style/medias.js
CHANGED
|
@@ -23,9 +23,9 @@ export default class Medias {
|
|
|
23
23
|
this.array.forEach(callback);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
asCSS(className) {
|
|
26
|
+
asCSS(className, indent) {
|
|
27
27
|
const css = this.array.reduce((css, media) => {
|
|
28
|
-
const mediaCSS = media.asCSS(className);
|
|
28
|
+
const mediaCSS = media.asCSS(className, indent);
|
|
29
29
|
|
|
30
30
|
css += mediaCSS;
|
|
31
31
|
|
package/src/style/ruleSet.js
CHANGED
|
@@ -46,12 +46,11 @@ export default class RuleSet {
|
|
|
46
46
|
asCSS(className, indent) {
|
|
47
47
|
let css = EMPTY_STRING;
|
|
48
48
|
|
|
49
|
-
const declarationsCSS = this.declarations.asCSS(
|
|
49
|
+
const declarationsCSS = this.declarations.asCSS(null, indent);
|
|
50
50
|
|
|
51
51
|
if (declarationsCSS !== EMPTY_STRING) {
|
|
52
52
|
css = `${indent}.${className}${this.selectors} {
|
|
53
|
-
${declarationsCSS}
|
|
54
|
-
${indent}}
|
|
53
|
+
${declarationsCSS}${indent}}
|
|
55
54
|
|
|
56
55
|
`;
|
|
57
56
|
}
|
package/src/style.js
CHANGED
|
@@ -4,6 +4,8 @@ import Medias from "./style/medias";
|
|
|
4
4
|
import RuleSets from "./style/ruleSets";
|
|
5
5
|
import Declarations from "./style/declarations";
|
|
6
6
|
|
|
7
|
+
import { EMPTY_STRING } from "./constants";
|
|
8
|
+
|
|
7
9
|
export default class Style {
|
|
8
10
|
constructor(declarations, ruleSets, medias) {
|
|
9
11
|
this.declarations = declarations;
|
|
@@ -38,9 +40,10 @@ export default class Style {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
asCSS(className) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const indent = EMPTY_STRING,
|
|
44
|
+
declarationsCSS = this.declarations.asCSS(className, indent),
|
|
45
|
+
ruleSetsCSS = this.ruleSets.asCSS(className, indent),
|
|
46
|
+
mediasCSS = this.medias.asCSS(className, indent),
|
|
44
47
|
css = `${declarationsCSS}${ruleSetsCSS}${mediasCSS}`;
|
|
45
48
|
|
|
46
49
|
return css;
|
package/src/utilities/styles.js
CHANGED
|
@@ -18,9 +18,9 @@ const { styleMap } = globalThis;
|
|
|
18
18
|
function renderStyle(style) {
|
|
19
19
|
const headDOMElement = document.querySelector(HEAD),
|
|
20
20
|
styleDOMElement = document.createElement(STYLE),
|
|
21
|
-
innerHTML = `
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
innerHTML = `
|
|
22
|
+
${style}
|
|
23
|
+
`;
|
|
24
24
|
|
|
25
25
|
Object.assign(styleDOMElement, {
|
|
26
26
|
innerHTML
|
|
@@ -41,11 +41,11 @@ function renderStyles() {
|
|
|
41
41
|
function generateStyle(args, className, superStyle = null) {
|
|
42
42
|
const strings = args.shift(), ///
|
|
43
43
|
content = strings.reduce((content, string, index) => {
|
|
44
|
-
const arg = args[index];
|
|
44
|
+
const arg = args[index] || null;
|
|
45
45
|
|
|
46
|
-
content = (arg
|
|
47
|
-
`${content}${string}
|
|
48
|
-
`${content}${string}`;
|
|
46
|
+
content = (arg === null) ?
|
|
47
|
+
`${content}${string}` :
|
|
48
|
+
`${content}${string}${arg}`;
|
|
49
49
|
|
|
50
50
|
return content;
|
|
51
51
|
}, EMPTY_STRING),
|