| 97 | // Static content here can only come from compiled templates. |
| 98 | // As long as the user only uses trusted templates, this is safe. |
| 99 | insertStaticContent(content, parent, anchor, namespace, start, end) { |
| 100 | // <parent> before | first ... last | anchor </parent> |
| 101 | const before = anchor ? anchor.previousSibling : parent.lastChild |
| 102 | // #5308 can only take cached path if: |
| 103 | // - has a single root node |
| 104 | // - nextSibling info is still available |
| 105 | if (start && (start === end || start.nextSibling)) { |
| 106 | // cached |
| 107 | while (true) { |
| 108 | parent.insertBefore(start!.cloneNode(true), anchor) |
| 109 | if (start === end || !(start = start!.nextSibling)) break |
| 110 | } |
| 111 | } else { |
| 112 | // fresh insert |
| 113 | templateContainer.innerHTML = unsafeToTrustedHTML( |
| 114 | namespace === 'svg' |
| 115 | ? `<svg>${content}</svg>` |
| 116 | : namespace === 'mathml' |
| 117 | ? `<math>${content}</math>` |
| 118 | : content, |
| 119 | ) as string |
| 120 | |
| 121 | const template = templateContainer.content |
| 122 | if (namespace === 'svg' || namespace === 'mathml') { |
| 123 | // remove outer svg/math wrapper |
| 124 | const wrapper = template.firstChild! |
| 125 | while (wrapper.firstChild) { |
| 126 | template.appendChild(wrapper.firstChild) |
| 127 | } |
| 128 | template.removeChild(wrapper) |
| 129 | } |
| 130 | parent.insertBefore(template, anchor) |
| 131 | } |
| 132 | return [ |
| 133 | // first |
| 134 | before ? before.nextSibling! : parent.firstChild!, |
| 135 | // last |
| 136 | anchor ? anchor.previousSibling! : parent.lastChild!, |
| 137 | ] |
| 138 | }, |
| 139 | } |