Source: externs/shaka/text.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @externs
  8. */
  9. /**
  10. * @interface
  11. * @exportDoc
  12. */
  13. shaka.extern.CueRegion = class {
  14. constructor() {
  15. /**
  16. * Region identifier.
  17. * @type {string}
  18. * @exportDoc
  19. */
  20. this.id;
  21. /**
  22. * The X offset to start the rendering area in viewportAnchorUnits of the
  23. * video width.
  24. * @type {number}
  25. * @exportDoc
  26. */
  27. this.viewportAnchorX;
  28. /**
  29. * The X offset to start the rendering area in viewportAnchorUnits of the
  30. * video height.
  31. * @type {number}
  32. * @exportDoc
  33. */
  34. this.viewportAnchorY;
  35. /**
  36. * The X offset to start the rendering area in percentage (0-100) of this
  37. * region width.
  38. * @type {number}
  39. * @exportDoc
  40. */
  41. this.regionAnchorX;
  42. /**
  43. * The Y offset to start the rendering area in percentage (0-100) of the
  44. * region height.
  45. * @type {number}
  46. * @exportDoc
  47. */
  48. this.regionAnchorY;
  49. /**
  50. * The width of the rendering area in widthUnits.
  51. * @type {number}
  52. * @exportDoc
  53. */
  54. this.width;
  55. /**
  56. * The width of the rendering area in heightUnits.
  57. * @type {number}
  58. * @exportDoc
  59. */
  60. this.height;
  61. /**
  62. * The units (percentage, pixels or lines) the region height is in.
  63. * @type {shaka.text.CueRegion.units}
  64. * @exportDoc
  65. */
  66. this.heightUnits;
  67. /**
  68. * The units (percentage or pixels) the region width is in.
  69. * @type {shaka.text.CueRegion.units}
  70. * @exportDoc
  71. */
  72. this.widthUnits;
  73. /**
  74. * The units (percentage or pixels) the region viewportAnchors are in.
  75. * @type {shaka.text.CueRegion.units}
  76. * @exportDoc
  77. */
  78. this.viewportAnchorUnits;
  79. /**
  80. * If scroll=UP, it means that cues in the region will be added to the
  81. * bottom of the region and will push any already displayed cues in the
  82. * region up. Otherwise (scroll=NONE) cues will stay fixed at the location
  83. * they were first painted in.
  84. * @type {shaka.text.CueRegion.scrollMode}
  85. * @exportDoc
  86. */
  87. this.scroll;
  88. }
  89. };
  90. /**
  91. * @interface
  92. * @exportDoc
  93. */
  94. shaka.extern.Cue = class {
  95. constructor() {
  96. /**
  97. * The start time of the cue in seconds, relative to the start of the
  98. * presentation.
  99. * @type {number}
  100. * @exportDoc
  101. */
  102. this.startTime;
  103. /**
  104. * The end time of the cue in seconds, relative to the start of the
  105. * presentation.
  106. * @type {number}
  107. * @exportDoc
  108. */
  109. this.endTime;
  110. /**
  111. * The text payload of the cue. If nestedCues is non-empty, this should be
  112. * empty. Top-level block containers should have no payload of their own.
  113. * @type {string}
  114. * @exportDoc
  115. */
  116. this.payload;
  117. /**
  118. * The region to render the cue into. Only supported on top-level cues,
  119. * because nested cues are inline elements.
  120. * @type {shaka.extern.CueRegion}
  121. * @exportDoc
  122. */
  123. this.region;
  124. /**
  125. * The indent (in percent) of the cue box in the direction defined by the
  126. * writing direction.
  127. * @type {?number}
  128. * @exportDoc
  129. */
  130. this.position;
  131. /**
  132. * Position alignment of the cue.
  133. * @type {shaka.text.Cue.positionAlign}
  134. * @exportDoc
  135. */
  136. this.positionAlign;
  137. /**
  138. * Size of the cue box (in percents), where 0 means "auto".
  139. * @type {number}
  140. * @exportDoc
  141. */
  142. this.size;
  143. /**
  144. * Alignment of the text inside the cue box.
  145. * @type {shaka.text.Cue.textAlign}
  146. * @exportDoc
  147. */
  148. this.textAlign;
  149. /**
  150. * Text direction of the cue.
  151. * @type {shaka.text.Cue.direction}
  152. * @exportDoc
  153. */
  154. this.direction;
  155. /**
  156. * Text writing mode of the cue.
  157. * @type {shaka.text.Cue.writingMode}
  158. * @exportDoc
  159. */
  160. this.writingMode;
  161. /**
  162. * The way to interpret line field. (Either as an integer line number or
  163. * percentage from the display box).
  164. * @type {shaka.text.Cue.lineInterpretation}
  165. * @exportDoc
  166. */
  167. this.lineInterpretation;
  168. /**
  169. * The offset from the display box in either number of lines or
  170. * percentage depending on the value of lineInterpretation.
  171. * @type {?number}
  172. * @exportDoc
  173. */
  174. this.line;
  175. /**
  176. * Separation between line areas inside the cue box in px or em
  177. * (e.g. '100px'/'100em'). If not specified, this should be no less than
  178. * the largest font size applied to the text in the cue.
  179. * @type {string}.
  180. * @exportDoc
  181. */
  182. this.lineHeight;
  183. /**
  184. * Line alignment of the cue box.
  185. * Start alignment means the cue box’s top side (for horizontal cues), left
  186. * side (for vertical growing right), or right side (for vertical growing
  187. * left) is aligned at the line.
  188. * Center alignment means the cue box is centered at the line.
  189. * End alignment The cue box’s bottom side (for horizontal cues), right side
  190. * (for vertical growing right), or left side (for vertical growing left) is
  191. * aligned at the line.
  192. * @type {shaka.text.Cue.lineAlign}
  193. * @exportDoc
  194. */
  195. this.lineAlign;
  196. /**
  197. * Vertical alignments of the cues within their extents.
  198. * 'BEFORE' means displaying the captions at the top of the text display
  199. * container box, 'CENTER' means in the middle, 'AFTER' means at the bottom.
  200. * @type {shaka.text.Cue.displayAlign}
  201. * @exportDoc
  202. */
  203. this.displayAlign;
  204. /**
  205. * Text color as a CSS color, e.g. "#FFFFFF" or "white".
  206. * @type {string}
  207. * @exportDoc
  208. */
  209. this.color;
  210. /**
  211. * Text background color as a CSS color, e.g. "#FFFFFF" or "white".
  212. * @type {string}
  213. * @exportDoc
  214. */
  215. this.backgroundColor;
  216. /**
  217. * The number of horizontal and vertical cells into which the Root Container
  218. * Region area is divided.
  219. *
  220. * @type {{ columns: number, rows: number }}
  221. * @exportDoc
  222. */
  223. this.cellResolution;
  224. /**
  225. * The URL of the background image, e.g. "data:[mime type];base64,[data]".
  226. * @type {string}
  227. * @exportDoc
  228. */
  229. this.backgroundImage;
  230. /**
  231. * The border around this cue as a CSS border.
  232. * @type {string}
  233. * @exportDoc
  234. */
  235. this.border;
  236. /**
  237. * Text font size in px or em (e.g. '100px'/'100em').
  238. * @type {string}
  239. * @exportDoc
  240. */
  241. this.fontSize;
  242. /**
  243. * Text font weight. Either normal or bold.
  244. * @type {shaka.text.Cue.fontWeight}
  245. * @exportDoc
  246. */
  247. this.fontWeight;
  248. /**
  249. * Text font style. Normal, italic or oblique.
  250. * @type {shaka.text.Cue.fontStyle}
  251. * @exportDoc
  252. */
  253. this.fontStyle;
  254. /**
  255. * Text font family.
  256. * @type {string}
  257. * @exportDoc
  258. */
  259. this.fontFamily;
  260. /**
  261. * Text shadow color as a CSS text-shadow value.
  262. * @type {string}
  263. * @exportDoc
  264. */
  265. this.textShadow = '';
  266. /**
  267. * Text stroke color as a CSS color, e.g. "#FFFFFF" or "white".
  268. * @type {string}
  269. * @exportDoc
  270. */
  271. this.textStrokeColor;
  272. /**
  273. * Text stroke width as a CSS stroke-width value.
  274. * @type {string}
  275. * @exportDoc
  276. */
  277. this.textStrokeWidth;
  278. /**
  279. * Text letter spacing as a CSS letter-spacing value.
  280. * @type {string}
  281. * @exportDoc
  282. */
  283. this.letterSpacing;
  284. /**
  285. * Text line padding as a CSS line-padding value.
  286. * @type {string}
  287. * @exportDoc
  288. */
  289. this.linePadding;
  290. /**
  291. * Opacity of the cue element, from 0-1.
  292. * @type {number}
  293. * @exportDoc
  294. */
  295. this.opacity;
  296. /**
  297. * Text decoration. A combination of underline, overline
  298. * and line through. Empty array means no decoration.
  299. * @type {!Array.<!shaka.text.Cue.textDecoration>}
  300. * @exportDoc
  301. */
  302. this.textDecoration;
  303. /**
  304. * Whether or not line wrapping should be applied to the cue.
  305. * @type {boolean}
  306. * @exportDoc
  307. */
  308. this.wrapLine;
  309. /**
  310. * Id of the cue.
  311. * @type {string}
  312. * @exportDoc
  313. */
  314. this.id;
  315. /**
  316. * Nested cues, which should be laid out horizontally in one block.
  317. * Top-level cues are blocks, and nested cues are inline elements.
  318. * Cues can be nested arbitrarily deeply.
  319. * @type {!Array.<!shaka.extern.Cue>}
  320. * @exportDoc
  321. */
  322. this.nestedCues;
  323. /**
  324. * If true, this represents a container element that is "above" the main
  325. * cues. For example, the <body> and <div> tags that contain the <p> tags
  326. * in a TTML file. This controls the flow of the final cues; any nested cues
  327. * within an "isContainer" cue will be laid out as separate lines.
  328. * @type {boolean}
  329. * @exportDoc
  330. */
  331. this.isContainer;
  332. /**
  333. * Whether or not the cue only acts as a line break between two nested cues.
  334. * Should only appear in nested cues.
  335. * @type {boolean}
  336. * @exportDoc
  337. */
  338. this.lineBreak;
  339. }
  340. };
  341. /**
  342. * An interface for plugins that parse text tracks.
  343. *
  344. * @interface
  345. * @exportDoc
  346. */
  347. shaka.extern.TextParser = class {
  348. /**
  349. * Parse an initialization segment. Some formats do not have init
  350. * segments so this won't always be called.
  351. *
  352. * @param {!Uint8Array} data
  353. * The data that makes up the init segment.
  354. *
  355. * @exportDoc
  356. */
  357. parseInit(data) {}
  358. /**
  359. * Parse a media segment and return the cues that make up the segment.
  360. *
  361. * @param {!Uint8Array} data
  362. * The next section of buffer.
  363. * @param {shaka.extern.TextParser.TimeContext} timeContext
  364. * The time information that should be used to adjust the times values
  365. * for each cue.
  366. * @param {?(string|undefined)} uri
  367. * The media uri.
  368. * @return {!Array.<!shaka.extern.Cue>}
  369. *
  370. * @exportDoc
  371. */
  372. parseMedia(data, timeContext, uri) {}
  373. /**
  374. * Notifies the stream if the manifest is in sequence mode or not.
  375. *
  376. * @param {boolean} sequenceMode
  377. */
  378. setSequenceMode(sequenceMode) {}
  379. };
  380. /**
  381. * A collection of time offsets used to adjust text cue times.
  382. *
  383. * @typedef {{
  384. * periodStart: number,
  385. * segmentStart: number,
  386. * segmentEnd: number,
  387. * vttOffset: number
  388. * }}
  389. *
  390. * @property {number} periodStart
  391. * The absolute start time of the period in seconds.
  392. * @property {number} segmentStart
  393. * The absolute start time of the segment in seconds.
  394. * @property {number} segmentEnd
  395. * The absolute end time of the segment in seconds.
  396. * @property {number} vttOffset
  397. * The start time relative to either segment or period start depending
  398. * on <code>segmentRelativeVttTiming</code> configuration.
  399. *
  400. * @exportDoc
  401. */
  402. shaka.extern.TextParser.TimeContext;
  403. /**
  404. * @typedef {function():!shaka.extern.TextParser}
  405. * @exportDoc
  406. */
  407. shaka.extern.TextParserPlugin;
  408. /**
  409. * @summary
  410. * An interface for plugins that display text.
  411. *
  412. * @description
  413. * This should handle displaying the text cues on the page. This is given the
  414. * cues to display and told when to start and stop displaying. This should only
  415. * display the cues it is given and remove cues when told to.
  416. *
  417. * <p>
  418. * This should only change whether it is displaying the cues through the
  419. * <code>setTextVisibility</code> function; the app should not change the text
  420. * visibility outside the top-level Player methods. If you really want to
  421. * control text visibility outside the Player methods, you must set the
  422. * <code>streaming.alwaysStreamText</code> Player configuration value to
  423. * <code>true</code>.
  424. *
  425. * @interface
  426. * @extends {shaka.util.IDestroyable}
  427. * @exportDoc
  428. */
  429. shaka.extern.TextDisplayer = class {
  430. /**
  431. * @override
  432. * @exportDoc
  433. */
  434. destroy() {}
  435. /**
  436. * Append given text cues to the list of cues to be displayed.
  437. *
  438. * @param {!Array.<!shaka.text.Cue>} cues
  439. * Text cues to be appended.
  440. *
  441. * @exportDoc
  442. */
  443. append(cues) {}
  444. /**
  445. * Remove all cues that are fully contained by the given time range (relative
  446. * to the presentation). <code>endTime</code> will be greater to equal to
  447. * <code>startTime</code>. <code>remove</code> should only return
  448. * <code>false</code> if the displayer has been destroyed. If the displayer
  449. * has not been destroyed <code>remove</code> should return <code>true</code>.
  450. *
  451. * @param {number} startTime
  452. * @param {number} endTime
  453. *
  454. * @return {boolean}
  455. *
  456. * @exportDoc
  457. */
  458. remove(startTime, endTime) {}
  459. /**
  460. * Returns true if text is currently visible.
  461. *
  462. * @return {boolean}
  463. *
  464. * @exportDoc
  465. */
  466. isTextVisible() {}
  467. /**
  468. * Set text visibility.
  469. *
  470. * @param {boolean} on
  471. *
  472. * @exportDoc
  473. */
  474. setTextVisibility(on) {}
  475. };
  476. /**
  477. * A factory for creating a TextDisplayer.
  478. *
  479. * @typedef {function():!shaka.extern.TextDisplayer}
  480. * @exportDoc
  481. */
  482. shaka.extern.TextDisplayer.Factory;