-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebVfx.js
More file actions
3876 lines (3446 loc) · 167 KB
/
WebVfx.js
File metadata and controls
3876 lines (3446 loc) · 167 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
=====================================================================
ELUSIEN'S WEBVFX FRAMEWORK FOR SHOTCUT (HTTP://ELUSIEN.CO.UK/SHOTCUT)
=====================================================================
FOR A FULL DESCRIPTION, INCLUDING DOCUMENTATION AND EXAMPLES SEE THE ABOVE WEBSITE.
THIS FRAMEWORK ENABLES SHOTCUT HTML OVERLAY FILTERS TO BE DEVELOPED QUICKLY USING A MODERN BROWSER,
WITH ALL ITS DEVELOPMENT TOOLS (E.G. USING FUNCTION KEY F12) AT YOUR DISPOSAL. SHOTCUT DOES NOT HAVE ANY
SUCH TOOLS, OTHER THAN A BASIC CONSOLE.LOG, AND IN MANY CASES OF ERROR YOU JUST END UP WITH A BLANK SCREEN.
YOU CAN STYLE THE HTML ELEMENTS AS NORMAL USING CSS THEN MODIFY THE PROPERTIES YOU WANT TO ANIMATE
USING THIS FRAMEWORK.
WHEN YOU APPLY THIS FILTER TO A CLIP IN SHOTCUT, YOU NEED TO TICK THE BOX THAT SAYS
'USE WEBVFX JAVASCRIPT EXTENSION' AND CONFIRM THAT YOU KNOW HOW TO USE IT.
THERE ARE 3 PARTS TO THIS FRAMEWORK TWO OF WHICH ARE EXPOSED TO THE USER VIA HTML TAG PARAMETERS:
1) ANIMATION EFFECTS:
THIS ENABLES YOU TO ANIMATE CSS PROPERTIES FOR ANY OF THE HTML ELEMENTS IN THE HTML OVERLAY FILTER.
IT ALSO ENABLES THE USE OF "KEYFRAMES" FOR FINE CONTROL OF THE ANIMATION. E.G.
A) FADEOUT AN ELEMENT:
<DIV CLASS='WEBVFX' DATA-ANIMATE='{0%: {OPACITY: 1;}, 100%: {OPACITY: 0%;}}'>
FADING TEXT
</DIV>
B) FADEOUT AN ELEMENT, THEN FADE IT BACK IN:
<DIV CLASS='WEBVFX' DATA-ANIMATE='{0%: {OPACITY: 1;}, 50%: {OPACITY: 0%;}, 100%: {OPACITY: 1;}}'>
TEXT FADING OUT THEN BACK IN
</DIV>
C) CHANGE AN ELEMENT'S COLOUR, MOVE IT AROUND, CHANGE IT FROM A SQUARE SHAPE TO A CIRCLE.
<DIV CLASS='WEBVFX' DATA-ANIMATE=
'{START: 0.2, END: 1.0, EASE: "EASEOUTSINE",
0%: {BACKGROUNDCOLOR: #F00; LEFT: 0PX; TOP: 0PX; BORDERRADIUS: 0%;},
25%: {BACKGROUNDCOLOR: #00F; LEFT:100PX; TOP: 0PX; BORDERRADIUS: 50%;},
50%: {BACKGROUNDCOLOR: #0F0; LEFT:200PX; TOP:200PX; BORDERRADIUS: 0%;},
75%: {BACKGROUNDCOLOR: #F0F; LEFT: 0PX; TOP:200PX; BORDERRADIUS: 50%;},
100%: {BACKGROUNDCOLOR: #FF0; LEFT:100PX; TOP: 0PX; BORDERRADIUS: 0%;}
}'>
HI
</DIV>
2) STOPWATCH EFFECTS:
THIS ENABLES YOU TO HAVE 1 OR MORE STOPWATCHES IN THE HTML OVERLAY FILTER. IT ALSO ENABLES THE
USE OF "KEYFRAMES" FOR FINE CONTROL OF THE STOPWATCHES.
A STOPWATCH CONSISTS OF 4 ELEMENTS SPECIFIED USING HTML '<SPAN></SPAN>' TAGS.
<SPAN> NUMBER 1 IS THE FRAME NUMBER;
<SPAN> NUMBER 2 IS THE HOUR NUMBER;
<SPAN> NUMBER 3 IS THE MINUTE NUMBER;
<SPAN> NUMBER 4 IS THE MILLISECOND NUMBER
NORMALLY YOU WOULD INITIALISE EACH OF THE <SPAN> ELEMENTS BY PLACING A ZERO (0) IN IT. PLACING ANY
OTHER NUMBER WILL INITIALISE IT TO THAT VALUE. LEAVING THE <SPAN> EMPTY WILL HIDE IT (SEE EXAMPLES). E.G.
A) STOPWATCH SHOWING FRAME-NUMBER, MINUTES AND SECONDS:
<DIV CLASS="WEBVFX" DATA-STOPWATCH=''>
FRAME <SPAN>0</SPAN> => <SPAN></SPAN><SPAN>00</SPAN>M <SPAN>00</SPAN>S <SPAN></SPAN>
</DIV>
B) STOPWATCH SHOWING MINUTES AND SECONDS, RUNNING FOR 120 SECONDS WITH VARIOUS PAUSES AND RESUMES:
<DIV CLASS="WEBVFX" DATA-CONTROL='120:24' DATA-STOPWATCH=
'{10%: {PAUSE;},
20%: {RESUME;},
40%: {PAUSE;},
60%: {RESUME: SKIP;},
80%: {PAUSE;},
90%: {RESUME: 60000;}
}'>
<SPAN></SPAN></SPAN><SPAN></SPAN><SPAN>00</SPAN>M <SPAN>00</SPAN>S <SPAN></SPAN>
</DIV>
3) USER-SUPPLIED EFFECTS:
THIS ENABLES YOU TO PROVIDE YOUR OWN JAVASCRIPT FUNCTION TO DO SOMETHING TO THE HTML. THIS FUNCTION
WILL BE CALLED FOR EACH FRAME WITH THE PARAMETERS:
TIME: THE "NORMALISED TIME" OF THIS FRAME (0.0 TO 1.0);
FRAME_NUMBER: THE NUMBER OF THIS FRAME
FRAME_RATE : THE FRAME-RATE IN FRAMES PER SECOND
TO DO THIS YOU NEED TO CREATE THE JAVASCRIPT FUNCTION, THEN ADD IT TO A GLOBAL-SCOPE ARRAY CALLED
"WEBVFX_ADD_TO_FRAME" E.G.
<SCRIPT>
FUNCTION FLASH(TIME, FRAME_NUMBER, FRAME_RATE) {
BULB = DOCUMENT.GETELEMENTBYID("BULB");
BULB.STYLE.OPACITY = ((FRAME_NUMBER % 10) < 5) ? 0.1 : 1.0;
}
WEBVFX_ADD_TO_FRAME = [FLASH];
<SCRIPT>
* THE CREATIVE COMMONS ATTRIBUTION-SHAREALIKE 4.0 INTERNATIONAL LICENCE (CC BY-SA 4.0)
* SEE HTTPS://CREATIVECOMMONS.ORG/LICENSES/BY-SA/4.0/
*
* COPYRIGHT (C) 2018 - ELUSIEN ENTERTAINMENT
*
* ATTRIBUTION — YOU MUST GIVE APPROPRIATE CREDIT, PROVIDE A LINK TO THE LICENSE,
* AND INDICATE IF CHANGES WERE MADE. YOU MAY DO SO IN ANY REASONABLE MANNER,
* BUT NOT IN ANY WAY THAT SUGGESTS THE LICENSOR ENDORSES YOU OR YOUR USE.
*
* SHAREALIKE — IF YOU REMIX, TRANSFORM, OR BUILD UPON THE MATERIAL, YOU MUST DISTRIBUTE
* YOUR CONTRIBUTIONS UNDER THE SAME LICENSE AS THE ORIGINAL.
*
* NO ADDITIONAL RESTRICTIONS — YOU MAY NOT APPLY LEGAL TERMS OR TECHNOLOGICAL MEASURES
* THAT LEGALLY RESTRICT OTHERS FROM DOING ANYTHING THE LICENSE PERMITS.
*
* NOTICES:
* YOU DO NOT HAVE TO COMPLY WITH THE LICENSE FOR ELEMENTS OF THE MATERIAL IN THE PUBLIC DOMAIN
* OR WHERE YOUR USE IS PERMITTED BY AN APPLICABLE EXCEPTION OR LIMITATION.
* NO WARRANTIES ARE GIVEN. THE LICENSE MAY NOT GIVE YOU ALL OF THE PERMISSIONS NECESSARY
* FOR YOUR INTENDED USE. FOR EXAMPLE, OTHER RIGHTS SUCH AS PUBLICITY, PRIVACY, OR MORAL RIGHTS
* MAY LIMIT HOW YOU USE THE MATERIAL.
*
* THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
* ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @VERSION 1.16
*/
var Elusien = {
iter : 0,
niters : 0,
delay : 0,
frame_number: 0,
frame_length: 0,
frame_busy : 0
};
function Easing_Funs(){
/*
Easing Equations v1.3, Oct. 29, 2002, Open source under the BSD License.
Copyright © 2001-2002 Robert Penner. All rights reserved.
These tweening functions provide different flavors of math-based motion under a consistent API.
Math.easingType(t,b,c,d)
t: current time,
b: beginning value (i.e value at time_start),
c: change in value (end_value - b), can be negative
d: duration (i.e. time_end - time_start)
Type of easing HTML data-easing value Description
-------------- ---------------------- -----------
Linear "linearTween" linear tweening - no easing is performed
Quadratic "easeInQuad" t^2 acceleration from zero velocity
"easeOutQuad" t^2 deceleration to zero velocity
"easeInOutQuad" t^2 acceleration until halfway, then deceleration
Cubic "easeInCubic" t^3 acceleration from zero velocity
"easeOutCubic" t^3 deceleration to zero velocity
"easeInOutCubic" t^3 acceleration until halfway, then deceleration
Quartic "easeInQuartic" t^4 acceleration from zero velocity
"easeOutQuartic" t^4 deceleration to zero velocity
"easeInOutQuartic" t^4 acceleration until halfway, then deceleration
Quintic "easeInQuintic" t^5 acceleration from zero velocity
"easeOutQuintic" t^5 deceleration to zero velocity
"easeInOutQuintic" t^5 acceleration until halfway, then deceleration
Sinusoidal "easeInSine" sinusoidal acceleration from zero velocity
"easeOutSine" sinusoidal deceleration to zero velocity
"easeInOutSine" sinusoidal acceleration until halfway, then deceleration
Exponential "easeInExpo" exponential acceleration from zero velocity
"easeOutExpo" exponential deceleration to zero velocity
"easeInOutExpo" exponential acceleration until halfway, then deceleration
Circular "easeInCirc" circular acceleration from zero velocity
"easeOutCirc" circular deceleration to zero velocity
"easeInOutCirc" circular acceleration until halfway, then deceleration
Bounce "easeInBounce" elastic bounce, then acceleration from zero velocity
"easeOutBounce" elastic deceleration to zero velocity, then bounce
"easeInOutBounce" elastic bounce, then acceleration until halfway, then deceleration, then bounce
Changes:
1.3 - tweaked the exponential easing functions to make endpoints exact
1.2 - inline optimizations (changing t and multiplying in one step)--thanks to Tatsuo Kato for the idea
Discussed in Chapter 7 of Robert Penner's Programming Macromedia Flash MX (including graphs of the easing equations)
http://www.robertpenner.com/profmx
http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/
this.linearTween = function (t, b, c, d) {return c * t/d + b;};
this.easeInQuad = function (t, b, c, d) {return c * (t/=d) *t + b;};
this.easeOutQuad = function (t, b, c, d) {return -c * (t/=d) *(t-2) + b;};
this.easeInOutQuad = function (t, b, c, d) {return ((t/=d/2) < 1) ? c/2*t*t + b : -c/2*((--t)*(t-2) - 1) + b;};
this.easeInCubic = function (t, b, c, d) {return c * (t/=d) *t*t + b;};
this.easeOutCubic = function (t, b, c, d) {return c * ((t=t/d-1) *t*t + 1) + b;};
this.easeInOutCubic = function (t, b, c, d) {return ((t/=d/2) < 1) ? c/2*t*t*t + b : c/2*((t-=2)*t*t + 2) + b;};
this.easeInQuart = function (t, b, c, d) {return c * (t/=d) *t*t*t + b;};
this.easeOutQuart = function (t, b, c, d) {return -c * ((t=t/d-1) *t*t*t - 1) + b;};
this.easeInOutQuart = function (t, b, c, d) {return ((t/=d/2) < 1) ? c/2*t*t*t*t + b : -c/2*((t-=2)*t*t*t - 2) + b;};
this.easeInQuint = function (t, b, c, d) {return c * (t/=d) *t*t*t*t + b;};
this.easeOutQuint = function (t, b, c, d) {return c * ((t=t/d-1) *t*t*t*t + 1) + b;};
this.easeInOutQuint = function (t, b, c, d) {return ((t/=d/2) < 1) ? c/2*t*t*t*t*t + b : c/2*((t-=2)*t*t*t*t + 2) + b;};
this.easeInSine = function (t, b, c, d) {return -c * Math.cos(t/d * (Math.PI/2)) + c + b;};
this.easeOutSine = function (t, b, c, d) {return c * Math.sin(t/d * (Math.PI/2)) + b;};
this.easeInOutSine = function (t, b, c, d) {return -c/2 * (Math.cos(t/d * Math.PI) - 1) + b;};
this.easeInExpo = function (t, b, c, d) {return (t===0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;};
this.easeOutExpo = function (t, b, c, d) {return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;};
this.easeInOutExpo = function (t, b, c, d) {return (t===0) ? b : ((t==d) ? b+c : (((t/=d/2) < 1) ? c/2 * Math.pow(2, 10 * (t - 1)) + b : c/2*(-Math.pow(2, -10 * --t) + 2) + b));};
this.easeInCirc = function (t, b, c, d) {return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;};
this.easeOutCirc = function (t, b, c, d) {return c * Math.sqrt(1 - (t=t/d-1)*t) + b;};
this.easeInOutCirc = function (t, b, c, d) {return ((t/=d/2) < 1) ? -c/2 * (Math.sqrt(1 - t*t) - 1) + b : c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;};
this.easeInBounce = function (t, b, c, d) {return (t===0) ? b : (((t/=d) == 1) ? b + c : -(c * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - (d*0.3 /4)) * (2 * Math.PI) / (d*0.3 ))) + b);};
this.easeOutBounce = function (t, b, c, d) {return (t===0) ? b : (((t/=d/2) == 2) ? b + c : (c * Math.pow(2, -10 * t ) * Math.sin((t * d - (d*0.3 /4)) * (2 * Math.PI) / (d*0.3 ))) + c + b);};
this.easeInOutBounce= function (t, b, c, d) {return (t===0) ? b : (((t/=d/2) == 2) ? b + c : ((t<1) ? -0.5 * (c * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - (d*0.3*1.5/4)) * (2 * Math.PI) / (d*0.3*1.5))) + b :
(c * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - (d*0.3*1.5/4)) * (2 * Math.PI) / (d*0.3*1.5))) * 0.5 + c + b));};
} // #################### END OF Easing_Funs CONSTRUCTOR ####################
/**
* Behaves the same as setTimeout except uses requestAnimationFrame() where possible for better performance
* @param {function} fn The callback function
* @param {int} delay The delay in milliseconds
*/
window.requestTimeout = function(fn, delay) {
var start = new Date().getTime(),
handle = {};
function loop(){
var current = new Date().getTime(),
delta = current - start;
if (delta >= delay) {
fn.call();
} else {
handle.value = requestAnimFrame(loop);
}
}
handle.value = requestAnimFrame(loop);
return handle;
};
/**
* Behaves the same as clearTimeout except uses cancelRequestAnimationFrame() where possible for better performance
* @param {int|object} fn The callback function
*/
window.clearRequestTimeout = function(handle) {
window.cancelAnimationFrame(handle.value);
};
/**
* Behaves the same as setInterval except uses requestAnimationFrame() where possible for better performance
* @param {function} fn The callback function
* @param {int} delay The delay in milliseconds
*/
window.requestInterval = function(fn, delay) {
var start = new Date().getTime(),
handle = {};
function loop() {
var current = new Date().getTime(),
delta = current - start;
if(delta >= delay) {
fn.call();
start = new Date().getTime();
}
handle.value = requestAnimFrame(loop);
}
handle.value = requestAnimFrame(loop);
return handle;
};
/**
* Behaves the same as clearInterval except uses cancelRequestAnimationFrame() where possible for better performance
* @param {int|object} fn The callback function
*/
window.clearRequestInterval = function(handle) {
window.cancelAnimationFrame(handle.value);
};
// ######################### parse SRT/VTT subtitle files ###########################
function timeInMs(timestamp) {
if (!isNaN(timestamp)) {return timestamp;}
var match = timestamp.match(/^(?:(\d{2,}):)?(\d{2}):(\d{2})[,.](\d{3})$/);
if (!match) {
throw new Error('Invalid SRT or VTT time format: "' + timestamp + '"');
}
var hours = match[1] ? parseInt(match[1], 10) * 3600000 : 0;
var minutes = parseInt(match[2], 10) * 60000;
var seconds = parseInt(match[3], 10) * 1000;
var milliseconds = parseInt(match[4], 10);
return hours + minutes + seconds + milliseconds;
}
/**
* Converts SubRip subtitles into an array of objects
* [{
* id: `Number of subtitle`
* startTime: `Start time of subtitle`
* endTime: `End time of subtitle
* text: `Text of subtitle`
* }]
*
* @param {String} srt_str : The SubRip subtitles string (can handle v simple VTT strings too)
* @return {Array} cues : An array of "Cue" structures, 1 for each subtitle.
**/
function fromSrt(srt_str) {
//var RE = /^((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3}) --> ((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3})(?: (.*))/g;
var regex = /(\d+)\n((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3}) --> ((?:\d{2,}:)?\d{2}:\d{2}[,.]\d{3})/g;
/* e.g. (for .srt file)
12
00:00:23,500 --> 00:00:25,100
<b>What's happening?</b>
or for .vtt file
12
00:00:23.500 --> 00:00:25.100 region:bill align:right
<v bill><b>What's happening?</b>
*/
var parts = srt_str.replace(/\r/g, '').split(regex);
parts.shift();
var cues = [];
var i = 0;
while (i < parts.length) {
cues.push({
processing: 0, // -1 = finished; 0 = not started; 1 = in progress
start : 0, // startTime in NORMALISED time units
end : 0, // endTime in NORMALISED time units
id : parts[i++].trim(),
startTime : timeInMs(parts[i++].trim()),
endTime : timeInMs(parts[i++].trim()),
text : parts[i++].trim()
});
}
//console.log(cues);
return cues;
}
// ##################################### END OF SUBTITLE PARSING ################################
// The EXIF stuff is not used, it is too difficult to implement in Javascript for shotcut.
/*
From the EXIF standard documentation
(http://web.archive.org/web/20131018091152/http://exif.org/Exif2-2.PDF)
Table 18 Tag Support Levels (5)
Orientation:
The image orientation viewed in terms of rows and columns.
Tag = 274 (112 Hex)
Type = SHORT
Count = 1
Default = 1
1 = The 0th row is the visual top of the image, and the 0th column is the visual left-hand side. (Normal)
2 = The 0th row is the visual top of the image, and the 0th column is the visual right-hand side.
3 = The 0th row is the visual bottom of the image, and the 0th column is the visual right-hand side.
4 = The 0th row is the visual bottom of the image, and the 0th column is the visual left-hand side.
5 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual top.
6 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.
7 = The 0th row is the visual right-hand side of the image, and the 0th column is the visual bottom.
8 = The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.
Other = reserved
*/
var exif_orientations = [
'scale( 1, 1) rotate( 0deg)',
'scale( 1, 1) rotate( 0deg)',
'scale(-1, 1) rotate( 0deg)',
'scale( 1, 1) rotate(180deg)',
'scale( 1,-1) rotate( 0deg)',
'scale(-1, 1) rotate( 90deg)',
'scale( 1, 1) rotate( 90deg)',
'scale(-1, 1) rotate(-90deg)',
'scale( 1, 1) rotate(-90deg)'
];
function _arrayBufferToBase64( buffer ) { // Used in EXIF code - CAN IGNORE
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {binary += String.fromCharCode( bytes[ i ] );}
return window.btoa( binary );
}
function exif_orientation(filename) { // Used in EXIF code - CAN IGNORE
if (!(window.File && window.FileReader && window.FileList && window.Blob)) {
alert('The File APIs are not fully supported in this browser.');
}
var file = new File([""], filename);
//console.log('EXIF:' + filename + ': ' + file.name);
var file_reader = new FileReader();
file_reader.onload = function() {
//console.log('OK:' + this.readyState + ', ' + this.error + '; ' + this.result.length);
var scanner = new DataView(this.result);
var idx = 0;
var value = 1; // Non-rotated is the default
if(this.result.length < 2 || scanner.getUint16(idx) != 0xFFD8) {
return 0; // Not a JPEG
}
idx += 2;
var maxBytes = scanner.byteLength;
while(idx < maxBytes - 2) {
var uint16 = scanner.getUint16(idx);
idx += 2;
switch(uint16) {
case 0xFFE1: // Start of EXIF
var exifLength = scanner.getUint16(idx);
maxBytes = exifLength - idx;
idx += 2;
break;
case 0x0112: // Orientation tag
// Read the value, its 6 bytes further out
// See page 102 at the following URL
// http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf
value = scanner.getUint16(idx + 6, false);
maxBytes = 0; // Stop scanning
break;
}
}
};
file_reader.readAsArrayBuffer(file);
}
function rand_between(xmin, xmax) { return Math.random() * (xmax - xmin) + xmin; }
function Producer(params) {
/*
==============================================================================================================
Description
-----------
This function is called to save its parameters as its properties. These are required by the
render function in order to animate the objects on the screen by manipulating certain of their CSS properties.
Parameters Description
---------- -----------
params An object containing all the parameters
==============================================================================================================
*/
this.params = params; // Add params objects as a property of the Producer class
} // #################### END OF Producer CONSTRUCTOR ####################
Producer.prototype.render = function(time) {
/*
==============================================================================================================
Description
-----------
This function is called once for each frame to manipulate the various objects' CSS properties by 1 increment.
By using "prototype" it is stored in the Producer object as a method called "render".
This is the main function, since it is where the animated frames are produced.
Parameters Description
---------- -----------
time The current normalised (between 0.0 and 1.0) time. This is incremented on each call by an
amount equal to 1/(duration*framerate), where duration = the length of the clip in seconds
and framerate is the number of frames per second.
==============================================================================================================
*/
var property;
var startval;
var changeval;
var propertyval;
var i;
var j;
var k;
var t = time;
var duration;
var animate;
var start;
var end;
var ease;
var keyftime;
var keystart;
var keyend;
var kt;
var kd;
var prop;
var fprop;
var tprop;
var fp = [];
var tp = [];
var aprops = [];
var from = {};
var to = {};
Elusien.frame_length = t / (++Elusien.frame_number);
if (typeof webvfx_add_to_frame !=='undefined') {for (i = 0; i < webvfx_add_to_frame.length; i++) {webvfx_add_to_frame[i](time, this.params.browser, Elusien.frame_number, Elusien.frame_rate);}}
for (var param in this.params) {
if (typeof this.params[param].animate != "undefined"){
animate = this.params[param].animate;
start = animate.start;
end = animate.end;
ease = animate.ease;
duration = end - start;
aprops = Object.getOwnPropertyNames(this.params[param].animate).sort();
if ((t >= start) && (t <= end)) {
// The next statement is to get over the problem that the time never reaches 1.0. the last time is for the last frame
// which can appear up to 1/frame-rate seconds before 1.0. Since we do not know the framerate, assume it is 24fps.
if ((end-t) < 2*Elusien.frame_length){t = end;}
j = 0;
for (k = 0; k < aprops.length; k++) {
if (aprops[k].match(/^\d+(.\d)*$/) !== null) {
prop = +aprops[k];
keyftime = (prop * duration / 100) + start;
if (keyftime <= t) {
kt = t - keyftime;
keystart = k;
keyend = keystart+1;
if (aprops[keyend].match(/^\d+(.\d)*$/) === null) {
keyend = keystart;
kt = 1.0;
kd = kt;
} else {
kd = (+aprops[keyend] * duration / 100) - (+aprops[keystart] * duration / 100);
}
}
}
}
//console.log('DEBUG: prop=' + prop + ', keystart=' + keystart + ', keyend=' + keyend);
from = animate[aprops[keystart]];
to = animate[aprops[keyend]];
fp = Object.getOwnPropertyNames(from);
tp = Object.getOwnPropertyNames( to );
for (j=0; j<fp.length; j++) {
property = fp[j];
propertyval = " ";
for (i = 0; i < from[property].length; i++) {
fprop = from[property][i];
// if(typeof fprop == "string"){fprop = fprop.trim();} // do NOT trim
tprop = to[property][i];
// if(typeof tprop == "string"){tprop = tprop.trim();} // do NOT trim
if (typeof fprop == "string" && fprop[0] != '#') {
propertyval += fprop;
} else if ((typeof fprop == "string") && (fprop[0] == '#')) {
propertyval += "rgb(";
startval = parseInt(fprop.substring(1,3),16);
changeval = parseInt(tprop.substring(1,3),16) - startval;
propertyval += Math.floor(this.params[param].easing[ease](kt, +startval, +changeval, kd)) + ',';
startval = parseInt(fprop.substring(3,5),16);
changeval = parseInt(tprop.substring(3,5),16) - startval;
propertyval += Math.floor(this.params[param].easing[ease](kt, +startval, +changeval, kd)) + ',';
startval = parseInt(fprop.substring(5,7),16);
changeval = parseInt(tprop.substring(5,7),16) - startval;
propertyval += Math.floor(this.params[param].easing[ease](kt, +startval, +changeval, kd)) + ')';
} else {
startval = fprop;
changeval = tprop - startval;
propertyval += this.params[param].easing[ease](kt, +startval, +changeval, kd);
}
}
//console.log(time + "|DEBUG: property=" + property + ": " + propertyval);
this.params[param].style[property] = propertyval;
}
}
} else if (typeof this.params[param].stopwatch != "undefined"){
run_stopwatch (this.params[param].stopwatch , this.params[param].sw_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].slideshow != "undefined"){
run_slideshow (this.params[param].slideshow , this.params[param].ss_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].explosion != "undefined"){
run_explosion (this.params[param].explosion , this.params[param].ex_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].rolling != "undefined"){
run_rolling (this.params[param].rolling , this.params[param].rl_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].fragment != "undefined"){
run_fragment (this.params[param].fragment , this.params[param].fg_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].subtitle != "undefined"){
run_subtitle (this.params[param].subtitle , this.params[param].st_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].typewrite != "undefined"){
run_typewriter(this.params[param].typewriter, this.params[param].tw_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].ntypewrite != "undefined"){
run_ntypewriter(this.params[param].ntypewriter, this.params[param].nt_params, time, Elusien.frame_number, Elusien.frame_rate);
} else if (typeof this.params[param].credits != "undefined"){
run_credits (this.params[param].credits, this.params[param].vc_params, time, Elusien.frame_number, Elusien.frame_rate);
}
}
}; // #################### END OF render ####################
function credits_to_JSON_string(data_credits) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's credits request..
Parameters Description
---------- -----------
data_credits The string the user provided on the "data-credits" attribute in the HTML.
==============================================================================================================
*/
return data_credits.replace( /\n/g, ' ')
.replace( /(['"])/g, '')
.replace( /\s+:/g, ': ')
.replace( /\s{2,}/g, ' ')
.replace( /([a-z0-9_.]+):/ig, '"$1":')
.replace( /:\s*([^:},\s}]*)\s*,{0,1}/g, ':"$1",')
.replace( /[;,]\s*}/g, '}');
}
function typewriter_to_JSON_string(data_typewriter) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's typewriter request..
Parameters Description
---------- -----------
data_typewriter The string the user provided on the "data-typewriter" attribute in the HTML.
==============================================================================================================
*/
return data_typewriter.replace( /\n/g, ' ')
.replace( /(['"])/g, '')
.replace( /\s+:/g, ': ')
.replace( /\s{2,}/g, ' ')
.replace( /([a-z0-9_.]+):/ig, '"$1":')
.replace( /:\s*([^:},\s}]*)\s*,{0,1}/g, ':"$1",')
.replace( /[;,]\s*}/g, '}');
}
function ntypewriter_to_JSON_string(data_ntypewriter) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's typewriter request..
Parameters Description
---------- -----------
data_ntypewriter The string the user provided on the "data-typewriter" attribute in the HTML.
==============================================================================================================
*/
return data_ntypewriter.replace( /\n/g, ' ')
.replace( /(['"])/g, '')
.replace( /\s+:/g, ': ')
.replace( /\s{2,}/g, ' ')
.replace( /([a-z0-9_.]+):/ig, '"$1":')
.replace( /:\s*([^:},\s}]*)\s*,{0,1}/g, ':"$1",')
.replace( /[;,]\s*}/g, '}');
}
function slideshow_to_JSON_string(data_slideshow) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's slideshow request..
Parameters Description
---------- -----------
data_animate The string the user provided on the "data-slideshow" attribute in the HTML.
==============================================================================================================
*/
return data_slideshow.replace( /\n/g, ' ')
.replace( /(['"])/g, '')
.replace( /\s+:/g, ': ')
.replace( /\s{2,}/g, ' ')
.replace( /([a-z0-9_.]+):/ig, '"$1":')
.replace( /:\s*([^:},\s}]*)\s*,{0,1}/g, ':"$1",')
.replace( /[;,]\s*}/g, '}');
}
function animate_to_JSON_string(data_animate) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's animation request..
Parameters Description
---------- -----------
data_animate The string the user provided on the "data-animate" attribute in the HTML.
==============================================================================================================
*/
return data_animate.replace( /\n/g, ' ')
.replace( /\s+:/g, ': ')
.replace( /\s{2,}/g, ' ')
.replace( /(\d\d\d)(.\d*){0,1}%:/g, '$1$2:')
.replace( /(\D)(\d\d)(.\d*){0,1}%:/g, '$10$2$3:')
.replace( /(\D\D)(\d)(.\d*){0,1}%:/g, '$100$2$3:')
.replace( /([a-z0-9_.]+):/ig, '"$1":')
.replace( /:([^:]*)\s*;/g, ':"$1",')
.replace( /[;,]\s*}/g, '}');
}
function explosion_to_JSON_string(data_explosion) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's explosion request..
Parameters Description
---------- -----------
data_explosion The string the user provided on the "data-explode" attribute in the HTML.
==============================================================================================================
*/
return data_explosion.replace( /\n/g, ' ') // Replace newline by space
.replace( /(['"])/g, '') // Remove quotes
.replace( /\s+:/g, ': ') // Remove spaces before ':' and append a space
.replace( /\s{2,}/g, ' ') // replace multiple spaces by a single space
.replace( /(\d\d\d)(.\d*){0,1}%:/g, '$1$2:') // These 3 lines convert keyframes to
.replace( /(\D)(\d\d)(.\d*){0,1}%:/g, '$10$2$3:') // numbers such as:
.replace( /(\D\D)(\d)(.\d*){0,1}%:/g, '$100$2$3:') // 050.1276 (get rid of '%')
.replace( /(\d\d\d)(.\d*){0,1}:\s+([a-z]*)/g, '$1$2: $3') // Add a space after the keyframe
.replace( /([a-z0-9_.]+):/ig, '"$1":') // Put double-quotes around property names
.replace( /:\s*([^:}," ]*)\s*/g, ': "$1"') // Put double-quotes around property values
.replace( /[;,]\s*}/g, '}'); // Remove last ',' or ';' before a '}'
}
function rolling_to_JSON_string(data_rolling) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's rolling request..
Parameters Description
---------- -----------
data_rolling The string the user provided on the "data-roll" attribute in the HTML.
==============================================================================================================
*/
return data_rolling.replace( /\n/g, ' ') // Replace newline by space
.replace( /(['"])/g, '') // Remove quotes
.replace( /\s+:/g, ': ') // Remove spaces before ':' and append a space
.replace( /\s{2,}/g, ' ') // replace multiple spaces by a single space
.replace( /(\d\d\d)(.\d*){0,1}%:/g, '$1$2:') // These 3 lines convert keyframes to
.replace( /(\D)(\d\d)(.\d*){0,1}%:/g, '$10$2$3:') // numbers such as:
.replace( /(\D\D)(\d)(.\d*){0,1}%:/g, '$100$2$3:') // 050.1276 (get rid of '%')
.replace( /(\d\d\d)(.\d*){0,1}:\s+([a-z]*)/g, '$1$2: $3') // Add a space after the keyframe
.replace( /([a-z0-9_.]+):/ig, '"$1":') // Put double-quotes around property names
.replace( /:\s*([^:}," ]*)\s*/g, ': "$1"') // Put double-quotes around property values
.replace( /[;,]\s*}/g, '}'); // Remove last ',' or ';' before a '}'
}
function fragment_to_JSON_string(data_fragment) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's fragmentation request..
Parameters Description
---------- -----------
data_fragment The string the user provided on the "data-fragment" attribute in the HTML.
==============================================================================================================
*/
return data_fragment.replace( /\n/g, ' ') // Replace newline by space
.replace( /(['"])/g, '') // Remove quotes
.replace( /\s+:/g, ': ') // Remove spaces before ':' and append a space
.replace( /\s{2,}/g, ' ') // replace multiple spaces by a single space
.replace( /(\d\d\d)(.\d*){0,1}%:/g, '$1$2:') // These 3 lines convert keyframes to
.replace( /(\D)(\d\d)(.\d*){0,1}%:/g, '$10$2$3:') // numbers such as:
.replace( /(\D\D)(\d)(.\d*){0,1}%:/g, '$100$2$3:') // 050.1276 (get rid of '%')
.replace( /(\d\d\d)(.\d*){0,1}:\s+([a-z]*)/g, '$1$2: $3') // Add a space after the keyframe
.replace( /([a-z0-9_.]+):/ig, '"$1":') // Put double-quotes around property names
.replace( /:\s*([^:}," ]*)\s*/g, ': "$1"') // Put double-quotes around property values
.replace( /[;,]\s*}/g, '}'); // Remove last ',' or ';' before a '}'
}
function stopwatch_to_JSON_string(data_stopwatch) {
/*
==============================================================================================================
Description
-----------
This function is called once to create the JSON string from the user's animation request..
Parameters Description
---------- -----------
data_animate The string the user provided on the "data-animate" attribute in the HTML.
==============================================================================================================
*/
return data_stopwatch.replace( /\n/g, ' ')
.replace( /\s+:/g, ': ')
.replace( /\s{2,}/g, ' ')
.replace( /pause\s*;/g, 'pause: normal;')
.replace( /resume\s*;/g, 'resume: normal;')
.replace( /(\d\d\d)(.\d*){0,1}%:/g, '$1$2:')
.replace(/(\D)(\d\d)(.\d*){0,1}%:/g, '$10$2$3:')
.replace(/(\D\D)(\d)(.\d*){0,1}%:/g, '$100$2$3:')
.replace( /([a-z0-9_.]+):/ig, '"$1":')
.replace( /:([^:]*)\s*;/g, ':"$1",')
.replace( /[;,]\s*}/g, '}');
}
function HTML_entity(chars, pos) {
var str = chars.slice(pos, pos + Math.min(8, (chars.length-pos+1))).join('');
if (chars[pos] == '&') {console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' + str);}
var ret = str.replace(/^(&.{1,8};)(.*)/, '$1');
if (chars[pos] == '&') {console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' + ret);}
return ret;
}
function format_explosion_data(explosion, ex_params){
// explosion_data.element is explosions[ex];
// explosion_data.sequence is explode[ex];
// explosion_data.spans becomes the span elements, which are the individual characters of the text.
var chars = explosion.innerHTML.split('');
var width = document.documentElement.clientWidth; //"innerwidth" in window ? window.innerwidth : document.documentElement.offsetwidth;
var height = document.documentElement.clientHeight; //"innerHeight" in window ? window.innerHeight : document.documentElement.offsetHeight;
var mfact = 2.0;
var xmin = -mfact * width;
var xmax = mfact * width;
var ymin = -mfact * height;
var ymax = mfact * height;
var spantext = [];
var tag = false;
var entity = false;
for (var i=0; i<chars.length; i++) {
if (chars[i] == '<') {
tag = true;
}
if (!tag) { // A single space is ignored in an inline-block, so convert it to a non-breaking space instead.
// Check for an HTML etity (e,g, & < etc...)
if (chars[i] == '&') {
entity = HTML_entity(chars, i);
}
if (entity) {
spantext.push('<span class="e_x_p_l_o_d_e">', entity, '</span>');
i += entity.length - 1;
entity = false;
} else {
spantext.push('<span class="e_x_p_l_o_d_e">', (chars[i] != ' ' ? chars[i] : ' '), '</span>');
}
} else {
spantext.push(chars[i]);
}
if (chars[i] == '>') {
tag = false;
}
}
explosion.innerHTML = spantext.join('');
ex_params.spans = explosion.getElementsByClassName('e_x_p_l_o_d_e');
//console.log('ex_params.begin=', ex_params.begin, ', ex_params.state=', ex_params.state, 'ex_params.trans_end=', ex_params.trans_end);
//console.log(ex_params);
for (i = 0; i < ex_params.spans.length; i++) {
ex_params.styles[i] = ex_params.spans[i].style;
ex_params.coords[i] = new Coords(rand_between(xmin, xmax),
rand_between(ymin, ymax),
(Math.random() < 0.5 ? 0 : 4),
i / ex_params.spans.length);
ex_params.styles[i].display = 'inline-block';
ex_params.styles[i].margin = 0;
ex_params.styles[i].padding = 0;
ex_params.styles[i].border = 0;
ex_params.styles[i].opacity = (ex_params.explode.begin == 'visible') ? 1.0 : 0.0;
}
return;
}
function format_rolling_data(rolling, rl_params){
// rolling_data.element is explosions[ex];
// rolling_data.sequence is explode[ex];
// rolling_data.spans becomes the span elements, which are the individual characters of the text.
/*
* https://codepen.io/kh-mamun/pen/NdwZdW
*/
var chars = rolling.innerHTML.trim().split('');
var spantext = [];
var tag = false;
var entity = false;
//console.log(rolling);
//console.log(chars);
for (var i=0; i<chars.length; i++) {
if (chars[i] == '<') {
tag = true;
}
if (!tag) { // A single space is ignored in an inline-block, so convert it to a non-breaking space instead.
// Check for an HTML etity (e,g, & < etc...)
if (chars[i] == '&') {
entity = HTML_entity(chars, i);
}
if (entity) {
spantext.push('<span class="f_l_o_w" style="text-decoration: inherit">', entity, '</span>');
i += entity.length - 1;
entity = false;
} else {
spantext.push('<span class="f_l_o_w" style="text-decoration: inherit">', (chars[i] != ' ' ? chars[i] : ' '), '</span>');
}
} else {
spantext.push(chars[i]);
}
if (chars[i] == '>') {
tag = false;
}
}
rl_params.originalHTML = rolling.innerHTML;
rolling.innerHTML = spantext.join('');
rl_params.spans = rolling.getElementsByClassName('f_l_o_w');
//console.log('rl_params.begin=', rl_params.begin, ', rl_params.state=', rl_params.state, 'rl_params.trans_end=', rl_params.trans_end);
//console.log(JSON.stringify(rl_params, null, 4));
//console.log(rolling);
rl_params.xform = [];
for (i = 0; i < rl_params.spans.length; i++) {
rl_params.xform[i] = new Xform(0);
rl_params.coords[i] = new Coords(rl_params.animparams[0].translate[0],
rl_params.animparams[0].translate[1],
rl_params.animparams[0].scale,
i / rl_params.spans.length,
rl_params.animparams[0].opacity,
rl_params.animparams[0].rotate
); // Initial (flow) or final (roll) translate (x, y)
rl_params.coords[i].k = 0; // This keyframe
rl_params.coords[i].p = rl_params.animparams[0].pcnt/100; // THIS keyframe's percent (as a decimal 0 to 1)
rl_params.coords[i].np = rl_params.animparams[1].pcnt/100; // the NEXT keyframe's percent (as a decimal 0 to 1)
rl_params.coords[i].nx = rl_params.animparams[1].translate[0];
rl_params.coords[i].ny = rl_params.animparams[1].translate[1];
rl_params.coords[i].nz = rl_params.animparams[1].scale;
rl_params.coords[i].no = rl_params.animparams[1].opacity;
rl_params.coords[i].nr = rl_params.animparams[1].rotate;
rl_params.styles[i] = rl_params.spans[i].style;
rl_params.styles[i].display = 'inline-block';
rl_params.styles[i].margin = 0;
rl_params.styles[i].padding = 0;
rl_params.styles[i].border = 0;
rl_params.styles[i].opacity = (rl_params.roll.begin == 'visible') ? 1.0 : 0.0;
}
//console.log(rl_params);
return;
}
function format_typewriter_data(typewriter, tw_params){
// typewriter_data.element is typewriters[tw];
// typewriter_data.sequence is typewrite[tw];
// typewriter_data.spans becomes the span elements, which are the individual characters of the text.
var chars = typewriter.innerHTML.split('');
var spantext = [];
var tag = false;
var entity = false;
for (var i=0; i<chars.length; i++) {
if (chars[i].charCodeAt(0) < 32) { continue; }
if (chars[i] == '<') { tag = true; }
if (!tag) { // A single space is ignored in an inline-block, so convert it to a non-breaking space instead.
// Check for an HTML etity (e,g, & < etc...)
if (chars[i] == '&') {
entity = HTML_entity(chars, i);
}
if (entity) {
spantext.push('<span class="f_l_o_w" style="text-decoration: inherit">', entity, '</span>');
i += entity.length - 1;
entity = false;
} else {
spantext.push('<span class="_typewriter_">', (chars[i] != ' ' ? chars[i] : ' '), '</span>');
}
} else {
spantext.push(chars[i]);
}
if (chars[i] == '>') {
tag = false;
}
}
typewriter.innerHTML = spantext.join('');
tw_params.spans = typewriter.getElementsByClassName('_typewriter_');
//console.log(tw_params);
for (i = 0; i < tw_params.spans.length; i++) {
tw_params.cstyle[i] = window.getComputedStyle(tw_params.spans[i], null);
if (i === 0) { tw_params.borderRightColor = tw_params.cstyle[0].borderRightColor; }
tw_params.style[i] = tw_params.spans[i].style;
tw_params.style[i].display = 'inline-block';
tw_params.style[i].visibility = 'hidden';
tw_params.style[i].borderRightColor = 'transparent';
tw_params.style[i].borderLeftColor = 'transparent';
tw_params.style[i].borderBottomColor = 'transparent';
tw_params.style[i].borderTopColor = 'transparent';
// tw_params.style[i].margin = 0;
// tw_params.style[i].padding = 0;