Outlook_Addin_LLM/node_modules/@fluentui/utilities/lib-amd/getId.js

43 lines
1.6 KiB
JavaScript

define(["require", "exports", "./dom/getWindow", "@fluentui/merge-styles"], function (require, exports, getWindow_1, merge_styles_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetIds = exports.getId = void 0;
// Initialize global window id.
var CURRENT_ID_PROPERTY = '__currentId__';
var DEFAULT_ID_STRING = 'id__';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var _global = (0, getWindow_1.getWindow)() || {};
if (_global[CURRENT_ID_PROPERTY] === undefined) {
_global[CURRENT_ID_PROPERTY] = 0;
}
var _initializedStylesheetResets = false;
/**
* Generates a unique id in the global scope (this spans across duplicate copies of the same library.)
*
* @public
*/
function getId(prefix) {
if (!_initializedStylesheetResets) {
// Configure ids to reset on stylesheet resets.
var stylesheet = merge_styles_1.Stylesheet.getInstance();
if (stylesheet && stylesheet.onReset) {
stylesheet.onReset(resetIds);
}
_initializedStylesheetResets = true;
}
var index = _global[CURRENT_ID_PROPERTY]++;
return (prefix === undefined ? DEFAULT_ID_STRING : prefix) + index;
}
exports.getId = getId;
/**
* Resets id counter to an (optional) number.
*
* @public
*/
function resetIds(counter) {
if (counter === void 0) { counter = 0; }
_global[CURRENT_ID_PROPERTY] = counter;
}
exports.resetIds = resetIds;
});
//# sourceMappingURL=getId.js.map