@@ -112,7 +112,9 @@ const JSON_Presenter = {
112
112
doStep : ( script , stepno ) => {
113
113
const goto = ( script , stepno ) => {
114
114
if ( stepno < script . steps . length ) {
115
- JSON_Presenter . doStep ( script , stepno ) ;
115
+ setTimeout ( function ( ) {
116
+ JSON_Presenter . doStep ( script , stepno ) ;
117
+ } , 1 ) ;
116
118
}
117
119
} ;
118
120
@@ -252,57 +254,59 @@ const JSON_Presenter = {
252
254
}
253
255
} ;
254
256
255
- // Process a single transform step
256
- const doTransformStep = ( block , target , nSteps , n , transform , onFinish ) => {
257
- transform ( block , target , nSteps , n ) ;
257
+ // Process a single transition step
258
+ const doTransitionStep = ( block , target , step , nSteps , n , transition , onFinish ) => {
259
+ transition ( block , target , step , nSteps , n ) ;
258
260
if ( n < nSteps ) {
259
261
setTimeout ( function ( ) {
260
- doTransformStep ( block , target , nSteps , n + 1 , transform , onFinish ) ;
262
+ doTransitionStep ( block , target , step , nSteps , n + 1 , transition , onFinish ) ;
261
263
} , 40 ) ;
262
264
} else {
263
265
onFinish ( ) ;
264
266
}
265
267
} ;
266
268
267
- // Transform block
268
- const transformBlock = ( block , target , nSteps , n ) => {
269
- const boundingRect = script . element . getBoundingClientRect ( ) ;
269
+ // Compute a block size
270
+ const setComputedBlockSize = ( block , target , nSteps , n ) => {
271
+ const boundingRect = block . container . getBoundingClientRect ( ) ;
270
272
w = Math . round ( boundingRect . width ) ;
271
273
h = Math . round ( boundingRect . height ) ;
272
- const left = block . properties . blockLeft * w / 1000 ;
273
- const top = block . properties . blockTop * h / 1000 ;
274
274
const width = block . properties . blockWidth * w / 1000 ;
275
275
const height = block . properties . blockHeight * h / 1000 ;
276
- const endLeft = target . properties . blockLeft * w / 1000 ;
277
- const endTop = target . properties . blockTop * h / 1000 ;
278
276
const endWidth = target . properties . blockWidth * w / 1000 ;
279
277
const endHeight = target . properties . blockHeight * h / 1000 ;
280
- block . element . style [ `left` ] =
281
- left + Math . round ( ( endLeft - left ) * n / nSteps ) ;
282
- block . element . style [ `top` ] =
283
- top + Math . round ( ( endTop - top ) * n / nSteps ) ;
284
278
block . element . style [ `width` ] =
285
279
`${ width + Math . round ( ( endWidth - width ) * n / nSteps ) } px` ;
286
280
block . element . style [ `height` ] =
287
281
`${ height + Math . round ( ( endHeight - height ) * n / nSteps ) } px` ;
288
282
} ;
289
283
290
- const doTransformBlock = ( script , step , stepno ) => {
291
- const block = script . blocks [ step . block ] ;
292
- const target = script . blocks [ step . target ] ;
293
- const nSteps = Math . round ( parseFloat ( step . duration ) * 25 ) ;
294
- doTransformStep ( block , target , nSteps , 0 , transformBlock , function ( ) {
295
- if ( step . wait ) {
296
- goto ( script , stepno + 1 ) ;
297
- }
298
- } ) ;
299
- if ( ! step . wait ) {
300
- goto ( script , stepno + 1 ) ;
301
- }
284
+ // Compute a block position
285
+ const setComputedBlockPosition = ( block , target , nSteps , n ) => {
286
+ const boundingRect = block . container . getBoundingClientRect ( ) ;
287
+ w = Math . round ( boundingRect . width ) ;
288
+ h = Math . round ( boundingRect . height ) ;
289
+ const left = block . properties . blockLeft * w / 1000 ;
290
+ const top = block . properties . blockTop * h / 1000 ;
291
+ const endLeft = target . properties . blockLeft * w / 1000 ;
292
+ const endTop = target . properties . blockTop * h / 1000 ;
293
+ block . element . style [ `left` ] =
294
+ left + Math . round ( ( endLeft - left ) * n / nSteps ) ;
295
+ block . element . style [ `top` ] =
296
+ top + Math . round ( ( endTop - top ) * n / nSteps ) ;
302
297
} ;
303
298
304
- // Transform font color
305
- const setComputedColor = ( block , target , nSteps , n ) => {
299
+ // Compute a font size
300
+ const setComputedFontSize = ( block , target , nSteps , n ) => {
301
+ h = Math . round ( script . element . getBoundingClientRect ( ) . height ) ;
302
+ const size = block . properties . fontSize * h / 1000 ;
303
+ const endSize = target . properties . fontSize * h / 1000 ;
304
+ block . element . inner . text . style [ `font-size` ] =
305
+ `${ size + Math . round ( ( endSize - size ) * n / nSteps ) } px` ;
306
+ } ;
307
+
308
+ // Compute a font color
309
+ const setComputedFontColor = ( block , target , nSteps , n ) => {
306
310
const color = block . spec . fontColor ;
307
311
const endColor = target . spec . fontColor ;
308
312
const rStart = parseInt ( color . slice ( 1 , 3 ) , 16 ) ;
@@ -320,34 +324,48 @@ const JSON_Presenter = {
320
324
block . element . inner . text . style [ `color` ] = `#${ r } ${ g } ${ b } ` ;
321
325
} ;
322
326
323
- const doTransformFontColor = ( script , step , stepno ) => {
324
- const block = script . blocks [ step . block ] ;
325
- const target = script . blocks [ step . target ] ;
326
- const nSteps = Math . round ( parseFloat ( step . duration ) * 25 ) ;
327
- doTransformStep ( block , target , nSteps , 0 , setComputedColor , function ( ) {
328
- if ( step . wait ) {
329
- goto ( script , stepno + 1 ) ;
327
+ const computeTransitionValues = ( block , target , step , nSteps , n ) => {
328
+ for ( const type of step . type ) {
329
+ switch ( type ) {
330
+ case `block size` :
331
+ setComputedBlockSize ( block , target , nSteps , n ) ;
332
+ break ;
333
+ case `block position` :
334
+ setComputedBlockPosition ( block , target , nSteps , n ) ;
335
+ break ;
336
+ case `font size` :
337
+ setComputedFontSize ( block , target , nSteps , n ) ;
338
+ break ;
339
+ case `font color` :
340
+ setComputedFontColor ( block , target , nSteps , n ) ;
341
+ break ;
342
+ default :
343
+ throw Error ( `Unknown transition type: '${ type } '` ) ;
330
344
}
331
- } ) ;
332
- if ( ! step . wait ) {
333
- goto ( script , stepno + 1 ) ;
334
345
}
335
346
} ;
336
347
337
- // Transform font size
338
- const setComputedFontSize = ( block , target , nSteps , n ) => {
348
+ // Do the transition
349
+ const computeTransitionStep = ( block , target , types , nSteps , n ) => {
350
+ if ( Array . isArray ( types ) ) {
351
+ for ( const type of types ) {
352
+ computeTransitionValues ( block , target , type , nSteps , n ) ;
353
+ }
354
+ } else {
355
+ computeTransitionValues ( block , target , types , nSteps , n ) ;
356
+ }
339
357
h = Math . round ( script . element . getBoundingClientRect ( ) . height ) ;
340
358
const size = block . properties . fontSize * h / 1000 ;
341
359
const endSize = target . properties . fontSize * h / 1000 ;
342
360
block . element . inner . text . style [ `font-size` ] =
343
361
`${ size + Math . round ( ( endSize - size ) * n / nSteps ) } px` ;
344
362
} ;
345
363
346
- const doTransformFontSize = ( script , step , stepno ) => {
364
+ const doTransition = ( script , step , stepno ) => {
347
365
const block = script . blocks [ step . block ] ;
348
366
const target = script . blocks [ step . target ] ;
349
367
const nSteps = Math . round ( parseFloat ( step . duration ) * 25 ) ;
350
- doTransformStep ( block , target , nSteps , 0 , setComputedFontSize , function ( ) {
368
+ doTransitionStep ( block , target , step , nSteps , 0 , computeTransitionStep , function ( ) {
351
369
if ( step . wait ) {
352
370
goto ( script , stepno + 1 ) ;
353
371
}
@@ -357,23 +375,6 @@ const JSON_Presenter = {
357
375
}
358
376
} ;
359
377
360
- // Transform an element
361
- const doTransform = ( script , step , stepno ) => {
362
- switch ( step . type ) {
363
- case `block` :
364
- doTransformBlock ( script , step , stepno ) ;
365
- break ;
366
- case `font color` :
367
- doTransformFontColor ( script , step , stepno ) ;
368
- break ;
369
- case `font size` :
370
- doTransformFontSize ( script , step , stepno ) ;
371
- break ;
372
- default :
373
- throw Error ( `Unknown transform type: '${ step . type } '` ) ;
374
- }
375
- } ;
376
-
377
378
// Process a single step
378
379
const step = script . steps [ stepno ] ;
379
380
switch ( step . action ) {
@@ -404,8 +405,8 @@ const JSON_Presenter = {
404
405
case `fade down` :
405
406
doFade ( script , step , stepno , false ) ;
406
407
break ;
407
- case `transform ` :
408
- doTransform ( script , step , stepno ) ;
408
+ case `transition ` :
409
+ doTransition ( script , step , stepno ) ;
409
410
break ;
410
411
default :
411
412
throw Error ( `Unknown action: '${ step . action } '` ) ;
0 commit comments