first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { Theme } from '@fluentui/theme';
export declare const ThemeContext: React.Context<Theme | undefined>;
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThemeContext = void 0;
var React = require("react");
exports.ThemeContext = React.createContext(undefined);
//# sourceMappingURL=ThemeContext.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ThemeContext.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/ThemeContext.ts"],"names":[],"mappings":";;;AAAA,6BAA+B;AAGlB,QAAA,YAAY,GAAG,KAAK,CAAC,aAAa,CAAoB,SAAS,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport type { Theme } from '@fluentui/theme';\n\nexport const ThemeContext = React.createContext<Theme | undefined>(undefined);\n"]}
@@ -0,0 +1,6 @@
import * as React from 'react';
import type { ThemeProviderProps } from './ThemeProvider.types';
/**
* ThemeProvider, used for providing css variables and registering stylesheets.
*/
export declare const ThemeProvider: React.FunctionComponent<ThemeProviderProps>;
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThemeProvider = void 0;
var React = require("react");
var useThemeProviderClasses_1 = require("./useThemeProviderClasses");
var useThemeProvider_1 = require("./useThemeProvider");
var react_hooks_1 = require("@fluentui/react-hooks");
/**
* ThemeProvider, used for providing css variables and registering stylesheets.
*/
exports.ThemeProvider = React.forwardRef(function (props, ref) {
var rootRef = (0, react_hooks_1.useMergedRefs)(ref, React.useRef(null));
var _a = (0, useThemeProvider_1.useThemeProvider)(props, {
ref: rootRef,
as: 'div',
applyTo: 'element',
}), render = _a.render, state = _a.state;
// Render styles.
(0, useThemeProviderClasses_1.useThemeProviderClasses)(state);
// Return the rendered content.
return render(state);
});
exports.ThemeProvider.displayName = 'ThemeProvider';
//# sourceMappingURL=ThemeProvider.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ThemeProvider.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/ThemeProvider.tsx"],"names":[],"mappings":";;;AAAA,6BAA+B;AAC/B,qEAAoE;AACpE,uDAAsD;AACtD,qDAAsD;AAGtD;;GAEG;AACU,QAAA,aAAa,GAAG,KAAK,CAAC,UAAU,CAC3C,UAAC,KAAyB,EAAE,GAA8B;IACxD,IAAM,OAAO,GAAG,IAAA,2BAAa,EAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAc,IAAI,CAAC,CAAC,CAAC;IAC9D,IAAA,KAAoB,IAAA,mCAAgB,EAAC,KAAK,EAAE;QAChD,GAAG,EAAE,OAAO;QACZ,EAAE,EAAE,KAAK;QACT,OAAO,EAAE,SAAS;KACnB,CAAC,EAJM,MAAM,YAAA,EAAE,KAAK,WAInB,CAAC;IAEH,iBAAiB;IACjB,IAAA,iDAAuB,EAAC,KAAK,CAAC,CAAC;IAE/B,+BAA+B;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAC6C,CAAC;AAEjD,qBAAa,CAAC,WAAW,GAAG,eAAe,CAAC","sourcesContent":["import * as React from 'react';\nimport { useThemeProviderClasses } from './useThemeProviderClasses';\nimport { useThemeProvider } from './useThemeProvider';\nimport { useMergedRefs } from '@fluentui/react-hooks';\nimport type { ThemeProviderProps } from './ThemeProvider.types';\n\n/**\n * ThemeProvider, used for providing css variables and registering stylesheets.\n */\nexport const ThemeProvider = React.forwardRef<HTMLDivElement, ThemeProviderProps>(\n (props: ThemeProviderProps, ref: React.Ref<HTMLDivElement>) => {\n const rootRef = useMergedRefs(ref, React.useRef<HTMLElement>(null));\n const { render, state } = useThemeProvider(props, {\n ref: rootRef,\n as: 'div',\n applyTo: 'element',\n });\n\n // Render styles.\n useThemeProviderClasses(state);\n\n // Return the rendered content.\n return render(state);\n },\n) as React.FunctionComponent<ThemeProviderProps>;\n\nThemeProvider.displayName = 'ThemeProvider';\n"]}
@@ -0,0 +1,38 @@
import * as React from 'react';
import type { Theme, PartialTheme } from '@fluentui/theme';
import type { ICustomizerContext } from '@fluentui/utilities';
/**
* {@docCategory ThemeProvider}
* Props for the ThemeProvider component.
*/
export interface ThemeProviderProps extends React.HTMLAttributes<HTMLDivElement> {
/**
* A component that should be used as the root element of the ThemeProvider component.
*/
as?: React.ElementType;
/**
* Optional ref to the root element.
*/
ref?: React.Ref<HTMLElement>;
/**
* Defines the theme provided by the user.
*/
theme?: PartialTheme | Theme;
/**
* Defines where body-related theme is applied to.
* Setting to 'element' will apply body styles to the root element of ThemeProvider.
* Setting to 'body' will apply body styles to document body.
* Setting to 'none' will not apply body styles to either element or body.
*
* @defaultvalue 'element'
*/
applyTo?: 'element' | 'body' | 'none';
}
/**
* State for the ThemeProvider component.
*/
export type ThemeProviderState = Omit<ThemeProviderProps, 'theme' | 'ref'> & {
theme: Theme;
ref: React.RefObject<HTMLElement | null>;
customizerContext: ICustomizerContext;
};
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ThemeProvider.types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ThemeProvider.types.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/ThemeProvider.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { Theme, PartialTheme } from '@fluentui/theme';\nimport type { ICustomizerContext } from '@fluentui/utilities';\n\n/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n * {@docCategory ThemeProvider}\n * Props for the ThemeProvider component.\n */\nexport interface ThemeProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * A component that should be used as the root element of the ThemeProvider component.\n */\n as?: React.ElementType;\n\n /**\n * Optional ref to the root element.\n */\n ref?: React.Ref<HTMLElement>;\n\n /**\n * Defines the theme provided by the user.\n */\n theme?: PartialTheme | Theme;\n\n /**\n * Defines where body-related theme is applied to.\n * Setting to 'element' will apply body styles to the root element of ThemeProvider.\n * Setting to 'body' will apply body styles to document body.\n * Setting to 'none' will not apply body styles to either element or body.\n *\n * @defaultvalue 'element'\n */\n applyTo?: 'element' | 'body' | 'none';\n}\n\n/**\n * State for the ThemeProvider component.\n */\nexport type ThemeProviderState = Omit<ThemeProviderProps, 'theme' | 'ref'> & {\n theme: Theme;\n\n ref: React.RefObject<HTMLElement | null>;\n\n customizerContext: ICustomizerContext;\n};\n"]}
@@ -0,0 +1,5 @@
export { ThemeProvider } from './ThemeProvider';
export { useTheme } from './useTheme';
export { ThemeContext } from './ThemeContext';
export * from './makeStyles';
export type { ThemeProviderProps } from './ThemeProvider.types';
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThemeContext = exports.useTheme = exports.ThemeProvider = void 0;
var tslib_1 = require("tslib");
var ThemeProvider_1 = require("./ThemeProvider");
Object.defineProperty(exports, "ThemeProvider", { enumerable: true, get: function () { return ThemeProvider_1.ThemeProvider; } });
var useTheme_1 = require("./useTheme");
Object.defineProperty(exports, "useTheme", { enumerable: true, get: function () { return useTheme_1.useTheme; } });
var ThemeContext_1 = require("./ThemeContext");
Object.defineProperty(exports, "ThemeContext", { enumerable: true, get: function () { return ThemeContext_1.ThemeContext; } });
tslib_1.__exportStar(require("./makeStyles"), exports);
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,uDAA6B","sourcesContent":["export { ThemeProvider } from './ThemeProvider';\nexport { useTheme } from './useTheme';\nexport { ThemeContext } from './ThemeContext';\nexport * from './makeStyles';\nexport type { ThemeProviderProps } from './ThemeProvider.types';\n"]}
@@ -0,0 +1,28 @@
import type { IStyle } from '@fluentui/style-utilities';
import type { Theme } from '@fluentui/theme';
export type StylesClassMapping<TStyleSet extends {
[key in keyof TStyleSet]: IStyle;
}> = {
[key in keyof TStyleSet]: string;
};
/**
* Options that can be provided to the hook generated by `makeStyles`.
* @deprecated Only used in deprecated `makeStyles` implementation below.
*/
export type UseStylesOptions = {
theme?: Theme;
};
/**
* Registers a css object, optionally as a function of the theme.
*
* @param styleOrFunction - Either a css javascript object, or a function which takes in `ITheme`
* and returns a css javascript object.
*
* @deprecated Use `mergeStyles` instead for v8 related code. We will be using a new implementation of `makeStyles` in
* future versions of the library.
*/
export declare function makeStyles<TStyleSet extends {
[key in keyof TStyleSet]: IStyle;
} = {
[key: string]: IStyle;
}>(styleOrFunction: TStyleSet | ((theme: Theme) => TStyleSet)): (options?: UseStylesOptions) => StylesClassMapping<TStyleSet>;
@@ -0,0 +1,111 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeStyles = makeStyles;
var React = require("react");
var useTheme_1 = require("./useTheme");
var utilities_1 = require("@fluentui/utilities");
var react_window_provider_1 = require("@fluentui/react-window-provider");
var mergeStylesRenderer_1 = require("./styleRenderers/mergeStylesRenderer");
var graphGet = function (graphNode, _a) {
var _b, _c, _d;
var windowId = _a[0], id = _a[1], theme = _a[2];
return (_d = (_c = (_b = graphNode.get(windowId)) === null || _b === void 0 ? void 0 : _b.get(id)) === null || _c === void 0 ? void 0 : _c.get(theme)) === null || _d === void 0 ? void 0 : _d.classMap;
};
var graphSet = function (graphNode, _a, classMap) {
var _b, _c;
var windowId = _a[0], id = _a[1], theme = _a[2];
var windowNode = (_b = graphNode.get(windowId)) !== null && _b !== void 0 ? _b : new Map();
graphNode.set(windowId, windowNode);
var idNode = (_c = windowNode.get(id)) !== null && _c !== void 0 ? _c : new Map();
windowNode.set(id, idNode);
idNode.set(theme, { classMap: classMap, refCount: 0 });
};
function graphRef(graphNode, _a) {
var _b, _c;
var windowId = _a[0], id = _a[1], theme = _a[2];
var node = (_c = (_b = graphNode.get(windowId)) === null || _b === void 0 ? void 0 : _b.get(id)) === null || _c === void 0 ? void 0 : _c.get(theme);
if (node) {
node.refCount++;
}
}
function graphDeref(graphNode, _a) {
var _b, _c, _d, _e, _f, _g, _h, _j;
var windowId = _a[0], id = _a[1], theme = _a[2];
var node = (_c = (_b = graphNode.get(windowId)) === null || _b === void 0 ? void 0 : _b.get(id)) === null || _c === void 0 ? void 0 : _c.get(theme);
if (node) {
node.refCount--;
if (node.refCount === 0) {
(_e = (_d = graphNode.get(windowId)) === null || _d === void 0 ? void 0 : _d.get(id)) === null || _e === void 0 ? void 0 : _e.delete(theme);
if (((_g = (_f = graphNode.get(windowId)) === null || _f === void 0 ? void 0 : _f.get(id)) === null || _g === void 0 ? void 0 : _g.size) === 0) {
(_h = graphNode.get(windowId)) === null || _h === void 0 ? void 0 : _h.delete(id);
if (((_j = graphNode.get(windowId)) === null || _j === void 0 ? void 0 : _j.size) === 0) {
graphNode.delete(windowId);
}
}
}
}
}
/**
* Registers a css object, optionally as a function of the theme.
*
* @param styleOrFunction - Either a css javascript object, or a function which takes in `ITheme`
* and returns a css javascript object.
*
* @deprecated Use `mergeStyles` instead for v8 related code. We will be using a new implementation of `makeStyles` in
* future versions of the library.
*/
function makeStyles(styleOrFunction) {
// Create graph of inputs to map to output.
var graph = new Map();
// Retain a dictionary of window ids we're tracking
var allWindows = new Set();
// cleanupMapEntries will
// 1. remove all the graph branches for the window,
// 2. remove the event listener,
// 3. delete the allWindows entry.
var cleanupMapEntries = function (ev) {
var win = ev.currentTarget;
var winId = win.__id__;
graph.delete(winId);
win.removeEventListener('unload', cleanupMapEntries);
allWindows.delete(winId);
};
// eslint-disable-next-line @typescript-eslint/no-deprecated
return function (options) {
if (options === void 0) { options = {}; }
var theme = options.theme;
var winId;
var win = (0, react_window_provider_1.useWindow)();
if (win) {
win.__id__ = win.__id__ || (0, utilities_1.getId)();
winId = win.__id__;
if (!allWindows.has(winId)) {
allWindows.add(winId);
win.addEventListener('unload', cleanupMapEntries);
}
}
var contextualTheme = (0, useTheme_1.useTheme)();
theme = theme || contextualTheme;
var renderer = mergeStylesRenderer_1.mergeStylesRenderer;
var id = renderer.getId();
var path = [winId, id, theme];
var value = graphGet(graph, path);
// Don't keep around unused styles
React.useEffect(function () {
graphRef(graph, [winId, id, theme]);
return function () { return graphDeref(graph, [winId, id, theme]); };
}, [winId, id, theme]);
if (!value) {
var styles = isStyleFunction(styleOrFunction)
? styleOrFunction(theme)
: styleOrFunction;
value = mergeStylesRenderer_1.mergeStylesRenderer.renderStyles(styles, { targetWindow: win, rtl: !!theme.rtl });
graphSet(graph, path, value);
}
return value;
};
}
function isStyleFunction(styleOrFunction) {
return typeof styleOrFunction === 'function';
}
//# sourceMappingURL=makeStyles.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import type { ThemeProviderState } from './ThemeProvider.types';
import type { JSXElement } from '@fluentui/utilities';
export declare const renderThemeProvider: (state: ThemeProviderState) => JSXElement;
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderThemeProvider = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var utilities_1 = require("@fluentui/utilities");
var ThemeContext_1 = require("./ThemeContext");
var renderThemeProvider = function (state) {
var customizerContext = state.customizerContext, ref = state.ref, theme = state.theme;
var Root = state.as || 'div';
var rootProps = typeof state.as === 'string'
? (0, utilities_1.getNativeElementProps)(state.as, state)
: state.as === React.Fragment
? { children: state.children }
: (0, utilities_1.omit)(state, ['as']);
return (React.createElement(ThemeContext_1.ThemeContext.Provider, { value: theme },
React.createElement(utilities_1.CustomizerContext.Provider, { value: customizerContext },
React.createElement(utilities_1.FocusRectsProvider, { providerRef: ref },
React.createElement(Root, tslib_1.__assign({}, rootProps))))));
};
exports.renderThemeProvider = renderThemeProvider;
//# sourceMappingURL=renderThemeProvider.js.map
@@ -0,0 +1 @@
{"version":3,"file":"renderThemeProvider.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/renderThemeProvider.tsx"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,iDAAyG;AACzG,+CAA8C;AAKvC,IAAM,mBAAmB,GAAG,UAAC,KAAyB;IACnD,IAAA,iBAAiB,GAAiB,KAAK,kBAAtB,EAAE,GAAG,GAAY,KAAK,IAAjB,EAAE,KAAK,GAAK,KAAK,MAAV,CAAW;IAChD,IAAM,IAAI,GAAG,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC;IAC/B,IAAM,SAAS,GACb,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAC1B,CAAC,CAAC,IAAA,iCAAqB,EAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC;QACxC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,QAAQ;YAC7B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE;YAC9B,CAAC,CAAC,IAAA,gBAAI,EAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAE1B,OAAO,CACL,oBAAC,2BAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK;QACjC,oBAAC,6BAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,iBAAiB;YAClD,oBAAC,8BAAkB,IAAC,WAAW,EAAE,GAAG;gBAClC,oBAAC,IAAI,uBAAK,SAAS,EAAI,CACJ,CACM,CACP,CACzB,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,mBAAmB,uBAmB9B","sourcesContent":["import * as React from 'react';\nimport { CustomizerContext, FocusRectsProvider, getNativeElementProps, omit } from '@fluentui/utilities';\nimport { ThemeContext } from './ThemeContext';\nimport type { ThemeProviderState } from './ThemeProvider.types';\n\nimport type { JSXElement } from '@fluentui/utilities';\n\nexport const renderThemeProvider = (state: ThemeProviderState): JSXElement => {\n const { customizerContext, ref, theme } = state;\n const Root = state.as || 'div';\n const rootProps =\n typeof state.as === 'string'\n ? getNativeElementProps(state.as, state)\n : state.as === React.Fragment\n ? { children: state.children }\n : omit(state, ['as']);\n\n return (\n <ThemeContext.Provider value={theme}>\n <CustomizerContext.Provider value={customizerContext}>\n <FocusRectsProvider providerRef={ref}>\n <Root {...rootProps} />\n </FocusRectsProvider>\n </CustomizerContext.Provider>\n </ThemeContext.Provider>\n );\n};\n"]}
@@ -0,0 +1,2 @@
import type { StyleRenderer } from './types';
export declare const mergeStylesRenderer: StyleRenderer;
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeStylesRenderer = void 0;
var merge_styles_1 = require("@fluentui/merge-styles");
var _seed = 0;
exports.mergeStylesRenderer = {
reset: function () {
// If the stylesheet reset call is made, invalidate the cache keys.
merge_styles_1.Stylesheet.getInstance().onReset(function () { return _seed++; });
},
getId: function () { return _seed; },
renderStyles: function (styleSet, options) {
return (0, merge_styles_1.mergeCssSets)((Array.isArray(styleSet) ? styleSet : [styleSet]), options);
},
renderFontFace: function (fontFace, options) {
return (0, merge_styles_1.fontFace)(fontFace);
},
renderKeyframes: function (keyframes) {
return (0, merge_styles_1.keyframes)(keyframes);
},
};
//# sourceMappingURL=mergeStylesRenderer.js.map
@@ -0,0 +1 @@
{"version":3,"file":"mergeStylesRenderer.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/styleRenderers/mergeStylesRenderer.tsx"],"names":[],"mappings":";;;AAAA,uDAKgC;AAGhC,IAAI,KAAK,GAAG,CAAC,CAAC;AAED,QAAA,mBAAmB,GAAkB;IAChD,KAAK,EAAE;QACL,mEAAmE;QACnE,yBAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,cAAM,OAAA,KAAK,EAAE,EAAP,CAAO,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,EAAE,cAAM,OAAA,KAAK,EAAL,CAAK;IAElB,YAAY,EAAE,UAAC,QAAQ,EAAE,OAAO;QAC9B,OAAO,IAAA,2BAAY,EAAC,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAQ,EAAE,OAAO,CAAQ,CAAC;IAChG,CAAC;IAED,cAAc,EAAE,UAAC,QAAQ,EAAE,OAAO;QAChC,OAAO,IAAA,uBAAa,EAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,eAAe,EAAE,UAAA,SAAS;QACxB,OAAO,IAAA,wBAAc,EAAC,SAAgB,CAAC,CAAC;IAC1C,CAAC;CACF,CAAC","sourcesContent":["import {\n Stylesheet,\n mergeCssSets,\n fontFace as mergeFontFace,\n keyframes as mergeKeyframes,\n} from '@fluentui/merge-styles';\nimport type { StyleRenderer } from './types';\n\nlet _seed = 0;\n\nexport const mergeStylesRenderer: StyleRenderer = {\n reset: () => {\n // If the stylesheet reset call is made, invalidate the cache keys.\n Stylesheet.getInstance().onReset(() => _seed++);\n },\n\n getId: () => _seed,\n\n renderStyles: (styleSet, options) => {\n return mergeCssSets((Array.isArray(styleSet) ? styleSet : [styleSet]) as any, options) as any;\n },\n\n renderFontFace: (fontFace, options) => {\n return mergeFontFace(fontFace);\n },\n\n renderKeyframes: keyframes => {\n return mergeKeyframes(keyframes as any);\n },\n};\n"]}
@@ -0,0 +1,31 @@
import type { IFontFace, IKeyframes } from '@fluentui/merge-styles';
type StyleRendererOptions = {
rtl?: boolean;
targetWindow: Window | undefined;
};
export interface StyleRenderer {
/**
* Expected to initialize or re-initialize the renderer. Primarily for testing purposes.
*/
reset: () => void;
/**
* Returns a unique id for the renderer; used as part of the cache key when determining if new
* styles need to be rendered.
*/
getId: () => number;
/**
* Renders a stylesheet and returns the map of key to class name.
*/
renderStyles: <TRuleSet>(ruleSet: TRuleSet, options: StyleRendererOptions) => {
[key in keyof TRuleSet]: string;
};
/**
* Renders keyframes and returns the keyframe name.
*/
renderKeyframes: (keyframes: IKeyframes, options: StyleRendererOptions) => string;
/**
* Renders fontfaces.
*/
renderFontFace: (fontFace: IFontFace, options: StyleRendererOptions) => void;
}
export {};
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/styleRenderers/types.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { IFontFace, IKeyframes } from '@fluentui/merge-styles';\n\ntype StyleRendererOptions = {\n rtl?: boolean;\n targetWindow: Window | undefined;\n};\n\nexport interface StyleRenderer {\n /**\n * Expected to initialize or re-initialize the renderer. Primarily for testing purposes.\n */\n reset: () => void;\n\n /**\n * Returns a unique id for the renderer; used as part of the cache key when determining if new\n * styles need to be rendered.\n */\n getId: () => number;\n\n /**\n * Renders a stylesheet and returns the map of key to class name.\n */\n renderStyles: <TRuleSet>(ruleSet: TRuleSet, options: StyleRendererOptions) => { [key in keyof TRuleSet]: string };\n\n /**\n * Renders keyframes and returns the keyframe name.\n */\n renderKeyframes: (keyframes: IKeyframes, options: StyleRendererOptions) => string;\n\n /**\n * Renders fontfaces.\n */\n renderFontFace: (fontFace: IFontFace, options: StyleRendererOptions) => void;\n}\n"]}
@@ -0,0 +1,5 @@
import type { Theme } from '@fluentui/theme';
/**
* React hook for programmatically accessing the theme.
*/
export declare const useTheme: () => Theme;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTheme = void 0;
var React = require("react");
var utilities_1 = require("@fluentui/utilities");
var theme_1 = require("@fluentui/theme");
var ThemeContext_1 = require("./ThemeContext");
/**
* Get theme from CustomizerContext or Customizations singleton.
*/
function useCompatTheme() {
return (0, utilities_1.useCustomizationSettings)(['theme']).theme;
}
/**
* React hook for programmatically accessing the theme.
*/
var useTheme = function () {
var theme = React.useContext(ThemeContext_1.ThemeContext);
var legacyTheme = useCompatTheme();
return theme || legacyTheme || (0, theme_1.createTheme)({});
};
exports.useTheme = useTheme;
//# sourceMappingURL=useTheme.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useTheme.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/useTheme.ts"],"names":[],"mappings":";;;AAAA,6BAA+B;AAC/B,iDAA+D;AAC/D,yCAA8C;AAC9C,+CAA8C;AAG9C;;GAEG;AACH,SAAS,cAAc;IACrB,OAAO,IAAA,oCAAwB,EAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AACnD,CAAC;AAED;;GAEG;AACI,IAAM,QAAQ,GAAG;IACtB,IAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,2BAAY,CAAC,CAAC;IAC7C,IAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,OAAO,KAAK,IAAI,WAAW,IAAI,IAAA,mBAAW,EAAC,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,QAAQ,YAKnB","sourcesContent":["import * as React from 'react';\nimport { useCustomizationSettings } from '@fluentui/utilities';\nimport { createTheme } from '@fluentui/theme';\nimport { ThemeContext } from './ThemeContext';\nimport type { ITheme, Theme } from '@fluentui/theme';\n\n/**\n * Get theme from CustomizerContext or Customizations singleton.\n */\nfunction useCompatTheme(): ITheme | undefined {\n return useCustomizationSettings(['theme']).theme;\n}\n\n/**\n * React hook for programmatically accessing the theme.\n */\nexport const useTheme = (): Theme => {\n const theme = React.useContext(ThemeContext);\n const legacyTheme = useCompatTheme();\n\n return theme || legacyTheme || createTheme({});\n};\n"]}
@@ -0,0 +1,10 @@
import type { ThemeProviderProps, ThemeProviderState } from './ThemeProvider.types';
import type { JSXElement } from '@fluentui/utilities';
/**
* Returns the ThemeProvider render function and calculated state, given user input, ref, and
* a set of default prop values.
*/
export declare const useThemeProvider: (props: ThemeProviderProps, defaultProps: ThemeProviderProps) => {
state: ThemeProviderState;
render: (state: ThemeProviderState) => JSXElement;
};
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useThemeProvider = void 0;
var renderThemeProvider_1 = require("./renderThemeProvider");
var useThemeProviderState_1 = require("./useThemeProviderState");
var utilities_1 = require("@fluentui/utilities");
/**
* Returns the ThemeProvider render function and calculated state, given user input, ref, and
* a set of default prop values.
*/
var useThemeProvider = function (props, defaultProps) {
var state = (0, utilities_1.getPropsWithDefaults)(defaultProps, props);
// Apply changes to state.
(0, useThemeProviderState_1.useThemeProviderState)(state);
return {
state: state,
render: renderThemeProvider_1.renderThemeProvider,
};
};
exports.useThemeProvider = useThemeProvider;
//# sourceMappingURL=useThemeProvider.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useThemeProvider.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/useThemeProvider.tsx"],"names":[],"mappings":";;;AAAA,6DAAsE;AACtE,iEAAgE;AAChE,iDAA2D;AAK3D;;;GAGG;AACI,IAAM,gBAAgB,GAAG,UAC9B,KAAyB,EACzB,YAAgC;IAKhC,IAAM,KAAK,GAAG,IAAA,gCAAoB,EAAC,YAAY,EAAE,KAAK,CAAuB,CAAC;IAE9E,0BAA0B;IAC1B,IAAA,6CAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO;QACL,KAAK,OAAA;QACL,MAAM,2CAAA;KACP,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,gBAAgB,oBAgB3B","sourcesContent":["import { renderThemeProvider as render } from './renderThemeProvider';\nimport { useThemeProviderState } from './useThemeProviderState';\nimport { getPropsWithDefaults } from '@fluentui/utilities';\nimport type { ThemeProviderProps, ThemeProviderState } from './ThemeProvider.types';\n\nimport type { JSXElement } from '@fluentui/utilities';\n\n/**\n * Returns the ThemeProvider render function and calculated state, given user input, ref, and\n * a set of default prop values.\n */\nexport const useThemeProvider = (\n props: ThemeProviderProps,\n defaultProps: ThemeProviderProps,\n): {\n state: ThemeProviderState;\n render: (state: ThemeProviderState) => JSXElement;\n} => {\n const state = getPropsWithDefaults(defaultProps, props) as ThemeProviderState;\n\n // Apply changes to state.\n useThemeProviderState(state);\n\n return {\n state,\n render,\n };\n};\n"]}
@@ -0,0 +1,2 @@
import type { ThemeProviderState } from './ThemeProvider.types';
export declare function useThemeProviderClasses(state: ThemeProviderState): void;
@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useThemeProviderClasses = useThemeProviderClasses;
var React = require("react");
var utilities_1 = require("@fluentui/utilities");
var react_window_provider_1 = require("@fluentui/react-window-provider");
var makeStyles_1 = require("./makeStyles");
// eslint-disable-next-line @typescript-eslint/no-deprecated
var useThemeProviderStyles = (0, makeStyles_1.makeStyles)(function (theme) {
var semanticColors = theme.semanticColors, fonts = theme.fonts;
return {
body: [
{
color: semanticColors.bodyText,
background: semanticColors.bodyBackground,
fontFamily: fonts.medium.fontFamily,
fontWeight: fonts.medium.fontWeight,
fontSize: fonts.medium.fontSize,
MozOsxFontSmoothing: fonts.medium.MozOsxFontSmoothing,
WebkitFontSmoothing: fonts.medium.WebkitFontSmoothing,
},
],
};
});
/**
* Hook to add class to body element.
*/
function useApplyClassToBody(state, classesToApply) {
var _a;
var applyTo = state.applyTo;
var applyToBody = applyTo === 'body';
var body = (_a = (0, react_window_provider_1.useDocument)()) === null || _a === void 0 ? void 0 : _a.body;
React.useEffect(function () {
if (!applyToBody || !body) {
return;
}
for (var _i = 0, classesToApply_1 = classesToApply; _i < classesToApply_1.length; _i++) {
var classToApply = classesToApply_1[_i];
if (classToApply) {
body.classList.add(classToApply);
}
}
return function () {
if (!applyToBody || !body) {
return;
}
for (var _i = 0, classesToApply_2 = classesToApply; _i < classesToApply_2.length; _i++) {
var classToApply = classesToApply_2[_i];
if (classToApply) {
body.classList.remove(classToApply);
}
}
};
}, [applyToBody, body, classesToApply]);
}
function useThemeProviderClasses(state) {
var classes = useThemeProviderStyles(state);
var className = state.className, applyTo = state.applyTo;
useApplyClassToBody(state, [classes.root, classes.body]);
state.className = (0, utilities_1.css)(className, classes.root, applyTo === 'element' && classes.body);
}
//# sourceMappingURL=useThemeProviderClasses.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useThemeProviderClasses.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/useThemeProviderClasses.tsx"],"names":[],"mappings":";;AA4DA,0DAOC;AAnED,6BAA+B;AAC/B,iDAA0C;AAC1C,yEAA8D;AAC9D,2CAA0C;AAI1C,4DAA4D;AAC5D,IAAM,sBAAsB,GAAG,IAAA,uBAAU,EAAC,UAAC,KAAY;IAC7C,IAAA,cAAc,GAAY,KAAK,eAAjB,EAAE,KAAK,GAAK,KAAK,MAAV,CAAW;IAExC,OAAO;QACL,IAAI,EAAE;YACJ;gBACE,KAAK,EAAE,cAAc,CAAC,QAAQ;gBAC9B,UAAU,EAAE,cAAc,CAAC,cAAc;gBACzC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;gBACnC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;gBACnC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;gBAC/B,mBAAmB,EAAE,KAAK,CAAC,MAAM,CAAC,mBAAmB;gBACrD,mBAAmB,EAAE,KAAK,CAAC,MAAM,CAAC,mBAAmB;aACtD;SACF;KACqB,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAyB,EAAE,cAAwB;;IACtE,IAAA,OAAO,GAAK,KAAK,QAAV,CAAW;IAE1B,IAAM,WAAW,GAAG,OAAO,KAAK,MAAM,CAAC;IACvC,IAAM,IAAI,GAAG,MAAA,IAAA,mCAAW,GAAE,0CAAE,IAAI,CAAC;IAEjC,KAAK,CAAC,SAAS,CAAC;QACd,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,KAA2B,UAAc,EAAd,iCAAc,EAAd,4BAAc,EAAd,IAAc,EAAE,CAAC;YAAvC,IAAM,YAAY,uBAAA;YACrB,IAAI,YAAY,EAAE,CAAC;gBACjB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QAED,OAAO;YACL,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC1B,OAAO;YACT,CAAC;YAED,KAA2B,UAAc,EAAd,iCAAc,EAAd,4BAAc,EAAd,IAAc,EAAE,CAAC;gBAAvC,IAAM,YAAY,uBAAA;gBACrB,IAAI,YAAY,EAAE,CAAC;oBACjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBACtC,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAgB,uBAAuB,CAAC,KAAyB;IAC/D,IAAM,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACtC,IAAA,SAAS,GAAc,KAAK,UAAnB,EAAE,OAAO,GAAK,KAAK,QAAV,CAAW;IAErC,mBAAmB,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAEzD,KAAK,CAAC,SAAS,GAAG,IAAA,eAAG,EAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AACxF,CAAC","sourcesContent":["import * as React from 'react';\nimport { css } from '@fluentui/utilities';\nimport { useDocument } from '@fluentui/react-window-provider';\nimport { makeStyles } from './makeStyles';\nimport type { ThemeProviderState } from './ThemeProvider.types';\nimport type { Theme } from '@fluentui/theme';\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nconst useThemeProviderStyles = makeStyles((theme: Theme) => {\n const { semanticColors, fonts } = theme;\n\n return {\n body: [\n {\n color: semanticColors.bodyText,\n background: semanticColors.bodyBackground,\n fontFamily: fonts.medium.fontFamily,\n fontWeight: fonts.medium.fontWeight,\n fontSize: fonts.medium.fontSize,\n MozOsxFontSmoothing: fonts.medium.MozOsxFontSmoothing,\n WebkitFontSmoothing: fonts.medium.WebkitFontSmoothing,\n },\n ],\n } as Record<string, any>;\n});\n\n/**\n * Hook to add class to body element.\n */\nfunction useApplyClassToBody(state: ThemeProviderState, classesToApply: string[]): void {\n const { applyTo } = state;\n\n const applyToBody = applyTo === 'body';\n const body = useDocument()?.body;\n\n React.useEffect(() => {\n if (!applyToBody || !body) {\n return;\n }\n\n for (const classToApply of classesToApply) {\n if (classToApply) {\n body.classList.add(classToApply);\n }\n }\n\n return () => {\n if (!applyToBody || !body) {\n return;\n }\n\n for (const classToApply of classesToApply) {\n if (classToApply) {\n body.classList.remove(classToApply);\n }\n }\n };\n }, [applyToBody, body, classesToApply]);\n}\n\nexport function useThemeProviderClasses(state: ThemeProviderState): void {\n const classes = useThemeProviderStyles(state);\n const { className, applyTo } = state;\n\n useApplyClassToBody(state, [classes.root, classes.body]);\n\n state.className = css(className, classes.root, applyTo === 'element' && classes.body);\n}\n"]}
@@ -0,0 +1,2 @@
import type { ThemeProviderState } from './ThemeProvider.types';
export declare const useThemeProviderState: (draftState: ThemeProviderState) => void;
@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useThemeProviderState = void 0;
var theme_1 = require("@fluentui/theme");
var React = require("react");
var useTheme_1 = require("./useTheme");
var utilities_1 = require("@fluentui/utilities");
var themeToIdMap = new Map();
var getThemeId = function () {
var themes = [];
for (var _i = 0; _i < arguments.length; _i++) {
themes[_i] = arguments[_i];
}
var ids = [];
for (var _a = 0, themes_1 = themes; _a < themes_1.length; _a++) {
var theme = themes_1[_a];
if (theme) {
var id = theme.id || themeToIdMap.get(theme);
if (!id) {
id = (0, utilities_1.getId)('');
themeToIdMap.set(theme, id);
}
ids.push(id);
}
}
return ids.join('-');
};
var useThemeProviderState = function (draftState) {
var userTheme = draftState.theme;
// Pull contextual theme.
var parentTheme = (0, useTheme_1.useTheme)();
// Update the incoming theme with a memoized version of the merged theme.
var theme = (draftState.theme = React.useMemo(function () {
var mergedTheme = (0, theme_1.mergeThemes)(parentTheme, userTheme);
mergedTheme.id = getThemeId(parentTheme, userTheme);
return mergedTheme;
}, [parentTheme, userTheme]));
draftState.customizerContext = React.useMemo(function () { return ({
customizations: {
inCustomizerContext: true,
settings: { theme: theme },
scopedSettings: theme.components || {},
},
}); }, [theme]);
if (draftState.theme.rtl !== parentTheme.rtl) {
draftState.dir = draftState.theme.rtl ? 'rtl' : 'ltr';
}
};
exports.useThemeProviderState = useThemeProviderState;
//# sourceMappingURL=useThemeProviderState.js.map
@@ -0,0 +1 @@
{"version":3,"file":"useThemeProviderState.js","sourceRoot":"../src/","sources":["utilities/ThemeProvider/useThemeProviderState.tsx"],"names":[],"mappings":";;;AAAA,yCAA8C;AAC9C,6BAA+B;AAC/B,uCAAsC;AACtC,iDAA4C;AAK5C,IAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE/C,IAAM,UAAU,GAAG;IAAC,gBAA+C;SAA/C,UAA+C,EAA/C,qBAA+C,EAA/C,IAA+C;QAA/C,2BAA+C;;IACjE,IAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,KAAoB,UAAM,EAAN,iBAAM,EAAN,oBAAM,EAAN,IAAM,EAAE,CAAC;QAAxB,IAAM,KAAK,eAAA;QACd,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,EAAE,GAAI,KAAe,CAAC,EAAE,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAExD,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,EAAE,GAAG,IAAA,iBAAK,EAAC,EAAE,CAAC,CAAC;gBACf,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC9B,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC;AAEK,IAAM,qBAAqB,GAAG,UAAC,UAA8B;IAClE,IAAM,SAAS,GAAiB,UAAU,CAAC,KAAK,CAAC;IAEjD,yBAAyB;IACzB,IAAM,WAAW,GAAG,IAAA,mBAAQ,GAAE,CAAC;IAE/B,yEAAyE;IACzE,IAAM,KAAK,GAAG,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAQ;QACrD,IAAM,WAAW,GAAU,IAAA,mBAAW,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAE/D,WAAW,CAAC,EAAE,GAAG,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAEpD,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAE9B,UAAU,CAAC,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAC1C,cAAM,OAAA,CAAC;QACL,cAAc,EAAE;YACd,mBAAmB,EAAE,IAAI;YACzB,QAAQ,EAAE,EAAE,KAAK,OAAA,EAAE;YACnB,cAAc,EAAE,KAAK,CAAC,UAAU,IAAI,EAAE;SACvC;KACF,CAAC,EANI,CAMJ,EACF,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,WAAW,CAAC,GAAG,EAAE,CAAC;QAC7C,UAAU,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACxD,CAAC;AACH,CAAC,CAAC;AA7BW,QAAA,qBAAqB,yBA6BhC","sourcesContent":["import { mergeThemes } from '@fluentui/theme';\nimport * as React from 'react';\nimport { useTheme } from './useTheme';\nimport { getId } from '@fluentui/utilities';\nimport type { PartialTheme, Theme } from '@fluentui/theme';\nimport type { ThemeProviderState } from './ThemeProvider.types';\nimport type { ICustomizerContext } from '@fluentui/utilities';\n\nconst themeToIdMap = new Map<Object, string>();\n\nconst getThemeId = (...themes: (Theme | PartialTheme | undefined)[]) => {\n const ids: string[] = [];\n\n for (const theme of themes) {\n if (theme) {\n let id = (theme as Theme).id || themeToIdMap.get(theme);\n\n if (!id) {\n id = getId('');\n themeToIdMap.set(theme, id);\n }\n ids.push(id);\n }\n }\n\n return ids.join('-');\n};\n\nexport const useThemeProviderState = (draftState: ThemeProviderState): void => {\n const userTheme: PartialTheme = draftState.theme;\n\n // Pull contextual theme.\n const parentTheme = useTheme();\n\n // Update the incoming theme with a memoized version of the merged theme.\n const theme = (draftState.theme = React.useMemo<Theme>(() => {\n const mergedTheme: Theme = mergeThemes(parentTheme, userTheme);\n\n mergedTheme.id = getThemeId(parentTheme, userTheme);\n\n return mergedTheme;\n }, [parentTheme, userTheme]));\n\n draftState.customizerContext = React.useMemo<ICustomizerContext>(\n () => ({\n customizations: {\n inCustomizerContext: true,\n settings: { theme },\n scopedSettings: theme.components || {},\n },\n }),\n [theme],\n );\n\n if (draftState.theme.rtl !== parentTheme.rtl) {\n draftState.dir = draftState.theme.rtl ? 'rtl' : 'ltr';\n }\n};\n"]}