|
|
@ -78,65 +78,50 @@ export function template(content, flags) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @typedef {{e: string, is?: string, p: Record<string, string>, c: Array<TemplateStructure>} | null | string | [string]} TemplateStructure
|
|
|
|
* @typedef {{e: string, is?: string, p: Record<string, string>, c: Array<TemplateStructure>} | undefined | string | [string]} TemplateStructure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {Array<TemplateStructure>} structure
|
|
|
|
* @param {Array<TemplateStructure>} structure
|
|
|
|
* @param {'svg' | 'math'} [ns]
|
|
|
|
* @param {NAMESPACE_SVG | NAMESPACE_MATHML | undefined} [ns]
|
|
|
|
* @param {Array<string | undefined>} [namespace_stack]
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function structure_to_fragment(structure, ns, namespace_stack = [], foreign_object_count = 0) {
|
|
|
|
function structure_to_fragment(structure, ns) {
|
|
|
|
var fragment = create_fragment();
|
|
|
|
var fragment = create_fragment();
|
|
|
|
for (var i = 0; i < structure.length; i += 1) {
|
|
|
|
|
|
|
|
var item = structure[i];
|
|
|
|
for (var item of structure) {
|
|
|
|
if (item == null || Array.isArray(item)) {
|
|
|
|
if (item === undefined || Array.isArray(item)) {
|
|
|
|
const data = item ? item[0] : '';
|
|
|
|
fragment.append(create_comment(item ? item[0] : ''));
|
|
|
|
fragment.append(create_comment(data));
|
|
|
|
continue;
|
|
|
|
} else if (typeof item === 'string') {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof item === 'string') {
|
|
|
|
fragment.append(create_text(item));
|
|
|
|
fragment.append(create_text(item));
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let namespace =
|
|
|
|
|
|
|
|
foreign_object_count > 0
|
|
|
|
|
|
|
|
? undefined
|
|
|
|
|
|
|
|
: namespace_stack[namespace_stack.length - 1] ??
|
|
|
|
|
|
|
|
(ns
|
|
|
|
|
|
|
|
? ns === 'svg'
|
|
|
|
|
|
|
|
? NAMESPACE_SVG
|
|
|
|
|
|
|
|
: ns === 'math'
|
|
|
|
|
|
|
|
? NAMESPACE_MATHML
|
|
|
|
|
|
|
|
: undefined
|
|
|
|
|
|
|
|
: item.e === 'svg'
|
|
|
|
|
|
|
|
? NAMESPACE_SVG
|
|
|
|
|
|
|
|
: item.e === 'math'
|
|
|
|
|
|
|
|
? NAMESPACE_MATHML
|
|
|
|
|
|
|
|
: undefined);
|
|
|
|
|
|
|
|
if (namespace !== namespace_stack[namespace_stack.length - 1]) {
|
|
|
|
|
|
|
|
namespace_stack.push(namespace);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {NAMESPACE_SVG | NAMESPACE_MATHML | undefined} */
|
|
|
|
|
|
|
|
let namespace = item.e === 'svg' ? NAMESPACE_SVG : item.e === 'math' ? NAMESPACE_MATHML : ns;
|
|
|
|
|
|
|
|
|
|
|
|
var element = create_element(item.e, namespace, item.is);
|
|
|
|
var element = create_element(item.e, namespace, item.is);
|
|
|
|
|
|
|
|
|
|
|
|
for (var key in item.p) {
|
|
|
|
for (var key in item.p) {
|
|
|
|
set_attribute(element, key, item.p[key]);
|
|
|
|
set_attribute(element, key, item.p[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.c) {
|
|
|
|
if (item.c) {
|
|
|
|
(element.tagName === 'TEMPLATE'
|
|
|
|
var target =
|
|
|
|
|
|
|
|
element.tagName === 'TEMPLATE'
|
|
|
|
? /** @type {HTMLTemplateElement} */ (element).content
|
|
|
|
? /** @type {HTMLTemplateElement} */ (element).content
|
|
|
|
: element
|
|
|
|
: element;
|
|
|
|
).append(
|
|
|
|
|
|
|
|
...structure_to_fragment(
|
|
|
|
target.append(
|
|
|
|
item.c,
|
|
|
|
structure_to_fragment(item.c, element.tagName === 'foreignObject' ? undefined : namespace)
|
|
|
|
ns,
|
|
|
|
|
|
|
|
namespace_stack,
|
|
|
|
|
|
|
|
element.tagName === 'foreignObject' ? foreign_object_count + 1 : foreign_object_count
|
|
|
|
|
|
|
|
).childNodes
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace_stack.pop();
|
|
|
|
|
|
|
|
fragment.append(element);
|
|
|
|
fragment.append(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fragment;
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -277,7 +262,10 @@ export function ns_template_fn(structure, flags, ns = 'svg') {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
if (!node) {
|
|
|
|
var fragment = structure_to_fragment(structure, ns);
|
|
|
|
var fragment = structure_to_fragment(
|
|
|
|
|
|
|
|
structure,
|
|
|
|
|
|
|
|
ns === 'svg' ? NAMESPACE_SVG : NAMESPACE_MATHML
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (is_fragment) {
|
|
|
|
if (is_fragment) {
|
|
|
|
node = document.createDocumentFragment();
|
|
|
|
node = document.createDocumentFragment();
|
|
|
|