@ -87,18 +87,17 @@ export function svg_template_with_script(svg, return_fragment) {
* @ param { ( ) => Node } [ template _element _fn ]
* @ param { ( ) => Node } [ template _element _fn ]
* @ returns { Element | DocumentFragment | Node [ ] }
* @ returns { Element | DocumentFragment | Node [ ] }
* /
* /
/*#__NO_SIDE_EFFECTS__*/
function open _template ( is _fragment , use _clone _node , anchor , template _element _fn ) {
function open _template ( is _fragment , use _clone _node , anchor , template _element _fn ) {
if ( hydrating ) {
if ( hydrating ) {
if ( anchor !== null ) {
if ( anchor !== null ) {
// TODO why is this sometimes null and sometimes not? needs clear documentation
hydrate _block _anchor ( anchor ) ;
hydrate _block _anchor ( anchor ) ;
}
}
// In ssr+hydration optimization mode, we might remove the template_element,
// so we need to is_fragment flag to properly handle hydrated content accordingly.
return is _fragment ? hydrate _nodes : /** @type {Element} */ ( hydrate _nodes [ 0 ] ) ;
const nodes = hydrate _nodes ;
if ( nodes !== null ) {
return is _fragment ? nodes : /** @type {Element} */ ( nodes [ 0 ] ) ;
}
}
}
return use _clone _node
return use _clone _node
? clone _node ( /** @type {() => Element} */ ( template _element _fn ) ( ) , true )
? clone _node ( /** @type {() => Element} */ ( template _element _fn ) ( ) , true )
: document . importNode ( /** @type {() => Element} */ ( template _element _fn ) ( ) , true ) ;
: document . importNode ( /** @type {() => Element} */ ( template _element _fn ) ( ) , true ) ;
@ -108,11 +107,10 @@ function open_template(is_fragment, use_clone_node, anchor, template_element_fn)
* @ param { null | Text | Comment | Element } anchor
* @ 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 }
* /
* /
/*#__NO_SIDE_EFFECTS__*/
export function open ( anchor , template _element _fn , use _clone _node = true ) {
export function open ( anchor , template _element _fn , use _clone _node = true ) {
return open _template ( false , use _clone _node , anchor , template _element _fn ) ;
return /** @type {Element} */ ( open _template ( false , use _clone _node , anchor , template _element _fn ) ) ;
}
}
/ * *
/ * *
@ -121,7 +119,6 @@ export function open(anchor, template_element_fn, use_clone_node = true) {
* @ param { boolean } [ use _clone _node ]
* @ param { boolean } [ use _clone _node ]
* @ returns { Element | DocumentFragment | Node [ ] }
* @ returns { Element | DocumentFragment | Node [ ] }
* /
* /
/*#__NO_SIDE_EFFECTS__*/
export function open _frag ( anchor , template _element _fn , use _clone _node = true ) {
export function open _frag ( anchor , 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 , anchor , template _element _fn ) ;
}
}
@ -175,21 +172,25 @@ export function comment(anchor) {
/ * *
/ * *
* Assign the created ( or in hydration mode , traversed ) dom elements to the current block
* Assign the created ( or in hydration mode , traversed ) dom elements to the current block
* and insert the elements into the dom ( in client mode ) .
* and insert the elements into the dom ( in client mode ) .
* @ param { Element | Text } dom
* @ param { import ( '#client' ) . Dom } dom
* @ param { boolean } is _fragment
* @ param { boolean } is _fragment
* @ param { null | Text | Comment | Element } anchor
* @ param { null | Text | Comment | Element } anchor
* @ returns { import ( '#client' ) . Dom }
* @ returns { import ( '#client' ) . Dom }
* /
* /
function close _template ( dom , is _fragment , anchor ) {
function close _template ( dom , is _fragment , anchor ) {
/** @type {import('#client').Dom} */
var current = dom ;
var current = is _fragment
? is _array ( dom )
if ( ! hydrating ) {
? dom
if ( is _fragment ) {
: /** @type {import('#client').TemplateNode[]} */ ( Array . from ( dom . childNodes ) )
// if hydrating, `dom` is already an array of nodes, but if not then
: dom ;
// we need to create an array to store it on the current effect
current = /** @type {import('#client').Dom} */ ( [ ... /** @type {Node} */ ( dom ) . childNodes ] ) ;
if ( ! hydrating && anchor !== null ) {
}
insert ( current , anchor ) ;
if ( anchor !== null ) {
// TODO as with `open_template — why is this sometimes null and sometimes not?
insert ( current , anchor ) ;
}
}
}
/** @type {import('#client').Effect} */ ( current _effect ) . dom = current ;
/** @type {import('#client').Effect} */ ( current _effect ) . dom = current ;