@@ -5,8 +5,25 @@ import { create_rule, delete_rule } from './style_manager';
5
5
import { custom_event } from './dom' ;
6
6
import { add_render_callback } from './scheduler' ;
7
7
import { TransitionConfig } from '../transition' ;
8
+ import { Fragment } from './Component' ;
8
9
9
10
let promise : Promise < void > | null ;
11
+ type INTRO = 1 ;
12
+ type OUTRO = 0 ;
13
+ interface Outro {
14
+ /**
15
+ * remaining outros
16
+ */
17
+ r : number ;
18
+ /**
19
+ * callbacks
20
+ */
21
+ c : Function [ ] ;
22
+ /**
23
+ * parent outro
24
+ */
25
+ p : Outro ;
26
+ }
10
27
11
28
function wait ( ) {
12
29
if ( ! promise ) {
@@ -19,12 +36,12 @@ function wait() {
19
36
return promise ;
20
37
}
21
38
22
- function dispatch ( node : Element , direction : boolean , kind : 'start' | 'end' ) {
39
+ function dispatch ( node : Element , direction : INTRO | OUTRO | boolean , kind : 'start' | 'end' ) {
23
40
node . dispatchEvent ( custom_event ( `${ direction ? 'intro' : 'outro' } ${ kind } ` ) ) ;
24
41
}
25
42
26
43
const outroing = new Set ( ) ;
27
- let outros ;
44
+ let outros : Outro ;
28
45
29
46
export function group_outros ( ) {
30
47
outros = {
@@ -41,14 +58,14 @@ export function check_outros() {
41
58
outros = outros . p ;
42
59
}
43
60
44
- export function transition_in ( block , local ?: 0 | 1 ) {
61
+ export function transition_in ( block : Fragment , local ?: 0 | 1 ) {
45
62
if ( block && block . i ) {
46
63
outroing . delete ( block ) ;
47
64
block . i ( local ) ;
48
65
}
49
66
}
50
67
51
- export function transition_out ( block , local : 0 | 1 , detach ?: 0 | 1 , callback ?) {
68
+ export function transition_out ( block : Fragment , local : 0 | 1 , detach ?: 0 | 1 , callback ?) {
52
69
if ( block && block . o ) {
53
70
if ( outroing . has ( block ) ) return ;
54
71
outroing . add ( block ) ;
@@ -225,21 +242,39 @@ export function create_out_transition(node: Element & ElementCSSInlineStyle, fn:
225
242
} ;
226
243
}
227
244
245
+ interface PendingProgram {
246
+ start : number ;
247
+ b : INTRO | OUTRO ;
248
+ group ?: Outro ;
249
+ }
250
+ interface Program {
251
+ a : number ;
252
+ b : INTRO | OUTRO ;
253
+ /**
254
+ * direction
255
+ */
256
+ d : 1 | - 1 ;
257
+ duration : number ;
258
+ start : number ;
259
+ end : number ;
260
+ group ?: Outro ;
261
+ }
262
+
228
263
export function create_bidirectional_transition ( node : Element & ElementCSSInlineStyle , fn : TransitionFn , params : any , intro : boolean ) {
229
264
let config = fn ( node , params ) ;
230
265
231
266
let t = intro ? 0 : 1 ;
232
267
233
- let running_program = null ;
234
- let pending_program = null ;
268
+ let running_program : Program | null = null ;
269
+ let pending_program : PendingProgram | null = null ;
235
270
let animation_name = null ;
236
271
237
272
function clear_animation ( ) {
238
273
if ( animation_name ) delete_rule ( node , animation_name ) ;
239
274
}
240
275
241
- function init ( program , duration ) {
242
- const d = program . b - t ;
276
+ function init ( program : PendingProgram , duration : number ) : Program {
277
+ const d = ( program . b - t ) as Program [ 'd' ] ;
243
278
duration *= Math . abs ( d ) ;
244
279
245
280
return {
@@ -253,7 +288,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline
253
288
} ;
254
289
}
255
290
256
- function go ( b ) {
291
+ function go ( b : INTRO | OUTRO ) {
257
292
const {
258
293
delay = 0 ,
259
294
duration = 300 ,
@@ -262,7 +297,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline
262
297
css
263
298
} = config || null_transition ;
264
299
265
- const program = {
300
+ const program : PendingProgram = {
266
301
start : now ( ) + delay ,
267
302
b
268
303
} ;
@@ -331,7 +366,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline
331
366
}
332
367
333
368
return {
334
- run ( b ) {
369
+ run ( b : INTRO | OUTRO ) {
335
370
if ( is_function ( config ) ) {
336
371
wait ( ) . then ( ( ) => {
337
372
// @ts -ignore
0 commit comments