highmark-markdown 0.0.206 → 0.0.209

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.
Files changed (66) hide show
  1. package/example.js +9414 -7797
  2. package/lib/constants.js +13 -1
  3. package/lib/defaultMarkdownStyle.js +14 -0
  4. package/lib/example/constants.js +5 -1
  5. package/lib/example/view/div/preview.js +5 -3
  6. package/lib/example/view/div/sizeable/left.js +2 -2
  7. package/lib/example/view/textarea/{bnf.js → css.js} +17 -17
  8. package/lib/example/view/textarea/{lexicalEntries.js → markdownStyle.js} +25 -19
  9. package/lib/example/view/xmp.js +2 -2
  10. package/lib/example/view.js +30 -21
  11. package/lib/example.js +9 -2
  12. package/lib/index.js +25 -1
  13. package/lib/markdownStyle/bnf.js +14 -0
  14. package/lib/markdownStyle/entries.js +50 -0
  15. package/lib/markdownStyle/lexer.js +162 -0
  16. package/lib/{example/view/div/sizeable/right.js → markdownStyle/parser.js} +46 -34
  17. package/lib/style/declaration.js +72 -0
  18. package/lib/style/declarations.js +89 -0
  19. package/lib/style/division.js +83 -0
  20. package/lib/style/ruleSet.js +85 -0
  21. package/lib/style/ruleSets.js +89 -0
  22. package/lib/style/selector.js +131 -0
  23. package/lib/style/selectors.js +134 -0
  24. package/lib/style/selectorsList.js +128 -0
  25. package/lib/styleElement/markdown/default.js +163 -0
  26. package/lib/styleElement/markdown.js +195 -0
  27. package/lib/styleElement.js +100 -0
  28. package/lib/utilities/content.js +29 -4
  29. package/lib/utilities/css.js +51 -0
  30. package/lib/utilities/entries.js +24 -0
  31. package/lib/utilities/query.js +27 -1
  32. package/package.json +1 -1
  33. package/src/constants.js +3 -0
  34. package/src/defaultMarkdownStyle.js +143 -0
  35. package/src/example/constants.js +1 -0
  36. package/src/example/view/div/preview.js +5 -2
  37. package/src/example/view/div/sizeable/left.js +1 -1
  38. package/src/example/view/textarea/{bnf.js → css.js} +10 -10
  39. package/src/example/view/textarea/markdownStyle.js +41 -0
  40. package/src/example/view/xmp.js +0 -3
  41. package/src/example/view.js +52 -48
  42. package/src/example.js +10 -1
  43. package/src/index.js +6 -0
  44. package/src/markdownStyle/bnf.js +81 -0
  45. package/src/markdownStyle/entries.js +39 -0
  46. package/src/markdownStyle/lexer.js +43 -0
  47. package/src/markdownStyle/parser.js +15 -0
  48. package/src/style/declaration.js +42 -0
  49. package/src/style/declarations.js +64 -0
  50. package/src/style/division.js +46 -0
  51. package/src/style/ruleSet.js +48 -0
  52. package/src/style/ruleSets.js +57 -0
  53. package/src/style/selector.js +126 -0
  54. package/src/style/selectors.js +121 -0
  55. package/src/style/selectorsList.js +95 -0
  56. package/src/styleElement/markdown/default.js +28 -0
  57. package/src/styleElement/markdown.js +48 -0
  58. package/src/styleElement.js +49 -0
  59. package/src/utilities/content.js +27 -0
  60. package/src/utilities/css.js +41 -0
  61. package/src/utilities/entries.js +23 -0
  62. package/src/utilities/query.js +29 -0
  63. package/lib/example/view/textarea/parseTree.js +0 -183
  64. package/src/example/view/div/sizeable/right.js +0 -19
  65. package/src/example/view/textarea/lexicalEntries.js +0 -36
  66. package/src/example/view/textarea/parseTree.js +0 -50
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ import elementMap from "../elementMap";
4
+
5
+ import { ruleNamesExpressionFromElementMap } from "../utilities/entries";
6
+
7
+ const ruleNamesExpression = ruleNamesExpressionFromElementMap(elementMap);
8
+
9
+ const entries = [
10
+ {
11
+ "escaped": "^\\\\[^\\s]"
12
+ },
13
+ {
14
+ "rule-name": `^(?:${ruleNamesExpression})`
15
+ },
16
+ {
17
+ "number": "^(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?"
18
+ },
19
+ {
20
+ "colour": "^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})"
21
+ },
22
+ {
23
+ "unit": "^(?:deg|%)"
24
+ },
25
+ {
26
+ "name": "^[_a-zA-Z0-9]+"
27
+ },
28
+ {
29
+ "bracket": "^(?:\\{|\\})"
30
+ },
31
+ {
32
+ "special": "^(?:,|:|;|-|\\.|\\(|\\)|\\[|\\])"
33
+ },
34
+ {
35
+ "unassigned": "^[^\\s]+"
36
+ }
37
+ ];
38
+
39
+ export default entries;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ import { CommonLexer } from "occam-lexers";
4
+ import { WhitespaceToken,
5
+ EndOfLineNonSignificantToken,
6
+ CStyleSingleLineCommentToken,
7
+ DoublyQuotedStringLiteralToken,
8
+ EndOfLineCommentSignificantToken,
9
+ CStyleEndOfMultiLineCommentToken,
10
+ CStyleStartOfMultiLineCommentToken,
11
+ CStyleMiddleOfMultiLineCommentToken } from "occam-lexers";
12
+
13
+ import entries from "./entries";
14
+
15
+ export default class MarkdownStyleLexer extends CommonLexer {
16
+ static entries = entries;
17
+
18
+ static EndOfLineToken = EndOfLineNonSignificantToken;
19
+
20
+ static WhitespaceToken = WhitespaceToken;
21
+
22
+ static EndOfLineCommentToken = EndOfLineCommentSignificantToken; ///
23
+
24
+ static SingleLineCommentToken = CStyleSingleLineCommentToken; ///
25
+
26
+ static RegularExpressionToken = null;
27
+
28
+ static EndOfMultiLineCommentToken = CStyleEndOfMultiLineCommentToken; ///
29
+
30
+ static StartOfMultiLineCommentToken = CStyleStartOfMultiLineCommentToken; ///
31
+
32
+ static MiddleOfMultiLineCommentToken = CStyleMiddleOfMultiLineCommentToken; ///
33
+
34
+ static SinglyQuotedStringLiteralToken = null;
35
+
36
+ static DoublyQuotedStringLiteralToken = DoublyQuotedStringLiteralToken;
37
+
38
+ static fromNothing() { return CommonLexer.fromNothing(MarkdownStyleLexer); }
39
+
40
+ static fromRules(rules) { return CommonLexer.fromRules(MarkdownStyleLexer, rules); }
41
+
42
+ static fromEntries(entries) { return CommonLexer.fromEntries(MarkdownStyleLexer, entries); }
43
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ import { CommonParser } from "occam-parsers";
4
+
5
+ import bnf from "./bnf";
6
+
7
+ export default class MarkdownStyleParser extends CommonParser {
8
+ static bnf = bnf;
9
+
10
+ static fromNothing() { return CommonParser.fromNothing(MarkdownStyleParser); }
11
+
12
+ static fromBNF(bnf) { return CommonParser.fromBNF(MarkdownStyleParser, bnf); }
13
+
14
+ static fromRules(rules) { return CommonParser.fromRules(MarkdownStyleParser, rules); }
15
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ import { COLOUR } from "../constants";
4
+ import { nodeQuery } from "../utilities/query";
5
+ import { contentFromNodeAndTokens } from "../utilities/content";
6
+
7
+ const nameNonTerminalNodeQuery = nodeQuery("/*/name"),
8
+ valuesNonTerminalNodeQuery = nodeQuery("/*/values");
9
+
10
+ export default class Declaration {
11
+ constructor(name, values) {
12
+ this.name = name;
13
+ this.values = values;
14
+ }
15
+
16
+ getName() {
17
+ return this.name;
18
+ }
19
+
20
+ getValues() {
21
+ return this.values;
22
+ }
23
+
24
+ asCSS() {
25
+ const name = this.name.replace(/colour/g, COLOUR),
26
+ css = ` ${name}: ${this.values};`;
27
+
28
+ return css;
29
+ }
30
+
31
+ static fromNodeAndTokens(node, tokens) {
32
+ const nameNonTerminalNode = nameNonTerminalNodeQuery(node),
33
+ valuesNonTerminalNode = valuesNonTerminalNodeQuery(node),
34
+ nameNonTerminalNodeContent = contentFromNodeAndTokens(nameNonTerminalNode, tokens),
35
+ valuesNonTerminalNodesContent = contentFromNodeAndTokens(valuesNonTerminalNode, tokens),
36
+ name = nameNonTerminalNodeContent, ///
37
+ values = valuesNonTerminalNodesContent, ///
38
+ declaration = new Declaration(name, values);
39
+
40
+ return declaration;
41
+ }
42
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ import Declaration from "./declaration";
4
+
5
+ import { nodesQuery } from "../utilities/query";
6
+ import { EMPTY_STRING } from "../constants";
7
+
8
+ const declarationNonTerminalNodesQuery = nodesQuery("/*/declaration");
9
+
10
+ export default class Declarations {
11
+ constructor(array) {
12
+ this.array = array;
13
+ }
14
+
15
+ getLength() { return this.array.length; }
16
+
17
+ asCSS(selectorsList) {
18
+ let css = EMPTY_STRING;
19
+
20
+ const length = this.getLength(),
21
+ selectorsListLength = selectorsList.getLength();
22
+
23
+ if ((length > 0) && (selectorsListLength > 0)) {
24
+ const declarationsCSS = this.array.reduce((declarationsCSS, declaration) => {
25
+ const declarationCSS = declaration.asCSS();
26
+
27
+ declarationsCSS = (declarationsCSS === null) ?
28
+ declarationCSS : ///
29
+ `${declarationsCSS}
30
+ ${declarationCSS}`;
31
+
32
+ return declarationsCSS;
33
+ }, null),
34
+ selectorsListCSS = selectorsList.asCSS();
35
+
36
+ css = `${selectorsListCSS} {
37
+ ${declarationsCSS}
38
+ }
39
+ `;
40
+ }
41
+
42
+ return css;
43
+ }
44
+
45
+ static fromNothing() {
46
+ const array = [],
47
+ declarations = new Declarations(array);
48
+
49
+ return declarations;
50
+ }
51
+
52
+ static fromNodeAndTokens(node, tokens) {
53
+ const declarationNonTerminalNodes = declarationNonTerminalNodesQuery(node),
54
+ array = declarationNonTerminalNodes.map((declarationNonTerminalNode) => {
55
+ const node = declarationNonTerminalNode, ///
56
+ declaration = Declaration.fromNodeAndTokens(node, tokens);
57
+
58
+ return declaration;
59
+ }),
60
+ declarations = new Declarations(array);
61
+
62
+ return declarations;
63
+ }
64
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ import RuleSets from "./ruleSets";
4
+ import Declarations from "./declarations";
5
+
6
+ import { EMPTY_STRING } from "../constants";
7
+
8
+ export default class Division {
9
+ constructor(ruleSets, declarations, selectorsList) {
10
+ this.ruleSets = ruleSets;
11
+ this.declarations = declarations;
12
+ this.selectorsList = selectorsList;
13
+ }
14
+
15
+ getRuleSets() {
16
+ return this.ruleSets;
17
+ }
18
+
19
+ getDeclarations() {
20
+ return this.declarations;
21
+ }
22
+
23
+ getSelectorsList() {
24
+ return this.selectorsList;
25
+ }
26
+
27
+ asCSS() {
28
+ const outermost = true,
29
+ ruleSetsCSS = this.ruleSets.asCSS(this.selectorsList, outermost),
30
+ declarationsCSS = this.declarations.asCSS(this.selectorsList, outermost),
31
+ css = (declarationsCSS === EMPTY_STRING) ?
32
+ ruleSetsCSS : ///
33
+ `${declarationsCSS}
34
+ ${ruleSetsCSS}`;
35
+
36
+ return css;
37
+ }
38
+
39
+ static fromNodeTokensAndSelectorsList(node, tokens, selectorsList) {
40
+ const ruleSets = RuleSets.fromNodeAndTokens(node, tokens),
41
+ declarations = Declarations.fromNodeAndTokens(node, tokens),
42
+ division = new Division(ruleSets, declarations, selectorsList);
43
+
44
+ return division;
45
+ }
46
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ import Declarations from "./declarations";
4
+ import SelectorsList from "./selectorsList";
5
+
6
+ import { EMPTY_STRING } from "../constants";
7
+
8
+ export default class RuleSet {
9
+ constructor(ruleSets, declarations, selectorsList) {
10
+ this.ruleSets = ruleSets;
11
+ this.declarations = declarations;
12
+ this.selectorsList = selectorsList;
13
+ }
14
+
15
+ getRuleSets() {
16
+ return this.ruleSets;
17
+ }
18
+
19
+ getDeclarations() {
20
+ return this.declarations;
21
+ }
22
+
23
+ getSelectorsList() {
24
+ return this.selectorsList;
25
+ }
26
+
27
+ asCSS(selectorsList, outermost = false) {
28
+ selectorsList = selectorsList.combine(this.selectorsList, outermost); ///
29
+
30
+ const declarationsCSS = this.declarations.asCSS(selectorsList),
31
+ ruleSetsCSS = this.ruleSets.asCSS(selectorsList),
32
+ css = (declarationsCSS === EMPTY_STRING) ?
33
+ ruleSetsCSS : ///
34
+ `${declarationsCSS}
35
+ ${ruleSetsCSS}`;
36
+
37
+ return css;
38
+ }
39
+
40
+ static fromRuleSetsNodeAndTokens(RuleSets, node, tokens) {
41
+ const ruleSets = RuleSets.fromNodeAndTokens(node, tokens),
42
+ declarations = Declarations.fromNodeAndTokens(node, tokens),
43
+ selectorsList = SelectorsList.fromNodeAndTokens(node, tokens),
44
+ ruleSet = new RuleSet(ruleSets, declarations, selectorsList);
45
+
46
+ return ruleSet;
47
+ }
48
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ import RuleSet from "./ruleSet";
4
+
5
+ import { nodesQuery } from "../utilities/query";
6
+ import { EMPTY_STRING } from "../constants";
7
+
8
+ const ruleSetNonTerminalNodesQuery = nodesQuery("/*/ruleSet");
9
+
10
+ export default class RuleSets {
11
+ constructor(array) {
12
+ this.array = array;
13
+ }
14
+
15
+ getLength() { return this.array.length; }
16
+
17
+ asCSS(selectorsList, outermost = false) {
18
+ let css = EMPTY_STRING;
19
+
20
+ const length = this.getLength(),
21
+ selectorsListLength = selectorsList.getLength();
22
+
23
+ if ((length > 0) && (selectorsListLength > 0)) {
24
+ css = this.array.reduce((css, ruleSet) => {
25
+ const ruleSetCSS = ruleSet.asCSS(selectorsList, outermost);
26
+
27
+ css = (css === null) ?
28
+ ruleSetCSS : ///
29
+ `${css}${ruleSetCSS}`;
30
+
31
+ return css;
32
+ }, null);
33
+ }
34
+
35
+ return css;
36
+ }
37
+
38
+ static fromNothing() {
39
+ const array = [],
40
+ ruleSets = new RuleSets(array);
41
+
42
+ return ruleSets;
43
+ }
44
+
45
+ static fromNodeAndTokens(node, tokens) {
46
+ const ruleSetNonTerminalNodes = ruleSetNonTerminalNodesQuery(node),
47
+ array = ruleSetNonTerminalNodes.map((ruleSetNonTerminalNode) => {
48
+ const node = ruleSetNonTerminalNode, ///
49
+ ruleSet = RuleSet.fromRuleSetsNodeAndTokens(RuleSets, node, tokens);
50
+
51
+ return ruleSet;
52
+ }),
53
+ ruleSets = new RuleSets(array);
54
+
55
+ return ruleSets;
56
+ }
57
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ import ruleNames from "../ruleNames";
4
+ import elementMap from "../elementMap";
5
+
6
+ import { nodeQuery } from "../utilities/query";
7
+ import { EMPTY_STRING } from "../constants";
8
+ import { remainingContentFromNodeTokensAndOffset } from "../utilities/content";
9
+
10
+ const { DIVISION_RULE_NAME,
11
+ STRONG_TEXT_RULE_NAME,
12
+ ORDERED_LIST_RULE_NAME,
13
+ UNORDERED_LIST_RULE_NAME,
14
+ ORDERED_LIST_ITEM_RULE_NAME,
15
+ UNORDERED_LIST_ITEM_RULE_NAME,
16
+ STRONGLY_EMPHASISED_TEXT_RULE_NAME } = ruleNames,
17
+ { tagName: strongTextTagName } = elementMap[STRONG_TEXT_RULE_NAME],
18
+ { tagName: orderedListTagName } = elementMap[ORDERED_LIST_RULE_NAME],
19
+ { tagName: unorderedListTagName } = elementMap[UNORDERED_LIST_RULE_NAME];
20
+
21
+ const ruleNameValues = Object.values(ruleNames),
22
+ ruleNameTerminalNodeQuery = nodeQuery("/selector/@rule-name");
23
+
24
+ export default class Selector {
25
+ constructor(content, whitespace) {
26
+ this.content = content;
27
+ this.whitespace = whitespace;
28
+ }
29
+
30
+ getContent() {
31
+ return this.content;
32
+ }
33
+
34
+ hasWhitespace() {
35
+ return this.whitespace;
36
+ }
37
+
38
+ static fromNodeAndTokens(node, tokens) {
39
+ let selector = null;
40
+
41
+ const content = contentFromNodeAndTokens(node, tokens);
42
+
43
+ if (content !== null) {
44
+ const whitespace = whitespaceFromNode(node);
45
+
46
+ selector = new Selector(content, whitespace);
47
+ }
48
+
49
+ return selector;
50
+ }
51
+ }
52
+
53
+ function whitespaceFromNode(node) {
54
+ const ruleNameTerminalNode = ruleNameTerminalNodeQuery(node),
55
+ whitespace = (ruleNameTerminalNode !== null);
56
+
57
+ return whitespace;
58
+ }
59
+
60
+ function contentFromNodeAndTokens(node, tokens) {
61
+ let content;
62
+
63
+ const ruleNameTerminalNode = ruleNameTerminalNodeQuery(node);
64
+
65
+ if (ruleNameTerminalNode !== null) {
66
+ content = EMPTY_STRING;
67
+
68
+ const ruleNameTerminalNodeContent = ruleNameTerminalNode.getContent(),
69
+ ruleName = ruleNameTerminalNodeContent, ///
70
+ ruleNameValuesIncludesRuleName = ruleNameValues.includes(ruleName);
71
+
72
+ if (ruleNameValuesIncludesRuleName) {
73
+ const { tagName, className } = elementMap[ruleName];
74
+
75
+ if (tagName !== null) {
76
+ content = `${content}${tagName}`;
77
+ }
78
+
79
+ switch (ruleName) {
80
+ case DIVISION_RULE_NAME: {
81
+ content = null;
82
+
83
+ break;
84
+ }
85
+
86
+ case ORDERED_LIST_ITEM_RULE_NAME: {
87
+ content = `${orderedListTagName} > ${content}`;
88
+
89
+ break;
90
+ }
91
+
92
+ case UNORDERED_LIST_ITEM_RULE_NAME: {
93
+ content = `${unorderedListTagName} > ${content}`;
94
+
95
+ break;
96
+ }
97
+
98
+ case STRONGLY_EMPHASISED_TEXT_RULE_NAME: {
99
+ content = `${content} > ${strongTextTagName}`;
100
+
101
+ break;
102
+ }
103
+ }
104
+
105
+ if (className !== null) {
106
+ content = `${content}.${className}`;
107
+ }
108
+
109
+ if (ruleName === DIVISION_RULE_NAME) {
110
+ content = null;
111
+ } else {
112
+ const offset = 1,
113
+ remainingContent = remainingContentFromNodeTokensAndOffset(node, tokens, offset);
114
+
115
+ content = `${content}${remainingContent}`;
116
+ }
117
+ }
118
+ } else {
119
+ const offset = 0,
120
+ remainingContent = remainingContentFromNodeTokensAndOffset(node, tokens, offset);
121
+
122
+ content = remainingContent; ///
123
+ }
124
+
125
+ return content;
126
+ }
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ import Selector from "./selector";
6
+
7
+ import { nodesQuery } from "../utilities/query";
8
+
9
+ const selectorNonTerminalNodesQuery = nodesQuery("/selectors/selector");
10
+
11
+ const { first } = arrayUtilities;
12
+
13
+ export default class Selectors {
14
+ constructor(content, whitespace) {
15
+ this.content = content;
16
+ this.whitespace = whitespace;
17
+ }
18
+
19
+ getContent() {
20
+ return this.content;
21
+ }
22
+
23
+ hasWhitespace() {
24
+ return this.whitespace;
25
+ }
26
+
27
+ combine(selectors, outermost = false) {
28
+ if (selectors !== null) {
29
+ const outerSelectors = this, ///
30
+ innerSelectors = selectors, ///
31
+ outerSelectorsContent = outerSelectors.getContent(),
32
+ innerSelectorsContent = innerSelectors.getContent(),
33
+ outerSelectorsWhitespace = outerSelectors.hasWhitespace(),
34
+ innerSelectorsWhitespace = innerSelectors.hasWhitespace();
35
+
36
+ selectors = null;
37
+
38
+ if (outermost && !innerSelectorsWhitespace) {
39
+ ///
40
+ } else {
41
+ if ((outerSelectorsContent !== null) && (innerSelectorsContent !== null)) {
42
+ const content = `${outerSelectorsContent}${innerSelectorsContent}`,
43
+ whitespace = outerSelectorsWhitespace;
44
+
45
+ selectors = Selectors.fromContentAndWhitespace(content, whitespace);
46
+ }
47
+ }
48
+ }
49
+
50
+ return selectors;
51
+ }
52
+
53
+ asCSS() {
54
+ const css = this.content; ///
55
+
56
+ return css;
57
+ }
58
+
59
+ static fromNodeAndTokens(node, tokens) {
60
+ const selectors = selectorsFromNodeAndTokens(node, tokens);
61
+
62
+ return selectors;
63
+ }
64
+
65
+ static fromSelectorsString(selectorsString) {
66
+ const content = selectorsString,
67
+ whitespace = false,
68
+ selectors = new Selectors(content, whitespace);
69
+
70
+ return selectors;
71
+ }
72
+
73
+ static fromContentAndWhitespace(content, whitespace) {
74
+ const selectors = new Selectors(content, whitespace);
75
+
76
+ return selectors;
77
+ }
78
+ }
79
+
80
+ function selectorsFromNodeAndTokens(node, tokens) {
81
+ let selectors = null;
82
+
83
+ const selectorNonTerminalNodes = selectorNonTerminalNodesQuery(node),
84
+ selectorArray = selectorNonTerminalNodes.reduce((selectorArray, selectorNonTerminalNode) => {
85
+ const node = selectorNonTerminalNode, ///
86
+ selector = Selector.fromNodeAndTokens(node, tokens);
87
+
88
+ if (selector !== null) {
89
+ selectorArray.push(selector);
90
+ }
91
+
92
+ return selectorArray;
93
+ }, []),
94
+ selectorsArrayLength = selectorArray.length;
95
+
96
+ if (selectorsArrayLength > 0) {
97
+ const firstSelector = first(selectorArray),
98
+ selector = firstSelector, ///
99
+ content = selectorArray.reduce((content, selector) => {
100
+ const selectorContent = selector.getContent(),
101
+ selectorWhitespace = selector.hasWhitespace();
102
+
103
+ if (content === null) {
104
+ content = selectorWhitespace ?
105
+ ` ${selectorContent}` :
106
+ `${selectorContent}`;
107
+ } else {
108
+ content = selectorWhitespace ?
109
+ `${content} ${selectorContent}` :
110
+ `${content}${selectorContent}`;
111
+ }
112
+
113
+ return content;
114
+ }, null),
115
+ whitespace = selector.hasWhitespace();
116
+
117
+ selectors = new Selectors(content, whitespace);
118
+ }
119
+
120
+ return selectors;
121
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ import Selectors from "./selectors";
4
+
5
+ import { EMPTY_STRING } from "../constants";
6
+ import { nodeQuery, nodesQuery } from "../utilities/query";
7
+
8
+ const selectorsNonTerminalNodesQuery = nodesQuery("/selectorsList/selectors"),
9
+ selectorsListNonTerminalNodeQuery = nodeQuery("/ruleSet/selectorsList");
10
+
11
+ export default class SelectorsList {
12
+ constructor(array) {
13
+ this.array = array;
14
+ }
15
+
16
+ getLength() { return this.array.length; }
17
+
18
+ reduceSelectors(callback, initialValue) { return this.array.reduce(callback, initialValue); }
19
+
20
+ forEachSelectors(callback) { this.array.forEach(callback); }
21
+
22
+ combine(selectorsList, outermost = false) {
23
+ const outerSelectorsList = SelectorsList.fromArray(this.array), ///
24
+ innerSelectorsList = selectorsList, ///
25
+ array = outerSelectorsList.reduceSelectors((array, outerSelectors) => {
26
+ innerSelectorsList.forEachSelectors((innerSelectors) => {
27
+ const selectors = outerSelectors.combine(innerSelectors, outermost);
28
+
29
+ if (selectors !== null) {
30
+ array.push(selectors);
31
+ }
32
+ });
33
+
34
+ return array;
35
+ }, []);
36
+
37
+ selectorsList = SelectorsList.fromArray(array);
38
+
39
+ return selectorsList;
40
+ }
41
+
42
+ asCSS() {
43
+ let css = EMPTY_STRING;
44
+
45
+ const length = this.getLength();
46
+
47
+ if (length > 0) {
48
+ css = this.array.reduce((css, selectors) => {
49
+ const selectorsCSS = selectors.asCSS();
50
+
51
+ css = (css === null) ?
52
+ selectorsCSS : ///
53
+ `${css},
54
+ ${selectorsCSS}`;
55
+
56
+ return css;
57
+ }, null);
58
+ }
59
+
60
+ return css;
61
+ }
62
+
63
+ static fromArray(array) {
64
+ const selectorsList = new SelectorsList(array);
65
+
66
+ return selectorsList;
67
+ }
68
+
69
+ static fromNodeAndTokens(node, tokens) {
70
+ const selectorsListNonTerminalNode = selectorsListNonTerminalNodeQuery(node);
71
+
72
+ node = selectorsListNonTerminalNode; ///
73
+
74
+ const selectorsNonTerminalNodes = selectorsNonTerminalNodesQuery(node),
75
+ array = selectorsNonTerminalNodes.map((selectorsNonTerminalNode) => {
76
+ const node = selectorsNonTerminalNode, ///
77
+ selectors = Selectors.fromNodeAndTokens(node, tokens);
78
+
79
+ return selectors;
80
+ }),
81
+ selectorsList = new SelectorsList(array);
82
+
83
+ return selectorsList;
84
+ }
85
+
86
+ static fromSelectorsString(selectorsString) {
87
+ const selectors = Selectors.fromSelectorsString(selectorsString),
88
+ array = [
89
+ selectors
90
+ ],
91
+ selectorsList = new SelectorsList(array);
92
+
93
+ return selectorsList;
94
+ }
95
+ }