document.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. /**
  3. * @license
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.execCommandInsertHtml = exports.execCommand = exports.write = void 0;
  8. var html_impl_1 = require("../../internals/html_impl");
  9. /**
  10. * write safely calls {@link Document.write} on the given {@link Document} with
  11. * the given {@link SafeHtml}.
  12. */
  13. function write(doc, text) {
  14. doc.write((0, html_impl_1.unwrapHtml)(text));
  15. }
  16. exports.write = write;
  17. /**
  18. * Safely calls {@link Document.execCommand}. When command is insertHtml, a
  19. * SafeHtml must be passed in as value.
  20. */
  21. function execCommand(doc, command, value) {
  22. var commandString = String(command);
  23. var valueArgument = value;
  24. if (commandString.toLowerCase() === 'inserthtml') {
  25. valueArgument = (0, html_impl_1.unwrapHtml)(value);
  26. }
  27. return doc.execCommand(commandString, /* showUi= */ false, valueArgument);
  28. }
  29. exports.execCommand = execCommand;
  30. /**
  31. * Safely calls {@link Document.execCommand}('insertHtml').
  32. * @deprecated Use safeDocument.execCommand.
  33. */
  34. function execCommandInsertHtml(doc, html) {
  35. return doc.execCommand('insertHTML', /* showUi= */ false, (0, html_impl_1.unwrapHtml)(html));
  36. }
  37. exports.execCommandInsertHtml = execCommandInsertHtml;