UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

1 lines 3.14 kB
{"version":3,"file":"private.mjs","sources":["../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/src/cdk/private/trusted-types.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\n// A module to facilitate use of a Trusted Types policy internally within\n// Angular Material. It lazily constructs the Trusted Types policy, providing\n// helper utilities for promoting strings to Trusted Types. When Trusted Types\n// are not available, strings are used as a fallback.\n// All use of this module is security-sensitive and should go through security review.\n\nexport interface TrustedHTML {\n __brand__: 'TrustedHTML';\n}\n\ninterface TrustedTypePolicyFactory {\n createPolicy(\n policyName: string,\n policyOptions: {\n createHTML?: (input: string) => string;\n },\n ): TrustedTypePolicy;\n}\n\ninterface TrustedTypePolicy {\n createHTML(input: string): TrustedHTML;\n}\n\n/**\n * The Trusted Types policy, or null if Trusted Types are not\n * enabled/supported, or undefined if the policy has not been created yet.\n */\nlet policy: TrustedTypePolicy | null | undefined;\n\n/**\n * Returns the Trusted Types policy, or null if Trusted Types are not\n * enabled/supported. The first call to this function will create the policy.\n */\nfunction getPolicy(): TrustedTypePolicy | null {\n if (policy === undefined) {\n policy = null;\n if (typeof window !== 'undefined') {\n const ttWindow = window as unknown as {trustedTypes?: TrustedTypePolicyFactory};\n if (ttWindow.trustedTypes !== undefined) {\n policy = ttWindow.trustedTypes.createPolicy('angular#components', {\n createHTML: (s: string) => s,\n });\n }\n }\n }\n return policy;\n}\n\n/**\n * Unsafely promote a string to a TrustedHTML, falling back to strings when\n * Trusted Types are not available.\n *\n * Important!!! This is a security-sensitive function; any use of this function\n * must go through security review. In particular, it must be assured that the\n * provided string will never cause an XSS vulnerability if used in a context\n * that will be interpreted as HTML by a browser, e.g. when assigning to\n * element.innerHTML.\n */\nexport function trustedHTMLFromString(html: string): TrustedHTML {\n return getPolicy()?.createHTML(html) || (html as unknown as TrustedHTML);\n}\n"],"names":["policy","getPolicy","undefined","window","ttWindow","trustedTypes","createPolicy","createHTML","s","trustedHTMLFromString","html"],"mappings":";;;;AAmCA,IAAIA,MAA4C;AAMhD,SAASC,SAASA,GAAA;EAChB,IAAID,MAAM,KAAKE,SAAS,EAAE;AACxBF,IAAAA,MAAM,GAAG,IAAI;AACb,IAAA,IAAI,OAAOG,MAAM,KAAK,WAAW,EAAE;MACjC,MAAMC,QAAQ,GAAGD,MAA8D;AAC/E,MAAA,IAAIC,QAAQ,CAACC,YAAY,KAAKH,SAAS,EAAE;QACvCF,MAAM,GAAGI,QAAQ,CAACC,YAAY,CAACC,YAAY,CAAC,oBAAoB,EAAE;UAChEC,UAAU,EAAGC,CAAS,IAAKA;AAC5B,SAAA,CAAC;AACJ;AACF;AACF;AACA,EAAA,OAAOR,MAAM;AACf;AAYM,SAAUS,qBAAqBA,CAACC,IAAY,EAAA;EAChD,OAAOT,SAAS,EAAE,EAAEM,UAAU,CAACG,IAAI,CAAC,IAAKA,IAA+B;AAC1E;;;;"}