Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ass-compiler

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ass-compiler - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

1496

dist/ass-compiler.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.assCompiler = {})));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.assCompiler = {})));
}(this, (function (exports) { 'use strict';
function parseEffect(text) {
var param = text
.toLowerCase()
.trim()
.split(/\s*;\s*/);
if (param[0] === 'banner') {
return {
name: param[0],
delay: param[1] * 1 || 0,
leftToRight: param[2] * 1 || 0,
fadeAwayWidth: param[3] * 1 || 0,
};
function parseEffect(text) {
var param = text
.toLowerCase()
.trim()
.split(/\s*;\s*/);
if (param[0] === 'banner') {
return {
name: param[0],
delay: param[1] * 1 || 0,
leftToRight: param[2] * 1 || 0,
fadeAwayWidth: param[3] * 1 || 0,
};
}
if (/^scroll\s/.test(param[0])) {
return {
name: param[0],
y1: Math.min(param[1] * 1, param[2] * 1),
y2: Math.max(param[1] * 1, param[2] * 1),
delay: param[3] * 1 || 0,
fadeAwayHeight: param[4] * 1 || 0,
};
}
return null;
}
if (/^scroll\s/.test(param[0])) {
return {
name: param[0],
y1: Math.min(param[1] * 1, param[2] * 1),
y2: Math.max(param[1] * 1, param[2] * 1),
delay: param[3] * 1 || 0,
fadeAwayHeight: param[4] * 1 || 0,
};
function parseDrawing(text) {
return text
.toLowerCase()
// numbers
.replace(/([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)/g, ' $1 ')
// commands
.replace(/([mnlbspc])/g, ' $1 ')
.trim()
.replace(/\s+/g, ' ')
.split(/\s(?=[mnlbspc])/)
.map(function (cmd) { return (
cmd.split(' ')
.filter(function (x, i) { return !(i && isNaN(x * 1)); })
); });
}
return null;
}
function parseDrawing(text) {
return text
.toLowerCase()
.replace(/([mnlbspc])/g, ' $1 ')
.trim()
.replace(/\s+/g, ' ')
.split(/\s(?=[mnlbspc])/)
.map(function (cmd) { return cmd.split(' '); });
}
var numTags = [
'b', 'i', 'u', 's', 'fsp',
'k', 'K', 'kf', 'ko', 'kt',
'fe', 'q', 'p', 'pbo', 'a', 'an',
'fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr',
'be', 'blur', 'bord', 'xbord', 'ybord', 'shad', 'xshad', 'yshad' ];
var numTags = [
'b', 'i', 'u', 's', 'fsp',
'k', 'K', 'kf', 'ko', 'kt',
'fe', 'q', 'p', 'pbo', 'a', 'an',
'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")) }); });
var numRegexs = numTags.map(function (nt) { return ({ name: nt, regex: new RegExp(("^" + nt + "-?\\d")) }); });
function parseTag(text) {
var assign;
function parseTag(text) {
var assign;
var tag = {};
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[name] = text.slice(name.length) * 1;
return tag;
}
}
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);
} 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;
} else if (/^alpha&?H?[0-9a-f]+/i.test(text)) {
(assign = text.match(/^alpha&?H?([0-9a-f]+)/i), tag.alpha = assign[1]);
tag.alpha = ("00" + (tag.alpha)).slice(-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);
} else if (/^i?clip/.test(text)) {
var p = text
.match(/^i?clip\((.*?)\)?$/)[1]
.trim()
.split(/\s*,\s*/);
tag.clip = {
inverse: /iclip/.test(text),
scale: 1,
drawing: null,
dots: null,
};
if (p.length === 1) {
tag.clip.drawing = parseDrawing(p[0]);
}
if (p.length === 2) {
tag.clip.scale = p[0] * 1;
tag.clip.drawing = parseDrawing(p[1]);
}
if (p.length === 4) {
tag.clip.dots = p.map(Number);
}
} else if (/^t\(/.test(text)) {
var p$1 = text
.match(/^t\((.*?)\)?$/)[1]
.trim()
.replace(/\\.*/, function (x) { return x.replace(/,/g, '\n'); })
.split(/\s*,\s*/);
if (!p$1[0]) { return tag; }
tag.t = {
t1: 0,
t2: 0,
accel: 1,
tags: p$1[p$1.length - 1]
.replace(/\n/g, ',')
.split('\\')
.slice(1)
.map(parseTag),
};
if (p$1.length === 2) {
tag.t.accel = p$1[0] * 1;
}
if (p$1.length === 3) {
tag.t.t1 = p$1[0] * 1;
tag.t.t2 = p$1[1] * 1;
}
if (p$1.length === 4) {
tag.t.t1 = p$1[0] * 1;
tag.t.t2 = p$1[1] * 1;
tag.t.accel = p$1[2] * 1;
}
}
var tag = {};
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[name] = text.slice(name.length) * 1;
return tag;
return tag;
}
function parseTags(text) {
var tags = [];
var depth = 0;
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);
}
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);
} 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;
} else if (/^alpha&?H?[0-9a-f]+/i.test(text)) {
(assign = text.match(/^alpha&?H?([0-9a-f]+)/i), tag.alpha = assign[1]);
tag.alpha = ("00" + (tag.alpha)).slice(-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);
} else if (/^i?clip/.test(text)) {
var p = text
.match(/^i?clip\((.*?)\)?$/)[1]
.trim()
.split(/\s*,\s*/);
tag.clip = {
inverse: /iclip/.test(text),
scale: 1,
drawing: null,
dots: null,
};
if (p.length === 1) {
tag.clip.drawing = parseDrawing(p[0]);
function parseText(text) {
var pairs = text.split(/{([^{}]*?)}/);
var parsed = [];
if (pairs[0].length) {
parsed.push({ tags: [], text: pairs[0], drawing: [] });
}
if (p.length === 2) {
tag.clip.scale = p[0] * 1;
tag.clip.drawing = parseDrawing(p[1]);
for (var i = 1; i < pairs.length; i += 2) {
var tags = parseTags(pairs[i]);
var isDrawing = tags.reduce(function (v, tag) { return (tag.p === undefined ? v : !!tag.p); }, false);
parsed.push({
tags: tags,
text: isDrawing ? '' : pairs[i + 1],
drawing: isDrawing ? parseDrawing(pairs[i + 1]) : [],
});
}
if (p.length === 4) {
tag.clip.dots = p.map(Number);
}
} else if (/^t\(/.test(text)) {
var p$1 = text
.match(/^t\((.*?)\)?$/)[1]
.trim()
.replace(/\\.*/, function (x) { return x.replace(/,/g, '\n'); })
.split(/\s*,\s*/);
if (!p$1[0]) { return tag; }
tag.t = {
t1: 0,
t2: 0,
accel: 1,
tags: p$1[p$1.length - 1]
.replace(/\n/g, ',')
.split('\\')
.slice(1)
.map(parseTag),
return {
raw: text,
combined: parsed.map(function (frag) { return frag.text; }).join(''),
parsed: parsed,
};
if (p$1.length === 2) {
tag.t.accel = p$1[0] * 1;
}
if (p$1.length === 3) {
tag.t.t1 = p$1[0] * 1;
tag.t.t2 = p$1[1] * 1;
}
if (p$1.length === 4) {
tag.t.t1 = p$1[0] * 1;
tag.t.t2 = p$1[1] * 1;
tag.t.accel = p$1[2] * 1;
}
}
return tag;
}
function parseTime(time) {
var t = time.split(':');
return t[0] * 3600 + t[1] * 60 + t[2] * 1;
}
function parseTags(text) {
var tags = [];
var depth = 0;
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);
function parseDialogue(text, format) {
var fields = text.split(',');
if (fields.length > format.length) {
var textField = fields.slice(format.length - 1).join();
fields = fields.slice(0, format.length - 1);
fields.push(textField);
}
var dia = {};
for (var i = 0; i < fields.length; i++) {
var fmt = format[i];
var fld = fields[i].trim();
switch (fmt) {
case 'Layer':
case 'MarginL':
case 'MarginR':
case 'MarginV':
dia[fmt] = fld * 1;
break;
case 'Start':
case 'End':
dia[fmt] = parseTime(fld);
break;
case 'Effect':
dia[fmt] = parseEffect(fld);
break;
case 'Text':
dia[fmt] = parseText(fld);
break;
default:
dia[fmt] = fld;
}
str = '';
} else {
str += x;
}
}
tags.push(str);
return tags.map(parseTag);
}
function parseText(text) {
var pairs = text.split(/{([^{}]*?)}/);
var parsed = [];
if (pairs[0].length) {
parsed.push({ tags: [], text: pairs[0], drawing: [] });
return dia;
}
for (var i = 1; i < pairs.length; i += 2) {
var tags = parseTags(pairs[i]);
var isDrawing = tags.reduce(function (v, tag) { return (tag.p === undefined ? v : !!tag.p); }, false);
parsed.push({
tags: tags,
text: isDrawing ? '' : pairs[i + 1],
drawing: isDrawing ? parseDrawing(pairs[i + 1]) : [],
});
}
return {
raw: text,
combined: parsed.map(function (frag) { return frag.text; }).join(''),
parsed: parsed,
};
}
function parseTime(time) {
var t = time.split(':');
return t[0] * 3600 + t[1] * 60 + t[2] * 1;
}
function parseDialogue(text, format) {
var fields = text.split(',');
if (fields.length > format.length) {
var textField = fields.slice(format.length - 1).join();
fields = fields.slice(0, format.length - 1);
fields.push(textField);
function parseFormat(text) {
return text.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
}
var dia = {};
for (var i = 0; i < fields.length; i++) {
var fmt = format[i];
var fld = fields[i].trim();
switch (fmt) {
case 'Layer':
case 'MarginL':
case 'MarginR':
case 'MarginV':
dia[fmt] = fld * 1;
break;
case 'Start':
case 'End':
dia[fmt] = parseTime(fld);
break;
case 'Effect':
dia[fmt] = parseEffect(fld);
break;
case 'Text':
dia[fmt] = parseText(fld);
break;
default:
dia[fmt] = fld;
}
function parseStyle(text) {
return text.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
}
return dia;
}
function parse(text) {
var tree = {
info: {},
styles: { format: [], style: [] },
events: { format: [], comment: [], dialogue: [] },
};
var lines = text.split(/\r?\n/);
var state = 0;
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
if (/^;/.test(line)) { continue; }
function parseFormat(text) {
return text.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
}
if (/^\[Script Info\]/i.test(line)) { state = 1; }
else if (/^\[V4\+? Styles\]/i.test(line)) { state = 2; }
else if (/^\[Events\]/i.test(line)) { state = 3; }
else if (/^\[.*\]/.test(line)) { state = 0; }
function parseStyle(text) {
return text.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
}
function parse(text) {
var tree = {
info: {},
styles: { format: [], style: [] },
events: { format: [], comment: [], dialogue: [] },
};
var lines = text.split(/\r?\n/);
var state = 0;
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
if (/^;/.test(line)) { continue; }
if (/^\[Script Info\]/i.test(line)) { state = 1; }
else if (/^\[V4\+? Styles\]/i.test(line)) { state = 2; }
else if (/^\[Events\]/i.test(line)) { state = 3; }
else if (/^\[.*\]/.test(line)) { state = 0; }
if (state === 0) { continue; }
if (state === 1) {
if (/:/.test(line)) {
var ref = line.match(/(.*?)\s*:\s*(.*)/);
var key = ref[1];
var value = ref[2];
tree.info[key] = value;
if (state === 0) { continue; }
if (state === 1) {
if (/:/.test(line)) {
var ref = line.match(/(.*?)\s*:\s*(.*)/);
var key = ref[1];
var value = ref[2];
tree.info[key] = value;
}
}
}
if (state === 2) {
if (/^Format\s*:/i.test(line)) {
tree.styles.format = parseFormat(line);
if (state === 2) {
if (/^Format\s*:/i.test(line)) {
tree.styles.format = parseFormat(line);
}
if (/^Style\s*:/i.test(line)) {
tree.styles.style.push(parseStyle(line));
}
}
if (/^Style\s*:/i.test(line)) {
tree.styles.style.push(parseStyle(line));
if (state === 3) {
if (/^Format\s*:/i.test(line)) {
tree.events.format = parseFormat(line);
}
if (/^(?:Comment|Dialogue)\s*:/i.test(line)) {
var ref$1 = line.match(/^(\w+?)\s*:\s*(.*)/i);
var key$1 = ref$1[1];
var value$1 = ref$1[2];
tree.events[key$1.toLowerCase()].push(parseDialogue(value$1, tree.events.format));
}
}
}
if (state === 3) {
if (/^Format\s*:/i.test(line)) {
tree.events.format = parseFormat(line);
}
if (/^(?:Comment|Dialogue)\s*:/i.test(line)) {
var ref$1 = line.match(/^(\w+?)\s*:\s*(.*)/i);
var key$1 = ref$1[1];
var value$1 = ref$1[2];
tree.events[key$1.toLowerCase()].push(parseDialogue(value$1, tree.events.format));
}
}
return tree;
}
return tree;
}
var assign = Object.assign || (
/* istanbul ignore next */
function assign(target) {
var sources = [], len = arguments.length - 1;
while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
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]];
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 = {
type: null,
prev: null,
next: null,
points: [],
};
if (/[mnlbs]/.test(arr[0])) {
cmd.type = arr[0]
.toUpperCase()
.replace('N', 'L')
.replace('B', 'C');
function createCommand(arr) {
var cmd = {
type: null,
prev: null,
next: null,
points: [],
};
if (/[mnlbs]/.test(arr[0])) {
cmd.type = arr[0]
.toUpperCase()
.replace('N', 'L')
.replace('B', 'C');
}
for (var len = arr.length - !(arr.length & 1), i = 1; i < len; i += 2) {
cmd.points.push({ x: arr[i] * 1, y: arr[i + 1] * 1 });
}
return cmd;
}
for (var len = arr.length - !(arr.length & 1), i = 1; i < len; i += 2) {
cmd.points.push({ x: arr[i] * 1, y: arr[i + 1] * 1 });
}
return cmd;
}
function isValid(cmd) {
if (!cmd.points.length || !cmd.type) {
return false;
function isValid(cmd) {
if (!cmd.points.length || !cmd.type) {
return false;
}
if (/C|S/.test(cmd.type) && cmd.points.length < 3) {
return false;
}
return true;
}
if (/C|S/.test(cmd.type) && cmd.points.length < 3) {
return false;
}
return true;
}
function getViewBox(commands) {
var ref;
function getViewBox(commands) {
var ref;
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
(ref = []).concat.apply(ref, commands.map(function (ref) {
var points = ref.points;
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
(ref = []).concat.apply(ref, commands.map(function (ref) {
var points = ref.points;
return points;
})).forEach(function (ref) {
var x = ref.x;
var y = ref.y;
return points;
})).forEach(function (ref) {
var x = ref.x;
var y = ref.y;
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
});
return {
minX: minX,
minY: minY,
width: maxX - minX,
height: maxY - minY,
};
}
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
});
return {
minX: minX,
minY: minY,
width: maxX - minX,
height: maxY - minY,
};
}
/**
* Convert S command to B command
* Reference from https://github.com/d3/d3/blob/v3.5.17/src/svg/line.js#L259
* @param {Array} points points
* @param {String} prev type of previous command
* @param {String} next type of next command
* @return {Array} converted commands
*/
function s2b(points, prev, next) {
var results = [];
var bb1 = [0, 2 / 3, 1 / 3, 0];
var bb2 = [0, 1 / 3, 2 / 3, 0];
var bb3 = [0, 1 / 6, 2 / 3, 1 / 6];
var dot4 = function (a, b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]); };
var px = [points[points.length - 1].x, points[0].x, points[1].x, points[2].x];
var py = [points[points.length - 1].y, points[0].y, points[1].y, points[2].y];
results.push({
type: prev === 'M' ? 'M' : 'L',
points: [{ x: dot4(bb3, px), y: dot4(bb3, py) }],
});
for (var i = 3; i < points.length; i++) {
px = [points[i - 3].x, points[i - 2].x, points[i - 1].x, points[i].x];
py = [points[i - 3].y, points[i - 2].y, points[i - 1].y, points[i].y];
/**
* Convert S command to B command
* Reference from https://github.com/d3/d3/blob/v3.5.17/src/svg/line.js#L259
* @param {Array} points points
* @param {String} prev type of previous command
* @param {String} next type of next command
* @return {Array} converted commands
*/
function s2b(points, prev, next) {
var results = [];
var bb1 = [0, 2 / 3, 1 / 3, 0];
var bb2 = [0, 1 / 3, 2 / 3, 0];
var bb3 = [0, 1 / 6, 2 / 3, 1 / 6];
var dot4 = function (a, b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]); };
var px = [points[points.length - 1].x, points[0].x, points[1].x, points[2].x];
var py = [points[points.length - 1].y, points[0].y, points[1].y, points[2].y];
results.push({
type: 'C',
points: [
{ x: dot4(bb1, px), y: dot4(bb1, py) },
{ x: dot4(bb2, px), y: dot4(bb2, py) },
{ x: dot4(bb3, px), y: dot4(bb3, py) } ],
type: prev === 'M' ? 'M' : 'L',
points: [{ x: dot4(bb3, px), y: dot4(bb3, py) }],
});
for (var i = 3; i < points.length; i++) {
px = [points[i - 3].x, points[i - 2].x, points[i - 1].x, points[i].x];
py = [points[i - 3].y, points[i - 2].y, points[i - 1].y, points[i].y];
results.push({
type: 'C',
points: [
{ x: dot4(bb1, px), y: dot4(bb1, py) },
{ x: dot4(bb2, px), y: dot4(bb2, py) },
{ x: dot4(bb3, px), y: dot4(bb3, py) } ],
});
}
if (next === 'L' || next === 'C') {
var last = points[points.length - 1];
results.push({ type: 'L', points: [{ x: last.x, y: last.y }] });
}
return results;
}
if (next === 'L' || next === 'C') {
var last = points[points.length - 1];
results.push({ type: 'L', points: [{ x: last.x, y: last.y }] });
}
return results;
}
function toSVGPath(instructions) {
return instructions.map(function (ref) {
var type = ref.type;
var points = ref.points;
function toSVGPath(instructions) {
return instructions.map(function (ref) {
var type = ref.type;
var points = ref.points;
return (
type + points.map(function (ref) {
var x = ref.x;
var y = ref.y;
return (
type + points.map(function (ref) {
var x = ref.x;
var y = ref.y;
return (x + "," + y);
}).join(',')
);
}).join('');
}
return (x + "," + y);
}).join(',')
);
}).join('');
}
function compileDrawing(rawCommands) {
var ref$1;
function compileDrawing(rawCommands) {
var ref$1;
var commands = [];
var i = 0;
while (i < rawCommands.length) {
var arr = rawCommands[i];
var cmd = createCommand(arr);
if (cmd.type) {
if (cmd.type === 'S') {
var ref = commands[i - 1].points.slice(-1)[0];
var x = ref.x;
var y = ref.y;
cmd.points.unshift({ x: x, y: y });
}
var commands = [];
var i = 0;
while (i < rawCommands.length) {
var arr = rawCommands[i];
var cmd = createCommand(arr);
if (isValid(cmd)) {
if (cmd.type === 'S') {
var ref = (commands[i - 1] || { points: [{ x: 0, y: 0 }] }).points.slice(-1)[0];
var x = ref.x;
var y = ref.y;
cmd.points.unshift({ x: x, y: y });
}
if (i) {

@@ -440,413 +445,412 @@ cmd.prev = commands[i - 1].type;

commands.push(cmd);
}
i++;
} else {
if (commands[i - 1].type === 'S') {
var additionPoints = {
p: cmd.points,
c: commands[i - 1].points.slice(0, 3),
};
commands[i - 1].points = commands[i - 1].points.concat(
(additionPoints[arr[0]] || []).map(function (ref) {
var x = ref.x;
var y = ref.y;
i++;
} else {
if (i && commands[i - 1].type === 'S') {
var additionPoints = {
p: cmd.points,
c: commands[i - 1].points.slice(0, 3),
};
commands[i - 1].points = commands[i - 1].points.concat(
(additionPoints[arr[0]] || []).map(function (ref) {
var x = ref.x;
var y = ref.y;
return ({ x: x, y: y });
})
);
return ({ x: x, y: y });
})
);
}
rawCommands.splice(i, 1);
}
rawCommands.splice(i, 1);
}
}
var instructions = (ref$1 = []).concat.apply(
ref$1, commands.map(function (ref) {
var type = ref.type;
var points = ref.points;
var prev = ref.prev;
var next = ref.next;
var instructions = (ref$1 = []).concat.apply(
ref$1, commands.map(function (ref) {
var type = ref.type;
var points = ref.points;
var prev = ref.prev;
var next = ref.next;
return (
type === 'S'
? s2b(points, prev, next)
: { type: type, points: points }
return (
type === 'S'
? s2b(points, prev, next)
: { type: type, points: points }
);
})
);
})
);
return assign({ instructions: instructions, d: toSVGPath(instructions) }, getViewBox(commands));
}
return assign({ instructions: instructions, d: toSVGPath(instructions) }, getViewBox(commands));
}
var tTags = [
'fs', 'clip',
'c1', 'c2', 'c3', 'c4', 'a1', 'a2', 'a3', 'a4', 'alpha',
'fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr',
'be', 'blur', 'bord', 'xbord', 'ybord', 'shad', 'xshad', 'yshad' ];
var tTags = [
'fs', 'clip',
'c1', 'c2', 'c3', 'c4', 'a1', 'a2', 'a3', 'a4', 'alpha',
'fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr',
'be', 'blur', 'bord', 'xbord', 'ybord', 'shad', 'xshad', 'yshad' ];
function compileTag(tag, key, presets) {
var obj, obj$1, obj$2;
function compileTag(tag, key, presets) {
var obj, obj$1, obj$2;
if ( presets === void 0 ) presets = {};
var value = tag[key];
if (value === undefined) {
return null;
}
if (key === 'pos' || key === 'org') {
return value.length === 2 ? ( obj = {}, obj[key] = { x: value[0], y: value[1] }, obj) : null;
}
if (key === 'move') {
var x1 = value[0];
var y1 = value[1];
var x2 = value[2];
var y2 = value[3];
var t1 = value[4]; if ( t1 === void 0 ) t1 = 0;
var t2 = value[5]; if ( t2 === void 0 ) t2 = 0;
return value.length === 4 || value.length === 6
? { move: { x1: x1, y1: y1, x2: x2, y2: y2, t1: t1, t2: t2 } }
: null;
}
if (key === 'fad' || key === 'fade') {
if (value.length === 2) {
var t1$1 = value[0];
var t2$1 = value[1];
return { fade: { type: 'fad', t1: t1$1, t2: t2$1 } };
if ( presets === void 0 ) presets = {};
var value = tag[key];
if (value === undefined) {
return null;
}
if (value.length === 7) {
var a1 = value[0];
var a2 = value[1];
var a3 = value[2];
var t1$2 = value[3];
var t2$2 = value[4];
var t3 = value[5];
var t4 = value[6];
return { fade: { type: 'fade', a1: a1, a2: a2, a3: a3, t1: t1$2, t2: t2$2, t3: t3, t4: t4 } };
if (key === 'pos' || key === 'org') {
return value.length === 2 ? ( obj = {}, obj[key] = { x: value[0], y: value[1] }, obj) : null;
}
return null;
}
if (key === 'clip') {
var inverse = value.inverse;
var scale = value.scale;
var drawing = value.drawing;
var dots = value.dots;
if (drawing) {
return { clip: { inverse: inverse, scale: scale, drawing: compileDrawing(drawing), dots: dots } };
if (key === 'move') {
var x1 = value[0];
var y1 = value[1];
var x2 = value[2];
var y2 = value[3];
var t1 = value[4]; if ( t1 === void 0 ) t1 = 0;
var t2 = value[5]; if ( t2 === void 0 ) t2 = 0;
return value.length === 4 || value.length === 6
? { move: { x1: x1, y1: y1, x2: x2, y2: y2, t1: t1, t2: t2 } }
: null;
}
if (dots) {
var x1$1 = dots[0];
var y1$1 = dots[1];
var x2$1 = dots[2];
var y2$1 = dots[3];
return { clip: { inverse: inverse, scale: scale, drawing: drawing, dots: { x1: x1$1, y1: y1$1, x2: x2$1, y2: y2$1 } } };
if (key === 'fad' || key === 'fade') {
if (value.length === 2) {
var t1$1 = value[0];
var t2$1 = value[1];
return { fade: { type: 'fad', t1: t1$1, t2: t2$1 } };
}
if (value.length === 7) {
var a1 = value[0];
var a2 = value[1];
var a3 = value[2];
var t1$2 = value[3];
var t2$2 = value[4];
var t3 = value[5];
var t4 = value[6];
return { fade: { type: 'fade', a1: a1, a2: a2, a3: a3, t1: t1$2, t2: t2$2, t3: t3, t4: t4 } };
}
return null;
}
return null;
}
if (/^[xy]?(bord|shad)$/.test(key)) {
value = Math.max(value, 0);
}
if (key === 'bord') {
return { xbord: value, ybord: value };
}
if (key === 'shad') {
return { xshad: value, yshad: value };
}
if (/^c\d$/.test(key)) {
return ( obj$1 = {}, obj$1[key] = value || presets[key], obj$1);
}
if (key === 'alpha') {
return { a1: value, a2: value, a3: value, a4: value };
}
if (key === 'fr') {
return { frz: value };
}
if (key === 'fs') {
return {
fs: /^\+|-/.test(value)
? (value * 1 > -10 ? (1 + value / 10) : 1) * presets.fs
: value * 1,
};
}
if (key === 't') {
var t1$3 = value.t1;
var accel = value.accel;
var tags = value.tags;
var t2$3 = value.t2 || (presets.end - presets.start) * 1e3;
var compiledTag = {};
tags.forEach(function (t) {
var k = Object.keys(t)[0];
if (~tTags.indexOf(k) && !(k === 'clip' && !t[k].dots)) {
assign(compiledTag, compileTag(t, k, presets));
if (key === 'clip') {
var inverse = value.inverse;
var scale = value.scale;
var drawing = value.drawing;
var dots = value.dots;
if (drawing) {
return { clip: { inverse: inverse, scale: scale, drawing: compileDrawing(drawing), dots: dots } };
}
});
return { t: { t1: t1$3, t2: t2$3, accel: accel, tag: compiledTag } };
if (dots) {
var x1$1 = dots[0];
var y1$1 = dots[1];
var x2$1 = dots[2];
var y2$1 = dots[3];
return { clip: { inverse: inverse, scale: scale, drawing: drawing, dots: { x1: x1$1, y1: y1$1, x2: x2$1, y2: y2$1 } } };
}
return null;
}
if (/^[xy]?(bord|shad)$/.test(key)) {
value = Math.max(value, 0);
}
if (key === 'bord') {
return { xbord: value, ybord: value };
}
if (key === 'shad') {
return { xshad: value, yshad: value };
}
if (/^c\d$/.test(key)) {
return ( obj$1 = {}, obj$1[key] = value || presets[key], obj$1);
}
if (key === 'alpha') {
return { a1: value, a2: value, a3: value, a4: value };
}
if (key === 'fr') {
return { frz: value };
}
if (key === 'fs') {
return {
fs: /^\+|-/.test(value)
? (value * 1 > -10 ? (1 + value / 10) : 1) * presets.fs
: value * 1,
};
}
if (key === 't') {
var t1$3 = value.t1;
var accel = value.accel;
var tags = value.tags;
var t2$3 = value.t2 || (presets.end - presets.start) * 1e3;
var compiledTag = {};
tags.forEach(function (t) {
var k = Object.keys(t)[0];
if (~tTags.indexOf(k) && !(k === 'clip' && !t[k].dots)) {
assign(compiledTag, compileTag(t, k, presets));
}
});
return { t: { t1: t1$3, t2: t2$3, accel: accel, tag: compiledTag } };
}
return ( obj$2 = {}, obj$2[key] = value, obj$2);
}
return ( obj$2 = {}, obj$2[key] = value, obj$2);
}
var a2an = [
null, 1, 2, 3,
null, 7, 8, 9,
null, 4, 5, 6 ];
var a2an = [
null, 1, 2, 3,
null, 7, 8, 9,
null, 4, 5, 6 ];
var globalTags = ['r', 'a', 'an', 'pos', 'org', 'move', 'fade', 'fad', 'clip'];
var globalTags = ['r', 'a', 'an', 'pos', 'org', 'move', 'fade', 'fad', 'clip'];
function createSlice(name, styles) {
return {
name: name,
borderStyle: styles[name].style.BorderStyle,
tag: styles[name].tag,
fragments: [],
};
}
function createSlice(name, styles) {
return {
name: name,
borderStyle: styles[name].style.BorderStyle,
tag: styles[name].tag,
fragments: [],
};
}
function compileText(ref) {
var styles = ref.styles;
var name = ref.name;
var parsed = ref.parsed;
var start = ref.start;
var end = ref.end;
function compileText(ref) {
var styles = ref.styles;
var name = ref.name;
var parsed = ref.parsed;
var start = ref.start;
var end = ref.end;
var alignment;
var pos;
var org;
var move;
var fade;
var clip;
var slices = [];
var slice = createSlice(name, styles);
var prevTag = {};
for (var i = 0; i < parsed.length; i++) {
var ref$1 = parsed[i];
var tags = ref$1.tags;
var text = ref$1.text;
var drawing = ref$1.drawing;
var reset = (void 0);
for (var j = 0; j < tags.length; j++) {
var tag = tags[j];
reset = tag.r === undefined ? reset : tag.r;
}
var fragment = {
tag: reset === undefined ? JSON.parse(JSON.stringify(prevTag)) : {},
text: text,
drawing: drawing.length ? compileDrawing(drawing) : null,
};
for (var j$1 = 0; j$1 < tags.length; j$1++) {
var tag$1 = tags[j$1];
alignment = alignment || a2an[tag$1.a || 0] || tag$1.an;
pos = pos || compileTag(tag$1, 'pos');
org = org || compileTag(tag$1, 'org');
move = move || compileTag(tag$1, 'move');
fade = fade || compileTag(tag$1, 'fade') || compileTag(tag$1, 'fad');
clip = compileTag(tag$1, 'clip') || clip;
var key = Object.keys(tag$1)[0];
if (key && !~globalTags.indexOf(key)) {
var ref$2 = slice.tag;
var c1 = ref$2.c1;
var c2 = ref$2.c2;
var c3 = ref$2.c3;
var c4 = ref$2.c4;
var fs = prevTag.fs || slice.tag.fs;
var compiledTag = compileTag(tag$1, key, { start: start, end: end, c1: c1, c2: c2, c3: c3, c4: c4, fs: fs });
if (key === 't') {
fragment.tag.t = fragment.tag.t || [];
fragment.tag.t.push(compiledTag.t);
var alignment;
var pos;
var org;
var move;
var fade;
var clip;
var slices = [];
var slice = createSlice(name, styles);
var prevTag = {};
for (var i = 0; i < parsed.length; i++) {
var ref$1 = parsed[i];
var tags = ref$1.tags;
var text = ref$1.text;
var drawing = ref$1.drawing;
var reset = (void 0);
for (var j = 0; j < tags.length; j++) {
var tag = tags[j];
reset = tag.r === undefined ? reset : tag.r;
}
var fragment = {
tag: reset === undefined ? JSON.parse(JSON.stringify(prevTag)) : {},
text: text,
drawing: drawing.length ? compileDrawing(drawing) : null,
};
for (var j$1 = 0; j$1 < tags.length; j$1++) {
var tag$1 = tags[j$1];
alignment = alignment || a2an[tag$1.a || 0] || tag$1.an;
pos = pos || compileTag(tag$1, 'pos');
org = org || compileTag(tag$1, 'org');
move = move || compileTag(tag$1, 'move');
fade = fade || compileTag(tag$1, 'fade') || compileTag(tag$1, 'fad');
clip = compileTag(tag$1, 'clip') || clip;
var key = Object.keys(tag$1)[0];
if (key && !~globalTags.indexOf(key)) {
var ref$2 = slice.tag;
var c1 = ref$2.c1;
var c2 = ref$2.c2;
var c3 = ref$2.c3;
var c4 = ref$2.c4;
var fs = prevTag.fs || slice.tag.fs;
var compiledTag = compileTag(tag$1, key, { start: start, end: end, c1: c1, c2: c2, c3: c3, c4: c4, fs: fs });
if (key === 't') {
fragment.tag.t = fragment.tag.t || [];
fragment.tag.t.push(compiledTag.t);
} else {
assign(fragment.tag, compiledTag);
}
}
}
prevTag = fragment.tag;
if (reset !== undefined) {
slices.push(slice);
slice = createSlice(styles[reset] ? reset : name, styles);
}
if (fragment.text || fragment.drawing) {
var prev = slice.fragments[slice.fragments.length - 1] || {};
if (prev.text && fragment.text && !Object.keys(fragment.tag).length) {
// merge fragment to previous if its tag is empty
prev.text += fragment.text;
} else {
assign(fragment.tag, compiledTag);
slice.fragments.push(fragment);
}
}
}
prevTag = fragment.tag;
if (reset !== undefined) {
slices.push(slice);
slice = createSlice(styles[reset] ? reset : name, styles);
}
if (fragment.text || fragment.drawing) {
var prev = slice.fragments[slice.fragments.length - 1] || {};
if (prev.text && fragment.text && !Object.keys(fragment.tag).length) {
// merge fragment to previous if its tag is empty
prev.text += fragment.text;
} else {
slice.fragments.push(fragment);
}
}
slices.push(slice);
return assign({ alignment: alignment, slices: slices }, pos, org, move, fade, clip);
}
slices.push(slice);
return assign({ alignment: alignment, slices: slices }, pos, org, move, fade, clip);
}
function compileDialogues(ref) {
var styles = ref.styles;
var dialogues = ref.dialogues;
function compileDialogues(ref) {
var styles = ref.styles;
var dialogues = ref.dialogues;
var minLayer = Infinity;
var results = [];
for (var i = 0; i < dialogues.length; i++) {
var dia = dialogues[i];
if (dia.Start >= dia.End) {
continue;
var minLayer = Infinity;
var results = [];
for (var i = 0; i < dialogues.length; i++) {
var dia = dialogues[i];
if (dia.Start >= dia.End) {
continue;
}
if (!styles[dia.Style]) {
dia.Style = 'Default';
}
var stl = styles[dia.Style].style;
var compiledText = compileText({
styles: styles,
name: dia.Style,
parsed: dia.Text.parsed,
start: dia.Start,
end: dia.End,
});
var alignment = compiledText.alignment || stl.Alignment;
minLayer = Math.min(minLayer, dia.Layer);
results.push(assign({
layer: dia.Layer,
start: dia.Start,
end: dia.End,
// reset style by `\r` will not effect margin and alignment
margin: {
left: dia.MarginL || stl.MarginL,
right: dia.MarginR || stl.MarginR,
vertical: dia.MarginV || stl.MarginV,
},
effect: dia.Effect,
}, compiledText, { alignment: alignment }));
}
if (!styles[dia.Style]) {
dia.Style = 'Default';
for (var i$1 = 0; i$1 < results.length; i$1++) {
results[i$1].layer -= minLayer;
}
var stl = styles[dia.Style].style;
var compiledText = compileText({
styles: styles,
name: dia.Style,
parsed: dia.Text.parsed,
start: dia.Start,
end: dia.End,
});
var alignment = compiledText.alignment || stl.Alignment;
minLayer = Math.min(minLayer, dia.Layer);
results.push(assign({
layer: dia.Layer,
start: dia.Start,
end: dia.End,
// reset style by `\r` will not effect margin and alignment
margin: {
left: dia.MarginL || stl.MarginL,
right: dia.MarginR || stl.MarginR,
vertical: dia.MarginV || stl.MarginV,
},
effect: dia.Effect,
}, compiledText, { alignment: alignment }));
return results.sort(function (a, b) { return a.start - b.start || a.end - b.end; });
}
for (var i$1 = 0; i$1 < results.length; i$1++) {
results[i$1].layer -= minLayer;
}
return results.sort(function (a, b) { return a.start - b.start || a.end - b.end; });
}
// same as Aegisub
// https://github.com/Aegisub/Aegisub/blob/master/src/ass_style.h
var DEFAULT_STYLE = {
Name: 'Default',
Fontname: 'Arial',
Fontsize: '20',
PrimaryColour: '&H00FFFFFF&',
SecondaryColour: '&H000000FF&',
OutlineColour: '&H00000000&',
BackColour: '&H00000000&',
Bold: '0',
Italic: '0',
Underline: '0',
StrikeOut: '0',
ScaleX: '100',
ScaleY: '100',
Spacing: '0',
Angle: '0',
BorderStyle: '1',
Outline: '2',
Shadow: '2',
Alignment: '2',
MarginL: '10',
MarginR: '10',
MarginV: '10',
Encoding: '1',
};
// same as Aegisub
// https://github.com/Aegisub/Aegisub/blob/master/src/ass_style.h
var DEFAULT_STYLE = {
Name: 'Default',
Fontname: 'Arial',
Fontsize: '20',
PrimaryColour: '&H00FFFFFF&',
SecondaryColour: '&H000000FF&',
OutlineColour: '&H00000000&',
BackColour: '&H00000000&',
Bold: '0',
Italic: '0',
Underline: '0',
StrikeOut: '0',
ScaleX: '100',
ScaleY: '100',
Spacing: '0',
Angle: '0',
BorderStyle: '1',
Outline: '2',
Shadow: '2',
Alignment: '2',
MarginL: '10',
MarginR: '10',
MarginV: '10',
Encoding: '1',
};
function parseStyleColor(color) {
var ref = color.match(/&H(\w\w)?(\w{6})&?/);
var a = ref[1];
var c = ref[2];
return [a || '00', c];
}
function parseStyleColor(color) {
var ref = color.match(/&H(\w\w)?(\w{6})&?/);
var a = ref[1];
var c = ref[2];
return [a || '00', c];
}
function compileStyles(ref) {
var info = ref.info;
var style = ref.style;
var format = ref.format;
var defaultStyle = ref.defaultStyle;
function compileStyles(ref) {
var info = ref.info;
var style = ref.style;
var format = ref.format;
var defaultStyle = ref.defaultStyle;
var result = {};
var styles = [
assign({}, DEFAULT_STYLE, defaultStyle, { Name: 'Default' }) ].concat( style.map(function (stl) {
var s = {};
for (var i = 0; i < format.length; i++) {
s[format[i]] = stl[i];
var result = {};
var styles = [
assign({}, DEFAULT_STYLE, defaultStyle, { Name: 'Default' }) ].concat( style.map(function (stl) {
var s = {};
for (var i = 0; i < format.length; i++) {
s[format[i]] = stl[i];
}
return s;
}) );
var loop = function ( i ) {
var s = styles[i];
// this behavior is same as Aegisub by black-box testing
if (/^(\*+)Default$/.test(s.Name)) {
s.Name = 'Default';
}
return s;
}) );
var loop = function ( i ) {
var s = styles[i];
// this behavior is same as Aegisub by black-box testing
if (/^(\*+)Default$/.test(s.Name)) {
s.Name = 'Default';
}
Object.keys(s).forEach(function (key) {
if (key !== 'Name' && key !== 'Fontname' && !/Colour/.test(key)) {
s[key] *= 1;
}
});
var ref$1 = parseStyleColor(s.PrimaryColour);
var a1 = ref$1[0];
var c1 = ref$1[1];
var ref$2 = parseStyleColor(s.SecondaryColour);
var a2 = ref$2[0];
var c2 = ref$2[1];
var ref$3 = parseStyleColor(s.OutlineColour);
var a3 = ref$3[0];
var c3 = ref$3[1];
var ref$4 = parseStyleColor(s.BackColour);
var a4 = ref$4[0];
var c4 = ref$4[1];
var tag = {
fn: s.Fontname,
fs: s.Fontsize,
c1: c1,
a1: a1,
c2: c2,
a2: a2,
c3: c3,
a3: a3,
c4: c4,
a4: a4,
b: Math.abs(s.Bold),
i: Math.abs(s.Italic),
u: Math.abs(s.Underline),
s: Math.abs(s.StrikeOut),
fscx: s.ScaleX,
fscy: s.ScaleY,
fsp: s.Spacing,
frz: s.Angle,
xbord: s.Outline,
ybord: s.Outline,
xshad: s.Shadow,
yshad: s.Shadow,
q: /^[0-3]$/.test(info.WrapStyle) ? info.WrapStyle * 1 : 2,
Object.keys(s).forEach(function (key) {
if (key !== 'Name' && key !== 'Fontname' && !/Colour/.test(key)) {
s[key] *= 1;
}
});
var ref$1 = parseStyleColor(s.PrimaryColour);
var a1 = ref$1[0];
var c1 = ref$1[1];
var ref$2 = parseStyleColor(s.SecondaryColour);
var a2 = ref$2[0];
var c2 = ref$2[1];
var ref$3 = parseStyleColor(s.OutlineColour);
var a3 = ref$3[0];
var c3 = ref$3[1];
var ref$4 = parseStyleColor(s.BackColour);
var a4 = ref$4[0];
var c4 = ref$4[1];
var tag = {
fn: s.Fontname,
fs: s.Fontsize,
c1: c1,
a1: a1,
c2: c2,
a2: a2,
c3: c3,
a3: a3,
c4: c4,
a4: a4,
b: Math.abs(s.Bold),
i: Math.abs(s.Italic),
u: Math.abs(s.Underline),
s: Math.abs(s.StrikeOut),
fscx: s.ScaleX,
fscy: s.ScaleY,
fsp: s.Spacing,
frz: s.Angle,
xbord: s.Outline,
ybord: s.Outline,
xshad: s.Shadow,
yshad: s.Shadow,
q: /^[0-3]$/.test(info.WrapStyle) ? info.WrapStyle * 1 : 2,
};
result[s.Name] = { style: s, tag: tag };
};
result[s.Name] = { style: s, tag: tag };
};
for (var i = 0; i < styles.length; i++) loop( i );
return result;
}
for (var i = 0; i < styles.length; i++) loop( i );
return result;
}
function compile(text, options) {
if ( options === void 0 ) options = {};
function compile(text, options) {
if ( options === void 0 ) options = {};
var tree = parse(text);
var styles = compileStyles({
info: tree.info,
style: tree.styles.style,
format: tree.styles.format,
defaultStyle: options.defaultStyle || {},
});
return {
info: tree.info,
width: tree.info.PlayResX * 1 || null,
height: tree.info.PlayResY * 1 || null,
collisions: tree.info.Collisions || 'Normal',
styles: styles,
dialogues: compileDialogues({
var tree = parse(text);
var styles = compileStyles({
info: tree.info,
style: tree.styles.style,
format: tree.styles.format,
defaultStyle: options.defaultStyle || {},
});
return {
info: tree.info,
width: tree.info.PlayResX * 1 || null,
height: tree.info.PlayResY * 1 || null,
collisions: tree.info.Collisions || 'Normal',
styles: styles,
dialogues: tree.events.dialogue,
}),
};
}
dialogues: compileDialogues({
styles: styles,
dialogues: tree.events.dialogue,
}),
};
}
exports.parse = parse;
exports.compile = compile;
exports.parse = parse;
exports.compile = compile;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));

@@ -1,1 +0,1 @@

(function(t,r){typeof exports==="object"&&typeof module!=="undefined"?r(exports):typeof define==="function"&&define.amd?define(["exports"],r):r(t.assCompiler={})})(this,function(t){"use strict";function r(t){var r=t.toLowerCase().trim().split(/\s*;\s*/);if(r[0]==="banner"){return{name:r[0],delay:r[1]*1||0,leftToRight:r[2]*1||0,fadeAwayWidth:r[3]*1||0}}if(/^scroll\s/.test(r[0])){return{name:r[0],y1:Math.min(r[1]*1,r[2]*1),y2:Math.max(r[1]*1,r[2]*1),delay:r[3]*1||0,fadeAwayHeight:r[4]*1||0}}return null}function a(t){return t.toLowerCase().replace(/([mnlbspc])/g," $1 ").trim().replace(/\s+/g," ").split(/\s(?=[mnlbspc])/).map(function(t){return t.split(" ")})}var e=["b","i","u","s","fsp","k","K","kf","ko","kt","fe","q","p","pbo","a","an","fscx","fscy","fax","fay","frx","fry","frz","fr","be","blur","bord","xbord","ybord","shad","xshad","yshad"];var n=e.map(function(t){return{name:t,regex:new RegExp("^"+t+"-?\\d")}});function i(t){var r;var e={};for(var s=0;s<n.length;s++){var l=n[s];var f=l.name;var v=l.regex;if(v.test(t)){e[f]=t.slice(f.length)*1;return e}}if(/^fn/.test(t)){e.fn=t.slice(2)}else if(/^r/.test(t)){e.r=t.slice(1)}else if(/^fs[\d+-]/.test(t)){e.fs=t.slice(2)}else if(/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(t)){var o=t.match(/^(\d?)c&?H?(\w*)/);var c=o[1];var u=o[2];e["c"+(c||1)]=u&&("000000"+u).slice(-6)}else if(/^\da&?H?[0-9a-f]+/i.test(t)){var p=t.match(/^(\d)a&?H?(\w\w)/);var d=p[1];var y=p[2];e["a"+d]=y}else if(/^alpha&?H?[0-9a-f]+/i.test(t)){r=t.match(/^alpha&?H?([0-9a-f]+)/i),e.alpha=r[1];e.alpha=("00"+e.alpha).slice(-2)}else if(/^(?:pos|org|move|fad|fade)\(/.test(t)){var g=t.match(/^(\w+)\((.*?)\)?$/);var h=g[1];var m=g[2];e[h]=m.trim().split(/\s*,\s*/).map(Number)}else if(/^i?clip/.test(t)){var x=t.match(/^i?clip\((.*?)\)?$/)[1].trim().split(/\s*,\s*/);e.clip={inverse:/iclip/.test(t),scale:1,drawing:null,dots:null};if(x.length===1){e.clip.drawing=a(x[0])}if(x.length===2){e.clip.scale=x[0]*1;e.clip.drawing=a(x[1])}if(x.length===4){e.clip.dots=x.map(Number)}}else if(/^t\(/.test(t)){var b=t.match(/^t\((.*?)\)?$/)[1].trim().replace(/\\.*/,function(t){return t.replace(/,/g,"\n")}).split(/\s*,\s*/);if(!b[0]){return e}e.t={t1:0,t2:0,accel:1,tags:b[b.length-1].replace(/\n/g,",").split("\\").slice(1).map(i)};if(b.length===2){e.t.accel=b[0]*1}if(b.length===3){e.t.t1=b[0]*1;e.t.t2=b[1]*1}if(b.length===4){e.t.t1=b[0]*1;e.t.t2=b[1]*1;e.t.accel=b[2]*1}}return e}function s(t){var r=[];var a=0;var e="";for(var n=0;n<t.length;n++){var s=t[n];if(s==="("){a++}if(s===")"){a--}if(a<0){a=0}if(!a&&s==="\\"){if(e){r.push(e)}e=""}else{e+=s}}r.push(e);return r.map(i)}function l(t){var r=t.split(/{([^{}]*?)}/);var e=[];if(r[0].length){e.push({tags:[],text:r[0],drawing:[]})}for(var n=1;n<r.length;n+=2){var i=s(r[n]);var l=i.reduce(function(t,r){return r.p===undefined?t:!!r.p},false);e.push({tags:i,text:l?"":r[n+1],drawing:l?a(r[n+1]):[]})}return{raw:t,combined:e.map(function(t){return t.text}).join(""),parsed:e}}function f(t){var r=t.split(":");return r[0]*3600+r[1]*60+r[2]*1}function v(t,a){var e=t.split(",");if(e.length>a.length){var n=e.slice(a.length-1).join();e=e.slice(0,a.length-1);e.push(n)}var i={};for(var s=0;s<e.length;s++){var v=a[s];var o=e[s].trim();switch(v){case"Layer":case"MarginL":case"MarginR":case"MarginV":i[v]=o*1;break;case"Start":case"End":i[v]=f(o);break;case"Effect":i[v]=r(o);break;case"Text":i[v]=l(o);break;default:i[v]=o}}return i}function o(t){return t.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function c(t){return t.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function u(t){var r={info:{},styles:{format:[],style:[]},events:{format:[],comment:[],dialogue:[]}};var a=t.split(/\r?\n/);var e=0;for(var n=0;n<a.length;n++){var i=a[n].trim();if(/^;/.test(i)){continue}if(/^\[Script Info\]/i.test(i)){e=1}else if(/^\[V4\+? Styles\]/i.test(i)){e=2}else if(/^\[Events\]/i.test(i)){e=3}else if(/^\[.*\]/.test(i)){e=0}if(e===0){continue}if(e===1){if(/:/.test(i)){var s=i.match(/(.*?)\s*:\s*(.*)/);var l=s[1];var f=s[2];r.info[l]=f}}if(e===2){if(/^Format\s*:/i.test(i)){r.styles.format=o(i)}if(/^Style\s*:/i.test(i)){r.styles.style.push(c(i))}}if(e===3){if(/^Format\s*:/i.test(i)){r.events.format=o(i)}if(/^(?:Comment|Dialogue)\s*:/i.test(i)){var u=i.match(/^(\w+?)\s*:\s*(.*)/i);var p=u[1];var d=u[2];r.events[p.toLowerCase()].push(v(d,r.events.format))}}}return r}var p=Object.assign||function t(r){var a=[],e=arguments.length-1;while(e-- >0)a[e]=arguments[e+1];for(var n=0;n<a.length;n++){if(!a[n]){continue}var i=Object.keys(a[n]);for(var s=0;s<i.length;s++){r[i[s]]=a[n][i[s]]}}return r};function d(t){var r={type:null,prev:null,next:null,points:[]};if(/[mnlbs]/.test(t[0])){r.type=t[0].toUpperCase().replace("N","L").replace("B","C")}for(var a=t.length-!(t.length&1),e=1;e<a;e+=2){r.points.push({x:t[e]*1,y:t[e+1]*1})}return r}function y(t){if(!t.points.length||!t.type){return false}if(/C|S/.test(t.type)&&t.points.length<3){return false}return true}function g(t){var r;var a=Infinity;var e=Infinity;var n=-Infinity;var i=-Infinity;(r=[]).concat.apply(r,t.map(function(t){var r=t.points;return r})).forEach(function(t){var r=t.x;var s=t.y;a=Math.min(a,r);e=Math.min(e,s);n=Math.max(n,r);i=Math.max(i,s)});return{minX:a,minY:e,width:n-a,height:i-e}}function h(t,r,a){var e=[];var n=[0,2/3,1/3,0];var i=[0,1/3,2/3,0];var s=[0,1/6,2/3,1/6];var l=function(t,r){return t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3]};var f=[t[t.length-1].x,t[0].x,t[1].x,t[2].x];var v=[t[t.length-1].y,t[0].y,t[1].y,t[2].y];e.push({type:r==="M"?"M":"L",points:[{x:l(s,f),y:l(s,v)}]});for(var o=3;o<t.length;o++){f=[t[o-3].x,t[o-2].x,t[o-1].x,t[o].x];v=[t[o-3].y,t[o-2].y,t[o-1].y,t[o].y];e.push({type:"C",points:[{x:l(n,f),y:l(n,v)},{x:l(i,f),y:l(i,v)},{x:l(s,f),y:l(s,v)}]})}if(a==="L"||a==="C"){var c=t[t.length-1];e.push({type:"L",points:[{x:c.x,y:c.y}]})}return e}function m(t){return t.map(function(t){var r=t.type;var a=t.points;return r+a.map(function(t){var r=t.x;var a=t.y;return r+","+a}).join(",")}).join("")}function x(t){var r;var a=[];var e=0;while(e<t.length){var n=t[e];var i=d(n);if(i.type){if(i.type==="S"){var s=a[e-1].points.slice(-1)[0];var l=s.x;var f=s.y;i.points.unshift({x:l,y:f})}if(y(i)){if(e){i.prev=a[e-1].type;a[e-1].next=i.type}a.push(i)}e++}else{if(a[e-1].type==="S"){var v={p:i.points,c:a[e-1].points.slice(0,3)};a[e-1].points=a[e-1].points.concat((v[n[0]]||[]).map(function(t){var r=t.x;var a=t.y;return{x:r,y:a}}))}t.splice(e,1)}}var o=(r=[]).concat.apply(r,a.map(function(t){var r=t.type;var a=t.points;var e=t.prev;var n=t.next;return r==="S"?h(a,e,n):{type:r,points:a}}));return p({instructions:o,d:m(o)},g(a))}var b=["fs","clip","c1","c2","c3","c4","a1","a2","a3","a4","alpha","fscx","fscy","fax","fay","frx","fry","frz","fr","be","blur","bord","xbord","ybord","shad","xshad","yshad"];function S(t,r,a){var e,n,i;if(a===void 0)a={};var s=t[r];if(s===undefined){return null}if(r==="pos"||r==="org"){return s.length===2?(e={},e[r]={x:s[0],y:s[1]},e):null}if(r==="move"){var l=s[0];var f=s[1];var v=s[2];var o=s[3];var c=s[4];if(c===void 0)c=0;var u=s[5];if(u===void 0)u=0;return s.length===4||s.length===6?{move:{x1:l,y1:f,x2:v,y2:o,t1:c,t2:u}}:null}if(r==="fad"||r==="fade"){if(s.length===2){var d=s[0];var y=s[1];return{fade:{type:"fad",t1:d,t2:y}}}if(s.length===7){var g=s[0];var h=s[1];var m=s[2];var w=s[3];var M=s[4];var C=s[5];var O=s[6];return{fade:{type:"fade",a1:g,a2:h,a3:m,t1:w,t2:M,t3:C,t4:O}}}return null}if(r==="clip"){var k=s.inverse;var F=s.scale;var L=s.drawing;var j=s.dots;if(L){return{clip:{inverse:k,scale:F,drawing:x(L),dots:j}}}if(j){var E=j[0];var H=j[1];var N=j[2];var $=j[3];return{clip:{inverse:k,scale:F,drawing:L,dots:{x1:E,y1:H,x2:N,y2:$}}}}return null}if(/^[xy]?(bord|shad)$/.test(r)){s=Math.max(s,0)}if(r==="bord"){return{xbord:s,ybord:s}}if(r==="shad"){return{xshad:s,yshad:s}}if(/^c\d$/.test(r)){return n={},n[r]=s||a[r],n}if(r==="alpha"){return{a1:s,a2:s,a3:s,a4:s}}if(r==="fr"){return{frz:s}}if(r==="fs"){return{fs:/^\+|-/.test(s)?(s*1>-10?1+s/10:1)*a.fs:s*1}}if(r==="t"){var I=s.t1;var R=s.accel;var A=s.tags;var B=s.t2||(a.end-a.start)*1e3;var z={};A.forEach(function(t){var r=Object.keys(t)[0];if(~b.indexOf(r)&&!(r==="clip"&&!t[r].dots)){p(z,S(t,r,a))}});return{t:{t1:I,t2:B,accel:R,tag:z}}}return i={},i[r]=s,i}var w=[null,1,2,3,null,7,8,9,null,4,5,6];var M=["r","a","an","pos","org","move","fade","fad","clip"];function C(t,r){return{name:t,borderStyle:r[t].style.BorderStyle,tag:r[t].tag,fragments:[]}}function O(t){var r=t.styles;var a=t.name;var e=t.parsed;var n=t.start;var i=t.end;var s;var l;var f;var v;var o;var c;var u=[];var d=C(a,r);var y={};for(var g=0;g<e.length;g++){var h=e[g];var m=h.tags;var b=h.text;var O=h.drawing;var k=void 0;for(var F=0;F<m.length;F++){var L=m[F];k=L.r===undefined?k:L.r}var j={tag:k===undefined?JSON.parse(JSON.stringify(y)):{},text:b,drawing:O.length?x(O):null};for(var E=0;E<m.length;E++){var H=m[E];s=s||w[H.a||0]||H.an;l=l||S(H,"pos");f=f||S(H,"org");v=v||S(H,"move");o=o||S(H,"fade")||S(H,"fad");c=S(H,"clip")||c;var N=Object.keys(H)[0];if(N&&!~M.indexOf(N)){var $=d.tag;var I=$.c1;var R=$.c2;var A=$.c3;var B=$.c4;var z=y.fs||d.tag.fs;var D=S(H,N,{start:n,end:i,c1:I,c2:R,c3:A,c4:B,fs:z});if(N==="t"){j.tag.t=j.tag.t||[];j.tag.t.push(D.t)}else{p(j.tag,D)}}}y=j.tag;if(k!==undefined){u.push(d);d=C(r[k]?k:a,r)}if(j.text||j.drawing){var P=d.fragments[d.fragments.length-1]||{};if(P.text&&j.text&&!Object.keys(j.tag).length){P.text+=j.text}else{d.fragments.push(j)}}}u.push(d);return p({alignment:s,slices:u},l,f,v,o,c)}function k(t){var r=t.styles;var a=t.dialogues;var e=Infinity;var n=[];for(var i=0;i<a.length;i++){var s=a[i];if(s.Start>=s.End){continue}if(!r[s.Style]){s.Style="Default"}var l=r[s.Style].style;var f=O({styles:r,name:s.Style,parsed:s.Text.parsed,start:s.Start,end:s.End});var v=f.alignment||l.Alignment;e=Math.min(e,s.Layer);n.push(p({layer:s.Layer,start:s.Start,end:s.End,margin:{left:s.MarginL||l.MarginL,right:s.MarginR||l.MarginR,vertical:s.MarginV||l.MarginV},effect:s.Effect},f,{alignment:v}))}for(var o=0;o<n.length;o++){n[o].layer-=e}return n.sort(function(t,r){return t.start-r.start||t.end-r.end})}var F={Name:"Default",Fontname:"Arial",Fontsize:"20",PrimaryColour:"&H00FFFFFF&",SecondaryColour:"&H000000FF&",OutlineColour:"&H00000000&",BackColour:"&H00000000&",Bold:"0",Italic:"0",Underline:"0",StrikeOut:"0",ScaleX:"100",ScaleY:"100",Spacing:"0",Angle:"0",BorderStyle:"1",Outline:"2",Shadow:"2",Alignment:"2",MarginL:"10",MarginR:"10",MarginV:"10",Encoding:"1"};function L(t){var r=t.match(/&H(\w\w)?(\w{6})&?/);var a=r[1];var e=r[2];return[a||"00",e]}function j(t){var r=t.info;var a=t.style;var e=t.format;var n=t.defaultStyle;var i={};var s=[p({},F,n,{Name:"Default"})].concat(a.map(function(t){var r={};for(var a=0;a<e.length;a++){r[e[a]]=t[a]}return r}));var l=function(t){var a=s[t];if(/^(\*+)Default$/.test(a.Name)){a.Name="Default"}Object.keys(a).forEach(function(t){if(t!=="Name"&&t!=="Fontname"&&!/Colour/.test(t)){a[t]*=1}});var e=L(a.PrimaryColour);var n=e[0];var l=e[1];var f=L(a.SecondaryColour);var v=f[0];var o=f[1];var c=L(a.OutlineColour);var u=c[0];var p=c[1];var d=L(a.BackColour);var y=d[0];var g=d[1];var h={fn:a.Fontname,fs:a.Fontsize,c1:l,a1:n,c2:o,a2:v,c3:p,a3:u,c4:g,a4:y,b:Math.abs(a.Bold),i:Math.abs(a.Italic),u:Math.abs(a.Underline),s:Math.abs(a.StrikeOut),fscx:a.ScaleX,fscy:a.ScaleY,fsp:a.Spacing,frz:a.Angle,xbord:a.Outline,ybord:a.Outline,xshad:a.Shadow,yshad:a.Shadow,q:/^[0-3]$/.test(r.WrapStyle)?r.WrapStyle*1:2};i[a.Name]={style:a,tag:h}};for(var f=0;f<s.length;f++)l(f);return i}function E(t,r){if(r===void 0)r={};var a=u(t);var e=j({info:a.info,style:a.styles.style,format:a.styles.format,defaultStyle:r.defaultStyle||{}});return{info:a.info,width:a.info.PlayResX*1||null,height:a.info.PlayResY*1||null,collisions:a.info.Collisions||"Normal",styles:e,dialogues:k({styles:e,dialogues:a.events.dialogue})}}t.parse=u;t.compile=E;Object.defineProperty(t,"__esModule",{value:true})});
(function(t,r){typeof exports==="object"&&typeof module!=="undefined"?r(exports):typeof define==="function"&&define.amd?define(["exports"],r):r(t.assCompiler={})})(this,function(t){"use strict";function f(t){var r=t.toLowerCase().trim().split(/\s*;\s*/);if(r[0]==="banner"){return{name:r[0],delay:r[1]*1||0,leftToRight:r[2]*1||0,fadeAwayWidth:r[3]*1||0}}if(/^scroll\s/.test(r[0])){return{name:r[0],y1:Math.min(r[1]*1,r[2]*1),y2:Math.max(r[1]*1,r[2]*1),delay:r[3]*1||0,fadeAwayHeight:r[4]*1||0}}return null}function m(t){return t.toLowerCase().replace(/([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)/g," $1 ").replace(/([mnlbspc])/g," $1 ").trim().replace(/\s+/g," ").split(/\s(?=[mnlbspc])/).map(function(t){return t.split(" ").filter(function(t,r){return!(r&&isNaN(t*1))})})}var r=["b","i","u","s","fsp","k","K","kf","ko","kt","fe","q","p","pbo","a","an","fscx","fscy","fax","fay","frx","fry","frz","fr","be","blur","bord","xbord","ybord","shad","xshad","yshad"];var x=r.map(function(t){return{name:t,regex:new RegExp("^"+t+"-?\\d")}});function b(t){var r;var a={};for(var e=0;e<x.length;e++){var n=x[e];var i=n.name;var s=n.regex;if(s.test(t)){a[i]=t.slice(i.length)*1;return a}}if(/^fn/.test(t)){a.fn=t.slice(2)}else if(/^r/.test(t)){a.r=t.slice(1)}else if(/^fs[\d+-]/.test(t)){a.fs=t.slice(2)}else if(/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(t)){var l=t.match(/^(\d?)c&?H?(\w*)/);var f=l[1];var o=l[2];a["c"+(f||1)]=o&&("000000"+o).slice(-6)}else if(/^\da&?H?[0-9a-f]+/i.test(t)){var v=t.match(/^(\d)a&?H?(\w\w)/);var c=v[1];var u=v[2];a["a"+c]=u}else if(/^alpha&?H?[0-9a-f]+/i.test(t)){r=t.match(/^alpha&?H?([0-9a-f]+)/i),a.alpha=r[1];a.alpha=("00"+a.alpha).slice(-2)}else if(/^(?:pos|org|move|fad|fade)\(/.test(t)){var p=t.match(/^(\w+)\((.*?)\)?$/);var d=p[1];var g=p[2];a[d]=g.trim().split(/\s*,\s*/).map(Number)}else if(/^i?clip/.test(t)){var y=t.match(/^i?clip\((.*?)\)?$/)[1].trim().split(/\s*,\s*/);a.clip={inverse:/iclip/.test(t),scale:1,drawing:null,dots:null};if(y.length===1){a.clip.drawing=m(y[0])}if(y.length===2){a.clip.scale=y[0]*1;a.clip.drawing=m(y[1])}if(y.length===4){a.clip.dots=y.map(Number)}}else if(/^t\(/.test(t)){var h=t.match(/^t\((.*?)\)?$/)[1].trim().replace(/\\.*/,function(t){return t.replace(/,/g,"\n")}).split(/\s*,\s*/);if(!h[0]){return a}a.t={t1:0,t2:0,accel:1,tags:h[h.length-1].replace(/\n/g,",").split("\\").slice(1).map(b)};if(h.length===2){a.t.accel=h[0]*1}if(h.length===3){a.t.t1=h[0]*1;a.t.t2=h[1]*1}if(h.length===4){a.t.t1=h[0]*1;a.t.t2=h[1]*1;a.t.accel=h[2]*1}}return a}function s(t){var r=[];var a=0;var e="";for(var n=0;n<t.length;n++){var i=t[n];if(i==="("){a++}if(i===")"){a--}if(a<0){a=0}if(!a&&i==="\\"){if(e){r.push(e)}e=""}else{e+=i}}r.push(e);return r.map(b)}function o(t){var r=t.split(/{([^{}]*?)}/);var a=[];if(r[0].length){a.push({tags:[],text:r[0],drawing:[]})}for(var e=1;e<r.length;e+=2){var n=s(r[e]);var i=n.reduce(function(t,r){return r.p===undefined?t:!!r.p},false);a.push({tags:n,text:i?"":r[e+1],drawing:i?m(r[e+1]):[]})}return{raw:t,combined:a.map(function(t){return t.text}).join(""),parsed:a}}function v(t){var r=t.split(":");return r[0]*3600+r[1]*60+r[2]*1}function u(t,r){var a=t.split(",");if(a.length>r.length){var e=a.slice(r.length-1).join();a=a.slice(0,r.length-1);a.push(e)}var n={};for(var i=0;i<a.length;i++){var s=r[i];var l=a[i].trim();switch(s){case"Layer":case"MarginL":case"MarginR":case"MarginV":n[s]=l*1;break;case"Start":case"End":n[s]=v(l);break;case"Effect":n[s]=f(l);break;case"Text":n[s]=o(l);break;default:n[s]=l}}return n}function p(t){return t.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function d(t){return t.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function n(t){var r={info:{},styles:{format:[],style:[]},events:{format:[],comment:[],dialogue:[]}};var a=t.split(/\r?\n/);var e=0;for(var n=0;n<a.length;n++){var i=a[n].trim();if(/^;/.test(i)){continue}if(/^\[Script Info\]/i.test(i)){e=1}else if(/^\[V4\+? Styles\]/i.test(i)){e=2}else if(/^\[Events\]/i.test(i)){e=3}else if(/^\[.*\]/.test(i)){e=0}if(e===0){continue}if(e===1){if(/:/.test(i)){var s=i.match(/(.*?)\s*:\s*(.*)/);var l=s[1];var f=s[2];r.info[l]=f}}if(e===2){if(/^Format\s*:/i.test(i)){r.styles.format=p(i)}if(/^Style\s*:/i.test(i)){r.styles.style.push(d(i))}}if(e===3){if(/^Format\s*:/i.test(i)){r.events.format=p(i)}if(/^(?:Comment|Dialogue)\s*:/i.test(i)){var o=i.match(/^(\w+?)\s*:\s*(.*)/i);var v=o[1];var c=o[2];r.events[v.toLowerCase()].push(u(c,r.events.format))}}}return r}var R=Object.assign||function t(r){var a=[],e=arguments.length-1;while(e-- >0)a[e]=arguments[e+1];for(var n=0;n<a.length;n++){if(!a[n]){continue}var i=Object.keys(a[n]);for(var s=0;s<i.length;s++){r[i[s]]=a[n][i[s]]}}return r};function c(t){var r={type:null,prev:null,next:null,points:[]};if(/[mnlbs]/.test(t[0])){r.type=t[0].toUpperCase().replace("N","L").replace("B","C")}for(var a=t.length-!(t.length&1),e=1;e<a;e+=2){r.points.push({x:t[e]*1,y:t[e+1]*1})}return r}function g(t){if(!t.points.length||!t.type){return false}if(/C|S/.test(t.type)&&t.points.length<3){return false}return true}function y(t){var r;var e=Infinity;var n=Infinity;var i=-Infinity;var s=-Infinity;(r=[]).concat.apply(r,t.map(function(t){var r=t.points;return r})).forEach(function(t){var r=t.x;var a=t.y;e=Math.min(e,r);n=Math.min(n,a);i=Math.max(i,r);s=Math.max(s,a)});return{minX:e,minY:n,width:i-e,height:s-n}}function h(t,r,a){var e=[];var n=[0,2/3,1/3,0];var i=[0,1/3,2/3,0];var s=[0,1/6,2/3,1/6];var l=function(t,r){return t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3]};var f=[t[t.length-1].x,t[0].x,t[1].x,t[2].x];var o=[t[t.length-1].y,t[0].y,t[1].y,t[2].y];e.push({type:r==="M"?"M":"L",points:[{x:l(s,f),y:l(s,o)}]});for(var v=3;v<t.length;v++){f=[t[v-3].x,t[v-2].x,t[v-1].x,t[v].x];o=[t[v-3].y,t[v-2].y,t[v-1].y,t[v].y];e.push({type:"C",points:[{x:l(n,f),y:l(n,o)},{x:l(i,f),y:l(i,o)},{x:l(s,f),y:l(s,o)}]})}if(a==="L"||a==="C"){var c=t[t.length-1];e.push({type:"L",points:[{x:c.x,y:c.y}]})}return e}function S(t){return t.map(function(t){var r=t.type;var a=t.points;return r+a.map(function(t){var r=t.x;var a=t.y;return r+","+a}).join(",")}).join("")}function A(t){var r;var a=[];var e=0;while(e<t.length){var n=t[e];var i=c(n);if(g(i)){if(i.type==="S"){var s=(a[e-1]||{points:[{x:0,y:0}]}).points.slice(-1)[0];var l=s.x;var f=s.y;i.points.unshift({x:l,y:f})}if(e){i.prev=a[e-1].type;a[e-1].next=i.type}a.push(i);e++}else{if(e&&a[e-1].type==="S"){var o={p:i.points,c:a[e-1].points.slice(0,3)};a[e-1].points=a[e-1].points.concat((o[n[0]]||[]).map(function(t){var r=t.x;var a=t.y;return{x:r,y:a}}))}t.splice(e,1)}}var v=(r=[]).concat.apply(r,a.map(function(t){var r=t.type;var a=t.points;var e=t.prev;var n=t.next;return r==="S"?h(a,e,n):{type:r,points:a}}));return R({instructions:v,d:S(v)},y(a))}var B=["fs","clip","c1","c2","c3","c4","a1","a2","a3","a4","alpha","fscx","fscy","fax","fay","frx","fry","frz","fr","be","blur","bord","xbord","ybord","shad","xshad","yshad"];function z(t,r,a){var e,n,i;if(a===void 0)a={};var s=t[r];if(s===undefined){return null}if(r==="pos"||r==="org"){return s.length===2?(e={},e[r]={x:s[0],y:s[1]},e):null}if(r==="move"){var l=s[0];var f=s[1];var o=s[2];var v=s[3];var c=s[4];if(c===void 0)c=0;var u=s[5];if(u===void 0)u=0;return s.length===4||s.length===6?{move:{x1:l,y1:f,x2:o,y2:v,t1:c,t2:u}}:null}if(r==="fad"||r==="fade"){if(s.length===2){var p=s[0];var d=s[1];return{fade:{type:"fad",t1:p,t2:d}}}if(s.length===7){var g=s[0];var y=s[1];var h=s[2];var m=s[3];var x=s[4];var b=s[5];var S=s[6];return{fade:{type:"fade",a1:g,a2:y,a3:h,t1:m,t2:x,t3:b,t4:S}}}return null}if(r==="clip"){var w=s.inverse;var M=s.scale;var C=s.drawing;var O=s.dots;if(C){return{clip:{inverse:w,scale:M,drawing:A(C),dots:O}}}if(O){var k=O[0];var F=O[1];var L=O[2];var N=O[3];return{clip:{inverse:w,scale:M,drawing:C,dots:{x1:k,y1:F,x2:L,y2:N}}}}return null}if(/^[xy]?(bord|shad)$/.test(r)){s=Math.max(s,0)}if(r==="bord"){return{xbord:s,ybord:s}}if(r==="shad"){return{xshad:s,yshad:s}}if(/^c\d$/.test(r)){return n={},n[r]=s||a[r],n}if(r==="alpha"){return{a1:s,a2:s,a3:s,a4:s}}if(r==="fr"){return{frz:s}}if(r==="fs"){return{fs:/^\+|-/.test(s)?(s*1>-10?1+s/10:1)*a.fs:s*1}}if(r==="t"){var j=s.t1;var E=s.accel;var H=s.tags;var $=s.t2||(a.end-a.start)*1e3;var I={};H.forEach(function(t){var r=Object.keys(t)[0];if(~B.indexOf(r)&&!(r==="clip"&&!t[r].dots)){R(I,z(t,r,a))}});return{t:{t1:j,t2:$,accel:E,tag:I}}}return i={},i[r]=s,i}var D=[null,1,2,3,null,7,8,9,null,4,5,6];var P=["r","a","an","pos","org","move","fade","fad","clip"];function V(t,r){return{name:t,borderStyle:r[t].style.BorderStyle,tag:r[t].tag,fragments:[]}}function w(t){var r=t.styles;var a=t.name;var e=t.parsed;var n=t.start;var i=t.end;var s;var l;var f;var o;var v;var c;var u=[];var p=V(a,r);var d={};for(var g=0;g<e.length;g++){var y=e[g];var h=y.tags;var m=y.text;var x=y.drawing;var b=void 0;for(var S=0;S<h.length;S++){var w=h[S];b=w.r===undefined?b:w.r}var M={tag:b===undefined?JSON.parse(JSON.stringify(d)):{},text:m,drawing:x.length?A(x):null};for(var C=0;C<h.length;C++){var O=h[C];s=s||D[O.a||0]||O.an;l=l||z(O,"pos");f=f||z(O,"org");o=o||z(O,"move");v=v||z(O,"fade")||z(O,"fad");c=z(O,"clip")||c;var k=Object.keys(O)[0];if(k&&!~P.indexOf(k)){var F=p.tag;var L=F.c1;var N=F.c2;var j=F.c3;var E=F.c4;var H=d.fs||p.tag.fs;var $=z(O,k,{start:n,end:i,c1:L,c2:N,c3:j,c4:E,fs:H});if(k==="t"){M.tag.t=M.tag.t||[];M.tag.t.push($.t)}else{R(M.tag,$)}}}d=M.tag;if(b!==undefined){u.push(p);p=V(r[b]?b:a,r)}if(M.text||M.drawing){var I=p.fragments[p.fragments.length-1]||{};if(I.text&&M.text&&!Object.keys(M.tag).length){I.text+=M.text}else{p.fragments.push(M)}}}u.push(p);return R({alignment:s,slices:u},l,f,o,v,c)}function i(t){var r=t.styles;var a=t.dialogues;var e=Infinity;var n=[];for(var i=0;i<a.length;i++){var s=a[i];if(s.Start>=s.End){continue}if(!r[s.Style]){s.Style="Default"}var l=r[s.Style].style;var f=w({styles:r,name:s.Style,parsed:s.Text.parsed,start:s.Start,end:s.End});var o=f.alignment||l.Alignment;e=Math.min(e,s.Layer);n.push(R({layer:s.Layer,start:s.Start,end:s.End,margin:{left:s.MarginL||l.MarginL,right:s.MarginR||l.MarginR,vertical:s.MarginV||l.MarginV},effect:s.Effect},f,{alignment:o}))}for(var v=0;v<n.length;v++){n[v].layer-=e}return n.sort(function(t,r){return t.start-r.start||t.end-r.end})}var l={Name:"Default",Fontname:"Arial",Fontsize:"20",PrimaryColour:"&H00FFFFFF&",SecondaryColour:"&H000000FF&",OutlineColour:"&H00000000&",BackColour:"&H00000000&",Bold:"0",Italic:"0",Underline:"0",StrikeOut:"0",ScaleX:"100",ScaleY:"100",Spacing:"0",Angle:"0",BorderStyle:"1",Outline:"2",Shadow:"2",Alignment:"2",MarginL:"10",MarginR:"10",MarginV:"10",Encoding:"1"};function M(t){var r=t.match(/&H(\w\w)?(\w{6})&?/);var a=r[1];var e=r[2];return[a||"00",e]}function C(t){var g=t.info;var r=t.style;var e=t.format;var a=t.defaultStyle;var y={};var h=[R({},l,a,{Name:"Default"})].concat(r.map(function(t){var r={};for(var a=0;a<e.length;a++){r[e[a]]=t[a]}return r}));var n=function(t){var r=h[t];if(/^(\*+)Default$/.test(r.Name)){r.Name="Default"}Object.keys(r).forEach(function(t){if(t!=="Name"&&t!=="Fontname"&&!/Colour/.test(t)){r[t]*=1}});var a=M(r.PrimaryColour);var e=a[0];var n=a[1];var i=M(r.SecondaryColour);var s=i[0];var l=i[1];var f=M(r.OutlineColour);var o=f[0];var v=f[1];var c=M(r.BackColour);var u=c[0];var p=c[1];var d={fn:r.Fontname,fs:r.Fontsize,c1:n,a1:e,c2:l,a2:s,c3:v,a3:o,c4:p,a4:u,b:Math.abs(r.Bold),i:Math.abs(r.Italic),u:Math.abs(r.Underline),s:Math.abs(r.StrikeOut),fscx:r.ScaleX,fscy:r.ScaleY,fsp:r.Spacing,frz:r.Angle,xbord:r.Outline,ybord:r.Outline,xshad:r.Shadow,yshad:r.Shadow,q:/^[0-3]$/.test(g.WrapStyle)?g.WrapStyle*1:2};y[r.Name]={style:r,tag:d}};for(var i=0;i<h.length;i++)n(i);return y}function a(t,r){if(r===void 0)r={};var a=n(t);var e=C({info:a.info,style:a.styles.style,format:a.styles.format,defaultStyle:r.defaultStyle||{}});return{info:a.info,width:a.info.PlayResX*1||null,height:a.info.PlayResY*1||null,collisions:a.info.Collisions||"Normal",styles:e,dialogues:i({styles:e,dialogues:a.events.dialogue})}}t.parse=n;t.compile=a;Object.defineProperty(t,"__esModule",{value:true})});
{
"name": "ass-compiler",
"version": "0.0.8",
"version": "0.0.9",
"description": "Parses and compiles ASS subtitle format to easy-to-use data structure.",

@@ -17,2 +17,3 @@ "main": "dist/ass-compiler.js",

"test": "npm run lint && npm run unit && npm run cover",
"dev": "rollup -c -w",
"bundle": "rollup -c",

@@ -44,15 +45,16 @@ "minify": "uglifyjs dist/ass-compiler.js -m -o dist/ass-compiler.min.js",

"chai": "^4.1.2",
"cross-env": "^5.1.3",
"eslint": "^4.18.1",
"cross-env": "^5.1.4",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-import": "^2.10.0",
"istanbul": "^0.4.5",
"mocha": "^5.0.1",
"mocha": "^5.0.5",
"mocha-istanbul": "^0.3.0",
"rollup": "^0.56.3",
"rollup": "^0.57.1",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-multi-entry": "^2.0.2",
"uglify-js": "^3.3.12"
"rollup-plugin-replace": "^2.0.0",
"uglify-js": "^3.3.18"
}
}

@@ -102,17 +102,15 @@ import { assign } from '../utils.js';

const cmd = createCommand(arr);
if (cmd.type) {
if (isValid(cmd)) {
if (cmd.type === 'S') {
const { x, y } = commands[i - 1].points.slice(-1)[0];
const { x, y } = (commands[i - 1] || { points: [{ x: 0, y: 0 }] }).points.slice(-1)[0];
cmd.points.unshift({ x, y });
}
if (isValid(cmd)) {
if (i) {
cmd.prev = commands[i - 1].type;
commands[i - 1].next = cmd.type;
}
commands.push(cmd);
if (i) {
cmd.prev = commands[i - 1].type;
commands[i - 1].next = cmd.type;
}
commands.push(cmd);
i++;
} else {
if (commands[i - 1].type === 'S') {
if (i && commands[i - 1].type === 'S') {
const additionPoints = {

@@ -119,0 +117,0 @@ p: cmd.points,

export function parseDrawing(text) {
return text
.toLowerCase()
// numbers
.replace(/([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)/g, ' $1 ')
// commands
.replace(/([mnlbspc])/g, ' $1 ')

@@ -8,3 +11,6 @@ .trim()

.split(/\s(?=[mnlbspc])/)
.map(cmd => cmd.split(' '));
.map(cmd => (
cmd.split(' ')
.filter((x, i) => !(i && Number.isNaN(x * 1)))
));
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc