@vaadin/vaadin-themable-mixin 25.0.0-alpha19 → 25.0.0-alpha20
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/lumo-injection-mixin.js +1 -1
- package/package.json +5 -5
- package/src/css-property-observer.js +13 -12
- package/src/lumo-injector.js +10 -10
- package/src/lumo-modules.js +3 -3
package/lumo-injection-mixin.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/vaadin-themable-mixin",
|
|
3
|
-
"version": "25.0.0-
|
|
3
|
+
"version": "25.0.0-alpha20",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
36
|
-
"@vaadin/component-base": "25.0.0-
|
|
36
|
+
"@vaadin/component-base": "25.0.0-alpha20",
|
|
37
37
|
"lit": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@polymer/polymer": "^3.0.0",
|
|
41
|
-
"@vaadin/chai-plugins": "25.0.0-
|
|
42
|
-
"@vaadin/test-runner-commands": "25.0.0-
|
|
41
|
+
"@vaadin/chai-plugins": "25.0.0-alpha20",
|
|
42
|
+
"@vaadin/test-runner-commands": "25.0.0-alpha20",
|
|
43
43
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
44
44
|
"sinon": "^21.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c948aae591a30b432f3784000d4677674cae56e0"
|
|
47
47
|
}
|
|
@@ -11,16 +11,15 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export class CSSPropertyObserver {
|
|
13
13
|
#root;
|
|
14
|
-
#name;
|
|
15
14
|
#callback;
|
|
16
15
|
#properties = new Set();
|
|
17
16
|
#styleSheet;
|
|
18
17
|
#isConnected = false;
|
|
19
18
|
|
|
20
|
-
constructor(root,
|
|
19
|
+
constructor(root, callback) {
|
|
21
20
|
this.#root = root;
|
|
22
|
-
this.#name = name;
|
|
23
21
|
this.#callback = callback;
|
|
22
|
+
this.#styleSheet = new CSSStyleSheet();
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
#handleTransitionEvent(event) {
|
|
@@ -33,16 +32,12 @@ export class CSSPropertyObserver {
|
|
|
33
32
|
observe(property) {
|
|
34
33
|
this.connect();
|
|
35
34
|
|
|
36
|
-
this.#properties.
|
|
37
|
-
this.#rootHost.style.setProperty(`--${this.#name}-props`, [...this.#properties].join(', '));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
connect() {
|
|
41
|
-
if (this.#isConnected) {
|
|
35
|
+
if (this.#properties.has(property)) {
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
this.#
|
|
39
|
+
this.#properties.add(property);
|
|
40
|
+
|
|
46
41
|
this.#styleSheet.replaceSync(`
|
|
47
42
|
:is(:root, :host)::before {
|
|
48
43
|
content: '' !important;
|
|
@@ -51,9 +46,16 @@ export class CSSPropertyObserver {
|
|
|
51
46
|
left: -9999px !important;
|
|
52
47
|
visibility: hidden !important;
|
|
53
48
|
transition: 1ms allow-discrete step-end !important;
|
|
54
|
-
transition-property:
|
|
49
|
+
transition-property: ${[...this.#properties].join(', ')} !important;
|
|
55
50
|
}
|
|
56
51
|
`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
connect() {
|
|
55
|
+
if (this.#isConnected) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
57
59
|
this.#root.adoptedStyleSheets.unshift(this.#styleSheet);
|
|
58
60
|
|
|
59
61
|
this.#rootHost.addEventListener('transitionstart', (event) => this.#handleTransitionEvent(event));
|
|
@@ -69,7 +71,6 @@ export class CSSPropertyObserver {
|
|
|
69
71
|
|
|
70
72
|
this.#rootHost.removeEventListener('transitionstart', this.#handleTransitionEvent);
|
|
71
73
|
this.#rootHost.removeEventListener('transitionend', this.#handleTransitionEvent);
|
|
72
|
-
this.#rootHost.style.removeProperty(`--${this.#name}-props`);
|
|
73
74
|
|
|
74
75
|
this.#isConnected = false;
|
|
75
76
|
}
|
package/src/lumo-injector.js
CHANGED
|
@@ -34,26 +34,26 @@ import { parseStyleSheets } from './lumo-modules.js';
|
|
|
34
34
|
* }
|
|
35
35
|
*
|
|
36
36
|
* html {
|
|
37
|
-
* --vaadin-text-field-
|
|
38
|
-
* --vaadin-text-field-
|
|
37
|
+
* --_lumo-vaadin-text-field-inject: 1;
|
|
38
|
+
* --_lumo-vaadin-text-field-inject-modules:
|
|
39
39
|
* lumo_base-field,
|
|
40
40
|
* lumo_text-field;
|
|
41
41
|
*
|
|
42
|
-
* --vaadin-email-field-
|
|
43
|
-
* --vaadin-email-field-
|
|
42
|
+
* --_lumo-vaadin-email-field-inject: 1;
|
|
43
|
+
* --_lumo-vaadin-email-field-inject-modules:
|
|
44
44
|
* lumo_base-field,
|
|
45
45
|
* lumo_email-field;
|
|
46
46
|
* }
|
|
47
47
|
* ```
|
|
48
48
|
*
|
|
49
|
-
* The class observes the custom property `--{tagName}-
|
|
49
|
+
* The class observes the custom property `--_lumo-{tagName}-inject`,
|
|
50
50
|
* which indicates whether styles are present for the given component
|
|
51
51
|
* in the document style sheets. When the property is set to `1`, the
|
|
52
52
|
* class recursively searches all document style sheets for CSS modules
|
|
53
|
-
* listed in the `--{tagName}-
|
|
53
|
+
* listed in the `--_lumo-{tagName}-inject-modules` property that apply to
|
|
54
54
|
* the given component tag name. The found rules are then injected
|
|
55
55
|
* into the component's Shadow DOM using the `adoptedStyleSheets` API,
|
|
56
|
-
* in the order specified in the `--{tagName}-
|
|
56
|
+
* in the order specified in the `--_lumo-{tagName}-inject-modules` property.
|
|
57
57
|
* The same module can be used in multiple components.
|
|
58
58
|
*
|
|
59
59
|
* The class also removes the injected styles when the property is set to `0`.
|
|
@@ -82,8 +82,8 @@ export class LumoInjector {
|
|
|
82
82
|
|
|
83
83
|
constructor(root = document) {
|
|
84
84
|
this.#root = root;
|
|
85
|
-
this.#cssPropertyObserver = new CSSPropertyObserver(this.#root,
|
|
86
|
-
const tagName = propertyName.
|
|
85
|
+
this.#cssPropertyObserver = new CSSPropertyObserver(this.#root, (propertyName) => {
|
|
86
|
+
const tagName = propertyName.match(/^--_lumo-(.*)-inject$/u)?.[1];
|
|
87
87
|
this.#updateStyleSheet(tagName);
|
|
88
88
|
});
|
|
89
89
|
}
|
|
@@ -98,7 +98,7 @@ export class LumoInjector {
|
|
|
98
98
|
* Adds a component to the list of elements monitored for style injection.
|
|
99
99
|
* If the styles have already been detected, they are injected into the
|
|
100
100
|
* component's shadow DOM immediately. Otherwise, the class watches the
|
|
101
|
-
* custom property `--{tagName}-
|
|
101
|
+
* custom property `--_lumo-{tagName}-inject` to trigger injection when
|
|
102
102
|
* the styles are added to the document or root element.
|
|
103
103
|
*
|
|
104
104
|
* @param {HTMLElement} component
|
package/src/lumo-modules.js
CHANGED
|
@@ -58,9 +58,9 @@ function parseStyleSheet(
|
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
if (rule instanceof CSSStyleRule && rule.cssText.includes('-
|
|
61
|
+
if (rule instanceof CSSStyleRule && rule.cssText.includes('-inject')) {
|
|
62
62
|
for (const property of rule.style) {
|
|
63
|
-
const tagName = property.match(/^--(.*)-
|
|
63
|
+
const tagName = property.match(/^--_lumo-(.*)-inject-modules$/u)?.[1];
|
|
64
64
|
if (!tagName) {
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
@@ -111,7 +111,7 @@ function parseStyleSheet(
|
|
|
111
111
|
*
|
|
112
112
|
* ```css
|
|
113
113
|
* html {
|
|
114
|
-
* --vaadin-text-field-
|
|
114
|
+
* --_lumo-vaadin-text-field-inject-modules:
|
|
115
115
|
* lumo_base-field,
|
|
116
116
|
* lumo_text-field;
|
|
117
117
|
* }
|