@fluentui/web-components 3.0.0-beta.57 → 3.0.0-beta.59

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/CHANGELOG.md CHANGED
@@ -1,12 +1,30 @@
1
1
  # Change Log - @fluentui/web-components
2
2
 
3
- This log was last generated on Fri, 16 Aug 2024 04:08:08 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 21 Aug 2024 04:07:01 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [3.0.0-beta.59](https://github.com/microsoft/fluentui/tree/@fluentui/web-components_v3.0.0-beta.59)
8
+
9
+ Wed, 21 Aug 2024 04:07:01 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/web-components_v3.0.0-beta.58..@fluentui/web-components_v3.0.0-beta.59)
11
+
12
+ ### Changes
13
+
14
+ - feat: update fast-element to latest stable version ([PR #32344](https://github.com/microsoft/fluentui/pull/32344) by 13071055+chrisdholt@users.noreply.github.com)
15
+
16
+ ## [3.0.0-beta.58](https://github.com/microsoft/fluentui/tree/@fluentui/web-components_v3.0.0-beta.58)
17
+
18
+ Tue, 20 Aug 2024 04:06:57 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/web-components_v3.0.0-beta.57..@fluentui/web-components_v3.0.0-beta.58)
20
+
21
+ ### Changes
22
+
23
+ - feat: enabling setting theme on an individual element and unsetting themes ([PR #31973](https://github.com/microsoft/fluentui/pull/31973) by machi@microsoft.com)
24
+
7
25
  ## [3.0.0-beta.57](https://github.com/microsoft/fluentui/tree/@fluentui/web-components_v3.0.0-beta.57)
8
26
 
9
- Fri, 16 Aug 2024 04:08:08 GMT
27
+ Fri, 16 Aug 2024 04:08:15 GMT
10
28
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/web-components_v3.0.0-beta.56..@fluentui/web-components_v3.0.0-beta.57)
11
29
 
12
30
  ### Changes
@@ -17,10 +17,13 @@ export type Theme = Record<string, string | number>;
17
17
  * Note that this argument is not limited to existing theme objects (from
18
18
  * `@fluentui/tokens`), you can pass in an arbitrary theme object as long
19
19
  * as each entry’s value is either a string or a number.
20
+ * @param node - The node to set the theme on, defaults to `document` for
21
+ * setting global theme.
20
22
  * @internal
21
23
  */
22
- export declare const setTheme: (theme: Theme) => void;
24
+ export declare function setTheme(theme: Theme | null, node?: Document | HTMLElement): void;
23
25
  /**
24
26
  * @internal
27
+ * @deprecated Use `setTheme(theme, element)` instead.
25
28
  */
26
- export declare const setThemeFor: (element: HTMLElement, theme: Theme) => void;
29
+ export declare function setThemeFor(element: HTMLElement, theme: Theme | null): void;
@@ -0,0 +1,3 @@
1
+ import { type TestRenderFunction } from '@tensile-perf/web-components';
2
+ declare const tests: Record<string, TestRenderFunction>;
3
+ export { tests };
@@ -0,0 +1,3 @@
1
+ import { type TestRenderFunction } from '@tensile-perf/web-components';
2
+ declare const tests: Record<string, TestRenderFunction>;
3
+ export { tests };
@@ -15,9 +15,11 @@ const tests = {
15
15
  setTheme(webDarkTheme);
16
16
  setTheme(teamsDarkTheme);
17
17
  setTheme(teamsLightTheme);
18
+ // Unset themes
19
+ setTheme(null);
18
20
  endMeasure();
19
21
  onComplete();
20
22
  },
21
23
  };
22
24
  export { tests };
23
- //# sourceMappingURL=set-theme.bench.js.map
25
+ //# sourceMappingURL=set-theme.global.bench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-theme.global.bench.js","sourceRoot":"","sources":["../../../src/theme/set-theme.global.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,8BAA8B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEhG,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,KAAK,GAAuC;IAChD,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;QACxB,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,kBAAkB,EAAE,CAAC;QAE1D,YAAY,EAAE,CAAC;QAEf,mBAAmB;QACnB,QAAQ,CAAC,aAAa,CAAC,CAAC;QACxB,QAAQ,CAAC,YAAY,CAAC,CAAC;QACvB,QAAQ,CAAC,cAAc,CAAC,CAAC;QACzB,QAAQ,CAAC,eAAe,CAAC,CAAC;QAE1B,gBAAgB;QAChB,QAAQ,CAAC,aAAa,CAAC,CAAC;QACxB,QAAQ,CAAC,YAAY,CAAC,CAAC;QACvB,QAAQ,CAAC,cAAc,CAAC,CAAC;QACzB,QAAQ,CAAC,eAAe,CAAC,CAAC;QAE1B,eAAe;QACf,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEf,UAAU,EAAE,CAAC;QAEb,UAAU,EAAE,CAAC;IACf,CAAC;CACF,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -1,7 +1,21 @@
1
- const SUPPORTS_REGISTER_PROPERTY = 'registerProperty' in CSS;
1
+ import { uniqueId } from '@microsoft/fast-web-utilities';
2
2
  const SUPPORTS_ADOPTED_STYLE_SHEETS = 'adoptedStyleSheets' in document;
3
- const themeStyleSheet = new CSSStyleSheet();
3
+ const SUPPORTS_CSS_SCOPE = 'CSSScopeRule' in window;
4
+ // A map from a theme to Custom Property declarations for the theme as a string.
5
+ // Each value should be a list of CSS Custom Property declarations, and should
6
+ // NOT include any selector, `{`, or `}`.
4
7
  const themeStyleTextMap = new Map();
8
+ // A map from a theme to a unique string used to identity a theme. The string
9
+ // will be used as the value of the `data-fluent-theme` attribute on a
10
+ // differently themed element.
11
+ const scopedThemeKeyMap = new Map();
12
+ // A map from an element with shadow root to a `CSSStyleSheet` object that
13
+ // references its local theme style sheet.
14
+ const shadowAdoptedStyleSheetMap = new Map();
15
+ // A map from an element to its set theme. This is used only when
16
+ // `document.adoptedStyleSheets` or CSS Scope is not supported.
17
+ const elementThemeMap = new Map();
18
+ const globalThemeStyleSheet = new CSSStyleSheet();
5
19
  /**
6
20
  * Sets the theme tokens as CSS Custom Properties. The Custom Properties are
7
21
  * set in a constructed stylesheet on `document.adoptedStyleSheets` if
@@ -15,53 +29,163 @@ const themeStyleTextMap = new Map();
15
29
  * Note that this argument is not limited to existing theme objects (from
16
30
  * `@fluentui/tokens`), you can pass in an arbitrary theme object as long
17
31
  * as each entry’s value is either a string or a number.
32
+ * @param node - The node to set the theme on, defaults to `document` for
33
+ * setting global theme.
18
34
  * @internal
19
35
  */
20
- export const setTheme = (theme) => {
36
+ export function setTheme(theme, node = document) {
37
+ if (!node || !isThemeableNode(node)) {
38
+ return;
39
+ }
21
40
  // Fallback to setting token custom properties on `<html>` element’s `style`
22
- // attribute, only checking the support of `document.adoptedStyleSheets`
23
- // here because it has broader support than `CSS.registerProperty()`, which
24
- // is checked later.
25
- if (!SUPPORTS_ADOPTED_STYLE_SHEETS) {
26
- setThemeFor(document.documentElement, theme);
41
+ // attribute.
42
+ if (!SUPPORTS_ADOPTED_STYLE_SHEETS || (node instanceof HTMLElement && !node.shadowRoot && !SUPPORTS_CSS_SCOPE)) {
43
+ const target = node === document ? document.documentElement : node;
44
+ setThemePropertiesOnElement(theme, target);
27
45
  return;
28
46
  }
47
+ if ([document, document.documentElement, document.body].includes(node)) {
48
+ setGlobalTheme(theme);
49
+ }
50
+ else {
51
+ setLocalTheme(theme, node);
52
+ }
53
+ }
54
+ function getThemeStyleText(theme) {
29
55
  if (!themeStyleTextMap.has(theme)) {
30
56
  const tokenDeclarations = [];
31
57
  for (const [tokenName, tokenValue] of Object.entries(theme)) {
32
- if (typeof tokenValue !== 'string' && Number.isNaN(tokenValue)) {
33
- throw new Error(`"${tokenName}" must be a string or a number.`);
34
- }
35
- const name = `--${tokenName}`;
36
- const initialValue = tokenValue.toString();
37
- if (SUPPORTS_REGISTER_PROPERTY) {
38
- try {
39
- // @ts-expect-error - Baseline 2024
40
- CSS.registerProperty({
41
- name,
42
- initialValue,
43
- inherits: true,
44
- });
45
- }
46
- catch { }
47
- }
48
- tokenDeclarations.push(`${name}:${initialValue};`);
58
+ tokenDeclarations.push(`--${tokenName}:${tokenValue.toString()};`);
59
+ }
60
+ themeStyleTextMap.set(theme, tokenDeclarations.join(''));
61
+ }
62
+ return themeStyleTextMap.get(theme);
63
+ }
64
+ /**
65
+ * A themeable node should either be one of the following:
66
+ * - `document`
67
+ * - `html`
68
+ * - `body`
69
+ * - Any HTML element inside `body`
70
+ */
71
+ function isThemeableNode(node) {
72
+ return [document, document.documentElement].includes(node) || (node instanceof HTMLElement && !!node.closest('body'));
73
+ }
74
+ function setGlobalTheme(theme) {
75
+ if (theme === null) {
76
+ if (document.adoptedStyleSheets.includes(globalThemeStyleSheet)) {
77
+ globalThemeStyleSheet.replaceSync('');
49
78
  }
50
- themeStyleTextMap.set(theme, `html{${tokenDeclarations.join('')}}`);
79
+ return;
51
80
  }
52
81
  // Update the CSSStyleSheet with the new theme
53
- themeStyleSheet.replaceSync(themeStyleTextMap.get(theme));
82
+ globalThemeStyleSheet.replaceSync(`
83
+ html {
84
+ ${getThemeStyleText(theme)}
85
+ }
86
+ `);
54
87
  // Adopt the updated CSSStyleSheet if it hasn't been adopted yet
55
- if (!document.adoptedStyleSheets.includes(themeStyleSheet)) {
56
- document.adoptedStyleSheets.push(themeStyleSheet);
88
+ if (!document.adoptedStyleSheets.includes(globalThemeStyleSheet)) {
89
+ document.adoptedStyleSheets.push(globalThemeStyleSheet);
90
+ }
91
+ }
92
+ function setLocalTheme(theme, element) {
93
+ if (theme === null) {
94
+ if (element.shadowRoot && shadowAdoptedStyleSheetMap.has(element)) {
95
+ shadowAdoptedStyleSheetMap.get(element).replaceSync('');
96
+ }
97
+ else {
98
+ delete element.dataset.fluentTheme;
99
+ forceRepaint(element);
100
+ }
101
+ return;
102
+ }
103
+ if (element.shadowRoot) {
104
+ getShadowAdoptedStyleSheet(element).replaceSync(`
105
+ :host {
106
+ ${getThemeStyleText(theme)}
107
+ }
108
+ `);
109
+ }
110
+ else {
111
+ element.dataset.fluentTheme = getScopedThemeKey(theme);
112
+ forceRepaint(element);
57
113
  }
58
- };
114
+ }
115
+ function getShadowAdoptedStyleSheet(element) {
116
+ var _a;
117
+ if (!shadowAdoptedStyleSheetMap.has(element)) {
118
+ const shadowAdoptedStyleSheet = new CSSStyleSheet();
119
+ shadowAdoptedStyleSheetMap.set(element, shadowAdoptedStyleSheet);
120
+ (_a = element.shadowRoot) === null || _a === void 0 ? void 0 : _a.adoptedStyleSheets.push(shadowAdoptedStyleSheet);
121
+ }
122
+ return shadowAdoptedStyleSheetMap.get(element);
123
+ }
124
+ function getScopedThemeKey(theme) {
125
+ if (!scopedThemeKeyMap.has(theme)) {
126
+ const themeKey = uniqueId('fluent-theme-');
127
+ const scopedThemeStyleSheet = new CSSStyleSheet();
128
+ scopedThemeKeyMap.set(theme, themeKey);
129
+ scopedThemeStyleSheet.replaceSync(`
130
+ @scope ([data-fluent-theme="${themeKey}"]) {
131
+ :scope {
132
+ ${getThemeStyleText(theme)}
133
+ }
134
+ }
135
+ `);
136
+ document.adoptedStyleSheets.push(scopedThemeStyleSheet);
137
+ }
138
+ return scopedThemeKeyMap.get(theme);
139
+ }
140
+ function setThemePropertiesOnElement(theme, element) {
141
+ let tokens;
142
+ if (theme === null) {
143
+ if (!elementThemeMap.has(element)) {
144
+ return;
145
+ }
146
+ tokens = elementThemeMap.get(element);
147
+ }
148
+ else {
149
+ elementThemeMap.set(element, theme);
150
+ tokens = theme;
151
+ }
152
+ for (const [tokenName, tokenValue] of Object.entries(tokens)) {
153
+ if (theme === null) {
154
+ element.style.removeProperty(`--${tokenName}`);
155
+ }
156
+ else {
157
+ element.style.setProperty(`--${tokenName}`, tokenValue.toString());
158
+ }
159
+ }
160
+ }
59
161
  /**
60
- * @internal
162
+ * This function fixes a Safari bug: when an element should no longer be
163
+ * selected by an `@scope` rule, the styles defined in the `:scope` selector
164
+ * persist.
165
+ * @see https://bugs.webkit.org/show_bug.cgi?id=276454
166
+ *
167
+ * UA sniff regular expression is based on
168
+ * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#rendering_engine | the MDN documentation}.
61
169
  */
62
- export const setThemeFor = (element, theme) => {
63
- for (const [tokenName, tokenValue] of Object.entries(theme)) {
64
- element.style.setProperty(`--${tokenName}`, tokenValue.toString());
170
+ const { userAgent: UA } = navigator;
171
+ const isWebkit = /\bAppleWebKit\/[\d+\.]+\b/.test(UA);
172
+ function forceRepaint(element) {
173
+ if (!isWebkit) {
174
+ return;
65
175
  }
66
- };
176
+ const name = 'visibility';
177
+ const tempValue = 'hidden';
178
+ const currentValue = element.style.getPropertyValue(name);
179
+ element.style.setProperty(name, tempValue);
180
+ requestAnimationFrame(() => {
181
+ element.style.setProperty(name, currentValue);
182
+ });
183
+ }
184
+ /**
185
+ * @internal
186
+ * @deprecated Use `setTheme(theme, element)` instead.
187
+ */
188
+ export function setThemeFor(element, theme) {
189
+ setThemePropertiesOnElement(theme, element);
190
+ }
67
191
  //# sourceMappingURL=set-theme.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-theme.js","sourceRoot":"","sources":["../../../src/theme/set-theme.ts"],"names":[],"mappings":"AAOA,MAAM,0BAA0B,GAAG,kBAAkB,IAAI,GAAG,CAAC;AAC7D,MAAM,6BAA6B,GAAG,oBAAoB,IAAI,QAAQ,CAAC;AACvE,MAAM,eAAe,GAAG,IAAI,aAAa,EAAE,CAAC;AAC5C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAiB,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;IACvC,4EAA4E;IAC5E,yEAAyE;IACzE,2EAA2E;IAC3E,oBAAoB;IACpB,IAAI,CAAC,6BAA6B,EAAE;QAClC,WAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QAC7C,OAAO;KACR;IA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,KAAK,SAAS,EAAE,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpE;KACF;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,SAAS,CAAC;AACpC,MAAM,QAAQ,GAAG,2BAA2B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACtD,SAAS,YAAY,CAAC,OAAoB;IACxC,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO;KACR;IAED,MAAM,IAAI,GAAG,YAAY,CAAC;IAC1B,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC3B,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE1D,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3C,qBAAqB,CAAC,GAAG,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAoB,EAAE,KAAmB;IACnE,2BAA2B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { measurePerformance } from '@tensile-perf/web-components';
2
+ import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/tokens';
3
+ import { setTheme } from './set-theme.js';
4
+ const tests = {
5
+ mount: ({ onComplete }) => {
6
+ const { startMeasure, endMeasure } = measurePerformance();
7
+ const el = document.createElement('div');
8
+ document.body.append(el);
9
+ startMeasure();
10
+ // Newly set themes
11
+ setTheme(webLightTheme, el);
12
+ setTheme(webDarkTheme, el);
13
+ setTheme(teamsDarkTheme, el);
14
+ setTheme(teamsLightTheme, el);
15
+ // Cached themes
16
+ setTheme(webLightTheme, el);
17
+ setTheme(webDarkTheme, el);
18
+ setTheme(teamsDarkTheme, el);
19
+ setTheme(teamsLightTheme, el);
20
+ // Unset themes
21
+ setTheme(null, el);
22
+ endMeasure();
23
+ onComplete();
24
+ },
25
+ };
26
+ export { tests };
27
+ //# sourceMappingURL=set-theme.local.bench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-theme.local.bench.js","sourceRoot":"","sources":["../../../src/theme/set-theme.local.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,8BAA8B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEhG,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,KAAK,GAAuC;IAChD,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;QACxB,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,kBAAkB,EAAE,CAAC;QAE1D,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAEzB,YAAY,EAAE,CAAC;QAEf,mBAAmB;QACnB,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAC5B,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC3B,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAC7B,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QAE9B,gBAAgB;QAChB,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAC5B,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC3B,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAC7B,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QAE9B,eAAe;QACf,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAEnB,UAAU,EAAE,CAAC;QAEb,UAAU,EAAE,CAAC;IACf,CAAC;CACF,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { measurePerformance } from '@tensile-perf/web-components';
2
+ import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/tokens';
3
+ import { setTheme } from './set-theme.js';
4
+ const tests = {
5
+ mount: ({ onComplete }) => {
6
+ const { startMeasure, endMeasure } = measurePerformance();
7
+ const el = document.createElement('div');
8
+ el.attachShadow({ mode: 'open' });
9
+ el.shadowRoot.append(document.createElement('span'));
10
+ document.body.append(el);
11
+ startMeasure();
12
+ // Newly set themes
13
+ setTheme(webLightTheme, el);
14
+ setTheme(webDarkTheme, el);
15
+ setTheme(teamsDarkTheme, el);
16
+ setTheme(teamsLightTheme, el);
17
+ // Cached themes
18
+ setTheme(webLightTheme, el);
19
+ setTheme(webDarkTheme, el);
20
+ setTheme(teamsDarkTheme, el);
21
+ setTheme(teamsLightTheme, el);
22
+ // Unset themes
23
+ setTheme(null, el);
24
+ endMeasure();
25
+ onComplete();
26
+ },
27
+ };
28
+ export { tests };
29
+ //# sourceMappingURL=set-theme.shadow.bench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-theme.shadow.bench.js","sourceRoot":"","sources":["../../../src/theme/set-theme.shadow.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,8BAA8B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEhG,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,KAAK,GAAuC;IAChD,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;QACxB,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,kBAAkB,EAAE,CAAC;QAE1D,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAClC,EAAE,CAAC,UAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QACtD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAEzB,YAAY,EAAE,CAAC;QAEf,mBAAmB;QACnB,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAC5B,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC3B,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAC7B,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QAE9B,gBAAgB;QAChB,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAC5B,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC3B,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAC7B,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QAE9B,eAAe;QACf,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAEnB,UAAU,EAAE,CAAC;QAEb,UAAU,EAAE,CAAC;IACf,CAAC;CACF,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -8001,14 +8001,17 @@ export declare const roleForMenuItem: {
8001
8001
  * Note that this argument is not limited to existing theme objects (from
8002
8002
  * `@fluentui/tokens`), you can pass in an arbitrary theme object as long
8003
8003
  * as each entry’s value is either a string or a number.
8004
+ * @param node - The node to set the theme on, defaults to `document` for
8005
+ * setting global theme.
8004
8006
  * @internal
8005
8007
  */
8006
- export declare const setTheme: (theme: Theme) => void;
8008
+ export declare function setTheme(theme: Theme | null, node?: Document | HTMLElement): void;
8007
8009
 
8008
8010
  /**
8009
8011
  * @internal
8012
+ * @deprecated Use `setTheme(theme, element)` instead.
8010
8013
  */
8011
- export declare const setThemeFor: (element: HTMLElement, theme: Theme) => void;
8014
+ export declare function setThemeFor(element: HTMLElement, theme: Theme | null): void;
8012
8015
 
8013
8016
  /**
8014
8017
  * CSS custom property value for the {@link @fluentui/tokens#shadow16 | `shadow16`} design token.