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,9 @@
/**
* Builds a class names object from a given map.
*
* @param styles - Map of unprocessed styles.
* @returns Map of property name to class name.
*/
export declare function buildClassMap<T extends Object>(styles: T): {
[key in keyof T]?: string;
};
+31
View File
@@ -0,0 +1,31 @@
import { mergeStyles } from '../MergeStyles';
/**
* Builds a class names object from a given map.
*
* @param styles - Map of unprocessed styles.
* @returns Map of property name to class name.
*/
export function buildClassMap(styles) {
var classes = {};
var _loop_1 = function (styleName) {
if (styles.hasOwnProperty(styleName)) {
var className_1;
Object.defineProperty(classes, styleName, {
get: function () {
if (className_1 === undefined) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
className_1 = mergeStyles(styles[styleName]).toString();
}
return className_1;
},
enumerable: true,
configurable: true,
});
}
};
for (var styleName in styles) {
_loop_1(styleName);
}
return classes;
}
//# sourceMappingURL=buildClassMap.js.map
@@ -0,0 +1 @@
{"version":3,"file":"buildClassMap.js","sourceRoot":"../src/","sources":["utilities/buildClassMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAmB,MAAS;IACvD,IAAI,OAAO,GAAkC,EAAE,CAAC;4BAEvC,SAAS;QAChB,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;YACrC,IAAI,WAAiB,CAAC;YAEtB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE;gBACxC,GAAG,EAAE;oBACH,IAAI,WAAS,KAAK,SAAS,EAAE,CAAC;wBAC5B,8DAA8D;wBAC9D,WAAS,GAAG,WAAW,CAAC,MAAM,CAAC,SAAS,CAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;oBAC/D,CAAC;oBACD,OAAO,WAAS,CAAC;gBACnB,CAAC;gBACD,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;QACL,CAAC;;IAfH,KAAK,IAAI,SAAS,IAAI,MAAM;gBAAnB,SAAS;KAgBjB;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { mergeStyles } from '../MergeStyles';\n\n/**\n * Builds a class names object from a given map.\n *\n * @param styles - Map of unprocessed styles.\n * @returns Map of property name to class name.\n */\nexport function buildClassMap<T extends Object>(styles: T): { [key in keyof T]?: string } {\n let classes: { [key in keyof T]?: string } = {};\n\n for (let styleName in styles) {\n if (styles.hasOwnProperty(styleName)) {\n let className: string;\n\n Object.defineProperty(classes, styleName, {\n get: (): string => {\n if (className === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n className = mergeStyles(styles[styleName] as any).toString();\n }\n return className;\n },\n enumerable: true,\n configurable: true,\n });\n }\n }\n\n return classes;\n}\n"]}
@@ -0,0 +1,7 @@
/**
* Gets an icon classname. You should be able to add this classname to an I tag with no
* additional classnames, and render the icon.
*
* @public
*/
export declare function getIconClassName(name: string): string;
@@ -0,0 +1,26 @@
import { mergeStyles } from '@fluentui/merge-styles';
import { getIcon } from './icons';
var defaultIconStyles = {
display: 'inline-block',
};
/**
* Gets an icon classname. You should be able to add this classname to an I tag with no
* additional classnames, and render the icon.
*
* @public
*/
export function getIconClassName(name) {
var className = '';
var icon = getIcon(name);
if (icon) {
className = mergeStyles(icon.subset.className, defaultIconStyles, {
selectors: {
'::before': {
content: "\"".concat(icon.code, "\""),
},
},
});
}
return className;
}
//# sourceMappingURL=getIconClassName.js.map
@@ -0,0 +1 @@
{"version":3,"file":"getIconClassName.js","sourceRoot":"../src/","sources":["utilities/getIconClassName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,IAAM,iBAAiB,GAAW;IAChC,OAAO,EAAE,cAAc;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,IAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3B,IAAI,IAAI,EAAE,CAAC;QACT,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,iBAAiB,EAAE;YAChE,SAAS,EAAE;gBACT,UAAU,EAAE;oBACV,OAAO,EAAE,YAAI,IAAI,CAAC,IAAI,OAAG;iBAC1B;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { mergeStyles } from '@fluentui/merge-styles';\nimport { getIcon } from './icons';\nimport type { IStyle } from '@fluentui/merge-styles';\n\nconst defaultIconStyles: IStyle = {\n display: 'inline-block',\n};\n\n/**\n * Gets an icon classname. You should be able to add this classname to an I tag with no\n * additional classnames, and render the icon.\n *\n * @public\n */\nexport function getIconClassName(name: string): string {\n let className = '';\n const icon = getIcon(name);\n\n if (icon) {\n className = mergeStyles(icon.subset.className, defaultIconStyles, {\n selectors: {\n '::before': {\n content: `\"${icon.code}\"`,\n },\n },\n });\n }\n\n return className;\n}\n"]}
+80
View File
@@ -0,0 +1,80 @@
import type { IRawStyle, IFontFace } from '@fluentui/merge-styles';
import type { JSXElement } from '@fluentui/utilities';
export interface IIconSubset {
fontFace?: IFontFace;
icons: {
[key: string]: string | JSXElement;
};
style?: IRawStyle;
/**
* Indicates to the icon renderer that it is safe to merge any props on the original `Icon` element
* onto the child content element registered for the icon which are valid for HTML images.
*/
mergeImageProps?: boolean;
}
export interface IIconSubsetRecord extends IIconSubset {
isRegistered?: boolean;
className?: string;
}
export interface IIconRecord {
code: string | undefined;
subset: IIconSubsetRecord;
}
export interface IIconOptions {
/**
* By default, registering the same set of icons will generate a console warning per duplicate icon
* registered, because this scenario can create unexpected consequences.
*
* Some scenarios include:
*
* Icon set was previously registered using a different base url.
* Icon set was previously registered but a different version was provided.
* Icons in a previous registered set overlap with a new set.
*
* To simply ignore previously registered icons, you can specify to disable warnings. This means
* that if an icon which was previous registered is registered again, it will be silently ignored.
* However, consider whether the problems listed above will cause issues.
**/
disableWarnings: boolean;
/**
* @deprecated Use `disableWarnings` instead.
*/
warnOnMissingIcons?: boolean;
}
export interface IIconRecords {
__options: IIconOptions;
__remapped: {
[key: string]: string;
};
[key: string]: IIconRecord | {};
}
/**
* Registers a given subset of icons.
*
* @param iconSubset - the icon subset definition.
*/
export declare function registerIcons(iconSubset: IIconSubset, options?: Partial<IIconOptions>): void;
/**
* Unregisters icons by name.
*
* @param iconNames - List of icons to unregister.
*/
export declare function unregisterIcons(iconNames: string[]): void;
/**
* Remaps one icon name to another.
*/
export declare function registerIconAlias(iconName: string, mappedToName: string): void;
/**
* Gets an icon definition. If an icon is requested but the subset has yet to be registered,
* it will get registered immediately.
*
* @public
* @param name - Name of icon.
*/
export declare function getIcon(name?: string): IIconRecord | undefined;
/**
* Sets the icon options.
*
* @public
*/
export declare function setIconOptions(options: Partial<IIconOptions>): void;
+165
View File
@@ -0,0 +1,165 @@
import { __assign } from "tslib";
import { GlobalSettings, warn } from '@fluentui/utilities';
import { fontFace, mergeStyles, Stylesheet } from '@fluentui/merge-styles';
var ICON_SETTING_NAME = 'icons';
var _iconSettings = GlobalSettings.getValue(ICON_SETTING_NAME, {
__options: {
disableWarnings: false,
warnOnMissingIcons: true,
},
__remapped: {},
});
// Reset icon registration on stylesheet resets.
var stylesheet = Stylesheet.getInstance();
if (stylesheet && stylesheet.onReset) {
stylesheet.onReset(function () {
for (var name_1 in _iconSettings) {
if (_iconSettings.hasOwnProperty(name_1) && !!_iconSettings[name_1].subset) {
_iconSettings[name_1].subset.className = undefined;
}
}
});
}
/**
* Normalizes an icon name for consistent mapping.
* Current implementation is to convert the icon name to lower case.
*
* @param name - Icon name to normalize.
* @returns {string} Normalized icon name to use for indexing and mapping.
*/
var normalizeIconName = function (name) { return name.toLowerCase(); };
/**
* Registers a given subset of icons.
*
* @param iconSubset - the icon subset definition.
*/
export function registerIcons(iconSubset, options) {
var subset = __assign(__assign({}, iconSubset), { isRegistered: false, className: undefined });
var icons = iconSubset.icons;
// Grab options, optionally mix user provided ones on top.
options = options ? __assign(__assign({}, _iconSettings.__options), options) : _iconSettings.__options;
for (var iconName in icons) {
if (icons.hasOwnProperty(iconName)) {
var code = icons[iconName];
var normalizedIconName = normalizeIconName(iconName);
if (_iconSettings[normalizedIconName]) {
_warnDuplicateIcon(iconName);
}
else {
_iconSettings[normalizedIconName] = {
code: code,
subset: subset,
};
}
}
}
}
/**
* Unregisters icons by name.
*
* @param iconNames - List of icons to unregister.
*/
export function unregisterIcons(iconNames) {
var options = _iconSettings.__options;
var _loop_1 = function (iconName) {
var normalizedIconName = normalizeIconName(iconName);
if (_iconSettings[normalizedIconName]) {
delete _iconSettings[normalizedIconName];
}
else {
// Warn that we are trying to delete an icon that doesn't exist
if (!options.disableWarnings) {
warn("The icon \"".concat(iconName, "\" tried to unregister but was not registered."));
}
}
// Delete any aliases for this iconName
if (_iconSettings.__remapped[normalizedIconName]) {
delete _iconSettings.__remapped[normalizedIconName];
}
// Delete any items that were an alias for this iconName
Object.keys(_iconSettings.__remapped).forEach(function (key) {
if (_iconSettings.__remapped[key] === normalizedIconName) {
delete _iconSettings.__remapped[key];
}
});
};
for (var _i = 0, iconNames_1 = iconNames; _i < iconNames_1.length; _i++) {
var iconName = iconNames_1[_i];
_loop_1(iconName);
}
}
/**
* Remaps one icon name to another.
*/
export function registerIconAlias(iconName, mappedToName) {
_iconSettings.__remapped[normalizeIconName(iconName)] = normalizeIconName(mappedToName);
}
/**
* Gets an icon definition. If an icon is requested but the subset has yet to be registered,
* it will get registered immediately.
*
* @public
* @param name - Name of icon.
*/
export function getIcon(name) {
var icon = undefined;
var options = _iconSettings.__options;
name = name ? normalizeIconName(name) : '';
name = _iconSettings.__remapped[name] || name;
if (name) {
icon = _iconSettings[name];
if (icon) {
var subset = icon.subset;
if (subset && subset.fontFace) {
if (!subset.isRegistered) {
fontFace(subset.fontFace);
subset.isRegistered = true;
}
if (!subset.className) {
subset.className = mergeStyles(subset.style, {
fontFamily: subset.fontFace.fontFamily,
fontWeight: subset.fontFace.fontWeight || 'normal',
fontStyle: subset.fontFace.fontStyle || 'normal',
});
}
}
}
else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (!options.disableWarnings && options.warnOnMissingIcons) {
warn("The icon \"".concat(name, "\" was used but not registered. See https://github.com/microsoft/fluentui/wiki/Using-icons for more information."));
}
}
}
return icon;
}
/**
* Sets the icon options.
*
* @public
*/
export function setIconOptions(options) {
_iconSettings.__options = __assign(__assign({}, _iconSettings.__options), options);
}
var _missingIcons = [];
var _missingIconsTimer = undefined;
function _warnDuplicateIcon(iconName) {
var options = _iconSettings.__options;
var warningDelay = 2000;
var maxIconsInMessage = 10;
if (!options.disableWarnings) {
_missingIcons.push(iconName);
if (_missingIconsTimer === undefined) {
_missingIconsTimer = setTimeout(function () {
warn("Some icons were re-registered. Applications should only call registerIcons for any given " +
"icon once. Redefining what an icon is may have unintended consequences. Duplicates " +
"include: \n" +
_missingIcons.slice(0, maxIconsInMessage).join(', ') +
(_missingIcons.length > maxIconsInMessage ? " (+ ".concat(_missingIcons.length - maxIconsInMessage, " more)") : ''));
_missingIconsTimer = undefined;
_missingIcons = [];
}, warningDelay);
}
}
}
//# sourceMappingURL=icons.js.map
File diff suppressed because one or more lines are too long
+4
View File
@@ -0,0 +1,4 @@
export { buildClassMap } from './buildClassMap';
export { getIcon, registerIcons, registerIconAlias, unregisterIcons, setIconOptions } from './icons';
export { getIconClassName } from './getIconClassName';
export type { IIconRecord, IIconSubset, IIconSubsetRecord, IIconOptions } from './icons';
+4
View File
@@ -0,0 +1,4 @@
export { buildClassMap } from './buildClassMap';
export { getIcon, registerIcons, registerIconAlias, unregisterIcons, setIconOptions } from './icons';
export { getIconClassName } from './getIconClassName';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAErG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { buildClassMap } from './buildClassMap';\n\nexport { getIcon, registerIcons, registerIconAlias, unregisterIcons, setIconOptions } from './icons';\n\nexport { getIconClassName } from './getIconClassName';\nexport type { IIconRecord, IIconSubset, IIconSubsetRecord, IIconOptions } from './icons';\n"]}