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.2 to 0.0.3

22

dist/ass-compiler.js

@@ -143,4 +143,12 @@ (function (global, factory) {

function parseTags(text) {
var depth = 0;
return text
.replace(/\((?:[^()]+|\([^()]*\))*\)/g, function (x) { return x.replace(/\\/g, '\n'); })
.split('')
.map(function (x) {
if (x === '(') { depth++; }
if (x === ')') { depth--; }
if (depth < 0) { depth = 0; }
return (depth && x === '\\') ? '\n' : x;
})
.join('')
.split(/\\/)

@@ -467,4 +475,5 @@ .slice(1)

function compileTag(tag, key, presets) {
var obj, obj$1, obj$2;
if ( presets === void 0 ) presets = {};
var value = tag[key];

@@ -475,4 +484,3 @@ if (value === undefined) {

if (key === 'pos' || key === 'org') {
return value.length === 2 ? ( obj = {}, obj[key] = { x: value[0], y: value[1] }, obj ) : null;
var obj;
return value.length === 2 ? ( obj = {}, obj[key] = { x: value[0], y: value[1] }, obj) : null;
}

@@ -535,4 +543,3 @@ if (key === 'move') {

if (/^c\d$/.test(key)) {
return ( obj$1 = {}, obj$1[key] = value || presets[key], obj$1 );
var obj$1;
return ( obj$1 = {}, obj$1[key] = value || presets[key], obj$1);
}

@@ -566,4 +573,3 @@ if (key === 'alpha') {

}
return ( obj$2 = {}, obj$2[key] = value, obj$2 );
var obj$2;
return ( obj$2 = {}, obj$2[key] = value, obj$2);
}

@@ -570,0 +576,0 @@

@@ -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"];function n(t){var r={};for(var i=0;i<e.length;i++){var s=e[i];var f=new RegExp("^"+s+"-?\\d");if(f.test(t)){r[s]=t.slice(s.length)*1}}if(/^fn/.test(t)){r.fn=t.slice(2)}if(/^r/.test(t)){r.r=t.slice(1)}if(/^fs[\d+-]/.test(t)){r.fs=t.slice(2)}if(/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(t)){var l=t.match(/^(\d?)c&?H?(\w*)/);var v=l[1];var o=l[2];r["c"+(v||1)]=o&&("000000"+o).slice(-6)}if(/^\da&?H?[0-9a-f]+/i.test(t)){var c=t.match(/^(\d)a&?H?(\w\w)/);var u=c[1];var p=c[2];r["a"+u]=p}if(/^alpha&?H?[0-9a-f]+/i.test(t)){var d;d=t.match(/^alpha&?H?(\w\w)/),r.alpha=d[1]}if(/^(?:pos|org|move|fad|fade)\(/.test(t)){var g=t.match(/^(\w+)\((.*?)\)/);var h=g[1];var y=g[2];r[h]=y.trim().split(/\s*,\s*/).map(Number)}if(/^i?clip/.test(t)){var m=t.match(/^i?clip\((.*)\)/)[1].trim().split(/\s*,\s*/);r.clip={inverse:/iclip/.test(t),scale:1,drawing:null,dots:null};if(m.length===1){r.clip.drawing=a(m[0])}if(m.length===2){r.clip.scale=m[0]*1;r.clip.drawing=a(m[1])}if(m.length===4){r.clip.dots=m.map(Number)}}if(/^t\(/.test(t)){var x=t.match(/^t\((.*)\)/)[1].trim().replace(/\\.*/,function(t){return t.replace(/,/g,"\n")}).split(/\s*,\s*/);if(!x[0]){return r}r.t={t1:0,t2:0,accel:1,tags:x[x.length-1].replace(/\n/g,",").split("\\").slice(1).map(n)};if(x.length===2){r.t.accel=x[0]*1}if(x.length===3){r.t.t1=x[0]*1;r.t.t2=x[1]*1}if(x.length===4){r.t.t1=x[0]*1;r.t.t2=x[1]*1;r.t.accel=x[2]*1}}return r}function i(t){return t.replace(/\((?:[^()]+|\([^()]*\))*\)/g,function(t){return t.replace(/\\/g,"\n")}).split(/\\/).slice(1).map(function(t){return t.replace(/\n/g,"\\")}).map(n)}function s(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 s=i(r[n]);var f=s.reduce(function(t,r){return r.p===undefined?t:!!r.p},false);e.push({tags:s,text:f?"":r[n+1],drawing:f?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 l(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 l=0;l<e.length;l++){var v=a[l];var o=e[l].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]=s(o);break;default:i[v]=o}}return i}function v(t){return t.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function o(t){return t.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function c(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 f=s[1];var c=s[2];r.info[f]=c}}if(e===2){if(/^Format\s*:/i.test(i)){r.styles.format=v(i)}if(/^Style\s*:/i.test(i)){r.styles.style.push(o(i))}}if(e===3){if(/^Format\s*:/i.test(i)){r.events.format=v(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(l(d,r.events.format))}}}return r}function u(t){var r=[],a=arguments.length-1;while(a-- >0)r[a]=arguments[a+1];if(Object.assign){return Object.assign.apply(Object,[t].concat(r))}for(var e=0;e<r.length;e++){if(!r[e]){continue}var n=Object.keys(r[e]);for(var i=0;i<n.length;i++){t[n[i]]=r[e][n[i]]}}return t}function p(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 d(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=Infinity;var a=Infinity;var e=-Infinity;var n=-Infinity;(i=[]).concat.apply(i,t.map(function(t){var r=t.points;return r})).forEach(function(t){var i=t.x;var s=t.y;r=Math.min(r,i);a=Math.min(a,s);e=Math.max(e,i);n=Math.max(n,s)});return{minX:r,minY:a,width:e-r,height:n-a};var i}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 f=function(t,r){return t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3]};var l=[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:f(s,l),y:f(s,v)}]});for(var o=3;o<t.length;o++){l=[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:f(n,l),y:f(n,v)},{x:f(i,l),y:f(i,v)},{x:f(s,l),y:f(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 y(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 m(t){var r=[];var a=0;while(a<t.length){var e=t[a];var n=p(e);if(n.type){if(n.type==="S"){var i=r[a-1].points.slice(-1)[0];var s=i.x;var f=i.y;n.points.unshift({x:s,y:f})}if(d(n)){if(a){n.prev=r[a-1].type;r[a-1].next=n.type}r.push(n)}a++}else{if(r[a-1].type==="S"){var l={p:n.points,c:r[a-1].points.slice(0,3)};r[a-1].points=r[a-1].points.concat((l[e[0]]||[]).map(function(t){var r=t.x;var a=t.y;return{x:r,y:a}}))}t.splice(a,1)}}var v=(o=[]).concat.apply(o,r.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 u({instructions:v,d:y(v)},g(r));var o}var x=["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 b(t,r,a){if(a===void 0)a={};var e=t[r];if(e===undefined){return null}if(r==="pos"||r==="org"){return e.length===2?(n={},n[r]={x:e[0],y:e[1]},n):null;var n}if(r==="move"){var i=e[0];var s=e[1];var f=e[2];var l=e[3];var v=e[4];if(v===void 0)v=0;var o=e[5];if(o===void 0)o=0;return e.length===4||e.length===6?{move:{x1:i,y1:s,x2:f,y2:l,t1:v,t2:o}}:null}if(r==="fad"||r==="fade"){if(e.length===2){var c=e[0];var p=e[1];return{fade:{type:"fad",t1:c,t2:p}}}if(e.length===7){var d=e[0];var g=e[1];var h=e[2];var y=e[3];var w=e[4];var S=e[5];var M=e[6];return{fade:{type:"fade",a1:d,a2:g,a3:h,t1:y,t2:w,t3:S,t4:M}}}return null}if(r==="clip"){var C=e.inverse;var O=e.scale;var k=e.drawing;var j=e.dots;if(k){return{clip:{inverse:C,scale:O,drawing:m(k),dots:j}}}if(j){var L=j[0];var E=j[1];var H=j[2];var N=j[3];return{clip:{inverse:C,scale:O,drawing:k,dots:{x1:L,y1:E,x2:H,y2:N}}}}return null}if(/^[xy]?(bord|shad)$/.test(r)){e=Math.max(e,0)}if(r==="bord"){return{xbord:e,ybord:e}}if(r==="shad"){return{xshad:e,yshad:e}}if(/^c\d$/.test(r)){return I={},I[r]=e||a[r],I;var I}if(r==="alpha"){return{a1:e,a2:e,a3:e,a4:e}}if(r==="fr"){return{frz:e}}if(r==="fs"){return{fs:/^\+|-/.test(e)?(e*1>-10?1+e/10:1)*a.fs:e*1}}if(r==="t"){var R=e.t1;var F=e.accel;var z=e.tags;var $=e.t2||(a.end-a.start)*1e3;var A={};z.forEach(function(t){var r=Object.keys(t)[0];if(~x.indexOf(r)&&!(r==="clip"&&!t[r].dots)){u(A,b(t,r,a))}});return{t:{t1:R,t2:$,accel:F,tag:A}}}return B={},B[r]=e,B;var B}var w=[null,1,2,3,null,7,8,9,null,4,5,6];var S=["r","a","an","pos","org","move","fade","fad","clip"];function M(t,r){return{name:t,borderStyle:r[t].style.BorderStyle,tag:r[t].tag,fragments:[]}}function C(t){var r=t.styles;var a=t.name;var e=t.parsed;var n=t.start;var i=t.end;var s;var f;var l;var v;var o;var c;var p=[];var d=M(a,r);var g={};for(var h=0;h<e.length;h++){var y=e[h];var x=y.tags;var C=y.text;var O=y.drawing;var k=void 0;for(var j=0;j<x.length;j++){var L=x[j];k=L.r===undefined?k:L.r}var E={tag:k===undefined?JSON.parse(JSON.stringify(g)):{},text:C,drawing:O.length?m(O):null};for(var H=0;H<x.length;H++){var N=x[H];s=s||w[N.a||0]||N.an;f=f||b(N,"pos");l=l||b(N,"org");v=v||b(N,"move");o=o||b(N,"fade")||b(N,"fad");c=b(N,"clip")||c;var I=Object.keys(N)[0];if(I&&!~S.indexOf(I)){var R=d.tag;var F=R.c1;var z=R.c2;var $=R.c3;var A=R.c4;var B=g.fs||d.tag.fs;var P=b(N,I,{start:n,end:i,c1:F,c2:z,c3:$,c4:A,fs:B});if(I==="t"){E.tag.t=E.tag.t||[];E.tag.t.push(P.t)}else{u(E.tag,P)}}}g=E.tag;if(k!==undefined){p.push(d);d=M(k||a,r)}if(E.text||E.drawing){var T=d.fragments[d.fragments.length-1]||{};if(T.text&&E.text&&!Object.keys(E.tag).length){T.text+=E.text}else{d.fragments.push(E)}}}p.push(d);return u({alignment:s,slices:p},f,l,v,o,c)}function O(t){var r=t.info;var a=t.styles;var e=t.dialogues;var n=Infinity;var i=[];for(var s=0;s<e.length;s++){var f=e[s];if(f.Start>=f.End){continue}var l=a[f.Style].style;var v=r.Timer/100||1;var o=C({styles:a,name:f.Style,parsed:f.Text.parsed,start:f.Start,end:f.End});var c=o.alignment||l.Alignment;n=Math.min(n,f.Layer);i.push(u({layer:f.Layer,start:f.Start/v,end:f.End/v,margin:{left:f.MarginL||l.MarginL,right:f.MarginR||l.MarginR,vertical:f.MarginV||l.MarginV},effect:f.Effect},o,{alignment:c}))}for(var p=0;p<i.length;p++){i[p].layer-=n}return i.sort(function(t,r){return t.start-r.start||t.end-r.end})}function k(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={};for(var i=0;i<a.length;i++){var s=a[i];var f={};for(var l=0;l<e.length;l++){var v=e[l];f[v]=v==="Name"||v==="Fontname"||/Colour/.test(v)?s[l]:s[l]*1}var o=k(f.PrimaryColour);var c=o[0];var u=o[1];var p=k(f.SecondaryColour);var d=p[0];var g=p[1];var h=k(f.OutlineColour);var y=h[0];var m=h[1];var x=k(f.BackColour);var b=x[0];var w=x[1];var S={fn:f.Fontname,fs:f.Fontsize,c1:u,a1:c,c2:g,a2:d,c3:m,a3:y,c4:w,a4:b,b:Math.abs(f.Bold),i:Math.abs(f.Italic),u:Math.abs(f.Underline),s:Math.abs(f.StrikeOut),fscx:f.ScaleX,fscy:f.ScaleY,fsp:f.Spacing,frz:f.Angle,xbord:f.Outline,ybord:f.Outline,xshad:f.Shadow,yshad:f.Shadow,q:/^[0-3]$/.test(r.WrapStyle)?r.WrapStyle*1:2};n[f.Name]={style:f,tag:S}}return n}function L(t){var r=c(t);var a=j({info:r.info,style:r.styles.style,format:r.styles.format});return{info:r.info,width:r.info.PlayResX*1||null,height:r.info.PlayResY*1||null,collisions:r.info.Collisions||"Normal",styles:a,dialogues:O({info:r.info,styles:a,dialogues:r.events.dialogue})}}t.parse=c;t.compile=L;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 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"];function n(t){var r={};for(var i=0;i<e.length;i++){var s=e[i];var f=new RegExp("^"+s+"-?\\d");if(f.test(t)){r[s]=t.slice(s.length)*1}}if(/^fn/.test(t)){r.fn=t.slice(2)}if(/^r/.test(t)){r.r=t.slice(1)}if(/^fs[\d+-]/.test(t)){r.fs=t.slice(2)}if(/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(t)){var l=t.match(/^(\d?)c&?H?(\w*)/);var v=l[1];var o=l[2];r["c"+(v||1)]=o&&("000000"+o).slice(-6)}if(/^\da&?H?[0-9a-f]+/i.test(t)){var c=t.match(/^(\d)a&?H?(\w\w)/);var u=c[1];var p=c[2];r["a"+u]=p}if(/^alpha&?H?[0-9a-f]+/i.test(t)){var d;d=t.match(/^alpha&?H?(\w\w)/),r.alpha=d[1]}if(/^(?:pos|org|move|fad|fade)\(/.test(t)){var h=t.match(/^(\w+)\((.*?)\)/);var y=h[1];var g=h[2];r[y]=g.trim().split(/\s*,\s*/).map(Number)}if(/^i?clip/.test(t)){var m=t.match(/^i?clip\((.*)\)/)[1].trim().split(/\s*,\s*/);r.clip={inverse:/iclip/.test(t),scale:1,drawing:null,dots:null};if(m.length===1){r.clip.drawing=a(m[0])}if(m.length===2){r.clip.scale=m[0]*1;r.clip.drawing=a(m[1])}if(m.length===4){r.clip.dots=m.map(Number)}}if(/^t\(/.test(t)){var x=t.match(/^t\((.*)\)/)[1].trim().replace(/\\.*/,function(t){return t.replace(/,/g,"\n")}).split(/\s*,\s*/);if(!x[0]){return r}r.t={t1:0,t2:0,accel:1,tags:x[x.length-1].replace(/\n/g,",").split("\\").slice(1).map(n)};if(x.length===2){r.t.accel=x[0]*1}if(x.length===3){r.t.t1=x[0]*1;r.t.t2=x[1]*1}if(x.length===4){r.t.t1=x[0]*1;r.t.t2=x[1]*1;r.t.accel=x[2]*1}}return r}function i(t){var r=0;return t.split("").map(function(t){if(t==="("){r++}if(t===")"){r--}if(r<0){r=0}return r&&t==="\\"?"\n":t}).join("").split(/\\/).slice(1).map(function(t){return t.replace(/\n/g,"\\")}).map(n)}function s(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 s=i(r[n]);var f=s.reduce(function(t,r){return r.p===undefined?t:!!r.p},false);e.push({tags:s,text:f?"":r[n+1],drawing:f?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 l(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 l=0;l<e.length;l++){var v=a[l];var o=e[l].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]=s(o);break;default:i[v]=o}}return i}function v(t){return t.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function o(t){return t.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/)}function c(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 f=s[1];var c=s[2];r.info[f]=c}}if(e===2){if(/^Format\s*:/i.test(i)){r.styles.format=v(i)}if(/^Style\s*:/i.test(i)){r.styles.style.push(o(i))}}if(e===3){if(/^Format\s*:/i.test(i)){r.events.format=v(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(l(d,r.events.format))}}}return r}function u(t){var r=[],a=arguments.length-1;while(a-- >0)r[a]=arguments[a+1];if(Object.assign){return Object.assign.apply(Object,[t].concat(r))}for(var e=0;e<r.length;e++){if(!r[e]){continue}var n=Object.keys(r[e]);for(var i=0;i<n.length;i++){t[n[i]]=r[e][n[i]]}}return t}function p(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 d(t){if(!t.points.length||!t.type){return false}if(/C|S/.test(t.type)&&t.points.length<3){return false}return true}function h(t){var r=Infinity;var a=Infinity;var e=-Infinity;var n=-Infinity;(i=[]).concat.apply(i,t.map(function(t){var r=t.points;return r})).forEach(function(t){var i=t.x;var s=t.y;r=Math.min(r,i);a=Math.min(a,s);e=Math.max(e,i);n=Math.max(n,s)});return{minX:r,minY:a,width:e-r,height:n-a};var i}function y(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 f=function(t,r){return t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3]};var l=[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:f(s,l),y:f(s,v)}]});for(var o=3;o<t.length;o++){l=[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:f(n,l),y:f(n,v)},{x:f(i,l),y:f(i,v)},{x:f(s,l),y:f(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 g(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 m(t){var r=[];var a=0;while(a<t.length){var e=t[a];var n=p(e);if(n.type){if(n.type==="S"){var i=r[a-1].points.slice(-1)[0];var s=i.x;var f=i.y;n.points.unshift({x:s,y:f})}if(d(n)){if(a){n.prev=r[a-1].type;r[a-1].next=n.type}r.push(n)}a++}else{if(r[a-1].type==="S"){var l={p:n.points,c:r[a-1].points.slice(0,3)};r[a-1].points=r[a-1].points.concat((l[e[0]]||[]).map(function(t){var r=t.x;var a=t.y;return{x:r,y:a}}))}t.splice(a,1)}}var v=(o=[]).concat.apply(o,r.map(function(t){var r=t.type;var a=t.points;var e=t.prev;var n=t.next;return r==="S"?y(a,e,n):{type:r,points:a}}));return u({instructions:v,d:g(v)},h(r));var o}var x=["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 b(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 f=s[0];var l=s[1];var v=s[2];var o=s[3];var c=s[4];if(c===void 0)c=0;var p=s[5];if(p===void 0)p=0;return s.length===4||s.length===6?{move:{x1:f,y1:l,x2:v,y2:o,t1:c,t2:p}}:null}if(r==="fad"||r==="fade"){if(s.length===2){var d=s[0];var h=s[1];return{fade:{type:"fad",t1:d,t2:h}}}if(s.length===7){var y=s[0];var g=s[1];var w=s[2];var S=s[3];var M=s[4];var C=s[5];var O=s[6];return{fade:{type:"fade",a1:y,a2:g,a3:w,t1:S,t2:M,t3:C,t4:O}}}return null}if(r==="clip"){var j=s.inverse;var k=s.scale;var L=s.drawing;var E=s.dots;if(L){return{clip:{inverse:j,scale:k,drawing:m(L),dots:E}}}if(E){var H=E[0];var N=E[1];var I=E[2];var R=E[3];return{clip:{inverse:j,scale:k,drawing:L,dots:{x1:H,y1:N,x2:I,y2:R}}}}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 F=s.t1;var z=s.accel;var $=s.tags;var A=s.t2||(a.end-a.start)*1e3;var B={};$.forEach(function(t){var r=Object.keys(t)[0];if(~x.indexOf(r)&&!(r==="clip"&&!t[r].dots)){u(B,b(t,r,a))}});return{t:{t1:F,t2:A,accel:z,tag:B}}}return i={},i[r]=s,i}var w=[null,1,2,3,null,7,8,9,null,4,5,6];var S=["r","a","an","pos","org","move","fade","fad","clip"];function M(t,r){return{name:t,borderStyle:r[t].style.BorderStyle,tag:r[t].tag,fragments:[]}}function C(t){var r=t.styles;var a=t.name;var e=t.parsed;var n=t.start;var i=t.end;var s;var f;var l;var v;var o;var c;var p=[];var d=M(a,r);var h={};for(var y=0;y<e.length;y++){var g=e[y];var x=g.tags;var C=g.text;var O=g.drawing;var j=void 0;for(var k=0;k<x.length;k++){var L=x[k];j=L.r===undefined?j:L.r}var E={tag:j===undefined?JSON.parse(JSON.stringify(h)):{},text:C,drawing:O.length?m(O):null};for(var H=0;H<x.length;H++){var N=x[H];s=s||w[N.a||0]||N.an;f=f||b(N,"pos");l=l||b(N,"org");v=v||b(N,"move");o=o||b(N,"fade")||b(N,"fad");c=b(N,"clip")||c;var I=Object.keys(N)[0];if(I&&!~S.indexOf(I)){var R=d.tag;var F=R.c1;var z=R.c2;var $=R.c3;var A=R.c4;var B=h.fs||d.tag.fs;var P=b(N,I,{start:n,end:i,c1:F,c2:z,c3:$,c4:A,fs:B});if(I==="t"){E.tag.t=E.tag.t||[];E.tag.t.push(P.t)}else{u(E.tag,P)}}}h=E.tag;if(j!==undefined){p.push(d);d=M(j||a,r)}if(E.text||E.drawing){var T=d.fragments[d.fragments.length-1]||{};if(T.text&&E.text&&!Object.keys(E.tag).length){T.text+=E.text}else{d.fragments.push(E)}}}p.push(d);return u({alignment:s,slices:p},f,l,v,o,c)}function O(t){var r=t.info;var a=t.styles;var e=t.dialogues;var n=Infinity;var i=[];for(var s=0;s<e.length;s++){var f=e[s];if(f.Start>=f.End){continue}var l=a[f.Style].style;var v=r.Timer/100||1;var o=C({styles:a,name:f.Style,parsed:f.Text.parsed,start:f.Start,end:f.End});var c=o.alignment||l.Alignment;n=Math.min(n,f.Layer);i.push(u({layer:f.Layer,start:f.Start/v,end:f.End/v,margin:{left:f.MarginL||l.MarginL,right:f.MarginR||l.MarginR,vertical:f.MarginV||l.MarginV},effect:f.Effect},o,{alignment:c}))}for(var p=0;p<i.length;p++){i[p].layer-=n}return i.sort(function(t,r){return t.start-r.start||t.end-r.end})}function j(t){var r=t.match(/&H(\w\w)?(\w{6})&?/);var a=r[1];var e=r[2];return[a||"00",e]}function k(t){var r=t.info;var a=t.style;var e=t.format;var n={};for(var i=0;i<a.length;i++){var s=a[i];var f={};for(var l=0;l<e.length;l++){var v=e[l];f[v]=v==="Name"||v==="Fontname"||/Colour/.test(v)?s[l]:s[l]*1}var o=j(f.PrimaryColour);var c=o[0];var u=o[1];var p=j(f.SecondaryColour);var d=p[0];var h=p[1];var y=j(f.OutlineColour);var g=y[0];var m=y[1];var x=j(f.BackColour);var b=x[0];var w=x[1];var S={fn:f.Fontname,fs:f.Fontsize,c1:u,a1:c,c2:h,a2:d,c3:m,a3:g,c4:w,a4:b,b:Math.abs(f.Bold),i:Math.abs(f.Italic),u:Math.abs(f.Underline),s:Math.abs(f.StrikeOut),fscx:f.ScaleX,fscy:f.ScaleY,fsp:f.Spacing,frz:f.Angle,xbord:f.Outline,ybord:f.Outline,xshad:f.Shadow,yshad:f.Shadow,q:/^[0-3]$/.test(r.WrapStyle)?r.WrapStyle*1:2};n[f.Name]={style:f,tag:S}}return n}function L(t){var r=c(t);var a=k({info:r.info,style:r.styles.style,format:r.styles.format});return{info:r.info,width:r.info.PlayResX*1||null,height:r.info.PlayResY*1||null,collisions:r.info.Collisions||"Normal",styles:a,dialogues:O({info:r.info,styles:a,dialogues:r.events.dialogue})}}t.parse=c;t.compile=L;Object.defineProperty(t,"__esModule",{value:true})});
{
"name": "ass-compiler",
"version": "0.0.2",
"version": "0.0.3",
"description": "Parses and compiles ASS subtitle format to easy-to-use data structure.",

@@ -43,4 +43,4 @@ "main": "dist/ass-compiler.js",

"chai": "^4.1.2",
"cross-env": "^5.1.0",
"eslint": "^4.9.0",
"cross-env": "^5.1.1",
"eslint": "^4.11.0",
"eslint-config-airbnb-base": "^12.1.0",

@@ -51,7 +51,8 @@ "eslint-plugin-import": "^2.8.0",

"mocha-istanbul": "^0.3.0",
"rollup": "^0.50.0",
"rollup-plugin-buble": "^0.16.0",
"rollup": "^0.51.7",
"rollup-plugin-buble": "^0.18.0",
"rollup-plugin-istanbul": "^1.1.0",
"uglify-js": "^3.1.4"
"rollup-plugin-multi-entry": "^2.0.2",
"uglify-js": "^3.1.9"
}
}
import { parseTag } from './tag.js';
export function parseTags(text) {
let depth = 0;
return text
.replace(/\((?:[^()]+|\([^()]*\))*\)/g, x => x.replace(/\\/g, '\n'))
.split('')
.map((x) => {
if (x === '(') depth++;
if (x === ')') depth--;
if (depth < 0) depth = 0;
return (depth && x === '\\') ? '\n' : x;
})
.join('')
.split(/\\/)

@@ -7,0 +15,0 @@ .slice(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