<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="libjass.ts" />

interface CSSStyleDeclaration {
	webkitAnimation: string;
	webkitAnimationDelay: string;
	webkitFilter: string;
	webkitTransform: string;
	webkitTransformOrigin: string;
}

interface Document {
	fullscreenElement: Element;
	mozFullScreenElement: Element;
	webkitFullscreenElement: Element;
}

module libjass.renderers {
	/**
	 * A renderer implementation that doesn't output anything.
	 *
	 * @constructor
	 *
	 * @param {!HTMLVideoElement} video
	 * @param {!libjass.ASS} ass
	 * @param {!libjass.renderers.RendererSettings} settings
	 *
	 * @memberof libjass.renderers
	 */
	export class NullRenderer {
		private static _highResolutionTimerInterval: number = 41;
		private static _lastRendererId = -1;

		private _id: number;

		private _settings: RendererSettings;

		private _dialogues: Dialogue[];
		private _endTimes: number[];

		private _state: VideoState;
		private _currentTime: number;

		private _timeUpdateIntervalHandle: number = null;

		constructor(private _video: HTMLVideoElement, private _ass: ASS, settings: RendererSettings) {
			this._id = ++NullRenderer._lastRendererId;

			this._settings = RendererSettings.from(settings);

			// Sort the dialogues array by end time and then by their original position in the script (id)
			this._dialogues = this._ass.dialogues.slice(0);
			this._dialogues.sort((dialogue1: Dialogue, dialogue2: Dialogue) => {
				var result = dialogue1.end - dialogue2.end;

				if (result === 0) {
					result = dialogue1.id - dialogue2.id;
				}

				return result;
			});

			this._endTimes = this._dialogues.map((dialogue: Dialogue) => dialogue.end);

			this._video.addEventListener("timeupdate", () => this._onVideoTimeUpdate(), false);
			this._video.addEventListener("seeking", () => this._onVideoSeeking(), false);
			this._video.addEventListener("pause", () => this._onVideoPause(), false);
			this._video.addEventListener("playing", () => this._onVideoPlaying(), false);
		}

		/**
		 * The unique ID of this renderer. Auto-generated.
		 *
		 * @type {number}
		 */
		get id(): number {
			return this._id;
		}

		/**
		 * @type {!HTMLVideoElement}
		 */
		get video(): HTMLVideoElement {
			return this._video;
		}

		/**
		 * @type {!libjass.ASS}
		 */
		get ass(): ASS {
			return this._ass;
		}

		/**
		 * @type {!libjass.renderers.RendererSettings}
		 */
		get settings(): RendererSettings {
			return this._settings;
		}

		/**
		 * @type {number}
		 */
		get currentTime(): number {
			return this._currentTime;
		}

		onVideoTimeUpdate(): void {
			this._currentTime = this._video.currentTime;

			if (libjass.debugMode) {
				console.log("NullRenderer.onVideoTimeUpdate: " + this._getVideoStateLogString());
			}

			var searchStart = 0;
			var searchEnd = this._endTimes.length;
			while (searchStart !== searchEnd) {
				var mid = ((searchStart + searchEnd) / 2) | 0;
				if (this._endTimes[mid] < this._currentTime) {
					searchStart = mid + 1;
				}
				else {
					searchEnd = mid;
				}
			}

			for (var i = searchStart; i < this._endTimes.length; i++) {
				var dialogue = this._dialogues[i];

				if (dialogue.start <= this._currentTime) {
					// This dialogue is visible right now. Draw it.
					this.draw(dialogue);
				}
				else if (dialogue.start <= (this._currentTime + this._settings.preRenderTime)) {
					// This dialogue will be visible soon. Pre-render it.
					this.preRender(dialogue);
				}
				else {
					// No more dialogues in the time range [currentTime, currentTime + settings.preRenderTime]
					break;
				}
			}
		}

		onVideoSeeking(): void {
			if (libjass.debugMode) {
				console.log("NullRenderer.onVideoSeeking: " + this._getVideoStateLogString());
			}
		}

		onVideoPause(): void {
			if (libjass.debugMode) {
				console.log("NullRenderer.onVideoPause: " + this._getVideoStateLogString());
			}

			if (this._timeUpdateIntervalHandle !== null) {
				clearInterval(this._timeUpdateIntervalHandle);
				this._timeUpdateIntervalHandle = null;
			}
		}

		onVideoPlaying(): void {
			if (libjass.debugMode) {
				console.log("NullRenderer.onVideoPlaying: " + this._getVideoStateLogString());
			}

			if (this._timeUpdateIntervalHandle === null) {
				this._timeUpdateIntervalHandle = setInterval(() => this._onVideoTimeChange(), NullRenderer._highResolutionTimerInterval);<commit_msg>Only log timeUpdate, etc. in verbose mode.<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="libjass.ts" />

interface CSSStyleDeclaration {
	webkitAnimation: string;
	webkitAnimationDelay: string;
	webkitFilter: string;
	webkitTransform: string;
	webkitTransformOrigin: string;
}

interface Document {
	fullscreenElement: Element;
	mozFullScreenElement: Element;
	webkitFullscreenElement: Element;
}

module libjass.renderers {
	/**
	 * A renderer implementation that doesn't output anything.
	 *
	 * @constructor
	 *
	 * @param {!HTMLVideoElement} video
	 * @param {!libjass.ASS} ass
	 * @param {!libjass.renderers.RendererSettings} settings
	 *
	 * @memberof libjass.renderers
	 */
	export class NullRenderer {
		private static _highResolutionTimerInterval: number = 41;
		private static _lastRendererId = -1;

		private _id: number;

		private _settings: RendererSettings;

		private _dialogues: Dialogue[];
		private _endTimes: number[];

		private _state: VideoState;
		private _currentTime: number;

		private _timeUpdateIntervalHandle: number = null;

		constructor(private _video: HTMLVideoElement, private _ass: ASS, settings: RendererSettings) {
			this._id = ++NullRenderer._lastRendererId;

			this._settings = RendererSettings.from(settings);

			// Sort the dialogues array by end time and then by their original position in the script (id)
			this._dialogues = this._ass.dialogues.slice(0);
			this._dialogues.sort((dialogue1: Dialogue, dialogue2: Dialogue) => {
				var result = dialogue1.end - dialogue2.end;

				if (result === 0) {
					result = dialogue1.id - dialogue2.id;
				}

				return result;
			});

			this._endTimes = this._dialogues.map((dialogue: Dialogue) => dialogue.end);

			this._video.addEventListener("timeupdate", () => this._onVideoTimeUpdate(), false);
			this._video.addEventListener("seeking", () => this._onVideoSeeking(), false);
			this._video.addEventListener("pause", () => this._onVideoPause(), false);
			this._video.addEventListener("playing", () => this._onVideoPlaying(), false);
		}

		/**
		 * The unique ID of this renderer. Auto-generated.
		 *
		 * @type {number}
		 */
		get id(): number {
			return this._id;
		}

		/**
		 * @type {!HTMLVideoElement}
		 */
		get video(): HTMLVideoElement {
			return this._video;
		}

		/**
		 * @type {!libjass.ASS}
		 */
		get ass(): ASS {
			return this._ass;
		}

		/**
		 * @type {!libjass.renderers.RendererSettings}
		 */
		get settings(): RendererSettings {
			return this._settings;
		}

		/**
		 * @type {number}
		 */
		get currentTime(): number {
			return this._currentTime;
		}

		onVideoTimeUpdate(): void {
			this._currentTime = this._video.currentTime;

			if (libjass.verboseMode) {
				console.log("NullRenderer.onVideoTimeUpdate: " + this._getVideoStateLogString());
			}

			var searchStart = 0;
			var searchEnd = this._endTimes.length;
			while (searchStart !== searchEnd) {
				var mid = ((searchStart + searchEnd) / 2) | 0;
				if (this._endTimes[mid] < this._currentTime) {
					searchStart = mid + 1;
				}
				else {
					searchEnd = mid;
				}
			}

			for (var i = searchStart; i < this._endTimes.length; i++) {
				var dialogue = this._dialogues[i];

				if (dialogue.start <= this._currentTime) {
					// This dialogue is visible right now. Draw it.
					this.draw(dialogue);
				}
				else if (dialogue.start <= (this._currentTime + this._settings.preRenderTime)) {
					// This dialogue will be visible soon. Pre-render it.
					this.preRender(dialogue);
				}
				else {
					// No more dialogues in the time range [currentTime, currentTime + settings.preRenderTime]
					break;
				}
			}
		}

		onVideoSeeking(): void {
			if (libjass.verboseMode) {
				console.log("NullRenderer.onVideoSeeking: " + this._getVideoStateLogString());
			}
		}

		onVideoPause(): void {
			if (libjass.verboseMode) {
				console.log("NullRenderer.onVideoPause: " + this._getVideoStateLogString());
			}

			if (this._timeUpdateIntervalHandle !== null) {
				clearInterval(this._timeUpdateIntervalHandle);
				this._timeUpdateIntervalHandle = null;
			}
		}

		onVideoPlaying(): void {
			if (libjass.verboseMode) {
				console.log("NullRenderer.onVideoPlaying: " + this._getVideoStateLogString());
			}

			if (this._timeUpdateIntervalHandle === null) {
				this._timeUpdateIntervalHandle = setInterval(() => this._onVideoTimeChange(), NullRenderer._highResolutionTimerInterval);
{'fraction_non_alphanumeric': 0.12276495854559984, 'fraction_numerical': 0.004594945559884127, 'mean_word_length': 3.532367587143504, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6288171', 'n_tokens_mistral': 3549, 'n_tokens_neox': 2969, 'n_words': 759}