Skip to content

Commit

Permalink
0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Dec 2, 2017
1 parent eb5c243 commit 75b41b9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 57 deletions.
117 changes: 62 additions & 55 deletions dist/ass-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,47 @@ var numTags = [
'fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr',
'be', 'blur', 'bord', 'xbord', 'ybord', 'shad', 'xshad', 'yshad' ];

var numRegexs = numTags.map(function (nt) { return ({ name: nt, regex: new RegExp(("^" + nt + "-?\\d")) }); });

function parseTag(text) {
var tag = {};
for (var i = 0; i < numTags.length; i++) {
var nt = numTags[i];
var regex = new RegExp(("^" + nt + "-?\\d"));
for (var i = 0; i < numRegexs.length; i++) {
var ref = numRegexs[i];
var name = ref.name;
var regex = ref.regex;
if (regex.test(text)) {
tag[nt] = text.slice(nt.length) * 1;
tag[name] = text.slice(name.length) * 1;
return tag;
}
}
if (/^fn/.test(text)) { tag.fn = text.slice(2); }
if (/^r/.test(text)) { tag.r = text.slice(1); }
if (/^fs[\d+-]/.test(text)) { tag.fs = text.slice(2); }
if (/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(text)) {
var ref = text.match(/^(\d?)c&?H?(\w*)/);
var num = ref[1];
var color = ref[2];
if (/^fn/.test(text)) {
tag.fn = text.slice(2);
} else if (/^r/.test(text)) {
tag.r = text.slice(1);
} else if (/^fs[\d+-]/.test(text)) {
tag.fs = text.slice(2);
} else if (/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(text)) {
var ref$1 = text.match(/^(\d?)c&?H?(\w*)/);
var num = ref$1[1];
var color = ref$1[2];
tag[("c" + (num || 1))] = color && ("000000" + color).slice(-6);
}
if (/^\da&?H?[0-9a-f]+/i.test(text)) {
var ref$1 = text.match(/^(\d)a&?H?(\w\w)/);
var num$1 = ref$1[1];
var alpha = ref$1[2];
} else if (/^\da&?H?[0-9a-f]+/i.test(text)) {
var ref$2 = text.match(/^(\d)a&?H?(\w\w)/);
var num$1 = ref$2[1];
var alpha = ref$2[2];
tag[("a" + num$1)] = alpha;
}
if (/^alpha&?H?[0-9a-f]+/i.test(text)) {
} else if (/^alpha&?H?[0-9a-f]+/i.test(text)) {
var assign;
(assign = text.match(/^alpha&?H?(\w\w)/), tag.alpha = assign[1]);
}
if (/^(?:pos|org|move|fad|fade)\(/.test(text)) {
var ref$2 = text.match(/^(\w+)\((.*?)\)/);
var key = ref$2[1];
var value = ref$2[2];
} else if (/^(?:pos|org|move|fad|fade)\(/.test(text)) {
var ref$3 = text.match(/^(\w+)\((.*?)\)/);
var key = ref$3[1];
var value = ref$3[2];
tag[key] = value
.trim()
.split(/\s*,\s*/)
.map(Number);
}
if (/^i?clip/.test(text)) {
} else if (/^i?clip/.test(text)) {
var p = text
.match(/^i?clip\((.*)\)/)[1]
.trim()
Expand All @@ -104,8 +107,7 @@ function parseTag(text) {
if (p.length === 4) {
tag.clip.dots = p.map(Number);
}
}
if (/^t\(/.test(text)) {
} else if (/^t\(/.test(text)) {
var p$1 = text
.match(/^t\((.*)\)/)[1]
.trim()
Expand Down Expand Up @@ -140,20 +142,25 @@ function parseTag(text) {
}

function parseTags(text) {
var tags = [];
var depth = 0;
return text
.split('')
.map(function (x) {
if (x === '(') { depth++; }
if (x === ')') { depth--; }
if (depth < 0) { depth = 0; }
return (depth && x === '\\') ? '\n' : x;
})
.join('')
.split(/\\/)
.slice(1)
.map(function (x) { return x.replace(/\n/g, '\\'); })
.map(parseTag);
var str = '';
for (var i = 0; i < text.length; i++) {
var x = text[i];
if (x === '(') { depth++; }
if (x === ')') { depth--; }
if (depth < 0) { depth = 0; }
if (!depth && x === '\\') {
if (str) {
tags.push(str);
}
str = '';
} else {
str += x;
}
}
tags.push(str);
return tags.map(parseTag);
}

function parseText(text) {
Expand Down Expand Up @@ -278,23 +285,23 @@ function parse(text) {
return tree;
}

function assign(target) {
var sources = [], len = arguments.length - 1;
while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];

if (Object.assign) {
return Object.assign.apply(Object, [ target ].concat( sources ));
}
for (var i = 0; i < sources.length; i++) {
if (!sources[i]) { continue; }
var keys = Object.keys(sources[i]);
for (var j = 0; j < keys.length; j++) {
// eslint-disable-next-line no-param-reassign
target[keys[j]] = sources[i][keys[j]];
var assign = Object.assign || (
/* istanbul ignore next */
function assign(target) {
var sources = [], len = arguments.length - 1;
while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];

for (var i = 0; i < sources.length; i++) {
if (!sources[i]) { continue; }
var keys = Object.keys(sources[i]);
for (var j = 0; j < keys.length; j++) {
// eslint-disable-next-line no-param-reassign
target[keys[j]] = sources[i][keys[j]];
}
}
return target;
}
return target;
}
);

function createCommand(arr) {
var cmd = {
Expand Down
Loading

0 comments on commit 75b41b9

Please sign in to comment.