@@ -306,11 +306,15 @@ export function children(element: Element) {
306
306
return Array . from ( element . childNodes ) ;
307
307
}
308
308
309
- function claim_node < R extends ChildNodeEx > ( nodes : ChildNodeArray , predicate : ( node : ChildNodeEx ) => node is R , processNode : ( node : ChildNodeEx ) => void , createNode : ( ) => R , dontUpdateLastIndex : boolean = false ) {
310
- // Try to find nodes in an order such that we lengthen the longest increasing subsequence
309
+ function init_claim_info ( nodes : ChildNodeArray ) {
311
310
if ( nodes . claim_info === undefined ) {
312
311
nodes . claim_info = { last_index : 0 , total_claimed : 0 } ;
313
312
}
313
+ }
314
+
315
+ function claim_node < R extends ChildNodeEx > ( nodes : ChildNodeArray , predicate : ( node : ChildNodeEx ) => node is R , processNode : ( node : ChildNodeEx ) => void , createNode : ( ) => R , dontUpdateLastIndex : boolean = false ) {
316
+ // Try to find nodes in an order such that we lengthen the longest increasing subsequence
317
+ init_claim_info ( nodes ) ;
314
318
315
319
const resultNode = ( ( ) => {
316
320
// We first try to find an element after the previous one
@@ -408,10 +412,17 @@ export function claim_html_tag(nodes) {
408
412
if ( start_index === end_index ) {
409
413
return new HtmlTag ( ) ;
410
414
}
415
+
416
+ init_claim_info ( nodes ) ;
411
417
const html_tag_nodes = nodes . splice ( start_index , end_index + 1 ) ;
412
418
detach ( html_tag_nodes [ 0 ] ) ;
413
419
detach ( html_tag_nodes [ html_tag_nodes . length - 1 ] ) ;
414
- return new HtmlTag ( html_tag_nodes . slice ( 1 , html_tag_nodes . length - 1 ) ) ;
420
+ const claimed_nodes = html_tag_nodes . slice ( 1 , html_tag_nodes . length - 1 ) ;
421
+ for ( const n of claimed_nodes ) {
422
+ n . claim_order = nodes . claim_info . total_claimed ;
423
+ nodes . claim_info . total_claimed += 1 ;
424
+ }
425
+ return new HtmlTag ( claimed_nodes ) ;
415
426
}
416
427
417
428
export function set_data ( text , data ) {
@@ -537,7 +548,7 @@ export function custom_event<T=any>(type: string, detail?: T) {
537
548
}
538
549
539
550
export function query_selector_all ( selector : string , parent : HTMLElement = document . body ) {
540
- return Array . from ( parent . querySelectorAll ( selector ) ) ;
551
+ return Array . from ( parent . querySelectorAll ( selector ) ) as ChildNodeArray ;
541
552
}
542
553
543
554
export class HtmlTag {
0 commit comments