* Helper used by html and svg string literal functions. * @param {HTMLElement | SVGSVGElement} container * @param {readonly string[]} strings * @return {HTMLElement}
(container, strings)
| 80 | * @return {HTMLElement} |
| 81 | */ |
| 82 | function createNode(container, strings) { |
| 83 | devAssert(strings.length === 1, 'Improper html template tag usage.'); |
| 84 | devAssert( |
| 85 | Array.isArray(strings) || hasOwn(strings, 'raw'), |
| 86 | 'Invalid template strings array' |
| 87 | ); |
| 88 | |
| 89 | if (self.trustedTypes && self.trustedTypes.createPolicy) { |
| 90 | const policy = self.trustedTypes.createPolicy( |
| 91 | 'static-template#createNode', |
| 92 | { |
| 93 | createHTML: function (unused) { |
| 94 | return strings[0]; |
| 95 | }, |
| 96 | } |
| 97 | ); |
| 98 | // @ts-ignore |
| 99 | container./*OK*/ innerHTML = policy.createHTML('ignored'); |
| 100 | } else { |
| 101 | container./*OK*/ innerHTML = strings[0]; |
| 102 | } |
| 103 | |
| 104 | const el = /** @type {HTMLElement} */ (container.firstElementChild); |
| 105 | devAssert(el, 'No elements in template'); |
| 106 | devAssert(!el.nextElementSibling, 'Too many root elements in template'); |
| 107 | |
| 108 | // Clear to free memory. |
| 109 | container.removeChild(el); |
| 110 | |
| 111 | return el; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Queries an element for all elements with a "ref" attribute, removing |