ember-style-modifier 2.0.0 → 3.0.0

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.
@@ -7,31 +7,34 @@ function isObject(o) {
7
7
  return typeof o === 'object' && Boolean(o);
8
8
  }
9
9
 
10
+ /**
11
+ * Returns a two-dimensional array, like:
12
+ *
13
+ * ```js
14
+ * [
15
+ * ['font-size', '16px'],
16
+ * ['text-align', 'center'],
17
+ * ['color', 'red']
18
+ * ]
19
+ * ```
20
+ *
21
+ * This data structure is slightly faster to process than an object / dictionary.
22
+ */
23
+ function compileStyles(positional, named) {
24
+ return [...positional.filter(isObject), named]
25
+ .map((obj) => Object.entries(obj).map(([k, v]) => [dasherize(k), v]))
26
+ .flat();
27
+ }
28
+
10
29
  export default class StyleModifier extends Modifier {
11
- /**
12
- * Returns a two-dimensional array, like:
13
- *
14
- * ```js
15
- * [
16
- * ['font-size', '16px'],
17
- * ['text-align', 'center'],
18
- * ['color', 'red']
19
- * ]
20
- * ```
21
- *
22
- * This data structure is slightly faster to process than an object / dictionary.
23
- */
24
- getStyles(positional, named) {
25
- // This is a workaround for the missing `Array#flat` in IE11.
26
- return [].concat(
27
- ...[...positional.filter(isObject), named].map((obj) =>
28
- Object.entries(obj).map(([k, v]) => [dasherize(k), v])
29
- )
30
- );
31
- }
30
+ existingStyles = new Set();
32
31
 
33
32
  setStyles(element, newStyles) {
34
- const rulesToRemove = this._oldStyles || new Set();
33
+ const { existingStyles } = this;
34
+ const rulesToRemove = new Set(existingStyles);
35
+
36
+ // clear cache of existing styles
37
+ existingStyles.clear();
35
38
 
36
39
  newStyles.forEach(([property, value]) => {
37
40
  assert(
@@ -58,16 +61,16 @@ export default class StyleModifier extends Modifier {
58
61
 
59
62
  // should not remove rules that have been updated in this cycle
60
63
  rulesToRemove.delete(property);
64
+
65
+ // cache styles that have been set for potential clean-up when argument changes
66
+ existingStyles.add(property);
61
67
  });
62
68
 
63
69
  // remove rules that were present in last cycle but aren't present in this one
64
70
  rulesToRemove.forEach((rule) => element.style.removeProperty(rule));
65
-
66
- // cache styles that in this rendering cycle for the next one
67
- this._oldStyles = new Set(newStyles.map((e) => e[0]));
68
71
  }
69
72
 
70
73
  modify(element, positional, named) {
71
- this.setStyles(element, this.getStyles(positional, named));
74
+ this.setStyles(element, compileStyles(positional, named));
72
75
  }
73
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-style-modifier",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "{{style}} modifier to set an element's style using the CSSStyleDeclaration API.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,64 +14,67 @@
14
14
  },
15
15
  "scripts": {
16
16
  "build": "ember build --environment=production",
17
- "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
18
- "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
17
+ "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
18
+ "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
19
19
  "lint:hbs": "ember-template-lint .",
20
20
  "lint:hbs:fix": "ember-template-lint . --fix",
21
21
  "lint:js": "eslint . --cache",
22
22
  "release": "release-it",
23
23
  "lint:js:fix": "eslint . --fix",
24
24
  "start": "ember serve",
25
- "test": "npm-run-all lint test:*",
25
+ "test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
26
26
  "test:ember": "ember test",
27
27
  "test:ember-compatibility": "ember try:each"
28
28
  },
29
29
  "dependencies": {
30
+ "ember-auto-import": "^2.5.0",
30
31
  "ember-cli-babel": "^7.26.11",
31
- "ember-auto-import": "^2.4.2",
32
32
  "ember-modifier": "^3.2.7 || ^4.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@ember/optional-features": "^2.0.0",
36
+ "@ember/string": "^3.0.1",
36
37
  "@ember/test-helpers": "^2.8.1",
37
- "@embroider/test-setup": "^2.0.0",
38
+ "@embroider/test-setup": "^2.0.2",
38
39
  "@glimmer/component": "^1.1.2",
39
40
  "@glimmer/tracking": "^1.1.2",
40
41
  "babel-eslint": "^10.1.0",
41
42
  "broccoli-asset-rev": "^3.0.0",
42
- "ember-cli": "~4.9.0",
43
+ "concurrently": "^7.6.0",
44
+ "ember-cli": "~4.9.2",
43
45
  "ember-cli-content-security-policy": "^2.0.3",
44
46
  "ember-cli-dependency-checker": "^3.3.1",
45
- "ember-cli-htmlbars": "^6.1.0",
47
+ "ember-cli-htmlbars": "^6.1.1",
46
48
  "ember-cli-inject-live-reload": "^2.1.0",
47
49
  "ember-cli-sri": "^2.1.1",
48
50
  "ember-cli-terser": "^4.0.2",
49
- "ember-disable-prototype-extensions": "^1.1.3",
50
51
  "ember-load-initializers": "^2.1.2",
51
52
  "ember-page-title": "^7.0.0",
52
53
  "ember-qunit": "^6.0.0",
53
- "ember-resolver": "^9.0.0",
54
- "ember-source": "~4.9.0",
54
+ "ember-resolver": "^10.0.0",
55
+ "ember-source": "~4.10.0",
55
56
  "ember-source-channel-url": "^3.0.0",
56
- "ember-template-lint": "^5.0.0",
57
+ "ember-template-lint": "^5.2.0",
57
58
  "ember-try": "^2.0.0",
58
59
  "eslint": "^7.32.0",
59
60
  "eslint-config-prettier": "^8.5.0",
60
- "eslint-plugin-ember": "^11.0.6",
61
+ "eslint-plugin-ember": "^11.2.1",
61
62
  "eslint-plugin-node": "^11.1.0",
62
63
  "eslint-plugin-prettier": "^4.2.1",
63
- "eslint-plugin-qunit": "^7.3.1",
64
+ "eslint-plugin-qunit": "^7.3.4",
64
65
  "loader.js": "^4.7.0",
65
- "npm-run-all": "^4.1.5",
66
- "prettier": "^2.7.1",
67
- "qunit": "^2.19.1",
66
+ "prettier": "^2.8.1",
67
+ "qunit": "^2.19.3",
68
68
  "qunit-dom": "^2.0.0",
69
69
  "release-it": "^15.0.0",
70
70
  "release-it-lerna-changelog": "^5.0.0",
71
- "webpack": "^5.74.0"
71
+ "webpack": "^5.75.0"
72
+ },
73
+ "peerDependencies": {
74
+ "@ember/string": "^3.0.1"
72
75
  },
73
76
  "engines": {
74
- "node": "14.* || >= 16"
77
+ "node": "14.* || 16.* || >= 18"
75
78
  },
76
79
  "publishConfig": {
77
80
  "registry": "https://registry.npmjs.org"
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (/* environment, appConfig */) {
4
- return {};
5
- };