@@ -52,12 +52,10 @@ import {
52
52
flushSync ,
53
53
expose ,
54
54
safe_not_equal ,
55
- managed_pre_effect ,
56
55
current_block ,
57
56
set_signal_value ,
58
57
source ,
59
58
managed_effect ,
60
- mark_subtree_inert ,
61
59
safe_equal ,
62
60
push ,
63
61
current_component_context ,
@@ -72,7 +70,7 @@ import {
72
70
} from './hydration.js' ;
73
71
import { array_from , define_property , get_descriptor , get_descriptors , is_array } from './utils.js' ;
74
72
import { is_promise } from '../common.js' ;
75
- import { bind_transition } from './transitions.js' ;
73
+ import { bind_transition , remove_in_transitions , trigger_transitions } from './transitions.js' ;
76
74
77
75
/** @type {Set<string> } */
78
76
const all_registerd_events = new Set ( ) ;
@@ -81,7 +79,7 @@ const all_registerd_events = new Set();
81
79
const root_event_handles = new Set ( ) ;
82
80
83
81
/** @returns {Text } */
84
- function empty ( ) {
82
+ export function empty ( ) {
85
83
return document . createTextNode ( '' ) ;
86
84
}
87
85
@@ -1369,11 +1367,7 @@ function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) {
1369
1367
consequent_transitions . add ( transition ) ;
1370
1368
transition . finished ( ( ) => {
1371
1369
consequent_transitions . delete ( transition ) ;
1372
- for ( let other of consequent_transitions ) {
1373
- if ( other . direction === 'in' ) {
1374
- consequent_transitions . delete ( other ) ;
1375
- }
1376
- }
1370
+ remove_in_transitions ( consequent_transitions ) ;
1377
1371
if ( consequent_transitions . size === 0 ) {
1378
1372
execute_effect ( consequent_effect ) ;
1379
1373
}
@@ -1382,11 +1376,7 @@ function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) {
1382
1376
alternate_transitions . add ( transition ) ;
1383
1377
transition . finished ( ( ) => {
1384
1378
alternate_transitions . delete ( transition ) ;
1385
- for ( let other of alternate_transitions ) {
1386
- if ( other . direction === 'in' ) {
1387
- alternate_transitions . delete ( other ) ;
1388
- }
1389
- }
1379
+ remove_in_transitions ( alternate_transitions ) ;
1390
1380
if ( alternate_transitions . size === 0 ) {
1391
1381
execute_effect ( alternate_effect ) ;
1392
1382
}
@@ -1674,11 +1664,7 @@ export function component(anchor_node, component_fn, render_fn) {
1674
1664
transitions . add ( transition ) ;
1675
1665
transition . finished ( ( ) => {
1676
1666
transitions . delete ( transition ) ;
1677
- for ( let other of transitions ) {
1678
- if ( other . direction === 'in' ) {
1679
- transitions . delete ( other ) ;
1680
- }
1681
- }
1667
+ remove_in_transitions ( transitions ) ;
1682
1668
if ( transitions . size === 0 ) {
1683
1669
if ( render . effect !== null ) {
1684
1670
if ( render . dom !== null ) {
@@ -1805,11 +1791,7 @@ function await_block(anchor_node, input, pending_fn, then_fn, catch_fn) {
1805
1791
transitions . add ( transition ) ;
1806
1792
transition . finished ( ( ) => {
1807
1793
transitions . delete ( transition ) ;
1808
- for ( let other of transitions ) {
1809
- if ( other . direction === 'in' ) {
1810
- transitions . delete ( other ) ;
1811
- }
1812
- }
1794
+ remove_in_transitions ( transitions ) ;
1813
1795
if ( transitions . size === 0 ) {
1814
1796
if ( render . effect !== null ) {
1815
1797
if ( render . dom !== null ) {
@@ -1863,6 +1845,7 @@ function await_block(anchor_node, input, pending_fn, then_fn, catch_fn) {
1863
1845
return ;
1864
1846
}
1865
1847
const transitions = render . transitions ;
1848
+ remove_in_transitions ( transitions ) ;
1866
1849
if ( transitions . size === 0 ) {
1867
1850
if ( render . dom !== null ) {
1868
1851
remove ( render . dom ) ;
@@ -1967,11 +1950,7 @@ export function key(anchor_node, key, render_fn) {
1967
1950
transitions . add ( transition ) ;
1968
1951
transition . finished ( ( ) => {
1969
1952
transitions . delete ( transition ) ;
1970
- for ( let other of transitions ) {
1971
- if ( other . direction === 'in' ) {
1972
- transitions . delete ( other ) ;
1973
- }
1974
- }
1953
+ remove_in_transitions ( transitions ) ;
1975
1954
if ( transitions . size === 0 ) {
1976
1955
if ( render . effect !== null ) {
1977
1956
if ( render . dom !== null ) {
@@ -2012,6 +1991,7 @@ export function key(anchor_node, key, render_fn) {
2012
1991
return ;
2013
1992
}
2014
1993
const transitions = render . transitions ;
1994
+ remove_in_transitions ( transitions ) ;
2015
1995
if ( transitions . size === 0 ) {
2016
1996
if ( render . dom !== null ) {
2017
1997
remove ( render . dom ) ;
@@ -2139,96 +2119,6 @@ export function destroy_each_item_block(
2139
2119
}
2140
2120
}
2141
2121
2142
- /**
2143
- * @this {import('./types.js').EachItemBlock}
2144
- * @param {import('./types.js').Transition } transition
2145
- * @returns {void }
2146
- */
2147
- function each_item_transition ( transition ) {
2148
- const block = this ;
2149
- const each_block = block . parent ;
2150
- const is_controlled = ( each_block . flags & EACH_IS_CONTROLLED ) !== 0 ;
2151
- // Disable optimization
2152
- if ( is_controlled ) {
2153
- const anchor = empty ( ) ;
2154
- each_block . flags ^= EACH_IS_CONTROLLED ;
2155
- append_child ( /** @type {Element } */ ( each_block . anchor ) , anchor ) ;
2156
- each_block . anchor = anchor ;
2157
- }
2158
- if ( transition . direction === 'key' && ( each_block . flags & EACH_IS_ANIMATED ) === 0 ) {
2159
- each_block . flags |= EACH_IS_ANIMATED ;
2160
- }
2161
- let transitions = block . transitions ;
2162
- if ( transitions === null ) {
2163
- block . transitions = transitions = new Set ( ) ;
2164
- }
2165
- transition . finished ( ( ) => {
2166
- if ( transitions !== null ) {
2167
- transitions . delete ( transition ) ;
2168
- if ( transition . direction !== 'key' ) {
2169
- for ( let other of transitions ) {
2170
- if ( other . direction === 'key' || other . direction === 'in' ) {
2171
- transitions . delete ( other ) ;
2172
- }
2173
- }
2174
- if ( transitions . size === 0 ) {
2175
- block . transitions = null ;
2176
- destroy_each_item_block ( block , null , true ) ;
2177
- }
2178
- }
2179
- }
2180
- } ) ;
2181
- transitions . add ( transition ) ;
2182
- }
2183
-
2184
- /**
2185
- * @param {Set<import('./types.js').Transition> } transitions
2186
- * @param {'in' | 'out' | 'key' } target_direction
2187
- * @param {DOMRect } [from]
2188
- * @returns {void }
2189
- */
2190
- export function trigger_transitions ( transitions , target_direction , from ) {
2191
- /** @type {Array<() => void> } */
2192
- const outros = [ ] ;
2193
- for ( const transition of transitions ) {
2194
- const direction = transition . direction ;
2195
- if ( target_direction === 'in' ) {
2196
- if ( direction === 'in' || direction === 'both' ) {
2197
- if ( direction === 'in' ) {
2198
- transition . cancel ( ) ;
2199
- }
2200
- transition . in ( ) ;
2201
- } else {
2202
- transition . cancel ( ) ;
2203
- }
2204
- transition . dom . inert = false ;
2205
- mark_subtree_inert ( transition . effect , false ) ;
2206
- } else if ( target_direction === 'key' ) {
2207
- if ( direction === 'key' ) {
2208
- transition . payload = transition . init ( /** @type {DOMRect } */ ( from ) ) ;
2209
- transition . in ( ) ;
2210
- }
2211
- } else {
2212
- if ( direction === 'out' || direction === 'both' ) {
2213
- transition . payload = transition . init ( ) ;
2214
- outros . push ( transition . out ) ;
2215
- }
2216
- transition . dom . inert = true ;
2217
- mark_subtree_inert ( transition . effect , true ) ;
2218
- }
2219
- }
2220
- if ( outros . length > 0 ) {
2221
- // Defer the outros to a microtask
2222
- const e = managed_pre_effect ( ( ) => {
2223
- destroy_signal ( e ) ;
2224
- const e2 = managed_effect ( ( ) => {
2225
- destroy_signal ( e2 ) ;
2226
- outros . forEach ( /** @param {any } o */ ( o ) => o ( ) ) ;
2227
- } ) ;
2228
- } , false ) ;
2229
- }
2230
- }
2231
-
2232
2122
/**
2233
2123
* @template V
2234
2124
* @param {V } item
@@ -2242,7 +2132,6 @@ export function each_item_block(item, key, index, render_fn, flags) {
2242
2132
const item_value = ( flags & EACH_ITEM_REACTIVE ) === 0 ? item : source ( item ) ;
2243
2133
const index_value = ( flags & EACH_INDEX_REACTIVE ) === 0 ? index : source ( index ) ;
2244
2134
const block = create_each_item_block ( item_value , index_value , key ) ;
2245
- block . transition = each_item_transition ;
2246
2135
const effect = render_effect (
2247
2136
/** @param {import('./types.js').EachItemBlock } block */
2248
2137
( block ) => {
@@ -2290,11 +2179,7 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
2290
2179
transitions . add ( transition ) ;
2291
2180
transition . finished ( ( ) => {
2292
2181
transitions . delete ( transition ) ;
2293
- for ( let other of transitions ) {
2294
- if ( other . direction === 'in' ) {
2295
- transitions . delete ( other ) ;
2296
- }
2297
- }
2182
+ remove_in_transitions ( transitions ) ;
2298
2183
if ( transitions . size === 0 ) {
2299
2184
if ( fallback . effect !== null ) {
2300
2185
if ( fallback . dom !== null ) {
0 commit comments