ember-style-modifier 1.0.0 → 2.1.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.
- package/addon/modifiers/style.js +29 -26
- package/package.json +22 -20
- package/config/environment.js +0 -5
package/addon/modifiers/style.js
CHANGED
|
@@ -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
|
|
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,
|
|
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": "1.0
|
|
3
|
+
"version": "2.1.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,66 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "ember build --environment=production",
|
|
17
|
-
"lint": "
|
|
18
|
-
"lint:fix": "npm
|
|
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
|
|
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-modifier": "^3.2.7"
|
|
32
|
+
"ember-modifier": "^3.2.7 || ^4.0.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@ember/optional-features": "^2.0.0",
|
|
35
36
|
"@ember/test-helpers": "^2.8.1",
|
|
36
|
-
"@embroider/test-setup": "^
|
|
37
|
+
"@embroider/test-setup": "^2.0.2",
|
|
37
38
|
"@glimmer/component": "^1.1.2",
|
|
38
39
|
"@glimmer/tracking": "^1.1.2",
|
|
39
40
|
"babel-eslint": "^10.1.0",
|
|
40
41
|
"broccoli-asset-rev": "^3.0.0",
|
|
41
|
-
"
|
|
42
|
-
"ember-cli": "~4.
|
|
42
|
+
"concurrently": "^7.6.0",
|
|
43
|
+
"ember-cli": "~4.9.2",
|
|
43
44
|
"ember-cli-content-security-policy": "^2.0.3",
|
|
44
45
|
"ember-cli-dependency-checker": "^3.3.1",
|
|
45
|
-
"ember-cli-htmlbars": "^6.1.
|
|
46
|
+
"ember-cli-htmlbars": "^6.1.1",
|
|
46
47
|
"ember-cli-inject-live-reload": "^2.1.0",
|
|
47
48
|
"ember-cli-sri": "^2.1.1",
|
|
48
49
|
"ember-cli-terser": "^4.0.2",
|
|
49
|
-
"ember-disable-prototype-extensions": "^1.1.3",
|
|
50
50
|
"ember-load-initializers": "^2.1.2",
|
|
51
51
|
"ember-page-title": "^7.0.0",
|
|
52
52
|
"ember-qunit": "^6.0.0",
|
|
53
|
-
"ember-resolver": "^
|
|
54
|
-
"ember-source": "~4.
|
|
53
|
+
"ember-resolver": "^10.0.0",
|
|
54
|
+
"ember-source": "~4.9.1",
|
|
55
55
|
"ember-source-channel-url": "^3.0.0",
|
|
56
|
-
"ember-template-lint": "^
|
|
56
|
+
"ember-template-lint": "^5.2.0",
|
|
57
57
|
"ember-try": "^2.0.0",
|
|
58
58
|
"eslint": "^7.32.0",
|
|
59
59
|
"eslint-config-prettier": "^8.5.0",
|
|
60
|
-
"eslint-plugin-ember": "^11.
|
|
60
|
+
"eslint-plugin-ember": "^11.2.1",
|
|
61
61
|
"eslint-plugin-node": "^11.1.0",
|
|
62
62
|
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
-
"eslint-plugin-qunit": "^7.3.
|
|
63
|
+
"eslint-plugin-qunit": "^7.3.4",
|
|
64
64
|
"loader.js": "^4.7.0",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"qunit": "^2.19.1",
|
|
65
|
+
"prettier": "^2.8.1",
|
|
66
|
+
"qunit": "^2.19.3",
|
|
68
67
|
"qunit-dom": "^2.0.0",
|
|
69
68
|
"release-it": "^15.0.0",
|
|
70
69
|
"release-it-lerna-changelog": "^5.0.0",
|
|
71
|
-
"webpack": "^5.
|
|
70
|
+
"webpack": "^5.75.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"ember-source": "^3.28.0 || ^4.0.0"
|
|
72
74
|
},
|
|
73
75
|
"engines": {
|
|
74
|
-
"node": "14.* || >=
|
|
76
|
+
"node": "14.* || 16.* || >= 18"
|
|
75
77
|
},
|
|
76
78
|
"publishConfig": {
|
|
77
79
|
"registry": "https://registry.npmjs.org"
|