* @param {TemplateStructure[]} structure * @param {typeof NAMESPACE_SVG | typeof NAMESPACE_MATHML | undefined} [ns]
(structure, ns)
| 169 | * @param {typeof NAMESPACE_SVG | typeof NAMESPACE_MATHML | undefined} [ns] |
| 170 | */ |
| 171 | function fragment_from_tree(structure, ns) { |
| 172 | var fragment = create_fragment(); |
| 173 | |
| 174 | for (var item of structure) { |
| 175 | if (typeof item === 'string') { |
| 176 | fragment.append(create_text(item)); |
| 177 | continue; |
| 178 | } |
| 179 | |
| 180 | // if `preserveComments === true`, comments are represented as `['// <data>']` |
| 181 | if (item === undefined || item[0][0] === '/') { |
| 182 | fragment.append(create_comment(item ? item[0].slice(3) : '')); |
| 183 | continue; |
| 184 | } |
| 185 | |
| 186 | const [name, attributes, ...children] = item; |
| 187 | |
| 188 | const namespace = name === 'svg' ? NAMESPACE_SVG : name === 'math' ? NAMESPACE_MATHML : ns; |
| 189 | |
| 190 | var element = create_element(name, namespace, attributes?.is); |
| 191 | |
| 192 | for (var key in attributes) { |
| 193 | set_attribute(element, key, attributes[key]); |
| 194 | } |
| 195 | |
| 196 | if (children.length > 0) { |
| 197 | var target = |
| 198 | element.nodeName === TEMPLATE_TAG |
| 199 | ? /** @type {HTMLTemplateElement} */ (element).content |
| 200 | : element; |
| 201 | |
| 202 | target.append( |
| 203 | fragment_from_tree(children, element.nodeName === 'foreignObject' ? undefined : namespace) |
| 204 | ); |
| 205 | } |
| 206 | |
| 207 | fragment.append(element); |
| 208 | } |
| 209 | |
| 210 | return fragment; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @param {TemplateStructure[]} structure |
no test coverage detected