@spectrum-web-components/theme 0.12.0 → 0.13.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 +17 -0
- package/core.dev.js +4 -0
- package/core.dev.js.map +7 -0
- package/core.js +4 -15
- package/core.js.map +7 -1
- package/custom-elements.json +3 -3
- package/express/scale-large.dev.js +5 -0
- package/express/scale-large.dev.js.map +7 -0
- package/express/scale-large.js +5 -16
- package/express/scale-large.js.map +7 -1
- package/express/scale-medium.dev.js +5 -0
- package/express/scale-medium.dev.js.map +7 -0
- package/express/scale-medium.js +5 -16
- package/express/scale-medium.js.map +7 -1
- package/express/theme-dark.dev.js +5 -0
- package/express/theme-dark.dev.js.map +7 -0
- package/express/theme-dark.js +5 -16
- package/express/theme-dark.js.map +7 -1
- package/express/theme-darkest.dev.js +5 -0
- package/express/theme-darkest.dev.js.map +7 -0
- package/express/theme-darkest.js +5 -16
- package/express/theme-darkest.js.map +7 -1
- package/express/theme-light.dev.js +5 -0
- package/express/theme-light.dev.js.map +7 -0
- package/express/theme-light.js +5 -16
- package/express/theme-light.js.map +7 -1
- package/express/theme-lightest.dev.js +5 -0
- package/express/theme-lightest.dev.js.map +7 -0
- package/express/theme-lightest.js +5 -16
- package/express/theme-lightest.js.map +7 -1
- package/package.json +97 -24
- package/scale-large.dev.js +5 -0
- package/scale-large.dev.js.map +7 -0
- package/scale-large.js +5 -16
- package/scale-large.js.map +7 -1
- package/scale-medium.dev.js +5 -0
- package/scale-medium.dev.js.map +7 -0
- package/scale-medium.js +5 -16
- package/scale-medium.js.map +7 -1
- package/sp-theme.dev.js +3 -0
- package/sp-theme.dev.js.map +7 -0
- package/sp-theme.js +3 -14
- package/sp-theme.js.map +7 -1
- package/src/Theme.dev.js +299 -0
- package/src/Theme.dev.js.map +7 -0
- package/src/Theme.js +276 -339
- package/src/Theme.js.map +7 -1
- package/src/express/core.dev.js +4 -0
- package/src/express/core.dev.js.map +7 -0
- package/src/express/core.js +4 -15
- package/src/express/core.js.map +7 -1
- package/src/express/scale-large.css.dev.js +190 -0
- package/src/express/scale-large.css.dev.js.map +7 -0
- package/src/express/scale-large.css.js +18 -21
- package/src/express/scale-large.css.js.map +7 -1
- package/src/express/scale-medium.css.dev.js +198 -0
- package/src/express/scale-medium.css.dev.js.map +7 -0
- package/src/express/scale-medium.css.js +18 -21
- package/src/express/scale-medium.css.js.map +7 -1
- package/src/express/theme-dark.css.dev.js +56 -0
- package/src/express/theme-dark.css.dev.js.map +7 -0
- package/src/express/theme-dark.css.js +4 -15
- package/src/express/theme-dark.css.js.map +7 -1
- package/src/express/theme-light.css.dev.js +56 -0
- package/src/express/theme-light.css.dev.js.map +7 -0
- package/src/express/theme-light.css.js +4 -15
- package/src/express/theme-light.css.js.map +7 -1
- package/src/express/theme.css.dev.js +1846 -0
- package/src/express/theme.css.dev.js.map +7 -0
- package/src/express/theme.css.js +6 -17
- package/src/express/theme.css.js.map +7 -1
- package/src/express/themes.dev.js +7 -0
- package/src/express/themes.dev.js.map +7 -0
- package/src/express/themes.js +7 -18
- package/src/express/themes.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/src/scale-large.css.dev.js +198 -0
- package/src/scale-large.css.dev.js.map +7 -0
- package/src/scale-large.css.js +18 -21
- package/src/scale-large.css.js.map +7 -1
- package/src/scale-medium.css.dev.js +200 -0
- package/src/scale-medium.css.dev.js.map +7 -0
- package/src/scale-medium.css.js +18 -21
- package/src/scale-medium.css.js.map +7 -1
- package/src/theme-dark.css.dev.js +58 -0
- package/src/theme-dark.css.dev.js.map +7 -0
- package/src/theme-dark.css.js +4 -15
- package/src/theme-dark.css.js.map +7 -1
- package/src/theme-darkest.css.dev.js +58 -0
- package/src/theme-darkest.css.dev.js.map +7 -0
- package/src/theme-darkest.css.js +4 -15
- package/src/theme-darkest.css.js.map +7 -1
- package/src/theme-light.css.dev.js +58 -0
- package/src/theme-light.css.dev.js.map +7 -0
- package/src/theme-light.css.js +4 -15
- package/src/theme-light.css.js.map +7 -1
- package/src/theme-lightest.css.dev.js +52 -0
- package/src/theme-lightest.css.dev.js.map +7 -0
- package/src/theme-lightest.css.js +4 -15
- package/src/theme-lightest.css.js.map +7 -1
- package/src/theme.css.dev.js +1840 -0
- package/src/theme.css.dev.js.map +7 -0
- package/src/theme.css.js +6 -17
- package/src/theme.css.js.map +7 -1
- package/src/themes.dev.js +7 -0
- package/src/themes.dev.js.map +7 -0
- package/src/themes.js +7 -18
- package/src/themes.js.map +7 -1
- package/src/typography.css.dev.js +946 -0
- package/src/typography.css.dev.js.map +7 -0
- package/src/typography.css.js +3 -14
- package/src/typography.css.js.map +7 -1
- package/stories/theme.stories.js +38 -43
- package/stories/theme.stories.js.map +7 -1
- package/test/theme-devmode.test.js +25 -0
- package/test/theme-devmode.test.js.map +7 -0
- package/test/theme-lazy.test.js +90 -108
- package/test/theme-lazy.test.js.map +7 -1
- package/test/theme.test-vrt.js +4 -15
- package/test/theme.test-vrt.js.map +7 -1
- package/test/themes.test.js +103 -120
- package/test/themes.test.js.map +7 -1
- package/theme-dark.dev.js +5 -0
- package/theme-dark.dev.js.map +7 -0
- package/theme-dark.js +5 -16
- package/theme-dark.js.map +7 -1
- package/theme-darkest.dev.js +5 -0
- package/theme-darkest.dev.js.map +7 -0
- package/theme-darkest.js +5 -16
- package/theme-darkest.js.map +7 -1
- package/theme-light.dev.js +5 -0
- package/theme-light.dev.js.map +7 -0
- package/theme-light.js +5 -16
- package/theme-light.js.map +7 -1
- package/theme-lightest.dev.js +5 -0
- package/theme-lightest.dev.js.map +7 -0
- package/theme-lightest.js +5 -16
- package/theme-lightest.js.map +7 -1
package/src/Theme.js
CHANGED
|
@@ -1,362 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { supportsAdoptingStyleSheets, } from '@spectrum-web-components/base';
|
|
13
|
-
const ThemeVariantValues = ['spectrum', 'express'];
|
|
14
|
-
const ScaleValues = ['medium', 'large', 'medium-express', 'large-express'];
|
|
1
|
+
import {
|
|
2
|
+
supportsAdoptingStyleSheets
|
|
3
|
+
} from "@spectrum-web-components/base";
|
|
4
|
+
const ThemeVariantValues = ["spectrum", "express"];
|
|
5
|
+
const ScaleValues = ["medium", "large", "medium-express", "large-express"];
|
|
15
6
|
const ColorValues = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
"light",
|
|
8
|
+
"lightest",
|
|
9
|
+
"dark",
|
|
10
|
+
"darkest",
|
|
11
|
+
"light-express",
|
|
12
|
+
"lightest-express",
|
|
13
|
+
"dark-express",
|
|
14
|
+
"darkest-express"
|
|
24
15
|
];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
16
|
+
const _Theme = class extends HTMLElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this._dir = "";
|
|
20
|
+
this._theme = "spectrum";
|
|
21
|
+
this._color = "";
|
|
22
|
+
this._scale = "";
|
|
23
|
+
this.trackedChildren = /* @__PURE__ */ new Set();
|
|
24
|
+
this._updateRequested = false;
|
|
25
|
+
this._contextConsumers = /* @__PURE__ */ new Map();
|
|
26
|
+
this.attachShadow({ mode: "open" });
|
|
27
|
+
const node = document.importNode(_Theme.template.content, true);
|
|
28
|
+
this.shadowRoot.appendChild(node);
|
|
29
|
+
this.shouldAdoptStyles();
|
|
30
|
+
this.addEventListener("sp-query-theme", this.onQueryTheme);
|
|
31
|
+
this.addEventListener("sp-language-context", this._handleContextPresence);
|
|
32
|
+
this.updateComplete = this.__createDeferredPromise();
|
|
33
|
+
}
|
|
34
|
+
static get observedAttributes() {
|
|
35
|
+
return ["color", "scale", "theme", "lang", "dir"];
|
|
36
|
+
}
|
|
37
|
+
set dir(dir) {
|
|
38
|
+
if (dir === this.dir)
|
|
39
|
+
return;
|
|
40
|
+
this.setAttribute("dir", dir);
|
|
41
|
+
this._dir = dir;
|
|
42
|
+
const targetDir = dir === "rtl" ? dir : "ltr";
|
|
43
|
+
this.trackedChildren.forEach((el) => {
|
|
44
|
+
el.setAttribute("dir", targetDir);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
get dir() {
|
|
48
|
+
return this._dir;
|
|
49
|
+
}
|
|
50
|
+
attributeChangedCallback(attrName, old, value) {
|
|
51
|
+
if (old === value) {
|
|
52
|
+
return;
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
if (attrName === "color") {
|
|
55
|
+
this.color = value;
|
|
56
|
+
} else if (attrName === "scale") {
|
|
57
|
+
this.scale = value;
|
|
58
|
+
} else if (attrName === "lang" && !!value) {
|
|
59
|
+
this.lang = value;
|
|
60
|
+
this._provideContext();
|
|
61
|
+
} else if (attrName === "theme") {
|
|
62
|
+
this.theme = value;
|
|
63
|
+
} else if (attrName === "dir") {
|
|
64
|
+
this.dir = value;
|
|
51
65
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.trackedChildren.forEach((el) => {
|
|
59
|
-
el.setAttribute('dir', targetDir);
|
|
60
|
-
});
|
|
66
|
+
}
|
|
67
|
+
requestUpdate() {
|
|
68
|
+
if (window.ShadyCSS !== void 0 && !window.ShadyCSS.nativeShadow) {
|
|
69
|
+
window.ShadyCSS.styleElement(this);
|
|
70
|
+
} else {
|
|
71
|
+
this.shouldAdoptStyles();
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
}
|
|
74
|
+
get theme() {
|
|
75
|
+
const themeFragments = _Theme.themeFragmentsByKind.get("theme");
|
|
76
|
+
const { name } = themeFragments && themeFragments.get("default") || {};
|
|
77
|
+
return this._theme || name || "";
|
|
78
|
+
}
|
|
79
|
+
set theme(newValue) {
|
|
80
|
+
if (newValue === this._theme)
|
|
81
|
+
return;
|
|
82
|
+
const theme = !!newValue && ThemeVariantValues.includes(newValue) ? newValue : this.theme;
|
|
83
|
+
if (theme !== this._theme) {
|
|
84
|
+
this._theme = theme;
|
|
85
|
+
this.requestUpdate();
|
|
69
86
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (attrName === 'color') {
|
|
75
|
-
this.color = value;
|
|
76
|
-
}
|
|
77
|
-
else if (attrName === 'scale') {
|
|
78
|
-
this.scale = value;
|
|
79
|
-
}
|
|
80
|
-
else if (attrName === 'lang' && !!value) {
|
|
81
|
-
this.lang = value;
|
|
82
|
-
this._provideContext();
|
|
83
|
-
}
|
|
84
|
-
else if (attrName === 'theme') {
|
|
85
|
-
this.theme = value;
|
|
86
|
-
}
|
|
87
|
-
else if (attrName === 'dir') {
|
|
88
|
-
this.dir = value;
|
|
89
|
-
}
|
|
87
|
+
if (theme) {
|
|
88
|
+
this.setAttribute("theme", theme);
|
|
89
|
+
} else {
|
|
90
|
+
this.removeAttribute("theme");
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* @attr
|
|
105
|
-
*/
|
|
106
|
-
get theme() {
|
|
107
|
-
const themeFragments = Theme.themeFragmentsByKind.get('theme');
|
|
108
|
-
const { name } = (themeFragments && themeFragments.get('default')) || {};
|
|
109
|
-
return this._theme || name || '';
|
|
110
|
-
}
|
|
111
|
-
set theme(newValue) {
|
|
112
|
-
if (newValue === this._theme)
|
|
113
|
-
return;
|
|
114
|
-
const theme = !!newValue && ThemeVariantValues.includes(newValue)
|
|
115
|
-
? newValue
|
|
116
|
-
: this.theme;
|
|
117
|
-
if (theme !== this._theme) {
|
|
118
|
-
this._theme = theme;
|
|
119
|
-
this.requestUpdate();
|
|
120
|
-
}
|
|
121
|
-
if (theme) {
|
|
122
|
-
this.setAttribute('theme', theme);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
this.removeAttribute('theme');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* The Spectrum color stops to apply to content scoped by this `sp-theme` element.
|
|
130
|
-
*
|
|
131
|
-
* A value is requried.
|
|
132
|
-
* @type {"lightest" | "light" | "dark" | "darkest" | ""}
|
|
133
|
-
* @attr
|
|
134
|
-
*/
|
|
135
|
-
get color() {
|
|
136
|
-
const themeFragments = Theme.themeFragmentsByKind.get('color');
|
|
137
|
-
const { name } = (themeFragments && themeFragments.get('default')) || {};
|
|
138
|
-
return this._color || name || '';
|
|
139
|
-
}
|
|
140
|
-
set color(newValue) {
|
|
141
|
-
if (newValue === this._color)
|
|
142
|
-
return;
|
|
143
|
-
const color = !!newValue && ColorValues.includes(newValue)
|
|
144
|
-
? newValue
|
|
145
|
-
: this.color;
|
|
146
|
-
if (color !== this._color) {
|
|
147
|
-
this._color = color;
|
|
148
|
-
this.requestUpdate();
|
|
149
|
-
}
|
|
150
|
-
if (color) {
|
|
151
|
-
this.setAttribute('color', color);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
this.removeAttribute('color');
|
|
155
|
-
}
|
|
92
|
+
}
|
|
93
|
+
get color() {
|
|
94
|
+
const themeFragments = _Theme.themeFragmentsByKind.get("color");
|
|
95
|
+
const { name } = themeFragments && themeFragments.get("default") || {};
|
|
96
|
+
return this._color || name || "";
|
|
97
|
+
}
|
|
98
|
+
set color(newValue) {
|
|
99
|
+
if (newValue === this._color)
|
|
100
|
+
return;
|
|
101
|
+
const color = !!newValue && ColorValues.includes(newValue) ? newValue : this.color;
|
|
102
|
+
if (color !== this._color) {
|
|
103
|
+
this._color = color;
|
|
104
|
+
this.requestUpdate();
|
|
156
105
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
* @type {"medium" | "large" | ""}
|
|
162
|
-
* @attr
|
|
163
|
-
*/
|
|
164
|
-
get scale() {
|
|
165
|
-
const themeFragments = Theme.themeFragmentsByKind.get('scale');
|
|
166
|
-
const { name } = (themeFragments && themeFragments.get('default')) || {};
|
|
167
|
-
return this._scale || name || '';
|
|
106
|
+
if (color) {
|
|
107
|
+
this.setAttribute("color", color);
|
|
108
|
+
} else {
|
|
109
|
+
this.removeAttribute("color");
|
|
168
110
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
else {
|
|
183
|
-
this.removeAttribute('scale');
|
|
184
|
-
}
|
|
111
|
+
}
|
|
112
|
+
get scale() {
|
|
113
|
+
const themeFragments = _Theme.themeFragmentsByKind.get("scale");
|
|
114
|
+
const { name } = themeFragments && themeFragments.get("default") || {};
|
|
115
|
+
return this._scale || name || "";
|
|
116
|
+
}
|
|
117
|
+
set scale(newValue) {
|
|
118
|
+
if (newValue === this._scale)
|
|
119
|
+
return;
|
|
120
|
+
const scale = !!newValue && ScaleValues.includes(newValue) ? newValue : this.scale;
|
|
121
|
+
if (scale !== this._scale) {
|
|
122
|
+
this._scale = scale;
|
|
123
|
+
this.requestUpdate();
|
|
185
124
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const getStyle = (fragments, name, kind) => {
|
|
191
|
-
const currentStyles = kind && kind !== 'theme' && this.theme === 'express'
|
|
192
|
-
? fragments.get(`${name}-express`)
|
|
193
|
-
: fragments.get(name);
|
|
194
|
-
// theme="spectrum" is available by default and doesn't need to be applied.
|
|
195
|
-
const isAppliedFragment = name === 'spectrum' || !kind || this.hasAttribute(kind);
|
|
196
|
-
if (currentStyles && isAppliedFragment) {
|
|
197
|
-
return currentStyles.styles;
|
|
198
|
-
}
|
|
199
|
-
return;
|
|
200
|
-
};
|
|
201
|
-
const styles = themeKinds.reduce((acc, kind) => {
|
|
202
|
-
const kindFragments = Theme.themeFragmentsByKind.get(kind);
|
|
203
|
-
let style;
|
|
204
|
-
if (kind === 'app' || kind === 'core') {
|
|
205
|
-
style = getStyle(kindFragments, kind);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
const { [kind]: name } = this;
|
|
209
|
-
style = getStyle(kindFragments, name, kind);
|
|
210
|
-
}
|
|
211
|
-
if (style) {
|
|
212
|
-
acc.push(style);
|
|
213
|
-
}
|
|
214
|
-
return acc;
|
|
215
|
-
}, []);
|
|
216
|
-
return [...styles];
|
|
125
|
+
if (scale) {
|
|
126
|
+
this.setAttribute("scale", scale);
|
|
127
|
+
} else {
|
|
128
|
+
this.removeAttribute("scale");
|
|
217
129
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
130
|
+
}
|
|
131
|
+
get styles() {
|
|
132
|
+
const themeKinds = [
|
|
133
|
+
..._Theme.themeFragmentsByKind.keys()
|
|
134
|
+
];
|
|
135
|
+
const getStyle = (fragments, name, kind) => {
|
|
136
|
+
const currentStyles = kind && kind !== "theme" && this.theme === "express" ? fragments.get(`${name}-express`) : fragments.get(name);
|
|
137
|
+
const isAppliedFragment = name === "spectrum" || !kind || this.hasAttribute(kind);
|
|
138
|
+
if (currentStyles && isAppliedFragment) {
|
|
139
|
+
return currentStyles.styles;
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
};
|
|
143
|
+
const styles = themeKinds.reduce((acc, kind) => {
|
|
144
|
+
const kindFragments = _Theme.themeFragmentsByKind.get(kind);
|
|
145
|
+
let style;
|
|
146
|
+
if (kind === "app" || kind === "core") {
|
|
147
|
+
style = getStyle(kindFragments, kind);
|
|
148
|
+
} else {
|
|
149
|
+
const { [kind]: name } = this;
|
|
150
|
+
style = getStyle(kindFragments, name, kind);
|
|
151
|
+
}
|
|
152
|
+
if (style) {
|
|
153
|
+
acc.push(style);
|
|
154
|
+
}
|
|
155
|
+
return acc;
|
|
156
|
+
}, []);
|
|
157
|
+
if (false) {
|
|
158
|
+
const issues = [];
|
|
159
|
+
const checkForAttribute = (name, resolvedValue, actualValue) => {
|
|
160
|
+
var _a;
|
|
161
|
+
const themeModifier = this.theme && this.theme !== "spectrum" ? `-${this.theme}` : "";
|
|
162
|
+
if (!resolvedValue) {
|
|
163
|
+
issues.push(`You have not explicitly set the "${name}" attribute and there is no default value on which to fallback.`);
|
|
164
|
+
} else if (!actualValue) {
|
|
165
|
+
issues.push(`You have not explicitly set the "${name}" attribute, the default value ("${resolvedValue}") is being used as a fallback.`);
|
|
166
|
+
} else if (!((_a = _Theme.themeFragmentsByKind.get(name)) == null ? void 0 : _a.get(resolvedValue + themeModifier))) {
|
|
167
|
+
issues.push(`You have set "${name}='${resolvedValue}'" but the associated theme fragment has not been loaded.`);
|
|
222
168
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
169
|
+
};
|
|
170
|
+
checkForAttribute("theme", this.theme, this._theme);
|
|
171
|
+
checkForAttribute("color", this.color, this._color);
|
|
172
|
+
checkForAttribute("scale", this.scale, this._scale);
|
|
173
|
+
if (issues.length) {
|
|
174
|
+
window.__swc.warn(this, "You are leveraging an <sp-theme> element and the following issues may disrupt your theme delivery:", "https://opensource.adobe.com/spectrum-web-components/components/theme/#example", {
|
|
175
|
+
issues
|
|
228
176
|
});
|
|
177
|
+
}
|
|
229
178
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
theme.color = this.color || undefined;
|
|
237
|
-
theme.scale = this.scale || undefined;
|
|
238
|
-
theme.lang =
|
|
239
|
-
this.lang || document.documentElement.lang || navigator.language;
|
|
240
|
-
theme.theme = this.theme || undefined;
|
|
179
|
+
return [...styles];
|
|
180
|
+
}
|
|
181
|
+
static get template() {
|
|
182
|
+
if (!this.templateElement) {
|
|
183
|
+
this.templateElement = document.createElement("template");
|
|
184
|
+
this.templateElement.innerHTML = "<slot></slot>";
|
|
241
185
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (!this.hasAttribute('dir')) {
|
|
253
|
-
let dirParent = (this.assignedSlot ||
|
|
254
|
-
this.parentNode);
|
|
255
|
-
while (dirParent !== document.documentElement &&
|
|
256
|
-
!(dirParent instanceof Theme)) {
|
|
257
|
-
dirParent = (dirParent.assignedSlot || // step into the shadow DOM of the parent of a slotted node
|
|
258
|
-
dirParent.parentNode || // DOM Element detected
|
|
259
|
-
dirParent.host);
|
|
260
|
-
}
|
|
261
|
-
this.dir = dirParent.dir === 'rtl' ? dirParent.dir : 'ltr';
|
|
262
|
-
}
|
|
186
|
+
return this.templateElement;
|
|
187
|
+
}
|
|
188
|
+
__createDeferredPromise() {
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
this.__resolve = resolve;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
onQueryTheme(event) {
|
|
194
|
+
if (event.defaultPrevented) {
|
|
195
|
+
return;
|
|
263
196
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
const { detail: theme } = event;
|
|
199
|
+
theme.color = this.color || void 0;
|
|
200
|
+
theme.scale = this.scale || void 0;
|
|
201
|
+
theme.lang = this.lang || document.documentElement.lang || navigator.language;
|
|
202
|
+
theme.theme = this.theme || void 0;
|
|
203
|
+
}
|
|
204
|
+
connectedCallback() {
|
|
205
|
+
this.shouldAdoptStyles();
|
|
206
|
+
if (window.ShadyCSS !== void 0) {
|
|
207
|
+
window.ShadyCSS.styleElement(this);
|
|
267
208
|
}
|
|
268
|
-
|
|
269
|
-
|
|
209
|
+
_Theme.instances.add(this);
|
|
210
|
+
if (!this.hasAttribute("dir")) {
|
|
211
|
+
let dirParent = this.assignedSlot || this.parentNode;
|
|
212
|
+
while (dirParent !== document.documentElement && !(dirParent instanceof _Theme)) {
|
|
213
|
+
dirParent = dirParent.assignedSlot || dirParent.parentNode || dirParent.host;
|
|
214
|
+
}
|
|
215
|
+
this.dir = dirParent.dir === "rtl" ? dirParent.dir : "ltr";
|
|
270
216
|
}
|
|
271
|
-
|
|
272
|
-
|
|
217
|
+
}
|
|
218
|
+
disconnectedCallback() {
|
|
219
|
+
_Theme.instances.delete(this);
|
|
220
|
+
}
|
|
221
|
+
startManagingContentDirection(el) {
|
|
222
|
+
this.trackedChildren.add(el);
|
|
223
|
+
}
|
|
224
|
+
stopManagingContentDirection(el) {
|
|
225
|
+
this.trackedChildren.delete(el);
|
|
226
|
+
}
|
|
227
|
+
async shouldAdoptStyles() {
|
|
228
|
+
if (!this._updateRequested) {
|
|
229
|
+
this.updateComplete = this.__createDeferredPromise();
|
|
230
|
+
this._updateRequested = true;
|
|
231
|
+
this._updateRequested = await false;
|
|
232
|
+
this.adoptStyles();
|
|
233
|
+
this.__resolve(true);
|
|
273
234
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
235
|
+
}
|
|
236
|
+
adoptStyles() {
|
|
237
|
+
const styles = this.styles;
|
|
238
|
+
if (window.ShadyCSS !== void 0 && !window.ShadyCSS.nativeShadow && window.ShadyCSS.ScopingShim) {
|
|
239
|
+
const fragmentCSS = [];
|
|
240
|
+
for (const [kind, fragments] of _Theme.themeFragmentsByKind) {
|
|
241
|
+
for (const [name, { styles: styles2 }] of fragments) {
|
|
242
|
+
if (name === "default")
|
|
243
|
+
continue;
|
|
244
|
+
let cssText = styles2.cssText;
|
|
245
|
+
if (!_Theme.defaultFragments.has(name)) {
|
|
246
|
+
cssText = cssText.replace(":host", `:host([${kind}='${name}'])`);
|
|
247
|
+
}
|
|
248
|
+
fragmentCSS.push(cssText);
|
|
281
249
|
}
|
|
250
|
+
}
|
|
251
|
+
window.ShadyCSS.ScopingShim.prepareAdoptedCssText(fragmentCSS, this.localName);
|
|
252
|
+
window.ShadyCSS.prepareTemplate(_Theme.template, this.localName);
|
|
253
|
+
} else if (supportsAdoptingStyleSheets) {
|
|
254
|
+
const styleSheets = [];
|
|
255
|
+
for (const style of styles) {
|
|
256
|
+
styleSheets.push(style.styleSheet);
|
|
257
|
+
}
|
|
258
|
+
this.shadowRoot.adoptedStyleSheets = styleSheets;
|
|
259
|
+
} else {
|
|
260
|
+
const styleNodes = this.shadowRoot.querySelectorAll("style");
|
|
261
|
+
styleNodes.forEach((element) => element.remove());
|
|
262
|
+
styles.forEach((s) => {
|
|
263
|
+
const style = document.createElement("style");
|
|
264
|
+
style.textContent = s.cssText;
|
|
265
|
+
this.shadowRoot.appendChild(style);
|
|
266
|
+
});
|
|
282
267
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
/* c8 ignore next */ if (window.ShadyCSS !== undefined &&
|
|
291
|
-
!window.ShadyCSS.nativeShadow &&
|
|
292
|
-
window.ShadyCSS.ScopingShim) {
|
|
293
|
-
// For browsers using the shim, there seems to be one set of
|
|
294
|
-
// processed styles per template, so it is hard to nest styles. So,
|
|
295
|
-
// for those, we load in all style fragments and then switch using a
|
|
296
|
-
// host selector (e.g. :host([color='dark']))
|
|
297
|
-
const fragmentCSS = [];
|
|
298
|
-
for (const [kind, fragments] of Theme.themeFragmentsByKind) {
|
|
299
|
-
for (const [name, { styles }] of fragments) {
|
|
300
|
-
if (name === 'default')
|
|
301
|
-
continue;
|
|
302
|
-
let cssText = styles.cssText;
|
|
303
|
-
if (!Theme.defaultFragments.has(name)) {
|
|
304
|
-
cssText = cssText.replace(':host', `:host([${kind}='${name}'])`);
|
|
305
|
-
}
|
|
306
|
-
fragmentCSS.push(cssText);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
window.ShadyCSS.ScopingShim.prepareAdoptedCssText(fragmentCSS, this.localName);
|
|
310
|
-
window.ShadyCSS.prepareTemplate(Theme.template, this.localName);
|
|
311
|
-
}
|
|
312
|
-
else if (supportsAdoptingStyleSheets) {
|
|
313
|
-
const styleSheets = [];
|
|
314
|
-
for (const style of styles) {
|
|
315
|
-
styleSheets.push(style.styleSheet);
|
|
316
|
-
}
|
|
317
|
-
this.shadowRoot.adoptedStyleSheets = styleSheets;
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
const styleNodes = this.shadowRoot.querySelectorAll('style');
|
|
321
|
-
styleNodes.forEach((element) => element.remove());
|
|
322
|
-
styles.forEach((s) => {
|
|
323
|
-
const style = document.createElement('style');
|
|
324
|
-
style.textContent = s.cssText;
|
|
325
|
-
this.shadowRoot.appendChild(style);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
static registerThemeFragment(name, kind, styles) {
|
|
330
|
-
const fragmentMap = Theme.themeFragmentsByKind.get(kind) || new Map();
|
|
331
|
-
if (fragmentMap.size === 0) {
|
|
332
|
-
Theme.themeFragmentsByKind.set(kind, fragmentMap);
|
|
333
|
-
// we're adding our first fragment for this kind, set as default
|
|
334
|
-
fragmentMap.set('default', { name, styles });
|
|
335
|
-
Theme.defaultFragments.add(name);
|
|
336
|
-
}
|
|
337
|
-
fragmentMap.set(name, { name, styles });
|
|
338
|
-
Theme.instances.forEach((instance) => instance.shouldAdoptStyles());
|
|
339
|
-
}
|
|
340
|
-
_provideContext() {
|
|
341
|
-
this._contextConsumers.forEach((consume) => consume(this.lang));
|
|
268
|
+
}
|
|
269
|
+
static registerThemeFragment(name, kind, styles) {
|
|
270
|
+
const fragmentMap = _Theme.themeFragmentsByKind.get(kind) || /* @__PURE__ */ new Map();
|
|
271
|
+
if (fragmentMap.size === 0) {
|
|
272
|
+
_Theme.themeFragmentsByKind.set(kind, fragmentMap);
|
|
273
|
+
fragmentMap.set("default", { name, styles });
|
|
274
|
+
_Theme.defaultFragments.add(name);
|
|
342
275
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
276
|
+
fragmentMap.set(name, { name, styles });
|
|
277
|
+
_Theme.instances.forEach((instance) => instance.shouldAdoptStyles());
|
|
278
|
+
}
|
|
279
|
+
_provideContext() {
|
|
280
|
+
this._contextConsumers.forEach((consume) => consume(this.lang));
|
|
281
|
+
}
|
|
282
|
+
_handleContextPresence(event) {
|
|
283
|
+
const target = event.composedPath()[0];
|
|
284
|
+
if (this._contextConsumers.has(target)) {
|
|
285
|
+
this._contextConsumers.delete(target);
|
|
286
|
+
} else {
|
|
287
|
+
this._contextConsumers.set(target, event.detail.callback);
|
|
288
|
+
const callback = this._contextConsumers.get(target);
|
|
289
|
+
if (callback) {
|
|
290
|
+
callback(this.lang || document.documentElement.lang || navigator.language);
|
|
291
|
+
}
|
|
357
292
|
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
Theme
|
|
361
|
-
Theme.
|
|
362
|
-
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
export let Theme = _Theme;
|
|
296
|
+
Theme.themeFragmentsByKind = /* @__PURE__ */ new Map();
|
|
297
|
+
Theme.defaultFragments = /* @__PURE__ */ new Set(["spectrum"]);
|
|
298
|
+
Theme.instances = /* @__PURE__ */ new Set();
|
|
299
|
+
//# sourceMappingURL=Theme.js.map
|