@vaadin/vaadin-themable-mixin 25.0.0-alpha7 → 25.0.0-alpha8
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/package.json +4 -4
- package/src/css-property-observer.js +36 -12
- package/src/lumo-injector.js +22 -5
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-alpha8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@polymer/polymer": "^3.0.0",
|
|
40
|
-
"@vaadin/chai-plugins": "25.0.0-
|
|
41
|
-
"@vaadin/test-runner-commands": "25.0.0-
|
|
40
|
+
"@vaadin/chai-plugins": "25.0.0-alpha8",
|
|
41
|
+
"@vaadin/test-runner-commands": "25.0.0-alpha8",
|
|
42
42
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
43
43
|
"sinon": "^18.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "ebf53673d5f639d2b1b6f2b31f640f530643ee2f"
|
|
46
46
|
}
|
|
@@ -14,14 +14,36 @@ export class CSSPropertyObserver {
|
|
|
14
14
|
#name;
|
|
15
15
|
#callback;
|
|
16
16
|
#properties = new Set();
|
|
17
|
+
#styleSheet;
|
|
18
|
+
#isConnected = false;
|
|
17
19
|
|
|
18
20
|
constructor(root, name, callback) {
|
|
19
21
|
this.#root = root;
|
|
20
22
|
this.#name = name;
|
|
21
23
|
this.#callback = callback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#handleTransitionEvent(event) {
|
|
27
|
+
const { propertyName } = event;
|
|
28
|
+
if (this.#properties.has(propertyName)) {
|
|
29
|
+
this.#callback(propertyName);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
observe(property) {
|
|
34
|
+
this.connect();
|
|
35
|
+
|
|
36
|
+
this.#properties.add(property);
|
|
37
|
+
this.#rootHost.style.setProperty(`--${this.#name}-props`, [...this.#properties].join(', '));
|
|
38
|
+
}
|
|
22
39
|
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
connect() {
|
|
41
|
+
if (this.#isConnected) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.#styleSheet = new CSSStyleSheet();
|
|
46
|
+
this.#styleSheet.replaceSync(`
|
|
25
47
|
:is(:root, :host)::before {
|
|
26
48
|
content: '' !important;
|
|
27
49
|
position: absolute !important;
|
|
@@ -32,22 +54,24 @@ export class CSSPropertyObserver {
|
|
|
32
54
|
transition-property: var(--${this.#name}-props) !important;
|
|
33
55
|
}
|
|
34
56
|
`);
|
|
35
|
-
this.#root.adoptedStyleSheets.unshift(styleSheet);
|
|
57
|
+
this.#root.adoptedStyleSheets.unshift(this.#styleSheet);
|
|
36
58
|
|
|
37
59
|
this.#rootHost.addEventListener('transitionstart', (event) => this.#handleTransitionEvent(event));
|
|
38
60
|
this.#rootHost.addEventListener('transitionend', (event) => this.#handleTransitionEvent(event));
|
|
39
|
-
}
|
|
40
61
|
|
|
41
|
-
|
|
42
|
-
const { propertyName } = event;
|
|
43
|
-
if (this.#properties.has(propertyName)) {
|
|
44
|
-
this.#callback(propertyName);
|
|
45
|
-
}
|
|
62
|
+
this.#isConnected = true;
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
|
|
49
|
-
this.#properties.
|
|
50
|
-
|
|
65
|
+
disconnect() {
|
|
66
|
+
this.#properties.clear();
|
|
67
|
+
|
|
68
|
+
this.#root.adoptedStyleSheets = this.#root.adoptedStyleSheets.filter((s) => s !== this.#styleSheet);
|
|
69
|
+
|
|
70
|
+
this.#rootHost.removeEventListener('transitionstart', this.#handleTransitionEvent);
|
|
71
|
+
this.#rootHost.removeEventListener('transitionend', this.#handleTransitionEvent);
|
|
72
|
+
this.#rootHost.style.removeProperty(`--${this.#name}-props`);
|
|
73
|
+
|
|
74
|
+
this.#isConnected = false;
|
|
51
75
|
}
|
|
52
76
|
|
|
53
77
|
get #rootHost() {
|
package/src/lumo-injector.js
CHANGED
|
@@ -84,10 +84,16 @@ export class LumoInjector {
|
|
|
84
84
|
this.#root = root;
|
|
85
85
|
this.#cssPropertyObserver = new CSSPropertyObserver(this.#root, 'vaadin-lumo-injector', (propertyName) => {
|
|
86
86
|
const tagName = propertyName.slice(2).replace('-lumo-inject', '');
|
|
87
|
-
this.#
|
|
87
|
+
this.#updateStyleSheet(tagName);
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
disconnect() {
|
|
92
|
+
this.#cssPropertyObserver.disconnect();
|
|
93
|
+
this.#styleSheetsByTag.clear();
|
|
94
|
+
this.#componentsByTag.values().forEach((components) => components.forEach(removeLumoStyleSheet));
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
/**
|
|
92
98
|
* Adds a component to the list of elements monitored for style injection.
|
|
93
99
|
* If the styles have already been detected, they are injected into the
|
|
@@ -103,8 +109,15 @@ export class LumoInjector {
|
|
|
103
109
|
this.#componentsByTag.set(tagName, this.#componentsByTag.get(tagName) ?? new Set());
|
|
104
110
|
this.#componentsByTag.get(tagName).add(component);
|
|
105
111
|
|
|
106
|
-
this.#
|
|
112
|
+
const stylesheet = this.#styleSheetsByTag.get(tagName);
|
|
113
|
+
if (stylesheet) {
|
|
114
|
+
if (stylesheet.cssRules.length > 0) {
|
|
115
|
+
injectLumoStyleSheet(component, stylesheet);
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
107
119
|
|
|
120
|
+
this.#initStyleSheet(tagName);
|
|
108
121
|
this.#cssPropertyObserver.observe(lumoInjectPropName);
|
|
109
122
|
}
|
|
110
123
|
|
|
@@ -121,7 +134,12 @@ export class LumoInjector {
|
|
|
121
134
|
removeLumoStyleSheet(component);
|
|
122
135
|
}
|
|
123
136
|
|
|
124
|
-
#
|
|
137
|
+
#initStyleSheet(tagName) {
|
|
138
|
+
this.#styleSheetsByTag.set(tagName, new CSSStyleSheet());
|
|
139
|
+
this.#updateStyleSheet(tagName);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#updateStyleSheet(tagName) {
|
|
125
143
|
const { tags, modules } = parseStyleSheets(this.#rootStyleSheets);
|
|
126
144
|
|
|
127
145
|
const cssText = (tags.get(tagName) ?? [])
|
|
@@ -129,9 +147,8 @@ export class LumoInjector {
|
|
|
129
147
|
.map((rule) => rule.cssText)
|
|
130
148
|
.join('\n');
|
|
131
149
|
|
|
132
|
-
const stylesheet = this.#styleSheetsByTag.get(tagName)
|
|
150
|
+
const stylesheet = this.#styleSheetsByTag.get(tagName);
|
|
133
151
|
stylesheet.replaceSync(cssText);
|
|
134
|
-
this.#styleSheetsByTag.set(tagName, stylesheet);
|
|
135
152
|
|
|
136
153
|
this.#componentsByTag.get(tagName)?.forEach((component) => {
|
|
137
154
|
if (cssText) {
|