1
1
// IWSY
2
2
3
- const IWSY = ( container , text ) => {
3
+ const IWSY = ( player , text ) => {
4
4
5
5
let script = text ;
6
6
let clicked = false ;
@@ -23,14 +23,14 @@ const IWSY = (container, text) => {
23
23
} ;
24
24
25
25
const release = step => {
26
- container . style . cursor = 'none' ;
26
+ player . style . cursor = 'none' ;
27
27
document . removeEventListener ( `click` , release ) ;
28
28
document . onkeydown = null ;
29
29
step . next ( ) ;
30
30
} ;
31
31
32
32
const doManual = step => {
33
- container . style . cursor = 'pointer' ;
33
+ player . style . cursor = 'pointer' ;
34
34
document . addEventListener ( `click` , release ) ;
35
35
document . onkeydown = ( event ) => {
36
36
switch ( event . code ) {
@@ -42,7 +42,7 @@ const IWSY = (container, text) => {
42
42
case `ArrowLeft` :
43
43
break ;
44
44
case `Enter` :
45
- container . style . cursor = 'none' ;
45
+ player . style . cursor = 'none' ;
46
46
document . addEventListener ( `click` , onClick ) ;
47
47
script . runMode = `auto` ;
48
48
release ( step ) ;
@@ -79,10 +79,10 @@ const IWSY = (container, text) => {
79
79
80
80
// Create a block.
81
81
const createBlock = ( block ) => {
82
- const w = container . getBoundingClientRect ( ) . width / 1000 ;
83
- const h = container . getBoundingClientRect ( ) . height / 1000 ;
82
+ const w = player . getBoundingClientRect ( ) . width / 1000 ;
83
+ const h = player . getBoundingClientRect ( ) . height / 1000 ;
84
84
const element = document . createElement ( `div` ) ;
85
- container . appendChild ( element ) ;
85
+ player . appendChild ( element ) ;
86
86
block . element = element ;
87
87
if ( script . speed === `scan` ) {
88
88
element . style [ `display` ] = `none` ;
@@ -276,7 +276,7 @@ const IWSY = (container, text) => {
276
276
element . style [ `background` ] = block . element . style [ `background` ]
277
277
element . style [ `border` ] = block . element . style [ `border` ]
278
278
element . style [ `border-radius` ] = block . element . style [ `border-radius` ]
279
- container . appendChild ( element ) ;
279
+ player . appendChild ( element ) ;
280
280
const text = document . createElement ( `div` ) ;
281
281
text . style [ `position` ] = `absolute` ;
282
282
text . style [ `left` ] = block . textPanel . style [ `left` ] ;
@@ -307,7 +307,7 @@ const IWSY = (container, text) => {
307
307
block . element . style [ `background` ] = `url("${ content . url } ")` ;
308
308
block . element . style [ `background-size` ] = `cover` ;
309
309
block . element . style [ `opacity` ] = 1.0 ;
310
- container . removeChild ( element ) ;
310
+ player . removeChild ( element ) ;
311
311
if ( ! continueFlag ) {
312
312
step . next ( ) ;
313
313
}
@@ -321,7 +321,7 @@ const IWSY = (container, text) => {
321
321
322
322
// Compute a block size
323
323
const setComputedBlockSize = ( block , target , ratio ) => {
324
- const boundingRect = container . getBoundingClientRect ( ) ;
324
+ const boundingRect = player . getBoundingClientRect ( ) ;
325
325
const w = boundingRect . width / 1000 ;
326
326
const h = boundingRect . height / 1000 ;
327
327
let width = block . width ;
@@ -348,7 +348,7 @@ const IWSY = (container, text) => {
348
348
349
349
// Compute a block position
350
350
const setComputedBlockPosition = ( block , target , ratio ) => {
351
- const boundingRect = container . getBoundingClientRect ( ) ;
351
+ const boundingRect = player . getBoundingClientRect ( ) ;
352
352
const w = boundingRect . width / 1000 ;
353
353
const h = boundingRect . height / 1000 ;
354
354
let left = block . left ;
@@ -375,7 +375,7 @@ const IWSY = (container, text) => {
375
375
376
376
// Compute a font size
377
377
const setComputedFontSize = ( block , target , ratio ) => {
378
- const h = Math . round ( container . getBoundingClientRect ( ) . height ) / 1000 ;
378
+ const h = Math . round ( player . getBoundingClientRect ( ) . height ) / 1000 ;
379
379
let size = block . fontSize ;
380
380
if ( ! isNaN ( size ) ) {
381
381
size *= h ;
@@ -457,7 +457,7 @@ const IWSY = (container, text) => {
457
457
for ( const name in script . blocks ) {
458
458
const block = script . blocks [ name ] ;
459
459
if ( block . element ) {
460
- container . removeChild ( block . element ) ;
460
+ player . removeChild ( block . element ) ;
461
461
block . element = null ;
462
462
}
463
463
}
@@ -492,15 +492,15 @@ const IWSY = (container, text) => {
492
492
if ( colon > 0 ) {
493
493
const aspectW = aspect . substr ( 0 , colon ) ;
494
494
const aspectH = aspect . substr ( colon + 1 ) ;
495
- const height = Math . round ( parseFloat ( container . offsetWidth ) * aspectH / aspectW ) ;
496
- container . style . height = `${ Math . round ( height ) } px` ;
495
+ const height = Math . round ( parseFloat ( player . offsetWidth ) * aspectH / aspectW ) ;
496
+ player . style . height = `${ Math . round ( height ) } px` ;
497
497
}
498
- container . style . position = `relative` ;
499
- container . style . overflow = `hidden` ;
500
- container . style . cursor = `none` ;
501
- container . style . border = step . border ;
502
- container . style . background = step . background . split ( `"` ) . join ( `"` ) ;
503
- container . style [ `background-size` ] = `cover` ;
498
+ player . style . position = `relative` ;
499
+ player . style . overflow = `hidden` ;
500
+ player . style . cursor = `none` ;
501
+ player . style . border = step . border ;
502
+ player . style . background = step . background . split ( `"` ) . join ( `"` ) ;
503
+ player . style [ `background-size` ] = `cover` ;
504
504
}
505
505
step . next ( ) ;
506
506
} ;
@@ -509,6 +509,7 @@ const IWSY = (container, text) => {
509
509
const scan = ( ) => {
510
510
script . speed = `scan` ;
511
511
removeBlocks ( ) ;
512
+ player . innerHTML = `` ;
512
513
doStep ( script . steps [ 0 ] ) ;
513
514
} ;
514
515
@@ -523,6 +524,70 @@ const IWSY = (container, text) => {
523
524
}
524
525
} ;
525
526
527
+ // Go to a specified step number
528
+ const gotoStep = ( target ) => {
529
+ script . scanTarget = target ;
530
+ script . singleStep = true ;
531
+ script . runMode = `manual` ;
532
+ scan ( ) ;
533
+ } ;
534
+
535
+ // Show a block
536
+ const block = blockIndex => {
537
+ player . innerHTML = `` ;
538
+ player . style . background = `` ;
539
+ const w = player . getBoundingClientRect ( ) . width / 1000 ;
540
+ const h = player . getBoundingClientRect ( ) . height / 1000 ;
541
+ script . blocks . forEach ( ( block , index ) => {
542
+ const element = document . createElement ( `div` ) ;
543
+ player . appendChild ( element ) ;
544
+ if ( script . speed === `scan` ) {
545
+ element . style [ `display` ] = `none` ;
546
+ }
547
+ element . style [ `position` ] = `absolute` ;
548
+ element . style [ `opacity` ] = `0.5` ;
549
+ let val = block . left ;
550
+ if ( ! isNaN ( val ) ) {
551
+ val *= w ;
552
+ }
553
+ element . style [ `left` ] = val ;
554
+ val = block . top ;
555
+ if ( ! isNaN ( val ) ) {
556
+ val *= h ;
557
+ }
558
+ element . style [ `top` ] = val ;
559
+ val = block . width ;
560
+ if ( ! isNaN ( val ) ) {
561
+ val = `${ val * w - 2 } px` ;
562
+ } else {
563
+ val = `calc(${ val } - 2px)`
564
+ }
565
+ element . style [ `width` ] = val ;
566
+ val = block . height ;
567
+ if ( ! isNaN ( val ) ) {
568
+ val = `${ val * h - 2 } px` ;
569
+ } else {
570
+ val = `calc(${ val } - 2px)`
571
+ }
572
+ element . style [ `height` ] = val ;
573
+ element . style [ `font-size` ] = `${ h * 40 } px`
574
+ element . innerHTML = block . name ;
575
+ if ( index == blockIndex ) {
576
+ element . style [ `background` ] = `#ddffdd` ;
577
+ element . style [ `border` ] = `1px solid #00ff00` ;
578
+ element . style [ `font-weight` ] = `bold`
579
+ element . style [ `z-index` ] = 10 ;
580
+ element . style . color = `#006600` ;
581
+ } else {
582
+ // element.style[`background`] = `#ff8888`;
583
+ element . style [ `border` ] = `1px solid #ff0000` ;
584
+ element . style [ `text-align` ] = `right` ;
585
+ element . style [ `z-index` ] = 0 ;
586
+ element . style . color = `#ff0000` ;
587
+ }
588
+ } ) ;
589
+ } ;
590
+
526
591
// Run the presentation
527
592
const run = then => {
528
593
initScript ( ) ;
@@ -553,17 +618,9 @@ const IWSY = (container, text) => {
553
618
step . next ( ) ;
554
619
} ;
555
620
556
- // Go to a specified step number
557
- const gotoStep = ( target ) => {
558
- script . scanTarget = target ;
559
- script . singleStep = true ;
560
- script . runMode = `manual` ;
561
- scan ( ) ;
562
- } ;
563
-
564
621
// Restore the cursor
565
622
const restoreCursor = ( ) => {
566
- container . style . cursor = `pointer` ;
623
+ player . style . cursor = `pointer` ;
567
624
if ( script . then ) {
568
625
script . then ( ) ;
569
626
script . then = null ;
@@ -635,9 +692,10 @@ const IWSY = (container, text) => {
635
692
// Initialize the script
636
693
const initScript = ( ) => {
637
694
document . onkeydown = null ;
638
- container . style . position = `relative` ;
639
- container . style . overflow = `hidden` ;
640
- container . style . cursor = 'none' ;
695
+ player . innerHTML = `` ;
696
+ player . style . position = `relative` ;
697
+ player . style . overflow = `hidden` ;
698
+ player . style . cursor = 'none' ;
641
699
script . speed = `normal` ;
642
700
script . singleStep = true ;
643
701
script . labels = { } ;
@@ -646,7 +704,7 @@ const IWSY = (container, text) => {
646
704
const block = script . blocks [ name ] ;
647
705
const element = block . element ;
648
706
if ( typeof element !== `undefined` ) {
649
- container . removeChild ( element ) ;
707
+ player . removeChild ( element ) ;
650
708
block . element = null ;
651
709
}
652
710
}
@@ -733,7 +791,6 @@ const IWSY = (container, text) => {
733
791
}
734
792
} ;
735
793
736
- container . innerHTML = `` ;
737
794
document . removeEventListener ( `click` , init ) ;
738
795
if ( script . runMode === `auto` ) {
739
796
document . addEventListener ( `click` , onClick ) ;
@@ -750,6 +807,7 @@ const IWSY = (container, text) => {
750
807
return {
751
808
setScript,
752
809
gotoStep,
810
+ block,
753
811
run,
754
812
stop,
755
813
onStep
0 commit comments