Skip to content

Commit

Permalink
0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Dec 1, 2018
1 parent 6257e07 commit 68942a7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 50 deletions.
61 changes: 37 additions & 24 deletions dist/ass.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,30 @@ var DEFAULT_STYLE = {
Encoding: '1',
};

/**
* @param {String} color
* @returns {Array} [AA, BBGGRR]
*/
function parseStyleColor(color) {
var ref = color.match(/&H(\w\w)?(\w{6})&?/);
var a = ref[1];
var c = ref[2];
return [a || '00', c];
if (/^(&|H|&H)[0-9a-f]{6,}/i.test(color)) {
var ref = color.match(/&?H?([0-9a-f]{2})?([0-9a-f]{6})/i);
var a = ref[1];
var c = ref[2];
return [a || '00', c];
}
var num = parseInt(color, 10);
if (!Number.isNaN(num)) {
var min = -2147483648;
var max = 2147483647;
if (num < min) {
return ['00', '000000'];
}
var aabbggrr = (min <= num && num <= max)
? ("00000000" + ((num < 0 ? num + 4294967296 : num).toString(16))).slice(-8)
: String(num).slice(0, 8);
return [aabbggrr.slice(0, 2), aabbggrr.slice(2)];
}
return ['00', '000000'];
}

function compileStyles(ref) {
Expand Down Expand Up @@ -1717,38 +1736,36 @@ function renderer(dialogue) {
}

function framing() {
var this$1 = this;

var vct = this.video.currentTime;
for (var i = this._.stagings.length - 1; i >= 0; i--) {
var dia = this$1._.stagings[i];
var dia = this._.stagings[i];
var end = dia.end;
if (dia.effect && /scroll/.test(dia.effect.name)) {
var ref = dia.effect;
var y1 = ref.y1;
var y2 = ref.y2;
var delay = ref.delay;
var duration = ((y2 || this$1._.resampledRes.height) - y1) / (1000 / delay);
var duration = ((y2 || this._.resampledRes.height) - y1) / (1000 / delay);
end = Math.min(end, dia.start + duration);
}
if (end < vct) {
this$1._.$stage.removeChild(dia.$div);
this._.$stage.removeChild(dia.$div);
if (dia.$clipPath) {
this$1._.$defs.removeChild(dia.$clipPath);
this._.$defs.removeChild(dia.$clipPath);
}
this$1._.stagings.splice(i, 1);
this._.stagings.splice(i, 1);
}
}
var dias = this.dialogues;
while (
this._.index < dias.length
&& vct >= dias[this._.index].start
) {
if (vct < dias[this$1._.index].end) {
var dia$1 = renderer.call(this$1, dias[this$1._.index]);
this$1._.stagings.push(dia$1);
if (vct < dias[this._.index].end) {
var dia$1 = renderer.call(this, dias[this._.index]);
this._.stagings.push(dia$1);
}
++this$1._.index;
++this._.index;
}
}

Expand All @@ -1772,13 +1789,11 @@ function pause() {
}

function clear() {
var this$1 = this;

while (this._.$stage.lastChild) {
this$1._.$stage.removeChild(this$1._.$stage.lastChild);
this._.$stage.removeChild(this._.$stage.lastChild);
}
while (this._.$defs.lastChild) {
this$1._.$defs.removeChild(this$1._.$defs.lastChild);
this._.$defs.removeChild(this._.$defs.lastChild);
}
this._.stagings = [];
this._.space = [];
Expand Down Expand Up @@ -1959,8 +1974,6 @@ function hide() {
}

function destroy() {
var this$1 = this;

pause.call(this);
clear.call(this);
unbindEvents.call(this, this._.listener);
Expand All @@ -1977,9 +1990,9 @@ function destroy() {
styleRoot.removeChild(this._.$animation);

// eslint-disable-next-line no-restricted-syntax
for (var key in this$1) {
if (Object.prototype.hasOwnProperty.call(this$1, key)) {
this$1[key] = null;
for (var key in this) {
if (Object.prototype.hasOwnProperty.call(this, key)) {
this[key] = null;
}
}

Expand Down
61 changes: 37 additions & 24 deletions dist/ass.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,30 @@
Encoding: '1',
};

/**
* @param {String} color
* @returns {Array} [AA, BBGGRR]
*/
function parseStyleColor(color) {
var ref = color.match(/&H(\w\w)?(\w{6})&?/);
var a = ref[1];
var c = ref[2];
return [a || '00', c];
if (/^(&|H|&H)[0-9a-f]{6,}/i.test(color)) {
var ref = color.match(/&?H?([0-9a-f]{2})?([0-9a-f]{6})/i);
var a = ref[1];
var c = ref[2];
return [a || '00', c];
}
var num = parseInt(color, 10);
if (!Number.isNaN(num)) {
var min = -2147483648;
var max = 2147483647;
if (num < min) {
return ['00', '000000'];
}
var aabbggrr = (min <= num && num <= max)
? ("00000000" + ((num < 0 ? num + 4294967296 : num).toString(16))).slice(-8)
: String(num).slice(0, 8);
return [aabbggrr.slice(0, 2), aabbggrr.slice(2)];
}
return ['00', '000000'];
}

function compileStyles(ref) {
Expand Down Expand Up @@ -1723,38 +1742,36 @@
}

function framing() {
var this$1 = this;

var vct = this.video.currentTime;
for (var i = this._.stagings.length - 1; i >= 0; i--) {
var dia = this$1._.stagings[i];
var dia = this._.stagings[i];
var end = dia.end;
if (dia.effect && /scroll/.test(dia.effect.name)) {
var ref = dia.effect;
var y1 = ref.y1;
var y2 = ref.y2;
var delay = ref.delay;
var duration = ((y2 || this$1._.resampledRes.height) - y1) / (1000 / delay);
var duration = ((y2 || this._.resampledRes.height) - y1) / (1000 / delay);
end = Math.min(end, dia.start + duration);
}
if (end < vct) {
this$1._.$stage.removeChild(dia.$div);
this._.$stage.removeChild(dia.$div);
if (dia.$clipPath) {
this$1._.$defs.removeChild(dia.$clipPath);
this._.$defs.removeChild(dia.$clipPath);
}
this$1._.stagings.splice(i, 1);
this._.stagings.splice(i, 1);
}
}
var dias = this.dialogues;
while (
this._.index < dias.length
&& vct >= dias[this._.index].start
) {
if (vct < dias[this$1._.index].end) {
var dia$1 = renderer.call(this$1, dias[this$1._.index]);
this$1._.stagings.push(dia$1);
if (vct < dias[this._.index].end) {
var dia$1 = renderer.call(this, dias[this._.index]);
this._.stagings.push(dia$1);
}
++this$1._.index;
++this._.index;
}
}

Expand All @@ -1778,13 +1795,11 @@
}

function clear() {
var this$1 = this;

while (this._.$stage.lastChild) {
this$1._.$stage.removeChild(this$1._.$stage.lastChild);
this._.$stage.removeChild(this._.$stage.lastChild);
}
while (this._.$defs.lastChild) {
this$1._.$defs.removeChild(this$1._.$defs.lastChild);
this._.$defs.removeChild(this._.$defs.lastChild);
}
this._.stagings = [];
this._.space = [];
Expand Down Expand Up @@ -1965,8 +1980,6 @@
}

function destroy() {
var this$1 = this;

pause.call(this);
clear.call(this);
unbindEvents.call(this, this._.listener);
Expand All @@ -1983,9 +1996,9 @@
styleRoot.removeChild(this._.$animation);

// eslint-disable-next-line no-restricted-syntax
for (var key in this$1) {
if (Object.prototype.hasOwnProperty.call(this$1, key)) {
this$1[key] = null;
for (var key in this) {
if (Object.prototype.hasOwnProperty.call(this, key)) {
this[key] = null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/ass.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assjs",
"version": "0.0.7",
"version": "0.0.8",
"description": "A JavaScript ASS subtitle format renderer",
"main": "dist/ass.js",
"module": "dist/ass.esm.js",
Expand Down

0 comments on commit 68942a7

Please sign in to comment.