UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

1 lines 2.96 kB
{"version":3,"file":"_id-generator-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/cdk/a11y/id-generator.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {APP_ID, inject, Injectable} from '@angular/core';\n\n/**\n * Keeps track of the ID count per prefix. This helps us make the IDs a bit more deterministic\n * like they were before the service was introduced. Note that ideally we wouldn't have to do\n * this, but there are some internal tests that rely on the IDs.\n */\nconst counters: Record<string, number> = {};\n\n/** Service that generates unique IDs for DOM nodes. */\n@Injectable({providedIn: 'root'})\nexport class _IdGenerator {\n private _appId = inject(APP_ID);\n private static _infix = `a${Math.floor(Math.random() * 100000).toString()}`;\n\n /**\n * Generates a unique ID with a specific prefix.\n * @param prefix Prefix to add to the ID.\n * @param randomize Add a randomized infix string.\n */\n getId(prefix: string, randomize: boolean = false): string {\n // Omit the app ID if it's the default `ng`. Since the vast majority of pages have one\n // Angular app on them, we can reduce the amount of breakages by not adding it.\n if (this._appId !== 'ng') {\n prefix += this._appId;\n }\n\n if (!counters.hasOwnProperty(prefix)) {\n counters[prefix] = 0;\n }\n\n return `${prefix}${randomize ? _IdGenerator._infix + '-' : ''}${counters[prefix]++}`;\n }\n}\n"],"names":["counters","_IdGenerator","_appId","inject","APP_ID","_infix","Math","floor","random","toString","getId","prefix","randomize","hasOwnProperty","deps","target","i0","ɵɵFactoryTarget","Injectable","ɵprov","ɵɵngDeclareInjectable","minVersion","version","ngImport","type","decorators","providedIn"],"mappings":";;;AAeA,MAAMA,QAAQ,GAA2B,EAAE;MAI9BC,YAAY,CAAA;AACfC,EAAAA,MAAM,GAAGC,MAAM,CAACC,MAAM,CAAC;AACvB,EAAA,OAAOC,MAAM,GAAG,CAAA,CAAA,EAAIC,IAAI,CAACC,KAAK,CAAC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