UNPKG

1.88 kBJavaScriptView Raw
1"use strict";
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 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.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 */
24const 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 */
30const parseFromString = (html) => {
31 return new win_js_1.win.DOMParser().parseFromString(html, 'text/html');
32};
33exports.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 */
39const setInnerHtml = (element, html) => {
40 element.innerHTML = html;
41};
42exports.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 */
47const applyWrapStyle = (element) => {
48 element.style.wordBreak = 'keep-all';
49 element.style.overflowWrap = 'anywhere';
50};
51exports.applyWrapStyle = applyWrapStyle;
52//# sourceMappingURL=dom.js.map
\No newline at end of file