blob: 6183b530346a70036a6b2a94032079b0e5d49ad8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// This file adds some simple checks to match internal Google rules.
// Internally at Google it has different a implementation.
import {BrandType} from '../types/common';
export type SafeStyleSheet = BrandType<string, '_safeHtml'>;
export function safeStyleSheet(
templateObj: TemplateStringsArray
): SafeStyleSheet {
const styleSheet = templateObj[0];
if (/[<>]/.test(styleSheet)) {
throw new Error('Forbidden characters in styleSheet string: ' + styleSheet);
}
return styleSheet as SafeStyleSheet;
}
export const safeStyleEl = {
setTextContent: (elem: HTMLStyleElement, safeStyleSheet: SafeStyleSheet) => {
elem.textContent = safeStyleSheet;
},
};
|