ember-style-modifier 4.4.0 → 4.6.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/README.md
CHANGED
|
@@ -10,8 +10,7 @@ This allows to set custom CSS of an element without requiring a [Content Securit
|
|
|
10
10
|
## Compatibility
|
|
11
11
|
|
|
12
12
|
* Ember.js v3.28 or above
|
|
13
|
-
*
|
|
14
|
-
* Node.js v18 or above
|
|
13
|
+
* Embroider or ember-auto-import v2
|
|
15
14
|
|
|
16
15
|
## Installation
|
|
17
16
|
|
|
@@ -26,6 +25,25 @@ argument. Property names are supported in dasherized as well as in camelCase
|
|
|
26
25
|
spelling. Value must be a string or `undefined`. You may set a priority by
|
|
27
26
|
adding an `"!important"` suffix.
|
|
28
27
|
|
|
28
|
+
```gjs
|
|
29
|
+
import style from 'ember-style-modifier';
|
|
30
|
+
|
|
31
|
+
<p
|
|
32
|
+
{{style
|
|
33
|
+
border="1px"
|
|
34
|
+
padding="1em !important"
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<p
|
|
40
|
+
{{style
|
|
41
|
+
(hash border="1px" padding="1em !important")
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
</p>
|
|
45
|
+
```
|
|
46
|
+
|
|
29
47
|
```hbs
|
|
30
48
|
<p
|
|
31
49
|
{{style
|
package/addon-main.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../src/modifiers/style.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../src/modifiers/style.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAGtC,OAAO,KAAK,KAAK,GAAG,MAAM,SAAS,CAAC;AAMpC,KAAK,SAAS,GACV,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GACvB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAC7B;IAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM,CAAA;CAAE,CAAC;AAuC9C,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,GAAG,qBAAqB,CAAC;IACzC,IAAI,EAAE;QACJ,UAAU,EAAE,SAAS,EAAE,CAAC;QACxB,KAAK,EAAE,SAAS,CAAC;KAClB,CAAC;CACH;AAED,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,QAAQ,CAAC,sBAAsB,CAAC;IACzE,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAExC,SAAS,CACP,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,EAC1C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IAuC/B,MAAM,CACJ,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,EAC1C,UAAU,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAC5B,KAAK,EAAE,SAAS;CAInB"}
|
package/dist/modifiers/style.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Modifier from 'ember-modifier';
|
|
2
|
-
import { dasherize } from '@ember/string';
|
|
3
2
|
import { assert } from '@ember/debug';
|
|
4
3
|
import { typeOf } from '@ember/utils';
|
|
5
4
|
|
|
@@ -11,6 +10,11 @@ import { typeOf } from '@ember/utils';
|
|
|
11
10
|
function isObject(o) {
|
|
12
11
|
return typeof o === 'object' && Boolean(o);
|
|
13
12
|
}
|
|
13
|
+
const DASHERIZE_REGEX = /([a-z\d])([A-Z])/g;
|
|
14
|
+
const DASHERIZE_REPLACEMENT = '$1-$2';
|
|
15
|
+
function dasherize(str) {
|
|
16
|
+
return str.replace(DASHERIZE_REGEX, DASHERIZE_REPLACEMENT).toLowerCase();
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* Returns a two-dimensional array, like:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sources":["../../src/modifiers/style.ts"],"sourcesContent":["import Modifier from 'ember-modifier';\nimport {
|
|
1
|
+
{"version":3,"file":"style.js","sources":["../../src/modifiers/style.ts"],"sourcesContent":["import Modifier from 'ember-modifier';\nimport { assert } from '@ember/debug';\nimport { typeOf } from '@ember/utils';\nimport type * as CSS from 'csstype';\n\n// Cannot be typed as `Partial<CSSStyleDeclaration>` because `CSSStyleDeclaration`\n// interface does _not_ included dashed CSS property names. It only includes the\n// camelCase version of a CSS property.\n// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1672\ntype CSSStyles =\n | Partial<CSS.Properties>\n | Partial<CSS.PropertiesHyphen>\n | { readonly [key: `--${string}`]: string };\n\nfunction isObject(o: unknown): boolean {\n return typeof o === 'object' && Boolean(o);\n}\n\nconst DASHERIZE_REGEX = /([a-z\\d])([A-Z])/g;\nconst DASHERIZE_REPLACEMENT = '$1-$2';\n\nfunction dasherize(str: string): string {\n return str.replace(DASHERIZE_REGEX, DASHERIZE_REPLACEMENT).toLowerCase();\n}\n\n/**\n * Returns a two-dimensional array, like:\n *\n * ```js\n * [\n * ['font-size', '16px'],\n * ['text-align', 'center'],\n * ['color', 'red']\n * ]\n * ```\n *\n * This data structure is slightly faster to process than an object / dictionary.\n */\nfunction compileStyles(\n positional: CSSStyles[],\n named: CSSStyles,\n): [string, string][] {\n return [...positional.filter(isObject), named]\n .map((obj) =>\n Object.entries(obj).map(\n ([k, v]) => [dasherize(k), v] as [string, string],\n ),\n )\n .flat();\n}\n\nexport interface StyleModifierSignature {\n Element: Element & ElementCSSInlineStyle;\n Args: {\n Positional: CSSStyles[];\n Named: CSSStyles;\n };\n}\n\nexport default class StyleModifier extends Modifier<StyleModifierSignature> {\n existingStyles: Set<string> = new Set();\n\n setStyles(\n element: StyleModifierSignature['Element'],\n newStyles: [string, string][],\n ) {\n const { existingStyles } = this;\n const rulesToRemove: Set<string> = new Set(existingStyles);\n\n // clear cache of existing styles\n existingStyles.clear();\n\n newStyles.forEach(([property, value]) => {\n assert(\n `Your given value for property '${property}' is ${value} (${typeOf(\n value,\n )}). ` +\n 'Accepted types are string and undefined. Please change accordingly.',\n typeof value === 'undefined' || typeOf(value) === 'string',\n );\n\n // priority must be specified as separate argument\n // value must not contain \"!important\"\n let priority = '';\n if (value && value.includes('!important')) {\n priority = 'important';\n value = value.replace('!important', '');\n }\n\n // update CSSOM\n element.style.setProperty(property, value, priority);\n\n // should not remove rules that have been updated in this cycle\n rulesToRemove.delete(property);\n\n // cache styles that have been set for potential clean-up when argument changes\n existingStyles.add(property);\n });\n\n // remove rules that were present in last cycle but aren't present in this one\n rulesToRemove.forEach((rule) => element.style.removeProperty(rule));\n }\n\n modify(\n element: StyleModifierSignature['Element'],\n positional: [CSSStyles] | [],\n named: CSSStyles,\n ) {\n this.setStyles(element, compileStyles(positional, named));\n }\n}\n"],"names":["isObject","o","Boolean","DASHERIZE_REGEX","DASHERIZE_REPLACEMENT","dasherize","str","replace","toLowerCase","compileStyles","positional","named","filter","map","obj","Object","entries","k","v","flat","StyleModifier","Modifier","existingStyles","Set","setStyles","element","newStyles","rulesToRemove","clear","forEach","property","value","assert","typeOf","priority","includes","style","setProperty","delete","add","rule","removeProperty","modify"],"mappings":";;;;AAKA;AACA;AACA;AACA;;AAMA,SAASA,QAAQA,CAACC,CAAU,EAAW;EACrC,OAAO,OAAOA,CAAC,KAAK,QAAQ,IAAIC,OAAO,CAACD,CAAC,CAAC;AAC5C;AAEA,MAAME,eAAe,GAAG,mBAAmB;AAC3C,MAAMC,qBAAqB,GAAG,OAAO;AAErC,SAASC,SAASA,CAACC,GAAW,EAAU;EACtC,OAAOA,GAAG,CAACC,OAAO,CAACJ,eAAe,EAAEC,qBAAqB,CAAC,CAACI,WAAW,EAAE;AAC1E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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AACP,QAAQ,EAAEC,KAAK,EAAEG,QAAQ,CAAC;;AAEpD;AACAP,MAAAA,aAAa,CAACW,MAAM,CAACR,QAAQ,CAAC;;AAE9B;AACAR,MAAAA,cAAc,CAACiB,GAAG,CAACT,QAAQ,CAAC;AAC9B,IAAA,CAAC,CAAC;;AAEF;AACAH,IAAAA,aAAa,CAACE,OAAO,CAAEW,IAAI,IAAKf,OAAO,CAACW,KAAK,CAACK,cAAc,CAACD,IAAI,CAAC,CAAC;AACrE,EAAA;AAEAE,EAAAA,MAAMA,CACJjB,OAA0C,EAC1Cf,UAA4B,EAC5BC,KAAgB,EAChB;IACA,IAAI,CAACa,SAAS,CAACC,OAAO,EAAEhB,aAAa,CAACC,UAAU,EAAEC,KAAK,CAAC,CAAC;AAC3D,EAAA;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-registry.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-style-modifier",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "{{style}} modifier to set an element's style using the CSSStyleDeclaration API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
"repository": "https://github.com/jelhan/ember-style-modifier",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "",
|
|
11
|
+
"imports": {
|
|
12
|
+
"#src/*": "./src/*"
|
|
13
|
+
},
|
|
11
14
|
"exports": {
|
|
12
15
|
".": {
|
|
13
16
|
"types": "./declarations/index.d.ts",
|
|
14
17
|
"default": "./dist/index.js"
|
|
15
18
|
},
|
|
19
|
+
"./*.css": "./dist/*.css",
|
|
16
20
|
"./*": {
|
|
17
21
|
"types": "./declarations/*.d.ts",
|
|
18
22
|
"default": "./dist/*.js"
|
|
@@ -31,76 +35,61 @@
|
|
|
31
35
|
"declarations",
|
|
32
36
|
"dist"
|
|
33
37
|
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "concurrently 'npm:build:*'",
|
|
36
|
-
"build:js": "rollup --config",
|
|
37
|
-
"build:types": "glint --declaration",
|
|
38
|
-
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
|
|
39
|
-
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
|
|
40
|
-
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
|
|
41
|
-
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
|
|
42
|
-
"lint:js": "eslint . --cache",
|
|
43
|
-
"lint:js:fix": "eslint . --fix",
|
|
44
|
-
"lint:types": "glint",
|
|
45
|
-
"prepack": "pnpm run build",
|
|
46
|
-
"start": "concurrently 'npm:start:*'",
|
|
47
|
-
"start:js": "rollup --config --watch --no-watch.clearScreen",
|
|
48
|
-
"start:types": "glint --declaration --watch",
|
|
49
|
-
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
|
|
50
|
-
"prepare": "pnpm run build"
|
|
51
|
-
},
|
|
52
38
|
"dependencies": {
|
|
53
|
-
"@embroider/addon-shim": "^1.
|
|
54
|
-
"decorator-transforms": "^2.0.0",
|
|
39
|
+
"@embroider/addon-shim": "^1.10.0",
|
|
55
40
|
"csstype": "^3.1.3",
|
|
41
|
+
"decorator-transforms": "^2.3.0",
|
|
56
42
|
"ember-modifier": "^3.2.7 || ^4.0.0"
|
|
57
43
|
},
|
|
58
44
|
"devDependencies": {
|
|
59
|
-
"@babel/core": "
|
|
60
|
-
"@babel/
|
|
61
|
-
"@babel/
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@types/
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
|
|
45
|
+
"@babel/core": "7.29.0",
|
|
46
|
+
"@babel/eslint-parser": "7.28.6",
|
|
47
|
+
"@babel/plugin-transform-typescript": "7.28.6",
|
|
48
|
+
"@babel/runtime": "7.29.2",
|
|
49
|
+
"@ember/app-tsconfig": "2.0.0",
|
|
50
|
+
"@ember/library-tsconfig": "2.0.0",
|
|
51
|
+
"@ember/test-helpers": "5.4.1",
|
|
52
|
+
"@embroider/addon-dev": "8.3.0",
|
|
53
|
+
"@embroider/compat": "4.1.17",
|
|
54
|
+
"@embroider/core": "4.4.7",
|
|
55
|
+
"@embroider/macros": "1.20.2",
|
|
56
|
+
"@embroider/vite": "1.7.2",
|
|
57
|
+
"@eslint/js": "9.39.4",
|
|
58
|
+
"@glimmer/component": "2.0.0",
|
|
59
|
+
"@glint/core": "2.0.0-alpha.11",
|
|
60
|
+
"@glint/environment-ember-loose": "2.0.0-alpha.3",
|
|
61
|
+
"@glint/environment-ember-template-imports": "2.0.0-alpha.3",
|
|
62
|
+
"@glint/template": "1.7.7",
|
|
63
|
+
"@glint/tsserver-plugin": "2.4.0",
|
|
64
|
+
"@rollup/plugin-babel": "7.0.0",
|
|
65
|
+
"@types/qunit": "2.19.13",
|
|
66
|
+
"babel-plugin-ember-template-compilation": "4.0.0",
|
|
67
|
+
"concurrently": "9.2.1",
|
|
68
|
+
"ember-qunit": "9.0.4",
|
|
69
|
+
"ember-resolver": "13.2.0",
|
|
70
|
+
"ember-source": "6.12.0",
|
|
71
|
+
"ember-template-lint": "7.9.3",
|
|
72
|
+
"eslint": "9.39.4",
|
|
73
|
+
"eslint-config-prettier": "10.1.8",
|
|
74
|
+
"eslint-plugin-ember": "12.7.5",
|
|
75
|
+
"eslint-plugin-import": "2.32.0",
|
|
76
|
+
"eslint-plugin-n": "17.24.0",
|
|
77
|
+
"globals": "17.4.0",
|
|
78
|
+
"prettier": "3.8.1",
|
|
79
|
+
"prettier-plugin-ember-template-tag": "2.1.3",
|
|
80
|
+
"qunit": "2.25.0",
|
|
81
|
+
"qunit-dom": "3.5.0",
|
|
82
|
+
"release-plan": "^0.18.0",
|
|
83
|
+
"rollup": "4.60.1",
|
|
84
|
+
"testem": "3.19.1",
|
|
85
|
+
"tracked-built-ins": "4.1.2",
|
|
86
|
+
"typescript": "6.0.2",
|
|
87
|
+
"typescript-eslint": "8.46.3",
|
|
88
|
+
"vite": "8.0.5"
|
|
89
|
+
},
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": "18.* || >= 20",
|
|
92
|
+
"pnpm": ">= 10.*"
|
|
104
93
|
},
|
|
105
94
|
"publishConfig": {
|
|
106
95
|
"registry": "https://registry.npmjs.org"
|
|
@@ -116,8 +105,19 @@
|
|
|
116
105
|
"./modifiers/style.js": "./dist/_app_/modifiers/style.js"
|
|
117
106
|
}
|
|
118
107
|
},
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
108
|
+
"scripts": {
|
|
109
|
+
"build": "rollup --config",
|
|
110
|
+
"format": "prettier . --cache --write",
|
|
111
|
+
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\" --prefixColors auto",
|
|
112
|
+
"lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\" --prefixColors auto && pnpm run format",
|
|
113
|
+
"lint:format": "prettier . --cache --check",
|
|
114
|
+
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
|
|
115
|
+
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
|
|
116
|
+
"lint:js": "eslint . --cache",
|
|
117
|
+
"lint:js:fix": "eslint . --fix",
|
|
118
|
+
"lint:types": "glint",
|
|
119
|
+
"release": "release-it",
|
|
120
|
+
"start": "vite dev",
|
|
121
|
+
"test": "vite build --mode=development --out-dir dist-tests && testem --file testem.cjs ci --port 0"
|
|
122
122
|
}
|
|
123
|
-
}
|
|
123
|
+
}
|