/** * libjass * * https://github.com/Arnavion/libjass * * Copyright 2013 Arnav Singh * * 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. */ (function (root, factory) { var global = this; if (typeof define === "function" && define.amd) { define([], function () { return factory(global); }); } else if (typeof exports === "object" && typeof module === "object") { module.exports = factory(global); } else if (typeof exports === "object") { exports.libjass = factory(global); } else { root.libjass = factory(global); } })(this, function (global) { "use strict"; return function (modules) { var installedModules = Object.create(null); function require(moduleId) { if (installedModules[moduleId]) { return installedModules[moduleId]; } var exports = installedModules[moduleId] = Object.create(null); modules[moduleId](exports, require); return exports; } return require(0); }([ /* 0 ./index */ function (exports, require) { var settings = require(23); var settings_1 = require(23); exports.debugMode = settings_1.debugMode; exports.verboseMode = settings_1.verboseMode; var set = require(33); var set_1 = require(33); exports.Set = set_1.Set; var map = require(30); var map_1 = require(30); exports.Map = map_1.Map; var promise = require(32); var promise_1 = require(32); exports.Promise = promise_1.Promise; exports.DeferredPromise = promise_1.DeferredPromise; var webworker = require(37); exports.webworker = webworker; var parts = require(8); exports.parts = parts; var parser = require(1); exports.parser = parser; var renderers = require(14); exports.renderers = renderers; var ass_1 = require(24); exports.ASS = ass_1.ASS; var attachment_1 = require(25); exports.Attachment = attachment_1.Attachment; exports.AttachmentType = attachment_1.AttachmentType; var dialogue_1 = require(26); exports.Dialogue = dialogue_1.Dialogue; var script_properties_1 = require(28); exports.ScriptProperties = script_properties_1.ScriptProperties; var style_1 = require(29); exports.Style = style_1.Style; var misc_1 = require(27); exports.BorderStyle = misc_1.BorderStyle; exports.Format = misc_1.Format; exports.WrappingStyle = misc_1.WrappingStyle; Object.defineProperties(exports, { debugMode: { get: function () { return settings.debugMode; }, set: settings.setDebugMode }, verboseMode: { get: function () { return settings.verboseMode; }, set: settings.setVerboseMode }, Set: { get: function () { return set.Set; }, set: set.setImplementation }, Map: { get: function () { return map.Map; }, set: map.setImplementation }, Promise: { get: function () { return promise.Promise; }, set: promise.setImplementation } }); }, /* 1 ./parser/index */ function (exports, require) { var parse_1 = require(3); exports.parse = parse_1.parse; var streams_1 = require(5); exports.BrowserReadableStream = streams_1.BrowserReadableStream; exports.StringStream = streams_1.StringStream; exports.XhrStream = streams_1.XhrStream; var stream_parsers_1 = require(4); exports.StreamParser = stream_parsers_1.StreamParser; exports.SrtStreamParser = stream_parsers_1.SrtStreamParser; }, /* 2 ./parser/misc */ function (exports, require) { var map_1 = require(30); /** * Parses a line into a {@link ./types/misc.Property}. * * @param {string} line * @return {!Property} */ function parseLineIntoProperty(line) { var colonPos = line.indexOf(":"); if (colonPos === -1) { return null; } var name = line.substr(0, colonPos); var value = line.substr(colonPos + 1).replace(/^\s+/, ""); return { name: name, value: value }; } exports.parseLineIntoProperty = parseLineIntoProperty; /** * Parses a line into a {@link ./types/misc.TypedTemplate} according to the given format specifier. * * @param {string} line * @param {!Array.} formatSpecifier * @return {!TypedTemplate} */ function parseLineIntoTypedTemplate(line, formatSpecifier) { var property = parseLineIntoProperty(line); if (property === null) { return null; } var value = property.value.split(","); if (value.length > formatSpecifier.length) { value[formatSpecifier.length - 1] = value.slice(formatSpecifier.length - 1).join(","); } var template = new map_1.Map(); formatSpecifier.forEach(function (formatKey, index) { template.set(formatKey, value[index]); }); return { type: property.name, template: template }; } exports.parseLineIntoTypedTemplate = parseLineIntoTypedTemplate; }, /* 3 ./parser/parse */ function (exports, require) { var parts = require(8); var settings_1 = require(23); var map_1 = require(30); var rules = new map_1.Map(); /** * Parses a given string with the specified rule. * * @param {string} input The string to be parsed. * @param {string} rule The rule to parse the string with * @return {*} The value returned depends on the rule used. * * @memberOf libjass.parser */ function parse(input, rule) { var run = new ParserRun(input, rule); if (run.result === null || run.result.end !== input.length) { if (settings_1.debugMode) { console.error("Parse failed. %s %s %o", rule, input, run.result); } throw new Error("Parse failed."); } return run.result.value; } exports.parse = parse; /** * This class represents a single run of the parser. * * @param {string} input * @param {string} rule * * @constructor * @private */ var ParserRun = function () { function ParserRun(input, rule) { this._input = input; this._parseTree = new ParseNode(null); this._result = rules.get(rule).call(this, this._parseTree); } Object.defineProperty(ParserRun.prototype, "result", { /** * @type {ParseNode} */ get: function () { return this._result; }, enumerable: true, configurable: true }); /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_dialogueParts = function (parent) { var _a; var current = new ParseNode(parent); current.value = []; while (this._haveMore()) { var enclosedTagsNode = this.parse_enclosedTags(current); if (enclosedTagsNode !== null) { (_a = current.value).push.apply(_a, enclosedTagsNode.value); } else { var whiteSpaceOrTextNode = this.parse_newline(current) || this.parse_hardspace(current) || this.parse_text(current); if (whiteSpaceOrTextNode === null) { parent.pop(); return null; } if (whiteSpaceOrTextNode.value instanceof parts.Text && current.value[current.value.length - 1] instanceof parts.Text) { // Merge consecutive text parts into one part var previousTextPart = current.value[current.value.length - 1]; current.value[current.value.length - 1] = new parts.Text(previousTextPart.value + whiteSpaceOrTextNode.value.value); } else { current.value.push(whiteSpaceOrTextNode.value); } } } var inDrawingMode = false; current.value.forEach(function (part, i) { if (part instanceof parts.DrawingMode) { inDrawingMode = part.scale !== 0; } else if (part instanceof parts.Text && inDrawingMode) { current.value[i] = new parts.DrawingInstructions(parse(part.value, "drawingInstructions")); } }); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_enclosedTags = function (parent) { var current = new ParseNode(parent); current.value = []; if (this.read(current, "{") === null) { parent.pop(); return null; } for (var next = this._peek(); this._haveMore() && next !== "}"; next = this._peek()) { var childNode = null; if (this.read(current, "\\") !== null) { childNode = this.parse_tag_alpha(current) || this.parse_tag_iclip(current) || this.parse_tag_xbord(current) || this.parse_tag_ybord(current) || this.parse_tag_xshad(current) || this.parse_tag_yshad(current) || this.parse_tag_blur(current) || this.parse_tag_bord(current) || this.parse_tag_clip(current) || this.parse_tag_fade(current) || this.parse_tag_fscx(current) || this.parse_tag_fscy(current) || this.parse_tag_move(current) || this.parse_tag_shad(current) || this.parse_tag_fad(current) || this.parse_tag_fax(current) || this.parse_tag_fay(current) || this.parse_tag_frx(current) || this.parse_tag_fry(current) || this.parse_tag_frz(current) || this.parse_tag_fsp(current) || this.parse_tag_fsplus(current) || this.parse_tag_fsminus(current) || this.parse_tag_org(current) || this.parse_tag_pbo(current) || this.parse_tag_pos(current) || this.parse_tag_an(current) || this.parse_tag_be(current) || this.parse_tag_fn(current) || this.parse_tag_fr(current) || this.parse_tag_fs(current) || this.parse_tag_kf(current) || this.parse_tag_ko(current) || this.parse_tag_1a(current) || this.parse_tag_1c(current) || this.parse_tag_2a(current) || this.parse_tag_2c(current) || this.parse_tag_3a(current) || this.parse_tag_3c(current) || this.parse_tag_4a(current) || this.parse_tag_4c(current) || this.parse_tag_a(current) || this.parse_tag_b(current) || this.parse_tag_c(current) || this.parse_tag_i(current) || this.parse_tag_k(current) || this.parse_tag_K(current) || this.parse_tag_p(current) || this.parse_tag_q(current) || this.parse_tag_r(current) || this.parse_tag_s(current) || this.parse_tag_t(current) || this.parse_tag_u(current); if (childNode === null) { current.pop(); } } if (childNode === null) { childNode = this.parse_comment(current); } if (childNode !== null) { if (childNode.value instanceof parts.Comment && current.value[current.value.length - 1] instanceof parts.Comment) { // Merge consecutive comment parts into one part current.value[current.value.length - 1] = new parts.Comment(current.value[current.value.length - 1].value + childNode.value.value); } else { current.value.push(childNode.value); } } else { parent.pop(); return null; } } if (this.read(current, "}") === null) { parent.pop(); return null; } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_newline = function (parent) { var current = new ParseNode(parent); if (this.read(current, "\\N") === null) { parent.pop(); return null; } current.value = new parts.NewLine(); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_hardspace = function (parent) { var current = new ParseNode(parent); if (this.read(current, "\\h") === null) { parent.pop(); return null; } current.value = new parts.Text(" "); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_text = function (parent) { var value = this._peek(); var current = new ParseNode(parent); var valueNode = new ParseNode(current, value); current.value = new parts.Text(valueNode.value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_comment = function (parent) { var value = this._peek(); var current = new ParseNode(parent); var valueNode = new ParseNode(current, value); current.value = new parts.Comment(valueNode.value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_a = function (parent) { var current = new ParseNode(parent); if (this.read(current, "a") === null) { parent.pop(); return null; } var next = this._peek(); switch (next) { case "1": var next2 = this._peek(2); switch (next2) { case "10": case "11": next = next2; break; } break; case "2": case "3": case "5": case "6": case "7": case "9": break; default: parent.pop(); return null; } var valueNode = new ParseNode(current, next); var value = null; switch (valueNode.value) { case "1": value = 1; break; case "2": value = 2; break; case "3": value = 3; break; case "5": value = 7; break; case "6": value = 8; break; case "7": value = 9; break; case "9": value = 4; break; case "10": value = 5; break; case "11": value = 6; break; } current.value = new parts.Alignment(value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_alpha = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_an = function (parent) { var current = new ParseNode(parent); if (this.read(current, "an") === null) { parent.pop(); return null; } var next = this._peek(); if (next < "1" || next > "9") { parent.pop(); return null; } var valueNode = new ParseNode(current, next); current.value = new parts.Alignment(parseInt(valueNode.value)); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_b = function (parent) { var current = new ParseNode(parent); if (this.read(current, "b") === null) { parent.pop(); return null; } var valueNode = null; var next = this._peek(); if (next >= "1" && next <= "9") { next = this._peek(3); if (next.substr(1) === "00") { valueNode = new ParseNode(current, next); valueNode.value = parseInt(valueNode.value); } } if (valueNode === null) { valueNode = this.parse_enableDisable(current); } if (valueNode !== null) { current.value = new parts.Bold(valueNode.value); } else { current.value = new parts.Bold(null); } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_be = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_blur = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_bord = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_c = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_clip = function (parent) { return this._parse_tag_clip_or_iclip("clip", parent); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fad = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fad") === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var startNode = this.parse_decimal(current); if (startNode === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var endNode = this.parse_decimal(current); if (endNode === null) { parent.pop(); return null; } if (this.read(current, ")") === null) { parent.pop(); return null; } current.value = new parts.Fade(startNode.value / 1e3, endNode.value / 1e3); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fade = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fade") === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var a1Node = this.parse_decimal(current); if (a1Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var a2Node = this.parse_decimal(current); if (a2Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var a3Node = this.parse_decimal(current); if (a3Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var t1Node = this.parse_decimal(current); if (t1Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var t2Node = this.parse_decimal(current); if (t2Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var t3Node = this.parse_decimal(current); if (t3Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var t4Node = this.parse_decimal(current); if (t4Node === null) { parent.pop(); return null; } if (this.read(current, ")") === null) { parent.pop(); return null; } current.value = new parts.ComplexFade(1 - a1Node.value / 255, 1 - a2Node.value / 255, 1 - a3Node.value / 255, t1Node.value / 1e3, t2Node.value / 1e3, t3Node.value / 1e3, t4Node.value / 1e3); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fax = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fay = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fn = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fn") === null) { parent.pop(); return null; } var valueNode = new ParseNode(current, ""); for (var next = this._peek(); this._haveMore() && next !== "\\" && next !== "}"; next = this._peek()) { valueNode.value += next; } if (valueNode.value.length > 0) { current.value = new parts.FontName(valueNode.value); } else { current.value = new parts.FontName(null); } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fr = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_frx = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fry = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_frz = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fs = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fsplus = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fs+") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode === null) { parent.pop(); return null; } current.value = new parts.FontSizePlus(valueNode.value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fsminus = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fs-") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode === null) { parent.pop(); return null; } current.value = new parts.FontSizeMinus(valueNode.value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fscx = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fscx") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode !== null) { current.value = new parts.FontScaleX(valueNode.value / 100); } else { current.value = new parts.FontScaleX(null); } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fscy = function (parent) { var current = new ParseNode(parent); if (this.read(current, "fscy") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode !== null) { current.value = new parts.FontScaleY(valueNode.value / 100); } else { current.value = new parts.FontScaleY(null); } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_fsp = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_i = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_iclip = function (parent) { return this._parse_tag_clip_or_iclip("iclip", parent); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_k = function (parent) { var current = new ParseNode(parent); if (this.read(current, "k") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode === null) { parent.pop(); return null; } current.value = new parts.ColorKaraoke(valueNode.value / 100); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_K = function (parent) { var current = new ParseNode(parent); if (this.read(current, "K") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode === null) { parent.pop(); return null; } current.value = new parts.SweepingColorKaraoke(valueNode.value / 100); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_kf = function (parent) { var current = new ParseNode(parent); if (this.read(current, "kf") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode === null) { parent.pop(); return null; } current.value = new parts.SweepingColorKaraoke(valueNode.value / 100); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_ko = function (parent) { var current = new ParseNode(parent); if (this.read(current, "ko") === null) { parent.pop(); return null; } var valueNode = this.parse_decimal(current); if (valueNode === null) { parent.pop(); return null; } current.value = new parts.OutlineKaraoke(valueNode.value / 100); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_move = function (parent) { var current = new ParseNode(parent); if (this.read(current, "move") === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var x1Node = this.parse_decimal(current); if (x1Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var y1Node = this.parse_decimal(current); if (y1Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var x2Node = this.parse_decimal(current); if (x2Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var y2Node = this.parse_decimal(current); if (y2Node === null) { parent.pop(); return null; } var t1Node = null; var t2Node = null; if (this.read(current, ",") !== null) { t1Node = this.parse_decimal(current); if (t1Node === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } t2Node = this.parse_decimal(current); if (t2Node === null) { parent.pop(); return null; } } if (this.read(current, ")") === null) { parent.pop(); return null; } current.value = new parts.Move(x1Node.value, y1Node.value, x2Node.value, y2Node.value, t1Node !== null ? t1Node.value / 1e3 : null, t2Node !== null ? t2Node.value / 1e3 : null); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_org = function (parent) { var current = new ParseNode(parent); if (this.read(current, "org") === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var xNode = this.parse_decimal(current); if (xNode === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var yNode = this.parse_decimal(current); if (yNode === null) { parent.pop(); return null; } if (this.read(current, ")") === null) { parent.pop(); return null; } current.value = new parts.RotationOrigin(xNode.value, yNode.value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_p = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_pbo = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_pos = function (parent) { var current = new ParseNode(parent); if (this.read(current, "pos") === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var xNode = this.parse_decimal(current); if (xNode === null) { parent.pop(); return null; } if (this.read(current, ",") === null) { parent.pop(); return null; } var yNode = this.parse_decimal(current); if (yNode === null) { parent.pop(); return null; } if (this.read(current, ")") === null) { parent.pop(); return null; } current.value = new parts.Position(xNode.value, yNode.value); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_q = function (parent) { var current = new ParseNode(parent); if (this.read(current, "q") === null) { parent.pop(); return null; } var next = this._peek(); if (next < "0" || next > "3") { parent.pop(); return null; } var valueNode = new ParseNode(current, next); current.value = new parts.WrappingStyle(parseInt(valueNode.value)); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_r = function (parent) { var current = new ParseNode(parent); if (this.read(current, "r") === null) { parent.pop(); return null; } var valueNode = new ParseNode(current, ""); for (var next = this._peek(); this._haveMore() && next !== "\\" && next !== "}"; next = this._peek()) { valueNode.value += next; } if (valueNode.value.length > 0) { current.value = new parts.Reset(valueNode.value); } else { current.value = new parts.Reset(null); } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_s = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_shad = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_t = function (parent) { var current = new ParseNode(parent); if (this.read(current, "t") === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var startNode = null; var endNode = null; var accelNode = null; var firstNode = this.parse_decimal(current); if (firstNode !== null) { if (this.read(current, ",") === null) { parent.pop(); return null; } var secondNode = this.parse_decimal(current); if (secondNode !== null) { startNode = firstNode; endNode = secondNode; if (this.read(current, ",") === null) { parent.pop(); return null; } var thirdNode = this.parse_decimal(current); if (thirdNode !== null) { accelNode = thirdNode; if (this.read(current, ",") === null) { parent.pop(); return null; } } } else { accelNode = firstNode; if (this.read(current, ",") === null) { parent.pop(); return null; } } } var transformTags = []; for (var next = this._peek(); this._haveMore() && next !== ")" && next !== "}"; next = this._peek()) { var childNode = null; if (this.read(current, "\\") !== null) { childNode = this.parse_tag_alpha(current) || this.parse_tag_iclip(current) || this.parse_tag_xbord(current) || this.parse_tag_ybord(current) || this.parse_tag_xshad(current) || this.parse_tag_yshad(current) || this.parse_tag_blur(current) || this.parse_tag_bord(current) || this.parse_tag_clip(current) || this.parse_tag_fscx(current) || this.parse_tag_fscy(current) || this.parse_tag_shad(current) || this.parse_tag_fax(current) || this.parse_tag_fay(current) || this.parse_tag_frx(current) || this.parse_tag_fry(current) || this.parse_tag_frz(current) || this.parse_tag_fsp(current) || this.parse_tag_fsplus(current) || this.parse_tag_fsminus(current) || this.parse_tag_be(current) || this.parse_tag_fr(current) || this.parse_tag_fs(current) || this.parse_tag_1a(current) || this.parse_tag_1c(current) || this.parse_tag_2a(current) || this.parse_tag_2c(current) || this.parse_tag_3a(current) || this.parse_tag_3c(current) || this.parse_tag_4a(current) || this.parse_tag_4c(current) || this.parse_tag_c(current); if (childNode === null) { current.pop(); } } if (childNode === null) { childNode = this.parse_comment(current); } if (childNode !== null) { if (childNode.value instanceof parts.Comment && transformTags[transformTags.length - 1] instanceof parts.Comment) { // Merge consecutive comment parts into one part transformTags[transformTags.length - 1] = new parts.Comment(transformTags[transformTags.length - 1].value + childNode.value.value); } else { transformTags.push(childNode.value); } } else { parent.pop(); return null; } } this.read(current, ")"); current.value = new parts.Transform(startNode !== null ? startNode.value / 1e3 : null, endNode !== null ? endNode.value / 1e3 : null, accelNode !== null ? accelNode.value / 1e3 : null, transformTags); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_u = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_xbord = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_xshad = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_ybord = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_yshad = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_1a = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_1c = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_2a = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_2c = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_3a = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_3c = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_4a = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_tag_4c = function () { throw new Error("Method not implemented."); }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_drawingInstructions = function (parent) { var current = new ParseNode(parent); var currentType = null; var numberParts = []; current.value = []; while (this._haveMore()) { while (this.read(current, " ") !== null) {} if (!this._haveMore()) { break; } if (currentType !== null) { var numberPart = this.parse_decimal(current); if (numberPart !== null) { numberParts.push(numberPart); if (currentType === "m" && numberParts.length === 2) { current.value.push(new parts.drawing.MoveInstruction(numberParts[0].value, numberParts[1].value)); numberParts.splice(0, numberParts.length); } else if (currentType === "l" && numberParts.length === 2) { current.value.push(new parts.drawing.LineInstruction(numberParts[0].value, numberParts[1].value)); numberParts.splice(0, numberParts.length); } else if (currentType === "b" && numberParts.length === 6) { current.value.push(new parts.drawing.CubicBezierCurveInstruction(numberParts[0].value, numberParts[1].value, numberParts[2].value, numberParts[3].value, numberParts[4].value, numberParts[5].value)); numberParts.splice(0, numberParts.length); } continue; } } var typePart = this.parse_text(current); if (typePart === null) { break; } var newType = typePart.value.value; switch (newType) { case "m": case "l": case "b": currentType = newType; numberParts.splice(0, numberParts.length); break; } } while (this.read(current, " ") !== null) {} return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_decimalInt32 = function (parent) { var current = new ParseNode(parent); var isNegative = this.read(current, "-") !== null; var numberNode = new ParseNode(current, ""); for (var next = this._peek(); this._haveMore() && next >= "0" && next <= "9"; next = this._peek()) { numberNode.value += next; } if (numberNode.value.length === 0) { parent.pop(); return null; } var value = parseInt(numberNode.value); if (value >= 4294967295) { value = 4294967295; } else if (isNegative) { value = -value; } current.value = value; return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_hexInt32 = function (parent) { var current = new ParseNode(parent); var isNegative = this.read(current, "-") !== null; var numberNode = new ParseNode(current, ""); for (var next = this._peek(); this._haveMore() && (next >= "0" && next <= "9" || next >= "a" && next <= "f" || next >= "A" && next <= "F"); next = this._peek()) { numberNode.value += next; } if (numberNode.value.length === 0) { parent.pop(); return null; } var value = parseInt(numberNode.value, 16); if (value >= 4294967295) { value = 4294967295; } else if (isNegative) { value = -value; } current.value = value; return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_decimalOrHexInt32 = function (parent) { var current = new ParseNode(parent); var valueNode = this.read(current, "&H") !== null || this.read(current, "&h") !== null ? this.parse_hexInt32(current) : this.parse_decimalInt32(current); if (valueNode === null) { parent.pop(); return null; } current.value = valueNode.value; return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_decimal = function (parent) { var current = new ParseNode(parent); var negative = this.read(current, "-") !== null; var numericalPart = this.parse_unsignedDecimal(current); if (numericalPart === null) { parent.pop(); return null; } current.value = numericalPart.value; if (negative) { current.value = -current.value; } return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_unsignedDecimal = function (parent) { var current = new ParseNode(parent); var characteristicNode = new ParseNode(current, ""); var mantissaNode = null; for (var next = this._peek(); this._haveMore() && next >= "0" && next <= "9"; next = this._peek()) { characteristicNode.value += next; } if (characteristicNode.value.length === 0) { parent.pop(); return null; } if (this.read(current, ".") !== null) { mantissaNode = new ParseNode(current, ""); for (var next = this._peek(); this._haveMore() && next >= "0" && next <= "9"; next = this._peek()) { mantissaNode.value += next; } if (mantissaNode.value.length === 0) { parent.pop(); return null; } } current.value = parseFloat(characteristicNode.value + (mantissaNode !== null ? "." + mantissaNode.value : "")); return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_enableDisable = function (parent) { var next = this._peek(); if (next === "0" || next === "1") { var result = new ParseNode(parent, next); result.value = result.value === "1"; return result; } return null; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_color = function (parent) { var current = new ParseNode(parent); while (this.read(current, "&") !== null || this.read(current, "H") !== null) {} var valueNode = this.parse_hexInt32(current); if (valueNode === null) { parent.pop(); return null; } var value = valueNode.value; current.value = new parts.Color(value & 255, value >> 8 & 255, value >> 16 & 255); while (this.read(current, "&") !== null || this.read(current, "H") !== null) {} return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_alpha = function (parent) { var current = new ParseNode(parent); while (this.read(current, "&") !== null || this.read(current, "H") !== null) {} var valueNode = this.parse_hexInt32(current); if (valueNode === null) { parent.pop(); return null; } var value = valueNode.value; current.value = 1 - (value & 255) / 255; while (this.read(current, "&") !== null || this.read(current, "H") !== null) {} return current; }; /** * @param {!ParseNode} parent * @return {ParseNode} */ ParserRun.prototype.parse_colorWithAlpha = function (parent) { var current = new ParseNode(parent); var valueNode = this.parse_decimalOrHexInt32(current); if (valueNode === null) { parent.pop(); return null; } var value = valueNode.value; current.value = new parts.Color(value & 255, value >> 8 & 255, value >> 16 & 255, 1 - (value >> 24 & 255) / 255); return current; }; /** * @param {!ParseNode} parent * @param {string} next * @return {ParseNode} */ ParserRun.prototype.read = function (parent, next) { if (this._peek(next.length) !== next) { return null; } return new ParseNode(parent, next); }; /** * @param {number=1} count * @return {string} * * @private */ ParserRun.prototype._peek = function (count) { if (count === void 0) { count = 1; } // Fastpath for count === 1. http://jsperf.com/substr-vs-indexer if (count === 1) { return this._input[this._parseTree.end]; } return this._input.substr(this._parseTree.end, count); }; /** * @return {boolean} * * @private */ ParserRun.prototype._haveMore = function () { return this._parseTree.end < this._input.length; }; /** * @param {string} tagName One of "clip" and "iclip" * @param {!ParseNode} parent * @return {ParseNode} * * @private */ ParserRun.prototype._parse_tag_clip_or_iclip = function (tagName, parent) { var current = new ParseNode(parent); if (this.read(current, tagName) === null) { parent.pop(); return null; } if (this.read(current, "(") === null) { parent.pop(); return null; } var x1Node = null; var x2Node = null; var y1Node = null; var y2Node = null; var scaleNode = null; var commandsNode = null; var firstNode = this.parse_decimal(current); if (firstNode !== null) { if (this.read(current, ",") === null) { parent.pop(); return null; } var secondNode = this.parse_decimal(current); if (secondNode !== null) { x1Node = firstNode; y1Node = secondNode; } else { scaleNode = firstNode; } } if (x1Node !== null && y1Node !== null) { if (this.read(current, ",") === null) { parent.pop(); return null; } x2Node = this.parse_decimal(current); if (this.read(current, ",") === null) { parent.pop(); return null; } y2Node = this.parse_decimal(current); current.value = new parts.RectangularClip(x1Node.value, y1Node.value, x2Node.value, y2Node.value, tagName === "clip"); } else { commandsNode = new ParseNode(current, ""); for (var next = this._peek(); this._haveMore() && next !== ")" && next !== "}"; next = this._peek()) { commandsNode.value += next; } current.value = new parts.VectorClip(scaleNode !== null ? scaleNode.value : 1, parse(commandsNode.value, "drawingInstructions"), tagName === "clip"); } if (this.read(current, ")") === null) { parent.pop(); return null; } return current; }; return ParserRun; }(); /** * Constructs a simple tag parser function and sets it on the prototype of the {@link ./parser/parse.ParserRun} class. * * @param {string} tagName The name of the tag to generate the parser function for * @param {function(new: !libjass.parts.Part, *)} tagConstructor The type of tag to be returned by the generated parser function * @param {function(!ParseNode): ParseNode} valueParser The parser for the tag's value * @param {boolean} required Whether the tag's value is required or optional * * @private */ function makeTagParserFunction(tagName, tagConstructor, valueParser, required) { ParserRun.prototype["parse_tag_" + tagName] = function (parent) { var self = this; var current = new ParseNode(parent); if (self.read(current, tagName) === null) { parent.pop(); return null; } var valueNode = valueParser.call(self, current); if (valueNode !== null) { current.value = new tagConstructor(valueNode.value); } else if (!required) { current.value = new tagConstructor(null); } else { parent.pop(); return null; } return current; }; } makeTagParserFunction("alpha", parts.Alpha, ParserRun.prototype.parse_alpha, false); makeTagParserFunction("be", parts.Blur, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("blur", parts.GaussianBlur, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("bord", parts.Border, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("c", parts.PrimaryColor, ParserRun.prototype.parse_color, false); makeTagParserFunction("fax", parts.SkewX, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("fay", parts.SkewY, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("fr", parts.RotateZ, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("frx", parts.RotateX, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("fry", parts.RotateY, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("frz", parts.RotateZ, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("fs", parts.FontSize, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("fsp", parts.LetterSpacing, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("i", parts.Italic, ParserRun.prototype.parse_enableDisable, false); makeTagParserFunction("p", parts.DrawingMode, ParserRun.prototype.parse_decimal, true); makeTagParserFunction("pbo", parts.DrawingBaselineOffset, ParserRun.prototype.parse_decimal, true); makeTagParserFunction("s", parts.StrikeThrough, ParserRun.prototype.parse_enableDisable, false); makeTagParserFunction("shad", parts.Shadow, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("u", parts.Underline, ParserRun.prototype.parse_enableDisable, false); makeTagParserFunction("xbord", parts.BorderX, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("xshad", parts.ShadowX, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("ybord", parts.BorderY, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("yshad", parts.ShadowY, ParserRun.prototype.parse_decimal, false); makeTagParserFunction("1a", parts.PrimaryAlpha, ParserRun.prototype.parse_alpha, false); makeTagParserFunction("1c", parts.PrimaryColor, ParserRun.prototype.parse_color, false); makeTagParserFunction("2a", parts.SecondaryAlpha, ParserRun.prototype.parse_alpha, false); makeTagParserFunction("2c", parts.SecondaryColor, ParserRun.prototype.parse_color, false); makeTagParserFunction("3a", parts.OutlineAlpha, ParserRun.prototype.parse_alpha, false); makeTagParserFunction("3c", parts.OutlineColor, ParserRun.prototype.parse_color, false); makeTagParserFunction("4a", parts.ShadowAlpha, ParserRun.prototype.parse_alpha, false); makeTagParserFunction("4c", parts.ShadowColor, ParserRun.prototype.parse_color, false); for (var _i = 0, _a = Object.keys(ParserRun.prototype); _i < _a.length; _i++) { var key = _a[_i]; if (key.indexOf("parse_") === 0 && typeof ParserRun.prototype[key] === "function") { rules.set(key.substr("parse_".length), ParserRun.prototype[key]); } } /** * This class represents a single parse node. It has a start and end position, and an optional value object. * * @param {ParseNode} parent The parent of this parse node. * @param {*=null} value If provided, it is assigned as the value of the node. * * @constructor * @private */ var ParseNode = function () { function ParseNode(parent, value) { if (value === void 0) { value = null; } this._parent = parent; this._children = []; if (parent !== null) { parent.children.push(this); } this._start = parent !== null ? parent.end : 0; this._end = this._start; this.value = value; } Object.defineProperty(ParseNode.prototype, "start", { /** * The start position of this parse node. * * @type {number} */ get: function () { return this._start; }, enumerable: true, configurable: true }); Object.defineProperty(ParseNode.prototype, "end", { /** * The end position of this parse node. * * @type {number} */ get: function () { return this._end; }, enumerable: true, configurable: true }); Object.defineProperty(ParseNode.prototype, "parent", { /** * @type {ParseNode} */ get: function () { return this._parent; }, enumerable: true, configurable: true }); Object.defineProperty(ParseNode.prototype, "children", { /** * @type {!Array.} */ get: function () { return this._children; }, enumerable: true, configurable: true }); Object.defineProperty(ParseNode.prototype, "value", { /** * An optional object associated with this parse node. * * @type {*} */ get: function () { return this._value; }, /** * An optional object associated with this parse node. * * If the value is a string, then the end property is updated to be the length of the string. * * @type {*} */ set: function (newValue) { this._value = newValue; if (this._value !== null && this._value.constructor === String && this._children.length === 0) { this._setEnd(this._start + this._value.length); } }, enumerable: true, configurable: true }); /** * Removes the last child of this node and updates the end position to be end position of the new last child. */ ParseNode.prototype.pop = function () { this._children.splice(this._children.length - 1, 1); if (this._children.length > 0) { this._setEnd(this._children[this._children.length - 1].end); } else { this._setEnd(this.start); } }; /** * Updates the end property of this node and its parent recursively to the root node. * * @param {number} newEnd * * @private */ ParseNode.prototype._setEnd = function (newEnd) { this._end = newEnd; if (this._parent !== null && this._parent.end !== this._end) { this._parent._setEnd(this._end); } }; return ParseNode; }(); var promise_1 = require(32); var commands_1 = require(36); var misc_1 = require(38); misc_1.registerWorkerCommand(commands_1.WorkerCommands.Parse, function (parameters) { return new promise_1.Promise(function (resolve) { resolve(parse(parameters.input, parameters.rule)); }); }); }, /* 4 ./parser/stream-parsers */ function (exports, require) { var settings_1 = require(23); var ass_1 = require(24); var style_1 = require(29); var dialogue_1 = require(26); var attachment_1 = require(25); var map_1 = require(30); var promise_1 = require(32); var misc_1 = require(2); var Section; (function (Section) { Section[Section["ScriptInfo"] = 0] = "ScriptInfo"; Section[Section["Styles"] = 1] = "Styles"; Section[Section["Events"] = 2] = "Events"; Section[Section["Fonts"] = 3] = "Fonts"; Section[Section["Graphics"] = 4] = "Graphics"; Section[Section["Other"] = 5] = "Other"; Section[Section["EOF"] = 6] = "EOF"; })(Section || (Section = {})); /** * A parser that parses an {@link libjass.ASS} object from a {@link libjass.parser.Stream}. * * @param {!libjass.parser.Stream} stream The {@link libjass.parser.Stream} to parse * * @constructor * @memberOf libjass.parser */ var StreamParser = function () { function StreamParser(stream) { var _this = this; this._stream = stream; this._ass = new ass_1.ASS(); this._minimalDeferred = new promise_1.DeferredPromise(); this._deferred = new promise_1.DeferredPromise(); this._shouldSwallowBom = true; this._currentSection = Section.ScriptInfo; this._currentAttachment = null; this._stream.nextLine().then(function (line) { return _this._onNextLine(line); }, function (reason) { _this._minimalDeferred.reject(reason); _this._deferred.reject(reason); }); } Object.defineProperty(StreamParser.prototype, "minimalASS", { /** * @type {!Promise.} A promise that will be resolved when the script properties of the ASS script have been parsed from the stream. Styles and events have not necessarily been * parsed at the point this promise becomes resolved. */ get: function () { return this._minimalDeferred.promise; }, enumerable: true, configurable: true }); Object.defineProperty(StreamParser.prototype, "ass", { /** * @type {!Promise.} A promise that will be resolved when the entire stream has been parsed. */ get: function () { return this._deferred.promise; }, enumerable: true, configurable: true }); Object.defineProperty(StreamParser.prototype, "currentSection", { /** * @type {number} */ get: function () { return this._currentSection; }, /** * @type {number} */ set: function (value) { if (this._currentAttachment !== null) { this._ass.addAttachment(this._currentAttachment); this._currentAttachment = null; } if (this._currentSection === Section.ScriptInfo && value !== Section.ScriptInfo) { // Exiting script info section this._minimalDeferred.resolve(this._ass); } if (value === Section.EOF) { var scriptProperties = this._ass.properties; if (scriptProperties.resolutionX === undefined || scriptProperties.resolutionY === undefined) { // Malformed script. this._minimalDeferred.reject("Malformed ASS script."); this._deferred.reject("Malformed ASS script."); } else { this._minimalDeferred.resolve(this._ass); this._deferred.resolve(this._ass); } } this._currentSection = value; }, enumerable: true, configurable: true }); /** * @param {string} line * * @private */ StreamParser.prototype._onNextLine = function (line) { var _this = this; if (line === null) { this.currentSection = Section.EOF; return; } if (line[line.length - 1] === "\r") { line = line.substr(0, line.length - 1); } if (line.charCodeAt(0) === 65279 && this._shouldSwallowBom) { line = line.substr(1); } this._shouldSwallowBom = false; if (line === "") {} else if (line[0] === ";" && this._currentAttachment === null) {} else if (line === "[Script Info]") { this.currentSection = Section.ScriptInfo; } else if (line === "[V4+ Styles]" || line === "[V4 Styles]") { this.currentSection = Section.Styles; } else if (line === "[Events]") { this.currentSection = Section.Events; } else if (line === "[Fonts]") { this.currentSection = Section.Fonts; } else if (line === "[Graphics]") { this.currentSection = Section.Graphics; } else { if (this._currentAttachment === null && line[0] === "[" && line[line.length - 1] === "]") { /* This looks like the start of a new section. The section name is unrecognized if it is. * Since there's no current attachment being parsed it's definitely the start of a new section. * If an attachment is being parsed, this might be part of the attachment. */ this.currentSection = Section.Other; } switch (this.currentSection) { case Section.ScriptInfo: var property = misc_1.parseLineIntoProperty(line); if (property !== null) { switch (property.name) { case "PlayResX": this._ass.properties.resolutionX = parseInt(property.value); break; case "PlayResY": this._ass.properties.resolutionY = parseInt(property.value); break; case "WrapStyle": this._ass.properties.wrappingStyle = parseInt(property.value); break; case "ScaledBorderAndShadow": this._ass.properties.scaleBorderAndShadow = property.value === "yes"; break; } } break; case Section.Styles: if (this._ass.stylesFormatSpecifier === null) { var property_1 = misc_1.parseLineIntoProperty(line); if (property_1 !== null && property_1.name === "Format") { this._ass.stylesFormatSpecifier = property_1.value.split(",").map(function (str) { return str.trim(); }); } else {} } else { try { this._ass.addStyle(line); } catch (ex) { if (settings_1.debugMode) { console.error("Could not parse style from line " + line + " - " + (ex.stack || ex)); } } } break; case Section.Events: if (this._ass.dialoguesFormatSpecifier === null) { var property_2 = misc_1.parseLineIntoProperty(line); if (property_2 !== null && property_2.name === "Format") { this._ass.dialoguesFormatSpecifier = property_2.value.split(",").map(function (str) { return str.trim(); }); } else {} } else { try { this._ass.addEvent(line); } catch (ex) { if (settings_1.debugMode) { console.error("Could not parse event from line " + line + " - " + (ex.stack || ex)); } } } break; case Section.Fonts: case Section.Graphics: var startOfNewAttachmentRegex = this.currentSection === Section.Fonts ? /^fontname:(.+)/ : /^filename:(.+)/; var startOfNewAttachment = startOfNewAttachmentRegex.exec(line); if (startOfNewAttachment !== null) { // Start of new attachment if (this._currentAttachment !== null) { this._ass.addAttachment(this._currentAttachment); this._currentAttachment = null; } this._currentAttachment = new attachment_1.Attachment(startOfNewAttachment[1].trim(), this.currentSection === Section.Fonts ? attachment_1.AttachmentType.Font : attachment_1.AttachmentType.Graphic); } else if (this._currentAttachment !== null) { try { this._currentAttachment.contents += uuencodedToBase64(line); } catch (ex) { if (settings_1.debugMode) { console.error("Encountered error while reading font " + this._currentAttachment.filename + ": %o", ex); } this._currentAttachment = null; } } else {} break; case Section.Other: // Ignore other sections. break; default: throw new Error("Unhandled state " + this.currentSection); } } this._stream.nextLine().then(function (line) { return _this._onNextLine(line); }, function (reason) { _this._minimalDeferred.reject(reason); _this._deferred.reject(reason); }); }; return StreamParser; }(); exports.StreamParser = StreamParser; /** * A parser that parses an {@link libjass.ASS} object from a {@link libjass.parser.Stream} of an SRT script. * * @param {!libjass.parser.Stream} stream The {@link libjass.parser.Stream} to parse * * @constructor * @memberOf libjass.parser */ var SrtStreamParser = function () { function SrtStreamParser(stream) { var _this = this; this._stream = stream; this._ass = new ass_1.ASS(); this._deferred = new promise_1.DeferredPromise(); this._shouldSwallowBom = true; this._currentDialogueNumber = null; this._currentDialogueStart = null; this._currentDialogueEnd = null; this._currentDialogueText = null; this._stream.nextLine().then(function (line) { return _this._onNextLine(line); }, function (reason) { _this._deferred.reject(reason); }); this._ass.properties.resolutionX = 1280; this._ass.properties.resolutionY = 720; this._ass.properties.wrappingStyle = 1; this._ass.properties.scaleBorderAndShadow = true; var newStyle = new style_1.Style(new map_1.Map([ [ "Name", "Default" ], [ "FontSize", "36" ] ])); this._ass.styles.set(newStyle.name, newStyle); } Object.defineProperty(SrtStreamParser.prototype, "ass", { /** * @type {!Promise.} A promise that will be resolved when the entire stream has been parsed. */ get: function () { return this._deferred.promise; }, enumerable: true, configurable: true }); /** * @param {string} line * * @private */ SrtStreamParser.prototype._onNextLine = function (line) { var _this = this; if (line === null) { if (this._currentDialogueNumber !== null && this._currentDialogueStart !== null && this._currentDialogueEnd !== null && this._currentDialogueText !== null) { this._ass.dialogues.push(new dialogue_1.Dialogue(new map_1.Map([ [ "Style", "Default" ], [ "Start", this._currentDialogueStart ], [ "End", this._currentDialogueEnd ], [ "Text", this._currentDialogueText ] ]), this._ass)); } this._deferred.resolve(this._ass); return; } if (line[line.length - 1] === "\r") { line = line.substr(0, line.length - 1); } if (line.charCodeAt(0) === 65279 && this._shouldSwallowBom) { line = line.substr(1); } this._shouldSwallowBom = false; if (line === "") { if (this._currentDialogueNumber !== null && this._currentDialogueStart !== null && this._currentDialogueEnd !== null && this._currentDialogueText !== null) { this._ass.dialogues.push(new dialogue_1.Dialogue(new map_1.Map([ [ "Style", "Default" ], [ "Start", this._currentDialogueStart ], [ "End", this._currentDialogueEnd ], [ "Text", this._currentDialogueText ] ]), this._ass)); } this._currentDialogueNumber = this._currentDialogueStart = this._currentDialogueEnd = this._currentDialogueText = null; } else { if (this._currentDialogueNumber === null) { if (/^\d+$/.test(line)) { this._currentDialogueNumber = line; } } else if (this._currentDialogueStart === null && this._currentDialogueEnd === null) { var match = /^(\d\d:\d\d:\d\d,\d\d\d) --> (\d\d:\d\d:\d\d,\d\d\d)/.exec(line); if (match !== null) { this._currentDialogueStart = match[1].replace(",", "."); this._currentDialogueEnd = match[2].replace(",", "."); } } else { line = line.replace(//g, "{\\b1}").replace(/\{b\}/g, "{\\b1}").replace(/<\/b>/g, "{\\b0}").replace(/\{\/b\}/g, "{\\b0}").replace(//g, "{\\i1}").replace(/\{i\}/g, "{\\i1}").replace(/<\/i>/g, "{\\i0}").replace(/\{\/i\}/g, "{\\i0}").replace(//g, "{\\u1}").replace(/\{u\}/g, "{\\u1}").replace(/<\/u>/g, "{\\u0}").replace(/\{\/u\}/g, "{\\u0}").replace(//g, function (/* ujs:unreferenced */ substring, red, green, blue) { return "{c&H" + blue + green + red + "&}"; }).replace(/<\/font>/g, "{\\c}"); if (this._currentDialogueText !== null) { this._currentDialogueText += "\\N" + line; } else { this._currentDialogueText = line; } } } this._stream.nextLine().then(function (line) { return _this._onNextLine(line); }, function (reason) { _this._deferred.reject(reason); }); }; return SrtStreamParser; }(); exports.SrtStreamParser = SrtStreamParser; /** * Converts a uuencoded string to a base64 string. * * @param {string} str * @return {string} * * @private */ function uuencodedToBase64(str) { var result = ""; for (var i = 0; i < str.length; i++) { var charCode = str.charCodeAt(i) - 33; if (charCode < 0 || charCode > 63) { throw new Error("Out-of-range character code " + charCode + " at index " + i + " in string " + str); } if (charCode < 26) { result += String.fromCharCode("A".charCodeAt(0) + charCode); } else if (charCode < 52) { result += String.fromCharCode("a".charCodeAt(0) + charCode - 26); } else if (charCode < 62) { result += String.fromCharCode("0".charCodeAt(0) + charCode - 52); } else if (charCode === 62) { result += "+"; } else { result += "/"; } } return result; } }, /* 5 ./parser/streams */ function (exports, require) { var promise_1 = require(32); /** * A {@link libjass.parser.Stream} that reads from a string in memory. * * @param {string} str The string * * @constructor * @implements {libjass.parser.Stream} * @memberOf libjass.parser */ var StringStream = function () { function StringStream(str) { this._str = str; this._readTill = 0; } /** * @return {!Promise.} A promise that will be resolved with the next line, or null if the string has been completely read. */ StringStream.prototype.nextLine = function () { var result = null; if (this._readTill < this._str.length) { var nextNewLinePos = this._str.indexOf("\n", this._readTill); if (nextNewLinePos !== -1) { result = promise_1.Promise.resolve(this._str.substring(this._readTill, nextNewLinePos)); this._readTill = nextNewLinePos + 1; } else { result = promise_1.Promise.resolve(this._str.substr(this._readTill)); this._readTill = this._str.length; } } else { result = promise_1.Promise.resolve(null); } return result; }; return StringStream; }(); exports.StringStream = StringStream; /** * A {@link libjass.parser.Stream} that reads from an XMLHttpRequest object. * * @param {!XMLHttpRequest} xhr The XMLHttpRequest object. Make sure to not call .open() on this object before passing it in here, * since event handlers cannot be registered after open() has been called. * * @constructor * @implements {libjass.parser.Stream} * @memberOf libjass.parser */ var XhrStream = function () { function XhrStream(xhr) { var _this = this; this._xhr = xhr; this._readTill = 0; this._pendingDeferred = null; this._failedError = null; xhr.addEventListener("progress", function () { return _this._onXhrProgress(); }, false); xhr.addEventListener("load", function () { return _this._onXhrLoad(); }, false); xhr.addEventListener("error", function (event) { return _this._onXhrError(event); }, false); } /** * @return {!Promise.} A promise that will be resolved with the next line, or null if the stream is exhausted. */ XhrStream.prototype.nextLine = function () { if (this._pendingDeferred !== null) { throw new Error("XhrStream only supports one pending unfulfilled read at a time."); } var deferred = this._pendingDeferred = new promise_1.DeferredPromise(); this._tryResolveNextLine(); return deferred.promise; }; /** * @private */ XhrStream.prototype._onXhrProgress = function () { if (this._pendingDeferred === null) { return; } if (this._xhr.readyState === XMLHttpRequest.DONE) { /* Suppress resolving next line here. Let the "load" or "error" event handlers do it. * * This is required because a failed XHR fires the progress event with readyState === DONE before it fires the error event. * This would confuse _tryResolveNextLine() into thinking the request succeeded with no data if it was called here. */ return; } this._tryResolveNextLine(); }; /** * @private */ XhrStream.prototype._onXhrLoad = function () { if (this._pendingDeferred === null) { return; } this._tryResolveNextLine(); }; /** * @param {!ErrorEvent} event * * @private */ XhrStream.prototype._onXhrError = function (event) { this._failedError = event; if (this._pendingDeferred === null) { return; } this._tryResolveNextLine(); }; /** * @private */ XhrStream.prototype._tryResolveNextLine = function () { if (this._failedError !== null) { this._pendingDeferred.reject(this._failedError); return; } var response = this._xhr.responseText; var nextNewLinePos = response.indexOf("\n", this._readTill); if (nextNewLinePos !== -1) { this._pendingDeferred.resolve(response.substring(this._readTill, nextNewLinePos)); this._readTill = nextNewLinePos + 1; this._pendingDeferred = null; } else if (this._xhr.readyState === XMLHttpRequest.DONE) { if (this._failedError !== null) { this._pendingDeferred.reject(this._failedError); } else if (this._readTill < response.length) { this._pendingDeferred.resolve(response.substr(this._readTill)); this._readTill = response.length; } else { this._pendingDeferred.resolve(null); } this._pendingDeferred = null; } }; return XhrStream; }(); exports.XhrStream = XhrStream; /** * A {@link libjass.parser.Stream} that reads from a ReadableStream object. * * @param {!ReadableStream} stream * @param {string} encoding * * @constructor * @implements {libjass.parser.Stream} * @memberOf libjass.parser */ var BrowserReadableStream = function () { function BrowserReadableStream(stream, encoding) { this._buffer = ""; this._pendingDeferred = null; this._reader = stream.getReader(); this._decoder = new global.TextDecoder(encoding, { ignoreBOM: true }); } /** * @return {!Promise.} A promise that will be resolved with the next line, or null if the stream is exhausted. */ BrowserReadableStream.prototype.nextLine = function () { if (this._pendingDeferred !== null) { throw new Error("BrowserReadableStream only supports one pending unfulfilled read at a time."); } var deferred = this._pendingDeferred = new promise_1.DeferredPromise(); this._tryResolveNextLine(); return deferred.promise; }; /** * @private */ BrowserReadableStream.prototype._tryResolveNextLine = function () { var _this = this; var nextNewLinePos = this._buffer.indexOf("\n"); if (nextNewLinePos !== -1) { this._pendingDeferred.resolve(this._buffer.substr(0, nextNewLinePos)); this._buffer = this._buffer.substr(nextNewLinePos + 1); this._pendingDeferred = null; } else { this._reader.read().then(function (next) { var value = next.value; var done = next.done; if (!done) { _this._buffer += _this._decoder.decode(value, { stream: true }); _this._tryResolveNextLine(); } else { // No more data. if (_this._buffer.length === 0) { _this._pendingDeferred.resolve(null); } else { _this._pendingDeferred.resolve(_this._buffer); _this._buffer = ""; } _this._pendingDeferred = null; } }); } }; return BrowserReadableStream; }(); exports.BrowserReadableStream = BrowserReadableStream; }, /* 6 ./parser/ttf */ function (exports, require) { var __decorate = require(34).__decorate; var map_1 = require(30); var set_1 = require(33); var DataType; (function (DataType) { DataType[DataType["Char"] = 0] = "Char"; DataType[DataType["Uint16"] = 1] = "Uint16"; DataType[DataType["Uint32"] = 2] = "Uint32"; })(DataType || (DataType = {})); var fieldDecorators = new map_1.Map(); var OffsetTable = function () { function OffsetTable() {} __decorate([ field(DataType.Uint16) ], OffsetTable.prototype, "majorVersion", void 0); __decorate([ field(DataType.Uint16) ], OffsetTable.prototype, "minorVersion", void 0); __decorate([ field(DataType.Uint16) ], OffsetTable.prototype, "numTables", void 0); __decorate([ field(DataType.Uint16) ], OffsetTable.prototype, "searchRange", void 0); __decorate([ field(DataType.Uint16) ], OffsetTable.prototype, "entrySelector", void 0); __decorate([ field(DataType.Uint16) ], OffsetTable.prototype, "rangeShift", void 0); OffsetTable = __decorate([ struct ], OffsetTable); return OffsetTable; }(); var TableRecord = function () { function TableRecord() {} __decorate([ field(DataType.Char) ], TableRecord.prototype, "c1", void 0); __decorate([ field(DataType.Char) ], TableRecord.prototype, "c2", void 0); __decorate([ field(DataType.Char) ], TableRecord.prototype, "c3", void 0); __decorate([ field(DataType.Char) ], TableRecord.prototype, "c4", void 0); __decorate([ field(DataType.Uint32) ], TableRecord.prototype, "checksum", void 0); __decorate([ field(DataType.Uint32) ], TableRecord.prototype, "offset", void 0); __decorate([ field(DataType.Uint32) ], TableRecord.prototype, "length", void 0); TableRecord = __decorate([ struct ], TableRecord); return TableRecord; }(); var NameTableHeader = function () { function NameTableHeader() {} __decorate([ field(DataType.Uint16) ], NameTableHeader.prototype, "formatSelector", void 0); __decorate([ field(DataType.Uint16) ], NameTableHeader.prototype, "count", void 0); __decorate([ field(DataType.Uint16) ], NameTableHeader.prototype, "stringOffset", void 0); NameTableHeader = __decorate([ struct ], NameTableHeader); return NameTableHeader; }(); var NameRecord = function () { function NameRecord() {} __decorate([ field(DataType.Uint16) ], NameRecord.prototype, "platformId", void 0); __decorate([ field(DataType.Uint16) ], NameRecord.prototype, "encodingId", void 0); __decorate([ field(DataType.Uint16) ], NameRecord.prototype, "languageId", void 0); __decorate([ field(DataType.Uint16) ], NameRecord.prototype, "nameId", void 0); __decorate([ field(DataType.Uint16) ], NameRecord.prototype, "length", void 0); __decorate([ field(DataType.Uint16) ], NameRecord.prototype, "offset", void 0); NameRecord = __decorate([ struct ], NameRecord); return NameRecord; }(); /** * Gets all the font names from the given font attachment. * * @param {!libjass.Attachment} attachment * @return {!libjass.Set.} */ function getTtfNames(attachment) { var decoded = atob(attachment.contents); var bytes = new Uint8Array(new ArrayBuffer(decoded.length)); for (var i = 0; i < decoded.length; i++) { bytes[i] = decoded.charCodeAt(i); } var reader = { dataView: new DataView(bytes.buffer), position: 0 }; var offsetTable = OffsetTable.read(reader); var nameTableRecord = null; for (var i = 0; i < offsetTable.numTables; i++) { var tableRecord = TableRecord.read(reader); if (tableRecord.c1 + tableRecord.c2 + tableRecord.c3 + tableRecord.c4 === "name") { nameTableRecord = tableRecord; break; } } reader.position = nameTableRecord.offset; var nameTableHeader = NameTableHeader.read(reader); var result = new set_1.Set(); for (var i = 0; i < nameTableHeader.count; i++) { var nameRecord = NameRecord.read(reader); switch (nameRecord.nameId) { case 1: case 4: case 6: var recordOffset = nameTableRecord.offset + nameTableHeader.stringOffset + nameRecord.offset; var nameBytes = bytes.subarray(recordOffset, recordOffset + nameRecord.length); switch (nameRecord.platformId) { case 1: { var name_1 = ""; for (var j = 0; j < nameBytes.length; j++) { name_1 += String.fromCharCode(nameBytes[j]); } result.add(name_1); } break; case 3: { var name_2 = ""; for (var j = 0; j < nameBytes.length; j += 2) { name_2 += String.fromCharCode((nameBytes[j] << 8) + nameBytes[j + 1]); } result.add(name_2); } break; } break; default: break; } } return result; } exports.getTtfNames = getTtfNames; /** * @param {!function(new(): T)} clazz * @return {!function(new(): T)} * * @template T * @private */ function struct(clazz) { var fields = clazz.__fields; clazz.read = function (reader) { var result = new clazz(); for (var _i = 0; _i < fields.length; _i++) { var field_1 = fields[_i]; var value = void 0; switch (field_1.type) { case DataType.Char: value = String.fromCharCode(reader.dataView.getInt8(reader.position)); reader.position += 1; break; case DataType.Uint16: value = reader.dataView.getUint16(reader.position); reader.position += 2; break; case DataType.Uint32: value = reader.dataView.getUint32(reader.position); reader.position += 4; break; } result[field_1.field] = value; } return result; }; return clazz; } /** * @param {number} type * @return {function(T, string)} * * @template T * @private */ function field(type) { var existingDecorator = fieldDecorators.get(type); if (existingDecorator === undefined) { existingDecorator = function (proto, field) { var ctor = proto.constructor; if (ctor.__fields === undefined) { ctor.__fields = []; } ctor.__fields.push({ type: type, field: field }); }; fieldDecorators.set(type, existingDecorator); } return existingDecorator; } }, /* 7 ./parts/drawing */ function (exports) { /** * An instruction to move to a particular position. * * @param {number} x * @param {number} y * * @constructor * @implements {libjass.parts.drawing.Instruction} * @memberOf libjass.parts.drawing */ var MoveInstruction = function () { function MoveInstruction(x, y) { this._x = x; this._y = y; } Object.defineProperty(MoveInstruction.prototype, "x", { /** * The X position of this move instruction. * * @type {number} */ get: function () { return this._x; }, enumerable: true, configurable: true }); Object.defineProperty(MoveInstruction.prototype, "y", { /** * The Y position of this move instruction. * * @type {number} */ get: function () { return this._y; }, enumerable: true, configurable: true }); return MoveInstruction; }(); exports.MoveInstruction = MoveInstruction; /** * An instruction to draw a line to a particular position. * * @param {number} x * @param {number} y * * @constructor * @implements {libjass.parts.drawing.Instruction} * @memberOf libjass.parts.drawing */ var LineInstruction = function () { function LineInstruction(x, y) { this._x = x; this._y = y; } Object.defineProperty(LineInstruction.prototype, "x", { /** * The X position of this line instruction. * * @type {number} */ get: function () { return this._x; }, enumerable: true, configurable: true }); Object.defineProperty(LineInstruction.prototype, "y", { /** * The Y position of this line instruction. * * @type {number} */ get: function () { return this._y; }, enumerable: true, configurable: true }); return LineInstruction; }(); exports.LineInstruction = LineInstruction; /** * An instruction to draw a cubic bezier curve to a particular position, with two given control points. * * @param {number} x1 * @param {number} y1 * @param {number} x2 * @param {number} y2 * @param {number} x3 * @param {number} y3 * * @constructor * @implements {libjass.parts.drawing.Instruction} * @memberOf libjass.parts.drawing */ var CubicBezierCurveInstruction = function () { function CubicBezierCurveInstruction(x1, y1, x2, y2, x3, y3) { this._x1 = x1; this._y1 = y1; this._x2 = x2; this._y2 = y2; this._x3 = x3; this._y3 = y3; } Object.defineProperty(CubicBezierCurveInstruction.prototype, "x1", { /** * The X position of the first control point of this cubic bezier curve instruction. * * @type {number} */ get: function () { return this._x1; }, enumerable: true, configurable: true }); Object.defineProperty(CubicBezierCurveInstruction.prototype, "y1", { /** * The Y position of the first control point of this cubic bezier curve instruction. * * @type {number} */ get: function () { return this._y1; }, enumerable: true, configurable: true }); Object.defineProperty(CubicBezierCurveInstruction.prototype, "x2", { /** * The X position of the second control point of this cubic bezier curve instruction. * * @type {number} */ get: function () { return this._x2; }, enumerable: true, configurable: true }); Object.defineProperty(CubicBezierCurveInstruction.prototype, "y2", { /** * The Y position of the second control point of this cubic bezier curve instruction. * * @type {number} */ get: function () { return this._y2; }, enumerable: true, configurable: true }); Object.defineProperty(CubicBezierCurveInstruction.prototype, "x3", { /** * The ending X position of this cubic bezier curve instruction. * * @type {number} */ get: function () { return this._x3; }, enumerable: true, configurable: true }); Object.defineProperty(CubicBezierCurveInstruction.prototype, "y3", { /** * The ending Y position of this cubic bezier curve instruction. * * @type {number} */ get: function () { return this._y3; }, enumerable: true, configurable: true }); return CubicBezierCurveInstruction; }(); exports.CubicBezierCurveInstruction = CubicBezierCurveInstruction; }, /* 8 ./parts/index */ function (exports, require) { var drawing = require(7); exports.drawing = drawing; /** * Represents a CSS color with red, green, blue and alpha components. * * Instances of this class are immutable. * * @param {number} red * @param {number} green * @param {number} blue * @param {number=1} alpha * * @constructor * @memberOf libjass.parts */ var Color = function () { function Color(red, green, blue, alpha) { if (alpha === void 0) { alpha = 1; } this._red = red; this._green = green; this._blue = blue; this._alpha = alpha; } Object.defineProperty(Color.prototype, "red", { /** * The red component of this color as a number between 0 and 255. * * @type {number} */ get: function () { return this._red; }, enumerable: true, configurable: true }); Object.defineProperty(Color.prototype, "green", { /** * The green component of this color as a number between 0 and 255. * * @type {number} */ get: function () { return this._green; }, enumerable: true, configurable: true }); Object.defineProperty(Color.prototype, "blue", { /** * The blue component of this color as a number between 0 and 255. * * @type {number} */ get: function () { return this._blue; }, enumerable: true, configurable: true }); Object.defineProperty(Color.prototype, "alpha", { /** * The alpha component of this color as a number between 0 and 1, where 0 means transparent and 1 means opaque. * * @type {number} */ get: function () { return this._alpha; }, enumerable: true, configurable: true }); /** * @param {?number} value The new alpha. If null, the existing alpha is used. * @return {!libjass.parts.Color} Returns a new Color instance with the same color but the provided alpha. */ Color.prototype.withAlpha = function (value) { if (value !== null) { return new Color(this._red, this._green, this._blue, value); } return this; }; /** * @return {string} The CSS representation "rgba(...)" of this color. */ Color.prototype.toString = function () { return "rgba(" + this._red + ", " + this._green + ", " + this._blue + ", " + this._alpha.toFixed(3) + ")"; }; /** * Returns a new Color by interpolating the current color to the final color by the given progression. * * @param {!libjass.parts.Color} final * @param {number} progression * @return {!libjass.parts.Color} */ Color.prototype.interpolate = function (final, progression) { return new Color(this._red + progression * (final.red - this._red), this._green + progression * (final.green - this._green), this._blue + progression * (final.blue - this._blue), this._alpha + progression * (final.alpha - this._alpha)); }; return Color; }(); exports.Color = Color; /** * A comment, i.e., any text enclosed in {} that is not understood as an ASS tag. * * @param {string} value The text of this comment * * @constructor * @memberOf libjass.parts */ var Comment = function () { function Comment(value) { this._value = value; } Object.defineProperty(Comment.prototype, "value", { /** * The value of this comment. * * @type {string} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Comment; }(); exports.Comment = Comment; /** * A block of text, i.e., any text not enclosed in {}. Also includes \h. * * @param {string} value The content of this block of text * * @constructor * @memberOf libjass.parts */ var Text = function () { function Text(value) { this._value = value; } Object.defineProperty(Text.prototype, "value", { /** * The value of this text part. * * @type {string} */ get: function () { return this._value; }, enumerable: true, configurable: true }); /** * @return {string} */ Text.prototype.toString = function () { return "Text { value: " + this._value.replace(/\u00A0/g, "\\h") + " }"; }; return Text; }(); exports.Text = Text; /** * A newline character \N. * * @constructor * @memberOf libjass.parts */ var NewLine = function () { function NewLine() {} return NewLine; }(); exports.NewLine = NewLine; /** * An italic tag {\i} * * @param {?boolean} value {\i1} -> true, {\i0} -> false, {\i} -> null * * @constructor * @memberOf libjass.parts */ var Italic = function () { function Italic(value) { this._value = value; } Object.defineProperty(Italic.prototype, "value", { /** * The value of this italic tag. * * @type {?boolean} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Italic; }(); exports.Italic = Italic; /** * A bold tag {\b} * * @param {*} value {\b1} -> true, {\b0} -> false, {\b###} -> weight of the bold (number), {\b} -> null * * @constructor * @memberOf libjass.parts */ var Bold = function () { function Bold(value) { this._value = value; } Object.defineProperty(Bold.prototype, "value", { /** * The value of this bold tag. * * @type {?boolean|?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Bold; }(); exports.Bold = Bold; /** * An underline tag {\u} * * @param {?boolean} value {\u1} -> true, {\u0} -> false, {\u} -> null * * @constructor * @memberOf libjass.parts */ var Underline = function () { function Underline(value) { this._value = value; } Object.defineProperty(Underline.prototype, "value", { /** * The value of this underline tag. * * @type {?boolean} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Underline; }(); exports.Underline = Underline; /** * A strike-through tag {\s} * * @param {?boolean} value {\s1} -> true, {\s0} -> false, {\s} -> null * * @constructor * @memberOf libjass.parts */ var StrikeThrough = function () { function StrikeThrough(value) { this._value = value; } Object.defineProperty(StrikeThrough.prototype, "value", { /** * The value of this strike-through tag. * * @type {?boolean} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return StrikeThrough; }(); exports.StrikeThrough = StrikeThrough; /** * A border tag {\bord} * * @param {?number} value {\bord###} -> width (number), {\bord} -> null * * @constructor * @memberOf libjass.parts */ var Border = function () { function Border(value) { this._value = value; } Object.defineProperty(Border.prototype, "value", { /** * The value of this border tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Border; }(); exports.Border = Border; /** * A horizontal border tag {\xbord} * * @param {?number} value {\xbord###} -> width (number), {\xbord} -> null * * @constructor * @memberOf libjass.parts */ var BorderX = function () { function BorderX(value) { this._value = value; } Object.defineProperty(BorderX.prototype, "value", { /** * The value of this horizontal border tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return BorderX; }(); exports.BorderX = BorderX; /** * A vertical border tag {\ybord} * * @param {?number} value {\ybord###} -> height (number), {\ybord} -> null * * @constructor * @memberOf libjass.parts */ var BorderY = function () { function BorderY(value) { this._value = value; } Object.defineProperty(BorderY.prototype, "value", { /** * The value of this vertical border tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return BorderY; }(); exports.BorderY = BorderY; /** * A shadow tag {\shad} * * @param {?number} value {\shad###} -> depth (number), {\shad} -> null * * @constructor * @memberOf libjass.parts */ var Shadow = function () { function Shadow(value) { this._value = value; } Object.defineProperty(Shadow.prototype, "value", { /** * The value of this shadow tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Shadow; }(); exports.Shadow = Shadow; /** * A horizontal shadow tag {\xshad} * * @param {?number} value {\xshad###} -> depth (number), {\xshad} -> null * * @constructor * @memberOf libjass.parts */ var ShadowX = function () { function ShadowX(value) { this._value = value; } Object.defineProperty(ShadowX.prototype, "value", { /** * The value of this horizontal shadow tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return ShadowX; }(); exports.ShadowX = ShadowX; /** * A vertical shadow tag {\yshad} * * @param {?number} value {\yshad###} -> depth (number), {\yshad} -> null * * @constructor * @memberOf libjass.parts */ var ShadowY = function () { function ShadowY(value) { this._value = value; } Object.defineProperty(ShadowY.prototype, "value", { /** * The value of this vertical shadow tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return ShadowY; }(); exports.ShadowY = ShadowY; /** * A blur tag {\be} * * @param {?number} value {\be###} -> strength (number), {\be} -> null * * @constructor * @memberOf libjass.parts */ var Blur = function () { function Blur(value) { this._value = value; } Object.defineProperty(Blur.prototype, "value", { /** * The value of this blur tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Blur; }(); exports.Blur = Blur; /** * A Gaussian blur tag {\blur} * * @param {?number} value {\blur###} -> strength (number), {\blur} -> null * * @constructor * @memberOf libjass.parts */ var GaussianBlur = function () { function GaussianBlur(value) { this._value = value; } Object.defineProperty(GaussianBlur.prototype, "value", { /** * The value of this Gaussian blur tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return GaussianBlur; }(); exports.GaussianBlur = GaussianBlur; /** * A font name tag {\fn} * * @param {?string} value {\fn###} -> name (string), {\fn} -> null * * @constructor * @memberOf libjass.parts */ var FontName = function () { function FontName(value) { this._value = value; } Object.defineProperty(FontName.prototype, "value", { /** * The value of this font name tag. * * @type {?string} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return FontName; }(); exports.FontName = FontName; /** * A font size tag {\fs} * * @param {?number} value {\fs###} -> size (number), {\fs} -> null * * @constructor * @memberOf libjass.parts */ var FontSize = function () { function FontSize(value) { this._value = value; } Object.defineProperty(FontSize.prototype, "value", { /** * The value of this font size tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return FontSize; }(); exports.FontSize = FontSize; /** * A font size increase tag {\fs+} * * @param {number} value {\fs+###} -> difference (number) * * @constructor * @memberOf libjass.parts */ var FontSizePlus = function () { function FontSizePlus(value) { this._value = value; } Object.defineProperty(FontSizePlus.prototype, "value", { /** * The value of this font size increase tag. * * @type {number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return FontSizePlus; }(); exports.FontSizePlus = FontSizePlus; /** * A font size decrease tag {\fs-} * * @param {number} value {\fs-###} -> difference (number) * * @constructor * @memberOf libjass.parts */ var FontSizeMinus = function () { function FontSizeMinus(value) { this._value = value; } Object.defineProperty(FontSizeMinus.prototype, "value", { /** * The value of this font size decrease tag. * * @type {number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return FontSizeMinus; }(); exports.FontSizeMinus = FontSizeMinus; /** * A horizontal font scaling tag {\fscx} * * @param {?number} value {\fscx###} -> scale (number), {\fscx} -> null * * @constructor * @memberOf libjass.parts */ var FontScaleX = function () { function FontScaleX(value) { this._value = value; } Object.defineProperty(FontScaleX.prototype, "value", { /** * The value of this horizontal font scaling tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return FontScaleX; }(); exports.FontScaleX = FontScaleX; /** * A vertical font scaling tag {\fscy} * * @param {?number} value {\fscy###} -> scale (number), {\fscy} -> null * * @constructor * @memberOf libjass.parts */ var FontScaleY = function () { function FontScaleY(value) { this._value = value; } Object.defineProperty(FontScaleY.prototype, "value", { /** * The value of this vertical font scaling tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return FontScaleY; }(); exports.FontScaleY = FontScaleY; /** * A letter-spacing tag {\fsp} * * @param {?number} value {\fsp###} -> spacing (number), {\fsp} -> null * * @constructor * @memberOf libjass.parts */ var LetterSpacing = function () { function LetterSpacing(value) { this._value = value; } Object.defineProperty(LetterSpacing.prototype, "value", { /** * The value of this letter-spacing tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return LetterSpacing; }(); exports.LetterSpacing = LetterSpacing; /** * An X-axis rotation tag {\frx} * * @param {?number} value {\frx###} -> angle (number), {\frx} -> null * * @constructor * @memberOf libjass.parts */ var RotateX = function () { function RotateX(value) { this._value = value; } Object.defineProperty(RotateX.prototype, "value", { /** * The value of this X-axis rotation tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return RotateX; }(); exports.RotateX = RotateX; /** * A Y-axis rotation tag {\fry} * * @param {?number} value {\fry###} -> angle (number), {\fry} -> null * * @constructor * @memberOf libjass.parts */ var RotateY = function () { function RotateY(value) { this._value = value; } Object.defineProperty(RotateY.prototype, "value", { /** * The value of this Y-axis rotation tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return RotateY; }(); exports.RotateY = RotateY; /** * A Z-axis rotation tag {\fr} or {\frz} * * @param {?number} value {\frz###} -> angle (number), {\frz} -> null * * @constructor * @memberOf libjass.parts */ var RotateZ = function () { function RotateZ(value) { this._value = value; } Object.defineProperty(RotateZ.prototype, "value", { /** * The value of this Z-axis rotation tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return RotateZ; }(); exports.RotateZ = RotateZ; /** * An X-axis shearing tag {\fax} * * @param {?number} value {\fax###} -> angle (number), {\fax} -> null * * @constructor * @memberOf libjass.parts */ var SkewX = function () { function SkewX(value) { this._value = value; } Object.defineProperty(SkewX.prototype, "value", { /** * The value of this X-axis shearing tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return SkewX; }(); exports.SkewX = SkewX; /** * A Y-axis shearing tag {\fay} * * @param {?number} value {\fay###} -> angle (number), {\fay} -> null * * @constructor * @memberOf libjass.parts */ var SkewY = function () { function SkewY(value) { this._value = value; } Object.defineProperty(SkewY.prototype, "value", { /** * The value of this Y-axis shearing tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return SkewY; }(); exports.SkewY = SkewY; /** * A primary color tag {\c} or {\1c} * * @param {libjass.parts.Color} value {\1c###} -> color (Color), {\1c} -> null * * @constructor * @memberOf libjass.parts */ var PrimaryColor = function () { function PrimaryColor(value) { this._value = value; } Object.defineProperty(PrimaryColor.prototype, "value", { /** * The value of this primary color tag. * * @type {libjass.parts.Color} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return PrimaryColor; }(); exports.PrimaryColor = PrimaryColor; /** * A secondary color tag {\2c} * * @param {libjass.parts.Color} value {\2c###} -> color (Color), {\2c} -> null * * @constructor * @memberOf libjass.parts */ var SecondaryColor = function () { function SecondaryColor(value) { this._value = value; } Object.defineProperty(SecondaryColor.prototype, "value", { /** * The value of this secondary color tag. * * @type {libjass.parts.Color} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return SecondaryColor; }(); exports.SecondaryColor = SecondaryColor; /** * An outline color tag {\3c} * * @param {libjass.parts.Color} value {\3c###} -> color (Color), {\3c} -> null * * @constructor * @memberOf libjass.parts */ var OutlineColor = function () { function OutlineColor(value) { this._value = value; } Object.defineProperty(OutlineColor.prototype, "value", { /** * The value of this outline color tag. * * @type {libjass.parts.Color} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return OutlineColor; }(); exports.OutlineColor = OutlineColor; /** * A shadow color tag {\4c} * * @param {libjass.parts.Color} value {\4c###} -> color (Color), {\4c} -> null * * @constructor * @memberOf libjass.parts */ var ShadowColor = function () { function ShadowColor(value) { this._value = value; } Object.defineProperty(ShadowColor.prototype, "value", { /** * The value of this shadow color tag. * * @type {libjass.parts.Color} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return ShadowColor; }(); exports.ShadowColor = ShadowColor; /** * An alpha tag {\alpha} * * @param {?number} value {\alpha###} -> alpha (number), {\alpha} -> null * * @constructor * @memberOf libjass.parts */ var Alpha = function () { function Alpha(value) { this._value = value; } Object.defineProperty(Alpha.prototype, "value", { /** * The value of this alpha tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Alpha; }(); exports.Alpha = Alpha; /** * A primary alpha tag {\1a} * * @param {?number} value {\1a###} -> alpha (number), {\1a} -> null * * @constructor * @memberOf libjass.parts */ var PrimaryAlpha = function () { function PrimaryAlpha(value) { this._value = value; } Object.defineProperty(PrimaryAlpha.prototype, "value", { /** * The value of this primary alpha tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return PrimaryAlpha; }(); exports.PrimaryAlpha = PrimaryAlpha; /** * A secondary alpha tag {\2a} * * @param {?number} value {\2a###} -> alpha (number), {\2a} -> null * * @constructor * @memberOf libjass.parts */ var SecondaryAlpha = function () { function SecondaryAlpha(value) { this._value = value; } Object.defineProperty(SecondaryAlpha.prototype, "value", { /** * The value of this secondary alpha tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return SecondaryAlpha; }(); exports.SecondaryAlpha = SecondaryAlpha; /** * An outline alpha tag {\3a} * * @param {?number} value {\3a###} -> alpha (number), {\3a} -> null * * @constructor * @memberOf libjass.parts */ var OutlineAlpha = function () { function OutlineAlpha(value) { this._value = value; } Object.defineProperty(OutlineAlpha.prototype, "value", { /** * The value of this outline alpha tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return OutlineAlpha; }(); exports.OutlineAlpha = OutlineAlpha; /** * A shadow alpha tag {\4a} * * @param {?number} value {\4a###} -> alpha (number), {\4a} -> null * * @constructor * @memberOf libjass.parts */ var ShadowAlpha = function () { function ShadowAlpha(value) { this._value = value; } Object.defineProperty(ShadowAlpha.prototype, "value", { /** * The value of this shadow alpha tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return ShadowAlpha; }(); exports.ShadowAlpha = ShadowAlpha; /** * An alignment tag {\an} or {\a} * * @param {number} value {\an###} -> alignment (number) * * @constructor * @memberOf libjass.parts */ var Alignment = function () { function Alignment(value) { this._value = value; } Object.defineProperty(Alignment.prototype, "value", { /** * The value of this alignment tag. * * @type {?number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Alignment; }(); exports.Alignment = Alignment; /** * A color karaoke tag {\k} * * @param {number} duration {\k###} -> duration (number) * * @constructor * @memberOf libjass.parts */ var ColorKaraoke = function () { function ColorKaraoke(duration) { this._duration = duration; } Object.defineProperty(ColorKaraoke.prototype, "duration", { /** * The duration of this color karaoke tag. * * @type {number} */ get: function () { return this._duration; }, enumerable: true, configurable: true }); return ColorKaraoke; }(); exports.ColorKaraoke = ColorKaraoke; /** * A sweeping color karaoke tag {\K} or {\kf} * * @param {number} duration {\kf###} -> duration (number) * * @constructor * @memberOf libjass.parts */ var SweepingColorKaraoke = function () { function SweepingColorKaraoke(duration) { this._duration = duration; } Object.defineProperty(SweepingColorKaraoke.prototype, "duration", { /** * The duration of this sweeping color karaoke tag. * * @type {number} */ get: function () { return this._duration; }, enumerable: true, configurable: true }); return SweepingColorKaraoke; }(); exports.SweepingColorKaraoke = SweepingColorKaraoke; /** * An outline karaoke tag {\ko} * * @param {number} duration {\ko###} -> duration (number) * * @constructor * @memberOf libjass.parts */ var OutlineKaraoke = function () { function OutlineKaraoke(duration) { this._duration = duration; } Object.defineProperty(OutlineKaraoke.prototype, "duration", { /** * The duration of this outline karaoke tag. * * @type {number} */ get: function () { return this._duration; }, enumerable: true, configurable: true }); return OutlineKaraoke; }(); exports.OutlineKaraoke = OutlineKaraoke; /** * A wrapping style tag {\q} * * @param {number} value {\q###} -> style (number) * * @constructor * @memberOf libjass.parts */ var WrappingStyle = function () { function WrappingStyle(value) { this._value = value; } Object.defineProperty(WrappingStyle.prototype, "value", { /** * The value of this wrapping style tag. * * @type {number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return WrappingStyle; }(); exports.WrappingStyle = WrappingStyle; /** * A style reset tag {\r} * * @param {?string} value {\r###} -> style name (string), {\r} -> null * * @constructor * @memberOf libjass.parts */ var Reset = function () { function Reset(value) { this._value = value; } Object.defineProperty(Reset.prototype, "value", { /** * The value of this style reset tag. * * @type {?string} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return Reset; }(); exports.Reset = Reset; /** * A position tag {\pos} * * @param {number} x * @param {number} y * * @constructor * @memberOf libjass.parts */ var Position = function () { function Position(x, y) { this._x = x; this._y = y; } Object.defineProperty(Position.prototype, "x", { /** * The x value of this position tag. * * @type {number} */ get: function () { return this._x; }, enumerable: true, configurable: true }); Object.defineProperty(Position.prototype, "y", { /** * The y value of this position tag. * * @type {number} */ get: function () { return this._y; }, enumerable: true, configurable: true }); return Position; }(); exports.Position = Position; /** * A movement tag {\move} * * @param {number} x1 * @param {number} y1 * @param {number} x2 * @param {number} y2 * @param {number} t1 * @param {number} t2 * * @constructor * @memberOf libjass.parts */ var Move = function () { function Move(x1, y1, x2, y2, t1, t2) { this._x1 = x1; this._y1 = y1; this._x2 = x2; this._y2 = y2; this._t1 = t1; this._t2 = t2; } Object.defineProperty(Move.prototype, "x1", { /** * The starting x value of this move tag. * * @type {number} */ get: function () { return this._x1; }, enumerable: true, configurable: true }); Object.defineProperty(Move.prototype, "y1", { /** * The starting y value of this move tag. * * @type {number} */ get: function () { return this._y1; }, enumerable: true, configurable: true }); Object.defineProperty(Move.prototype, "x2", { /** * The ending x value of this move tag. * * @type {number} */ get: function () { return this._x2; }, enumerable: true, configurable: true }); Object.defineProperty(Move.prototype, "y2", { /** * The ending y value of this move tag. * * @type {number} */ get: function () { return this._y2; }, enumerable: true, configurable: true }); Object.defineProperty(Move.prototype, "t1", { /** * The start time of this move tag. * * @type {number} */ get: function () { return this._t1; }, enumerable: true, configurable: true }); Object.defineProperty(Move.prototype, "t2", { /** * The end time value of this move tag. * * @type {number} */ get: function () { return this._t2; }, enumerable: true, configurable: true }); return Move; }(); exports.Move = Move; /** * A rotation origin tag {\org} * * @param {number} x * @param {number} y * * @constructor * @memberOf libjass.parts */ var RotationOrigin = function () { function RotationOrigin(x, y) { this._x = x; this._y = y; } Object.defineProperty(RotationOrigin.prototype, "x", { /** * The x value of this rotation origin tag. * * @type {number} */ get: function () { return this._x; }, enumerable: true, configurable: true }); Object.defineProperty(RotationOrigin.prototype, "y", { /** * The y value of this rotation origin tag. * * @type {number} */ get: function () { return this._y; }, enumerable: true, configurable: true }); return RotationOrigin; }(); exports.RotationOrigin = RotationOrigin; /** * A simple fade tag {\fad} * * @param {number} start * @param {number} end * * @constructor * @memberOf libjass.parts */ var Fade = function () { function Fade(start, end) { this._start = start; this._end = end; } Object.defineProperty(Fade.prototype, "start", { /** * The start time of this fade tag. * * @type {number} */ get: function () { return this._start; }, enumerable: true, configurable: true }); Object.defineProperty(Fade.prototype, "end", { /** * The end time of this fade tag. * * @type {number} */ get: function () { return this._end; }, enumerable: true, configurable: true }); return Fade; }(); exports.Fade = Fade; /** * A complex fade tag {\fade} * * @param {number} a1 * @param {number} a2 * @param {number} a3 * @param {number} t1 * @param {number} t2 * @param {number} t3 * @param {number} t4 * * @constructor * @memberOf libjass.parts */ var ComplexFade = function () { function ComplexFade(a1, a2, a3, t1, t2, t3, t4) { this._a1 = a1; this._a2 = a2; this._a3 = a3; this._t1 = t1; this._t2 = t2; this._t3 = t3; this._t4 = t4; } Object.defineProperty(ComplexFade.prototype, "a1", { /** * The alpha value of this complex fade tag at time t2. * * @type {number} */ get: function () { return this._a1; }, enumerable: true, configurable: true }); Object.defineProperty(ComplexFade.prototype, "a2", { /** * The alpha value of this complex fade tag at time t3. * * @type {number} */ get: function () { return this._a2; }, enumerable: true, configurable: true }); Object.defineProperty(ComplexFade.prototype, "a3", { /** * The alpha value of this complex fade tag at time t4. * * @type {number} */ get: function () { return this._a3; }, enumerable: true, configurable: true }); Object.defineProperty(ComplexFade.prototype, "t1", { /** * The starting time of this complex fade tag. * * @type {number} */ get: function () { return this._t1; }, enumerable: true, configurable: true }); Object.defineProperty(ComplexFade.prototype, "t2", { /** * The first intermediate time of this complex fade tag. * * @type {number} */ get: function () { return this._t2; }, enumerable: true, configurable: true }); Object.defineProperty(ComplexFade.prototype, "t3", { /** * The second intermediate time of this complex fade tag. * * @type {number} */ get: function () { return this._t3; }, enumerable: true, configurable: true }); Object.defineProperty(ComplexFade.prototype, "t4", { /** * The ending time of this complex fade tag. * * @type {number} */ get: function () { return this._t4; }, enumerable: true, configurable: true }); return ComplexFade; }(); exports.ComplexFade = ComplexFade; /** * A transform tag {\t} * * @param {number} start * @param {number} end * @param {number} accel * @param {!Array.} tags * * @constructor * @memberOf libjass.parts */ var Transform = function () { function Transform(start, end, accel, tags) { this._start = start; this._end = end; this._accel = accel; this._tags = tags; } Object.defineProperty(Transform.prototype, "start", { /** * The starting time of this transform tag. * * @type {?number} */ get: function () { return this._start; }, enumerable: true, configurable: true }); Object.defineProperty(Transform.prototype, "end", { /** * The ending time of this transform tag. * * @type {?number} */ get: function () { return this._end; }, enumerable: true, configurable: true }); Object.defineProperty(Transform.prototype, "accel", { /** * The acceleration of this transform tag. * * @type {?number} */ get: function () { return this._accel; }, enumerable: true, configurable: true }); Object.defineProperty(Transform.prototype, "tags", { /** * The tags animated by this transform tag. * * @type {!Array.} */ get: function () { return this._tags; }, enumerable: true, configurable: true }); return Transform; }(); exports.Transform = Transform; /** * A rectangular clip tag {\clip} or {\iclip} * * @param {number} x1 * @param {number} y1 * @param {number} x2 * @param {number} y2 * @param {boolean} inside * * @constructor * @memberOf libjass.parts */ var RectangularClip = function () { function RectangularClip(x1, y1, x2, y2, inside) { this._x1 = x1; this._y1 = y1; this._x2 = x2; this._y2 = y2; this._inside = inside; } Object.defineProperty(RectangularClip.prototype, "x1", { /** * The X coordinate of the starting position of this rectangular clip tag. * * @type {number} */ get: function () { return this._x1; }, enumerable: true, configurable: true }); Object.defineProperty(RectangularClip.prototype, "y1", { /** * The Y coordinate of the starting position of this rectangular clip tag. * * @type {number} */ get: function () { return this._y1; }, enumerable: true, configurable: true }); Object.defineProperty(RectangularClip.prototype, "x2", { /** * The X coordinate of the ending position of this rectangular clip tag. * * @type {number} */ get: function () { return this._x2; }, enumerable: true, configurable: true }); Object.defineProperty(RectangularClip.prototype, "y2", { /** * The Y coordinate of the ending position of this rectangular clip tag. * * @type {number} */ get: function () { return this._y2; }, enumerable: true, configurable: true }); Object.defineProperty(RectangularClip.prototype, "inside", { /** * Whether this rectangular clip tag clips the region it encloses or the region it excludes. * * @type {boolean} */ get: function () { return this._inside; }, enumerable: true, configurable: true }); return RectangularClip; }(); exports.RectangularClip = RectangularClip; /** * A vector clip tag {\clip} or {\iclip} * * @param {number} scale * @param {!Array.} instructions * @param {boolean} inside * * @constructor * @memberOf libjass.parts */ var VectorClip = function () { function VectorClip(scale, instructions, inside) { this._scale = scale; this._instructions = instructions; this._inside = inside; } Object.defineProperty(VectorClip.prototype, "scale", { /** * The scale of this vector clip tag. * * @type {number} */ get: function () { return this._scale; }, enumerable: true, configurable: true }); Object.defineProperty(VectorClip.prototype, "instructions", { /** * The clip commands of this vector clip tag. * * @type {string} */ get: function () { return this._instructions; }, enumerable: true, configurable: true }); Object.defineProperty(VectorClip.prototype, "inside", { /** * Whether this vector clip tag clips the region it encloses or the region it excludes. * * @type {boolean} */ get: function () { return this._inside; }, enumerable: true, configurable: true }); return VectorClip; }(); exports.VectorClip = VectorClip; /** * A drawing mode tag {\p} * * @param {number} scale * * @constructor * @memberOf libjass.parts */ var DrawingMode = function () { function DrawingMode(scale) { this._scale = scale; } Object.defineProperty(DrawingMode.prototype, "scale", { /** * The scale of this drawing mode tag. * * @type {number} */ get: function () { return this._scale; }, enumerable: true, configurable: true }); return DrawingMode; }(); exports.DrawingMode = DrawingMode; /** * A drawing mode baseline offset tag {\pbo} * * @param {number} value * * @constructor * @memberOf libjass.parts */ var DrawingBaselineOffset = function () { function DrawingBaselineOffset(value) { this._value = value; } Object.defineProperty(DrawingBaselineOffset.prototype, "value", { /** * The value of this drawing mode baseline offset tag. * * @type {number} */ get: function () { return this._value; }, enumerable: true, configurable: true }); return DrawingBaselineOffset; }(); exports.DrawingBaselineOffset = DrawingBaselineOffset; /** * A pseudo-part representing text interpreted as drawing instructions * * @param {!Array.} instructions * * @constructor * @memberOf libjass.parts */ var DrawingInstructions = function () { function DrawingInstructions(instructions) { this._instructions = instructions; } Object.defineProperty(DrawingInstructions.prototype, "instructions", { /** * The instructions contained in this drawing instructions part. * * @type {!Array.} */ get: function () { return this._instructions; }, enumerable: true, configurable: true }); return DrawingInstructions; }(); exports.DrawingInstructions = DrawingInstructions; var addToString = function (ctor, ctorName) { if (!ctor.prototype.hasOwnProperty("toString")) { var propertyNames = Object.getOwnPropertyNames(ctor.prototype).filter(function (property) { return property !== "constructor"; }); ctor.prototype.toString = function () { var _this = this; return ctorName + " { " + propertyNames.map(function (name) { return name + ": " + _this[name]; }).join(", ") + (propertyNames.length > 0 ? " " : "") + "}"; }; } }; var misc_1 = require(38); for (var _i = 0, _a = Object.keys(exports); _i < _a.length; _i++) { var key = _a[_i]; var value = exports[key]; if (value instanceof Function) { addToString(value, key); misc_1.registerClassPrototype(value.prototype); } } for (var _b = 0, _c = Object.keys(drawing); _b < _c.length; _b++) { var key = _c[_b]; var value = drawing[key]; if (value instanceof Function) { addToString(value, "Drawing" + key); misc_1.registerClassPrototype(value.prototype); } } }, /* 9 ./renderers/clocks/auto */ function (exports, require) { var settings_1 = require(23); var manual_1 = require(11); /** * An implementation of {@link libjass.renderers.Clock} that automatically ticks and generates {@link libjass.renderers.ClockEvent}s according to the state of an external driver. * * For example, if you're using libjass to render subtitles on a canvas with your own video controls, these video controls will function as the driver to this AutoClock. * It would call {@link libjass.renderers.AutoClock.play}, {@link libjass.renderers.AutoClock.pause}, etc. when the user pressed the corresponding video controls. * * The difference from ManualClock is that AutoClock does not require the driver to call something like {@link libjass.renderers.ManualClock.tick}. Instead it keeps its * own time with a high-resolution requestAnimationFrame-based timer. * * If using libjass with a