id-generator-Dw_9dSDu.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as i0 from '@angular/core';
  2. import { inject, APP_ID, Injectable } from '@angular/core';
  3. /**
  4. * Keeps track of the ID count per prefix. This helps us make the IDs a bit more deterministic
  5. * like they were before the service was introduced. Note that ideally we wouldn't have to do
  6. * this, but there are some internal tests that rely on the IDs.
  7. */
  8. const counters = {};
  9. /** Service that generates unique IDs for DOM nodes. */
  10. class _IdGenerator {
  11. _appId = inject(APP_ID);
  12. /**
  13. * Generates a unique ID with a specific prefix.
  14. * @param prefix Prefix to add to the ID.
  15. */
  16. getId(prefix) {
  17. // Omit the app ID if it's the default `ng`. Since the vast majority of pages have one
  18. // Angular app on them, we can reduce the amount of breakages by not adding it.
  19. if (this._appId !== 'ng') {
  20. prefix += this._appId;
  21. }
  22. if (!counters.hasOwnProperty(prefix)) {
  23. counters[prefix] = 0;
  24. }
  25. return `${prefix}${counters[prefix]++}`;
  26. }
  27. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _IdGenerator, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  28. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _IdGenerator, providedIn: 'root' });
  29. }
  30. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _IdGenerator, decorators: [{
  31. type: Injectable,
  32. args: [{ providedIn: 'root' }]
  33. }] });
  34. export { _IdGenerator as _ };
  35. //# sourceMappingURL=id-generator-Dw_9dSDu.mjs.map