@spectrum-web-components/theme 0.10.2 → 0.10.3-express.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +56 -38
  2. package/custom-elements.json +162 -2
  3. package/express/scale-large.d.ts +1 -0
  4. package/express/scale-large.js +15 -0
  5. package/express/scale-large.js.map +1 -0
  6. package/express/scale-medium.d.ts +1 -0
  7. package/express/scale-medium.js +15 -0
  8. package/express/scale-medium.js.map +1 -0
  9. package/express/theme-dark.d.ts +1 -0
  10. package/express/theme-dark.js +15 -0
  11. package/express/theme-dark.js.map +1 -0
  12. package/express/theme-light.d.ts +1 -0
  13. package/express/theme-light.js +15 -0
  14. package/express/theme-light.js.map +1 -0
  15. package/package.json +11 -4
  16. package/src/Theme.d.ts +12 -7
  17. package/src/Theme.js +59 -13
  18. package/src/Theme.js.map +1 -1
  19. package/src/express/core.d.ts +1 -0
  20. package/src/express/core.js +15 -0
  21. package/src/express/core.js.map +1 -0
  22. package/src/express/scale-large.css.d.ts +2 -0
  23. package/src/express/scale-large.css.js +4079 -0
  24. package/src/express/scale-large.css.js.map +1 -0
  25. package/src/express/scale-medium.css.d.ts +2 -0
  26. package/src/express/scale-medium.css.js +4133 -0
  27. package/src/express/scale-medium.css.js.map +1 -0
  28. package/src/express/theme-dark.css.d.ts +2 -0
  29. package/src/express/theme-dark.css.js +35 -0
  30. package/src/express/theme-dark.css.js.map +1 -0
  31. package/src/express/theme-light.css.d.ts +2 -0
  32. package/src/express/theme-light.css.js +35 -0
  33. package/src/express/theme-light.css.js.map +1 -0
  34. package/src/express/theme.css.d.ts +2 -0
  35. package/src/express/theme.css.js +1649 -0
  36. package/src/express/theme.css.js.map +1 -0
  37. package/src/express/themes.d.ts +5 -0
  38. package/src/express/themes.js +17 -0
  39. package/src/express/themes.js.map +1 -0
  40. package/src/typography.css.js +1 -1
  41. package/src/typography.css.js.map +1 -1
  42. package/test/theme-lazy.test.js +1 -1
  43. package/test/theme-lazy.test.js.map +1 -1
  44. package/test/themes.test.js +2 -2
  45. package/test/themes.test.js.map +1 -1
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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 largeStyles from '../src/express/scale-large.css.js';
13
+ import { Theme } from '../src/Theme.js';
14
+ Theme.registerThemeFragment('large-express', 'scale', largeStyles);
15
+ //# sourceMappingURL=scale-large.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale-large.js","sourceRoot":"","sources":["scale-large.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,WAAW,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,KAAK,CAAC,qBAAqB,CAAC,eAAe,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC","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 largeStyles from '../src/express/scale-large.css.js';\nimport { Theme } from '../src/Theme.js';\n\nTheme.registerThemeFragment('large-express', 'scale', largeStyles);\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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 mediumStyles from '../src/express/scale-medium.css.js';
13
+ import { Theme } from '../src/Theme.js';
14
+ Theme.registerThemeFragment('medium-express', 'scale', mediumStyles);
15
+ //# sourceMappingURL=scale-medium.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale-medium.js","sourceRoot":"","sources":["scale-medium.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,YAAY,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,KAAK,CAAC,qBAAqB,CAAC,gBAAgB,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC","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 mediumStyles from '../src/express/scale-medium.css.js';\nimport { Theme } from '../src/Theme.js';\n\nTheme.registerThemeFragment('medium-express', 'scale', mediumStyles);\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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 darkStyles from '../src/express/theme-dark.css.js';
13
+ import { Theme } from '../src/Theme.js';
14
+ Theme.registerThemeFragment('dark-express', 'color', darkStyles);
15
+ //# sourceMappingURL=theme-dark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-dark.js","sourceRoot":"","sources":["theme-dark.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,KAAK,CAAC,qBAAqB,CAAC,cAAc,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC","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 darkStyles from '../src/express/theme-dark.css.js';\nimport { Theme } from '../src/Theme.js';\n\nTheme.registerThemeFragment('dark-express', 'color', darkStyles);\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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 lightStyles from '../src/express/theme-light.css.js';
13
+ import { Theme } from '../src/Theme.js';
14
+ Theme.registerThemeFragment('light-express', 'color', lightStyles);
15
+ //# sourceMappingURL=theme-light.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-light.js","sourceRoot":"","sources":["theme-light.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,WAAW,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,KAAK,CAAC,qBAAqB,CAAC,eAAe,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC","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 lightStyles from '../src/express/theme-light.css.js';\nimport { Theme } from '../src/Theme.js';\n\nTheme.registerThemeFragment('light-express', 'color', lightStyles);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/theme",
3
- "version": "0.10.2",
3
+ "version": "0.10.3-express.0+781feb2fe",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,6 +22,8 @@
22
22
  "exports": {
23
23
  ".": "./src/index.js",
24
24
  "./src/*": "./src/*",
25
+ "./express/*": "./express/*",
26
+ "./src/express/*": "./src/express/*",
25
27
  "./package.json": "./package.json",
26
28
  "./sp-theme": "./sp-theme.js",
27
29
  "./sp-theme.js": "./sp-theme.js",
@@ -57,7 +59,7 @@
57
59
  ],
