Class: shaka.text.TtmlTextParser

Constructor

new TtmlTextParser()

Implements:
Source:

Classes

RateInfo_
Contains information about frame/subframe rate and frame rate multiplier for time in frame format.

Members

genericFontFamilies_ :Object<string, string>

The font families of the generic TTML font families.
Type:
  • Object<string, string>
Source:

parameterNs_ :Array<string>

The namespace URL for TTML parameters. Can be assigned any name in the TTML document, not just "ttp:", so we use this with getAttributeNS() to ensure that we support arbitrary namespace names.
Type:
  • Array<string>
Source:

percentValue_ :RegExp

Type:
  • RegExp
Source:
Example
0.6% 90% 300% 1000%

pixelValues_ :RegExp

Type:
  • RegExp
Source:
Example
100px

rubyAlignments_ :Object<string, string>

The CSS ruby-align values, by their TTML name.
Type:
  • Object<string, string>
Source:

rubyTags_ :Object<string, string>

The HTML elements of the parts of ruby, by their TTML name. The delimiters are only shown by browsers which do not support ruby.
Type:
  • Object<string, string>
Source:

smpteNsList_ :Array<string>

The supported namespace URLs for SMPTE fields.
Type:
  • Array<string>
Source:

styleEbuttsNs_ :string

The namespace URL for EBU TTML styles. Can be assigned any name in the TTML document, not just "ebutts:", so we use this with getAttributeNS() to ensure that we support arbitrary namespace names.
Type:
  • string
Source:

styleNs_ :Array<string>

The namespace URL for TTML styles. Can be assigned any name in the TTML document, not just "tts:", so we use this with getAttributeNS() to ensure that we support arbitrary namespace names.
Type:
  • Array<string>
Source:

textAlignments_ :Object<string, !Array<?>>

The position alignment and the line alignment of each text alignment.
Type:
  • Object<string, !Array<?>>
Source:

textDecorations_ :Object<string, shaka.text.Cue.textDecoration>

The text decorations, by their lower case TTML name.
Type:
Source:

timeColonFormat_ :RegExp

Type:
  • RegExp
Source:
Example
00:00:40, 00:40, 01:02:43.0345555, 02:43.03 or 02:45.5

timeColonFormatFrames_ :RegExp

Type:
  • RegExp
Source:
Example
00:00:40:07 (7 frames) or 00:00:40:07.1 (7 frames, 1 subframe)

timeFramesOrTicksFormat_ :RegExp

Type:
  • RegExp
Source:
Example
75f or 75.5f frames, or 50t or 50.5t ticks

timeHMSFormat_ :RegExp

Type:
  • RegExp
Source:
Example
3.45h, 3m, 4.20s or 500ms

transparentColor_ :RegExp

Matches no color, and fully transparent colors.
Type:
  • RegExp
Source:
Example
transparent, #ff000000 or rgba(255,0,0,0)

ttmlNs_ :Array<string>

Supported TTML element namespaces. The empty namespace preserves support for legacy documents that omit namespace declarations.
Type:
  • Array<string>
Source:

unicodeBidi_ :Object<string, string>

The CSS unicode-bidi value of each TTML unicodeBidi value.
Type:
  • Object<string, string>
Source:

unitValues_ :RegExp

Type:
  • RegExp
Source:
Example
100px, 8em, 0.80c, 6.667rh

manifestType_ :string

Type:
  • string
Source:

pixelExtent_ :?{width: number, height: number}

The size of the root container of the document being parsed, in pixels, if its tts:extent is in pixels.
Type:
  • ?{width: number, height: number}
Source:

preservedCues_ :WeakSet<!shaka.text.Cue>

The cues of the text whose white space is preserved.
Type:
Source:

rubyContainers_ :WeakMap<!shaka.text.Cue, string>

The ruby base containers and ruby text containers, by their cue, which are rearranged into the ruby of their ruby container.
Type:
Source:

Methods

animateRegions_(cuesnon-null, animatedRegions) → {Array<!shaka.text.Cue>}

