Files
starface-outlook-sync-addin/node_modules/@fluentui/utilities/lib-commonjs/getId.js
T
Stefan Hacker 37ad745546 first commit
2026-04-03 09:38:48 +02:00

42 lines
1.4 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getId = getId;
exports.resetIds = resetIds;
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;
}
/**
* Resets id counter to an (optional) number.
*
* @public
*/
function resetIds(counter) {
if (counter === void 0) { counter = 0; }
_global[CURRENT_ID_PROPERTY] = counter;
}
//# sourceMappingURL=getId.js.map