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Polymer Project Authors. All rights reserved.\n * This code may only be used under the BSD style license found at\n * http://polymer.github.io/LICENSE.txt\n * The complete set of authors may be found at\n * http://polymer.github.io/AUTHORS.txt\n * The complete set of contributors may be found at\n * http://polymer.github.io/CONTRIBUTORS.txt\n * Code distributed by Google as part of the polymer project is also\n * subject to an additional IP rights grant found at\n * http://polymer.github.io/PATENTS.txt\n */\n\nimport {isPrimitive} from '../lib/parts.js';\nimport {directive, NodePart, Part} from '../lit-html.js';\n\ninterface PreviousValue {\n readonly value: unknown;\n readonly fragment: DocumentFragment;\n}\n\n// For each part, remember the value that was last rendered to the part by the\n// unsafeHTML directive, and the DocumentFragment that was last set as a value.\n// The DocumentFragment is used as a unique key to check if the last value\n// rendered to the part was with unsafeHTML. If not, we'll always re-render the\n// value passed to unsafeHTML.\nconst previousValues = new WeakMap();\n\n/**\n * Renders the result as HTML, rather than text.\n *\n * Note, this is unsafe to use with any user-provided input that hasn't been\n * sanitized or escaped, as it may lead to cross-site-scripting\n * vulnerabilities.\n */\nexport const unsafeHTML = directive((value: unknown) => (part: Part): void => {\n if (!(part instanceof NodePart)) {\n throw new Error('unsafeHTML can only be used in text bindings');\n }\n\n const previousValue = previousValues.get(part);\n\n if (previousValue !== undefined && isPrimitive(value) &&\n value === previousValue.value && part.value === previousValue.fragment) {\n return;\n }\n\n const template = document.createElement('template');\n template.innerHTML = value as string; // innerHTML casts to string internally\n const fragment = document.importNode(template.content, true);\n part.setValue(fragment);\n previousValues.set(part, {value, fragment});\n});\n"]}