Splits the cues of the animated regions at the boundaries of the animations, so that each part is presented in the region animated as it is during its interval.
Parameters:
Name Type Description
cues Array<!shaka.text.Cue>
animatedRegions shaka.text.TtmlTextParser.RegionAnimations_
Source:
Returns:
Type
Array<!shaka.text.Cue>

clipCue_(cuenon-null, start, end) → {shaka.text.Cue}

Clips the times of a cue and of its nested cues to an interval.
Parameters:
Name Type Description
cue shaka.text.Cue
start number
end number
Source:
Returns:
The cue, or null if it is outside of the interval.
Type
shaka.text.Cue

getLineage_(elementnon-null, parentElementnullable) → {Array<!shaka.extern.xml.Node>}

Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
parentElement shaka.extern.xml.Node <nullable>
Source:
Returns:
The ancestors of the element, from the body, and the element.
Type
Array<!shaka.extern.xml.Node>

getName_(node) → {string}

Parameters:
Name Type Description
node shaka.extern.xml.Node | string
Source:
Returns:
The local name of the node if it is a TTML element, or an empty string otherwise.
Type
string

getRegionPadding_(padding, regionnon-null, writingModenullable, toRootPercentage) → {string}

Converts the padding of a region to its top, right, bottom and left lengths, in pixels or in percentage of the height or width of the region. The padding is expressed as the before, end, after and start lengths, relative to the writing mode of the region. See https://www.w3.org/TR/ttml1/#style-attribute-padding
Parameters:
Name Type Attributes Description
padding string
region shaka.text.CueRegion
writingMode string <nullable>
toRootPercentage function(string, boolean): ?number
Source:
Returns:
Type
string

getRegionPosition_(position, regionnon-null, toRootPercentage) → {Array<number>}

Converts the position of a region to the position of its top left corner, in percentage of the root container. A percentage of the position is relative to the space which is not occupied by the region, like a CSS background position. See https://www.w3.org/TR/ttml2/#style-value-position
Parameters:
Name Type Description
position string
region shaka.text.CueRegion
toRootPercentage function(string, boolean): ?number
Source:
Returns:
The horizontal and vertical positions.
Type
Array<number>

getTimedChildren_(elementnon-null) → {Array<(!shaka.extern.xml.Node|string)>}

Gets the children of an element which take part in its timing, or null if the element has no children for timing purposes.
Parameters:
Name Type Description
element shaka.extern.xml.Node
Source:
Returns:
Type
Array<(!shaka.extern.xml.Node|string)>

hasTimeAttributes_(elementnon-null) → {boolean}

Parameters:
Name Type Description
element shaka.extern.xml.Node
Source:
Returns:
True if the element has a begin, end or dur attribute.
Type
boolean

isContentElement_(node) → {boolean}

Parameters:
Name Type Description
node shaka.extern.xml.Node | string
Source:
Returns:
True if the node is a content element:
,

, or
.

Type
boolean

isSeqContainer_(elementnon-null) → {boolean}

Parameters:
Name Type Description
element shaka.extern.xml.Node
Source:
Returns:
True if the element is a sequential time container.
Type
boolean

parseLength_(value) → {Array<string>}

Parameters:
Name Type Description
value string
Source:
Returns:
The number and the unit of the length, at the indexes 1 and 2, or null if the value is not a length.
Type
Array<string>

round_(value) → {number}

Parameters:
Name Type Description
value number
Source:
Returns:
The value, without the rounding errors of floating point numbers, like 0.30000000000000004.
Type
number

splitTimeline_(start, end, itemsnon-null, getInterval) → {Array<{start: number, end: number, active: !Array<T>}>}

Splits an interval at the boundaries of the items, including parts with no active items. Active items retain their original order, and their end time is exclusive.
Parameters:
Name Type Description
start number
end number
items Array<T>
getInterval function(T): shaka.text.TtmlTextParser.Interval_
Source:
Returns:
Type
Array<{start: number, end: number, active: !Array<T>}>

splitValues_(value) → {Array<string>}

Splits a value at its spaces, except inside colors like rgba(0, 0, 0, 0).
Parameters:
Name Type Description
value string
Source:
Returns:
Type
Array<string>

timeSpaces_(childrennon-null) → {Array<!shaka.text.Cue>}

