43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.resetIds = exports.getId = void 0;
|
||
|
var getWindow_1 = require("./dom/getWindow");
|
||
|
var merge_styles_1 = require("@fluentui/merge-styles");
|
||
|
// 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
|