Skip to content

Commit

Permalink
run ./build/all.py
Browse files Browse the repository at this point in the history
  • Loading branch information
valotvince committed Jun 18, 2019
1 parent b6a49d8 commit 457bf65
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/text/cue.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ shaka.text.Cue = function(startTime, endTime, payload) {
* @exportInterface
*/
this.children = [];

/**
* @override
* @exportInterface
*/
this.spacer = false;
};


Expand Down
41 changes: 30 additions & 11 deletions lib/text/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ shaka.text.TtmlTextParser.prototype.parseMedia = function(data, time) {
styles,
regionElements,
cueRegions,
whitespaceTrim);
whitespaceTrim,
false);
if (cue) {
ret.push(cue);
}
Expand Down Expand Up @@ -292,6 +293,14 @@ shaka.text.TtmlTextParser.getLeafNodes_ = function(element) {
return result;
};

/**
* Get the leaf nodes that can act as cues
* (begin and end attributes)
*
* @param {Element} element
* @return {!Array.<!Element>}
* @private
*/
shaka.text.TtmlTextParser.getLeafCues_ = function(element) {
if (!element) {
return [];
Expand All @@ -300,6 +309,14 @@ shaka.text.TtmlTextParser.getLeafCues_ = function(element) {
return Array.from(element.querySelectorAll('[begin][end]'));
};


/**
* Trims and removes multiple spaces from a string
*
* @param {string} textContent
* @return {string}
* @private
*/
shaka.text.TtmlTextParser.sanitizeTextContent = function(textContent) {
return textContent
// Trim leading and trailing whitespace.
Expand All @@ -320,14 +337,15 @@ shaka.text.TtmlTextParser.sanitizeTextContent = function(textContent) {
* @param {!Array.<!Element>} regionElements
* @param {!Array.<!shaka.text.CueRegion>} cueRegions
* @param {boolean} whitespaceTrim
* @param {boolean} isChild
* @return {shaka.text.Cue}
* @private
*/
shaka.text.TtmlTextParser.parseCue_ = function(
cueElement, offset, rateInfo, metadataElements, styles,
regionElements, cueRegions, whitespaceTrim, isChild) {
if (isChild && cueElement.nodeName === 'br') {
const cue = new shaka.text.Cue();
const cue = new shaka.text.Cue(0, 0, '');
cue.spacer = true;

return cue;
Expand Down Expand Up @@ -373,7 +391,7 @@ shaka.text.TtmlTextParser.parseCue_ = function(
for (let i = 0; i < cueElement.childNodes.length; i++) {
const childNode = cueElement.childNodes[i];
const childCue = shaka.text.TtmlTextParser.parseCue_(
childNode,
/** @type {!Element} */ (childNode),
offset,
rateInfo,
metadataElements,
Expand Down Expand Up @@ -408,17 +426,17 @@ shaka.text.TtmlTextParser.parseCue_ = function(
cue.children = children;

// Get other properties if available.
const [regionElement] = shaka.text.TtmlTextParser.getElementFromCollection_(
cueElement, 'region', regionElements, /* prefix= */ '');
const regionElement = shaka.text.TtmlTextParser.getElementFromCollection_(
cueElement, 'region', regionElements, /* prefix= */ '')[0];
if (regionElement && regionElement.getAttribute('xml:id')) {
let regionId = regionElement.getAttribute('xml:id');
let regionsWithId = cueRegions.filter(function(region) {
return region.id == regionId;
});
cue.region = regionsWithId[0];
}
const [imageElement] = shaka.text.TtmlTextParser.getElementFromCollection_(
cueElement, 'smpte:backgroundImage', metadataElements, '#');
const imageElement = shaka.text.TtmlTextParser.getElementFromCollection_(
cueElement, 'smpte:backgroundImage', metadataElements, '#')[0];
shaka.text.TtmlTextParser.addStyle_(
cue,
cueElement,
Expand Down Expand Up @@ -756,8 +774,9 @@ shaka.text.TtmlTextParser.getStyleAttributeFromRegion_ = function(
}
}

let [style] = shaka.text.TtmlTextParser.getElementFromCollection_(
region, 'style', styles, /* prefix= */ '');
const style = shaka.text.TtmlTextParser.getElementFromCollection_(
region, 'style', styles, /* prefix= */ '')[0];

if (style) {
return XmlUtils.getAttributeNS(style, ttsNs, attribute);
}
Expand Down Expand Up @@ -794,7 +813,7 @@ shaka.text.TtmlTextParser.getStyleAttributeFromElement_ = function(
const inheritedStyles = shaka.text.TtmlTextParser.getElementFromCollection_(
cueElement, 'style', styles, /* prefix= */ '');

let styleValue;
let styleValue = null;

// The last value in our styles stack takes the precedence over the others
for (let i = 0; i < inheritedStyles.length; i++) {
Expand All @@ -821,7 +840,7 @@ shaka.text.TtmlTextParser.getStyleAttributeFromElement_ = function(
* @param {string} attributeName
* @param {!Array.<Element>} collection
* @param {string} prefixName
* @return {Element}
* @return {Array.<!Element>}
* @private
*/
shaka.text.TtmlTextParser.getElementFromCollection_ = function(
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
},
"license": "Apache-2.0",
"scripts": {
"prepublish": "in-publish && python build/checkversion.py && python build/all.py --force || not-in-publish",
"lint": "eslint './{demo,lib,ui}/**/*.js'"
"prepublish": "in-publish && python build/checkversion.py && python build/all.py --force || not-in-publish"
}
}
15 changes: 15 additions & 0 deletions ui/text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ shaka.ui.TextDisplayer = class {
}
}

/**
* Displays children cues of a cue
*
* @param {Element} container
* @param {!shaka.extern.Cue} cue
* @returns {Element} the created captions container
* @private
*/
displayChildrenCue_(container, cue) {
const captions = shaka.util.Dom.createHTMLElement('span');

Expand All @@ -199,6 +207,13 @@ shaka.ui.TextDisplayer = class {
return captions;
}

/**
* Displays a cue
*
* @param {Element} container
* @param {!shaka.extern.Cue} cue
* @private
*/
displayCue_(container, cue) {
if (cue.children.length) {
const childrenContainer = shaka.util.Dom.createHTMLElement('p');
Expand Down

0 comments on commit 457bf65

Please sign in to comment.