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.9 to 0.0.10

33

dist/ass-compiler.js

@@ -497,3 +497,3 @@ (function (global, factory) {

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

@@ -556,3 +556,3 @@ if (key === 'move') {

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

@@ -586,3 +586,3 @@ if (key === 'alpha') {

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

@@ -753,7 +753,26 @@

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

@@ -760,0 +779,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 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})});
(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 v=l[2];a["c"+(f||1)]=v&&("000000"+v).slice(-6)}else if(/^\da&?H?[0-9a-f]+/i.test(t)){var o=t.match(/^(\d)a&?H?(\w\w)/);var c=o[1];var u=o[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 v(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 o(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]=o(l);break;case"Effect":n[s]=f(l);break;case"Text":n[s]=v(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 v=i.match(/^(\w+?)\s*:\s*(.*)/i);var o=v[1];var c=v[2];r.events[o.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 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 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 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 R({instructions:o,d:S(o)},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 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 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 N=O[2];var H=O[3];return{clip:{inverse:w,scale:M,drawing:C,dots:{x1:k,y1:F,x2:N,y2:H}}}}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 L=s.t1;var j=s.accel;var E=s.tags;var $=s.t2||(a.end-a.start)*1e3;var I={};E.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:L,t2:$,accel:j,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 v;var o;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");v=v||z(O,"move");o=o||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 N=F.c1;var H=F.c2;var L=F.c3;var j=F.c4;var E=d.fs||p.tag.fs;var $=z(O,k,{start:n,end:i,c1:N,c2:H,c3:L,c4:j,fs:E});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,v,o,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 v=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: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 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){if(/^(&|H|&H)[0-9a-f]{6,}/i.test(t)){var r=t.match(/&?H?([0-9a-f]{2})?([0-9a-f]{6})/i);var a=r[1];var e=r[2];return[a||"00",e]}var n=parseInt(t,10);if(!isNaN(n)){var i=-2147483648;var s=2147483647;if(n<i){return["00","000000"]}var l=i<=n&&n<=s?("00000000"+(n<0?n+4294967296:n).toString(16)).slice(-8):String(n).slice(0,8);return[l.slice(0,2),l.slice(2)]}return["00","000000"]}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 v=f[0];var o=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:o,a3:v,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.9",
"version": "0.0.10",
"description": "Parses and compiles ASS subtitle format to easy-to-use data structure.",

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

"devDependencies": {
"chai": "^4.1.2",
"cross-env": "^5.1.4",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.10.0",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"eslint": "^5.9.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"istanbul": "^0.4.5",
"mocha": "^5.0.5",
"mocha": "^5.2.0",
"mocha-istanbul": "^0.3.0",
"rollup": "^0.57.1",
"rollup-plugin-buble": "^0.19.2",
"rollup": "^0.67.1",
"rollup-plugin-buble": "^0.19.4",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-multi-entry": "^2.0.2",
"rollup-plugin-replace": "^2.0.0",
"uglify-js": "^3.3.18"
"rollup-plugin-replace": "^2.1.0",
"uglify-js": "^3.4.9"
}
}

@@ -31,5 +31,24 @@ import { assign } from '../utils.js';

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

@@ -36,0 +55,0 @@

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