@@ -399,12 +399,21 @@ export default class InlineComponentWrapper extends Wrapper {
399
399
return b `${ name } .$on("${ handler . name } ", ${ snippet } );` ;
400
400
} ) ;
401
401
402
+ const mount_target = has_css_custom_properties ? css_custom_properties_wrapper : ( parent_node || '#target' ) ;
403
+ const mount_anchor = has_css_custom_properties ? 'null' : ( parent_node ? 'null' : '#anchor' ) ;
404
+ const to_claim = parent_nodes && this . renderer . options . hydratable ;
405
+ let claim_nodes = parent_nodes ;
406
+
402
407
if ( this . node . name === 'svelte:component' ) {
403
408
const switch_value = block . get_unique_name ( 'switch_value' ) ;
404
409
const switch_props = block . get_unique_name ( 'switch_props' ) ;
405
410
406
411
const snippet = this . node . expression . manipulate ( block ) ;
407
412
413
+ if ( has_css_custom_properties ) {
414
+ this . set_css_custom_properties ( block , css_custom_properties_wrapper ) ;
415
+ }
416
+
408
417
block . chunks . init . push ( b `
409
418
var ${ switch_value } = ${ snippet } ;
410
419
@@ -427,39 +436,43 @@ export default class InlineComponentWrapper extends Wrapper {
427
436
b `if (${ name } ) @create_component(${ name } .$$.fragment);`
428
437
) ;
429
438
430
- if ( parent_nodes && this . renderer . options . hydratable ) {
431
- block . chunks . claim . push (
432
- b `if (${ name } ) @claim_component(${ name } .$$.fragment, ${ parent_nodes } );`
433
- ) ;
434
- }
435
-
436
- block . chunks . mount . push ( b `
437
- if (${ name } ) {
438
- @mount_component(${ name } , ${ parent_node || '#target' } , ${ parent_node ? 'null' : '#anchor' } );
439
- }
440
- ` ) ;
439
+ if ( css_custom_properties_wrapper ) this . create_css_custom_properties_wrapper_mount_chunk ( block , parent_node , css_custom_properties_wrapper ) ;
440
+ block . chunks . mount . push ( b `if (${ name } ) @mount_component(${ name } , ${ mount_target } , ${ mount_anchor } );` ) ;
441
441
442
- const anchor = this . get_or_create_anchor ( block , parent_node , parent_nodes ) ;
443
- const update_mount_node = this . get_update_mount_node ( anchor ) ;
442
+ if ( to_claim ) {
443
+ if ( css_custom_properties_wrapper ) claim_nodes = this . create_css_custom_properties_wrapper_claim_chunk ( block , claim_nodes , css_custom_properties_wrapper ) ;
444
+ block . chunks . claim . push ( b `if (${ name } ) @claim_component(${ name } .$$.fragment, ${ claim_nodes } );` ) ;
445
+ }
444
446
445
447
if ( updates . length ) {
446
448
block . chunks . update . push ( b `
447
449
${ updates }
448
450
` ) ;
449
451
}
450
452
453
+ const tmp_anchor = this . get_or_create_anchor ( block , parent_node , parent_nodes ) ;
454
+ const anchor = has_css_custom_properties ? 'null' : tmp_anchor ;
455
+ const update_mount_node = has_css_custom_properties ? css_custom_properties_wrapper : this . get_update_mount_node ( tmp_anchor ) ;
456
+ const update_insert =
457
+ css_custom_properties_wrapper &&
458
+ ( tmp_anchor . name !== 'null'
459
+ ? b `@insert(${ tmp_anchor } .parentNode, ${ css_custom_properties_wrapper } , ${ tmp_anchor } );`
460
+ : b `@insert(${ parent_node } , ${ css_custom_properties_wrapper } , ${ tmp_anchor } );` ) ;
461
+
451
462
block . chunks . update . push ( b `
452
463
if (${ switch_value } !== (${ switch_value } = ${ snippet } )) {
453
464
if (${ name } ) {
454
465
@group_outros();
455
466
const old_component = ${ name } ;
456
467
@transition_out(old_component.$$.fragment, 1, 0, () => {
457
468
@destroy_component(old_component, 1);
469
+ ${ has_css_custom_properties ? b `@detach(${ update_mount_node } )` : null }
458
470
});
459
471
@check_outros();
460
472
}
461
473
462
474
if (${ switch_value } ) {
475
+ ${ update_insert }
463
476
${ name } = new ${ switch_value } (${ switch_props } (#ctx));
464
477
465
478
${ munged_bindings }
@@ -501,62 +514,16 @@ export default class InlineComponentWrapper extends Wrapper {
501
514
` ) ;
502
515
503
516
if ( has_css_custom_properties ) {
504
- block . chunks . create . push ( b `${ css_custom_properties_wrapper } = @element("div");` ) ;
505
- block . chunks . hydrate . push ( b `@set_style(${ css_custom_properties_wrapper } , "display", "contents");` ) ;
506
- this . node . css_custom_properties . forEach ( attr => {
507
- const dependencies = attr . get_dependencies ( ) ;
508
- const should_cache = attr . should_cache ( ) ;
509
- const last = should_cache && block . get_unique_name ( `${ attr . name . replace ( / [ ^ a - z A - Z _ $ ] / g, '_' ) } _last` ) ;
510
- if ( should_cache ) block . add_variable ( last ) ;
511
- const value = attr . get_value ( block ) ;
512
- const init = should_cache ? x `${ last } = ${ value } ` : value ;
513
-
514
- block . chunks . hydrate . push ( b `@set_style(${ css_custom_properties_wrapper } , "${ attr . name } ", ${ init } );` ) ;
515
- if ( dependencies . length > 0 ) {
516
- let condition = block . renderer . dirty ( dependencies ) ;
517
- if ( should_cache ) condition = x `${ condition } && (${ last } !== (${ last } = ${ value } ))` ;
518
-
519
- block . chunks . update . push ( b `
520
- if (${ condition } ) {
521
- @set_style(${ css_custom_properties_wrapper } , "${ attr . name } ", ${ should_cache ? last : value } );
522
- }
523
- ` ) ;
524
- }
525
- } ) ;
517
+ this . set_css_custom_properties ( block , css_custom_properties_wrapper ) ;
526
518
}
527
519
block . chunks . create . push ( b `@create_component(${ name } .$$.fragment);` ) ;
528
520
529
- if ( parent_nodes && this . renderer . options . hydratable ) {
530
- let nodes = parent_nodes ;
531
- if ( has_css_custom_properties ) {
532
- nodes = block . get_unique_name ( `${ css_custom_properties_wrapper . name } _nodes` ) ;
533
- block . chunks . claim . push ( b `
534
- ${ css_custom_properties_wrapper } = @claim_element(${ parent_nodes } , "DIV", { style: true })
535
- var ${ nodes } = @children(${ css_custom_properties_wrapper } );
536
- ` ) ;
537
- }
538
- block . chunks . claim . push (
539
- b `@claim_component(${ name } .$$.fragment, ${ nodes } );`
540
- ) ;
541
- }
521
+ if ( css_custom_properties_wrapper ) this . create_css_custom_properties_wrapper_mount_chunk ( block , parent_node , css_custom_properties_wrapper ) ;
522
+ block . chunks . mount . push ( b `@mount_component(${ name } , ${ mount_target } , ${ mount_anchor } );` ) ;
542
523
543
- if ( has_css_custom_properties ) {
544
- if ( parent_node ) {
545
- block . chunks . mount . push ( b `@append(${ parent_node } , ${ css_custom_properties_wrapper } )` ) ;
546
- if ( is_head ( parent_node ) ) {
547
- block . chunks . destroy . push ( b `@detach(${ css_custom_properties_wrapper } );` ) ;
548
- }
549
- } else {
550
- block . chunks . mount . push ( b `@insert(#target, ${ css_custom_properties_wrapper } , #anchor);` ) ;
551
- // TODO we eventually need to consider what happens to elements
552
- // that belong to the same outgroup as an outroing element...
553
- block . chunks . destroy . push ( b `if (detaching) @detach(${ css_custom_properties_wrapper } );` ) ;
554
- }
555
- block . chunks . mount . push ( b `@mount_component(${ name } , ${ css_custom_properties_wrapper } , null);` ) ;
556
- } else {
557
- block . chunks . mount . push (
558
- b `@mount_component(${ name } , ${ parent_node || '#target' } , ${ parent_node ? 'null' : '#anchor' } );`
559
- ) ;
524
+ if ( to_claim ) {
525
+ if ( css_custom_properties_wrapper ) claim_nodes = this . create_css_custom_properties_wrapper_claim_chunk ( block , claim_nodes , css_custom_properties_wrapper ) ;
526
+ block . chunks . claim . push ( b `@claim_component(${ name } .$$.fragment, ${ claim_nodes } );` ) ;
560
527
}
561
528
562
529
block . chunks . intro . push ( b `
@@ -579,4 +546,64 @@ export default class InlineComponentWrapper extends Wrapper {
579
546
) ;
580
547
}
581
548
}
549
+
550
+ private create_css_custom_properties_wrapper_mount_chunk (
551
+ block : Block ,
552
+ parent_node : Identifier ,
553
+ css_custom_properties_wrapper : Identifier | null
554
+ ) {
555
+ if ( parent_node ) {
556
+ block . chunks . mount . push ( b `@append(${ parent_node } , ${ css_custom_properties_wrapper } )` ) ;
557
+ if ( is_head ( parent_node ) ) {
558
+ block . chunks . destroy . push ( b `@detach(${ css_custom_properties_wrapper } );` ) ;
559
+ }
560
+ } else {
561
+ block . chunks . mount . push ( b `@insert(#target, ${ css_custom_properties_wrapper } , #anchor);` ) ;
562
+ // TODO we eventually need to consider what happens to elements
563
+ // that belong to the same outgroup as an outroing element...
564
+ block . chunks . destroy . push ( b `if (detaching && ${ this . var } ) @detach(${ css_custom_properties_wrapper } );` ) ;
565
+ }
566
+ }
567
+
568
+ private create_css_custom_properties_wrapper_claim_chunk (
569
+ block : Block ,
570
+ parent_nodes : Identifier ,
571
+ css_custom_properties_wrapper : Identifier | null
572
+ ) {
573
+ const nodes = block . get_unique_name ( `${ css_custom_properties_wrapper . name } _nodes` ) ;
574
+ block . chunks . claim . push ( b `
575
+ ${ css_custom_properties_wrapper } = @claim_element(${ parent_nodes } , "DIV", { style: true })
576
+ var ${ nodes } = @children(${ css_custom_properties_wrapper } );
577
+ ` ) ;
578
+ return nodes ;
579
+ }
580
+
581
+ private set_css_custom_properties (
582
+ block : Block ,
583
+ css_custom_properties_wrapper : Identifier
584
+ ) {
585
+ block . chunks . create . push ( b `${ css_custom_properties_wrapper } = @element("div");` ) ;
586
+ block . chunks . hydrate . push ( b `@set_style(${ css_custom_properties_wrapper } , "display", "contents");` ) ;
587
+ this . node . css_custom_properties . forEach ( ( attr ) => {
588
+ const dependencies = attr . get_dependencies ( ) ;
589
+ const should_cache = attr . should_cache ( ) ;
590
+ const last = should_cache && block . get_unique_name ( `${ attr . name . replace ( / [ ^ a - z A - Z _ $ ] / g, '_' ) } _last` ) ;
591
+ if ( should_cache ) block . add_variable ( last ) ;
592
+ const value = attr . get_value ( block ) ;
593
+ const init = should_cache ? x `${ last } = ${ value } ` : value ;
594
+
595
+ block . chunks . hydrate . push (
596
+ b `@set_style(${ css_custom_properties_wrapper } , "${ attr . name } ", ${ init } );`
597
+ ) ;
598
+ if ( dependencies . length > 0 ) {
599
+ let condition = block . renderer . dirty ( dependencies ) ;
600
+ if ( should_cache ) condition = x `${ condition } && (${ last } !== (${ last } = ${ value } ))` ;
601
+ block . chunks . update . push ( b `
602
+ if (${ condition } ) {
603
+ @set_style(${ css_custom_properties_wrapper } , "${ attr . name } ", ${ should_cache ? last : value } );
604
+ }
605
+ ` ) ;
606
+ }
607
+ } ) ;
608
+ }
582
609
}
0 commit comments