Times the spaces between the elements of the content, so that they are only presented while the elements on both sides are, as a space at the start or at the end of a line is not presented.
Parameters:
Name Type Description
children Array<{cues: !Array<!shaka.text.Cue>, isSpace: boolean}>
Source:
Returns:
The cues of the children.
Type
Array<!shaka.text.Cue>

toCssLength_(value) → {string}

Converts a TTML length to a length for the displayer. A percentage is relative to the font size.
Parameters:
Name Type Description
value string
Source:
Returns:
The length in pixels, "em", cells or relative to the root container, or null if the value is not a length.
Type
string

addStyle_(cuenon-null, cueElementnon-null, parentElementnullable, regionnullable, imageElement, imageUrinullable, stylesnon-null, isNested, isLeaf)

Adds applicable style properties to a cue.
Parameters:
Name Type Attributes Description
cue shaka.text.Cue
cueElement shaka.extern.xml.Node
parentElement shaka.extern.xml.Node <nullable>
region shaka.extern.xml.Node <nullable>
imageElement shaka.extern.xml.Node
imageUri string <nullable>
styles Array<!shaka.extern.xml.Node>
isNested boolean
isLeaf boolean
Source:

addTextDecoration_(cuenon-null, decoration)

Parses text decoration values and adds/removes them to/from the cue.
Parameters:
Name Type Description
cue shaka.text.Cue
decoration string
Source:

animate_(cuenon-null, elementnon-null, stylesnon-null, intervalsnon-null, timeContext, addStyle) → {Array<!shaka.text.Cue>}

Applies the animations of an element, the elements which change its style during their interval, by splitting its cue at their boundaries. The cue is also removed while the element is not displayed. See https://www.w3.org/TR/ttml1/#animation-vocabulary-set
Parameters:
Name Type Description
cue shaka.text.Cue
element shaka.extern.xml.Node
styles Array<!shaka.extern.xml.Node>
intervals shaka.text.TtmlTextParser.Intervals_
timeContext shaka.extern.TextParser.TimeContext
addStyle function(!shaka.text.Cue, !shaka.extern.xml.Node) Adds the style of an element to a cue.
Source:
Returns:
Type
Array<!shaka.text.Cue>

collapseSpaces_(cuenon-null)

Collapses the white space of a paragraph like XSL does: the spaces at the start and at the end of the lines are removed, and so are the spaces which follow another space in the next span. A space between two texts which are not presented at the same times, like the words of a roll-up caption, is only presented while both are. See https://www.w3.org/TR/ttml2/#content-attribute-space
Parameters:
Name Type Description
cue shaka.text.Cue
Source:

convertTextShadow_(textShadow) → {string}

Converts a tts:textShadow value to a CSS text shadow, where the lengths can also be in cells or relative to the root container, like "1c" or "1rh".
Parameters:
Name Type Description
textShadow string
Source:
Returns:
Type
string

convertTTMLrgbaToHTMLrgba_(color) → {string}

Ensures any TTML RGBA's alpha range of 0-255 is converted to 0-1.
Parameters:
Name Type Description
color string
Source:
Returns:
Type
string

getAncestorStyleAttribute_(elementnullable, stylesnon-null, attribute) → {string}

Finds a style attribute specified on an element or on its closest ancestor which specifies it.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node <nullable>
styles Array<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

getAnimatedElement_(elementnon-null, activenon-null, stylesnon-null) → {shaka.extern.xml.Node}

Applies the styles of the active animations of an element to a copy of it.
Parameters:
Name Type Description
element shaka.extern.xml.Node
active Array<!shaka.extern.xml.Node> The active elements.
styles Array<!shaka.extern.xml.Node>
Source:
Returns:
Type
shaka.extern.xml.Node

getCellResolution_(cellResolutionnullable) → {?{columns: number, rows: number}}

If ttp:cellResolution provided returns cell resolution info with number of columns and rows into which the Root Container Region area is divided
Parameters:
Name Type Attributes Description
cellResolution string <nullable>
Source:
Returns:
Type
?{columns: number, rows: number}

getElementsFromCollection_(element, attributeName, collectionnon-null, prefixName, nsNameopt) → {Array<!shaka.extern.xml.Node>}

