@spectrum-web-components/theme 0.11.3 → 0.12.1-devmode.7

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