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