58
60
  "dependencies": {
59
61
  "@spectrum-web-components/base": "^0.5.4",
60
- "@spectrum-web-components/styles": "^0.12.2",
62
+ "@spectrum-web-components/styles": "^0.12.3-express.0+781feb2fe",
61
63
  "tslib": "^2.0.0"
62
64
  },
63
65
  "types": "./src/index.d.ts",
@@ -66,7 +68,12 @@
66
68
  "./sp-*.js",
67
69
  "./theme-*.js",
68
70
  "./scale-*.js",
69
- "./src/themes.js"
71
+ "./express/theme-*.js",
72
+ "./express/theme-*.ts",
73
+ "./express/scale-*.js",
74
+ "./src/themes.js",
75
+ "./src/express/core.js",
76
+ "./src/express/themes.js"
70
77
  ],
71
- "gitHead": "dd76f9532fdea946880147cc7645f113b998c326"
78
+ "gitHead": "781feb2fe1053c2861a9b768a86e403b1ab30581"
72
79
  }
package/src/Theme.d.ts CHANGED
@@ -14,23 +14,25 @@ declare global {
14
14
  declare type ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {
15
15
  adoptedStyleSheets?: CSSStyleSheet[];
16
16
  };
17
- declare type FragmentType = 'color' | 'scale' | 'core' | 'app';
18
- declare type SettableFragmentTypes = 'color' | 'scale';
17
+ declare type FragmentType = 'color' | 'scale' | 'theme' | 'core' | 'app';
18
+ declare type SettableFragmentTypes = 'color' | 'scale' | 'theme';
19
19
  declare type FragmentMap = Map<string, {
20
20
  name: string;
21
21
  styles: CSSResultGroup;
22
22
  }>;
23
23
  export declare type ThemeFragmentMap = Map<FragmentType, FragmentMap>;
24
- export declare type Color = 'light' | 'lightest' | 'dark' | 'darkest';
25
- export declare type Scale = 'medium' | 'large';
26
- declare type FragmentName = Color | Scale | 'core' | 'app';
24
+ export declare type Color = 'light' | 'lightest' | 'dark' | 'darkest' | 'light-express' | 'lightest-express' | 'dark-express' | 'darkest-express';
25
+ export declare type Scale = 'medium' | 'large' | 'medium-express' | 'large-express';
26
+ export declare type ThemeVariant = 'spectrum' | 'express';
27
+ declare type FragmentName = Color | Scale | ThemeVariant | 'core' | 'app';
27
28
  export interface ThemeData {
28
29
  color?: Color;
29
30
  scale?: Scale;
30
31
  lang?: string;
32
+ theme?: ThemeVariant;
31
33
  }
32
34
  declare type ThemeKindProvider = {
33
- [P in SettableFragmentTypes]: Color | Scale | '';
35
+ [P in SettableFragmentTypes]: ThemeVariant | Color | Scale | '';
34
36
  };
35
37
  export interface ProvideLang {
36
38
  callback: (lang: string) => void;
@@ -46,9 +48,12 @@ export declare class Theme extends HTMLElement implements ThemeKindProvider {
46
48
  private static templateElement?;
47
49
  private static instances;
48
50
  static get observedAttributes(): string[];
49
- protected attributeChangedCallback(attrName: SettableFragmentTypes, old: string | null, value: string | null): void;
51
+ protected attributeChangedCallback(attrName: SettableFragmentTypes | 'lang', old: string | null, value: string | null): void;
50
52
  private requestUpdate;
51
53
  shadowRoot: ShadowRootWithAdoptedStyleSheets;
54
+ private _theme;
55
+ get theme(): ThemeVariant | '';
56
+ set theme(newValue: ThemeVariant | '');
52
57
  private _color;
53
58
  get color(): Color | '';
54
59
  set color(newValue: Color | '');
package/src/Theme.js CHANGED
@@ -11,8 +11,18 @@ governing permissions and limitations under the License.
11
11
  */
12
12
  import { supportsAdoptingStyleSheets, } from '@spectrum-web-components/base';
13
13
  import coreStyles from './theme.css.js';
14
- const ScaleValues = ['medium', 'large'];
15
- const ColorValues = ['light', 'lightest', 'dark', 'darkest'];
14
+ const ThemeVariantValues = ['spectrum', 'express'];
15
+ const ScaleValues = ['medium', 'large', 'medium-express', 'large-express'];
16
+ const ColorValues = [
17
+ 'light',
18
+ 'lightest',
19
+ 'dark',
20
+ 'darkest',
21
+ 'light-express',
22
+ 'lightest-express',
23
+ 'dark-express',
24
+ 'darkest-express',
25
+ ];
16
26
  /**
17
27
  * @element sp-theme
18
28
  *
@@ -21,6 +31,7 @@ const ColorValues = ['light', 'lightest', 'dark', 'darkest'];
21
31
  export class Theme extends HTMLElement {
22
32
  constructor() {
23
33
  super();
34
+ this._theme = 'spectrum';
24
35
  this._color = '';
25
36
  this._scale = '';
26
37
  this.trackedChildren = new Set();
@@ -35,7 +46,7 @@ export class Theme extends HTMLElement {
35
46
  this.updateComplete = this.__createDeferredPromise();
36
47
  }
37
48
  static get observedAttributes() {
38
- return ['color', 'scale', 'lang'];
49
+ return ['color', 'scale', 'theme', 'lang'];
39
50
  }
40
51
  attributeChangedCallback(attrName, old, value) {
41
52
  if (old === value) {
@@ -51,6 +62,9 @@ export class Theme extends HTMLElement {
51
62
  this.lang = value;
52
63
  this._provideContext();
53
64
  }
65
+ else if (attrName === 'theme') {
66
+ this.theme = value;
67
+ }
54
68
  }
55
69
  requestUpdate() {
56
70
  if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {
@@ -60,6 +74,28 @@ export class Theme extends HTMLElement {
60
74
  this.shouldAdoptStyles();
61
75
  }
62
76
  }
77
+ get theme() {
78
+ const themeFragments = Theme.themeFragmentsByKind.get('theme');
79
+ const { name } = (themeFragments && themeFragments.get('default')) || {};
80
+ return this._theme || name || '';
81
+ }
82
+ set theme(newValue) {
83
+ if (newValue === this._theme)
84
+ return;
85
+ const theme = !!newValue && ThemeVariantValues.includes(newValue)
86
+ ? newValue
87
+ : this.theme;
88
+ if (theme !== this._theme) {
89
+ this._theme = theme;
90
+ this.requestUpdate();
91
+ }
92
+ if (theme) {
93
+ this.setAttribute('theme', theme);
94
+ }
95
+ else {
96
+ this.removeAttribute('theme');
97
+ }
98
+ }
63
99
  get color() {
64
100
  const themeFragments = Theme.themeFragmentsByKind.get('color');
65
101
  const { name } = (themeFragments && themeFragments.get('default')) || {};
@@ -108,20 +144,29 @@ export class Theme extends HTMLElement {
108
144
  const themeKinds = [
109
145
  ...Theme.themeFragmentsByKind.keys(),
110
146
  ];
147
+ const getStyle = (fragments, name, kind) => {
148
+ const currentStyles = kind && kind !== 'theme' && this.theme === 'express'
149
+ ? fragments.get(`${name}-express`)
150
+ : fragments.get(name);
151
+ // theme="spectrum" is available by default and doesn't need to be applied.
152
+ const isAppliedFragment = name === 'spectrum' || !kind || this.hasAttribute(kind);
153
+ if (currentStyles && isAppliedFragment) {
154
+ return currentStyles.styles;
155
+ }
156
+ return;
157
+ };
111
158
  const styles = themeKinds.reduce((acc, kind) => {
112
159
  const kindFragments = Theme.themeFragmentsByKind.get(kind);
113
- const addStyles = (name, kind) => {
114
- const currentStyles = kindFragments.get(name);
115
- if (currentStyles && (!kind || this.hasAttribute(kind))) {
116
- acc.push(currentStyles.styles);
117
- }
118
- };
160
+ let style;
119
161
  if (kind === 'app' || kind === 'core') {
120
- addStyles(kind);
162
+ style = getStyle(kindFragments, kind);
121
163
  }
122
164
  else {
123
165
  const { [kind]: name } = this;
124
- addStyles(name, kind);
166
+ style = getStyle(kindFragments, name, kind);
167
+ }
168
+ if (style) {
169
+ acc.push(style);
125
170
  }
126
171
  return acc;
127
172
  }, []);
@@ -149,6 +194,7 @@ export class Theme extends HTMLElement {
149
194
  theme.scale = this.scale || undefined;
150
195
  theme.lang =
151
196
  this.lang || document.documentElement.lang || navigator.language;
197
+ theme.theme = this.theme || undefined;
152
198
  }
153
199
  connectedCallback() {
154
200
  this.shouldAdoptStyles();
@@ -283,7 +329,7 @@ export class Theme extends HTMLElement {
283
329
  }
284
330
  }
285
331
  Theme.themeFragmentsByKind = new Map();
286
- Theme.defaultFragments = new Set(['core']);
332
+ Theme.defaultFragments = new Set(['spectrum']);
287
333
  Theme.instances = new Set();
288
- Theme.registerThemeFragment('core', 'core', coreStyles);
334
+ Theme.registerThemeFragment('spectrum', 'theme', coreStyles);
289
335
  //# sourceMappingURL=Theme.js.map
package/src/Theme.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Theme.js","sourceRoot":"","sources":["Theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAGH,2BAA2B,GAC9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IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAEO,sBAAsB,CAAC,KAA+B;QAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAgB,CAAC;QACtD,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YACpC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACzC;aAAM;YACH,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpD,IAAI,QAAQ,EAAE;gBACV,QAAQ,CACJ,IAAI,CAAC,IAAI;oBACL,QAAQ,CAAC,eAAe,CAAC,IAAI;oBAC7B,SAAS,CAAC,QAAQ,CACzB,CAAC;aACL;SACJ;IACL,CAAC;;AAvUc,0BAAoB,GAAqB,IAAI,GAAG,EAAE,CAAC;AACnD,sBAAgB,GAAsB,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAExD,eAAS,GAAe,IAAI,GAAG,EAAE,CAAC;AAuUrD,KAAK,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC","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';\n\nimport coreStyles from './theme.css.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' | 'core' | 'app';\ntype SettableFragmentTypes = 'color' | 'scale';\ntype FragmentMap = Map<string, { name: string; styles: CSSResultGroup }>;\nexport type ThemeFragmentMap = Map<FragmentType, FragmentMap>;\nexport type Color = 'light' | 'lightest' | 'dark' | 'darkest';\nexport type Scale = 'medium' | 'large';\nconst ScaleValues = ['medium', 'large'];\nconst ColorValues = ['light', 'lightest', 'dark', 'darkest'];\ntype FragmentName = Color | Scale | 'core' | 'app';\n\nexport interface ThemeData {\n color?: Color;\n scale?: Scale;\n lang?: string;\n}\n\ntype ThemeKindProvider = {\n [P in SettableFragmentTypes]: Color | Scale | '';\n};\n\nexport interface ProvideLang {\n callback: (lang: string) => void;\n}\n\n/**\n * @element sp-theme\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(['core']);\n private static templateElement?: HTMLTemplateElement;\n private static instances: Set<Theme> = new Set();\n\n static get observedAttributes(): string[] {\n return ['color', 'scale', 'lang'];\n }\n\n protected attributeChangedCallback(\n attrName: SettableFragmentTypes,\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 } else if (attrName === 'lang' && !!value) {\n this.lang = value;\n this._provideContext();\n }\n }\n\n private requestUpdate(): void {\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.styleElement(this);\n } else {\n this.shouldAdoptStyles();\n }\n }\n\n public shadowRoot!: ShadowRootWithAdoptedStyleSheets;\n\n private _color: Color | '' = '';\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 } else {\n this.removeAttribute('color');\n }\n }\n\n private _scale: Scale | '' = '';\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 } else {\n this.removeAttribute('scale');\n }\n }\n\n private get styles(): CSSResult[] {\n const themeKinds: FragmentType[] = [\n ...Theme.themeFragmentsByKind.keys(),\n ];\n const styles = themeKinds.reduce((acc, kind) => {\n const kindFragments = Theme.themeFragmentsByKind.get(\n kind\n ) as FragmentMap;\n const addStyles = (\n name: FragmentName,\n kind?: FragmentType\n ): void => {\n const currentStyles = kindFragments.get(name);\n if (currentStyles && (!kind || this.hasAttribute(kind))) {\n acc.push(currentStyles.styles as CSSResult);\n }\n };\n if (kind === 'app' || kind === 'core') {\n addStyles(kind);\n } else {\n const { [kind]: name } = this;\n addStyles(<FragmentName>name, kind);\n }\n return acc;\n }, [] as CSSResult[]);\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 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 }\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 const manageDir = (): void => {\n const { dir } = this;\n this.trackedChildren.forEach((el) => {\n el.setAttribute('dir', dir === 'rtl' ? dir : 'ltr');\n });\n };\n if (!this.observer) {\n this.observer = new MutationObserver(manageDir);\n }\n this.observer.observe(this, {\n attributes: true,\n attributeFilter: ['dir'],\n });\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 requestAnimationFrame(() => manageDir());\n }\n\n protected disconnectedCallback(): void {\n // Remove `this` to the instances array.\n Theme.instances.delete(this);\n this.observer.disconnect();\n }\n\n private observer!: MutationObserver;\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\n // rendering\n /* c8 ignore next */ 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 } 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<HTMLElement, ProvideLang['callback']>();\n\n private _provideContext(): void {\n this._contextConsumers.forEach((consume) => consume(this.lang));\n }\n\n private _handleContextPresence(event: CustomEvent<ProvideLang>): void {\n const target = event.composedPath()[0] as HTMLElement;\n if (this._contextConsumers.has(target)) {\n this._contextConsumers.delete(target);\n } else {\n this._contextConsumers.set(target, event.detail.callback);\n const callback = this._contextConsumers.get(target);\n if (callback) {\n callback(\n this.lang ||\n document.documentElement.lang ||\n navigator.language\n );\n }\n }\n }\n}\n\nTheme.registerThemeFragment('core', 'core', coreStyles);\n"]}
1
+ {"version":3,"file":"Theme.js","sourceRoot":"","sources":["Theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAGH,2BAA2B,GAC9B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,UAAU,MAAM,gBAAgB,CAAC;AAyCxC,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,WAAW,GAAG,CAAC,QAAQ,E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B,EAAE,CAAC,CAAC;IACxE,CAAC;IAIO,eAAe;QACnB,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAEO,sBAAsB,CAAC,KAA+B;QAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAgB,CAAC;QACtD,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YACpC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACzC;aAAM;YACH,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpD,IAAI,QAAQ,EAAE;gBACV,QAAQ,CACJ,IAAI,CAAC,IAAI;oBACL,QAAQ,CAAC,eAAe,CAAC,IAAI;oBAC7B,SAAS,CAAC,QAAQ,CACzB,CAAC;aACL;SACJ;IACL,CAAC;;AAhXc,0BAAoB,GAAqB,IAAI,GAAG,EAAE,CAAC;AACnD,sBAAgB,GAAsB,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AAE5D,eAAS,GAAe,IAAI,GAAG,EAAE,CAAC;AAgXrD,KAAK,CAAC,qBAAqB,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC","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';\n\nimport coreStyles from './theme.css.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) => void;\n}\n\n/**\n * @element sp-theme\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\n static get observedAttributes(): string[] {\n return ['color', 'scale', 'theme', 'lang'];\n }\n\n protected attributeChangedCallback(\n attrName: SettableFragmentTypes | 'lang',\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 } else if (attrName === 'lang' && !!value) {\n this.lang = value;\n this._provideContext();\n } else if (attrName === 'theme') {\n this.theme = value as ThemeVariant;\n }\n }\n\n private requestUpdate(): void {\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.styleElement(this);\n } else {\n this.shouldAdoptStyles();\n }\n }\n\n public shadowRoot!: ShadowRootWithAdoptedStyleSheets;\n\n private _theme: ThemeVariant | '' = 'spectrum';\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 } else {\n this.removeAttribute('theme');\n }\n }\n\n private _color: Color | '' = '';\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 } else {\n this.removeAttribute('color');\n }\n }\n\n private _scale: Scale | '' = '';\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 } 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 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 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 const manageDir = (): void => {\n const { dir } = this;\n this.trackedChildren.forEach((el) => {\n el.setAttribute('dir', dir === 'rtl' ? dir : 'ltr');\n });\n };\n if (!this.observer) {\n this.observer = new MutationObserver(manageDir);\n }\n this.observer.observe(this, {\n attributes: true,\n attributeFilter: ['dir'],\n });\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 requestAnimationFrame(() => manageDir());\n }\n\n protected disconnectedCallback(): void {\n // Remove `this` to the instances array.\n Theme.instances.delete(this);\n this.observer.disconnect();\n }\n\n private observer!: MutationObserver;\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\n // rendering\n /* c8 ignore next */ 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 } 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<HTMLElement, ProvideLang['callback']>();\n\n private _provideContext(): void {\n this._contextConsumers.forEach((consume) => consume(this.lang));\n }\n\n private _handleContextPresence(event: CustomEvent<ProvideLang>): void {\n const target = event.composedPath()[0] as HTMLElement;\n if (this._contextConsumers.has(target)) {\n this._contextConsumers.delete(target);\n } else {\n this._contextConsumers.set(target, event.detail.callback);\n const callback = this._contextConsumers.get(target);\n if (callback) {\n callback(\n this.lang ||\n document.documentElement.lang ||\n navigator.language\n );\n }\n }\n }\n}\n\nTheme.registerThemeFragment('spectrum', 'theme', coreStyles);\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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 { Theme } from '../Theme.js';
13
+ import coreStyles from './theme.css.js';
14
+ Theme.registerThemeFragment('express', 'theme', coreStyles);
15
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,UAAU,MAAM,gBAAgB,CAAC;AAExC,KAAK,CAAC,qBAAqB,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC","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', 'theme', coreStyles);\n"]}
@@ -0,0 +1,2 @@
1
+ declare const styles: import("@spectrum-web-components/base").CSSResult;
2
+ export default styles;