@@ -138,7 +138,8 @@ shaka.text.TtmlTextParser.prototype.parseMedia = function(data, time) {
138138 styles ,
139139 regionElements ,
140140 cueRegions ,
141- whitespaceTrim ) ;
141+ whitespaceTrim ,
142+ false ) ;
142143 if ( cue ) {
143144 ret . push ( cue ) ;
144145 }
@@ -292,6 +293,14 @@ shaka.text.TtmlTextParser.getLeafNodes_ = function(element) {
292293 return result ;
293294} ;
294295
296+ /**
297+ * Get the leaf nodes that can act as cues
298+ * (begin and end attributes)
299+ *
300+ * @param {Element } element
301+ * @return {!Array.<!Element> }
302+ * @private
303+ */
295304shaka . text . TtmlTextParser . getLeafCues_ = function ( element ) {
296305 if ( ! element ) {
297306 return [ ] ;
@@ -300,6 +309,14 @@ shaka.text.TtmlTextParser.getLeafCues_ = function(element) {
300309 return Array . from ( element . querySelectorAll ( '[begin][end]' ) ) ;
301310} ;
302311
312+
313+ /**
314+ * Trims and removes multiple spaces from a string
315+ *
316+ * @param {string } textContent
317+ * @return {string }
318+ * @private
319+ */
303320shaka . text . TtmlTextParser . sanitizeTextContent = function ( textContent ) {
304321 return textContent
305322 // Trim leading and trailing whitespace.
@@ -320,14 +337,15 @@ shaka.text.TtmlTextParser.sanitizeTextContent = function(textContent) {
320337 * @param {!Array.<!Element> } regionElements
321338 * @param {!Array.<!shaka.text.CueRegion> } cueRegions
322339 * @param {boolean } whitespaceTrim
340+ * @param {boolean } isChild
323341 * @return {shaka.text.Cue }
324342 * @private
325343 */
326344shaka . text . TtmlTextParser . parseCue_ = function (
327345 cueElement , offset , rateInfo , metadataElements , styles ,
328346 regionElements , cueRegions , whitespaceTrim , isChild ) {
329347 if ( isChild && cueElement . nodeName === 'br' ) {
330- const cue = new shaka . text . Cue ( ) ;
348+ const cue = new shaka . text . Cue ( 0 , 0 , '' ) ;
331349 cue . spacer = true ;
332350
333351 return cue ;
@@ -373,7 +391,7 @@ shaka.text.TtmlTextParser.parseCue_ = function(
373391 for ( let i = 0 ; i < cueElement . childNodes . length ; i ++ ) {
374392 const childNode = cueElement . childNodes [ i ] ;
375393 const childCue = shaka . text . TtmlTextParser . parseCue_ (
376- childNode ,
394+ /** @type { !Element } */ ( childNode ) ,
377395 offset ,
378396 rateInfo ,
379397 metadataElements ,
@@ -408,17 +426,17 @@ shaka.text.TtmlTextParser.parseCue_ = function(
408426 cue . children = children ;
409427
410428 // Get other properties if available.
411- const [ regionElement ] = shaka . text . TtmlTextParser . getElementFromCollection_ (
412- cueElement , 'region' , regionElements , /* prefix= */ '' ) ;
429+ const regionElement = shaka . text . TtmlTextParser . getElementFromCollection_ (
430+ cueElement , 'region' , regionElements , /* prefix= */ '' ) [ 0 ] ;
413431 if ( regionElement && regionElement . getAttribute ( 'xml:id' ) ) {
414432 let regionId = regionElement . getAttribute ( 'xml:id' ) ;
415433 let regionsWithId = cueRegions . filter ( function ( region ) {
416434 return region . id == regionId ;
417435 } ) ;
418436 cue . region = regionsWithId [ 0 ] ;
419437 }
420- const [ imageElement ] = shaka . text . TtmlTextParser . getElementFromCollection_ (
421- cueElement , 'smpte:backgroundImage' , metadataElements , '#' ) ;
438+ const imageElement = shaka . text . TtmlTextParser . getElementFromCollection_ (
439+ cueElement , 'smpte:backgroundImage' , metadataElements , '#' ) [ 0 ] ;
422440 shaka . text . TtmlTextParser . addStyle_ (
423441 cue ,
424442 cueElement ,
@@ -756,8 +774,9 @@ shaka.text.TtmlTextParser.getStyleAttributeFromRegion_ = function(
756774 }
757775 }
758776
759- let [ style ] = shaka . text . TtmlTextParser . getElementFromCollection_ (
760- region , 'style' , styles , /* prefix= */ '' ) ;
777+ const style = shaka . text . TtmlTextParser . getElementFromCollection_ (
778+ region , 'style' , styles , /* prefix= */ '' ) [ 0 ] ;
779+
761780 if ( style ) {
762781 return XmlUtils . getAttributeNS ( style , ttsNs , attribute ) ;
763782 }
@@ -794,7 +813,7 @@ shaka.text.TtmlTextParser.getStyleAttributeFromElement_ = function(
794813 const inheritedStyles = shaka . text . TtmlTextParser . getElementFromCollection_ (
795814 cueElement , 'style' , styles , /* prefix= */ '' ) ;
796815
797- let styleValue ;
816+ let styleValue = null ;
798817
799818 // The last value in our styles stack takes the precedence over the others
800819 for ( let i = 0 ; i < inheritedStyles . length ; i ++ ) {
@@ -821,7 +840,7 @@ shaka.text.TtmlTextParser.getStyleAttributeFromElement_ = function(
821840 * @param {string } attributeName
822841 * @param {!Array.<Element> } collection
823842 * @param {string } prefixName
824- * @return {Element }
843+ * @return {Array.<! Element> }
825844 * @private
826845 */
827846shaka . text . TtmlTextParser . getElementFromCollection_ = function (
0 commit comments