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;
};
@@ -0,0 +1,35 @@
define(["require", "exports", "../MergeStyles"], function (require, exports, MergeStyles_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildClassMap = buildClassMap;
/**
* Builds a class names object from a given map.
*
* @param styles - Map of unprocessed styles.
* @returns Map of property name to class name.
*/
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 = (0, MergeStyles_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":";;;IAQA,sCAsBC;IA5BD;;;;;OAKG;IACH,SAAgB,aAAa,CAAmB,MAAS;QACvD,IAAI,OAAO,GAAkC,EAAE,CAAC;gCAEvC,SAAS;YAChB,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;gBACrC,IAAI,WAAiB,CAAC;gBAEtB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE;oBACxC,GAAG,EAAE;wBACH,IAAI,WAAS,KAAK,SAAS,EAAE,CAAC;4BAC5B,8DAA8D;4BAC9D,WAAS,GAAG,IAAA,yBAAW,EAAC,MAAM,CAAC,SAAS,CAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;wBAC/D,CAAC;wBACD,OAAO,WAAS,CAAC;oBACnB,CAAC;oBACD,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,IAAI;iBACnB,CAAC,CAAC;YACL,CAAC;;QAfH,KAAK,IAAI,SAAS,IAAI,MAAM;oBAAnB,SAAS;SAgBjB;QAED,OAAO,OAAO,CAAC;IACjB,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,29 @@
define(["require", "exports", "@fluentui/merge-styles", "./icons"], function (require, exports, merge_styles_1, icons_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIconClassName = getIconClassName;
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
*/
function getIconClassName(name) {
var className = '';
var icon = (0, icons_1.getIcon)(name);
if (icon) {
className = (0, merge_styles_1.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":";;;IAcA,4CAeC;IAzBD,IAAM,iBAAiB,GAAW;QAChC,OAAO,EAAE,cAAc;KACxB,CAAC;IAEF;;;;;OAKG;IACH,SAAgB,gBAAgB,CAAC,IAAY;QAC3C,IAAI,SAAS,GAAG,EAAE,CAAC;QACnB,IAAM,IAAI,GAAG,IAAA,eAAO,EAAC,IAAI,CAAC,CAAC;QAE3B,IAAI,IAAI,EAAE,CAAC;YACT,SAAS,GAAG,IAAA,0BAAW,EAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,iBAAiB,EAAE;gBAChE,SAAS,EAAE;oBACT,UAAU,EAAE;wBACV,OAAO,EAAE,YAAI,IAAI,CAAC,IAAI,OAAG;qBAC1B;iBACF;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,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;
+171
View File
@@ -0,0 +1,171 @@
define(["require", "exports", "tslib", "@fluentui/utilities", "@fluentui/merge-styles"], function (require, exports, tslib_1, utilities_1, merge_styles_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerIcons = registerIcons;
exports.unregisterIcons = unregisterIcons;
exports.registerIconAlias = registerIconAlias;
exports.getIcon = getIcon;
exports.setIconOptions = setIconOptions;
var ICON_SETTING_NAME = 'icons';
var _iconSettings = utilities_1.GlobalSettings.getValue(ICON_SETTING_NAME, {
__options: {
disableWarnings: false,
warnOnMissingIcons: true,
},
__remapped: {},
});
// Reset icon registration on stylesheet resets.
var stylesheet = merge_styles_1.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.
*/
function registerIcons(iconSubset, options) {
var subset = tslib_1.__assign(tslib_1.__assign({}, iconSubset), { isRegistered: false, className: undefined });
var icons = iconSubset.icons;
// Grab options, optionally mix user provided ones on top.
options = options ? tslib_1.__assign(tslib_1.__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.
*/
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) {
(0, utilities_1.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.
*/
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.
*/
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) {
(0, merge_styles_1.fontFace)(subset.fontFace);
subset.isRegistered = true;
}
if (!subset.className) {
subset.className = (0, merge_styles_1.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) {
(0, utilities_1.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
*/
function setIconOptions(options) {
_iconSettings.__options = tslib_1.__assign(tslib_1.__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 () {
(0, utilities_1.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';
+13
View File
@@ -0,0 +1,13 @@
define(["require", "exports", "./buildClassMap", "./icons", "./getIconClassName"], function (require, exports, buildClassMap_1, icons_1, getIconClassName_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIconClassName = exports.setIconOptions = exports.unregisterIcons = exports.registerIconAlias = exports.registerIcons = exports.getIcon = exports.buildClassMap = void 0;
Object.defineProperty(exports, "buildClassMap", { enumerable: true, get: function () { return buildClassMap_1.buildClassMap; } });
Object.defineProperty(exports, "getIcon", { enumerable: true, get: function () { return icons_1.getIcon; } });
Object.defineProperty(exports, "registerIcons", { enumerable: true, get: function () { return icons_1.registerIcons; } });
Object.defineProperty(exports, "registerIconAlias", { enumerable: true, get: function () { return icons_1.registerIconAlias; } });
Object.defineProperty(exports, "unregisterIcons", { enumerable: true, get: function () { return icons_1.unregisterIcons; } });
Object.defineProperty(exports, "setIconOptions", { enumerable: true, get: function () { return icons_1.setIconOptions; } });
Object.defineProperty(exports, "getIconClassName", { enumerable: true, get: function () { return getIconClassName_1.getIconClassName; } });
});
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utilities/index.ts"],"names":[],"mappings":";;;;IAAS,8GAAA,aAAa,OAAA;IAEb,gGAAA,OAAO,OAAA;IAAE,sGAAA,aAAa,OAAA;IAAE,0GAAA,iBAAiB,OAAA;IAAE,wGAAA,eAAe,OAAA;IAAE,uGAAA,cAAc,OAAA;IAE1E,oHAAA,gBAAgB,OAAA","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"]}