Selects items from |collection| whose id matches |attributeName| from |element|.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
attributeName string
collection Array<shaka.extern.xml.Node>
prefixName string
nsName string <optional>
Source:
Returns:
Type
Array<!shaka.extern.xml.Node>

getInheritedAttribute_(elementnon-null, attributeName, nsNameopt) → {string}

Traverses upwards from a given node until a given attribute is found.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
attributeName string
nsName string <optional>
Source:
Returns:
Type
string

getInheritedStyleAttribute_(elementnon-null, stylesnon-null, attribute, styleElementsopt, non-null) → {string}

Finds a specified attribute on an element's styles and the styles those styles inherit from.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
styles Array<!shaka.extern.xml.Node>
attribute string
styleElements Array<!shaka.extern.xml.Node> <optional>
The styles to look into, instead of the styles referenced by the element.
Source:
Returns:
Type
string

getSpecifiedStyleAttribute_(elementnon-null, stylesnon-null, attribute) → {string}

Finds a style attribute specified on an element itself, inline or in the styles it references, but not inherited from its ancestors.
Parameters:
Name Type Description
element shaka.extern.xml.Node
styles Array<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

getStyleAttribute_(cueElementnon-null, regionnullable, stylesnon-null, attribute, shouldInheritRegionStylesopt) → {string}

Finds a specified attribute on either the original cue element or its associated region and returns the value if the attribute was found.
Parameters:
Name Type Attributes Default Description
cueElement shaka.extern.xml.Node
region shaka.extern.xml.Node <nullable>
styles Array<!shaka.extern.xml.Node>
attribute string
shouldInheritRegionStyles boolean <optional>
true
Source:
Returns:
Type
string

getStyleAttributeFromElement_(cueElementnon-null, stylesnon-null, attribute) → {string}

Finds a specified attribute on the cue element and returns the value if the attribute was found.
Parameters:
Name Type Description
cueElement shaka.extern.xml.Node
styles Array<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

getStyleAttributeFromRegion_(regionnullable, stylesnon-null, attribute) → {string}

Finds a specified attribute on the element's associated region and returns the value if the attribute was found.
Parameters:
Name Type Attributes Description
region shaka.extern.xml.Node <nullable>
styles Array<!shaka.extern.xml.Node>
attribute string
Source:
Returns:
Type
string

parseCue_(cueNodenon-null, timeContext, rateInfonon-null, metadataElementsnon-null, stylesnon-null, regionElementsnon-null, cueRegionsnon-null, collapseMultipleSpaces, cellResolutionnullable, parentCueElementnullable, isContent, urinullable, imagesnon-null, intervalsnon-null, parentInterval, usesRegions) → {Array<!shaka.text.Cue>}

Parses a TTML node into a Cue.
Parameters:
Name Type Attributes Description
cueNode shaka.extern.xml.Node
timeContext shaka.extern.TextParser.TimeContext
rateInfo shaka.text.TtmlTextParser.RateInfo_
metadataElements Array<!shaka.extern.xml.Node>
styles Array<!shaka.extern.xml.Node>
regionElements Array<!shaka.extern.xml.Node>
cueRegions Array<!shaka.text.CueRegion>
collapseMultipleSpaces boolean
cellResolution ?{columns: number, rows: number} <nullable>
parentCueElement shaka.extern.xml.Node <nullable>
isContent boolean
uri string | undefined <nullable>
images Array<string>
intervals shaka.text.TtmlTextParser.Intervals_ The intervals resolved by resolveTiming_.
parentInterval shaka.text.TtmlTextParser.Interval_ The active interval of the parent element.
usesRegions boolean Whether the content is flowed into regions, so that the content which is not in any region is not presented.
Source:
Returns:
The cues of the node, as an animated element is split into several cues.
Type
Array<!shaka.text.Cue>

parseCueRegion_(regionElementnon-null, stylesnon-null, globalExtentnullable, cellResolutionnullable) → {shaka.text.CueRegion}

