-
Notifications
You must be signed in to change notification settings - Fork 31
/
doc.js
1859 lines (1120 loc) · 49 KB
/
doc.js
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
/*
* Copyright (c) 2016, Pierre-Anthony Lemieux <pal@sandflow.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module imscDoc
*/
;
(function (imscDoc, sax, imscNames, imscStyles, imscUtils) {
/**
* Allows a client to provide callbacks to handle children of the <metadata> element
* @typedef {Object} MetadataHandler
* @property {?OpenTagCallBack} onOpenTag
* @property {?CloseTagCallBack} onCloseTag
* @property {?TextCallBack} onText
*/
/**
* Called when the opening tag of an element node is encountered.
* @callback OpenTagCallBack
* @param {string} ns Namespace URI of the element
* @param {string} name Local name of the element
* @param {Object[]} attributes List of attributes, each consisting of a
* `uri`, `name` and `value`
*/
/**
* Called when the closing tag of an element node is encountered.
* @callback CloseTagCallBack
*/
/**
* Called when a text node is encountered.
* @callback TextCallBack
* @param {string} contents Contents of the text node
*/
/**
* Parses an IMSC1 document into an opaque in-memory representation that exposes
* a single method <pre>getMediaTimeEvents()</pre> that returns a list of time
* offsets (in seconds) of the ISD, i.e. the points in time where the visual
* representation of the document change. `metadataHandler` allows the caller to
* be called back when nodes are present in <metadata> elements.
*
* @param {string} xmlstring XML document
* @param {?module:imscUtils.ErrorHandler} errorHandler Error callback
* @param {?MetadataHandler} metadataHandler Callback for <Metadata> elements
* @returns {Object} Opaque in-memory representation of an IMSC1 document
*/
imscDoc.fromXML = function (xmlstring, errorHandler, metadataHandler) {
var p = sax.parser(true, {xmlns: true});
var estack = [];
var xmllangstack = [];
var xmlspacestack = [];
var metadata_depth = 0;
var doc = null;
p.onclosetag = function (node) {
if (estack[0] instanceof Region) {
/* merge referenced styles */
if (doc.head !== null && doc.head.styling !== null) {
mergeReferencedStyles(doc.head.styling, estack[0].styleRefs, estack[0].styleAttrs, errorHandler);
}
delete estack[0].styleRefs;
} else if (estack[0] instanceof Styling) {
/* flatten chained referential styling */
for (var sid in estack[0].styles) {
if (! estack[0].styles.hasOwnProperty(sid)) continue;
mergeChainedStyles(estack[0], estack[0].styles[sid], errorHandler);
}
} else if (estack[0] instanceof P || estack[0] instanceof Span) {
/* merge anonymous spans */
if (estack[0].contents.length > 1) {
var cs = [estack[0].contents[0]];
var c;
for (c = 1; c < estack[0].contents.length; c++) {
if (estack[0].contents[c] instanceof AnonymousSpan &&
cs[cs.length - 1] instanceof AnonymousSpan) {
cs[cs.length - 1].text += estack[0].contents[c].text;
} else {
cs.push(estack[0].contents[c]);
}
}
estack[0].contents = cs;
}
// remove redundant nested anonymous spans (9.3.3(1)(c))
if (estack[0] instanceof Span &&
estack[0].contents.length === 1 &&
estack[0].contents[0] instanceof AnonymousSpan) {
estack[0].text = estack[0].contents[0].text;
delete estack[0].contents;
}
} else if (estack[0] instanceof ForeignElement) {
if (estack[0].node.uri === imscNames.ns_tt &&
estack[0].node.local === 'metadata') {
/* leave the metadata element */
metadata_depth--;
} else if (metadata_depth > 0 &&
metadataHandler &&
'onCloseTag' in metadataHandler) {
/* end of child of metadata element */
metadataHandler.onCloseTag();
}
}
// TODO: delete stylerefs?
// maintain the xml:space stack
xmlspacestack.shift();
// maintain the xml:lang stack
xmllangstack.shift();
// prepare for the next element
estack.shift();
};
p.ontext = function (str) {
if (estack[0] === undefined) {
/* ignoring text outside of elements */
} else if (estack[0] instanceof Span || estack[0] instanceof P) {
/* ignore children text nodes in ruby container spans */
if (estack[0] instanceof Span) {
var ruby = estack[0].styleAttrs[imscStyles.byName.ruby.qname];
if (ruby === 'container' || ruby === 'textContainer' || ruby === 'baseContainer') {
return;
}
}
/* create an anonymous span */
var s = new AnonymousSpan();
s.initFromText(doc, estack[0], str, xmllangstack[0], xmlspacestack[0], errorHandler);
estack[0].contents.push(s);
} else if (estack[0] instanceof ForeignElement &&
metadata_depth > 0 &&
metadataHandler &&
'onText' in metadataHandler) {
/* text node within a child of metadata element */
metadataHandler.onText(str);
}
};
p.onopentag = function (node) {
// maintain the xml:space stack
var xmlspace = node.attributes["xml:space"];
if (xmlspace) {
xmlspacestack.unshift(xmlspace.value);
} else {
if (xmlspacestack.length === 0) {
xmlspacestack.unshift("default");
} else {
xmlspacestack.unshift(xmlspacestack[0]);
}
}
/* maintain the xml:lang stack */
var xmllang = node.attributes["xml:lang"];
if (xmllang) {
xmllangstack.unshift(xmllang.value);
} else {
if (xmllangstack.length === 0) {
xmllangstack.unshift("");
} else {
xmllangstack.unshift(xmllangstack[0]);
}
}
/* process the element */
if (node.uri === imscNames.ns_tt) {
if (node.local === 'tt') {
if (doc !== null) {
reportFatal(errorHandler, "Two <tt> elements at (" + this.line + "," + this.column + ")");
}
doc = new TT();
doc.initFromNode(node, xmllangstack[0], errorHandler);
estack.unshift(doc);
} else if (node.local === 'head') {
if (!(estack[0] instanceof TT)) {
reportFatal(errorHandler, "Parent of <head> element is not <tt> at (" + this.line + "," + this.column + ")");
}
estack.unshift(doc.head);
} else if (node.local === 'styling') {
if (!(estack[0] instanceof Head)) {
reportFatal(errorHandler, "Parent of <styling> element is not <head> at (" + this.line + "," + this.column + ")");
}
estack.unshift(doc.head.styling);
} else if (node.local === 'style') {
var s;
if (estack[0] instanceof Styling) {
s = new Style();
s.initFromNode(node, errorHandler);
/* ignore <style> element missing @id */
if (!s.id) {
reportError(errorHandler, "<style> element missing @id attribute");
} else {
doc.head.styling.styles[s.id] = s;
}
estack.unshift(s);
} else if (estack[0] instanceof Region) {
/* nested styles can be merged with specified styles
* immediately, with lower priority
* (see 8.4.4.2(3) at TTML1 )
*/
s = new Style();
s.initFromNode(node, errorHandler);
mergeStylesIfNotPresent(s.styleAttrs, estack[0].styleAttrs);
estack.unshift(s);
} else {
reportFatal(errorHandler, "Parent of <style> element is not <styling> or <region> at (" + this.line + "," + this.column + ")");
}
} else if (node.local === 'initial') {
var ini;
if (estack[0] instanceof Styling) {
ini = new Initial();
ini.initFromNode(node, errorHandler);
for (var qn in ini.styleAttrs) {
if (! ini.styleAttrs.hasOwnProperty(qn)) continue;
doc.head.styling.initials[qn] = ini.styleAttrs[qn];
}
estack.unshift(ini);
} else {
reportFatal(errorHandler, "Parent of <initial> element is not <styling> at (" + this.line + "," + this.column + ")");
}
} else if (node.local === 'layout') {
if (!(estack[0] instanceof Head)) {
reportFatal(errorHandler, "Parent of <layout> element is not <head> at " + this.line + "," + this.column + ")");
}
estack.unshift(doc.head.layout);
} else if (node.local === 'region') {
if (!(estack[0] instanceof Layout)) {
reportFatal(errorHandler, "Parent of <region> element is not <layout> at " + this.line + "," + this.column + ")");
}
var r = new Region();
r.initFromNode(doc, node, xmllangstack[0], errorHandler);
if (!r.id || r.id in doc.head.layout.regions) {
reportError(errorHandler, "Ignoring <region> with duplicate or missing @id at " + this.line + "," + this.column + ")");
} else {
doc.head.layout.regions[r.id] = r;
}
estack.unshift(r);
} else if (node.local === 'body') {
if (!(estack[0] instanceof TT)) {
reportFatal(errorHandler, "Parent of <body> element is not <tt> at " + this.line + "," + this.column + ")");
}
if (doc.body !== null) {
reportFatal(errorHandler, "Second <body> element at " + this.line + "," + this.column + ")");
}
var b = new Body();
b.initFromNode(doc, node, xmllangstack[0], errorHandler);
doc.body = b;
estack.unshift(b);
} else if (node.local === 'div') {
if (!(estack[0] instanceof Div || estack[0] instanceof Body)) {
reportFatal(errorHandler, "Parent of <div> element is not <body> or <div> at " + this.line + "," + this.column + ")");
}
var d = new Div();
d.initFromNode(doc, estack[0], node, xmllangstack[0], errorHandler);
/* transform smpte:backgroundImage to TTML2 image element */
var bi = d.styleAttrs[imscStyles.byName.backgroundImage.qname];
if (bi) {
d.contents.push(new Image(bi));
delete d.styleAttrs[imscStyles.byName.backgroundImage.qname];
}
estack[0].contents.push(d);
estack.unshift(d);
} else if (node.local === 'image') {
if (!(estack[0] instanceof Div)) {
reportFatal(errorHandler, "Parent of <image> element is not <div> at " + this.line + "," + this.column + ")");
}
var img = new Image();
img.initFromNode(doc, estack[0], node, xmllangstack[0], errorHandler);
estack[0].contents.push(img);
estack.unshift(img);
} else if (node.local === 'p') {
if (!(estack[0] instanceof Div)) {
reportFatal(errorHandler, "Parent of <p> element is not <div> at " + this.line + "," + this.column + ")");
}
var p = new P();
p.initFromNode(doc, estack[0], node, xmllangstack[0], errorHandler);
estack[0].contents.push(p);
estack.unshift(p);
} else if (node.local === 'span') {
if (!(estack[0] instanceof Span || estack[0] instanceof P)) {
reportFatal(errorHandler, "Parent of <span> element is not <span> or <p> at " + this.line + "," + this.column + ")");
}
var ns = new Span();
ns.initFromNode(doc, estack[0], node, xmllangstack[0], xmlspacestack[0], errorHandler);
estack[0].contents.push(ns);
estack.unshift(ns);
} else if (node.local === 'br') {
if (!(estack[0] instanceof Span || estack[0] instanceof P)) {
reportFatal(errorHandler, "Parent of <br> element is not <span> or <p> at " + this.line + "," + this.column + ")");
}
var nb = new Br();
nb.initFromNode(doc, estack[0], node, xmllangstack[0], errorHandler);
estack[0].contents.push(nb);
estack.unshift(nb);
} else if (node.local === 'set') {
if (!(estack[0] instanceof Span ||
estack[0] instanceof P ||
estack[0] instanceof Div ||
estack[0] instanceof Body ||
estack[0] instanceof Region ||
estack[0] instanceof Br)) {
reportFatal(errorHandler, "Parent of <set> element is not a content element or a region at " + this.line + "," + this.column + ")");
}
var st = new Set();
st.initFromNode(doc, estack[0], node, errorHandler);
estack[0].sets.push(st);
estack.unshift(st);
} else {
/* element in the TT namespace, but not a content element */
estack.unshift(new ForeignElement(node));
}
} else {
/* ignore elements not in the TTML namespace unless in metadata element */
estack.unshift(new ForeignElement(node));
}
/* handle metadata callbacks */
if (estack[0] instanceof ForeignElement) {
if (node.uri === imscNames.ns_tt &&
node.local === 'metadata') {
/* enter the metadata element */
metadata_depth++;
} else if (
metadata_depth > 0 &&
metadataHandler &&
'onOpenTag' in metadataHandler
) {
/* start of child of metadata element */
var attrs = [];
for (var a in node.attributes) {
attrs[node.attributes[a].uri + " " + node.attributes[a].local] =
{
uri: node.attributes[a].uri,
local: node.attributes[a].local,
value: node.attributes[a].value
};
}
metadataHandler.onOpenTag(node.uri, node.local, attrs);
}
}
};
// parse the document
p.write(xmlstring).close();
// all referential styling has been flatten, so delete styles
delete doc.head.styling.styles;
// create default region if no regions specified
var hasRegions = false;
/* AFAIK the only way to determine whether an object has members */
for (var i in doc.head.layout.regions) {
if (doc.head.layout.regions.hasOwnProperty(i)) {
hasRegions = true;
break;
}
}
if (!hasRegions) {
/* create default region */
var dr = Region.prototype.createDefaultRegion(doc.lang);
doc.head.layout.regions[dr.id] = dr;
}
/* resolve desired timing for regions */
for (var region_i in doc.head.layout.regions) {
if (! doc.head.layout.regions.hasOwnProperty(region_i)) continue;
resolveTiming(doc, doc.head.layout.regions[region_i], null, null);
}
/* resolve desired timing for content elements */
if (doc.body) {
resolveTiming(doc, doc.body, null, null);
}
/* remove undefined spans in ruby containers */
if (doc.body) {
cleanRubyContainers(doc.body);
}
return doc;
};
function cleanRubyContainers(element) {
if (! ('contents' in element)) return;
var rubyval = 'styleAttrs' in element ? element.styleAttrs[imscStyles.byName.ruby.qname] : null;
var isrubycontainer = (element.kind === 'span' && (rubyval === "container" || rubyval === "textContainer" || rubyval === "baseContainer"));
for (var i = element.contents.length - 1; i >= 0; i--) {
if (isrubycontainer && !('styleAttrs' in element.contents[i] && imscStyles.byName.ruby.qname in element.contents[i].styleAttrs)) {
/* prune undefined <span> in ruby containers */
delete element.contents[i];
} else {
cleanRubyContainers(element.contents[i]);
}
}
}
function resolveTiming(doc, element, prev_sibling, parent) {
/* are we in a seq container? */
var isinseq = parent && parent.timeContainer === "seq";
/* determine implicit begin */
var implicit_begin = 0; /* default */
if (parent) {
if (isinseq && prev_sibling) {
/*
* if seq time container, offset from the previous sibling end
*/
implicit_begin = prev_sibling.end;
} else {
implicit_begin = parent.begin;
}
}
/* compute desired begin */
element.begin = element.explicit_begin ? element.explicit_begin + implicit_begin : implicit_begin;
/* determine implicit end */
var implicit_end = element.begin;
var s = null;
if ("sets" in element) {
for (var set_i = 0; set_i < element.sets.length; set_i++) {
resolveTiming(doc, element.sets[set_i], s, element);
if (element.timeContainer === "seq") {
implicit_end = element.sets[set_i].end;
} else {
implicit_end = Math.max(implicit_end, element.sets[set_i].end);
}
s = element.sets[set_i];
}
}
if (!('contents' in element)) {
/* anonymous spans and regions and <set> and <br>s and spans with only children text nodes */
if (isinseq) {
/* in seq container, implicit duration is zero */
implicit_end = element.begin;
} else {
/* in par container, implicit duration is indefinite */
implicit_end = Number.POSITIVE_INFINITY;
}
} else if ("contents" in element) {
for (var content_i = 0; content_i < element.contents.length; content_i++) {
resolveTiming(doc, element.contents[content_i], s, element);
if (element.timeContainer === "seq") {
implicit_end = element.contents[content_i].end;
} else {
implicit_end = Math.max(implicit_end, element.contents[content_i].end);
}
s = element.contents[content_i];
}
}
/* determine desired end */
/* it is never made really clear in SMIL that the explicit end is offset by the implicit begin */
if (element.explicit_end !== null && element.explicit_dur !== null) {
element.end = Math.min(element.begin + element.explicit_dur, implicit_begin + element.explicit_end);
} else if (element.explicit_end === null && element.explicit_dur !== null) {
element.end = element.begin + element.explicit_dur;
} else if (element.explicit_end !== null && element.explicit_dur === null) {
element.end = implicit_begin + element.explicit_end;
} else {
element.end = implicit_end;
}
delete element.explicit_begin;
delete element.explicit_dur;
delete element.explicit_end;
doc._registerEvent(element);
}
function ForeignElement(node) {
this.node = node;
}
function TT() {
this.events = [];
this.head = new Head();
this.body = null;
}
TT.prototype.initFromNode = function (node, xmllang, errorHandler) {
/* compute cell resolution */
var cr = extractCellResolution(node, errorHandler);
this.cellLength = {
'h': new imscUtils.ComputedLength(0, 1/cr.h),
'w': new imscUtils.ComputedLength(1/cr.w, 0)
};
/* extract frame rate and tick rate */
var frtr = extractFrameAndTickRate(node, errorHandler);
this.effectiveFrameRate = frtr.effectiveFrameRate;
this.tickRate = frtr.tickRate;
/* extract aspect ratio */
this.aspectRatio = extractAspectRatio(node, errorHandler);
/* check timebase */
var attr = findAttribute(node, imscNames.ns_ttp, "timeBase");
if (attr !== null && attr !== "media") {
reportFatal(errorHandler, "Unsupported time base");
}
/* retrieve extent */
var e = extractExtent(node, errorHandler);
if (e === null) {
this.pxLength = {
'h': null,
'w': null
};
} else {
if (e.h.unit !== "px" || e.w.unit !== "px") {
reportFatal(errorHandler, "Extent on TT must be in px or absent");
}
this.pxLength = {
'h': new imscUtils.ComputedLength(0, 1 / e.h.value),
'w': new imscUtils.ComputedLength(1 / e.w.value, 0)
};
}
/** set root container dimensions to (1, 1) arbitrarily
* the root container is mapped to actual dimensions at rendering
**/
this.dimensions = {
'h': new imscUtils.ComputedLength(0, 1),
'w': new imscUtils.ComputedLength(1, 0)
};
/* xml:lang */
this.lang = xmllang;
};
/* register a temporal events */
TT.prototype._registerEvent = function (elem) {
/* skip if begin is not < then end */
if (elem.end <= elem.begin)
return;
/* index the begin time of the event */
var b_i = indexOf(this.events, elem.begin);
if (!b_i.found) {
this.events.splice(b_i.index, 0, elem.begin);
}
/* index the end time of the event */
if (elem.end !== Number.POSITIVE_INFINITY) {
var e_i = indexOf(this.events, elem.end);
if (!e_i.found) {
this.events.splice(e_i.index, 0, elem.end);
}
}
};
/*
* Retrieves the range of ISD times covered by the document
*
* @returns {Array} Array of two elements: min_begin_time and max_begin_time
*
*/
TT.prototype.getMediaTimeRange = function () {
return [this.events[0], this.events[this.events.length - 1]];
};
/*
* Returns list of ISD begin times
*
* @returns {Array}
*/
TT.prototype.getMediaTimeEvents = function () {
return this.events;
};
/*
* Represents a TTML Head element
*/
function Head() {
this.styling = new Styling();
this.layout = new Layout();
}
/*
* Represents a TTML Styling element
*/
function Styling() {
this.styles = {};
this.initials = {};
}
/*
* Represents a TTML Style element
*/
function Style() {
this.id = null;
this.styleAttrs = null;
this.styleRefs = null;
}
Style.prototype.initFromNode = function (node, errorHandler) {
this.id = elementGetXMLID(node);
this.styleAttrs = elementGetStyles(node, errorHandler);
this.styleRefs = elementGetStyleRefs(node);
};
/*
* Represents a TTML initial element
*/
function Initial() {
this.styleAttrs = null;
}
Initial.prototype.initFromNode = function (node, errorHandler) {
this.styleAttrs = {};
for (var i in node.attributes) {
if (node.attributes[i].uri === imscNames.ns_itts ||
node.attributes[i].uri === imscNames.ns_ebutts ||
node.attributes[i].uri === imscNames.ns_tts) {
var qname = node.attributes[i].uri + " " + node.attributes[i].local;