Source: lib/text/cue.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.text.Cue');
  18. goog.provide('shaka.text.CueRegion');
  19. /**
  20. * Creates a Cue object.
  21. *
  22. * @param {number} startTime
  23. * @param {number} endTime
  24. * @param {string} payload
  25. *
  26. * @implements {shakaExtern.Cue}
  27. * @constructor
  28. * @struct
  29. * @export
  30. */
  31. shaka.text.Cue = function(startTime, endTime, payload) {
  32. const Cue = shaka.text.Cue;
  33. /**
  34. * @override
  35. * @exportInterface
  36. */
  37. this.startTime = startTime;
  38. /**
  39. * @override
  40. * @exportInterface
  41. */
  42. this.endTime = endTime;
  43. /**
  44. * @override
  45. * @exportInterface
  46. */
  47. this.payload = payload;
  48. /**
  49. * @override
  50. * @exportInterface
  51. */
  52. this.region = new shaka.text.CueRegion();
  53. /**
  54. * @override
  55. * @exportInterface
  56. */
  57. this.position = null;
  58. /**
  59. * @override
  60. * @exportInterface
  61. */
  62. this.positionAlign = Cue.positionAlign.AUTO;
  63. /**
  64. * @override
  65. * @exportInterface
  66. */
  67. this.size = 100;
  68. /**
  69. * @override
  70. * @exportInterface
  71. */
  72. this.textAlign = Cue.textAlign.CENTER;
  73. /**
  74. * @override
  75. * @exportInterface
  76. */
  77. this.writingDirection = Cue.writingDirection.HORIZONTAL_LEFT_TO_RIGHT;
  78. /**
  79. * @override
  80. * @exportInterface
  81. */
  82. this.lineInterpretation = Cue.lineInterpretation.LINE_NUMBER;
  83. /**
  84. * @override
  85. * @exportInterface
  86. */
  87. this.line = null;
  88. /**
  89. * @override
  90. * @exportInterface
  91. */
  92. this.lineHeight = '';
  93. /**
  94. * @override
  95. * @exportInterface
  96. */
  97. this.lineAlign = Cue.lineAlign.CENTER;
  98. /**
  99. * @override
  100. * @exportInterface
  101. */
  102. this.displayAlign = Cue.displayAlign.BEFORE;
  103. /**
  104. * @override
  105. * @exportInterface
  106. */
  107. this.color = '';
  108. /**
  109. * @override
  110. * @exportInterface
  111. */
  112. this.backgroundColor = '';
  113. /**
  114. * @override
  115. * @exportInterface
  116. */
  117. this.fontSize = '';
  118. /**
  119. * @override
  120. * @exportInterface
  121. */
  122. this.fontWeight = Cue.fontWeight.NORMAL;
  123. /**
  124. * @override
  125. * @exportInterface
  126. */
  127. this.fontStyle = Cue.fontStyle.NORMAL;
  128. /**
  129. * @override
  130. * @exportInterface
  131. */
  132. this.fontFamily = '';
  133. /**
  134. * @override
  135. * @exportInterface
  136. */
  137. this.textDecoration = [];
  138. /**
  139. * @override
  140. * @exportInterface
  141. */
  142. this.wrapLine = true;
  143. /**
  144. * @override
  145. * @exportInterface
  146. */
  147. this.id = '';
  148. };
  149. /**
  150. * @enum {string}
  151. * @export
  152. */
  153. shaka.text.Cue.positionAlign = {
  154. 'LEFT': 'line-left',
  155. 'RIGHT': 'line-right',
  156. 'CENTER': 'center',
  157. 'AUTO': 'auto'
  158. };
  159. /**
  160. * @enum {string}
  161. * @export
  162. */
  163. shaka.text.Cue.textAlign = {
  164. 'LEFT': 'left',
  165. 'RIGHT': 'right',
  166. 'CENTER': 'center',
  167. 'START': 'start',
  168. 'END': 'end'
  169. };
  170. /**
  171. * @enum {string}
  172. * @export
  173. */
  174. shaka.text.Cue.displayAlign = {
  175. 'BEFORE': 'before',
  176. 'CENTER': 'center',
  177. 'AFTER': 'after'
  178. };
  179. /**
  180. * @enum {number}
  181. * @export
  182. */
  183. shaka.text.Cue.writingDirection = {
  184. 'HORIZONTAL_LEFT_TO_RIGHT': 0,
  185. 'HORIZONTAL_RIGHT_TO_LEFT': 1,
  186. 'VERTICAL_LEFT_TO_RIGHT': 2,
  187. 'VERTICAL_RIGHT_TO_LEFT': 3
  188. };
  189. /**
  190. * @enum {number}
  191. * @export
  192. */
  193. shaka.text.Cue.lineInterpretation = {
  194. 'LINE_NUMBER': 0,
  195. 'PERCENTAGE': 1
  196. };
  197. /**
  198. * @enum {string}
  199. * @export
  200. */
  201. shaka.text.Cue.lineAlign = {
  202. 'CENTER': 'center',
  203. 'START': 'start',
  204. 'END': 'end'
  205. };
  206. /**
  207. * In CSS font weight can be a number, where 400 is normal and 700 is bold.
  208. * Use these values for the enum for consistency.
  209. * @enum {number}
  210. * @export
  211. */
  212. shaka.text.Cue.fontWeight = {
  213. 'NORMAL': 400,
  214. 'BOLD': 700
  215. };
  216. /**
  217. * @enum {string}
  218. * @export
  219. */
  220. shaka.text.Cue.fontStyle = {
  221. 'NORMAL': 'normal',
  222. 'ITALIC': 'italic',
  223. 'OBLIQUE': 'oblique'
  224. };
  225. /**
  226. * @enum {string}
  227. * @export
  228. */
  229. shaka.text.Cue.textDecoration = {
  230. 'UNDERLINE': 'underline',
  231. 'LINE_THROUGH': 'lineThrough',
  232. 'OVERLINE': 'overline'
  233. };
  234. /**
  235. * Creates a CueRegion object.
  236. *
  237. * @implements {shakaExtern.CueRegion}
  238. * @constructor
  239. * @struct
  240. * @export
  241. */
  242. shaka.text.CueRegion = function() {
  243. const CueRegion = shaka.text.CueRegion;
  244. /**
  245. * @override
  246. * @exportInterface
  247. */
  248. this.id = '';
  249. /**
  250. * @override
  251. * @exportInterface
  252. */
  253. this.viewportAnchorX = 0;
  254. /**
  255. * @override
  256. * @exportInterface
  257. */
  258. this.viewportAnchorY = 0;
  259. /**
  260. * @override
  261. * @exportInterface
  262. */
  263. this.regionAnchorX = 0;
  264. /**
  265. * @override
  266. * @exportInterface
  267. */
  268. this.regionAnchorY = 0;
  269. /**
  270. * @override
  271. * @exportInterface
  272. */
  273. this.width = 100;
  274. /**
  275. * @override
  276. * @exportInterface
  277. */
  278. this.height = 100;
  279. /**
  280. * @override
  281. * @exportInterface
  282. */
  283. this.heightUnits = CueRegion.units.PERCENTAGE;
  284. /**
  285. * @override
  286. * @exportInterface
  287. */
  288. this.widthUnits = CueRegion.units.PERCENTAGE;
  289. /**
  290. * @override
  291. * @exportInterface
  292. */
  293. this.viewportAnchorUnits = CueRegion.units.PERCENTAGE;
  294. /**
  295. * @override
  296. * @exportInterface
  297. */
  298. this.scroll = CueRegion.scrollMode.NONE;
  299. };
  300. /**
  301. * @enum {number}
  302. * @export
  303. */
  304. shaka.text.CueRegion.units = {
  305. 'PX': 0,
  306. 'PERCENTAGE': 1,
  307. 'LINES': 2
  308. };
  309. /**
  310. * @enum {string}
  311. * @export
  312. */
  313. shaka.text.CueRegion.scrollMode = {
  314. 'NONE': '',
  315. 'UP': 'up'
  316. };