|
|
@ -1,4 +1,4 @@
|
|
|
|
import { hydrate_nodes, hydrate_block_anchor, hydrating } from './hydration.js';
|
|
|
|
import { hydrate_nodes, hydrating } from './hydration.js';
|
|
|
|
import { child, clone_node, empty } from './operations.js';
|
|
|
|
import { child, clone_node, empty } from './operations.js';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
create_fragment_from_html,
|
|
|
|
create_fragment_from_html,
|
|
|
@ -83,18 +83,12 @@ export function svg_template_with_script(svg, return_fragment) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {boolean} is_fragment
|
|
|
|
* @param {boolean} is_fragment
|
|
|
|
* @param {boolean} use_clone_node
|
|
|
|
* @param {boolean} use_clone_node
|
|
|
|
* @param {null | Text | Comment | Element} anchor
|
|
|
|
|
|
|
|
* @param {() => Node} [template_element_fn]
|
|
|
|
* @param {() => Node} [template_element_fn]
|
|
|
|
* @returns {Element | DocumentFragment | Node[]}
|
|
|
|
* @returns {Element | DocumentFragment | Node[]}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
|
|
function open_template(is_fragment, use_clone_node, anchor, template_element_fn) {
|
|
|
|
function open_template(is_fragment, use_clone_node, template_element_fn) {
|
|
|
|
if (hydrating) {
|
|
|
|
if (hydrating) {
|
|
|
|
if (anchor !== null) {
|
|
|
|
|
|
|
|
// TODO why is this sometimes null and sometimes not? needs clear documentation
|
|
|
|
|
|
|
|
hydrate_block_anchor(anchor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return is_fragment ? hydrate_nodes : /** @type {Element} */ (hydrate_nodes[0]);
|
|
|
|
return is_fragment ? hydrate_nodes : /** @type {Element} */ (hydrate_nodes[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -104,23 +98,21 @@ function open_template(is_fragment, use_clone_node, anchor, template_element_fn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {null | Text | Comment | Element} anchor
|
|
|
|
|
|
|
|
* @param {() => Node} template_element_fn
|
|
|
|
* @param {() => Node} template_element_fn
|
|
|
|
* @param {boolean} [use_clone_node]
|
|
|
|
* @param {boolean} [use_clone_node]
|
|
|
|
* @returns {Element}
|
|
|
|
* @returns {Element}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function open(anchor, template_element_fn, use_clone_node = true) {
|
|
|
|
export function open(template_element_fn, use_clone_node = true) {
|
|
|
|
return /** @type {Element} */ (open_template(false, use_clone_node, anchor, template_element_fn));
|
|
|
|
return /** @type {Element} */ (open_template(false, use_clone_node, template_element_fn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {null | Text | Comment | Element} anchor
|
|
|
|
|
|
|
|
* @param {() => Node} template_element_fn
|
|
|
|
* @param {() => Node} template_element_fn
|
|
|
|
* @param {boolean} [use_clone_node]
|
|
|
|
* @param {boolean} [use_clone_node]
|
|
|
|
* @returns {Element | DocumentFragment | Node[]}
|
|
|
|
* @returns {Element | DocumentFragment | Node[]}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function open_frag(anchor, template_element_fn, use_clone_node = true) {
|
|
|
|
export function open_frag(template_element_fn, use_clone_node = true) {
|
|
|
|
return open_template(true, use_clone_node, anchor, template_element_fn);
|
|
|
|
return open_template(true, use_clone_node, template_element_fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const space_template = template(' ', false);
|
|
|
|
const space_template = template(' ', false);
|
|
|
@ -132,7 +124,7 @@ const comment_template = template('<!>', true);
|
|
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
|
|
export function space_frag(anchor) {
|
|
|
|
export function space_frag(anchor) {
|
|
|
|
/** @type {Node | null} */
|
|
|
|
/** @type {Node | null} */
|
|
|
|
var node = /** @type {any} */ (open(anchor, space_template));
|
|
|
|
var node = /** @type {any} */ (open(space_template));
|
|
|
|
// if an {expression} is empty during SSR, there might be no
|
|
|
|
// if an {expression} is empty during SSR, there might be no
|
|
|
|
// text node to hydrate (or an anchor comment is falsely detected instead)
|
|
|
|
// text node to hydrate (or an anchor comment is falsely detected instead)
|
|
|
|
// — we must therefore create one
|
|
|
|
// — we must therefore create one
|
|
|
@ -161,12 +153,9 @@ export function space(anchor) {
|
|
|
|
return anchor;
|
|
|
|
return anchor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {null | Text | Comment | Element} anchor
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
|
|
export function comment(anchor) {
|
|
|
|
export function comment() {
|
|
|
|
return open_frag(anchor, comment_template);
|
|
|
|
return open_frag(comment_template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|