Parses an Element into a TextTrackCue or VTTCue.
Parameters:
Name Type Attributes Description
regionElement shaka.extern.xml.Node
styles Array<!shaka.extern.xml.Node> Defined in the top of tt element and used principally for images.
globalExtent string <nullable>
cellResolution ?{columns: number, rows: number} <nullable>
Source:
Returns:
Type
shaka.text.CueRegion

parseInit(datanon-null)

Parse an initialization segment. Some formats do not have init segments so this won't always be called.
Parameters:
Name Type Description
data Uint8Array The data that makes up the init segment.
Implements:
Source:

parseMedia(datanon-null, timeContext, urinullable, imagesnon-null) → {Array<!shaka.text.Cue>}

Parse a media segment and return the cues that make up the segment.
Parameters:
Name Type Attributes Description
data Uint8Array The next section of buffer.
timeContext shaka.extern.TextParser.TimeContext The time information that should be used to adjust the times values for each cue.
uri string | undefined <nullable>
The media uri.
images Array<string>
Implements:
Source:
Returns:
Type
Array<!shaka.text.Cue>

parseTimeAttribute_(text, rateInfonon-null) → {number}

Parses a TTML time from the given attribute text.
Parameters:
Name Type Description
text string
rateInfo shaka.text.TtmlTextParser.RateInfo_
Source:
Returns:
Type
number

rearrangeRuby_(cuenon-null)

Rearranges a ruby container with a ruby base container into one ruby per base, as HTML has no containers for bases and annotations. A base with annotations from two ruby text containers is in a ruby annotated by the second one, in a ruby annotated by the first one.
Parameters:
Name Type Description
cue shaka.text.Cue
Source:

resolveFontSize_(elementnon-null, parentElementnullable, regionnullable, stylesnon-null) → {string}

Resolves the font size of an element. A percentage is relative to the font size of the parent element, and to a cell for the region, but the displayer always resolves a percentage relative to a cell.
Parameters:
Name Type Attributes Description
element shaka.extern.xml.Node
parentElement shaka.extern.xml.Node <nullable>
region shaka.extern.xml.Node <nullable>
styles Array<!shaka.extern.xml.Node>
Source:
Returns:
The font size, in cells, pixels, percentage of a cell or relative to the root container, or null if it can't be resolved.
Type
string

resolveTiming_(elementnon-null, rateInfonon-null, implicitBegin, isInSeq, intervalsnon-null) → {shaka.text.TtmlTextParser.Interval_}

Resolves the interval of an element and of its descendants, following the TTML timing model: an element begins relative to its parent in a parallel time container, and relative to the end of its previous sibling in a sequential one. Without an explicit end or duration, an element ends with its children, and an element without children lasts until its parent ends in a parallel time container, and has no duration in a sequential one. See https://www.w3.org/TR/ttml1/#timing-time-intervals The intervals are not clipped to the interval of the parent.
Parameters:
Name Type Description
element shaka.extern.xml.Node
rateInfo shaka.text.TtmlTextParser.RateInfo_
implicitBegin number The time the explicit times of the element are relative to.
isInSeq boolean Whether the parent is a sequential time container.
intervals shaka.text.TtmlTextParser.Intervals_ The resolved intervals, by element.
Source:
Returns:
Type
shaka.text.TtmlTextParser.Interval_

setManifestType(manifestType)

Notifies the manifest type.
Parameters:
Name Type Description
manifestType string
Implements:
Source:

toRootLength_(value, isWidth) → {string}

Converts the lengths in pixels of a value to lengths relative to the root container, when the size of the root container is known in pixels, so that they are scaled with the video like imscJS does.
Parameters:
Name Type Description
value string
isWidth boolean Whether the lengths are along the width of the root container, rather than along its height.
Source:
Returns:
Type
string

Type Definitions

Interval_

The interval during which an element is active, in seconds. An infinite end means that the duration is indefinite.
Type:
  • {start: number, end: number}
Source:

Intervals_

The intervals of the elements of a document.
Type:
Source:

RegionAnimation_

The region an animated region is presented as during an interval of its animations.
Type:
Source:

RegionAnimations_

The animations of the animated regions, by their identifier.
Type:
Source:

RegionLength_

A length of the origin or the extent of a region. isPixels tells whether it was specified in pixels, even if it is now a percentage of the root container.
Type:
Source: