@spectrum-web-components/theme 0.8.16 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/theme",
3
- "version": "0.8.16",
3
+ "version": "0.9.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -56,8 +56,8 @@
56
56
  "lit-html"
57
57
  ],
58
58
  "dependencies": {
59
- "@spectrum-web-components/base": "^0.4.6",
60
- "@spectrum-web-components/styles": "^0.10.1",
59
+ "@spectrum-web-components/base": "^0.5.1",
60
+ "@spectrum-web-components/styles": "^0.11.2",
61
61
  "tslib": "^2.0.0"
62
62
  },
63
63
  "types": "./src/index.d.ts",
@@ -68,5 +68,5 @@
68
68
  "./scale-*.js",
69
69
  "./src/themes.js"
70
70
  ],
71
- "gitHead": "9c7ac25264762a9b7bad2ef3f111d5eb613f9d05"
71
+ "gitHead": "5ad16bd185710525afa48bd76099cb0ebde4c4cb"
72
72
  }
package/src/Theme.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CSSResult } from '@spectrum-web-components/base';
1
+ import { CSSResultGroup } from '@spectrum-web-components/base';
2
2
  declare global {
3
3
  interface Window {
4
4
  ShadyCSS: {
@@ -10,15 +10,15 @@ declare global {
10
10
  };
11
11
  };
12
12
  }
13
- interface ShadowRoot {
14
- adoptedStyleSheets?: CSSStyleSheet[];
15
- }
16
13
  }
14
+ declare type ShadowRootWithAdoptedStyleSheets = HTMLElement['shadowRoot'] & {
15
+ adoptedStyleSheets?: CSSStyleSheet[];
16
+ };
17
17
  declare type FragmentType = 'color' | 'scale' | 'core' | 'app';
18
18
  declare type SettableFragmentTypes = 'color' | 'scale';
19
19
  declare type FragmentMap = Map<string, {
20
20
  name: string;
21
- styles: CSSResult;
21
+ styles: CSSResultGroup;
22
22
  }>;
23
23
  export declare type ThemeFragmentMap = Map<FragmentType, FragmentMap>;
24
24
  export declare type Color = 'light' | 'lightest' | 'dark' | 'darkest';
@@ -48,7 +48,7 @@ export declare class Theme extends HTMLElement implements ThemeKindProvider {
48
48
  static get observedAttributes(): string[];
49
49
  protected attributeChangedCallback(attrName: SettableFragmentTypes, old: string | null, value: string | null): void;
50
50
  private requestUpdate;
51
- shadowRoot: ShadowRoot;
51
+ shadowRoot: ShadowRootWithAdoptedStyleSheets;
52
52
  private _color;
53
53
  get color(): Color | '';
54
54
  set color(newValue: Color | '');
@@ -71,7 +71,7 @@ export declare class Theme extends HTMLElement implements ThemeKindProvider {
71
71
  private _updateRequested;
72
72
  private shouldAdoptStyles;
73
73
  protected adoptStyles(): void;
74
- static registerThemeFragment(name: FragmentName, kind: FragmentType, styles: CSSResult): void;
74
+ static registerThemeFragment(name: FragmentName, kind: FragmentType, styles: CSSResultGroup): void;
75
75
  private _contextConsumers;
76
76
  private _provideContext;
77
77
  private _handleContextPresence;
package/src/Theme.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Theme.js","sourceRoot":"","sources":["Theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAEH,2BAA2B,GAC9B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,UAAU,MAAM,gBAAgB,CAAC;AA+BxC,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAiB7D;;;;GAIG;AACH,MAAM,OAAO,KAAM,SAAQ,WAAW;IA8HlC;QACI,KAAK,EAAE,CAAC;QAzFJ,WAAM,GAAe,EAAE,CAAC;QA0BxB,WAAM,GAAe,EAAE,CAAC;QA8JxB,oBAAe,GAAqB,IAAI,GAAG,EAAE,CAAC;QAE9C,qBAAgB,GAAG,KAAK,CAAC;QAiFzB,sBAAiB,GAAG,IAAI,GAAG,EAAwC,CAAC;QAjLx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E;gBACV,QAAQ,CACJ,IAAI,CAAC,IAAI;oBACL,QAAQ,CAAC,eAAe,CAAC,IAAI;oBAC7B,SAAS,CAAC,QAAQ,CACzB,CAAC;aACL;SACJ;IACL,CAAC;;AArUc,0BAAoB,GAAqB,IAAI,GAAG,EAAE,CAAC;AACnD,sBAAgB,GAAsB,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAExD,eAAS,GAAe,IAAI,GAAG,EAAE,CAAC;AAqUrD,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 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 interface ShadowRoot {\n adoptedStyleSheets?: CSSStyleSheet[];\n }\n}\n\ntype FragmentType = 'color' | 'scale' | 'core' | 'app';\ntype SettableFragmentTypes = 'color' | 'scale';\ntype FragmentMap = Map<string, { name: string; styles: CSSResult }>;\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!: ShadowRoot;\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);\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.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(style.styleSheet as CSSStyleSheet);\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.cssText;\n this.shadowRoot.appendChild(style);\n });\n }\n }\n\n static registerThemeFragment(\n name: FragmentName,\n kind: FragmentType,\n styles: CSSResult\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;AAgCxC,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAiB7D;;;;GAIG;AACH,MAAM,OAAO,KAAM,SAAQ,WAAW;IA8HlC;QACI,KAAK,EAAE,CAAC;QAzFJ,WAAM,GAAe,EAAE,CAAC;QA0BxB,WAAM,GAAe,EAAE,CAAC;QA8JxB,oBAAe,GAAqB,IAAI,GAAG,EAAE,CAAC;QAE9C,qBAAgB,GAAG,KAAK,CAAC;QAmFzB,sBAAiB,GAAG,IAAI,GAAG,EAAwC,CAAC;QAnLxE,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC/D,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,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AI,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"]}