Auto-generate @constructor, @extends, @memberOf, @private and @static from TypeScript AST.

This commit is contained in:
Arnavion
2014-04-06 21:23:24 -07:00
parent 379265414a
commit 99dfafeafd
8 changed files with 102 additions and 285 deletions
+35 -1
View File
@@ -41,7 +41,41 @@ gulp.task("libjass.js", function (callback) {
return callback(null);
}
return gulp.src("./libjass.ts").pipe(TypeScript.gulp("/libjass.js", "/libjass.js.map")).pipe(UglifyJS.fixup()).pipe(gulp.dest("."));
return gulp.src("./libjass.ts").pipe(TypeScript.gulp("/libjass.js", "/libjass.js.map", function (namespaces) {
var visitor = function (current) {
var newText = [];
if (current instanceof TypeScript.AST.Namespace) {
current.members.forEach(visitor);
}
else if (current instanceof TypeScript.AST.Constructor) {
newText.push("@constructor");
if (current.baseType !== null) {
newText.push("@extends {" + current.baseType.fullName + "}");
}
if (current.parent !== null) {
newText.push("@memberOf " + current.parent.fullName);
}
current.members.forEach(visitor);
}
if (current.isPrivate) {
newText.push("@private");
}
if (current.isStatic) {
newText.push("@static");
}
if (newText.length > 0) {
current.astNode["gulp-typescript-new-comment"] = newText;
}
};
Object.keys(namespaces).forEach(function (namespaceName) { visitor(namespaces[namespaceName]); });
})).pipe(UglifyJS.fixup()).pipe(gulp.dest("."));
});
gulp.task("libjass.min.js", ["libjass.js"], function (callback) {
+66 -34
View File
@@ -170,7 +170,7 @@ var Compiler = function () {
exports.Compiler = Compiler;
exports.gulp = function (outputCodePath, outputSourceMapPath) {
exports.gulp = function (outputCodePath, outputSourceMapPath, astModifier) {
var files = [];
return Transform(function (file, encoding) {
@@ -183,7 +183,11 @@ exports.gulp = function (outputCodePath, outputSourceMapPath) {
var compiler = new Compiler();
compiler.addFiles(files);
var resolvedFiles = compiler.addFiles(files);
if (astModifier !== undefined) {
astModifier(exports.AST.walk(compiler, resolvedFiles));
}
var outputFiles = compiler.compile(outputCodePath, outputSourceMapPath);
@@ -250,10 +254,10 @@ var Namespace = function (_super) {
var Function = function (_super) {
__extends(Function, _super);
function Function(name, docNode, description, generics, parameters, returnType, isAbstract, isPrivate, isStatic) {
function Function(name, astNode, description, generics, parameters, returnType, isAbstract, isPrivate, isStatic) {
_super.call(this, name);
this.docNode = docNode;
this.astNode = astNode;
this.description = description;
@@ -274,10 +278,10 @@ var Function = function (_super) {
var Constructor = function (_super) {
__extends(Constructor, _super);
function Constructor(name, docNode, description, generics, parameters, baseType, isAbstract, isPrivate) {
function Constructor(name, astNode, description, generics, parameters, baseType, isAbstract, isPrivate) {
_super.call(this, name);
this.docNode = docNode;
this.astNode = astNode;
this.description = description;
@@ -311,8 +315,8 @@ var Property = function (_super) {
}(Scoped);
var Getter = function () {
function Getter(docNode, description, type) {
this.docNode = docNode;
function Getter(astNode, description, type) {
this.astNode = astNode;
this.description = description;
@@ -323,8 +327,8 @@ var Getter = function () {
}();
var Setter = function () {
function Setter(docNode, description, parameters) {
this.docNode = docNode;
function Setter(astNode, description, parameters) {
this.astNode = astNode;
this.description = description;
@@ -337,10 +341,10 @@ var Setter = function () {
var Variable = function (_super) {
__extends(Variable, _super);
function Variable(name, docNode, description, type) {
function Variable(name, astNode, description, type) {
_super.call(this, name);
this.docNode = docNode;
this.astNode = astNode;
this.description = description;
@@ -466,7 +470,7 @@ var Walker = function (_super) {
var modifiers = ((node.modifiers.item ? [node.modifiers.item] : node.modifiers.nodeOrTokens) || []).map(function (modifier) { return modifier.tokenKind; });
var isPrivate = !modifiers.some(function (modifier) { return modifier === TypeScript.SyntaxKind["ExportKeyword"]; });
var clazz = this._scope.enter(new Constructor(name, docNode, doc.rootDescription, doc.generics, doc.parameters, baseType, doc.isAbstract, isPrivate));
var clazz = this._scope.enter(new Constructor(name, node, doc.rootDescription, doc.generics, doc.parameters, baseType, doc.isAbstract, isPrivate));
clazz.parent.members.push(clazz);
@@ -488,7 +492,7 @@ var Walker = function (_super) {
var isPrivate = modifiers.some(function (modifier) { return modifier === TypeScript.SyntaxKind["PrivateKeyword"]; });
var isStatic = modifiers.some(function (modifier) { return modifier === TypeScript.SyntaxKind["StaticKeyword"]; });
var memberFunction = this._scope.enter(new Function(name, docNode, doc.rootDescription, doc.generics, doc.parameters, doc.returnType, doc.isAbstract, isPrivate, isStatic));
var memberFunction = this._scope.enter(new Function(name, node, doc.rootDescription, doc.generics, doc.parameters, doc.returnType, doc.isAbstract, isPrivate, isStatic));
memberFunction.parent.members.push(memberFunction);
@@ -508,7 +512,7 @@ var Walker = function (_super) {
var isPrivate = modifiers.some(function (modifier) { return modifier === TypeScript.SyntaxKind["PrivateKeyword"]; });
var isStatic = modifiers.some(function (modifier) { return modifier === TypeScript.SyntaxKind["StaticKeyword"]; });
var freeFunction = this._scope.enter(new Function(name, docNode, doc.rootDescription, doc.generics, doc.parameters, doc.returnType, doc.isAbstract, isPrivate, isStatic));
var freeFunction = this._scope.enter(new Function(name, node, doc.rootDescription, doc.generics, doc.parameters, doc.returnType, doc.isAbstract, isPrivate, isStatic));
freeFunction.parent.members.push(freeFunction);
@@ -535,7 +539,7 @@ var Walker = function (_super) {
this._scope.leave();
}
property.getter = new Getter(docNode, doc.rootDescription, doc.returnType);
property.getter = new Getter(node, doc.rootDescription, doc.returnType);
};
Walker.prototype.visitSetAccessor = function (node) {
@@ -558,7 +562,7 @@ var Walker = function (_super) {
this._scope.leave();
}
property.setter = new Setter(docNode, doc.rootDescription, doc.parameters);
property.setter = new Setter(node, doc.rootDescription, doc.parameters);
};
Walker.prototype.visitMemberVariableDeclaration = function (node) {
@@ -570,7 +574,7 @@ var Walker = function (_super) {
return;
}
var variable = this._scope.enter(new Variable(name, docNode, doc.rootDescription, doc.returnType));
var variable = this._scope.enter(new Variable(name, node, doc.rootDescription, doc.returnType));
variable.parent.members.push(variable);
@@ -586,7 +590,7 @@ var Walker = function (_super) {
return;
}
var variable = this._scope.enter(new Variable(name, docNode, doc.rootDescription, doc.returnType));
var variable = this._scope.enter(new Variable(name, node.variableDeclaration.variableDeclarators.item, doc.rootDescription, doc.returnType));
variable.parent.members.push(variable);
@@ -680,15 +684,6 @@ var Walker = function (_super) {
isAbstract = true;
break;
case "@constructor":
break;
case "@extends":
break;
case "@memberof":
break;
case "@param":
var result = readType(remainingLine);
var type = result[0];
@@ -711,9 +706,6 @@ var Walker = function (_super) {
}
break;
case "@private":
break;
case "@return":
var result = readType(remainingLine);
var type = result[0];
@@ -723,9 +715,6 @@ var Walker = function (_super) {
break;
case "@static":
break;
case "@template":
generics.push.apply(generics, remainingLine.split(/,/).map(function (word) { return word.trim(); }));
break;
@@ -838,3 +827,46 @@ exports.AST = {
walk: walk
};
Object.keys(TypeScript.SyntaxTreeToAstVisitor.prototype).forEach(function (key) {
if (key.substr(0, "visit".length) !== "visit") {
return;
}
var originalFunction = TypeScript.SyntaxTreeToAstVisitor.prototype[key];
if (originalFunction.length !== 1) {
return;
}
TypeScript.SyntaxTreeToAstVisitor.prototype[key] = function (node) {
var result = originalFunction.call(this, node);
if (node && node["gulp-typescript-new-comment"]) {
result["gulp-typescript-new-comment"] = node["gulp-typescript-new-comment"];
}
return result;
};
});
var originalEmitComments = TypeScript.Emitter.prototype.emitComments;
TypeScript.Emitter.prototype.emitComments = function (ast, pre, onlyPinnedOrTripleSlashComments) {
if (ast["gulp-typescript-new-comment"]) {
var trivia = ast.preComments()[0]._trivia;
var originalFullText = trivia.fullText();
var commentEndIndex = originalFullText.lastIndexOf("*/");
var fullText = originalFullText.substr(0, commentEndIndex);
fullText += "*\n";
ast["gulp-typescript-new-comment"].forEach(function (line) {
fullText += "* " + line + "\n";
});
trivia._fullText = fullText + originalFullText.substr(commentEndIndex);
trivia._fullWidth = trivia._fullText.length;
}
return originalEmitComments.apply(this, arguments);
};
+1 -1
View File
@@ -216,7 +216,7 @@ module.exports = {
var originalWarn = UglifyJS.AST_Node.warn;
UglifyJS.AST_Node.warn = function (text, properties) {
if (
(text === "{type} {name} is declared but not referenced [{file}:{line},{col}]" && properties.type === "Symbol" && properties.name === "substring" && properties.file === "libjass.js" && properties.line === 5917)
(text === "{type} {name} is declared but not referenced [{file}:{line},{col}]" && properties.type === "Symbol" && properties.name === "substring")
) {
return;
}
-19
View File
@@ -27,8 +27,6 @@ module libjass.parser {
* @param {string} input
* @param {string} rule
* @return {*}
*
* @memberof libjass.parser
*/
export function parse(input: string, rule: string): any {
var run = new ParserRun(input, rule);
@@ -47,13 +45,8 @@ module libjass.parser {
/**
* This class represents a single run of the parser.
*
* @constructor
*
* @param {string} input
* @param {string} rule
*
* @private
* @memberof libjass.parser
*/
class ParserRun {
private _parseTree: ParseNode = new ParseNode(null);
@@ -2166,8 +2159,6 @@ module libjass.parser {
/**
* @param {number=1} count
*
* @private
*/
private _peek(count: number = 1): string {
return this._input.substr(this._parseTree.end, count);
@@ -2175,8 +2166,6 @@ module libjass.parser {
/**
* @return {boolean}
*
* @private
*/
private _haveMore(): boolean {
return this._parseTree.end < this._input.length;
@@ -2186,8 +2175,6 @@ module libjass.parser {
* @param {string} tagName One of "clip" and "iclip"
* @param {!ParseNode} parent
* @return {ParseNode}
*
* @private
*/
private _parse_tag_clip_or_iclip(tagName: string, parent: ParseNode): ParseNode {
var current = new ParseNode(parent);
@@ -2342,12 +2329,8 @@ module libjass.parser {
/**
* This class represents a single parse node. It has a start and end position, and an optional value object.
*
* @constructor
* @param {ParseNode} parent The parent of this parse node. The parent's end position will be updated to the end position of this node whenever the latter changes.
* @param {?string=null} value A shortcut to assign a string to the value property.
*
* @private
* @memberof libjass.parser
*/
class ParseNode {
private _children: ParseNode[] = [];
@@ -2445,8 +2428,6 @@ module libjass.parser {
* Updates the end property of this node and its parent recursively to the root node.
*
* @param {number} newEnd
*
* @private
*/
private _setEnd(newEnd: number): void {
this._end = newEnd;
-166
View File
@@ -26,13 +26,10 @@ module libjass.parts {
*
* Instances of this class are immutable.
*
* @constructor
* @param {number} red
* @param {number} green
* @param {number} blue
* @param {number=1} alpha
*
* @memberof libjass.parts
*/
export class Color {
constructor(private _red: number, private _green: number, private _blue: number, private _alpha: number = 1) { }
@@ -101,10 +98,7 @@ module libjass.parts {
/**
* A comment, i.e., any text enclosed in {} that is not understood as an ASS tag.
*
* @constructor
* @param {string} value The text of this comment
*
* @memberof libjass.parts
*/
export class Comment {
constructor(private _value: string) { }
@@ -122,10 +116,7 @@ module libjass.parts {
/**
* A block of text, i.e., any text not enclosed in {}. Also includes \h.
*
* @constructor
* @param {string} value The content of this block of text
*
* @memberof libjass.parts
*/
export class Text {
constructor(private _value: string) { }
@@ -146,10 +137,6 @@ module libjass.parts {
/**
* A newline character \N.
*
* @constructor
*
* @memberof libjass.parts
*/
export class NewLine {
}
@@ -157,10 +144,7 @@ module libjass.parts {
/**
* An italic tag {\i}
*
* @constructor
* @param {?boolean} value {\i1} -> true, {\i0} -> false, {\i} -> null
*
* @memberof libjass.parts
*/
export class Italic {
constructor(private _value: boolean) { }
@@ -178,10 +162,7 @@ module libjass.parts {
/**
* A bold tag {\b}
*
* @constructor
* @param {*} value {\b1} -> true, {\b0} -> false, {\b###} -> weight of the bold (number), {\b} -> null
*
* @memberof libjass.parts
*/
export class Bold {
constructor(private _value: Object) { }
@@ -199,10 +180,7 @@ module libjass.parts {
/**
* An underline tag {\u}
*
* @constructor
* @param {?boolean} value {\u1} -> true, {\u0} -> false, {\u} -> null
*
* @memberof libjass.parts
*/
export class Underline {
constructor(private _value: boolean) { }
@@ -220,10 +198,7 @@ module libjass.parts {
/**
* A strike-through tag {\s}
*
* @constructor
* @param {?boolean} value {\s1} -> true, {\s0} -> false, {\s} -> null
*
* @memberof libjass.parts
*/
export class StrikeThrough {
constructor(private _value: boolean) { }
@@ -241,10 +216,7 @@ module libjass.parts {
/**
* A border tag {\bord}
*
* @constructor
* @param {?number} value {\bord###} -> width (number), {\bord} -> null
*
* @memberof libjass.parts
*/
export class Border {
constructor(private _value: number) { }
@@ -262,10 +234,7 @@ module libjass.parts {
/**
* A horizontal border tag {\xbord}
*
* @constructor
* @param {?number} value {\xbord###} -> width (number), {\xbord} -> null
*
* @memberof libjass.parts
*/
export class BorderX {
constructor(private _value: number) { }
@@ -283,10 +252,7 @@ module libjass.parts {
/**
* A vertical border tag {\ybord}
*
* @constructor
* @param {?number} value {\ybord###} -> height (number), {\ybord} -> null
*
* @memberof libjass.parts
*/
export class BorderY {
constructor(private _value: number) { }
@@ -304,10 +270,7 @@ module libjass.parts {
/**
* A shadow tag {\shad}
*
* @constructor
* @param {?number} value {\shad###} -> depth (number), {\shad} -> null
*
* @memberof libjass.parts
*/
export class Shadow {
constructor(private _value: number) { }
@@ -325,10 +288,7 @@ module libjass.parts {
/**
* A horizontal shadow tag {\xshad}
*
* @constructor
* @param {?number} value {\xshad###} -> depth (number), {\xshad} -> null
*
* @memberof libjass.parts
*/
export class ShadowX {
constructor(private _value: number) { }
@@ -346,10 +306,7 @@ module libjass.parts {
/**
* A vertical shadow tag {\yshad}
*
* @constructor
* @param {?number} value {\yshad###} -> depth (number), {\yshad} -> null
*
* @memberof libjass.parts
*/
export class ShadowY {
constructor(private _value: number) { }
@@ -367,10 +324,7 @@ module libjass.parts {
/**
* A blur tag {\be}
*
* @constructor
* @param {?number} value {\be###} -> strength (number), {\be} -> null
*
* @memberof libjass.parts
*/
export class Blur {
constructor(private _value: number) { }
@@ -388,10 +342,7 @@ module libjass.parts {
/**
* A Gaussian blur tag {\blur}
*
* @constructor
* @param {?number} value {\blur###} -> strength (number), {\blur} -> null
*
* @memberof libjass.parts
*/
export class GaussianBlur {
constructor(private _value: number) { }
@@ -409,10 +360,7 @@ module libjass.parts {
/**
* A font name tag {\fn}
*
* @constructor
* @param {?string} value {\fn###} -> name (string), {\fn} -> null
*
* @memberof libjass.parts
*/
export class FontName {
constructor(private _value: string) { }
@@ -430,10 +378,7 @@ module libjass.parts {
/**
* A font size tag {\fs}
*
* @constructor
* @param {?number} value {\fs###} -> size (number), {\fs} -> null
*
* @memberof libjass.parts
*/
export class FontSize {
constructor(private _value: number) { }
@@ -451,10 +396,7 @@ module libjass.parts {
/**
* A horizontal font scaling tag {\fscx}
*
* @constructor
* @param {?number} value {\fscx###} -> scale (number), {\fscx} -> null
*
* @memberof libjass.parts
*/
export class FontScaleX {
constructor(private _value: number) { }
@@ -472,10 +414,7 @@ module libjass.parts {
/**
* A vertical font scaling tag {\fscy}
*
* @constructor
* @param {?number} value {\fscy###} -> scale (number), {\fscy} -> null
*
* @memberof libjass.parts
*/
export class FontScaleY {
constructor(private _value: number) { }
@@ -493,10 +432,7 @@ module libjass.parts {
/**
* A letter-spacing tag {\fsp}
*
* @constructor
* @param {?number} value {\fsp###} -> spacing (number), {\fsp} -> null
*
* @memberof libjass.parts
*/
export class LetterSpacing {
constructor(private _value: number) { }
@@ -514,10 +450,7 @@ module libjass.parts {
/**
* An X-axis rotation tag {\frx}
*
* @constructor
* @param {?number} value {\frx###} -> angle (number), {\frx} -> null
*
* @memberof libjass.parts
*/
export class RotateX {
constructor(private _value: number) { }
@@ -535,10 +468,7 @@ module libjass.parts {
/**
* A Y-axis rotation tag {\fry}
*
* @constructor
* @param {?number} value {\fry###} -> angle (number), {\fry} -> null
*
* @memberof libjass.parts
*/
export class RotateY {
constructor(private _value: number) { }
@@ -556,10 +486,7 @@ module libjass.parts {
/**
* A Z-axis rotation tag {\fr} or {\frz}
*
* @constructor
* @param {?number} value {\frz###} -> angle (number), {\frz} -> null
*
* @memberof libjass.parts
*/
export class RotateZ {
constructor(private _value: number) { }
@@ -577,10 +504,7 @@ module libjass.parts {
/**
* An X-axis shearing tag {\fax}
*
* @constructor
* @param {?number} value {\fax###} -> angle (number), {\fax} -> null
*
* @memberof libjass.parts
*/
export class SkewX {
constructor(private _value: number) { }
@@ -598,10 +522,7 @@ module libjass.parts {
/**
* A Y-axis shearing tag {\fay}
*
* @constructor
* @param {?number} value {\fay###} -> angle (number), {\fay} -> null
*
* @memberof libjass.parts
*/
export class SkewY {
constructor(private _value: number) { }
@@ -619,10 +540,7 @@ module libjass.parts {
/**
* A primary color tag {\c} or {\1c}
*
* @constructor
* @param {libjass.parts.Color} value {\1c###} -> color (Color), {\1c} -> null
*
* @memberof libjass.parts
*/
export class PrimaryColor {
constructor(private _value: Color) { }
@@ -640,10 +558,7 @@ module libjass.parts {
/**
* A secondary color tag {\2c}
*
* @constructor
* @param {libjass.parts.Color} value {\2c###} -> color (Color), {\2c} -> null
*
* @memberof libjass.parts
*/
export class SecondaryColor {
constructor(private _value: Color) { }
@@ -661,10 +576,7 @@ module libjass.parts {
/**
* An outline color tag {\3c}
*
* @constructor
* @param {libjass.parts.Color} value {\3c###} -> color (Color), {\3c} -> null
*
* @memberof libjass.parts
*/
export class OutlineColor {
constructor(private _value: Color) { }
@@ -682,10 +594,7 @@ module libjass.parts {
/**
* A shadow color tag {\4c}
*
* @constructor
* @param {libjass.parts.Color} value {\4c###} -> color (Color), {\4c} -> null
*
* @memberof libjass.parts
*/
export class ShadowColor {
constructor(private _value: Color) { }
@@ -703,10 +612,7 @@ module libjass.parts {
/**
* An alpha tag {\alpha}
*
* @constructor
* @param {?number} value {\alpha###} -> alpha (number), {\alpha} -> null
*
* @memberof libjass.parts
*/
export class Alpha {
constructor(private _value: number) { }
@@ -724,10 +630,7 @@ module libjass.parts {
/**
* A primary alpha tag {\1a}
*
* @constructor
* @param {?number} value {\1a###} -> alpha (number), {\1a} -> null
*
* @memberof libjass.parts
*/
export class PrimaryAlpha {
constructor(private _value: number) { }
@@ -745,10 +648,7 @@ module libjass.parts {
/**
* A secondary alpha tag {\2a}
*
* @constructor
* @param {?number} value {\2a###} -> alpha (number), {\2a} -> null
*
* @memberof libjass.parts
*/
export class SecondaryAlpha {
constructor(private _value: number) { }
@@ -766,10 +666,7 @@ module libjass.parts {
/**
* An outline alpha tag {\3a}
*
* @constructor
* @param {?number} value {\3a###} -> alpha (number), {\3a} -> null
*
* @memberof libjass.parts
*/
export class OutlineAlpha {
constructor(private _value: number) { }
@@ -787,10 +684,7 @@ module libjass.parts {
/**
* A shadow alpha tag {\4a}
*
* @constructor
* @param {?number} value {\4a###} -> alpha (number), {\4a} -> null
*
* @memberof libjass.parts
*/
export class ShadowAlpha {
constructor(private _value: number) { }
@@ -808,10 +702,7 @@ module libjass.parts {
/**
* An alignment tag {\an} or {\a}
*
* @constructor
* @param {number} value {\an###} -> alignment (number)
*
* @memberof libjass.parts
*/
export class Alignment {
constructor(private _value: number) { }
@@ -829,10 +720,7 @@ module libjass.parts {
/**
* A color karaoke tag {\k}
*
* @constructor
* @param {number} duration {\k###} -> duration (number)
*
* @memberof libjass.parts
*/
export class ColorKaraoke {
constructor(private _duration: number) { }
@@ -850,10 +738,7 @@ module libjass.parts {
/**
* A sweeping color karaoke tag {\K} or {\kf}
*
* @constructor
* @param {number} duration {\kf###} -> duration (number)
*
* @memberof libjass.parts
*/
export class SweepingColorKaraoke {
constructor(private _duration: number) { }
@@ -871,10 +756,7 @@ module libjass.parts {
/**
* An outline karaoke tag {\ko}
*
* @constructor
* @param {number} duration {\ko###} -> duration (number)
*
* @memberof libjass.parts
*/
export class OutlineKaraoke {
constructor(private _duration: number) { }
@@ -892,10 +774,7 @@ module libjass.parts {
/**
* A wrapping style tag {\q}
*
* @constructor
* @param {number} value {\q###} -> style (number)
*
* @memberof libjass.parts
*/
export class WrappingStyle {
constructor(private _value: libjass.WrappingStyle) { }
@@ -913,10 +792,7 @@ module libjass.parts {
/**
* A style reset tag {\r}
*
* @constructor
* @param {?string} value {\r###} -> style name (string), {\r} -> null
*
* @memberof libjass.parts
*/
export class Reset {
constructor(private _value: string) { }
@@ -934,11 +810,8 @@ module libjass.parts {
/**
* A position tag {\pos}
*
* @constructor
* @param {number} x
* @param {number} y
*
* @memberof libjass.parts
*/
export class Position {
constructor(private _x: number, private _y: number) { }
@@ -965,15 +838,12 @@ module libjass.parts {
/**
* A movement tag {\move}
*
* @constructor
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} t1
* @param {number} t2
*
* @memberof libjass.parts
*/
export class Move {
constructor(private _x1: number, private _y1: number, private _x2: number, private _y2: number, private _t1: number, private _t2: number) { }
@@ -1036,11 +906,8 @@ module libjass.parts {
/**
* A rotation origin tag {\org}
*
* @constructor
* @param {number} x
* @param {number} y
*
* @memberof libjass.parts
*/
export class RotationOrigin {
constructor(private _x: number, private _y: number) { }
@@ -1067,11 +934,8 @@ module libjass.parts {
/**
* A simple fade tag {\fad}
*
* @constructor
* @param {number} start
* @param {number} end
*
* @memberof libjass.parts
*/
export class Fade {
constructor(private _start: number, private _end: number) { }
@@ -1098,7 +962,6 @@ module libjass.parts {
/**
* A complex fade tag {\fade}
*
* @constructor
* @param {number} a1
* @param {number} a2
* @param {number} a3
@@ -1106,8 +969,6 @@ module libjass.parts {
* @param {number} t2
* @param {number} t3
* @param {number} t4
*
* @memberof libjass.parts
*/
export class ComplexFade {
constructor(
@@ -1182,13 +1043,10 @@ module libjass.parts {
/**
* A transform tag {\t}
*
* @constructor
* @param {number} start
* @param {number} end
* @param {number} accel
* @param {!Array.<!libjass.parts.Tag>} tags
*
* @memberof libjass.parts
*/
export class Transform {
constructor(private _start: number, private _end: number, private _accel: number, private _tags: Part[]) { }
@@ -1233,14 +1091,11 @@ module libjass.parts {
/**
* A rectangular clip tag {\clip} or {\iclip}
*
* @constructor
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {boolean} inside
*
* @memberof libjass.parts
*/
export class RectangularClip {
constructor(private _x1: number, private _y1: number, private _x2: number, private _y2: number, private _inside: boolean) { }
@@ -1294,12 +1149,9 @@ module libjass.parts {
/**
* A vector clip tag {\clip} or {\iclip}
*
* @constructor
* @param {number} scale
* @param {!Array.<!libjass.parts.drawing.Instruction>} instructions
* @param {boolean} inside
*
* @memberof libjass.parts
*/
export class VectorClip {
constructor(private _scale: number, private _instructions: drawing.Instruction[], private _inside: boolean) { }
@@ -1335,10 +1187,7 @@ module libjass.parts {
/**
* A drawing mode tag {\p}
*
* @constructor
* @param {number} scale
*
* @memberof libjass.parts
*/
export class DrawingMode {
constructor(private _scale: number) { }
@@ -1356,10 +1205,7 @@ module libjass.parts {
/**
* A drawing mode baseline offset tag {\pbo}
*
* @constructor
* @param {number} value
*
* @memberof libjass.parts
*/
export class DrawingBaselineOffset {
constructor(private _value: number) { }
@@ -1377,10 +1223,7 @@ module libjass.parts {
/**
* A pseudo-part representing text interpreted as drawing instructions
*
* @constructor
* @param {!Array.<!libjass.parts.drawing.Instruction>} instructions
*
* @memberof libjass.parts
*/
export class DrawingInstructions {
constructor(private _instructions: drawing.Instruction[]) { }
@@ -1404,11 +1247,8 @@ module libjass.parts {
/**
* An instruction to move to a particular position.
*
* @constructor
* @param {number} x
* @param {number} y
*
* @memberof libjass.parts.drawing
*/
export class MoveInstruction implements Instruction {
constructor(private _x: number, private _y: number) { }
@@ -1435,11 +1275,8 @@ module libjass.parts {
/**
* An instruction to draw a line to a particular position.
*
* @constructor
* @param {number} x
* @param {number} y
*
* @memberof libjass.parts.drawing
*/
export class LineInstruction implements Instruction {
constructor(private _x: number, private _y: number) { }
@@ -1466,15 +1303,12 @@ module libjass.parts {
/**
* An instruction to draw a cubic bezier curve to a particular position, with two given control points.
*
* @constructor
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} x3
* @param {number} y3
*
* @memberof libjass.parts.drawing
*/
export class CubicBezierCurveInstruction implements Instruction {
constructor(private _x1: number, private _y1: number, private _x2: number, private _y2: number, private _x3: number, private _y3: number) { }
-35
View File
@@ -38,13 +38,9 @@ module libjass.renderers {
/**
* A renderer implementation that doesn't output anything.
*
* @constructor
*
* @param {!HTMLVideoElement} video
* @param {!libjass.ASS} ass
* @param {!libjass.renderers.RendererSettings} settings
*
* @memberof libjass.renderers
*/
export class NullRenderer {
private static _lastRendererId = -1;
@@ -321,14 +317,9 @@ module libjass.renderers {
/**
* A default renderer implementation.
*
* @constructor
* @extends {libjass.renderers.NullRenderer}
*
* @param {!HTMLVideoElement} video
* @param {!libjass.ASS} ass
* @param {!libjass.renderers.RendererSettings} settings
*
* @memberof libjass.renderers
*/
export class DefaultRenderer extends NullRenderer {
private _videoSubsWrapper: HTMLDivElement;
@@ -1002,8 +993,6 @@ module libjass.renderers {
/**
* @param {string} type
* @param {!Array.<*>} args
*
* @private
*/
private _dispatchEvent(type: string, args: Object[]): void {
var listeners = this._eventListeners.get(type);
@@ -1045,10 +1034,6 @@ module libjass.renderers {
/**
* Settings for the default renderer.
*
* @constructor
*
* @memberof libjass.renderers
*/
export class RendererSettings {
/**
@@ -1072,8 +1057,6 @@ module libjass.renderers {
*
* @param {!LinkStyle} linkStyle
* @return {!Map.<string, !Array.<string>>}
*
* @static
*/
static makeFontMapFromStyleElement(linkStyle: LinkStyle): Map<string, string[]> {
var map = new Map<string, string[]>();
@@ -1112,8 +1095,6 @@ module libjass.renderers {
*
* @param {!*} object
* @return {!libjass.renderers.RendererSettings}
*
* @static
*/
static from(object: any): RendererSettings {
return RendererSettings._from(object.fontMap, object.preRenderTime);
@@ -1138,12 +1119,8 @@ module libjass.renderers {
/**
* This class represents a single keyframe. It has a list of CSS properties (names and values) associated with a point in time. Multiple keyframes make up an animation.
*
* @constructor
* @param {number} time
* @param {!Object.<string, string>} properties
*
* @private
* @memberof libjass.renderers
*/
class Keyframe {
constructor(private _time: number, private _properties: KeyframePropertiesMap) { }
@@ -1167,12 +1144,8 @@ module libjass.renderers {
* This class represents a collection of animations. Each animation contains one or more keyframes.
* The collection can then be converted to a CSS3 representation.
*
* @constructor
* @param {!libjass.renderers.NullRenderer} renderer The renderer that this collection is associated with
* @param {!libjass.Dialogue} dialogue The Dialogue that this collection is associated with
*
* @private
* @memberof libjass.renderers
*/
class AnimationCollection {
private _id: string;
@@ -1253,16 +1226,12 @@ module libjass.renderers {
* This class represents the style attribute of a span.
* As a Dialogue's div is rendered, individual parts are added to span's, and this class is used to maintain the style attribute of those.
*
* @constructor
* @param {!libjass.renderers.NullRenderer} renderer The renderer that this set of styles is associated with
* @param {!libjass.Dialogue} dialogue The Dialogue that this set of styles is associated with
* @param {number} scaleX The horizontal scaling of the subtitles
* @param {number} scaleY The vertical scaling of the subtitles
* @param {!HTMLDivElement} fontSizeElement A <div> element to measure font sizes with
* @param {!SVGDefsElement} svgDefsElement An SVG <defs> element to append filter definitions to
*
* @private
* @memberof libjass.renderers
*/
class SpanStyles {
private static _fontSizeCache: Map<string, Map<number, number>> = new Map<string, Map<number, number>>();
@@ -1811,13 +1780,9 @@ module libjass.renderers {
/**
* This class represents an ASS drawing - a set of drawing instructions between {\p} tags.
*
* @constructor
* @param {number} drawingScale
* @param {number} scaleX
* @param {number} scaleY
*
* @private
* @memberof libjass.renderers
*/
class Drawing {
private _scaleX: number;
-21
View File
@@ -27,10 +27,6 @@ module libjass {
/**
* This class represents an ASS script. It contains the script properties, an array of Styles, and an array of Dialogues.
*
* @constructor
*
* @memberof libjass
*/
export class ASS {
private _properties: ScriptProperties = new ScriptProperties();
@@ -77,8 +73,6 @@ module libjass {
* @param {string} rawASS The raw text of the script.
* @param {number=0} type The type of the script. One of the libjass.Format constants.
* @return {!libjass.ASS}
*
* @static
*/
static fromString(raw: string, type: Format = Format.ASS): ASS {
raw = raw.replace(/\r$/gm, "");
@@ -204,10 +198,6 @@ module libjass {
/**
* This class represents the properties of an ASS script.
*
* @constructor
*
* @memberof libjass
*/
export class ScriptProperties {
private _resolutionX: number;
@@ -296,7 +286,6 @@ module libjass {
/**
* This class represents a single global style declaration in an ASS script. The styles can be obtained via the ASS.styles property.
*
* @constructor
* @param {!Object} template The template object that contains the style's properties. It is a map of the string values read from the ASS file.
* @param {string} template["Name"] The name of the style
* @param {string} template["Italic"] -1 if the style is italicized
@@ -317,8 +306,6 @@ module libjass {
* @param {string} template["MarginL"] The left margin
* @param {string} template["MarginR"] The right margin
* @param {string} template["MarginV"] The vertical margin
*
* @memberof libjass
*/
export class Style {
private _name: string;
@@ -591,7 +578,6 @@ module libjass {
/**
* This class represents a dialogue in an ASS script.
*
* @constructor
* @param {!Object} template The template object that contains the dialogue's properties. It is a map of the string values read from the ASS file.
* @param {string} template["Style"] The name of the default style of this dialogue
* @param {string} template["Start"] The start time
@@ -599,8 +585,6 @@ module libjass {
* @param {string} template["Layer"] The layer number
* @param {string} template["Text"] The text of this dialogue
* @param {ASS} ass The ASS object to which this dialogue belongs
*
* @memberof libjass
*/
export class Dialogue {
private static _lastDialogueId = -1;
@@ -708,8 +692,6 @@ module libjass {
/**
* Parses this dialogue's parts from the raw parts string.
*
* @private
*/
private _parsePartsString(): void {
this._parts = <parts.Part[]>parser.parse(this._rawPartsString, "dialogueParts");
@@ -766,9 +748,6 @@ module libjass {
*
* @param {string} str
* @return {number}
*
* @private
* @static
*/
private static _toTime(str: string): number {
return str.split(":").reduce<number>((previousValue, currentValue) => previousValue * 60 + parseFloat(currentValue), 0);
-8
View File
@@ -28,11 +28,7 @@ module libjass {
*
* Elements are stored as properties of an object, with names derived from their type.
*
* @constructor
* @template T
*
* @private
* @memberof libjass
*/
class SimpleSet<T> implements Set<T> {
private _elements: { [key: string]: T };
@@ -130,11 +126,7 @@ module libjass {
*
* Keys and values are stored as properties of an object, with property names derived from the key type.
*
* @constructor
* @template K, V
*
* @private
* @memberof libjass
*/
class SimpleMap<K, V> implements Map<K, V> {
private _keys: { [key: string]: K };