<commit_before>/**
 * libjass
 *
 * https://github.com/Arnavion/libjass
 *
 * Copyright 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///<reference path="utility.ts" />
///<reference path="parser.ts" />

"use strict";

module libjass {
	export class Dialogue {
		private static _lastDialogueId = -1;
		private static _animationStyleElement: HTMLDivElement = null;

		private _id: number;
		private _alignment: number;
		private _parts: tags.Tag[];

		/**
		 * @constructor
		 * @param {string} text
		 * @param {string} style
		 * @param {number} start
		 * @param {number} end
		 * @param {number} layer
		 * @param {{parse: function(string, string=): !*}} parser
		 * @param {!Info} info
		 * @param {!Array.<!Style>} styles
		 */
		constructor(text: string, private _style: Style, private _start: number, private _end: number, private _layer: number, parser: DialogueParser, private _info: Info, private _styles: Style[]) {
			this._id = ++Dialogue._lastDialogueId;
			this._parts = <tags.Tag[]>parser.parse(text);

			this._alignment = this._style.alignment;

		}

		get id(): number {
			return this._id;
		}

		get start(): number {
			return this._start;
		}

		get end(): number {
			return this._end;
		}

		get alignment(): number {
			return this._alignment;
		}

		get layer(): number {
			return this._layer;
		}

		get parts(): tags.Tag[] {
			return this._parts;
		}

		// Magic happens here (TODO: styling)
		/**
		 * @param {number} currentTime
		 * @return {!HTMLDivElement}
		 */
		draw(currentTime: number) {
			var sub = document.createElement("div");

			sub.setAttribute("data-dialogue-id", String(this._id));

			// Create an animation if there is a part that requires it
			var keyframes = new KeyframeCollection(this._id, this._start, this._end);

			this._parts.forEach(part => {
				if (part instanceof tags.Alignment) {
					this._alignment = (<tags.Alignment>part).value;
				}

				else if (part instanceof tags.Fade) {
					var fadePart = <tags.Fade>part;
					if (fadePart.start !== 0) {
						keyframes.add(this._start, "opacity", "0");
						keyframes.add(this._start + fadePart.start, "opacity", "1");
					}
					if (fadePart.end !== 0) {
						keyframes.add(this._end - fadePart.end, "opacity", "1");
						keyframes.add(this._end, "opacity", "0");
					}
				}
			});

			if (Dialogue._animationStyleElement === null) {
				Dialogue._animationStyleElement = <HTMLDivElement>document.querySelector("#animation-styles");
			}
			Dialogue._animationStyleElement.appendChild(document.createTextNode(keyframes.toCSS()));

			var scaleX = this._info.scaleX;<commit_msg>Fixed typo in type of animation styles element.<commit_after>/**
 * libjass
 *
 * https://github.com/Arnavion/libjass
 *
 * Copyright 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///<reference path="utility.ts" />
///<reference path="parser.ts" />

"use strict";

module libjass {
	export class Dialogue {
		private static _lastDialogueId = -1;
		private static _animationStyleElement: HTMLStyleElement = null;

		private _id: number;
		private _alignment: number;
		private _parts: tags.Tag[];

		/**
		 * @constructor
		 * @param {string} text
		 * @param {string} style
		 * @param {number} start
		 * @param {number} end
		 * @param {number} layer
		 * @param {{parse: function(string, string=): !*}} parser
		 * @param {!Info} info
		 * @param {!Array.<!Style>} styles
		 */
		constructor(text: string, private _style: Style, private _start: number, private _end: number, private _layer: number, parser: DialogueParser, private _info: Info, private _styles: Style[]) {
			this._id = ++Dialogue._lastDialogueId;
			this._parts = <tags.Tag[]>parser.parse(text);

			this._alignment = this._style.alignment;

		}

		get id(): number {
			return this._id;
		}

		get start(): number {
			return this._start;
		}

		get end(): number {
			return this._end;
		}

		get alignment(): number {
			return this._alignment;
		}

		get layer(): number {
			return this._layer;
		}

		get parts(): tags.Tag[] {
			return this._parts;
		}

		// Magic happens here (TODO: styling)
		/**
		 * @param {number} currentTime
		 * @return {!HTMLDivElement}
		 */
		draw(currentTime: number) {
			var sub = document.createElement("div");

			sub.setAttribute("data-dialogue-id", String(this._id));

			// Create an animation if there is a part that requires it
			var keyframes = new KeyframeCollection(this._id, this._start, this._end);

			this._parts.forEach(part => {
				if (part instanceof tags.Alignment) {
					this._alignment = (<tags.Alignment>part).value;
				}

				else if (part instanceof tags.Fade) {
					var fadePart = <tags.Fade>part;
					if (fadePart.start !== 0) {
						keyframes.add(this._start, "opacity", "0");
						keyframes.add(this._start + fadePart.start, "opacity", "1");
					}
					if (fadePart.end !== 0) {
						keyframes.add(this._end - fadePart.end, "opacity", "1");
						keyframes.add(this._end, "opacity", "0");
					}
				}
			});

			if (Dialogue._animationStyleElement === null) {
				Dialogue._animationStyleElement = <HTMLStyleElement>document.querySelector("#animation-styles");
			}
			Dialogue._animationStyleElement.appendChild(document.createTextNode(keyframes.toCSS()));

			var scaleX = this._info.scaleX;
{'fraction_non_alphanumeric': 0.1351222610352493, 'fraction_numerical': 0.00476341695776437, 'mean_word_length': 3.4018169112508736, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2788682', 'n_tokens_mistral': 2233, 'n_tokens_neox': 1879, 'n_words': 558}