@spectrum-web-components/theme 0.42.2 → 0.42.3
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/core.dev.js +1 -1
- package/core.dev.js.map +2 -2
- package/core.js +1 -1
- package/core.js.map +2 -2
- package/custom-elements.json +24 -14
- package/package.json +4 -4
- package/src/Theme.d.ts +21 -17
- package/src/Theme.dev.js +61 -23
- package/src/Theme.dev.js.map +2 -2
- package/src/Theme.js +1 -1
- package/src/Theme.js.map +3 -3
- package/src/express/core.dev.js +1 -1
- package/src/express/core.dev.js.map +2 -2
- package/src/express/core.js +1 -1
- package/src/express/core.js.map +2 -2
- package/stories/theme.stories.js +11 -6
- package/stories/theme.stories.js.map +2 -2
- package/test/theme-devmode.test.js +27 -1
- package/test/theme-devmode.test.js.map +2 -2
- package/test/themes.test.js +45 -3
- package/test/themes.test.js.map +2 -2
package/core.dev.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Theme } from "./src/Theme.dev.js";
|
|
3
3
|
import coreStyles from "./src/theme.css.js";
|
|
4
|
-
Theme.registerThemeFragment("spectrum", "
|
|
4
|
+
Theme.registerThemeFragment("spectrum", "system", coreStyles);
|
|
5
5
|
//# sourceMappingURL=core.dev.js.map
|
package/core.dev.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["core.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from './src/Theme.dev.js'\n\nimport coreStyles from './src/theme.css.js';\n\nTheme.registerThemeFragment('spectrum', '
|
|
5
|
-
"mappings": ";AAYA,SAAS,aAAa;AAEtB,OAAO,gBAAgB;AAEvB,MAAM,sBAAsB,YAAY,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from './src/Theme.dev.js'\n\nimport coreStyles from './src/theme.css.js';\n\nTheme.registerThemeFragment('spectrum', 'system', coreStyles);\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,aAAa;AAEtB,OAAO,gBAAgB;AAEvB,MAAM,sBAAsB,YAAY,UAAU,UAAU;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{Theme as e}from"./src/Theme.js";import m from"./src/theme.css.js";e.registerThemeFragment("spectrum","
|
|
1
|
+
"use strict";import{Theme as e}from"./src/Theme.js";import m from"./src/theme.css.js";e.registerThemeFragment("spectrum","system",m);
|
|
2
2
|
//# sourceMappingURL=core.js.map
|
package/core.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["core.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from './src/Theme.js';\n\nimport coreStyles from './src/theme.css.js';\n\nTheme.registerThemeFragment('spectrum', '
|
|
5
|
-
"mappings": "aAYA,OAAS,SAAAA,MAAa,iBAEtB,OAAOC,MAAgB,qBAEvBD,EAAM,sBAAsB,WAAY,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from './src/Theme.js';\n\nimport coreStyles from './src/theme.css.js';\n\nTheme.registerThemeFragment('spectrum', 'system', coreStyles);\n"],
|
|
5
|
+
"mappings": "aAYA,OAAS,SAAAA,MAAa,iBAEtB,OAAOC,MAAgB,qBAEvBD,EAAM,sBAAsB,WAAY,SAAUC,CAAU",
|
|
6
6
|
"names": ["Theme", "coreStyles"]
|
|
7
7
|
}
|
package/custom-elements.json
CHANGED
|
@@ -104,21 +104,28 @@
|
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"kind": "field",
|
|
107
|
-
"name": "
|
|
107
|
+
"name": "_system",
|
|
108
108
|
"type": {
|
|
109
|
-
"text": "
|
|
109
|
+
"text": "SystemVariant | ''"
|
|
110
110
|
},
|
|
111
111
|
"privacy": "private",
|
|
112
112
|
"default": "'spectrum'"
|
|
113
113
|
},
|
|
114
114
|
{
|
|
115
115
|
"kind": "field",
|
|
116
|
-
"name": "
|
|
116
|
+
"name": "system",
|
|
117
117
|
"type": {
|
|
118
|
-
"text": "\"spectrum\" | \"express\"
|
|
118
|
+
"text": "\"spectrum\" | \"express\""
|
|
119
119
|
},
|
|
120
|
-
"description": "The Spectrum
|
|
121
|
-
"attribute": "
|
|
120
|
+
"description": "The Spectrum system that is applied to the content scoped to this `sp-theme` element.\n\nA value is requried.",
|
|
121
|
+
"attribute": "system"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"kind": "field",
|
|
125
|
+
"name": "theme",
|
|
126
|
+
"type": {
|
|
127
|
+
"text": "SystemVariant | ''"
|
|
128
|
+
}
|
|
122
129
|
},
|
|
123
130
|
{
|
|
124
131
|
"kind": "field",
|
|
@@ -366,14 +373,6 @@
|
|
|
366
373
|
"description": "The Spectrum platform scale to apply to content scoped by this `sp-theme` element.\n\nA value is requried.",
|
|
367
374
|
"fieldName": "scale"
|
|
368
375
|
},
|
|
369
|
-
{
|
|
370
|
-
"name": "theme",
|
|
371
|
-
"type": {
|
|
372
|
-
"text": "\"spectrum\" | \"express\" | \"\""
|
|
373
|
-
},
|
|
374
|
-
"description": "The Spectrum theme that is applied to the content scoped to this `sp-theme` element.\n\nA value is requried.",
|
|
375
|
-
"fieldName": "theme"
|
|
376
|
-
},
|
|
377
376
|
{
|
|
378
377
|
"name": "lang",
|
|
379
378
|
"type": {
|
|
@@ -389,6 +388,17 @@
|
|
|
389
388
|
},
|
|
390
389
|
"description": "Reading direction of the content scoped to this `sp-theme` element.",
|
|
391
390
|
"fieldName": "dir"
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
"name": "system",
|
|
394
|
+
"type": {
|
|
395
|
+
"text": "\"spectrum\" | \"express\""
|
|
396
|
+
},
|
|
397
|
+
"description": "The Spectrum system that is applied to the content scoped to this `sp-theme` element.\n\nA value is requried.",
|
|
398
|
+
"fieldName": "system"
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
"name": "theme"
|
|
392
402
|
}
|
|
393
403
|
],
|
|
394
404
|
"superclass": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/theme",
|
|
3
|
-
"version": "0.42.
|
|
3
|
+
"version": "0.42.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -205,8 +205,8 @@
|
|
|
205
205
|
"lit-html"
|
|
206
206
|
],
|
|
207
207
|
"dependencies": {
|
|
208
|
-
"@spectrum-web-components/base": "^0.42.
|
|
209
|
-
"@spectrum-web-components/styles": "^0.42.
|
|
208
|
+
"@spectrum-web-components/base": "^0.42.3",
|
|
209
|
+
"@spectrum-web-components/styles": "^0.42.3"
|
|
210
210
|
},
|
|
211
211
|
"types": "./src/index.d.ts",
|
|
212
212
|
"customElements": "custom-elements.json",
|
|
@@ -227,5 +227,5 @@
|
|
|
227
227
|
"./src/express/themes.js",
|
|
228
228
|
"./src/express/themes-*.js"
|
|
229
229
|
],
|
|
230
|
-
"gitHead": "
|
|
230
|
+
"gitHead": "a03edce4f21f232f1705d8eb222e6e5436cad4c3"
|
|
231
231
|
}
|
package/src/Theme.d.ts
CHANGED
|
@@ -11,28 +11,30 @@ declare global {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
type ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {
|
|
15
15
|
adoptedStyleSheets?: CSSStyleSheet[];
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
type FragmentType = 'color' | 'scale' | 'system' | 'theme' | 'core' | 'app';
|
|
18
|
+
type SettableFragmentTypes = 'color' | 'scale' | 'system' | 'theme';
|
|
19
|
+
type FragmentMap = Map<string, {
|
|
20
20
|
name: string;
|
|
21
21
|
styles: CSSResultGroup;
|
|
22
22
|
}>;
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
26
|
-
export
|
|
27
|
-
|
|
23
|
+
export type ThemeFragmentMap = Map<FragmentType, FragmentMap>;
|
|
24
|
+
export type Color = 'light' | 'lightest' | 'dark' | 'darkest' | 'light-express' | 'lightest-express' | 'dark-express' | 'darkest-express';
|
|
25
|
+
export type Scale = 'medium' | 'large' | 'medium-express' | 'large-express';
|
|
26
|
+
export type ThemeVariant = 'spectrum' | 'express';
|
|
27
|
+
export type SystemVariant = 'spectrum' | 'express';
|
|
28
|
+
type FragmentName = Color | Scale | ThemeVariant | SystemVariant | 'core' | 'app';
|
|
28
29
|
export interface ThemeData {
|
|
29
30
|
color?: Color;
|
|
30
31
|
scale?: Scale;
|
|
31
32
|
lang?: string;
|
|
32
|
-
theme?:
|
|
33
|
+
theme?: SystemVariant;
|
|
34
|
+
system?: SystemVariant;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
[P in SettableFragmentTypes]: ThemeVariant | Color | Scale | '';
|
|
36
|
+
type ThemeKindProvider = {
|
|
37
|
+
[P in SettableFragmentTypes]: ThemeVariant | SystemVariant | Color | Scale | '';
|
|
36
38
|
};
|
|
37
39
|
export interface ProvideLang {
|
|
38
40
|
callback: (lang: string, unsubscribe: () => void) => void;
|
|
@@ -61,16 +63,18 @@ export declare class Theme extends HTMLElement implements ThemeKindProvider {
|
|
|
61
63
|
protected attributeChangedCallback(attrName: SettableFragmentTypes | 'lang' | 'dir', old: string | null, value: string | null): void;
|
|
62
64
|
private requestUpdate;
|
|
63
65
|
shadowRoot: ShadowRootWithAdoptedStyleSheets;
|
|
64
|
-
private
|
|
66
|
+
private _system;
|
|
65
67
|
/**
|
|
66
|
-
* The Spectrum
|
|
68
|
+
* The Spectrum system that is applied to the content scoped to this `sp-theme` element.
|
|
67
69
|
*
|
|
68
70
|
* A value is requried.
|
|
69
|
-
* @type {"spectrum" | "express"
|
|
71
|
+
* @type {"spectrum" | "express" }
|
|
70
72
|
* @attr
|
|
71
73
|
*/
|
|
72
|
-
get
|
|
73
|
-
set
|
|
74
|
+
get system(): SystemVariant | '';
|
|
75
|
+
set system(newValue: SystemVariant | '');
|
|
76
|
+
get theme(): SystemVariant | '';
|
|
77
|
+
set theme(newValue: SystemVariant | '');
|
|
74
78
|
private _color;
|
|
75
79
|
/**
|
|
76
80
|
* The Spectrum color stops to apply to content scoped by this `sp-theme` element.
|
package/src/Theme.dev.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
supportsAdoptingStyleSheets
|
|
4
4
|
} from "@spectrum-web-components/base";
|
|
5
5
|
import { version } from "@spectrum-web-components/base/src/version.js";
|
|
6
|
-
const
|
|
6
|
+
const SystemVariantValues = ["spectrum", "express"];
|
|
7
7
|
const ScaleValues = ["medium", "large", "medium-express", "large-express"];
|
|
8
8
|
const ColorValues = [
|
|
9
9
|
"light",
|
|
@@ -19,7 +19,7 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
19
19
|
constructor() {
|
|
20
20
|
super();
|
|
21
21
|
this._dir = "";
|
|
22
|
-
this.
|
|
22
|
+
this._system = "spectrum";
|
|
23
23
|
this._color = "";
|
|
24
24
|
this._scale = "";
|
|
25
25
|
this.trackedChildren = /* @__PURE__ */ new Set();
|
|
@@ -40,7 +40,15 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
40
40
|
this.updateComplete = this.__createDeferredPromise();
|
|
41
41
|
}
|
|
42
42
|
static get observedAttributes() {
|
|
43
|
-
return [
|
|
43
|
+
return [
|
|
44
|
+
"color",
|
|
45
|
+
"scale",
|
|
46
|
+
"lang",
|
|
47
|
+
"dir",
|
|
48
|
+
"system",
|
|
49
|
+
/* deprecated attributes, but still observing */
|
|
50
|
+
"theme"
|
|
51
|
+
];
|
|
44
52
|
}
|
|
45
53
|
set dir(dir) {
|
|
46
54
|
if (dir === this.dir)
|
|
@@ -73,6 +81,14 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
73
81
|
this._provideContext();
|
|
74
82
|
} else if (attrName === "theme") {
|
|
75
83
|
this.theme = value;
|
|
84
|
+
window.__swc.warn(
|
|
85
|
+
this,
|
|
86
|
+
'property theme in <sp-theme> has been deprecated. Please use system instead like this <sp-theme system="spectrum"/>',
|
|
87
|
+
"https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation",
|
|
88
|
+
{ level: "deprecation" }
|
|
89
|
+
);
|
|
90
|
+
} else if (attrName === "system") {
|
|
91
|
+
this.system = value;
|
|
76
92
|
} else if (attrName === "dir") {
|
|
77
93
|
this.dir = value;
|
|
78
94
|
}
|
|
@@ -85,30 +101,46 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
85
101
|
}
|
|
86
102
|
}
|
|
87
103
|
/**
|
|
88
|
-
* The Spectrum
|
|
104
|
+
* The Spectrum system that is applied to the content scoped to this `sp-theme` element.
|
|
89
105
|
*
|
|
90
106
|
* A value is requried.
|
|
91
|
-
* @type {"spectrum" | "express"
|
|
107
|
+
* @type {"spectrum" | "express" }
|
|
92
108
|
* @attr
|
|
93
109
|
*/
|
|
94
|
-
get
|
|
95
|
-
const
|
|
96
|
-
const { name } =
|
|
97
|
-
return this.
|
|
110
|
+
get system() {
|
|
111
|
+
const systemFragments = _Theme.themeFragmentsByKind.get("system");
|
|
112
|
+
const { name } = systemFragments && systemFragments.get("default") || {};
|
|
113
|
+
return this._system || name || "";
|
|
98
114
|
}
|
|
99
|
-
set
|
|
100
|
-
if (newValue === this.
|
|
115
|
+
set system(newValue) {
|
|
116
|
+
if (newValue === this._system)
|
|
101
117
|
return;
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
this.
|
|
118
|
+
const system = !!newValue && SystemVariantValues.includes(newValue) ? newValue : this.system;
|
|
119
|
+
if (system !== this._system) {
|
|
120
|
+
this._system = system;
|
|
105
121
|
this.requestUpdate();
|
|
106
122
|
}
|
|
107
|
-
if (
|
|
108
|
-
this.setAttribute("
|
|
123
|
+
if (system) {
|
|
124
|
+
this.setAttribute("system", system);
|
|
109
125
|
} else {
|
|
110
|
-
this.removeAttribute("
|
|
126
|
+
this.removeAttribute("system");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/*
|
|
130
|
+
* @deprecated The `theme` attribute has been deprecated in favor of the `system` attribute.
|
|
131
|
+
*/
|
|
132
|
+
get theme() {
|
|
133
|
+
if (!this.system) {
|
|
134
|
+
this.removeAttribute("system");
|
|
111
135
|
}
|
|
136
|
+
return this.system;
|
|
137
|
+
}
|
|
138
|
+
/*
|
|
139
|
+
* @deprecated The `theme` attribute has been deprecated in favor of the `system` attribute.
|
|
140
|
+
*/
|
|
141
|
+
set theme(newValue) {
|
|
142
|
+
this.system = newValue;
|
|
143
|
+
this.requestUpdate();
|
|
112
144
|
}
|
|
113
145
|
/**
|
|
114
146
|
* The Spectrum color stops to apply to content scoped by this `sp-theme` element.
|
|
@@ -167,7 +199,7 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
167
199
|
..._Theme.themeFragmentsByKind.keys()
|
|
168
200
|
];
|
|
169
201
|
const getStyle = (fragments, name, kind) => {
|
|
170
|
-
const currentStyles = kind && kind !== "theme" && this.theme === "express" ? fragments.get(`${name}-express`) : fragments.get(name);
|
|
202
|
+
const currentStyles = kind && kind !== "theme" && kind !== "system" && this.theme === "express" && this.system === "express" ? fragments.get(`${name}-express`) : fragments.get(name);
|
|
171
203
|
const isAppliedFragment = name === "spectrum" || !kind || this.hasAttribute(kind);
|
|
172
204
|
if (currentStyles && isAppliedFragment) {
|
|
173
205
|
return currentStyles.styles;
|
|
@@ -194,7 +226,7 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
194
226
|
const issues = [];
|
|
195
227
|
const checkForAttribute = (name, resolvedValue, actualValue) => {
|
|
196
228
|
var _a;
|
|
197
|
-
const
|
|
229
|
+
const systemModifier = this.system && this.system !== "spectrum" ? `-${this.system}` : "";
|
|
198
230
|
if (!resolvedValue) {
|
|
199
231
|
issues.push(
|
|
200
232
|
`You have not explicitly set the "${name}" attribute and there is no default value on which to fallback.`
|
|
@@ -204,16 +236,21 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
204
236
|
`You have not explicitly set the "${name}" attribute, the default value ("${resolvedValue}") is being used as a fallback.`
|
|
205
237
|
);
|
|
206
238
|
} else if (!((_a = _Theme.themeFragmentsByKind.get(name)) == null ? void 0 : _a.get(
|
|
207
|
-
resolvedValue + (name === "
|
|
239
|
+
resolvedValue + (name === "system" ? "" : systemModifier)
|
|
208
240
|
))) {
|
|
209
241
|
issues.push(
|
|
210
|
-
`You have set "${name}='${resolvedValue}'" but the associated
|
|
242
|
+
`You have set "${name}='${resolvedValue}'" but the associated system fragment has not been loaded.`
|
|
211
243
|
);
|
|
212
244
|
}
|
|
213
245
|
};
|
|
214
|
-
checkForAttribute("
|
|
246
|
+
checkForAttribute("system", this.system, this._system);
|
|
215
247
|
checkForAttribute("color", this.color, this._color);
|
|
216
248
|
checkForAttribute("scale", this.scale, this._scale);
|
|
249
|
+
if (this.hasAttribute("theme")) {
|
|
250
|
+
issues.push(
|
|
251
|
+
`The "theme" attribute has been deprecated in favor of "system".`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
217
254
|
if (issues.length) {
|
|
218
255
|
window.__swc.warn(
|
|
219
256
|
this,
|
|
@@ -257,7 +294,8 @@ const _Theme = class _Theme extends HTMLElement {
|
|
|
257
294
|
theme.color = this.color || void 0;
|
|
258
295
|
theme.scale = this.scale || void 0;
|
|
259
296
|
theme.lang = this.lang || document.documentElement.lang || navigator.language;
|
|
260
|
-
theme.theme = this.
|
|
297
|
+
theme.theme = this.system || void 0;
|
|
298
|
+
theme.system = this.system || void 0;
|
|
261
299
|
}
|
|
262
300
|
connectedCallback() {
|
|
263
301
|
this.shouldAdoptStyles();
|
package/src/Theme.dev.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["Theme.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResult,\n CSSResultGroup,\n supportsAdoptingStyleSheets,\n} from '@spectrum-web-components/base';\nimport { version } from '@spectrum-web-components/base/src/version.js';\n\ndeclare global {\n interface Window {\n ShadyCSS: {\n nativeShadow: boolean;\n prepareTemplate(\n template: HTMLTemplateElement,\n elementName: string,\n typeExtension?: string\n ): void;\n styleElement(host: HTMLElement): void;\n ScopingShim: {\n prepareAdoptedCssText(\n cssTextArray: string[],\n elementName: string\n ): void;\n };\n };\n }\n}\n\ntype ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {\n adoptedStyleSheets?: CSSStyleSheet[];\n};\n\ntype FragmentType = 'color' | 'scale' | 'theme' | 'core' | 'app';\ntype SettableFragmentTypes = 'color' | 'scale' | 'theme';\ntype FragmentMap = Map<string, { name: string; styles: CSSResultGroup }>;\nexport type ThemeFragmentMap = Map<FragmentType, FragmentMap>;\nexport type Color =\n | 'light'\n | 'lightest'\n | 'dark'\n | 'darkest'\n | 'light-express'\n | 'lightest-express'\n | 'dark-express'\n | 'darkest-express';\nexport type Scale = 'medium' | 'large' | 'medium-express' | 'large-express';\nexport type ThemeVariant = 'spectrum' | 'express';\nconst ThemeVariantValues = ['spectrum', 'express'];\nconst ScaleValues = ['medium', 'large', 'medium-express', 'large-express'];\nconst ColorValues = [\n 'light',\n 'lightest',\n 'dark',\n 'darkest',\n 'light-express',\n 'lightest-express',\n 'dark-express',\n 'darkest-express',\n];\ntype FragmentName = Color | Scale | ThemeVariant | 'core' | 'app';\n\nexport interface ThemeData {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: ThemeVariant;\n}\n\ntype ThemeKindProvider = {\n [P in SettableFragmentTypes]: ThemeVariant | Color | Scale | '';\n};\n\nexport interface ProvideLang {\n callback: (lang: string, unsubscribe: () => void) => void;\n}\n\n/**\n * @element sp-theme\n * @attr {string} [lang=\"\"] - The language of the content scoped to this `sp-theme` element, see: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang\" target=\"_blank\">MDN reference</a>.\n *\n * @slot - Content on which to apply the CSS Custom Properties defined by the current theme configuration\n */\nexport class Theme extends HTMLElement implements ThemeKindProvider {\n private static themeFragmentsByKind: ThemeFragmentMap = new Map();\n private static defaultFragments: Set<FragmentName> = new Set(['spectrum']);\n private static templateElement?: HTMLTemplateElement;\n private static instances: Set<Theme> = new Set();\n static VERSION = version;\n\n static get observedAttributes(): string[] {\n return ['color', 'scale', 'theme', 'lang', 'dir'];\n }\n\n _dir: 'ltr' | 'rtl' | '' = '';\n\n override set dir(dir: 'ltr' | 'rtl' | '') {\n if (dir === this.dir) return;\n this.setAttribute('dir', dir);\n this._dir = dir;\n const targetDir = dir === 'rtl' ? dir : 'ltr';\n /* c8 ignore next 3 */\n this.trackedChildren.forEach((el) => {\n el.setAttribute('dir', targetDir);\n });\n }\n\n /**\n * Reading direction of the content scoped to this `sp-theme` element.\n * @type {\"ltr\" | \"rtl\" | \"\"}\n * @attr\n */\n override get dir(): 'ltr' | 'rtl' | '' {\n return this._dir;\n }\n\n protected attributeChangedCallback(\n attrName: SettableFragmentTypes | 'lang' | 'dir',\n old: string | null,\n value: string | null\n ): void {\n if (old === value) {\n return;\n }\n if (attrName === 'color') {\n this.color = value as Color;\n } else if (attrName === 'scale') {\n this.scale = value as Scale;\n /* c8 ignore next 3 */\n } else if (attrName === 'lang' && !!value) {\n this.lang = value;\n this._provideContext();\n } else if (attrName === 'theme') {\n this.theme = value as ThemeVariant;\n } else if (attrName === 'dir') {\n this.dir = value as 'ltr' | 'rtl' | '';\n }\n }\n\n private requestUpdate(): void {\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.styleElement(this);\n } else {\n this.shouldAdoptStyles();\n }\n }\n\n public override shadowRoot!: ShadowRootWithAdoptedStyleSheets;\n\n private _theme: ThemeVariant | '' = 'spectrum';\n\n /**\n * The Spectrum theme that is applied to the content scoped to this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"spectrum\" | \"express\" | \"\"}\n * @attr\n */\n get theme(): ThemeVariant | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('theme');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._theme || (name as ThemeVariant) || '';\n }\n\n set theme(newValue: ThemeVariant | '') {\n if (newValue === this._theme) return;\n const theme =\n !!newValue && ThemeVariantValues.includes(newValue)\n ? newValue\n : this.theme;\n if (theme !== this._theme) {\n this._theme = theme;\n this.requestUpdate();\n }\n if (theme) {\n this.setAttribute('theme', theme);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('theme');\n }\n }\n\n private _color: Color | '' = '';\n\n /**\n * The Spectrum color stops to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"lightest\" | \"light\" | \"dark\" | \"darkest\" | \"\"}\n * @attr\n */\n get color(): Color | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('color');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._color || (name as Color) || '';\n }\n\n set color(newValue: Color | '') {\n if (newValue === this._color) return;\n const color =\n !!newValue && ColorValues.includes(newValue)\n ? newValue\n : this.color;\n if (color !== this._color) {\n this._color = color;\n this.requestUpdate();\n }\n if (color) {\n this.setAttribute('color', color);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('color');\n }\n }\n\n private _scale: Scale | '' = '';\n\n /**\n * The Spectrum platform scale to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"medium\" | \"large\" | \"\"}\n * @attr\n */\n get scale(): Scale | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('scale');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._scale || (name as Scale) || '';\n }\n\n set scale(newValue: Scale | '') {\n if (newValue === this._scale) return;\n const scale =\n !!newValue && ScaleValues.includes(newValue)\n ? newValue\n : this.scale;\n if (scale !== this._scale) {\n this._scale = scale;\n this.requestUpdate();\n }\n if (scale) {\n this.setAttribute('scale', scale);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('scale');\n }\n }\n\n private get styles(): CSSResultGroup[] {\n const themeKinds: FragmentType[] = [\n ...Theme.themeFragmentsByKind.keys(),\n ];\n const getStyle = (\n fragments: FragmentMap,\n name: FragmentName,\n kind?: FragmentType\n ): CSSResultGroup | undefined => {\n const currentStyles =\n kind && kind !== 'theme' && this.theme === 'express'\n ? fragments.get(`${name}-express`)\n : fragments.get(name);\n // theme=\"spectrum\" is available by default and doesn't need to be applied.\n const isAppliedFragment =\n name === 'spectrum' || !kind || this.hasAttribute(kind);\n if (currentStyles && isAppliedFragment) {\n return currentStyles.styles;\n }\n return;\n };\n const styles = themeKinds.reduce((acc, kind) => {\n const kindFragments = Theme.themeFragmentsByKind.get(\n kind\n ) as FragmentMap;\n let style: CSSResultGroup | undefined;\n if (kind === 'app' || kind === 'core') {\n style = getStyle(kindFragments, kind);\n } else {\n const { [kind]: name } = this;\n style = getStyle(kindFragments, <FragmentName>name, kind);\n }\n if (style) {\n acc.push(style);\n }\n return acc;\n }, [] as CSSResultGroup[]);\n if (window.__swc.DEBUG) {\n const issues: string[] = [];\n const checkForAttribute = (\n name: FragmentType,\n resolvedValue?: string,\n actualValue?: string\n ): void => {\n const themeModifier =\n this.theme && this.theme !== 'spectrum'\n ? `-${this.theme}`\n : '';\n if (!resolvedValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute and there is no default value on which to fallback.`\n );\n } else if (!actualValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute, the default value (\"${resolvedValue}\") is being used as a fallback.`\n );\n } else if (\n !Theme.themeFragmentsByKind\n .get(name)\n ?.get(\n resolvedValue +\n (name === 'theme' ? '' : themeModifier)\n )\n ) {\n issues.push(\n `You have set \"${name}='${resolvedValue}'\" but the associated theme fragment has not been loaded.`\n );\n }\n };\n checkForAttribute('theme', this.theme, this._theme);\n checkForAttribute('color', this.color, this._color);\n checkForAttribute('scale', this.scale, this._scale);\n if (issues.length) {\n window.__swc.warn(\n this,\n 'You are leveraging an <sp-theme> element and the following issues may disrupt your theme delivery:',\n 'https://opensource.adobe.com/spectrum-web-components/components/theme/#example',\n {\n issues,\n }\n );\n }\n if (['lightest', 'darkest'].includes(this.color)) {\n window.__swc.warn(\n this,\n `Color lightest and darkest are deprecated and will be removed in a future release`,\n 'https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation',\n { level: 'deprecation' }\n );\n }\n }\n return [...styles];\n }\n\n private static get template(): HTMLTemplateElement {\n if (!this.templateElement) {\n this.templateElement = document.createElement('template');\n this.templateElement.innerHTML = '<slot></slot>';\n }\n return this.templateElement;\n }\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n const node = document.importNode(Theme.template.content, true);\n this.shadowRoot.appendChild(node);\n this.shouldAdoptStyles();\n this.addEventListener(\n 'sp-query-theme',\n this.onQueryTheme as EventListener\n );\n this.addEventListener(\n 'sp-language-context',\n this._handleContextPresence as EventListener\n );\n this.updateComplete = this.__createDeferredPromise();\n }\n\n public updateComplete!: Promise<boolean>;\n private __resolve!: (compelted: boolean) => void;\n\n private __createDeferredPromise(): Promise<boolean> {\n return new Promise((resolve) => {\n this.__resolve = resolve;\n });\n }\n\n /* c8 ignore next 12 */\n private onQueryTheme(event: CustomEvent<ThemeData>): void {\n if (event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n const { detail: theme } = event;\n theme.color = this.color || undefined;\n theme.scale = this.scale || undefined;\n theme.lang =\n this.lang || document.documentElement.lang || navigator.language;\n theme.theme = this.theme || undefined;\n }\n\n protected connectedCallback(): void {\n this.shouldAdoptStyles();\n // Note, first update/render handles styleElement so we only call this if\n // connected after first update.\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined) {\n window.ShadyCSS.styleElement(this);\n }\n // Add `this` to the instances array.\n Theme.instances.add(this);\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement | DocumentFragment | ShadowRoot;\n while (\n dirParent !== document.documentElement &&\n !(dirParent instanceof Theme)\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n (dirParent as ShadowRoot).host) as\n | HTMLElement\n | DocumentFragment\n | ShadowRoot;\n }\n this.dir = dirParent.dir === 'rtl' ? dirParent.dir : 'ltr';\n }\n }\n\n protected disconnectedCallback(): void {\n // Remove `this` to the instances array.\n Theme.instances.delete(this);\n }\n\n public startManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.add(el);\n }\n\n public stopManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.delete(el);\n }\n\n private trackedChildren: Set<HTMLElement> = new Set();\n\n private _updateRequested = false;\n\n private async shouldAdoptStyles(): Promise<void> {\n if (!this._updateRequested) {\n this.updateComplete = this.__createDeferredPromise();\n this._updateRequested = true;\n this._updateRequested = await false;\n this.adoptStyles();\n this.__resolve(true);\n }\n }\n\n protected adoptStyles(): void {\n const styles = this.styles; // No test coverage on Edge\n\n // There are three separate cases here based on Shadow DOM support.\n // (1) shadowRoot polyfilled: use ShadyCSS\n // (2) shadowRoot.adoptedStyleSheets available: use it.\n // (3) shadowRoot.adoptedStyleSheets polyfilled: append styles after rendering\n /* c8 ignore next 28 */\n if (\n window.ShadyCSS !== undefined &&\n !window.ShadyCSS.nativeShadow &&\n window.ShadyCSS.ScopingShim\n ) {\n // For browsers using the shim, there seems to be one set of\n // processed styles per template, so it is hard to nest styles. So,\n // for those, we load in all style fragments and then switch using a\n // host selector (e.g. :host([color='dark']))\n const fragmentCSS: string[] = [];\n for (const [kind, fragments] of Theme.themeFragmentsByKind) {\n for (const [name, { styles }] of fragments) {\n if (name === 'default') continue;\n let cssText = (styles as CSSResult).cssText;\n if (!Theme.defaultFragments.has(name as FragmentName)) {\n cssText = cssText.replace(\n ':host',\n `:host([${kind}='${name}'])`\n );\n }\n fragmentCSS.push(cssText);\n }\n }\n window.ShadyCSS.ScopingShim.prepareAdoptedCssText(\n fragmentCSS,\n this.localName\n );\n window.ShadyCSS.prepareTemplate(Theme.template, this.localName);\n } else if (supportsAdoptingStyleSheets) {\n const styleSheets: CSSStyleSheet[] = [];\n for (const style of styles) {\n styleSheets.push(\n (style as CSSResult).styleSheet as CSSStyleSheet\n );\n }\n this.shadowRoot.adoptedStyleSheets = styleSheets;\n /* c8 ignore next 9 */\n } else {\n const styleNodes = this.shadowRoot.querySelectorAll('style');\n styleNodes.forEach((element) => element.remove());\n styles.forEach((s) => {\n const style = document.createElement('style');\n style.textContent = (s as CSSResult).cssText;\n this.shadowRoot.appendChild(style);\n });\n }\n }\n\n static registerThemeFragment(\n name: FragmentName,\n kind: FragmentType,\n styles: CSSResultGroup\n ): void {\n const fragmentMap = Theme.themeFragmentsByKind.get(kind) || new Map();\n if (fragmentMap.size === 0) {\n Theme.themeFragmentsByKind.set(kind, fragmentMap);\n // we're adding our first fragment for this kind, set as default\n fragmentMap.set('default', { name, styles });\n Theme.defaultFragments.add(name);\n }\n fragmentMap.set(name, { name, styles });\n Theme.instances.forEach((instance) => instance.shouldAdoptStyles());\n }\n\n private _contextConsumers = new Map<\n HTMLElement,\n [ProvideLang['callback'], () => void]\n >();\n\n /* c8 ignore next 5 */\n private _provideContext(): void {\n this._contextConsumers.forEach(([callback, unsubscribe]) =>\n callback(this.lang, unsubscribe)\n );\n }\n\n private _handleContextPresence(event: CustomEvent<ProvideLang>): void {\n event.stopPropagation();\n const target = event.composedPath()[0] as HTMLElement;\n /* c8 ignore next 3 */\n if (this._contextConsumers.has(target)) {\n return;\n }\n this._contextConsumers.set(target, [\n event.detail.callback,\n () => this._contextConsumers.delete(target),\n ]);\n const [callback, unsubscribe] =\n this._contextConsumers.get(target) || [];\n if (callback && unsubscribe) {\n callback(\n this.lang ||\n document.documentElement.lang ||\n navigator.language,\n unsubscribe\n );\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAYA;AAAA,EAGI;AAAA,OACG;AACP,SAAS,eAAe;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResult,\n CSSResultGroup,\n supportsAdoptingStyleSheets,\n} from '@spectrum-web-components/base';\nimport { version } from '@spectrum-web-components/base/src/version.js';\n\ndeclare global {\n interface Window {\n ShadyCSS: {\n nativeShadow: boolean;\n prepareTemplate(\n template: HTMLTemplateElement,\n elementName: string,\n typeExtension?: string\n ): void;\n styleElement(host: HTMLElement): void;\n ScopingShim: {\n prepareAdoptedCssText(\n cssTextArray: string[],\n elementName: string\n ): void;\n };\n };\n }\n}\n\ntype ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {\n adoptedStyleSheets?: CSSStyleSheet[];\n};\n\ntype FragmentType = 'color' | 'scale' | 'system' | 'theme' | 'core' | 'app';\ntype SettableFragmentTypes = 'color' | 'scale' | 'system' | 'theme';\ntype FragmentMap = Map<string, { name: string; styles: CSSResultGroup }>;\nexport type ThemeFragmentMap = Map<FragmentType, FragmentMap>;\nexport type Color =\n | 'light'\n | 'lightest'\n | 'dark'\n | 'darkest'\n | 'light-express'\n | 'lightest-express'\n | 'dark-express'\n | 'darkest-express';\nexport type Scale = 'medium' | 'large' | 'medium-express' | 'large-express';\nexport type ThemeVariant = 'spectrum' | 'express';\nexport type SystemVariant = 'spectrum' | 'express';\nconst SystemVariantValues = ['spectrum', 'express'];\nconst ScaleValues = ['medium', 'large', 'medium-express', 'large-express'];\nconst ColorValues = [\n 'light',\n 'lightest',\n 'dark',\n 'darkest',\n 'light-express',\n 'lightest-express',\n 'dark-express',\n 'darkest-express',\n];\ntype FragmentName =\n | Color\n | Scale\n | ThemeVariant\n | SystemVariant\n | 'core'\n | 'app';\n\nexport interface ThemeData {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: SystemVariant;\n system?: SystemVariant;\n}\n\ntype ThemeKindProvider = {\n [P in SettableFragmentTypes]:\n | ThemeVariant\n | SystemVariant\n | Color\n | Scale\n | '';\n};\n\nexport interface ProvideLang {\n callback: (lang: string, unsubscribe: () => void) => void;\n}\n\n/**\n * @element sp-theme\n * @attr {string} [lang=\"\"] - The language of the content scoped to this `sp-theme` element, see: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang\" target=\"_blank\">MDN reference</a>.\n *\n * @slot - Content on which to apply the CSS Custom Properties defined by the current theme configuration\n */\nexport class Theme extends HTMLElement implements ThemeKindProvider {\n private static themeFragmentsByKind: ThemeFragmentMap = new Map();\n private static defaultFragments: Set<FragmentName> = new Set(['spectrum']);\n private static templateElement?: HTMLTemplateElement;\n private static instances: Set<Theme> = new Set();\n static VERSION = version;\n\n static get observedAttributes(): string[] {\n return [\n 'color',\n 'scale',\n 'lang',\n 'dir',\n 'system',\n /* deprecated attributes, but still observing */\n 'theme',\n ];\n }\n\n _dir: 'ltr' | 'rtl' | '' = '';\n\n override set dir(dir: 'ltr' | 'rtl' | '') {\n if (dir === this.dir) return;\n this.setAttribute('dir', dir);\n this._dir = dir;\n const targetDir = dir === 'rtl' ? dir : 'ltr';\n /* c8 ignore next 3 */\n this.trackedChildren.forEach((el) => {\n el.setAttribute('dir', targetDir);\n });\n }\n\n /**\n * Reading direction of the content scoped to this `sp-theme` element.\n * @type {\"ltr\" | \"rtl\" | \"\"}\n * @attr\n */\n override get dir(): 'ltr' | 'rtl' | '' {\n return this._dir;\n }\n\n protected attributeChangedCallback(\n attrName: SettableFragmentTypes | 'lang' | 'dir',\n old: string | null,\n value: string | null\n ): void {\n if (old === value) {\n return;\n }\n if (attrName === 'color') {\n this.color = value as Color;\n } else if (attrName === 'scale') {\n this.scale = value as Scale;\n /* c8 ignore next 3 */\n } else if (attrName === 'lang' && !!value) {\n this.lang = value;\n this._provideContext();\n } else if (attrName === 'theme') {\n this.theme = value as SystemVariant;\n window.__swc.warn(\n this,\n 'property theme in <sp-theme> has been deprecated. Please use system instead like this <sp-theme system=\"spectrum\"/>',\n 'https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation',\n { level: 'deprecation' }\n );\n } else if (attrName === 'system') {\n this.system = value as SystemVariant;\n } else if (attrName === 'dir') {\n this.dir = value as 'ltr' | 'rtl' | '';\n }\n }\n\n private requestUpdate(): void {\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.styleElement(this);\n } else {\n this.shouldAdoptStyles();\n }\n }\n\n public override shadowRoot!: ShadowRootWithAdoptedStyleSheets;\n\n private _system: SystemVariant | '' = 'spectrum';\n /**\n * The Spectrum system that is applied to the content scoped to this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"spectrum\" | \"express\" }\n * @attr\n */\n get system(): SystemVariant | '' {\n const systemFragments = Theme.themeFragmentsByKind.get('system');\n const { name } =\n (systemFragments && systemFragments.get('default')) || {};\n return this._system || (name as SystemVariant) || '';\n }\n\n set system(newValue: SystemVariant | '') {\n if (newValue === this._system) return;\n const system =\n !!newValue && SystemVariantValues.includes(newValue)\n ? newValue\n : this.system;\n if (system !== this._system) {\n this._system = system;\n this.requestUpdate();\n }\n if (system) {\n this.setAttribute('system', system);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('system');\n }\n }\n\n /*\n * @deprecated The `theme` attribute has been deprecated in favor of the `system` attribute.\n */\n get theme(): SystemVariant | '' {\n if (!this.system) {\n this.removeAttribute('system');\n }\n return this.system;\n }\n\n /*\n * @deprecated The `theme` attribute has been deprecated in favor of the `system` attribute.\n */\n set theme(newValue: SystemVariant | '') {\n this.system = newValue;\n this.requestUpdate();\n }\n\n private _color: Color | '' = '';\n\n /**\n * The Spectrum color stops to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"lightest\" | \"light\" | \"dark\" | \"darkest\" | \"\"}\n * @attr\n */\n get color(): Color | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('color');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._color || (name as Color) || '';\n }\n\n set color(newValue: Color | '') {\n if (newValue === this._color) return;\n const color =\n !!newValue && ColorValues.includes(newValue)\n ? newValue\n : this.color;\n if (color !== this._color) {\n this._color = color;\n this.requestUpdate();\n }\n if (color) {\n this.setAttribute('color', color);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('color');\n }\n }\n\n private _scale: Scale | '' = '';\n\n /**\n * The Spectrum platform scale to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"medium\" | \"large\" | \"\"}\n * @attr\n */\n get scale(): Scale | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('scale');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._scale || (name as Scale) || '';\n }\n\n set scale(newValue: Scale | '') {\n if (newValue === this._scale) return;\n const scale =\n !!newValue && ScaleValues.includes(newValue)\n ? newValue\n : this.scale;\n if (scale !== this._scale) {\n this._scale = scale;\n this.requestUpdate();\n }\n if (scale) {\n this.setAttribute('scale', scale);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('scale');\n }\n }\n\n private get styles(): CSSResultGroup[] {\n const themeKinds: FragmentType[] = [\n ...Theme.themeFragmentsByKind.keys(),\n ];\n const getStyle = (\n fragments: FragmentMap,\n name: FragmentName,\n kind?: FragmentType\n ): CSSResultGroup | undefined => {\n const currentStyles =\n kind &&\n kind !== 'theme' &&\n kind !== 'system' &&\n this.theme === 'express' &&\n this.system === 'express'\n ? fragments.get(`${name}-express`)\n : fragments.get(name);\n // theme=\"spectrum\" is available by default and doesn't need to be applied.\n const isAppliedFragment =\n name === 'spectrum' || !kind || this.hasAttribute(kind);\n if (currentStyles && isAppliedFragment) {\n return currentStyles.styles;\n }\n return;\n };\n const styles = themeKinds.reduce((acc, kind) => {\n const kindFragments = Theme.themeFragmentsByKind.get(\n kind\n ) as FragmentMap;\n let style: CSSResultGroup | undefined;\n if (kind === 'app' || kind === 'core') {\n style = getStyle(kindFragments, kind);\n } else {\n const { [kind]: name } = this;\n style = getStyle(kindFragments, <FragmentName>name, kind);\n }\n if (style) {\n acc.push(style);\n }\n return acc;\n }, [] as CSSResultGroup[]);\n if (window.__swc.DEBUG) {\n const issues: string[] = [];\n const checkForAttribute = (\n name: FragmentType,\n resolvedValue?: string,\n actualValue?: string\n ): void => {\n const systemModifier =\n this.system && this.system !== 'spectrum'\n ? `-${this.system}`\n : '';\n if (!resolvedValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute and there is no default value on which to fallback.`\n );\n } else if (!actualValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute, the default value (\"${resolvedValue}\") is being used as a fallback.`\n );\n } else if (\n !Theme.themeFragmentsByKind\n .get(name)\n ?.get(\n resolvedValue +\n (name === 'system' ? '' : systemModifier)\n )\n ) {\n issues.push(\n `You have set \"${name}='${resolvedValue}'\" but the associated system fragment has not been loaded.`\n );\n }\n };\n\n checkForAttribute('system', this.system, this._system);\n checkForAttribute('color', this.color, this._color);\n checkForAttribute('scale', this.scale, this._scale);\n\n // Check for deprecated attributes\n if (this.hasAttribute('theme')) {\n issues.push(\n `The \"theme\" attribute has been deprecated in favor of \"system\".`\n );\n }\n\n if (issues.length) {\n window.__swc.warn(\n this,\n 'You are leveraging an <sp-theme> element and the following issues may disrupt your theme delivery:',\n 'https://opensource.adobe.com/spectrum-web-components/components/theme/#example',\n {\n issues,\n }\n );\n }\n if (['lightest', 'darkest'].includes(this.color)) {\n window.__swc.warn(\n this,\n `Color lightest and darkest are deprecated and will be removed in a future release`,\n 'https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation',\n { level: 'deprecation' }\n );\n }\n }\n return [...styles];\n }\n\n private static get template(): HTMLTemplateElement {\n if (!this.templateElement) {\n this.templateElement = document.createElement('template');\n this.templateElement.innerHTML = '<slot></slot>';\n }\n return this.templateElement;\n }\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n const node = document.importNode(Theme.template.content, true);\n this.shadowRoot.appendChild(node);\n this.shouldAdoptStyles();\n this.addEventListener(\n 'sp-query-theme',\n this.onQueryTheme as EventListener\n );\n this.addEventListener(\n 'sp-language-context',\n this._handleContextPresence as EventListener\n );\n this.updateComplete = this.__createDeferredPromise();\n }\n\n public updateComplete!: Promise<boolean>;\n private __resolve!: (compelted: boolean) => void;\n\n private __createDeferredPromise(): Promise<boolean> {\n return new Promise((resolve) => {\n this.__resolve = resolve;\n });\n }\n\n /* c8 ignore next 12 */\n private onQueryTheme(event: CustomEvent<ThemeData>): void {\n if (event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n const { detail: theme } = event;\n theme.color = this.color || undefined;\n theme.scale = this.scale || undefined;\n theme.lang =\n this.lang || document.documentElement.lang || navigator.language;\n // `theme` is deprecated in favor of `system` but maintaining `theme` as a deprecated path.\n theme.theme = this.system || undefined;\n theme.system = this.system || undefined;\n }\n\n protected connectedCallback(): void {\n this.shouldAdoptStyles();\n // Note, first update/render handles styleElement so we only call this if\n // connected after first update.\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined) {\n window.ShadyCSS.styleElement(this);\n }\n // Add `this` to the instances array.\n Theme.instances.add(this);\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement | DocumentFragment | ShadowRoot;\n while (\n dirParent !== document.documentElement &&\n !(dirParent instanceof Theme)\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n (dirParent as ShadowRoot).host) as\n | HTMLElement\n | DocumentFragment\n | ShadowRoot;\n }\n this.dir = dirParent.dir === 'rtl' ? dirParent.dir : 'ltr';\n }\n }\n\n protected disconnectedCallback(): void {\n // Remove `this` to the instances array.\n Theme.instances.delete(this);\n }\n\n public startManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.add(el);\n }\n\n public stopManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.delete(el);\n }\n\n private trackedChildren: Set<HTMLElement> = new Set();\n\n private _updateRequested = false;\n\n private async shouldAdoptStyles(): Promise<void> {\n if (!this._updateRequested) {\n this.updateComplete = this.__createDeferredPromise();\n this._updateRequested = true;\n this._updateRequested = await false;\n this.adoptStyles();\n this.__resolve(true);\n }\n }\n\n protected adoptStyles(): void {\n const styles = this.styles; // No test coverage on Edge\n\n // There are three separate cases here based on Shadow DOM support.\n // (1) shadowRoot polyfilled: use ShadyCSS\n // (2) shadowRoot.adoptedStyleSheets available: use it.\n // (3) shadowRoot.adoptedStyleSheets polyfilled: append styles after rendering\n /* c8 ignore next 28 */\n if (\n window.ShadyCSS !== undefined &&\n !window.ShadyCSS.nativeShadow &&\n window.ShadyCSS.ScopingShim\n ) {\n // For browsers using the shim, there seems to be one set of\n // processed styles per template, so it is hard to nest styles. So,\n // for those, we load in all style fragments and then switch using a\n // host selector (e.g. :host([color='dark']))\n const fragmentCSS: string[] = [];\n for (const [kind, fragments] of Theme.themeFragmentsByKind) {\n for (const [name, { styles }] of fragments) {\n if (name === 'default') continue;\n let cssText = (styles as CSSResult).cssText;\n if (!Theme.defaultFragments.has(name as FragmentName)) {\n cssText = cssText.replace(\n ':host',\n `:host([${kind}='${name}'])`\n );\n }\n fragmentCSS.push(cssText);\n }\n }\n window.ShadyCSS.ScopingShim.prepareAdoptedCssText(\n fragmentCSS,\n this.localName\n );\n window.ShadyCSS.prepareTemplate(Theme.template, this.localName);\n } else if (supportsAdoptingStyleSheets) {\n const styleSheets: CSSStyleSheet[] = [];\n for (const style of styles) {\n styleSheets.push(\n (style as CSSResult).styleSheet as CSSStyleSheet\n );\n }\n this.shadowRoot.adoptedStyleSheets = styleSheets;\n /* c8 ignore next 9 */\n } else {\n const styleNodes = this.shadowRoot.querySelectorAll('style');\n styleNodes.forEach((element) => element.remove());\n styles.forEach((s) => {\n const style = document.createElement('style');\n style.textContent = (s as CSSResult).cssText;\n this.shadowRoot.appendChild(style);\n });\n }\n }\n\n static registerThemeFragment(\n name: FragmentName,\n kind: FragmentType,\n styles: CSSResultGroup\n ): void {\n const fragmentMap = Theme.themeFragmentsByKind.get(kind) || new Map();\n if (fragmentMap.size === 0) {\n Theme.themeFragmentsByKind.set(kind, fragmentMap);\n // we're adding our first fragment for this kind, set as default\n fragmentMap.set('default', { name, styles });\n Theme.defaultFragments.add(name);\n }\n fragmentMap.set(name, { name, styles });\n Theme.instances.forEach((instance) => instance.shouldAdoptStyles());\n }\n\n private _contextConsumers = new Map<\n HTMLElement,\n [ProvideLang['callback'], () => void]\n >();\n\n /* c8 ignore next 5 */\n private _provideContext(): void {\n this._contextConsumers.forEach(([callback, unsubscribe]) =>\n callback(this.lang, unsubscribe)\n );\n }\n\n private _handleContextPresence(event: CustomEvent<ProvideLang>): void {\n event.stopPropagation();\n const target = event.composedPath()[0] as HTMLElement;\n /* c8 ignore next 3 */\n if (this._contextConsumers.has(target)) {\n return;\n }\n this._contextConsumers.set(target, [\n event.detail.callback,\n () => this._contextConsumers.delete(target),\n ]);\n const [callback, unsubscribe] =\n this._contextConsumers.get(target) || [];\n if (callback && unsubscribe) {\n callback(\n this.lang ||\n document.documentElement.lang ||\n navigator.language,\n unsubscribe\n );\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAYA;AAAA,EAGI;AAAA,OACG;AACP,SAAS,eAAe;AA0CxB,MAAM,sBAAsB,CAAC,YAAY,S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AAkB;AAAA,MAAQ,CAAC,CAAC,UAAU,WAAW,MAClD,SAAS,KAAK,MAAM,WAAW;AAAA,IACnC;AAAA,EACJ;AAAA,EAEQ,uBAAuB,OAAuC;AAClE,UAAM,gBAAgB;AACtB,UAAM,SAAS,MAAM,aAAa,EAAE,CAAC;AAErC,QAAI,KAAK,kBAAkB,IAAI,MAAM,GAAG;AACpC;AAAA,IACJ;AACA,SAAK,kBAAkB,IAAI,QAAQ;AAAA,MAC/B,MAAM,OAAO;AAAA,MACb,MAAM,KAAK,kBAAkB,OAAO,MAAM;AAAA,IAC9C,CAAC;AACD,UAAM,CAAC,UAAU,WAAW,IACxB,KAAK,kBAAkB,IAAI,MAAM,KAAK,CAAC;AAC3C,QAAI,YAAY,aAAa;AACzB;AAAA,QACI,KAAK,QACD,SAAS,gBAAgB,QACzB,UAAU;AAAA,QACd;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAxgBa,OACM,uBAAyC,oBAAI,IAAI;AADvD,OAEM,mBAAsC,oBAAI,IAAI,CAAC,UAAU,CAAC;AAFhE,OAIM,YAAwB,oBAAI,IAAI;AAJtC,OAKF,UAAU;AALd,WAAM,QAAN;",
|
|
6
6
|
"names": ["styles"]
|
|
7
7
|
}
|
package/src/Theme.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{supportsAdoptingStyleSheets as
|
|
1
|
+
"use strict";import{supportsAdoptingStyleSheets as m}from"@spectrum-web-components/base";import{version as d}from"@spectrum-web-components/base/src/version.js";const h=["spectrum","express"],c=["medium","large","medium-express","large-express"],p=["light","lightest","dark","darkest","light-express","lightest-express","dark-express","darkest-express"],r=class r extends HTMLElement{constructor(){super();this._dir="";this._system="spectrum";this._color="";this._scale="";this.trackedChildren=new Set;this._updateRequested=!1;this._contextConsumers=new Map;this.attachShadow({mode:"open"});const e=document.importNode(r.template.content,!0);this.shadowRoot.appendChild(e),this.shouldAdoptStyles(),this.addEventListener("sp-query-theme",this.onQueryTheme),this.addEventListener("sp-language-context",this._handleContextPresence),this.updateComplete=this.__createDeferredPromise()}static get observedAttributes(){return["color","scale","lang","dir","system","theme"]}set dir(e){if(e===this.dir)return;this.setAttribute("dir",e),this._dir=e;const t=e==="rtl"?e:"ltr";this.trackedChildren.forEach(s=>{s.setAttribute("dir",t)})}get dir(){return this._dir}attributeChangedCallback(e,t,s){t!==s&&(e==="color"?this.color=s:e==="scale"?this.scale=s:e==="lang"&&s?(this.lang=s,this._provideContext()):e==="theme"?(this.theme=s,window.__swc.warn(this,'property theme in <sp-theme> has been deprecated. Please use system instead like this <sp-theme system="spectrum"/>',"https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation",{level:"deprecation"})):e==="system"?this.system=s:e==="dir"&&(this.dir=s))}requestUpdate(){window.ShadyCSS!==void 0&&!window.ShadyCSS.nativeShadow?window.ShadyCSS.styleElement(this):this.shouldAdoptStyles()}get system(){const e=r.themeFragmentsByKind.get("system"),{name:t}=e&&e.get("default")||{};return this._system||t||""}set system(e){if(e===this._system)return;const t=e&&h.includes(e)?e:this.system;t!==this._system&&(this._system=t,this.requestUpdate()),t?this.setAttribute("system",t):this.removeAttribute("system")}get theme(){return this.system||this.removeAttribute("system"),this.system}set theme(e){this.system=e,this.requestUpdate()}get color(){const e=r.themeFragmentsByKind.get("color"),{name:t}=e&&e.get("default")||{};return this._color||t||""}set color(e){if(e===this._color)return;const t=e&&p.includes(e)?e:this.color;t!==this._color&&(this._color=t,this.requestUpdate()),t?this.setAttribute("color",t):this.removeAttribute("color")}get scale(){const e=r.themeFragmentsByKind.get("scale"),{name:t}=e&&e.get("default")||{};return this._scale||t||""}set scale(e){if(e===this._scale)return;const t=e&&c.includes(e)?e:this.scale;t!==this._scale&&(this._scale=t,this.requestUpdate()),t?this.setAttribute("scale",t):this.removeAttribute("scale")}get styles(){const e=[...r.themeFragmentsByKind.keys()],t=(a,i,n)=>{const o=n&&n!=="theme"&&n!=="system"&&this.theme==="express"&&this.system==="express"?a.get(`${i}-express`):a.get(i),l=i==="spectrum"||!n||this.hasAttribute(n);if(o&&l)return o.styles};return[...e.reduce((a,i)=>{const n=r.themeFragmentsByKind.get(i);let o;if(i==="app"||i==="core")o=t(n,i);else{const{[i]:l}=this;o=t(n,l,i)}return o&&a.push(o),a},[])]}static get template(){return this.templateElement||(this.templateElement=document.createElement("template"),this.templateElement.innerHTML="<slot></slot>"),this.templateElement}__createDeferredPromise(){return new Promise(e=>{this.__resolve=e})}onQueryTheme(e){if(e.defaultPrevented)return;e.preventDefault();const{detail:t}=e;t.color=this.color||void 0,t.scale=this.scale||void 0,t.lang=this.lang||document.documentElement.lang||navigator.language,t.theme=this.system||void 0,t.system=this.system||void 0}connectedCallback(){if(this.shouldAdoptStyles(),window.ShadyCSS!==void 0&&window.ShadyCSS.styleElement(this),r.instances.add(this),!this.hasAttribute("dir")){let e=this.assignedSlot||this.parentNode;for(;e!==document.documentElement&&!(e instanceof r);)e=e.assignedSlot||e.parentNode||e.host;this.dir=e.dir==="rtl"?e.dir:"ltr"}}disconnectedCallback(){r.instances.delete(this)}startManagingContentDirection(e){this.trackedChildren.add(e)}stopManagingContentDirection(e){this.trackedChildren.delete(e)}async shouldAdoptStyles(){this._updateRequested||(this.updateComplete=this.__createDeferredPromise(),this._updateRequested=!0,this._updateRequested=await!1,this.adoptStyles(),this.__resolve(!0))}adoptStyles(){const e=this.styles;if(window.ShadyCSS!==void 0&&!window.ShadyCSS.nativeShadow&&window.ShadyCSS.ScopingShim){const t=[];for(const[s,a]of r.themeFragmentsByKind)for(const[i,{styles:n}]of a){if(i==="default")continue;let o=n.cssText;r.defaultFragments.has(i)||(o=o.replace(":host",`:host([${s}='${i}'])`)),t.push(o)}window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t,this.localName),window.ShadyCSS.prepareTemplate(r.template,this.localName)}else if(m){const t=[];for(const s of e)t.push(s.styleSheet);this.shadowRoot.adoptedStyleSheets=t}else this.shadowRoot.querySelectorAll("style").forEach(s=>s.remove()),e.forEach(s=>{const a=document.createElement("style");a.textContent=s.cssText,this.shadowRoot.appendChild(a)})}static registerThemeFragment(e,t,s){const a=r.themeFragmentsByKind.get(t)||new Map;a.size===0&&(r.themeFragmentsByKind.set(t,a),a.set("default",{name:e,styles:s}),r.defaultFragments.add(e)),a.set(e,{name:e,styles:s}),r.instances.forEach(i=>i.shouldAdoptStyles())}_provideContext(){this._contextConsumers.forEach(([e,t])=>e(this.lang,t))}_handleContextPresence(e){e.stopPropagation();const t=e.composedPath()[0];if(this._contextConsumers.has(t))return;this._contextConsumers.set(t,[e.detail.callback,()=>this._contextConsumers.delete(t)]);const[s,a]=this._contextConsumers.get(t)||[];s&&a&&s(this.lang||document.documentElement.lang||navigator.language,a)}};r.themeFragmentsByKind=new Map,r.defaultFragments=new Set(["spectrum"]),r.instances=new Set,r.VERSION=d;export let Theme=r;
|
|
2
2
|
//# sourceMappingURL=Theme.js.map
|
package/src/Theme.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["Theme.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResult,\n CSSResultGroup,\n supportsAdoptingStyleSheets,\n} from '@spectrum-web-components/base';\nimport { version } from '@spectrum-web-components/base/src/version.js';\n\ndeclare global {\n interface Window {\n ShadyCSS: {\n nativeShadow: boolean;\n prepareTemplate(\n template: HTMLTemplateElement,\n elementName: string,\n typeExtension?: string\n ): void;\n styleElement(host: HTMLElement): void;\n ScopingShim: {\n prepareAdoptedCssText(\n cssTextArray: string[],\n elementName: string\n ): void;\n };\n };\n }\n}\n\ntype ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {\n adoptedStyleSheets?: CSSStyleSheet[];\n};\n\ntype FragmentType = 'color' | 'scale' | 'theme' | 'core' | 'app';\ntype SettableFragmentTypes = 'color' | 'scale' | 'theme';\ntype FragmentMap = Map<string, { name: string; styles: CSSResultGroup }>;\nexport type ThemeFragmentMap = Map<FragmentType, FragmentMap>;\nexport type Color =\n | 'light'\n | 'lightest'\n | 'dark'\n | 'darkest'\n | 'light-express'\n | 'lightest-express'\n | 'dark-express'\n | 'darkest-express';\nexport type Scale = 'medium' | 'large' | 'medium-express' | 'large-express';\nexport type ThemeVariant = 'spectrum' | 'express';\nconst ThemeVariantValues = ['spectrum', 'express'];\nconst ScaleValues = ['medium', 'large', 'medium-express', 'large-express'];\nconst ColorValues = [\n 'light',\n 'lightest',\n 'dark',\n 'darkest',\n 'light-express',\n 'lightest-express',\n 'dark-express',\n 'darkest-express',\n];\ntype FragmentName = Color | Scale | ThemeVariant | 'core' | 'app';\n\nexport interface ThemeData {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: ThemeVariant;\n}\n\ntype ThemeKindProvider = {\n [P in SettableFragmentTypes]: ThemeVariant | Color | Scale | '';\n};\n\nexport interface ProvideLang {\n callback: (lang: string, unsubscribe: () => void) => void;\n}\n\n/**\n * @element sp-theme\n * @attr {string} [lang=\"\"] - The language of the content scoped to this `sp-theme` element, see: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang\" target=\"_blank\">MDN reference</a>.\n *\n * @slot - Content on which to apply the CSS Custom Properties defined by the current theme configuration\n */\nexport class Theme extends HTMLElement implements ThemeKindProvider {\n private static themeFragmentsByKind: ThemeFragmentMap = new Map();\n private static defaultFragments: Set<FragmentName> = new Set(['spectrum']);\n private static templateElement?: HTMLTemplateElement;\n private static instances: Set<Theme> = new Set();\n static VERSION = version;\n\n static get observedAttributes(): string[] {\n return ['color', 'scale', 'theme', 'lang', 'dir'];\n }\n\n _dir: 'ltr' | 'rtl' | '' = '';\n\n override set dir(dir: 'ltr' | 'rtl' | '') {\n if (dir === this.dir) return;\n this.setAttribute('dir', dir);\n this._dir = dir;\n const targetDir = dir === 'rtl' ? dir : 'ltr';\n /* c8 ignore next 3 */\n this.trackedChildren.forEach((el) => {\n el.setAttribute('dir', targetDir);\n });\n }\n\n /**\n * Reading direction of the content scoped to this `sp-theme` element.\n * @type {\"ltr\" | \"rtl\" | \"\"}\n * @attr\n */\n override get dir(): 'ltr' | 'rtl' | '' {\n return this._dir;\n }\n\n protected attributeChangedCallback(\n attrName: SettableFragmentTypes | 'lang' | 'dir',\n old: string | null,\n value: string | null\n ): void {\n if (old === value) {\n return;\n }\n if (attrName === 'color') {\n this.color = value as Color;\n } else if (attrName === 'scale') {\n this.scale = value as Scale;\n /* c8 ignore next 3 */\n } else if (attrName === 'lang' && !!value) {\n this.lang = value;\n this._provideContext();\n } else if (attrName === 'theme') {\n this.theme = value as ThemeVariant;\n } else if (attrName === 'dir') {\n this.dir = value as 'ltr' | 'rtl' | '';\n }\n }\n\n private requestUpdate(): void {\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.styleElement(this);\n } else {\n this.shouldAdoptStyles();\n }\n }\n\n public override shadowRoot!: ShadowRootWithAdoptedStyleSheets;\n\n private _theme: ThemeVariant | '' = 'spectrum';\n\n /**\n * The Spectrum theme that is applied to the content scoped to this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"spectrum\" | \"express\" | \"\"}\n * @attr\n */\n get theme(): ThemeVariant | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('theme');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._theme || (name as ThemeVariant) || '';\n }\n\n set theme(newValue: ThemeVariant | '') {\n if (newValue === this._theme) return;\n const theme =\n !!newValue && ThemeVariantValues.includes(newValue)\n ? newValue\n : this.theme;\n if (theme !== this._theme) {\n this._theme = theme;\n this.requestUpdate();\n }\n if (theme) {\n this.setAttribute('theme', theme);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('theme');\n }\n }\n\n private _color: Color | '' = '';\n\n /**\n * The Spectrum color stops to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"lightest\" | \"light\" | \"dark\" | \"darkest\" | \"\"}\n * @attr\n */\n get color(): Color | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('color');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._color || (name as Color) || '';\n }\n\n set color(newValue: Color | '') {\n if (newValue === this._color) return;\n const color =\n !!newValue && ColorValues.includes(newValue)\n ? newValue\n : this.color;\n if (color !== this._color) {\n this._color = color;\n this.requestUpdate();\n }\n if (color) {\n this.setAttribute('color', color);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('color');\n }\n }\n\n private _scale: Scale | '' = '';\n\n /**\n * The Spectrum platform scale to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"medium\" | \"large\" | \"\"}\n * @attr\n */\n get scale(): Scale | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('scale');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._scale || (name as Scale) || '';\n }\n\n set scale(newValue: Scale | '') {\n if (newValue === this._scale) return;\n const scale =\n !!newValue && ScaleValues.includes(newValue)\n ? newValue\n : this.scale;\n if (scale !== this._scale) {\n this._scale = scale;\n this.requestUpdate();\n }\n if (scale) {\n this.setAttribute('scale', scale);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('scale');\n }\n }\n\n private get styles(): CSSResultGroup[] {\n const themeKinds: FragmentType[] = [\n ...Theme.themeFragmentsByKind.keys(),\n ];\n const getStyle = (\n fragments: FragmentMap,\n name: FragmentName,\n kind?: FragmentType\n ): CSSResultGroup | undefined => {\n const currentStyles =\n kind && kind !== 'theme' && this.theme === 'express'\n ? fragments.get(`${name}-express`)\n : fragments.get(name);\n // theme=\"spectrum\" is available by default and doesn't need to be applied.\n const isAppliedFragment =\n name === 'spectrum' || !kind || this.hasAttribute(kind);\n if (currentStyles && isAppliedFragment) {\n return currentStyles.styles;\n }\n return;\n };\n const styles = themeKinds.reduce((acc, kind) => {\n const kindFragments = Theme.themeFragmentsByKind.get(\n kind\n ) as FragmentMap;\n let style: CSSResultGroup | undefined;\n if (kind === 'app' || kind === 'core') {\n style = getStyle(kindFragments, kind);\n } else {\n const { [kind]: name } = this;\n style = getStyle(kindFragments, <FragmentName>name, kind);\n }\n if (style) {\n acc.push(style);\n }\n return acc;\n }, [] as CSSResultGroup[]);\n if (window.__swc.DEBUG) {\n const issues: string[] = [];\n const checkForAttribute = (\n name: FragmentType,\n resolvedValue?: string,\n actualValue?: string\n ): void => {\n const themeModifier =\n this.theme && this.theme !== 'spectrum'\n ? `-${this.theme}`\n : '';\n if (!resolvedValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute and there is no default value on which to fallback.`\n );\n } else if (!actualValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute, the default value (\"${resolvedValue}\") is being used as a fallback.`\n );\n } else if (\n !Theme.themeFragmentsByKind\n .get(name)\n ?.get(\n resolvedValue +\n (name === 'theme' ? '' : themeModifier)\n )\n ) {\n issues.push(\n `You have set \"${name}='${resolvedValue}'\" but the associated theme fragment has not been loaded.`\n );\n }\n };\n checkForAttribute('theme', this.theme, this._theme);\n checkForAttribute('color', this.color, this._color);\n checkForAttribute('scale', this.scale, this._scale);\n if (issues.length) {\n window.__swc.warn(\n this,\n 'You are leveraging an <sp-theme> element and the following issues may disrupt your theme delivery:',\n 'https://opensource.adobe.com/spectrum-web-components/components/theme/#example',\n {\n issues,\n }\n );\n }\n if (['lightest', 'darkest'].includes(this.color)) {\n window.__swc.warn(\n this,\n `Color lightest and darkest are deprecated and will be removed in a future release`,\n 'https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation',\n { level: 'deprecation' }\n );\n }\n }\n return [...styles];\n }\n\n private static get template(): HTMLTemplateElement {\n if (!this.templateElement) {\n this.templateElement = document.createElement('template');\n this.templateElement.innerHTML = '<slot></slot>';\n }\n return this.templateElement;\n }\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n const node = document.importNode(Theme.template.content, true);\n this.shadowRoot.appendChild(node);\n this.shouldAdoptStyles();\n this.addEventListener(\n 'sp-query-theme',\n this.onQueryTheme as EventListener\n );\n this.addEventListener(\n 'sp-language-context',\n this._handleContextPresence as EventListener\n );\n this.updateComplete = this.__createDeferredPromise();\n }\n\n public updateComplete!: Promise<boolean>;\n private __resolve!: (compelted: boolean) => void;\n\n private __createDeferredPromise(): Promise<boolean> {\n return new Promise((resolve) => {\n this.__resolve = resolve;\n });\n }\n\n /* c8 ignore next 12 */\n private onQueryTheme(event: CustomEvent<ThemeData>): void {\n if (event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n const { detail: theme } = event;\n theme.color = this.color || undefined;\n theme.scale = this.scale || undefined;\n theme.lang =\n this.lang || document.documentElement.lang || navigator.language;\n theme.theme = this.theme || undefined;\n }\n\n protected connectedCallback(): void {\n this.shouldAdoptStyles();\n // Note, first update/render handles styleElement so we only call this if\n // connected after first update.\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined) {\n window.ShadyCSS.styleElement(this);\n }\n // Add `this` to the instances array.\n Theme.instances.add(this);\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement | DocumentFragment | ShadowRoot;\n while (\n dirParent !== document.documentElement &&\n !(dirParent instanceof Theme)\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n (dirParent as ShadowRoot).host) as\n | HTMLElement\n | DocumentFragment\n | ShadowRoot;\n }\n this.dir = dirParent.dir === 'rtl' ? dirParent.dir : 'ltr';\n }\n }\n\n protected disconnectedCallback(): void {\n // Remove `this` to the instances array.\n Theme.instances.delete(this);\n }\n\n public startManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.add(el);\n }\n\n public stopManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.delete(el);\n }\n\n private trackedChildren: Set<HTMLElement> = new Set();\n\n private _updateRequested = false;\n\n private async shouldAdoptStyles(): Promise<void> {\n if (!this._updateRequested) {\n this.updateComplete = this.__createDeferredPromise();\n this._updateRequested = true;\n this._updateRequested = await false;\n this.adoptStyles();\n this.__resolve(true);\n }\n }\n\n protected adoptStyles(): void {\n const styles = this.styles; // No test coverage on Edge\n\n // There are three separate cases here based on Shadow DOM support.\n // (1) shadowRoot polyfilled: use ShadyCSS\n // (2) shadowRoot.adoptedStyleSheets available: use it.\n // (3) shadowRoot.adoptedStyleSheets polyfilled: append styles after rendering\n /* c8 ignore next 28 */\n if (\n window.ShadyCSS !== undefined &&\n !window.ShadyCSS.nativeShadow &&\n window.ShadyCSS.ScopingShim\n ) {\n // For browsers using the shim, there seems to be one set of\n // processed styles per template, so it is hard to nest styles. So,\n // for those, we load in all style fragments and then switch using a\n // host selector (e.g. :host([color='dark']))\n const fragmentCSS: string[] = [];\n for (const [kind, fragments] of Theme.themeFragmentsByKind) {\n for (const [name, { styles }] of fragments) {\n if (name === 'default') continue;\n let cssText = (styles as CSSResult).cssText;\n if (!Theme.defaultFragments.has(name as FragmentName)) {\n cssText = cssText.replace(\n ':host',\n `:host([${kind}='${name}'])`\n );\n }\n fragmentCSS.push(cssText);\n }\n }\n window.ShadyCSS.ScopingShim.prepareAdoptedCssText(\n fragmentCSS,\n this.localName\n );\n window.ShadyCSS.prepareTemplate(Theme.template, this.localName);\n } else if (supportsAdoptingStyleSheets) {\n const styleSheets: CSSStyleSheet[] = [];\n for (const style of styles) {\n styleSheets.push(\n (style as CSSResult).styleSheet as CSSStyleSheet\n );\n }\n this.shadowRoot.adoptedStyleSheets = styleSheets;\n /* c8 ignore next 9 */\n } else {\n const styleNodes = this.shadowRoot.querySelectorAll('style');\n styleNodes.forEach((element) => element.remove());\n styles.forEach((s) => {\n const style = document.createElement('style');\n style.textContent = (s as CSSResult).cssText;\n this.shadowRoot.appendChild(style);\n });\n }\n }\n\n static registerThemeFragment(\n name: FragmentName,\n kind: FragmentType,\n styles: CSSResultGroup\n ): void {\n const fragmentMap = Theme.themeFragmentsByKind.get(kind) || new Map();\n if (fragmentMap.size === 0) {\n Theme.themeFragmentsByKind.set(kind, fragmentMap);\n // we're adding our first fragment for this kind, set as default\n fragmentMap.set('default', { name, styles });\n Theme.defaultFragments.add(name);\n }\n fragmentMap.set(name, { name, styles });\n Theme.instances.forEach((instance) => instance.shouldAdoptStyles());\n }\n\n private _contextConsumers = new Map<\n HTMLElement,\n [ProvideLang['callback'], () => void]\n >();\n\n /* c8 ignore next 5 */\n private _provideContext(): void {\n this._contextConsumers.forEach(([callback, unsubscribe]) =>\n callback(this.lang, unsubscribe)\n );\n }\n\n private _handleContextPresence(event: CustomEvent<ProvideLang>): void {\n event.stopPropagation();\n const target = event.composedPath()[0] as HTMLElement;\n /* c8 ignore next 3 */\n if (this._contextConsumers.has(target)) {\n return;\n }\n this._contextConsumers.set(target, [\n event.detail.callback,\n () => this._contextConsumers.delete(target),\n ]);\n const [callback, unsubscribe] =\n this._contextConsumers.get(target) || [];\n if (callback && unsubscribe) {\n callback(\n this.lang ||\n document.documentElement.lang ||\n navigator.language,\n unsubscribe\n );\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "aAYA,OAGI,+BAAAA,MACG,gCACP,OAAS,WAAAC,MAAe,+
|
|
6
|
-
"names": ["supportsAdoptingStyleSheets", "version", "
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResult,\n CSSResultGroup,\n supportsAdoptingStyleSheets,\n} from '@spectrum-web-components/base';\nimport { version } from '@spectrum-web-components/base/src/version.js';\n\ndeclare global {\n interface Window {\n ShadyCSS: {\n nativeShadow: boolean;\n prepareTemplate(\n template: HTMLTemplateElement,\n elementName: string,\n typeExtension?: string\n ): void;\n styleElement(host: HTMLElement): void;\n ScopingShim: {\n prepareAdoptedCssText(\n cssTextArray: string[],\n elementName: string\n ): void;\n };\n };\n }\n}\n\ntype ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {\n adoptedStyleSheets?: CSSStyleSheet[];\n};\n\ntype FragmentType = 'color' | 'scale' | 'system' | 'theme' | 'core' | 'app';\ntype SettableFragmentTypes = 'color' | 'scale' | 'system' | 'theme';\ntype FragmentMap = Map<string, { name: string; styles: CSSResultGroup }>;\nexport type ThemeFragmentMap = Map<FragmentType, FragmentMap>;\nexport type Color =\n | 'light'\n | 'lightest'\n | 'dark'\n | 'darkest'\n | 'light-express'\n | 'lightest-express'\n | 'dark-express'\n | 'darkest-express';\nexport type Scale = 'medium' | 'large' | 'medium-express' | 'large-express';\nexport type ThemeVariant = 'spectrum' | 'express';\nexport type SystemVariant = 'spectrum' | 'express';\nconst SystemVariantValues = ['spectrum', 'express'];\nconst ScaleValues = ['medium', 'large', 'medium-express', 'large-express'];\nconst ColorValues = [\n 'light',\n 'lightest',\n 'dark',\n 'darkest',\n 'light-express',\n 'lightest-express',\n 'dark-express',\n 'darkest-express',\n];\ntype FragmentName =\n | Color\n | Scale\n | ThemeVariant\n | SystemVariant\n | 'core'\n | 'app';\n\nexport interface ThemeData {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: SystemVariant;\n system?: SystemVariant;\n}\n\ntype ThemeKindProvider = {\n [P in SettableFragmentTypes]:\n | ThemeVariant\n | SystemVariant\n | Color\n | Scale\n | '';\n};\n\nexport interface ProvideLang {\n callback: (lang: string, unsubscribe: () => void) => void;\n}\n\n/**\n * @element sp-theme\n * @attr {string} [lang=\"\"] - The language of the content scoped to this `sp-theme` element, see: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang\" target=\"_blank\">MDN reference</a>.\n *\n * @slot - Content on which to apply the CSS Custom Properties defined by the current theme configuration\n */\nexport class Theme extends HTMLElement implements ThemeKindProvider {\n private static themeFragmentsByKind: ThemeFragmentMap = new Map();\n private static defaultFragments: Set<FragmentName> = new Set(['spectrum']);\n private static templateElement?: HTMLTemplateElement;\n private static instances: Set<Theme> = new Set();\n static VERSION = version;\n\n static get observedAttributes(): string[] {\n return [\n 'color',\n 'scale',\n 'lang',\n 'dir',\n 'system',\n /* deprecated attributes, but still observing */\n 'theme',\n ];\n }\n\n _dir: 'ltr' | 'rtl' | '' = '';\n\n override set dir(dir: 'ltr' | 'rtl' | '') {\n if (dir === this.dir) return;\n this.setAttribute('dir', dir);\n this._dir = dir;\n const targetDir = dir === 'rtl' ? dir : 'ltr';\n /* c8 ignore next 3 */\n this.trackedChildren.forEach((el) => {\n el.setAttribute('dir', targetDir);\n });\n }\n\n /**\n * Reading direction of the content scoped to this `sp-theme` element.\n * @type {\"ltr\" | \"rtl\" | \"\"}\n * @attr\n */\n override get dir(): 'ltr' | 'rtl' | '' {\n return this._dir;\n }\n\n protected attributeChangedCallback(\n attrName: SettableFragmentTypes | 'lang' | 'dir',\n old: string | null,\n value: string | null\n ): void {\n if (old === value) {\n return;\n }\n if (attrName === 'color') {\n this.color = value as Color;\n } else if (attrName === 'scale') {\n this.scale = value as Scale;\n /* c8 ignore next 3 */\n } else if (attrName === 'lang' && !!value) {\n this.lang = value;\n this._provideContext();\n } else if (attrName === 'theme') {\n this.theme = value as SystemVariant;\n window.__swc.warn(\n this,\n 'property theme in <sp-theme> has been deprecated. Please use system instead like this <sp-theme system=\"spectrum\"/>',\n 'https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation',\n { level: 'deprecation' }\n );\n } else if (attrName === 'system') {\n this.system = value as SystemVariant;\n } else if (attrName === 'dir') {\n this.dir = value as 'ltr' | 'rtl' | '';\n }\n }\n\n private requestUpdate(): void {\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.styleElement(this);\n } else {\n this.shouldAdoptStyles();\n }\n }\n\n public override shadowRoot!: ShadowRootWithAdoptedStyleSheets;\n\n private _system: SystemVariant | '' = 'spectrum';\n /**\n * The Spectrum system that is applied to the content scoped to this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"spectrum\" | \"express\" }\n * @attr\n */\n get system(): SystemVariant | '' {\n const systemFragments = Theme.themeFragmentsByKind.get('system');\n const { name } =\n (systemFragments && systemFragments.get('default')) || {};\n return this._system || (name as SystemVariant) || '';\n }\n\n set system(newValue: SystemVariant | '') {\n if (newValue === this._system) return;\n const system =\n !!newValue && SystemVariantValues.includes(newValue)\n ? newValue\n : this.system;\n if (system !== this._system) {\n this._system = system;\n this.requestUpdate();\n }\n if (system) {\n this.setAttribute('system', system);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('system');\n }\n }\n\n /*\n * @deprecated The `theme` attribute has been deprecated in favor of the `system` attribute.\n */\n get theme(): SystemVariant | '' {\n if (!this.system) {\n this.removeAttribute('system');\n }\n return this.system;\n }\n\n /*\n * @deprecated The `theme` attribute has been deprecated in favor of the `system` attribute.\n */\n set theme(newValue: SystemVariant | '') {\n this.system = newValue;\n this.requestUpdate();\n }\n\n private _color: Color | '' = '';\n\n /**\n * The Spectrum color stops to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"lightest\" | \"light\" | \"dark\" | \"darkest\" | \"\"}\n * @attr\n */\n get color(): Color | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('color');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._color || (name as Color) || '';\n }\n\n set color(newValue: Color | '') {\n if (newValue === this._color) return;\n const color =\n !!newValue && ColorValues.includes(newValue)\n ? newValue\n : this.color;\n if (color !== this._color) {\n this._color = color;\n this.requestUpdate();\n }\n if (color) {\n this.setAttribute('color', color);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('color');\n }\n }\n\n private _scale: Scale | '' = '';\n\n /**\n * The Spectrum platform scale to apply to content scoped by this `sp-theme` element.\n *\n * A value is requried.\n * @type {\"medium\" | \"large\" | \"\"}\n * @attr\n */\n get scale(): Scale | '' {\n const themeFragments = Theme.themeFragmentsByKind.get('scale');\n const { name } =\n (themeFragments && themeFragments.get('default')) || {};\n return this._scale || (name as Scale) || '';\n }\n\n set scale(newValue: Scale | '') {\n if (newValue === this._scale) return;\n const scale =\n !!newValue && ScaleValues.includes(newValue)\n ? newValue\n : this.scale;\n if (scale !== this._scale) {\n this._scale = scale;\n this.requestUpdate();\n }\n if (scale) {\n this.setAttribute('scale', scale);\n /* c8 ignore next 3 */\n } else {\n this.removeAttribute('scale');\n }\n }\n\n private get styles(): CSSResultGroup[] {\n const themeKinds: FragmentType[] = [\n ...Theme.themeFragmentsByKind.keys(),\n ];\n const getStyle = (\n fragments: FragmentMap,\n name: FragmentName,\n kind?: FragmentType\n ): CSSResultGroup | undefined => {\n const currentStyles =\n kind &&\n kind !== 'theme' &&\n kind !== 'system' &&\n this.theme === 'express' &&\n this.system === 'express'\n ? fragments.get(`${name}-express`)\n : fragments.get(name);\n // theme=\"spectrum\" is available by default and doesn't need to be applied.\n const isAppliedFragment =\n name === 'spectrum' || !kind || this.hasAttribute(kind);\n if (currentStyles && isAppliedFragment) {\n return currentStyles.styles;\n }\n return;\n };\n const styles = themeKinds.reduce((acc, kind) => {\n const kindFragments = Theme.themeFragmentsByKind.get(\n kind\n ) as FragmentMap;\n let style: CSSResultGroup | undefined;\n if (kind === 'app' || kind === 'core') {\n style = getStyle(kindFragments, kind);\n } else {\n const { [kind]: name } = this;\n style = getStyle(kindFragments, <FragmentName>name, kind);\n }\n if (style) {\n acc.push(style);\n }\n return acc;\n }, [] as CSSResultGroup[]);\n if (window.__swc.DEBUG) {\n const issues: string[] = [];\n const checkForAttribute = (\n name: FragmentType,\n resolvedValue?: string,\n actualValue?: string\n ): void => {\n const systemModifier =\n this.system && this.system !== 'spectrum'\n ? `-${this.system}`\n : '';\n if (!resolvedValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute and there is no default value on which to fallback.`\n );\n } else if (!actualValue) {\n issues.push(\n `You have not explicitly set the \"${name}\" attribute, the default value (\"${resolvedValue}\") is being used as a fallback.`\n );\n } else if (\n !Theme.themeFragmentsByKind\n .get(name)\n ?.get(\n resolvedValue +\n (name === 'system' ? '' : systemModifier)\n )\n ) {\n issues.push(\n `You have set \"${name}='${resolvedValue}'\" but the associated system fragment has not been loaded.`\n );\n }\n };\n\n checkForAttribute('system', this.system, this._system);\n checkForAttribute('color', this.color, this._color);\n checkForAttribute('scale', this.scale, this._scale);\n\n // Check for deprecated attributes\n if (this.hasAttribute('theme')) {\n issues.push(\n `The \"theme\" attribute has been deprecated in favor of \"system\".`\n );\n }\n\n if (issues.length) {\n window.__swc.warn(\n this,\n 'You are leveraging an <sp-theme> element and the following issues may disrupt your theme delivery:',\n 'https://opensource.adobe.com/spectrum-web-components/components/theme/#example',\n {\n issues,\n }\n );\n }\n if (['lightest', 'darkest'].includes(this.color)) {\n window.__swc.warn(\n this,\n `Color lightest and darkest are deprecated and will be removed in a future release`,\n 'https://opensource.adobe.com/spectrum-web-components/tools/themes/#deprecation',\n { level: 'deprecation' }\n );\n }\n }\n return [...styles];\n }\n\n private static get template(): HTMLTemplateElement {\n if (!this.templateElement) {\n this.templateElement = document.createElement('template');\n this.templateElement.innerHTML = '<slot></slot>';\n }\n return this.templateElement;\n }\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n const node = document.importNode(Theme.template.content, true);\n this.shadowRoot.appendChild(node);\n this.shouldAdoptStyles();\n this.addEventListener(\n 'sp-query-theme',\n this.onQueryTheme as EventListener\n );\n this.addEventListener(\n 'sp-language-context',\n this._handleContextPresence as EventListener\n );\n this.updateComplete = this.__createDeferredPromise();\n }\n\n public updateComplete!: Promise<boolean>;\n private __resolve!: (compelted: boolean) => void;\n\n private __createDeferredPromise(): Promise<boolean> {\n return new Promise((resolve) => {\n this.__resolve = resolve;\n });\n }\n\n /* c8 ignore next 12 */\n private onQueryTheme(event: CustomEvent<ThemeData>): void {\n if (event.defaultPrevented) {\n return;\n }\n event.preventDefault();\n const { detail: theme } = event;\n theme.color = this.color || undefined;\n theme.scale = this.scale || undefined;\n theme.lang =\n this.lang || document.documentElement.lang || navigator.language;\n // `theme` is deprecated in favor of `system` but maintaining `theme` as a deprecated path.\n theme.theme = this.system || undefined;\n theme.system = this.system || undefined;\n }\n\n protected connectedCallback(): void {\n this.shouldAdoptStyles();\n // Note, first update/render handles styleElement so we only call this if\n // connected after first update.\n /* c8 ignore next 3 */\n if (window.ShadyCSS !== undefined) {\n window.ShadyCSS.styleElement(this);\n }\n // Add `this` to the instances array.\n Theme.instances.add(this);\n if (!this.hasAttribute('dir')) {\n let dirParent = ((this as HTMLElement).assignedSlot ||\n this.parentNode) as HTMLElement | DocumentFragment | ShadowRoot;\n while (\n dirParent !== document.documentElement &&\n !(dirParent instanceof Theme)\n ) {\n dirParent = ((dirParent as HTMLElement).assignedSlot || // step into the shadow DOM of the parent of a slotted node\n dirParent.parentNode || // DOM Element detected\n (dirParent as ShadowRoot).host) as\n | HTMLElement\n | DocumentFragment\n | ShadowRoot;\n }\n this.dir = dirParent.dir === 'rtl' ? dirParent.dir : 'ltr';\n }\n }\n\n protected disconnectedCallback(): void {\n // Remove `this` to the instances array.\n Theme.instances.delete(this);\n }\n\n public startManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.add(el);\n }\n\n public stopManagingContentDirection(el: HTMLElement): void {\n this.trackedChildren.delete(el);\n }\n\n private trackedChildren: Set<HTMLElement> = new Set();\n\n private _updateRequested = false;\n\n private async shouldAdoptStyles(): Promise<void> {\n if (!this._updateRequested) {\n this.updateComplete = this.__createDeferredPromise();\n this._updateRequested = true;\n this._updateRequested = await false;\n this.adoptStyles();\n this.__resolve(true);\n }\n }\n\n protected adoptStyles(): void {\n const styles = this.styles; // No test coverage on Edge\n\n // There are three separate cases here based on Shadow DOM support.\n // (1) shadowRoot polyfilled: use ShadyCSS\n // (2) shadowRoot.adoptedStyleSheets available: use it.\n // (3) shadowRoot.adoptedStyleSheets polyfilled: append styles after rendering\n /* c8 ignore next 28 */\n if (\n window.ShadyCSS !== undefined &&\n !window.ShadyCSS.nativeShadow &&\n window.ShadyCSS.ScopingShim\n ) {\n // For browsers using the shim, there seems to be one set of\n // processed styles per template, so it is hard to nest styles. So,\n // for those, we load in all style fragments and then switch using a\n // host selector (e.g. :host([color='dark']))\n const fragmentCSS: string[] = [];\n for (const [kind, fragments] of Theme.themeFragmentsByKind) {\n for (const [name, { styles }] of fragments) {\n if (name === 'default') continue;\n let cssText = (styles as CSSResult).cssText;\n if (!Theme.defaultFragments.has(name as FragmentName)) {\n cssText = cssText.replace(\n ':host',\n `:host([${kind}='${name}'])`\n );\n }\n fragmentCSS.push(cssText);\n }\n }\n window.ShadyCSS.ScopingShim.prepareAdoptedCssText(\n fragmentCSS,\n this.localName\n );\n window.ShadyCSS.prepareTemplate(Theme.template, this.localName);\n } else if (supportsAdoptingStyleSheets) {\n const styleSheets: CSSStyleSheet[] = [];\n for (const style of styles) {\n styleSheets.push(\n (style as CSSResult).styleSheet as CSSStyleSheet\n );\n }\n this.shadowRoot.adoptedStyleSheets = styleSheets;\n /* c8 ignore next 9 */\n } else {\n const styleNodes = this.shadowRoot.querySelectorAll('style');\n styleNodes.forEach((element) => element.remove());\n styles.forEach((s) => {\n const style = document.createElement('style');\n style.textContent = (s as CSSResult).cssText;\n this.shadowRoot.appendChild(style);\n });\n }\n }\n\n static registerThemeFragment(\n name: FragmentName,\n kind: FragmentType,\n styles: CSSResultGroup\n ): void {\n const fragmentMap = Theme.themeFragmentsByKind.get(kind) || new Map();\n if (fragmentMap.size === 0) {\n Theme.themeFragmentsByKind.set(kind, fragmentMap);\n // we're adding our first fragment for this kind, set as default\n fragmentMap.set('default', { name, styles });\n Theme.defaultFragments.add(name);\n }\n fragmentMap.set(name, { name, styles });\n Theme.instances.forEach((instance) => instance.shouldAdoptStyles());\n }\n\n private _contextConsumers = new Map<\n HTMLElement,\n [ProvideLang['callback'], () => void]\n >();\n\n /* c8 ignore next 5 */\n private _provideContext(): void {\n this._contextConsumers.forEach(([callback, unsubscribe]) =>\n callback(this.lang, unsubscribe)\n );\n }\n\n private _handleContextPresence(event: CustomEvent<ProvideLang>): void {\n event.stopPropagation();\n const target = event.composedPath()[0] as HTMLElement;\n /* c8 ignore next 3 */\n if (this._contextConsumers.has(target)) {\n return;\n }\n this._contextConsumers.set(target, [\n event.detail.callback,\n () => this._contextConsumers.delete(target),\n ]);\n const [callback, unsubscribe] =\n this._contextConsumers.get(target) || [];\n if (callback && unsubscribe) {\n callback(\n this.lang ||\n document.documentElement.lang ||\n navigator.language,\n unsubscribe\n );\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OAGI,+BAAAA,MACG,gCACP,OAAS,WAAAC,MAAe,+CA0CxB,MAAMC,EAAsB,CAAC,WAAY,SAAS,EAC5CC,EAAc,CAAC,SAAU,QAAS,iBAAkB,eAAe,EACnEC,EAAc,CAChB,QACA,WACA,OACA,UACA,gBACA,mBACA,eACA,iBACJ,EAoCaC,EAAN,MAAMA,UAAc,WAAyC,CA6ThE,aAAc,CACV,MAAM,EA3SV,UAA2B,GAgE3B,KAAQ,QAA8B,WAmDtC,KAAQ,OAAqB,GAkC7B,KAAQ,OAAqB,GAwO7B,KAAQ,gBAAoC,IAAI,IAEhD,KAAQ,iBAAmB,GAoF3B,KAAQ,kBAAoB,IAAI,IAvK5B,KAAK,aAAa,CAAE,KAAM,MAAO,CAAC,EAClC,MA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,GACZD,EACI,KAAK,MACD,SAAS,gBAAgB,MACzB,UAAU,SACdC,CACJ,CAER,CACJ,EAxgBapC,EACM,qBAAyC,IAAI,IADnDA,EAEM,iBAAsC,IAAI,IAAI,CAAC,UAAU,CAAC,EAFhEA,EAIM,UAAwB,IAAI,IAJlCA,EAKF,QAAUJ,EALd,WAAM,MAANI",
|
|
6
|
+
"names": ["supportsAdoptingStyleSheets", "version", "SystemVariantValues", "ScaleValues", "ColorValues", "_Theme", "node", "dir", "targetDir", "el", "attrName", "old", "value", "systemFragments", "name", "newValue", "system", "themeFragments", "color", "scale", "themeKinds", "getStyle", "fragments", "kind", "currentStyles", "isAppliedFragment", "acc", "kindFragments", "style", "resolve", "event", "theme", "dirParent", "styles", "fragmentCSS", "cssText", "styleSheets", "element", "fragmentMap", "instance", "callback", "unsubscribe", "target"]
|
|
7
7
|
}
|
package/src/express/core.dev.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["core.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from '../Theme.dev.js'\n\nimport coreStyles from './theme.css.js';\n\nTheme.registerThemeFragment('express', '
|
|
5
|
-
"mappings": ";AAYA,SAAS,aAAa;AAEtB,OAAO,gBAAgB;AAEvB,MAAM,sBAAsB,WAAW,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from '../Theme.dev.js'\n\nimport coreStyles from './theme.css.js';\n\nTheme.registerThemeFragment('express', 'system', coreStyles);\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,aAAa;AAEtB,OAAO,gBAAgB;AAEvB,MAAM,sBAAsB,WAAW,UAAU,UAAU;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/express/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{Theme as e}from"../Theme.js";import r from"./theme.css.js";e.registerThemeFragment("express","
|
|
1
|
+
"use strict";import{Theme as e}from"../Theme.js";import r from"./theme.css.js";e.registerThemeFragment("express","system",r);
|
|
2
2
|
//# sourceMappingURL=core.js.map
|
package/src/express/core.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["core.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from '../Theme.js';\n\nimport coreStyles from './theme.css.js';\n\nTheme.registerThemeFragment('express', '
|
|
5
|
-
"mappings": "aAYA,OAAS,SAAAA,MAAa,cAEtB,OAAOC,MAAgB,iBAEvBD,EAAM,sBAAsB,UAAW,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Theme } from '../Theme.js';\n\nimport coreStyles from './theme.css.js';\n\nTheme.registerThemeFragment('express', 'system', coreStyles);\n"],
|
|
5
|
+
"mappings": "aAYA,OAAS,SAAAA,MAAa,cAEtB,OAAOC,MAAgB,iBAEvBD,EAAM,sBAAsB,UAAW,SAAUC,CAAU",
|
|
6
6
|
"names": ["Theme", "coreStyles"]
|
|
7
7
|
}
|
package/stories/theme.stories.js
CHANGED
|
@@ -50,7 +50,7 @@ export const Default = ({
|
|
|
50
50
|
${storyStyles}
|
|
51
51
|
<sp-theme
|
|
52
52
|
color="${color}"
|
|
53
|
-
|
|
53
|
+
system=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
54
54
|
>
|
|
55
55
|
<div id="example">
|
|
56
56
|
<div>
|
|
@@ -90,7 +90,8 @@ export const displayFlex = () => html`
|
|
|
90
90
|
<sp-theme
|
|
91
91
|
id="flex-theme"
|
|
92
92
|
color="dark"
|
|
93
|
-
theme=${window.__swc_hack_knobs__.
|
|
93
|
+
theme=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
94
|
+
system=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
94
95
|
>
|
|
95
96
|
<sp-button>Start</sp-button>
|
|
96
97
|
<sp-button id="middle-button">Middle</sp-button>
|
|
@@ -126,7 +127,8 @@ export const nestedTheme = ({
|
|
|
126
127
|
${storyStyles}
|
|
127
128
|
<sp-theme
|
|
128
129
|
color="${outer}"
|
|
129
|
-
theme=${window.__swc_hack_knobs__.
|
|
130
|
+
theme=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
131
|
+
system=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
130
132
|
>
|
|
131
133
|
<div id="outer">
|
|
132
134
|
<div>
|
|
@@ -149,7 +151,8 @@ export const nestedTheme = ({
|
|
|
149
151
|
<sp-theme
|
|
150
152
|
color="${inner}"
|
|
151
153
|
dir="ltr"
|
|
152
|
-
theme=${window.__swc_hack_knobs__.
|
|
154
|
+
theme=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
155
|
+
system=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
153
156
|
>
|
|
154
157
|
<div id="inner">
|
|
155
158
|
<div>
|
|
@@ -201,7 +204,8 @@ export const reverseColorNestedTheme = ({
|
|
|
201
204
|
</style>
|
|
202
205
|
<sp-theme
|
|
203
206
|
color="${inner}"
|
|
204
|
-
theme=${window.__swc_hack_knobs__.
|
|
207
|
+
theme=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
208
|
+
system=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
205
209
|
>
|
|
206
210
|
<div id="outer">
|
|
207
211
|
<div>
|
|
@@ -224,7 +228,8 @@ export const reverseColorNestedTheme = ({
|
|
|
224
228
|
<sp-theme
|
|
225
229
|
color="${outer}"
|
|
226
230
|
dir="rtl"
|
|
227
|
-
theme=${window.__swc_hack_knobs__.
|
|
231
|
+
theme=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
232
|
+
system=${window.__swc_hack_knobs__.defaultSystemVariant}
|
|
228
233
|
>
|
|
229
234
|
<div id="inner">
|
|
230
235
|
<div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["theme.stories.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport '@spectrum-web-components/button-group/sp-button-group.js';\nimport '@spectrum-web-components/switch/sp-switch.js';\nimport '@spectrum-web-components/slider/sp-slider.js';\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport { Color } from '../src/index.js';\n\nexport default {\n component: 'sp-theme',\n title: 'Theme',\n argTypes: {\n colorStop: {\n control: {\n type: 'inline-radio',\n options: ['light', 'dark'],\n },\n },\n },\n args: {\n colorStop: 'light',\n },\n};\n\nconst storyStyles = html`\n <style type=\"text/css\">\n #outer,\n #example {\n width: 500px;\n padding: 3em;\n background-color: var(--spectrum-gray-100);\n color: var(--spectrum-gray-800);\n }\n\n #inner {\n margin-top: 2em;\n padding: 2em;\n background-color: var(--spectrum-gray-100);\n color: var(--spectrum-gray-800);\n }\n\n #buttons {\n margin-top: 2em;\n }\n </style>\n`;\n\nexport const Default = ({\n colorStop: color,\n}: {\n colorStop: Color;\n}): TemplateResult => {\n return html`\n ${storyStyles}\n <sp-theme\n color=\"${color}\"\n
|
|
5
|
-
"mappings": ";AAWA,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,SAAS,YAA4B;AAGrC,eAAe;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AAAA,EACP,UAAU;AAAA,IACN,WAAW;AAAA,MACP,SAAS;AAAA,QACL,MAAM;AAAA,QACN,SAAS,CAAC,SAAS,MAAM;AAAA,MAC7B;AAAA,IACJ;AAAA,EACJ;AAAA,EACA,MAAM;AAAA,IACF,WAAW;AAAA,EACf;AACJ;AAEA,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBb,aAAM,UAAU,CAAC;AAAA,EACpB,WAAW;AACf,MAEsB;AAClB,SAAO;AAAA,UACD,WAAW;AAAA;AAAA,qBAEA,KAAK;AAAA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport '@spectrum-web-components/button-group/sp-button-group.js';\nimport '@spectrum-web-components/switch/sp-switch.js';\nimport '@spectrum-web-components/slider/sp-slider.js';\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport { Color } from '../src/index.js';\n\nexport default {\n component: 'sp-theme',\n title: 'Theme',\n argTypes: {\n colorStop: {\n control: {\n type: 'inline-radio',\n options: ['light', 'dark'],\n },\n },\n },\n args: {\n colorStop: 'light',\n },\n};\n\nconst storyStyles = html`\n <style type=\"text/css\">\n #outer,\n #example {\n width: 500px;\n padding: 3em;\n background-color: var(--spectrum-gray-100);\n color: var(--spectrum-gray-800);\n }\n\n #inner {\n margin-top: 2em;\n padding: 2em;\n background-color: var(--spectrum-gray-100);\n color: var(--spectrum-gray-800);\n }\n\n #buttons {\n margin-top: 2em;\n }\n </style>\n`;\n\nexport const Default = ({\n colorStop: color,\n}: {\n colorStop: Color;\n}): TemplateResult => {\n return html`\n ${storyStyles}\n <sp-theme\n color=\"${color}\"\n system=${window.__swc_hack_knobs__.defaultSystemVariant}\n >\n <div id=\"example\">\n <div>\n <sp-slider\n value=\"5\"\n step=\"1\"\n min=\"1\"\n max=\"11\"\n label=\"Volume\"\n id=\"volume-slider\"\n ></sp-slider>\n </div>\n <div><sp-switch>Overdrive</sp-switch></div>\n <sp-button-group id=\"buttons\">\n <sp-button variant=\"primary\" treatment=\"outline\">\n Cancel\n </sp-button>\n <sp-button variant=\"accent\">Continue</sp-button>\n </sp-button-group>\n </div>\n </sp-theme>\n `;\n};\n\nexport const displayFlex = (): TemplateResult => html`\n <style type=\"text/css\">\n #flex-theme {\n display: flex;\n flex-direction: row;\n }\n #flex-theme sp-button {\n flex: 0 0;\n }\n #flex-theme #middle-button {\n flex: 1 0;\n }\n </style>\n <sp-theme\n id=\"flex-theme\"\n color=\"dark\"\n theme=${window.__swc_hack_knobs__.defaultSystemVariant}\n system=${window.__swc_hack_knobs__.defaultSystemVariant}\n >\n <sp-button>Start</sp-button>\n <sp-button id=\"middle-button\">Middle</sp-button>\n <sp-button>End</sp-button>\n </sp-theme>\n`;\n\nexport const none = (): TemplateResult => html`\n ${storyStyles}\n <div id=\"example\">\n <div>\n <sp-slider\n value=\"5\"\n step=\"1\"\n min=\"1\"\n max=\"11\"\n label=\"Volume\"\n id=\"volume-slider\"\n ></sp-slider>\n </div>\n <div><sp-switch>Overdrive</sp-switch></div>\n <sp-button-group id=\"buttons\">\n <sp-button variant=\"primary\" treatment=\"outline\">Cancel</sp-button>\n <sp-button variant=\"accent\">Continue</sp-button>\n </sp-button-group>\n </div>\n <sp-theme></sp-theme>\n`;\n\nexport const nestedTheme = ({\n colorStop: outer,\n}: {\n colorStop: Color;\n}): TemplateResult => {\n const inner = outer === 'light' ? 'dark' : 'light';\n return html`\n ${storyStyles}\n <sp-theme\n color=\"${outer}\"\n theme=${window.__swc_hack_knobs__.defaultSystemVariant}\n system=${window.__swc_hack_knobs__.defaultSystemVariant}\n >\n <div id=\"outer\">\n <div>\n <sp-slider\n value=\"5\"\n step=\"1\"\n min=\"1\"\n max=\"11\"\n label=\"Volume\"\n id=\"volume-slider\"\n ></sp-slider>\n </div>\n <div><sp-switch>Overdrive</sp-switch></div>\n <sp-button-group id=\"buttons\">\n <sp-button variant=\"primary\" treatment=\"outline\">\n Cancel\n </sp-button>\n <sp-button variant=\"accent\">Continue</sp-button>\n </sp-button-group>\n <sp-theme\n color=\"${inner}\"\n dir=\"ltr\"\n theme=${window.__swc_hack_knobs__.defaultSystemVariant}\n system=${window.__swc_hack_knobs__.defaultSystemVariant}\n >\n <div id=\"inner\">\n <div>\n <sp-slider\n value=\"5\"\n step=\"1\"\n min=\"1\"\n max=\"11\"\n label=\"Volume\"\n id=\"volume-slider-inner\"\n ></sp-slider>\n </div>\n <div><sp-switch>Overdrive</sp-switch></div>\n <sp-button-group id=\"buttons-inner\">\n <sp-button variant=\"primary\" treatment=\"outline\">\n Cancel\n </sp-button>\n <sp-button variant=\"accent\">Continue</sp-button>\n </sp-button-group>\n </div>\n </sp-theme>\n </div>\n </sp-theme>\n `;\n};\n\nexport const reverseColorNestedTheme = ({\n colorStop: outer,\n}: {\n colorStop: Color;\n}): TemplateResult => {\n const inner = outer === 'light' ? 'dark' : 'light';\n return html`\n <style type=\"text/css\">\n #outer {\n width: 500px;\n padding: 3em;\n background-color: var(--spectrum-gray-100);\n color: var(--spectrum-gray-800);\n }\n\n #inner {\n margin-top: 2em;\n padding: 2em;\n background-color: var(--spectrum-gray-100);\n color: var(--spectrum-gray-800);\n }\n\n #buttons {\n margin-top: 2em;\n }\n </style>\n <sp-theme\n color=\"${inner}\"\n theme=${window.__swc_hack_knobs__.defaultSystemVariant}\n system=${window.__swc_hack_knobs__.defaultSystemVariant}\n >\n <div id=\"outer\">\n <div>\n <sp-slider\n value=\"5\"\n step=\"1\"\n min=\"1\"\n max=\"11\"\n label=\"Volume\"\n id=\"volume-slider\"\n ></sp-slider>\n </div>\n <div><sp-switch>Overdrive</sp-switch></div>\n <sp-button-group id=\"buttons\">\n <sp-button variant=\"primary\" treatment=\"outline\">\n Cancel\n </sp-button>\n <sp-button variant=\"accent\">Continue</sp-button>\n </sp-button-group>\n <sp-theme\n color=\"${outer}\"\n dir=\"rtl\"\n theme=${window.__swc_hack_knobs__.defaultSystemVariant}\n system=${window.__swc_hack_knobs__.defaultSystemVariant}\n >\n <div id=\"inner\">\n <div>\n <sp-slider\n value=\"5\"\n step=\"1\"\n min=\"1\"\n max=\"11\"\n label=\"Volume\"\n id=\"volume-slider-inner\"\n ></sp-slider>\n </div>\n <div><sp-switch>Overdrive</sp-switch></div>\n <sp-button-group id=\"buttons-inner\">\n <sp-button variant=\"primary\" treatment=\"outline\">\n Cancel\n </sp-button>\n <sp-button variant=\"accent\">Continue</sp-button>\n </sp-button-group>\n </div>\n </sp-theme>\n </div>\n </sp-theme>\n `;\n};\n"],
|
|
5
|
+
"mappings": ";AAWA,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,SAAS,YAA4B;AAGrC,eAAe;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AAAA,EACP,UAAU;AAAA,IACN,WAAW;AAAA,MACP,SAAS;AAAA,QACL,MAAM;AAAA,QACN,SAAS,CAAC,SAAS,MAAM;AAAA,MAC7B;AAAA,IACJ;AAAA,EACJ;AAAA,EACA,MAAM;AAAA,IACF,WAAW;AAAA,EACf;AACJ;AAEA,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBb,aAAM,UAAU,CAAC;AAAA,EACpB,WAAW;AACf,MAEsB;AAClB,SAAO;AAAA,UACD,WAAW;AAAA;AAAA,qBAEA,KAAK;AAAA,qBACL,OAAO,mBAAmB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAqBU,KAAK;AAAA,oBACN,OAAO,mBAAmB,oBAAoB;AAAA,qBAC7C,OAAO,mBAAmB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAqBtC,KAAK;AAAA;AAAA,4BAEN,OAAO,mBAAmB,oBAAoB;AAAA,6BAC7C,OAAO,mBAAmB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyB3E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,8 +4,8 @@ import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
|
4
4
|
import { stub } from "sinon";
|
|
5
5
|
describe("Dev mode", () => {
|
|
6
6
|
window.__swc.verbose = true;
|
|
7
|
+
const consoleWarnStub = stub(console, "warn");
|
|
7
8
|
it("warns in Dev Mode when no attributes or fragments", async () => {
|
|
8
|
-
const consoleWarnStub = stub(console, "warn");
|
|
9
9
|
const el = await fixture(
|
|
10
10
|
html`
|
|
11
11
|
<sp-theme></sp-theme>
|
|
@@ -27,5 +27,31 @@ describe("Dev mode", () => {
|
|
|
27
27
|
});
|
|
28
28
|
consoleWarnStub.restore();
|
|
29
29
|
});
|
|
30
|
+
it("warns in Dev Mode when you pass a theme attribute", async () => {
|
|
31
|
+
const el = await fixture(
|
|
32
|
+
html`
|
|
33
|
+
<sp-theme
|
|
34
|
+
theme="classic"
|
|
35
|
+
color="dark"
|
|
36
|
+
scale="medium"
|
|
37
|
+
></sp-theme>
|
|
38
|
+
`
|
|
39
|
+
);
|
|
40
|
+
await elementUpdated(el);
|
|
41
|
+
expect(consoleWarnStub.called).to.be.true;
|
|
42
|
+
const spyCall = consoleWarnStub.getCall(0);
|
|
43
|
+
expect(
|
|
44
|
+
spyCall.args.at(0).includes("theme delivery"),
|
|
45
|
+
'confirm "theme-deprecation"-centric message'
|
|
46
|
+
).to.be.true;
|
|
47
|
+
expect(spyCall.args.at(-1), "confirm `data` shape").to.deep.equal({
|
|
48
|
+
data: {
|
|
49
|
+
localName: "sp-theme",
|
|
50
|
+
type: "api",
|
|
51
|
+
level: "default"
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
consoleWarnStub.restore();
|
|
55
|
+
});
|
|
30
56
|
});
|
|
31
57
|
//# sourceMappingURL=theme-devmode.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["theme-devmode.test.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport { Theme } from '@spectrum-web-components/theme';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\nimport { stub } from 'sinon';\n\ndescribe('Dev mode', () => {\n window.__swc.verbose = true;\n it('warns in Dev Mode when no attributes or fragments', async () => {\n const consoleWarnStub =
|
|
5
|
-
"mappings": ";AAYA,OAAO;AAEP,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AACtD,SAAS,YAAY;AAErB,SAAS,YAAY,MAAM;AACvB,SAAO,MAAM,UAAU;AACvB,KAAG,qDAAqD,YAAY;AAChE,UAAM,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport { Theme } from '@spectrum-web-components/theme';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\nimport { stub } from 'sinon';\n\ndescribe('Dev mode', () => {\n window.__swc.verbose = true;\n const consoleWarnStub = stub(console, 'warn');\n it('warns in Dev Mode when no attributes or fragments', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(consoleWarnStub.called).to.be.true;\n const spyCall = consoleWarnStub.getCall(0);\n expect(\n spyCall.args.at(0).includes('theme delivery'),\n 'confirm \"theme delivery\"-centric message'\n ).to.be.true;\n expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({\n data: {\n localName: 'sp-theme',\n type: 'api',\n level: 'default',\n },\n });\n consoleWarnStub.restore();\n });\n\n it('warns in Dev Mode when you pass a theme attribute', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme\n theme=\"classic\"\n color=\"dark\"\n scale=\"medium\"\n ></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(consoleWarnStub.called).to.be.true;\n const spyCall = consoleWarnStub.getCall(0);\n\n expect(\n spyCall.args.at(0).includes('theme delivery'),\n 'confirm \"theme-deprecation\"-centric message'\n ).to.be.true;\n expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({\n data: {\n localName: 'sp-theme',\n type: 'api',\n level: 'default',\n },\n });\n consoleWarnStub.restore();\n });\n});\n"],
|
|
5
|
+
"m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
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/test/themes.test.js
CHANGED
|
@@ -4,11 +4,11 @@ import "@spectrum-web-components/theme/src/themes.js";
|
|
|
4
4
|
import { Theme } from "@spectrum-web-components/theme";
|
|
5
5
|
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
6
6
|
import { css } from "@spectrum-web-components/base";
|
|
7
|
-
describe("
|
|
7
|
+
describe("Systems", () => {
|
|
8
8
|
it("loads - light", async () => {
|
|
9
9
|
const el = await fixture(
|
|
10
10
|
html`
|
|
11
|
-
<sp-theme
|
|
11
|
+
<sp-theme system="spectrum" color="light"></sp-theme>
|
|
12
12
|
`
|
|
13
13
|
);
|
|
14
14
|
await elementUpdated(el);
|
|
@@ -38,7 +38,7 @@ describe("Themes", () => {
|
|
|
38
38
|
it("adds an instance only once", async () => {
|
|
39
39
|
const el = await fixture(
|
|
40
40
|
html`
|
|
41
|
-
<sp-theme
|
|
41
|
+
<sp-theme system="express"></sp-theme>
|
|
42
42
|
`
|
|
43
43
|
);
|
|
44
44
|
await elementUpdated(el);
|
|
@@ -160,5 +160,47 @@ describe("Setting attributes", () => {
|
|
|
160
160
|
).to.equal(3);
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
|
+
it("prefers system over theme", async () => {
|
|
164
|
+
const el = await fixture(
|
|
165
|
+
html`
|
|
166
|
+
<sp-theme system="express"></sp-theme>
|
|
167
|
+
`
|
|
168
|
+
);
|
|
169
|
+
await elementUpdated(el);
|
|
170
|
+
expect(el.system).to.equal("express");
|
|
171
|
+
el.setAttribute("theme", "classic");
|
|
172
|
+
await elementUpdated(el);
|
|
173
|
+
expect(el.system).to.equal("express");
|
|
174
|
+
expect(el.theme).to.equal("express");
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
describe("Themes", () => {
|
|
178
|
+
it("updates system value even if only theme is added to sp-theme", async () => {
|
|
179
|
+
const el = await fixture(
|
|
180
|
+
html`
|
|
181
|
+
<sp-theme theme="express"></sp-theme>
|
|
182
|
+
`
|
|
183
|
+
);
|
|
184
|
+
await elementUpdated(el);
|
|
185
|
+
expect(el.theme).to.equal("express");
|
|
186
|
+
el.setAttribute("theme", "spectrum");
|
|
187
|
+
await elementUpdated(el);
|
|
188
|
+
expect(el.theme).to.equal("spectrum");
|
|
189
|
+
expect(el.system).to.equal("spectrum");
|
|
190
|
+
});
|
|
191
|
+
it("updates system and theme value iif both are added to sp-theme", async () => {
|
|
192
|
+
const el = await fixture(
|
|
193
|
+
html`
|
|
194
|
+
<sp-theme system="spectrum" theme="spectrum"></sp-theme>
|
|
195
|
+
`
|
|
196
|
+
);
|
|
197
|
+
await elementUpdated(el);
|
|
198
|
+
expect(el.theme).to.equal("spectrum");
|
|
199
|
+
expect(el.system).to.equal("spectrum");
|
|
200
|
+
el.setAttribute("theme", "express");
|
|
201
|
+
await elementUpdated(el);
|
|
202
|
+
expect(el.theme).to.equal("express");
|
|
203
|
+
expect(el.system).to.equal("express");
|
|
204
|
+
});
|
|
163
205
|
});
|
|
164
206
|
//# sourceMappingURL=themes.test.js.map
|
package/test/themes.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["themes.test.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport { Theme, ThemeFragmentMap } from '@spectrum-web-components/theme';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\nimport { css } from '@spectrum-web-components/base';\n\ntype TestableThemeConstructor = {\n instances: Set<Theme>;\n themeFragmentsByKind: ThemeFragmentMap;\n};\n\ndescribe('
|
|
5
|
-
"mappings": ";AAYA,OAAO;AACP,OAAO;AACP,SAAS,aAA+B;AACxC,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AACtD,SAAS,WAAW;AAOpB,SAAS,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport { Theme, ThemeFragmentMap } from '@spectrum-web-components/theme';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\nimport { css } from '@spectrum-web-components/base';\n\ntype TestableThemeConstructor = {\n instances: Set<Theme>;\n themeFragmentsByKind: ThemeFragmentMap;\n};\n\ndescribe('Systems', () => {\n it('loads - light', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme system=\"spectrum\" color=\"light\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el).to.exist;\n expect(el).shadowDom.to.exist;\n });\n it('loads - dark', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme color=\"dark\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el).to.exist;\n expect(el).shadowDom.to.exist;\n });\n it('loads - unkown', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme color=\"unknown\" scale=\"unknown\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el).to.exist;\n expect(el).shadowDom.to.exist;\n });\n it('adds an instance only once', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme system=\"express\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n const testableTheme = Theme as unknown as TestableThemeConstructor;\n expect(testableTheme.instances.has(el), 'first').to.be.true;\n expect(testableTheme.instances.size).to.equal(1);\n\n el.remove();\n expect(testableTheme.instances.has(el), 'second').to.be.false;\n expect(testableTheme.instances.size).to.equal(0);\n\n document.body.append(el);\n expect(testableTheme.instances.has(el), 'third').to.be.true;\n expect(testableTheme.instances.size).to.equal(1);\n });\n});\n\ndescribe('Lightest', () => {\n it('loads', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme color=\"lightest\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el).to.exist;\n expect(el).shadowDom.to.exist;\n });\n});\n\ndescribe('Medium', () => {\n it('loads', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme scale=\"medium\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el).to.exist;\n expect(el).shadowDom.to.exist;\n });\n});\n\ndescribe('App styles', () => {\n it('applies app fragments', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme color=\"light\">\n <style>\n div {\n padding: var(--app-padding);\n }\n </style>\n <div></div>\n </sp-theme>\n `\n );\n const div = el.querySelector('div') as HTMLDivElement;\n\n await elementUpdated(el);\n\n const preStylesDiv = getComputedStyle(div);\n expect(preStylesDiv.paddingBlockStart).to.equal('0px');\n\n Theme.registerThemeFragment(\n 'app',\n 'app',\n css`\n :host {\n --app-padding: 10px;\n }\n `\n );\n await elementUpdated(el);\n\n const postStylesDiv = getComputedStyle(div);\n expect(postStylesDiv.paddingBlockStart).to.equal('10px');\n\n (\n Theme as unknown as TestableThemeConstructor\n ).themeFragmentsByKind.delete('app');\n });\n});\n\ndescribe('Setting attributes', () => {\n it('loads', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme color=\"light\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el).to.not.be.undefined;\n expect(el.hasAttribute('scale')).to.be.false;\n\n if (el.shadowRoot.adoptedStyleSheets) {\n expect(el.shadowRoot.adoptedStyleSheets.length).to.equal(2);\n } else {\n expect(\n [...el.shadowRoot.querySelectorAll('style')].length\n ).to.equal(2);\n }\n\n await elementUpdated(el);\n\n // Invalid initial value falls back to default\n el.setAttribute('scale', 'fish');\n expect(el.getAttribute('scale')).to.equal('medium');\n\n if (el.shadowRoot.adoptedStyleSheets) {\n expect(el.shadowRoot.adoptedStyleSheets.length).to.equal(2);\n } else {\n expect(\n [...el.shadowRoot.querySelectorAll('style')].length\n ).to.equal(2);\n }\n\n el.color = 'dark';\n el.scale = 'medium';\n\n await elementUpdated(el);\n expect(el.getAttribute('color')).to.equal('dark');\n expect(el.getAttribute('scale')).to.equal('medium');\n\n if (el.shadowRoot.adoptedStyleSheets) {\n expect(el.shadowRoot.adoptedStyleSheets.length, 'all').to.equal(3);\n } else {\n expect(\n [...el.shadowRoot.querySelectorAll('style')].length\n ).to.equal(3);\n }\n\n // Invalid second + value fallsback to previous\n el.setAttribute('color', 'fish');\n\n await elementUpdated(el);\n expect(el.getAttribute('color')).to.equal('dark');\n\n if (el.shadowRoot.adoptedStyleSheets) {\n expect(el.shadowRoot.adoptedStyleSheets.length, 'last').to.equal(3);\n } else {\n expect(\n [...el.shadowRoot.querySelectorAll('style')].length\n ).to.equal(3);\n }\n });\n\n it('prefers system over theme', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme system=\"express\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el.system).to.equal('express');\n\n el.setAttribute('theme', 'classic');\n await elementUpdated(el);\n\n expect(el.system).to.equal('express');\n expect(el.theme).to.equal('express');\n });\n});\n\ndescribe('Themes', () => {\n it('updates system value even if only theme is added to sp-theme', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme theme=\"express\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el.theme).to.equal('express');\n\n el.setAttribute('theme', 'spectrum');\n await elementUpdated(el);\n\n expect(el.theme).to.equal('spectrum');\n expect(el.system).to.equal('spectrum');\n });\n it('updates system and theme value iif both are added to sp-theme', async () => {\n const el = await fixture<Theme>(\n html`\n <sp-theme system=\"spectrum\" theme=\"spectrum\"></sp-theme>\n `\n );\n\n await elementUpdated(el);\n\n expect(el.theme).to.equal('spectrum');\n expect(el.system).to.equal('spectrum');\n\n el.setAttribute('theme', 'express');\n await elementUpdated(el);\n expect(el.theme).to.equal('express');\n expect(el.system).to.equal('express');\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,OAAO;AACP,OAAO;AACP,SAAS,aAA+B;AACxC,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AACtD,SAAS,WAAW;AAOpB,SAAS,WAAW,MAAM;AACtB,KAAG,iBAAiB,YAAY;AAC5B,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AAEA,UAAM,eAAe,EAAE;AAEvB,WAAO,EAAE,EAAE,GAAG;AACd,WAAO,EAAE,EAAE,UAAU,GAAG;AAAA,EAC5B,CAAC;AACD,KAAG,gBAAgB,YAAY;AAC3B,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AAEA,UAAM,eAAe,EAAE;AAEvB,WAAO,EAAE,EAAE,GAAG;AACd,WAAO,EAAE,EAAE,UAAU,GAAG;AAAA,EAC5B,CAAC;AACD,KAAG,kBAAkB,YAAY;AAC7B,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AAEA,UAAM,eAAe,EAAE;AAEvB,WAAO,EAAE,EAAE,GAAG;AACd,WAAO,EAAE,EAAE,UAAU,GAAG;AAAA,EAC5B,CAAC;AACD,KAAG,8BAA8B,YAAY;AACzC,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AAEA,UAAM,eAAe,EAAE;AACvB,UAAM,gBAAgB;AACtB,WAAO,cAAc,UAAU,IAAI,E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