with-style 5.0.181 → 5.0.183

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.
@@ -5,35 +5,47 @@ import { Query } from "occam-query";
5
5
  import { EMPTY_STRING } from "../constants";
6
6
  import { contentFromQueryNodeAndTokens } from "../utilities/content";
7
7
 
8
- const priorityQuery = Query.fromExpression("/*/priority"),
9
- propertyQuery = Query.fromExpression("/*/property"),
10
- expressionQuery = Query.fromExpression("/*/expression");
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(property, expression, priority) {
14
- this.property = property;
15
- this.expression = expression;
16
- this.priority = priority;
13
+ constructor(propertyValues, propertyName, important) {
14
+ this.propertyValues = propertyValues;
15
+ this.propertyName = propertyName;
16
+ this.important = important;
17
17
  }
18
18
 
19
- getProperty() {
20
- return this.property;
19
+ getPropertyValues() {
20
+ return this.propertyValues;
21
21
  }
22
22
 
23
- getExpression() {
24
- return this.expression;
23
+ getNameProperty() {
24
+ return this.propertyName;
25
25
  }
26
26
 
27
- getPriority() {
28
- return this.priority;
27
+ getImportant() {
28
+ return this.important;
29
29
  }
30
30
 
31
- checkMatches(declarations) {
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 property = declaration.getProperty(),
34
- propertiesMatch = (property === this.property);
46
+ const matches = this.matchDeclaration(declaration);
35
47
 
36
- if (propertiesMatch) {
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
- `${indent}${this.property}: ${this.expression}${this.priority};` :
47
- `${indent}${this.property}: ${this.expression}${this.priority};\n`;
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 propertyContent = contentFromQueryNodeAndTokens(propertyQuery, node, tokens),
54
- expressionContent = contentFromQueryNodeAndTokens(expressionQuery, node, tokens),
55
- priorityContent = contentFromQueryNodeAndTokens(priorityQuery, node, tokens),
56
- property = propertyContent, ///
57
- expression = expressionContent, ///
58
- priority = (priorityContent === null) ?
59
- EMPTY_STRING :
60
- ` ${priorityContent}`,
61
- declaration = new Declaration(property, expression, priority);
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
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.checkMatches(this.array); ///
25
+ const matches = declaration.matchDeclarations(this); ///
43
26
 
44
27
  if (!matches) {
45
28
  this.array.unshift(declaration);
@@ -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
- if (superStyle !== null) {
55
- style.extends(superStyle);
56
- }
56
+ if (superStyle !== null) {
57
+ style.extends(superStyle);
58
+ }
57
59
 
58
- styleMap[className] = style;
60
+ styleMap[className] = style;
59
61
  }
60
62
 
61
63
  function retrieveStyle(className) {