MCPcopy Create free account
hub / github.com/angular/angular / CssVarNamespacer

Class CssVarNamespacer

packages/platform-browser/src/dom/css_var_namespacer.ts:21–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 */
20@Service()
21export class CssVarNamespacer {
22 private readonly namespacePrefix = inject(CSS_VAR_NAMESPACE, {optional: true}) ?? '';
23
24 /**
25 * Prepends the namespace prefix to a CSS variable name.
26 *
27 * @param name The CSS variable name to namespace, including the leading `--`.
28 * @returns The namespaced CSS variable name, including the leading `--`. Returns the input
29 * unchanged if no namespace is configured.
30 */
31 namespace(name: string): string {
32 // Validate that the whole `--foo` variable is passed in.
33 if (typeof ngDevMode === 'undefined' || ngDevMode) {
34 if (!name.startsWith('--')) {
35 throw new Error(
36 `CSS variable names passed to \`CssVarNamespacer\` must start with '--', got: '${name}'`,
37 );
38 }
39 }
40
41 // We want to support libraries which might be used by applications which do and don't
42 // namespace variables. Therefore the library always needs to use `CssVarNamespacer`, even
43 // though the application may not actually be namespacing anything.
44 if (!this.namespacePrefix) return name;
45
46 return `--${this.namespacePrefix}${name.substring('--'.length)}`;
47 }
48}

Callers

nothing calls this directly

Calls 1

injectFunction · 0.90

Tested by

no test coverage detected