1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright 2021 Google LLC
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * https://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.applyWrapStyle = exports.setInnerHtml = exports.parseFromString = void 0;
|
19 | /**
|
20 | * This file is a collection of risky functions that interact with elements.
|
21 | * BudouX does not apply any HTML sanitization by default, but this is the place
|
22 | * to install a sanitizer if needed.
|
23 | */
|
24 | const win_js_1 = require("./win.js");
|
25 | /**
|
26 | * Parses an html string and returns a parsed html document.
|
27 | * @param html An HTML string.
|
28 | * @return A Document.
|
29 | */
|
30 | const parseFromString = (html) => {
|
31 | return new win_js_1.win.DOMParser().parseFromString(html, 'text/html');
|
32 | };
|
33 | exports.parseFromString = parseFromString;
|
34 | /**
|
35 | * Sets an innerHTML on a given Element or ShadowRoot.
|
36 | * @param element An Element or ShadowRoot.
|
37 | * @param html An HTML string to set.
|
38 | */
|
39 | const setInnerHtml = (element, html) => {
|
40 | element.innerHTML = html;
|
41 | };
|
42 | exports.setInnerHtml = setInnerHtml;
|
43 | /**
|
44 | * Applies wrapping styles to make linebreak controls work in children.
|
45 | * @param element A parent element to apply the styles.
|
46 | */
|
47 | const applyWrapStyle = (element) => {
|
48 | element.style.wordBreak = 'keep-all';
|
49 | element.style.overflowWrap = 'anywhere';
|
50 | };
|
51 | exports.applyWrapStyle = applyWrapStyle;
|
52 | //# sourceMappingURL=dom.js.map |
\ | No newline at end of file |