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

ass-compiler

Package Overview
Dependencies
Maintainers
0
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.1.11 to 0.1.12

44

dist/ass-compiler.js

@@ -244,20 +244,2 @@ (function (global, factory) {

var assign = Object.assign || (
/* istanbul ignore next */
function assign(target) {
var sources = [], len = arguments.length - 1;
while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
for (var i = 0; i < sources.length; i++) {
if (!sources[i]) { continue; }
var keys = Object.keys(sources[i]);
for (var j = 0; j < keys.length; j++) {
// eslint-disable-next-line no-param-reassign
target[keys[j]] = sources[i][keys[j]];
}
}
return target;
}
);
var stylesFormat = ['Name', 'Fontname', 'Fontsize', 'PrimaryColour', 'SecondaryColour', 'OutlineColour', 'BackColour', 'Bold', 'Italic', 'Underline', 'StrikeOut', 'ScaleX', 'ScaleY', 'Spacing', 'Angle', 'BorderStyle', 'Outline', 'Shadow', 'Alignment', 'MarginL', 'MarginR', 'MarginV', 'Encoding'];

@@ -278,3 +260,3 @@ var eventsFormat = ['Layer', 'Start', 'End', 'Style', 'Name', 'MarginL', 'MarginR', 'MarginV', 'Effect', 'Text'];

var values = text.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
return assign.apply(void 0, [ {} ].concat( format.map(function (fmt, idx) {
return Object.assign.apply(Object, [ {} ].concat( format.map(function (fmt, idx) {
var obj;

@@ -616,7 +598,7 @@

return assign({ instructions: instructions, d: toSVGPath(instructions) }, getViewBox(commands));
return Object.assign({ instructions: instructions, d: toSVGPath(instructions) }, getViewBox(commands));
}
var tTags = [
'fs', 'clip',
'fs', 'fsp', 'clip',
'c1', 'c2', 'c3', 'c4', 'a1', 'a2', 'a3', 'a4', 'alpha',

@@ -720,3 +702,3 @@ 'fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr',

if (~tTags.indexOf(k) && !(k === 'clip' && !t[k].dots)) {
assign(compiledTag, compileTag(t, k, presets));
Object.assign(compiledTag, compileTag(t, k, presets));
}

@@ -737,3 +719,3 @@ });

function inheritTag(pTag) {
return JSON.parse(JSON.stringify(assign({}, pTag, {
return JSON.parse(JSON.stringify(Object.assign({}, pTag, {
k: undefined,

@@ -798,3 +780,3 @@ kf: undefined,

} else {
assign(fragment.tag, compiledTag);
Object.assign(fragment.tag, compiledTag);
}

@@ -820,3 +802,3 @@ }

return assign({ alignment: alignment, slices: slices }, pos, org, move, fade, clip);
return Object.assign({ alignment: alignment, slices: slices }, pos, org, move, fade, clip);
}

@@ -848,3 +830,3 @@

minLayer = Math.min(minLayer, dia.Layer);
results.push(assign({
results.push(Object.assign({
layer: dia.Layer,

@@ -930,5 +912,5 @@ start: dia.Start,

var result = {};
var styles = [assign({}, defaultStyle, { Name: 'Default' })].concat(style);
var styles = [Object.assign({}, defaultStyle, { Name: 'Default' })].concat(style);
var loop = function ( i ) {
var s = assign({}, DEFAULT_STYLE, styles[i]);
var s = Object.assign({}, DEFAULT_STYLE, styles[i]);
// this behavior is same as Aegisub by black-box testing

@@ -1014,3 +996,3 @@ if (/^(\*+)Default$/.test(s.Name)) {

var obj = assign({}, style, {
var obj = Object.assign({}, style, {
PrimaryColour: ("&H" + (tag.a1) + (tag.c1)),

@@ -1151,3 +1133,3 @@ SecondaryColour: ("&H" + (tag.a2) + (tag.c2)),

'[Script Info]',
stringifyInfo(assign({}, info, {
stringifyInfo(Object.assign({}, info, {
PlayResX: width,

@@ -1174,4 +1156,2 @@ PlayResY: height,

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):(t=typeof globalThis!=="undefined"?globalThis:t||self,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}}if(t!==""){return{name:t}}return null}function h(t){if(!t){return[]}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 S(t){var r;var e={};for(var a=0;a<x.length;a++){var n=x[a];var i=n.name;var s=n.regex;if(s.test(t)){e[i]=t.slice(i.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-fA-F]+|^\d?c$/.test(t)){var o=t.match(/^(\d?)c&?H?(\w*)/);var f=o[1];var l=o[2];e["c"+(f||1)]=l&&("000000"+l).slice(-6)}else if(/^\da&?H?[0-9a-fA-F]+/.test(t)){var u=t.match(/^(\d)a&?H?([0-9a-f]+)/i);var c=u[1];var v=u[2];e["a"+c]=("00"+v).slice(-2)}else if(/^alpha&?H?[0-9a-fA-F]+/.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 p=t.match(/^(\w+)\((.*?)\)?$/);var d=p[1];var g=p[2];e[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*/);e.clip={inverse:/iclip/.test(t),scale:1,drawing:null,dots:null};if(y.length===1){e.clip.drawing=h(y[0])}if(y.length===2){e.clip.scale=y[0]*1;e.clip.drawing=h(y[1])}if(y.length===4){e.clip.dots=y.map(Number)}}else if(/^t\(/.test(t)){var m=t.match(/^t\((.*?)\)?$/)[1].trim().replace(/\\.*/,function(t){return t.replace(/,/g,"\n")}).split(/\s*,\s*/);if(!m[0]){return e}e.t={t1:0,t2:0,accel:1,tags:m[m.length-1].replace(/\n/g,",").split("\\").slice(1).map(S)};if(m.length===2){e.t.accel=m[0]*1}if(m.length===3){e.t.t1=m[0]*1;e.t.t2=m[1]*1}if(m.length===4){e.t.t1=m[0]*1;e.t.t2=m[1]*1;e.t.accel=m[2]*1}}return e}function s(t){var r=[];var e=0;var a="";var n=t.split("\\").slice(1).concat("").join("\\");for(var i=0;i<n.length;i++){var s=n[i];if(s==="("){e++}if(s===")"){e--}if(e<0){e=0}if(!e&&s==="\\"){if(a){r.push(a)}a=""}else{a+=s}}return r.map(S)}function l(t){var r=t.split(/{([^{}]*?)}/);var e=[];if(r[0].length){e.push({tags:[],text:r[0],drawing:[]})}for(var a=1;a<r.length;a+=2){var n=s(r[a]);var i=n.reduce(function(t,r){return r.p===undefined?t:!!r.p},false);e.push({tags:n,text:i?"":r[a+1],drawing:i?h(r[a+1]):[]})}return{raw:t,combined:e.map(function(t){return t.text}).join(""),parsed:e}}function u(t){var r=t.split(":");return r[0]*3600+r[1]*60+r[2]*1}function v(t,r){var e=t.split(",");if(e.length>r.length){var a=e.slice(r.length-1).join();e=e.slice(0,r.length-1);e.push(a)}var n={};for(var i=0;i<e.length;i++){var s=r[i];var o=e[i].trim();switch(s){case"Layer":case"MarginL":case"MarginR":case"MarginV":n[s]=o*1;break;case"Start":case"End":n[s]=u(o);break;case"Effect":n[s]=f(o);break;case"Text":n[s]=l(o);break;default:n[s]=o}}return n}var I=Object.assign||function t(r){var e=[],a=arguments.length-1;while(a-- >0)e[a]=arguments[a+1];for(var n=0;n<e.length;n++){if(!e[n]){continue}var i=Object.keys(e[n]);for(var s=0;s<i.length;s++){r[i[s]]=e[n][i[s]]}}return r};var o=["Name","Fontname","Fontsize","PrimaryColour","SecondaryColour","OutlineColour","BackColour","Bold","Italic","Underline","StrikeOut","ScaleX","ScaleY","Spacing","Angle","BorderStyle","Outline","Shadow","Alignment","MarginL","MarginR","MarginV","Encoding"];var c=["Layer","Start","End","Style","Name","MarginL","MarginR","MarginV","Effect","Text"];function p(t){var e=o.concat(c);return t.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/).map(function(r){var t=e.find(function(t){return t.toLowerCase()===r.toLowerCase()});return t||r})}function d(t,r){var a=t.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);return I.apply(void 0,[{}].concat(r.map(function(t,r){var e;return e={},e[t]=a[r],e})))}function n(t){var r={info:{},styles:{format:[],style:[]},events:{format:[],comment:[],dialogue:[]}};var e=t.split(/\r?\n/);var a=0;for(var n=0;n<e.length;n++){var i=e[n].trim();if(/^;/.test(i)){continue}if(/^\[Script Info\]/i.test(i)){a=1}else if(/^\[V4\+? Styles\]/i.test(i)){a=2}else if(/^\[Events\]/i.test(i)){a=3}else if(/^\[.*\]/.test(i)){a=0}if(a===0){continue}if(a===1){if(/:/.test(i)){var s=i.match(/(.*?)\s*:\s*(.*)/);var o=s[1];var f=s[2];r.info[o]=f}}if(a===2){if(/^Format\s*:/i.test(i)){r.styles.format=p(i)}if(/^Style\s*:/i.test(i)){r.styles.style.push(d(i,r.styles.format))}}if(a===3){if(/^Format\s*:/i.test(i)){r.events.format=p(i)}if(/^(?:Comment|Dialogue)\s*:/i.test(i)){var l=i.match(/^(\w+?)\s*:\s*(.*)/i);var u=l[1];var c=l[2];r.events[u.toLowerCase()].push(v(c,r.events.format))}}}return r}function g(r){return Object.keys(r).map(function(t){return t+": "+r[t]}).join("\n")}function y(t){return("00"+t).slice(-2)}function e(t){var r=Number.parseFloat(t.toFixed(2));var e=r.toFixed(2).slice(-2);var a=(r|0)%60;var n=(r/60|0)%60;var i=r/3600|0;return i+":"+y(n)+":"+y(a)+"."+e}function a(t){if(!t){return""}if(t.name==="banner"){return"Banner;"+t.delay+";"+t.leftToRight+";"+t.fadeAwayWidth}if(/^scroll\s/.test(t.name)){return t.name.replace(/^\w/,function(t){return t.toUpperCase()})+";"+t.y1+";"+t.y2+";"+t.delay+";"+t.fadeAwayHeight}return t.name}function m(t){return t.map(function(t){return t.join(" ")}).join(" ")}function b(t){var r=Object.keys(t);var e=r[0];if(!e){return""}var a=t[e];if(["pos","org","move","fad","fade"].some(function(t){return t===e})){return"\\"+e+"("+a+")"}if(/^[ac]\d$/.test(e)){return"\\"+e[1]+e[0]+"&H"+a+"&"}if(e==="alpha"){return"\\alpha&H"+a+"&"}if(e==="clip"){return"\\"+(a.inverse?"i":"")+"clip("+(a.dots||""+(a.scale===1?"":a.scale+",")+m(a.drawing))+")"}if(e==="t"){return"\\t("+[a.t1,a.t2,a.accel,a.tags.map(b).join("")]+")"}return"\\"+e+a}function i(t){return t.parsed.map(function(t){var r=t.tags;var e=t.text;var a=t.drawing;var n=r.map(b).join("");var i=a.length?m(a):e;return""+(n?"{"+n+"}":"")+i}).join("")}function w(r,t){return t.map(function(t){switch(t){case"Start":case"End":return e(r[t]);case"MarginL":case"MarginR":case"MarginV":return r[t]||"0000";case"Effect":return a(r[t]);case"Text":return i(r.Text);default:return r[t]}}).join()}function j(t){var r;var e=t.info;var a=t.styles;var n=t.events;return["[Script Info]",g(e),"","[V4+ Styles]","Format: "+a.format.join(", ")].concat(a.style.map(function(r){return"Style: "+a.format.map(function(t){return r[t]}).join()}),[""],["[Events]"],["Format: "+n.format.join(", ")],(r=[]).concat.apply(r,["Comment","Dialogue"].map(function(r){return n[r.toLowerCase()].map(function(t){return{start:t.Start,end:t.End,string:r+": "+w(t,n.format)}})})).sort(function(t,r){return t.start-r.start||t.end-r.end}).map(function(t){return t.string}),[""]).join("\n")}function M(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 e=t.length-!(t.length&1),a=1;a<e;a+=2){r.points.push({x:t[a]*1,y:t[a+1]*1})}return r}function C(t){if(!t.points.length||!t.type){return false}if(/C|S/.test(t.type)&&t.points.length<3){return false}return true}function A(t){var r;var a=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 e=t.y;a=Math.min(a,r);n=Math.min(n,e);i=Math.max(i,r);s=Math.max(s,e)});return{minX:a,minY:n,width:i-a,height:s-n}}function R(t,r,e){var a=[];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 o=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 l=[t[t.length-1].y,t[0].y,t[1].y,t[2].y];a.push({type:r==="M"?"M":"L",points:[{x:o(s,f),y:o(s,l)}]});for(var u=3;u<t.length;u++){f=[t[u-3].x,t[u-2].x,t[u-1].x,t[u].x];l=[t[u-3].y,t[u-2].y,t[u-1].y,t[u].y];a.push({type:"C",points:[{x:o(n,f),y:o(n,l)},{x:o(i,f),y:o(i,l)},{x:o(s,f),y:o(s,l)}]})}if(e==="L"||e==="C"){var c=t[t.length-1];a.push({type:"L",points:[{x:c.x,y:c.y}]})}return a}function $(t){return t.map(function(t){var r=t.type;var e=t.points;return r+e.map(function(t){var r=t.x;var e=t.y;return r+","+e}).join(",")}).join("")}function B(t){var r;var e=[];var a=0;while(a<t.length){var n=t[a];var i=M(n);if(C(i)){if(i.type==="S"){var s=(e[a-1]||{points:[{x:0,y:0}]}).points.slice(-1)[0];var o=s.x;var f=s.y;i.points.unshift({x:o,y:f})}if(a){i.prev=e[a-1].type;e[a-1].next=i.type}e.push(i);a++}else{if(a&&e[a-1].type==="S"){var l={p:i.points,c:e[a-1].points.slice(0,3)};e[a-1].points=e[a-1].points.concat((l[n[0]]||[]).map(function(t){var r=t.x;var e=t.y;return{x:r,y:e}}))}t.splice(a,1)}}var u=(r=[]).concat.apply(r,e.map(function(t){var r=t.type;var e=t.points;var a=t.prev;var n=t.next;return r==="S"?R(e,a,n):{type:r,points:e}}));return I({instructions:u,d:$(u)},A(e))}var P=["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 V(t,r,e){var a,n,i;if(e===void 0)e={};var s=t[r];if(s===undefined){return null}if(r==="pos"||r==="org"){return s.length===2?(a={},a[r]={x:s[0],y:s[1]},a):null}if(r==="move"){var o=s[0];var f=s[1];var l=s[2];var u=s[3];var c=s[4];if(c===void 0)c=0;var v=s[5];if(v===void 0)v=0;return s.length===4||s.length===6?{move:{x1:o,y1:f,x2:l,y2:u,t1:c,t2:v}}: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 m=s[2];var h=s[3];var x=s[4];var S=s[5];var b=s[6];return{fade:{type:"fade",a1:g,a2:y,a3:m,t1:h,t2:x,t3:S,t4:b}}}return null}if(r==="clip"){var w=s.inverse;var j=s.scale;var M=s.drawing;var C=s.dots;if(M){return{clip:{inverse:w,scale:j,drawing:B(M),dots:C}}}if(C){var k=C[0];var O=C[1];var F=C[2];var L=C[3];return{clip:{inverse:w,scale:j,drawing:M,dots:{x1:k,y1:O,x2:F,y2:L}}}}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||e[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)*e.fs:s*1}}if(r==="K"){return{kf:s}}if(r==="t"){var E=s.t1;var H=s.accel;var N=s.tags;var A=s.t2||(e.end-e.start)*1e3;var R={};N.forEach(function(t){var r=Object.keys(t)[0];if(~P.indexOf(r)&&!(r==="clip"&&!t[r].dots)){I(R,V(t,r,e))}});return{t:{t1:E,t2:A,accel:H,tag:R}}}return i={},i[r]=s,i}var T=[null,1,2,3,null,7,8,9,null,4,5,6];var D=["r","a","an","pos","org","move","fade","fad","clip"];function z(t){return JSON.parse(JSON.stringify(I({},t,{k:undefined,kf:undefined,ko:undefined,kt:undefined})))}function X(t){var r=t.styles;var e=t.style;var a=t.parsed;var n=t.start;var i=t.end;var s;var o;var f;var l;var u;var c;var v=[];var p={style:e,fragments:[]};var d={};for(var g=0;g<a.length;g++){var y=a[g];var m=y.tags;var h=y.text;var x=y.drawing;var S=void 0;for(var b=0;b<m.length;b++){var w=m[b];S=w.r===undefined?S:w.r}var j={tag:S===undefined?z(d):{},text:h,drawing:x.length?B(x):null};for(var M=0;M<m.length;M++){var C=m[M];s=s||T[C.a||0]||C.an;o=o||V(C,"pos");f=f||V(C,"org");l=l||V(C,"move");u=u||V(C,"fade")||V(C,"fad");c=V(C,"clip")||c;var k=Object.keys(C)[0];if(k&&!~D.indexOf(k)){var O=r[e].tag;var F=O.c1;var L=O.c2;var E=O.c3;var H=O.c4;var N=d.fs||O.fs;var A=V(C,k,{start:n,end:i,c1:F,c2:L,c3:E,c4:H,fs:N});if(k==="t"){j.tag.t=j.tag.t||[];j.tag.t.push(A.t)}else{I(j.tag,A)}}}d=j.tag;if(S!==undefined){v.push(p);p={style:r[S]?S:e,fragments:[]}}if(j.text||j.drawing){var R=p.fragments[p.fragments.length-1]||{};if(R.text&&j.text&&!Object.keys(j.tag).length){R.text+=j.text}else{p.fragments.push(j)}}}v.push(p);return I({alignment:s,slices:v},o,f,l,u,c)}function Y(t){var r=t.styles;var e=t.dialogues;var a=Infinity;var n=[];for(var i=0;i<e.length;i++){var s=e[i];if(s.Start>=s.End){continue}if(!r[s.Style]){s.Style="Default"}var o=r[s.Style].style;var f=X({styles:r,style:s.Style,parsed:s.Text.parsed,start:s.Start,end:s.End});var l=f.alignment||o.Alignment;a=Math.min(a,s.Layer);n.push(I({layer:s.Layer,start:s.Start,end:s.End,style:s.Style,name:s.Name,margin:{left:s.MarginL||o.MarginL,right:s.MarginR||o.MarginR,vertical:s.MarginV||o.MarginV},effect:s.Effect},f,{alignment:l}))}for(var u=0;u<n.length;u++){n[u].layer-=a}return n.sort(function(t,r){return t.start-r.start||t.end-r.end})}var U={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 k(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 e=r[1];var a=r[2];return[e||"00",a]}var n=parseInt(t,10);if(!isNaN(n)){var i=-2147483648;var s=2147483647;if(n<i){return["00","000000"]}var o=i<=n&&n<=s?("00000000"+(n<0?n+4294967296:n).toString(16)).slice(-8):String(n).slice(0,8);return[o.slice(0,2),o.slice(2)]}return["00","000000"]}function J(t){var g=t.info;var r=t.style;var e=t.defaultStyle;var y={};var m=[I({},e,{Name:"Default"})].concat(r);var a=function(t){var r=I({},U,m[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 e=k(r.PrimaryColour);var a=e[0];var n=e[1];var i=k(r.SecondaryColour);var s=i[0];var o=i[1];var f=k(r.OutlineColour);var l=f[0];var u=f[1];var c=k(r.BackColour);var v=c[0];var p=c[1];var d={fn:r.Fontname,fs:r.Fontsize,c1:n,a1:a,c2:o,a2:s,c3:u,a3:l,c4:p,a4:v,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,fe:r.Encoding,q:/^[0-3]$/.test(g.WrapStyle)?g.WrapStyle*1:2};y[r.Name]={style:r,tag:d}};for(var n=0;n<m.length;n++)a(n);return y}function W(t,r){if(r===void 0)r={};var e=n(t);var a=J({info:e.info,style:e.styles.style,defaultStyle:r.defaultStyle||{}});return{info:e.info,width:e.info.PlayResX*1||null,height:e.info.PlayResY*1||null,collisions:e.info.Collisions||"Normal",styles:a,dialogues:Y({styles:a,dialogues:e.events.dialogue})}}function q(t){var r=t.style;var e=t.tag;var a=I({},r,{PrimaryColour:"&H"+e.a1+e.c1,SecondaryColour:"&H"+e.a2+e.c2,OutlineColour:"&H"+e.a3+e.c3,BackColour:"&H"+e.a4+e.c4});return"Style: "+o.map(function(t){return a[t]}).join()}var K={M:"m",L:"l",C:"b"};function O(t){var r=t.instructions;return r.map(function(t){var r;var e=t.type;var a=t.points;return(r=[K[e]]).concat.apply(r,a.map(function(t){var r=t.x;var e=t.y;return[r,e]})).join(" ")}).join(" ")}var F=function(e){return function(r){return function(t){return""+r+e+"&H"+t+"&"}}};var L=F("c");var E=F("a");var _={c1:L(1),c2:L(2),c3:L(3),c4:L(4),a1:E(1),a2:E(2),a3:E(3),a4:E(4),pos:function(t){return"pos("+[t.x,t.y]+")"},org:function(t){return"org("+[t.x,t.y]+")"},move:function(t){return"move("+[t.x1,t.y1,t.x2,t.y2,t.t1,t.t2]+")"},fade:function(t){return t.type==="fad"?"fad("+[t.t1,t.t2]+")":"fade("+[t.a1,t.a2,t.a3,t.t1,t.t2,t.t3,t.t4]+")"},clip:function(t){return(t.inverse?"i":"")+"clip("+(t.dots?""+[t.dots.x1,t.dots.y1,t.dots.x2,t.dots.y2]:""+(t.scale===1?"":t.scale+",")+O(t.drawing))+")"},t:function(t){return t.map(function(t){return"t("+[t.t1,t.t2,t.accel,H(t.tag)]+")"}).join("\\")}};function H(e){return Object.keys(e).map(function(r){var t=_[r]||function(t){return""+r+t};return"\\"+t(e[r])}).join("")}function G(t){return t.fragments.map(function(t){var r=t.tag;var e=t.text;var a=t.drawing;var n=H(r);return""+(n?"{"+n+"}":"")+(a?O(a):e)}).join("")}function Q(n,i){return n.slices.filter(function(t){return t.fragments.length}).map(function(t,r){var e=JSON.parse(JSON.stringify(t));var a={};if(r){a.r=t.style===n.style?"":t.style}else{if(i.Alignment!==n.alignment){a.an=n.alignment}["pos","org","move","fade","clip"].forEach(function(t){if(n[t]){a[t]=n[t]}})}e.fragments[0].tag=Object.assign(a,e.fragments[0].tag);return e}).map(G).join("")}function N(t,r){return t===r?"0000":t}function Z(t,r){return"Dialogue: "+[t.layer,e(t.start),e(t.end),t.style,t.name,N(t.margin.left,r.MarginL),N(t.margin.right,r.MarginR),N(t.margin.vertical,r.MarginV),a(t.effect),Q(t,r)].join()}function tt(t){var r=t.info;var e=t.width;var a=t.height;var n=t.collisions;var i=t.styles;var s=t.dialogues;return["[Script Info]",g(I({},r,{PlayResX:e,PlayResY:a,Collisions:n})),"","[V4+ Styles]","Format: "+o.join(", ")].concat(Object.keys(i).map(function(t){return q(i[t])}),[""],["[Events]"],["Format: "+c.join(", ")],s.sort(function(t,r){return t.start-r.start||t.end-r.end}).map(function(t){return Z(t,i[t.style].style)}),[""]).join("\n")}t.compile=W;t.decompile=tt;t.parse=n;t.stringify=j;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):(t=typeof globalThis!=="undefined"?globalThis:t||self,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}}if(t!==""){return{name:t}}return null}function h(t){if(!t){return[]}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 e={};for(var a=0;a<x.length;a++){var n=x[a];var i=n.name;var s=n.regex;if(s.test(t)){e[i]=t.slice(i.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-fA-F]+|^\d?c$/.test(t)){var o=t.match(/^(\d?)c&?H?(\w*)/);var f=o[1];var l=o[2];e["c"+(f||1)]=l&&("000000"+l).slice(-6)}else if(/^\da&?H?[0-9a-fA-F]+/.test(t)){var c=t.match(/^(\d)a&?H?([0-9a-f]+)/i);var u=c[1];var v=c[2];e["a"+u]=("00"+v).slice(-2)}else if(/^alpha&?H?[0-9a-fA-F]+/.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 p=t.match(/^(\w+)\((.*?)\)?$/);var d=p[1];var g=p[2];e[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*/);e.clip={inverse:/iclip/.test(t),scale:1,drawing:null,dots:null};if(y.length===1){e.clip.drawing=h(y[0])}if(y.length===2){e.clip.scale=y[0]*1;e.clip.drawing=h(y[1])}if(y.length===4){e.clip.dots=y.map(Number)}}else if(/^t\(/.test(t)){var m=t.match(/^t\((.*?)\)?$/)[1].trim().replace(/\\.*/,function(t){return t.replace(/,/g,"\n")}).split(/\s*,\s*/);if(!m[0]){return e}e.t={t1:0,t2:0,accel:1,tags:m[m.length-1].replace(/\n/g,",").split("\\").slice(1).map(b)};if(m.length===2){e.t.accel=m[0]*1}if(m.length===3){e.t.t1=m[0]*1;e.t.t2=m[1]*1}if(m.length===4){e.t.t1=m[0]*1;e.t.t2=m[1]*1;e.t.accel=m[2]*1}}return e}function s(t){var r=[];var e=0;var a="";var n=t.split("\\").slice(1).concat("").join("\\");for(var i=0;i<n.length;i++){var s=n[i];if(s==="("){e++}if(s===")"){e--}if(e<0){e=0}if(!e&&s==="\\"){if(a){r.push(a)}a=""}else{a+=s}}return r.map(b)}function l(t){var r=t.split(/{([^{}]*?)}/);var e=[];if(r[0].length){e.push({tags:[],text:r[0],drawing:[]})}for(var a=1;a<r.length;a+=2){var n=s(r[a]);var i=n.reduce(function(t,r){return r.p===undefined?t:!!r.p},false);e.push({tags:n,text:i?"":r[a+1],drawing:i?h(r[a+1]):[]})}return{raw:t,combined:e.map(function(t){return t.text}).join(""),parsed:e}}function c(t){var r=t.split(":");return r[0]*3600+r[1]*60+r[2]*1}function v(t,r){var e=t.split(",");if(e.length>r.length){var a=e.slice(r.length-1).join();e=e.slice(0,r.length-1);e.push(a)}var n={};for(var i=0;i<e.length;i++){var s=r[i];var o=e[i].trim();switch(s){case"Layer":case"MarginL":case"MarginR":case"MarginV":n[s]=o*1;break;case"Start":case"End":n[s]=c(o);break;case"Effect":n[s]=f(o);break;case"Text":n[s]=l(o);break;default:n[s]=o}}return n}var o=["Name","Fontname","Fontsize","PrimaryColour","SecondaryColour","OutlineColour","BackColour","Bold","Italic","Underline","StrikeOut","ScaleX","ScaleY","Spacing","Angle","BorderStyle","Outline","Shadow","Alignment","MarginL","MarginR","MarginV","Encoding"];var u=["Layer","Start","End","Style","Name","MarginL","MarginR","MarginV","Effect","Text"];function p(t){var e=o.concat(u);return t.match(/Format\s*:\s*(.*)/i)[1].split(/\s*,\s*/).map(function(r){var t=e.find(function(t){return t.toLowerCase()===r.toLowerCase()});return t||r})}function d(t,r){var a=t.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);return Object.assign.apply(Object,[{}].concat(r.map(function(t,r){var e;return e={},e[t]=a[r],e})))}function n(t){var r={info:{},styles:{format:[],style:[]},events:{format:[],comment:[],dialogue:[]}};var e=t.split(/\r?\n/);var a=0;for(var n=0;n<e.length;n++){var i=e[n].trim();if(/^;/.test(i)){continue}if(/^\[Script Info\]/i.test(i)){a=1}else if(/^\[V4\+? Styles\]/i.test(i)){a=2}else if(/^\[Events\]/i.test(i)){a=3}else if(/^\[.*\]/.test(i)){a=0}if(a===0){continue}if(a===1){if(/:/.test(i)){var s=i.match(/(.*?)\s*:\s*(.*)/);var o=s[1];var f=s[2];r.info[o]=f}}if(a===2){if(/^Format\s*:/i.test(i)){r.styles.format=p(i)}if(/^Style\s*:/i.test(i)){r.styles.style.push(d(i,r.styles.format))}}if(a===3){if(/^Format\s*:/i.test(i)){r.events.format=p(i)}if(/^(?:Comment|Dialogue)\s*:/i.test(i)){var l=i.match(/^(\w+?)\s*:\s*(.*)/i);var c=l[1];var u=l[2];r.events[c.toLowerCase()].push(v(u,r.events.format))}}}return r}function g(r){return Object.keys(r).map(function(t){return t+": "+r[t]}).join("\n")}function y(t){return("00"+t).slice(-2)}function e(t){var r=Number.parseFloat(t.toFixed(2));var e=r.toFixed(2).slice(-2);var a=(r|0)%60;var n=(r/60|0)%60;var i=r/3600|0;return i+":"+y(n)+":"+y(a)+"."+e}function a(t){if(!t){return""}if(t.name==="banner"){return"Banner;"+t.delay+";"+t.leftToRight+";"+t.fadeAwayWidth}if(/^scroll\s/.test(t.name)){return t.name.replace(/^\w/,function(t){return t.toUpperCase()})+";"+t.y1+";"+t.y2+";"+t.delay+";"+t.fadeAwayHeight}return t.name}function m(t){return t.map(function(t){return t.join(" ")}).join(" ")}function S(t){var r=Object.keys(t);var e=r[0];if(!e){return""}var a=t[e];if(["pos","org","move","fad","fade"].some(function(t){return t===e})){return"\\"+e+"("+a+")"}if(/^[ac]\d$/.test(e)){return"\\"+e[1]+e[0]+"&H"+a+"&"}if(e==="alpha"){return"\\alpha&H"+a+"&"}if(e==="clip"){return"\\"+(a.inverse?"i":"")+"clip("+(a.dots||""+(a.scale===1?"":a.scale+",")+m(a.drawing))+")"}if(e==="t"){return"\\t("+[a.t1,a.t2,a.accel,a.tags.map(S).join("")]+")"}return"\\"+e+a}function i(t){return t.parsed.map(function(t){var r=t.tags;var e=t.text;var a=t.drawing;var n=r.map(S).join("");var i=a.length?m(a):e;return""+(n?"{"+n+"}":"")+i}).join("")}function j(r,t){return t.map(function(t){switch(t){case"Start":case"End":return e(r[t]);case"MarginL":case"MarginR":case"MarginV":return r[t]||"0000";case"Effect":return a(r[t]);case"Text":return i(r.Text);default:return r[t]}}).join()}function w(t){var r;var e=t.info;var a=t.styles;var n=t.events;return["[Script Info]",g(e),"","[V4+ Styles]","Format: "+a.format.join(", ")].concat(a.style.map(function(r){return"Style: "+a.format.map(function(t){return r[t]}).join()}),[""],["[Events]"],["Format: "+n.format.join(", ")],(r=[]).concat.apply(r,["Comment","Dialogue"].map(function(r){return n[r.toLowerCase()].map(function(t){return{start:t.Start,end:t.End,string:r+": "+j(t,n.format)}})})).sort(function(t,r){return t.start-r.start||t.end-r.end}).map(function(t){return t.string}),[""]).join("\n")}function M(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 e=t.length-!(t.length&1),a=1;a<e;a+=2){r.points.push({x:t[a]*1,y:t[a+1]*1})}return r}function O(t){if(!t.points.length||!t.type){return false}if(/C|S/.test(t.type)&&t.points.length<3){return false}return true}function C(t){var r;var a=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 e=t.y;a=Math.min(a,r);n=Math.min(n,e);i=Math.max(i,r);s=Math.max(s,e)});return{minX:a,minY:n,width:i-a,height:s-n}}function R(t,r,e){var a=[];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 o=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 l=[t[t.length-1].y,t[0].y,t[1].y,t[2].y];a.push({type:r==="M"?"M":"L",points:[{x:o(s,f),y:o(s,l)}]});for(var c=3;c<t.length;c++){f=[t[c-3].x,t[c-2].x,t[c-1].x,t[c].x];l=[t[c-3].y,t[c-2].y,t[c-1].y,t[c].y];a.push({type:"C",points:[{x:o(n,f),y:o(n,l)},{x:o(i,f),y:o(i,l)},{x:o(s,f),y:o(s,l)}]})}if(e==="L"||e==="C"){var u=t[t.length-1];a.push({type:"L",points:[{x:u.x,y:u.y}]})}return a}function V(t){return t.map(function(t){var r=t.type;var e=t.points;return r+e.map(function(t){var r=t.x;var e=t.y;return r+","+e}).join(",")}).join("")}function I(t){var r;var e=[];var a=0;while(a<t.length){var n=t[a];var i=M(n);if(O(i)){if(i.type==="S"){var s=(e[a-1]||{points:[{x:0,y:0}]}).points.slice(-1)[0];var o=s.x;var f=s.y;i.points.unshift({x:o,y:f})}if(a){i.prev=e[a-1].type;e[a-1].next=i.type}e.push(i);a++}else{if(a&&e[a-1].type==="S"){var l={p:i.points,c:e[a-1].points.slice(0,3)};e[a-1].points=e[a-1].points.concat((l[n[0]]||[]).map(function(t){var r=t.x;var e=t.y;return{x:r,y:e}}))}t.splice(a,1)}}var c=(r=[]).concat.apply(r,e.map(function(t){var r=t.type;var e=t.points;var a=t.prev;var n=t.next;return r==="S"?R(e,a,n):{type:r,points:e}}));return Object.assign({instructions:c,d:V(c)},C(e))}var $=["fs","fsp","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,e){var a,n,i;if(e===void 0)e={};var s=t[r];if(s===undefined){return null}if(r==="pos"||r==="org"){return s.length===2?(a={},a[r]={x:s[0],y:s[1]},a):null}if(r==="move"){var o=s[0];var f=s[1];var l=s[2];var c=s[3];var u=s[4];if(u===void 0)u=0;var v=s[5];if(v===void 0)v=0;return s.length===4||s.length===6?{move:{x1:o,y1:f,x2:l,y2:c,t1:u,t2:v}}: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 m=s[2];var h=s[3];var x=s[4];var b=s[5];var S=s[6];return{fade:{type:"fade",a1:g,a2:y,a3:m,t1:h,t2:x,t3:b,t4:S}}}return null}if(r==="clip"){var j=s.inverse;var w=s.scale;var M=s.drawing;var O=s.dots;if(M){return{clip:{inverse:j,scale:w,drawing:I(M),dots:O}}}if(O){var C=O[0];var k=O[1];var F=O[2];var L=O[3];return{clip:{inverse:j,scale:w,drawing:M,dots:{x1:C,y1:k,x2:F,y2:L}}}}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||e[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)*e.fs:s*1}}if(r==="K"){return{kf:s}}if(r==="t"){var E=s.t1;var H=s.accel;var N=s.tags;var A=s.t2||(e.end-e.start)*1e3;var R={};N.forEach(function(t){var r=Object.keys(t)[0];if(~$.indexOf(r)&&!(r==="clip"&&!t[r].dots)){Object.assign(R,B(t,r,e))}});return{t:{t1:E,t2:A,accel:H,tag:R}}}return i={},i[r]=s,i}var T=[null,1,2,3,null,7,8,9,null,4,5,6];var D=["r","a","an","pos","org","move","fade","fad","clip"];function P(t){return JSON.parse(JSON.stringify(Object.assign({},t,{k:undefined,kf:undefined,ko:undefined,kt:undefined})))}function z(t){var r=t.styles;var e=t.style;var a=t.parsed;var n=t.start;var i=t.end;var s;var o;var f;var l;var c;var u;var v=[];var p={style:e,fragments:[]};var d={};for(var g=0;g<a.length;g++){var y=a[g];var m=y.tags;var h=y.text;var x=y.drawing;var b=void 0;for(var S=0;S<m.length;S++){var j=m[S];b=j.r===undefined?b:j.r}var w={tag:b===undefined?P(d):{},text:h,drawing:x.length?I(x):null};for(var M=0;M<m.length;M++){var O=m[M];s=s||T[O.a||0]||O.an;o=o||B(O,"pos");f=f||B(O,"org");l=l||B(O,"move");c=c||B(O,"fade")||B(O,"fad");u=B(O,"clip")||u;var C=Object.keys(O)[0];if(C&&!~D.indexOf(C)){var k=r[e].tag;var F=k.c1;var L=k.c2;var E=k.c3;var H=k.c4;var N=d.fs||k.fs;var A=B(O,C,{start:n,end:i,c1:F,c2:L,c3:E,c4:H,fs:N});if(C==="t"){w.tag.t=w.tag.t||[];w.tag.t.push(A.t)}else{Object.assign(w.tag,A)}}}d=w.tag;if(b!==undefined){v.push(p);p={style:r[b]?b:e,fragments:[]}}if(w.text||w.drawing){var R=p.fragments[p.fragments.length-1]||{};if(R.text&&w.text&&!Object.keys(w.tag).length){R.text+=w.text}else{p.fragments.push(w)}}}v.push(p);return Object.assign({alignment:s,slices:v},o,f,l,c,u)}function X(t){var r=t.styles;var e=t.dialogues;var a=Infinity;var n=[];for(var i=0;i<e.length;i++){var s=e[i];if(s.Start>=s.End){continue}if(!r[s.Style]){s.Style="Default"}var o=r[s.Style].style;var f=z({styles:r,style:s.Style,parsed:s.Text.parsed,start:s.Start,end:s.End});var l=f.alignment||o.Alignment;a=Math.min(a,s.Layer);n.push(Object.assign({layer:s.Layer,start:s.Start,end:s.End,style:s.Style,name:s.Name,margin:{left:s.MarginL||o.MarginL,right:s.MarginR||o.MarginR,vertical:s.MarginV||o.MarginV},effect:s.Effect},f,{alignment:l}))}for(var c=0;c<n.length;c++){n[c].layer-=a}return n.sort(function(t,r){return t.start-r.start||t.end-r.end})}var Y={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 k(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 e=r[1];var a=r[2];return[e||"00",a]}var n=parseInt(t,10);if(!isNaN(n)){var i=-2147483648;var s=2147483647;if(n<i){return["00","000000"]}var o=i<=n&&n<=s?("00000000"+(n<0?n+4294967296:n).toString(16)).slice(-8):String(n).slice(0,8);return[o.slice(0,2),o.slice(2)]}return["00","000000"]}function U(t){var g=t.info;var r=t.style;var e=t.defaultStyle;var y={};var m=[Object.assign({},e,{Name:"Default"})].concat(r);var a=function(t){var r=Object.assign({},Y,m[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 e=k(r.PrimaryColour);var a=e[0];var n=e[1];var i=k(r.SecondaryColour);var s=i[0];var o=i[1];var f=k(r.OutlineColour);var l=f[0];var c=f[1];var u=k(r.BackColour);var v=u[0];var p=u[1];var d={fn:r.Fontname,fs:r.Fontsize,c1:n,a1:a,c2:o,a2:s,c3:c,a3:l,c4:p,a4:v,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,fe:r.Encoding,q:/^[0-3]$/.test(g.WrapStyle)?g.WrapStyle*1:2};y[r.Name]={style:r,tag:d}};for(var n=0;n<m.length;n++)a(n);return y}function J(t,r){if(r===void 0)r={};var e=n(t);var a=U({info:e.info,style:e.styles.style,defaultStyle:r.defaultStyle||{}});return{info:e.info,width:e.info.PlayResX*1||null,height:e.info.PlayResY*1||null,collisions:e.info.Collisions||"Normal",styles:a,dialogues:X({styles:a,dialogues:e.events.dialogue})}}function W(t){var r=t.style;var e=t.tag;var a=Object.assign({},r,{PrimaryColour:"&H"+e.a1+e.c1,SecondaryColour:"&H"+e.a2+e.c2,OutlineColour:"&H"+e.a3+e.c3,BackColour:"&H"+e.a4+e.c4});return"Style: "+o.map(function(t){return a[t]}).join()}var q={M:"m",L:"l",C:"b"};function F(t){var r=t.instructions;return r.map(function(t){var r;var e=t.type;var a=t.points;return(r=[q[e]]).concat.apply(r,a.map(function(t){var r=t.x;var e=t.y;return[r,e]})).join(" ")}).join(" ")}var L=function(e){return function(r){return function(t){return""+r+e+"&H"+t+"&"}}};var E=L("c");var H=L("a");var K={c1:E(1),c2:E(2),c3:E(3),c4:E(4),a1:H(1),a2:H(2),a3:H(3),a4:H(4),pos:function(t){return"pos("+[t.x,t.y]+")"},org:function(t){return"org("+[t.x,t.y]+")"},move:function(t){return"move("+[t.x1,t.y1,t.x2,t.y2,t.t1,t.t2]+")"},fade:function(t){return t.type==="fad"?"fad("+[t.t1,t.t2]+")":"fade("+[t.a1,t.a2,t.a3,t.t1,t.t2,t.t3,t.t4]+")"},clip:function(t){return(t.inverse?"i":"")+"clip("+(t.dots?""+[t.dots.x1,t.dots.y1,t.dots.x2,t.dots.y2]:""+(t.scale===1?"":t.scale+",")+F(t.drawing))+")"},t:function(t){return t.map(function(t){return"t("+[t.t1,t.t2,t.accel,N(t.tag)]+")"}).join("\\")}};function N(e){return Object.keys(e).map(function(r){var t=K[r]||function(t){return""+r+t};return"\\"+t(e[r])}).join("")}function G(t){return t.fragments.map(function(t){var r=t.tag;var e=t.text;var a=t.drawing;var n=N(r);return""+(n?"{"+n+"}":"")+(a?F(a):e)}).join("")}function Q(n,i){return n.slices.filter(function(t){return t.fragments.length}).map(function(t,r){var e=JSON.parse(JSON.stringify(t));var a={};if(r){a.r=t.style===n.style?"":t.style}else{if(i.Alignment!==n.alignment){a.an=n.alignment}["pos","org","move","fade","clip"].forEach(function(t){if(n[t]){a[t]=n[t]}})}e.fragments[0].tag=Object.assign(a,e.fragments[0].tag);return e}).map(G).join("")}function A(t,r){return t===r?"0000":t}function Z(t,r){return"Dialogue: "+[t.layer,e(t.start),e(t.end),t.style,t.name,A(t.margin.left,r.MarginL),A(t.margin.right,r.MarginR),A(t.margin.vertical,r.MarginV),a(t.effect),Q(t,r)].join()}function _(t){var r=t.info;var e=t.width;var a=t.height;var n=t.collisions;var i=t.styles;var s=t.dialogues;return["[Script Info]",g(Object.assign({},r,{PlayResX:e,PlayResY:a,Collisions:n})),"","[V4+ Styles]","Format: "+o.join(", ")].concat(Object.keys(i).map(function(t){return W(i[t])}),[""],["[Events]"],["Format: "+u.join(", ")],s.sort(function(t,r){return t.start-r.start||t.end-r.end}).map(function(t){return Z(t,i[t.style].style)}),[""]).join("\n")}t.compile=J;t.decompile=_;t.parse=n;t.stringify=w});
{
"name": "ass-compiler",
"version": "0.1.11",
"version": "0.1.12",
"type": "module",
"description": "Parses and compiles ASS subtitle format to easy-to-use data structure.",

@@ -16,6 +17,5 @@ "main": "dist/ass-compiler.js",

"lint": "eslint src test",
"preunit": "rollup -c rollup.config.test.js",
"unit": "mocha temp/test.js",
"cover": "cross-env ISTANBUL_REPORT_DIR=coverage ISTANBUL_REPORTERS=text-summary,lcov npm run unit -- --reporter=mocha-istanbul",
"test": "npm run lint && npm run unit && npm run cover",
"unit": "vitest run",
"cover": "vitest run --coverage",
"test": "npm run lint && npm run unit",
"dev": "rollup -c -w",

@@ -47,17 +47,12 @@ "bundle": "rollup -c",

"devDependencies": {
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.2",
"istanbul": "^0.4.5",
"mocha": "^7.1.1",
"mocha-istanbul": "^0.3.0",
"rollup": "^2.6.1",
"@vitest/coverage-v8": "^2.0.4",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
"rollup": "^4.19.0",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-replace": "^2.2.0",
"uglify-js": "^3.9.1"
"uglify-js": "^3.19.0",
"vitest": "^2.0.4"
}
}
# ass-compiler
[![GitHub Action](https://github.com/weizhenye/ass-compiler/workflows/CI/badge.svg)](https://github.com/weizhenye/ass-compiler/actions)
[![Coverage](https://badgen.net/codecov/c/github/weizhenye/ass-compiler?icon=codecov)](https://codecov.io/gh/weizhenye/ass-compiler)
[![Dependencies](https://badgen.net/david/dep/weizhenye/ass-compiler?icon=https://api.iconify.design/si-glyph:connect-2.svg?color=white)](https://david-dm.org/weizhenye/ass-compiler)
[![NPM version](https://badgen.net/npm/v/ass-compiler?icon=npm)](https://www.npmjs.com/package/ass-compiler)
[![License](https://badgen.net/npm/license/ass-compiler?icon=https://api.iconify.design/octicon:law.svg?color=white)](https://github.com/weizhenye/ass-compiler/blob/master/LICENSE)
[![File size](https://badgen.net/bundlephobia/minzip/ass-compiler?icon=https://api.iconify.design/ant-design:file-zip-outline.svg?color=white)](https://bundlephobia.com/result?p=ass-compiler)
[![jsDelivr](https://badgen.net/jsdelivr/hits/npm/ass-compiler?icon=https://api.iconify.design/simple-icons:jsdelivr.svg?color=white)](https://www.jsdelivr.com/package/npm/ass-compiler)
[![GitHub Action](https://img.shields.io/github/actions/workflow/status/weizhenye/ass-compiler/ci.yml?logo=github)](https://github.com/weizhenye/ass-compiler/actions)
[![Codecov](https://img.shields.io/codecov/c/gh/weizhenye/ass-compiler?logo=codecov)](https://codecov.io/gh/weizhenye/ass-compiler)
[![License](https://img.shields.io/npm/l/ass-compiler)](https://github.com/weizhenye/ass-compiler/blob/master/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/ass-compiler?logo=npm)](https://www.npmjs.com/package/ass-compiler)
[![jsDelivr](https://img.shields.io/jsdelivr/npm/hm/ass-compiler?logo=jsdelivr)](https://www.jsdelivr.com/package/npm/ass-compiler)
[![File size](https://img.shields.io/bundlejs/size/ass-compiler)](https://bundlephobia.com/result?p=ass-compiler)

@@ -11,0 +10,0 @@ Parses and compiles ASS subtitle format to easy-to-use data structure.

import { compileText } from './text.js';
import { assign } from '../utils.js';

@@ -25,3 +24,3 @@ export function compileDialogues({ styles, dialogues }) {

minLayer = Math.min(minLayer, dia.Layer);
results.push(assign({
results.push(Object.assign({
layer: dia.Layer,

@@ -28,0 +27,0 @@ start: dia.Start,

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

import { assign } from '../utils.js';
function createCommand(arr) {

@@ -134,3 +132,3 @@ const cmd = {

return assign({ instructions, d: toSVGPath(instructions) }, getViewBox(commands));
return Object.assign({ instructions, d: toSVGPath(instructions) }, getViewBox(commands));
}

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

import { assign } from '../utils.js';
// same as Aegisub

@@ -57,5 +55,5 @@ // https://github.com/Aegisub/Aegisub/blob/master/src/ass_style.h

const result = {};
const styles = [assign({}, defaultStyle, { Name: 'Default' })].concat(style);
const styles = [Object.assign({}, defaultStyle, { Name: 'Default' })].concat(style);
for (let i = 0; i < styles.length; i++) {
const s = assign({}, DEFAULT_STYLE, styles[i]);
const s = Object.assign({}, DEFAULT_STYLE, styles[i]);
// this behavior is same as Aegisub by black-box testing

@@ -62,0 +60,0 @@ if (/^(\*+)Default$/.test(s.Name)) {

import { compileDrawing } from './drawing.js';
import { assign } from '../utils.js';
const tTags = [
'fs', 'clip',
'fs', 'fsp', 'clip',
'c1', 'c2', 'c3', 'c4', 'a1', 'a2', 'a3', 'a4', 'alpha',

@@ -82,3 +81,3 @@ 'fscx', 'fscy', 'fax', 'fay', 'frx', 'fry', 'frz', 'fr',

if (~tTags.indexOf(k) && !(k === 'clip' && !t[k].dots)) {
assign(compiledTag, compileTag(t, k, presets));
Object.assign(compiledTag, compileTag(t, k, presets));
}

@@ -85,0 +84,0 @@ });

import { compileDrawing } from './drawing.js';
import { compileTag } from './tag.js';
import { assign } from '../utils.js';

@@ -14,3 +13,3 @@ const a2an = [

function inheritTag(pTag) {
return JSON.parse(JSON.stringify(assign({}, pTag, {
return JSON.parse(JSON.stringify(Object.assign({}, pTag, {
k: undefined,

@@ -63,3 +62,3 @@ kf: undefined,

} else {
assign(fragment.tag, compiledTag);
Object.assign(fragment.tag, compiledTag);
}

@@ -85,3 +84,3 @@ }

return assign({ alignment, slices }, pos, org, move, fade, clip);
return Object.assign({ alignment, slices }, pos, org, move, fade, clip);
}
import { stringifyInfo, stringifyTime, stringifyEffect } from './stringifier.js';
import { assign, stylesFormat, eventsFormat } from './utils.js';
import { stylesFormat, eventsFormat } from './utils.js';
export function decompileStyle({ style, tag }) {
const obj = assign({}, style, {
const obj = Object.assign({}, style, {
PrimaryColour: `&H${tag.a1}${tag.c1}`,

@@ -120,3 +120,3 @@ SecondaryColour: `&H${tag.a2}${tag.c2}`,

'[Script Info]',
stringifyInfo(assign({}, info, {
stringifyInfo(Object.assign({}, info, {
PlayResX: width,

@@ -123,0 +123,0 @@ PlayResY: height,

@@ -1,6 +0,4 @@

import { assign } from '../utils.js';
export function parseStyle(text, format) {
const values = text.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
return assign({}, ...format.map((fmt, idx) => ({ [fmt]: values[idx] })));
return Object.assign({}, ...format.map((fmt, idx) => ({ [fmt]: values[idx] })));
}

@@ -1,17 +0,2 @@

export const assign = Object.assign || (
/* istanbul ignore next */
function assign(target, ...sources) {
for (let i = 0; i < sources.length; i++) {
if (!sources[i]) continue;
const keys = Object.keys(sources[i]);
for (let j = 0; j < keys.length; j++) {
// eslint-disable-next-line no-param-reassign
target[keys[j]] = sources[i][keys[j]];
}
}
return target;
}
);
export const stylesFormat = ['Name', 'Fontname', 'Fontsize', 'PrimaryColour', 'SecondaryColour', 'OutlineColour', 'BackColour', 'Bold', 'Italic', 'Underline', 'StrikeOut', 'ScaleX', 'ScaleY', 'Spacing', 'Angle', 'BorderStyle', 'Outline', 'Shadow', 'Alignment', 'MarginL', 'MarginR', 'MarginV', 'Encoding'];
export const eventsFormat = ['Layer', 'Start', 'End', 'Style', 'Name', 'MarginL', 'MarginR', 'MarginV', 'Effect', 'Text'];
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