diff --git a/dist/ass.esm.js b/dist/ass.esm.js index 2acced3..55ac889 100644 --- a/dist/ass.esm.js +++ b/dist/ass.esm.js @@ -488,7 +488,7 @@ function compileTag(tag, key, presets) { return null; } 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; } if (key === 'move') { var x1 = value[0]; @@ -546,7 +546,7 @@ function compileTag(tag, key, presets) { return { xshad: value, yshad: value }; } 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 ); } if (key === 'alpha') { return { a1: value, a2: value, a3: value, a4: value }; @@ -575,7 +575,7 @@ function compileTag(tag, key, presets) { }); return { t: { t1: t1$3, t2: t2$3, accel: accel, tag: compiledTag } }; } - return ( obj$2 = {}, obj$2[key] = value, obj$2); + return ( obj$2 = {}, obj$2[key] = value, obj$2 ); } var a2an = [ @@ -841,17 +841,19 @@ function compile(text, options) { }; } -var raf = - window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - (function (cb) { return setTimeout(cb, 50 / 3); }); +var raf = ( + window.requestAnimationFrame + || window.mozRequestAnimationFrame + || window.webkitRequestAnimationFrame + || (function (cb) { return setTimeout(cb, 50 / 3); }) +); -var caf = - window.cancelAnimationFrame || - window.mozCancelAnimationFrame || - window.webkitCancelAnimationFrame || - clearTimeout; +var caf = ( + window.cancelAnimationFrame + || window.mozCancelAnimationFrame + || window.webkitCancelAnimationFrame + || clearTimeout +); function color2rgba(c) { var t = c.match(/(\w\w)(\w\w)(\w\w)(\w\w)/); @@ -901,6 +903,11 @@ var vendor = { clipPath: getVendor('clipPath'), }; +function getStyleRoot(container) { + var rootNode = container.getRootNode ? container.getRootNode() : document; + return rootNode === document ? rootNode.head : rootNode; +} + var strokeTags = ['c3', 'a3', 'c4', 'a4', 'xbord', 'ybord', 'xshad', 'yshad', 'blur', 'be']; var transformTags = ['fscx', 'fscy', 'frx', 'fry', 'frz', 'fax', 'fay']; @@ -1155,10 +1162,12 @@ function getKeyframeString(name, list) { var KeyframeBlockList = function KeyframeBlockList() { this.obj = {}; }; + KeyframeBlockList.prototype.set = function set (keyText, prop, value) { if (!this.obj[keyText]) { this.obj[keyText] = {}; } this.obj[keyText][prop] = value; }; + KeyframeBlockList.prototype.setT = function setT (ref) { var t1 = ref.t1; var t2 = ref.t2; @@ -1176,6 +1185,7 @@ KeyframeBlockList.prototype.setT = function setT (ref) { } this.set('100.000%', prop, to); }; + KeyframeBlockList.prototype.toString = function toString () { var this$1 = this; @@ -1317,10 +1327,10 @@ function getKeyframes() { kbl.setT({ t1: t1, t2: t2, duration: duration, prop: 'letter-spacing', from: from$1, to: to$1 }); } var hasAlpha = ( - tag.a1 !== undefined && - tag.a1 === tag.a2 && - tag.a2 === tag.a3 && - tag.a3 === tag.a4 + tag.a1 !== undefined + && tag.a1 === tag.a2 + && tag.a2 === tag.a3 + && tag.a3 === tag.a4 ); if (tag.c1 || (tag.a1 && !hasAlpha)) { var from$2 = color2rgba(fromTag.a1 + fromTag.c1); @@ -1333,8 +1343,8 @@ function getKeyframes() { kbl.setT({ t1: t1, t2: t2, duration: duration, prop: 'opacity', from: from$3, to: to$3 }); } var hasStroke = strokeTags.some(function (x) { return ( - tag[x] !== undefined && - tag[x] !== (fragment.tag[x] || slice.tag[x]) + tag[x] !== undefined + && tag[x] !== (fragment.tag[x] || slice.tag[x]) ); }); if (hasStroke) { var scale = /Yes/i.test(this$1.info.ScaledBorderAndShadow) ? this$1.scale : 1; @@ -1343,8 +1353,8 @@ function getKeyframes() { kbl.setT({ t1: t1, t2: t2, duration: duration, prop: 'text-shadow', from: from$4, to: to$4 }); } var hasTransfrom = transformTags.some(function (x) { return ( - tag[x] !== undefined && - tag[x] !== (fragment.tag[x] || slice.tag[x]) + tag[x] !== undefined + && tag[x] !== (fragment.tag[x] || slice.tag[x]) ); }); if (hasTransfrom) { var toTag = assign({}, fromTag, tag); @@ -1374,12 +1384,12 @@ function getKeyframes() { function createAnimation(name, duration, delay) { var va = vendor.animation; return ( - va + "animation-name:" + name + ";" + - va + "animation-duration:" + duration + "s;" + - va + "animation-delay:" + delay + "s;" + - va + "animation-timing-function:linear;" + - va + "animation-iteration-count:1;" + - va + "animation-fill-mode:forwards;" + va + "animation-name:" + name + ";" + + va + "animation-duration:" + duration + "s;" + + va + "animation-delay:" + delay + "s;" + + va + "animation-timing-function:linear;" + + va + "animation-iteration-count:1;" + + va + "animation-fill-mode:forwards;" ); } @@ -1419,9 +1429,9 @@ function createDrawing(fragment, styleTag) { ['xlink:href', ("#" + symbolId)], ['filter', ("url(#" + filterId + ")")] ])); $svg.style.cssText = ( - 'position:absolute;' + - "left:" + (minX * scaleX - vbx) + "px;" + - "top:" + (minY * scaleY - vby) + "px;" + 'position:absolute;' + + "left:" + (minX * scaleX - vbx) + "px;" + + "top:" + (minY * scaleY - vby) + "px;" ); return { $svg: $svg, @@ -1467,8 +1477,8 @@ function createDialogue(dialogue) { } if (borderStyle === 3) { cssText += ( - "background-color:" + (color2rgba(tag.a3 + tag.c3)) + ";" + - "box-shadow:" + (createCSSStroke(tag, scale)) + ";" + "background-color:" + (color2rgba(tag.a3 + tag.c3)) + ";" + + "box-shadow:" + (createCSSStroke(tag, scale)) + ";" ); } cssText += tag.b ? ("font-weight:" + (tag.b === 1 ? 'bold' : tag.b) + ";") : ''; @@ -1555,19 +1565,19 @@ function allocate(dialogue) { var re = channel.right.end[y]; return ( (align === 'left' && ( - (le > vct && lw) || - (ce > vct && cw && 2 * width + cw > stageWidth) || - (re > vct && rw && width + rw > stageWidth) - )) || - (align === 'center' && ( - (le > vct && lw && 2 * lw + width > stageWidth) || - (ce > vct && cw) || - (re > vct && rw && 2 * rw + width > stageWidth) - )) || - (align === 'right' && ( - (le > vct && lw && lw + width > stageWidth) || - (ce > vct && cw && 2 * width + cw > stageWidth) || - (re > vct && rw) + (le > vct && lw) + || (ce > vct && cw && 2 * width + cw > stageWidth) + || (re > vct && rw && width + rw > stageWidth) + )) + || (align === 'center' && ( + (le > vct && lw && 2 * lw + width > stageWidth) + || (ce > vct && cw) + || (re > vct && rw && 2 * rw + width > stageWidth) + )) + || (align === 'right' && ( + (le > vct && lw && lw + width > stageWidth) + || (ce > vct && cw && 2 * width + cw > stageWidth) + || (re > vct && rw) )) ); }; @@ -1731,8 +1741,8 @@ function framing() { } var dias = this.dialogues; while ( - this._.index < dias.length && - vct >= dias[this._.index].start + this._.index < dias.length + && vct >= dias[this._.index].start ) { if (vct < dias[this$1._.index].end) { var dia$1 = renderer.call(this$1, dias[this$1._.index]); @@ -1787,8 +1797,8 @@ function seek() { if (!from) { return 0; } for (var i = from; i < to; i++) { if ( - dias[i].end > vct && vct >= dias[i].start || - i && dias[i - 1].end < vct && vct < dias[i].start + dias[i].end > vct && vct >= dias[i].start + || (i && dias[i - 1].end < vct && vct < dias[i].start) ) { return i; } @@ -1847,10 +1857,10 @@ function resize() { this.container.style.cssText = "width:" + cw + "px;height:" + ch + "px;"; var cssText = ( - "width:" + (this.width) + "px;" + - "height:" + (this.height) + "px;" + - "top:" + ((ch - this.height) / 2) + "px;" + - "left:" + ((cw - this.width) / 2) + "px;" + "width:" + (this.width) + "px;" + + "height:" + (this.height) + "px;" + + "top:" + ((ch - this.height) / 2) + "px;" + + "left:" + ((cw - this.width) / 2) + "px;" ); this._.$stage.style.cssText = cssText; this._.$svg.style.cssText = cssText; @@ -1882,9 +1892,6 @@ function init(source, video, options) { }; this._.$svg.appendChild(this._.$defs); this._.$stage.className = 'ASS-stage ASS-animation-paused'; - this._.$animation.type = 'text/css'; - this._.$animation.className = 'ASS-animation'; - document.head.appendChild(this._.$animation); this._.resampling = options.resampling || 'video_height'; @@ -1918,14 +1925,18 @@ function init(source, video, options) { }; this.dialogues = dialogues; - var $style = document.getElementById('ASS-global-style'); + var styleRoot = getStyleRoot(this.container); + var $style = styleRoot.querySelector('#ASS-global-style'); if (!$style) { $style = document.createElement('style'); $style.type = 'text/css'; $style.id = 'ASS-global-style'; $style.appendChild(document.createTextNode(GLOBAL_CSS)); - document.head.appendChild($style); + styleRoot.appendChild($style); } + this._.$animation.type = 'text/css'; + this._.$animation.className = 'ASS-animation'; + styleRoot.appendChild(this._.$animation); resize.call(this); @@ -1953,6 +1964,8 @@ function destroy() { pause.call(this); clear.call(this); unbindEvents.call(this, this._.listener); + + var styleRoot = getStyleRoot(this.container); if (!this._.hasInitContainer) { var isPlay = !this.video.paused; this.container.parentNode.insertBefore(this.video, this.container); @@ -1961,7 +1974,8 @@ function destroy() { this.video.play(); } } - document.head.removeChild(this._.$animation); + styleRoot.removeChild(this._.$animation); + // eslint-disable-next-line no-restricted-syntax for (var key in this$1) { if (Object.prototype.hasOwnProperty.call(this$1, key)) { @@ -1995,21 +2009,27 @@ var ASS = function ASS(source, video, options) { }; var prototypeAccessors = { resampling: { configurable: true } }; + ASS.prototype.resize = function resize$1 () { return resize.call(this); }; + ASS.prototype.show = function show$1 () { return show.call(this); }; + ASS.prototype.hide = function hide$1 () { return hide.call(this); }; + ASS.prototype.destroy = function destroy$1 () { return destroy.call(this); }; + prototypeAccessors.resampling.get = function () { return getter.call(this); }; + prototypeAccessors.resampling.set = function (r) { return setter.call(this, r); }; diff --git a/dist/ass.js b/dist/ass.js index f48a12d..72cef93 100644 --- a/dist/ass.js +++ b/dist/ass.js @@ -494,7 +494,7 @@ return null; } 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; } if (key === 'move') { var x1 = value[0]; @@ -552,7 +552,7 @@ return { xshad: value, yshad: value }; } 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 ); } if (key === 'alpha') { return { a1: value, a2: value, a3: value, a4: value }; @@ -581,7 +581,7 @@ }); return { t: { t1: t1$3, t2: t2$3, accel: accel, tag: compiledTag } }; } - return ( obj$2 = {}, obj$2[key] = value, obj$2); + return ( obj$2 = {}, obj$2[key] = value, obj$2 ); } var a2an = [ @@ -847,17 +847,19 @@ }; } - var raf = - window.requestAnimationFrame || - window.mozRequestAnimationFrame || - window.webkitRequestAnimationFrame || - (function (cb) { return setTimeout(cb, 50 / 3); }); + var raf = ( + window.requestAnimationFrame + || window.mozRequestAnimationFrame + || window.webkitRequestAnimationFrame + || (function (cb) { return setTimeout(cb, 50 / 3); }) + ); - var caf = - window.cancelAnimationFrame || - window.mozCancelAnimationFrame || - window.webkitCancelAnimationFrame || - clearTimeout; + var caf = ( + window.cancelAnimationFrame + || window.mozCancelAnimationFrame + || window.webkitCancelAnimationFrame + || clearTimeout + ); function color2rgba(c) { var t = c.match(/(\w\w)(\w\w)(\w\w)(\w\w)/); @@ -907,6 +909,11 @@ clipPath: getVendor('clipPath'), }; + function getStyleRoot(container) { + var rootNode = container.getRootNode ? container.getRootNode() : document; + return rootNode === document ? rootNode.head : rootNode; + } + var strokeTags = ['c3', 'a3', 'c4', 'a4', 'xbord', 'ybord', 'xshad', 'yshad', 'blur', 'be']; var transformTags = ['fscx', 'fscy', 'frx', 'fry', 'frz', 'fax', 'fay']; @@ -1161,10 +1168,12 @@ var KeyframeBlockList = function KeyframeBlockList() { this.obj = {}; }; + KeyframeBlockList.prototype.set = function set (keyText, prop, value) { if (!this.obj[keyText]) { this.obj[keyText] = {}; } this.obj[keyText][prop] = value; }; + KeyframeBlockList.prototype.setT = function setT (ref) { var t1 = ref.t1; var t2 = ref.t2; @@ -1182,6 +1191,7 @@ } this.set('100.000%', prop, to); }; + KeyframeBlockList.prototype.toString = function toString () { var this$1 = this; @@ -1323,10 +1333,10 @@ kbl.setT({ t1: t1, t2: t2, duration: duration, prop: 'letter-spacing', from: from$1, to: to$1 }); } var hasAlpha = ( - tag.a1 !== undefined && - tag.a1 === tag.a2 && - tag.a2 === tag.a3 && - tag.a3 === tag.a4 + tag.a1 !== undefined + && tag.a1 === tag.a2 + && tag.a2 === tag.a3 + && tag.a3 === tag.a4 ); if (tag.c1 || (tag.a1 && !hasAlpha)) { var from$2 = color2rgba(fromTag.a1 + fromTag.c1); @@ -1339,8 +1349,8 @@ kbl.setT({ t1: t1, t2: t2, duration: duration, prop: 'opacity', from: from$3, to: to$3 }); } var hasStroke = strokeTags.some(function (x) { return ( - tag[x] !== undefined && - tag[x] !== (fragment.tag[x] || slice.tag[x]) + tag[x] !== undefined + && tag[x] !== (fragment.tag[x] || slice.tag[x]) ); }); if (hasStroke) { var scale = /Yes/i.test(this$1.info.ScaledBorderAndShadow) ? this$1.scale : 1; @@ -1349,8 +1359,8 @@ kbl.setT({ t1: t1, t2: t2, duration: duration, prop: 'text-shadow', from: from$4, to: to$4 }); } var hasTransfrom = transformTags.some(function (x) { return ( - tag[x] !== undefined && - tag[x] !== (fragment.tag[x] || slice.tag[x]) + tag[x] !== undefined + && tag[x] !== (fragment.tag[x] || slice.tag[x]) ); }); if (hasTransfrom) { var toTag = assign({}, fromTag, tag); @@ -1380,12 +1390,12 @@ function createAnimation(name, duration, delay) { var va = vendor.animation; return ( - va + "animation-name:" + name + ";" + - va + "animation-duration:" + duration + "s;" + - va + "animation-delay:" + delay + "s;" + - va + "animation-timing-function:linear;" + - va + "animation-iteration-count:1;" + - va + "animation-fill-mode:forwards;" + va + "animation-name:" + name + ";" + + va + "animation-duration:" + duration + "s;" + + va + "animation-delay:" + delay + "s;" + + va + "animation-timing-function:linear;" + + va + "animation-iteration-count:1;" + + va + "animation-fill-mode:forwards;" ); } @@ -1425,9 +1435,9 @@ ['xlink:href', ("#" + symbolId)], ['filter', ("url(#" + filterId + ")")] ])); $svg.style.cssText = ( - 'position:absolute;' + - "left:" + (minX * scaleX - vbx) + "px;" + - "top:" + (minY * scaleY - vby) + "px;" + 'position:absolute;' + + "left:" + (minX * scaleX - vbx) + "px;" + + "top:" + (minY * scaleY - vby) + "px;" ); return { $svg: $svg, @@ -1473,8 +1483,8 @@ } if (borderStyle === 3) { cssText += ( - "background-color:" + (color2rgba(tag.a3 + tag.c3)) + ";" + - "box-shadow:" + (createCSSStroke(tag, scale)) + ";" + "background-color:" + (color2rgba(tag.a3 + tag.c3)) + ";" + + "box-shadow:" + (createCSSStroke(tag, scale)) + ";" ); } cssText += tag.b ? ("font-weight:" + (tag.b === 1 ? 'bold' : tag.b) + ";") : ''; @@ -1561,19 +1571,19 @@ var re = channel.right.end[y]; return ( (align === 'left' && ( - (le > vct && lw) || - (ce > vct && cw && 2 * width + cw > stageWidth) || - (re > vct && rw && width + rw > stageWidth) - )) || - (align === 'center' && ( - (le > vct && lw && 2 * lw + width > stageWidth) || - (ce > vct && cw) || - (re > vct && rw && 2 * rw + width > stageWidth) - )) || - (align === 'right' && ( - (le > vct && lw && lw + width > stageWidth) || - (ce > vct && cw && 2 * width + cw > stageWidth) || - (re > vct && rw) + (le > vct && lw) + || (ce > vct && cw && 2 * width + cw > stageWidth) + || (re > vct && rw && width + rw > stageWidth) + )) + || (align === 'center' && ( + (le > vct && lw && 2 * lw + width > stageWidth) + || (ce > vct && cw) + || (re > vct && rw && 2 * rw + width > stageWidth) + )) + || (align === 'right' && ( + (le > vct && lw && lw + width > stageWidth) + || (ce > vct && cw && 2 * width + cw > stageWidth) + || (re > vct && rw) )) ); }; @@ -1737,8 +1747,8 @@ } var dias = this.dialogues; while ( - this._.index < dias.length && - vct >= dias[this._.index].start + this._.index < dias.length + && vct >= dias[this._.index].start ) { if (vct < dias[this$1._.index].end) { var dia$1 = renderer.call(this$1, dias[this$1._.index]); @@ -1793,8 +1803,8 @@ if (!from) { return 0; } for (var i = from; i < to; i++) { if ( - dias[i].end > vct && vct >= dias[i].start || - i && dias[i - 1].end < vct && vct < dias[i].start + dias[i].end > vct && vct >= dias[i].start + || (i && dias[i - 1].end < vct && vct < dias[i].start) ) { return i; } @@ -1853,10 +1863,10 @@ this.container.style.cssText = "width:" + cw + "px;height:" + ch + "px;"; var cssText = ( - "width:" + (this.width) + "px;" + - "height:" + (this.height) + "px;" + - "top:" + ((ch - this.height) / 2) + "px;" + - "left:" + ((cw - this.width) / 2) + "px;" + "width:" + (this.width) + "px;" + + "height:" + (this.height) + "px;" + + "top:" + ((ch - this.height) / 2) + "px;" + + "left:" + ((cw - this.width) / 2) + "px;" ); this._.$stage.style.cssText = cssText; this._.$svg.style.cssText = cssText; @@ -1888,9 +1898,6 @@ }; this._.$svg.appendChild(this._.$defs); this._.$stage.className = 'ASS-stage ASS-animation-paused'; - this._.$animation.type = 'text/css'; - this._.$animation.className = 'ASS-animation'; - document.head.appendChild(this._.$animation); this._.resampling = options.resampling || 'video_height'; @@ -1924,14 +1931,18 @@ }; this.dialogues = dialogues; - var $style = document.getElementById('ASS-global-style'); + var styleRoot = getStyleRoot(this.container); + var $style = styleRoot.querySelector('#ASS-global-style'); if (!$style) { $style = document.createElement('style'); $style.type = 'text/css'; $style.id = 'ASS-global-style'; $style.appendChild(document.createTextNode(GLOBAL_CSS)); - document.head.appendChild($style); + styleRoot.appendChild($style); } + this._.$animation.type = 'text/css'; + this._.$animation.className = 'ASS-animation'; + styleRoot.appendChild(this._.$animation); resize.call(this); @@ -1959,6 +1970,8 @@ pause.call(this); clear.call(this); unbindEvents.call(this, this._.listener); + + var styleRoot = getStyleRoot(this.container); if (!this._.hasInitContainer) { var isPlay = !this.video.paused; this.container.parentNode.insertBefore(this.video, this.container); @@ -1967,7 +1980,8 @@ this.video.play(); } } - document.head.removeChild(this._.$animation); + styleRoot.removeChild(this._.$animation); + // eslint-disable-next-line no-restricted-syntax for (var key in this$1) { if (Object.prototype.hasOwnProperty.call(this$1, key)) { @@ -2001,21 +2015,27 @@ }; var prototypeAccessors = { resampling: { configurable: true } }; + ASS.prototype.resize = function resize$1 () { return resize.call(this); }; + ASS.prototype.show = function show$1 () { return show.call(this); }; + ASS.prototype.hide = function hide$1 () { return hide.call(this); }; + ASS.prototype.destroy = function destroy$1 () { return destroy.call(this); }; + prototypeAccessors.resampling.get = function () { return getter.call(this); }; + prototypeAccessors.resampling.set = function (r) { return setter.call(this, r); }; diff --git a/dist/ass.min.js b/dist/ass.min.js index 6d65cd7..b40cd89 100644 --- a/dist/ass.min.js +++ b/dist/ass.min.js @@ -1 +1 @@ -(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?module.exports=e():typeof define==="function"&&define.amd?define(e):t.ASS=e()})(this,function(){"use strict";function l(t){var e=t.toLowerCase().trim().split(/\s*;\s*/);if(e[0]==="banner"){return{name:e[0],delay:e[1]*1||0,leftToRight:e[2]*1||0,fadeAwayWidth:e[3]*1||0}}if(/^scroll\s/.test(e[0])){return{name:e[0],y1:Math.min(e[1]*1,e[2]*1),y2:Math.max(e[1]*1,e[2]*1),delay:e[3]*1||0,fadeAwayHeight:e[4]*1||0}}return null}function y(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,e){return!(e&&Number.isNaN(t*1))})})}var t=["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=t.map(function(t){return{name:t,regex:new RegExp("^"+t+"-?\\d")}});function w(t){var e;var a={};for(var r=0;re.length){var r=a.slice(e.length-1).join();a=a.slice(0,e.length-1);a.push(r)}var i={};for(var n=0;n0)a[r]=arguments[r+1];for(var i=0;i-10?1+s/10:1)*a.fs:s*1}}if(e==="t"){var E=s.t1;var T=s.accel;var F=s.tags;var j=s.t2||(a.end-a.start)*1e3;var L={};F.forEach(function(t){var e=Object.keys(t)[0];if(~O.indexOf(e)&&!(e==="clip"&&!t[e].dots)){P(L,z(t,e,a))}});return{t:{t1:E,t2:j,accel:T,tag:L}}}return n={},n[e]=s,n}var R=[null,1,2,3,null,7,8,9,null,4,5,6];var H=["r","a","an","pos","org","move","fade","fad","clip"];function I(t,e){return{name:t,borderStyle:e[t].style.BorderStyle,tag:e[t].tag,fragments:[]}}function S(t){var e=t.styles;var a=t.name;var r=t.parsed;var i=t.start;var n=t.end;var s;var o;var l;var f;var v;var h;var c=[];var d=I(a,e);var p={};for(var u=0;u=s.End){continue}if(!e[s.Style]){s.Style="Default"}var o=e[s.Style].style;var l=S({styles:e,name:s.Style,parsed:s.Text.parsed,start:s.Start,end:s.End});var f=l.alignment||o.Alignment;r=Math.min(r,s.Layer);i.push(P({layer:s.Layer,start:s.Start,end:s.End,margin:{left:s.MarginL||o.MarginL,right:s.MarginR||o.MarginR,vertical:s.MarginV||o.MarginV},effect:s.Effect},l,{alignment:f}))}for(var v=0;v0?1:-1;var u=l>0?1:-1;o=Math.abs(o);l=Math.abs(l);for(var g=Math.max(i,o-i);g=4&&e<=6){o.y=n+r/2}if(e>=7){o.y=n}}for(var l=s.childNodes.length-1;l>=0;l--){var f=s.childNodes[l];if(f.dataset.hasRotate==="true"){var v=o.x-i-f.offsetLeft;var h=o.y-n-f.offsetTop;f.style.cssText+=M.transform+"transform-origin:"+v+"px "+h+"px;"}}}function W(t,e){return"@"+M.animation+"keyframes "+t+" {"+e+"}\n"}var J=function t(){this.obj={}};J.prototype.set=function t(e,a,r){if(!this.obj[e]){this.obj[e]={}}this.obj[e][a]=r};J.prototype.setT=function t(e){var a=e.t1;var r=e.t2;var i=e.duration;var n=e.prop;var s=e.from;var o=e.to;this.set("0.000%",n,s);if(a/g,">").replace(/\s/g," ").replace(/\\h/g," ").replace(/\\N/g,"
").replace(/\\n/g,e===2?"
":" ")}function et(t){var d=this;var e=document.createElement("div");e.className="ASS-dialogue";var p=document.createDocumentFragment();var a=t.slices;var u=t.start;var g=t.end;a.forEach(function(h){var c=h.borderStyle;h.fragments.forEach(function(i){var t=i.text;var n=i.drawing;var e=i.animationName;var a=P({},h.tag,i.tag);var s="display:inline-block;";var r=d.video.currentTime;if(!n){s+='font-family:"'+a.fn+'",Arial;';s+="font-size:"+d.scale*G(a.fn,a.fs)+"px;";s+="color:"+q(a.a1+a.c1)+";";var o=/Yes/i.test(d.info.ScaledBorderAndShadow)?d.scale:1;if(c===1){s+="text-shadow:"+X(a,o)+";"}if(c===3){s+="background-color:"+q(a.a3+a.c3)+";"+"box-shadow:"+X(a,o)+";"}s+=a.b?"font-weight:"+(a.b===1?"bold":a.b)+";":"";s+=a.i?"font-style:italic;":"";s+=a.u||a.s?"text-decoration:"+(a.u?"underline":"")+" "+(a.s?"line-through":"")+";":"";s+=a.fsp?"letter-spacing:"+a.fsp+"px;":"";if(a.q===1||a.q===0||a.q===3){s+="word-break:break-all;white-space:normal;"}if(a.q===2){s+="word-break:normal;white-space:nowrap;"}}var l=D.some(function(t){return/^fsc[xy]$/.test(t)?a[t]!==100:!!a[t]});if(l){s+=M.transform+"transform:"+V(a)+";";if(!n){s+="transform-style:preserve-3d;word-break:normal;white-space:nowrap;"}}if(e){s+=K(e,g-u,Math.min(0,u-r))}if(n&&a.pbo){var f=d.scale*-a.pbo*(a.fscy||100)/100;s+="vertical-align:"+f+"px;"}var v=/"fr[xyz]":[^0]/.test(JSON.stringify(a));tt(t,a.q).split("
").forEach(function(t,e){var a=document.createElement("span");a.dataset.hasRotate=v;if(n){var r=Q.call(d,i,h.tag);a.style.cssText=r.cssText;a.appendChild(r.$svg)}else{if(e){p.appendChild(document.createElement("br"))}if(!t){return}a.innerHTML=t}a.style.cssText+=s;p.appendChild(a)})})});e.appendChild(p);return e}function at(t){var e=t.layer;var a=t.margin;var o=t.width;var r=t.height;var i=t.alignment;var n=t.end;var l=this.width-(this.scale*(a.left+a.right)|0);var s=this.height;var f=this.scale*a.vertical|0;var v=this.video.currentTime*100;this._.space[e]=this._.space[e]||{left:{width:new Uint16Array(s+1),end:new Uint16Array(s+1)},center:{width:new Uint16Array(s+1),end:new Uint16Array(s+1)},right:{width:new Uint16Array(s+1),end:new Uint16Array(s+1)}};var h=this._.space[e];var c=["right","left","center"][i%3];var d=function(t){var e=h.left.width[t];var a=h.center.width[t];var r=h.right.width[t];var i=h.left.end[t];var n=h.center.end[t];var s=h.right.end[t];return c==="left"&&(i>v&&e||n>v&&a&&2*o+a>l||s>v&&r&&o+r>l)||c==="center"&&(i>v&&e&&2*e+o>l||n>v&&a||s>v&&r&&2*r+o>l)||c==="right"&&(i>v&&e&&e+o>l||n>v&&a&&2*o+a>l||s>v&&r)};var p=0;var u=0;var g=function(t){p=d(t)?0:p+1;if(p>=r){u=t;return true}return false};if(i<=3){for(var m=s-f-1;m>f;m--){if(g(m)){break}}}else if(i>=7){for(var y=f+1;y>1;x3){u-=r-1}for(var w=u;w=4&&r<=6){f=(this.height-n)/2}if(r>=7){f=s.vertical}l=e.lefttoright?-i:this.width}}else if(t.pos||a){var v=t.pos||{x:0,y:0};if(r%3===1){l=this.scale*v.x}if(r%3===2){l=this.scale*v.x-i/2}if(r%3===0){l=this.scale*v.x-i}if(r<=3){f=this.scale*v.y-n}if(r>=4&&r<=6){f=this.scale*v.y-n/2}if(r>=7){f=this.scale*v.y}}else{if(r%3===1){l=0}if(r%3===2){l=(this.width-i)/2}if(r%3===0){l=this.width-i-this.scale*s.right}var h=o.some(function(t){return t.fragments.some(function(t){var e=t.animationName;return e})});if(h){if(r<=3){f=this.height-n-s.vertical}if(r>=4&&r<=6){f=(this.height-n)/2}if(r>=7){f=s.vertical}}else{f=at.call(this,t)}}return{x:l,y:f}}function it(t){var e=t.layer;var a=t.start;var r=t.end;var i=t.alignment;var n=t.effect;var s=t.pos;var o=t.margin;var l=t.animationName;var f=t.width;var v=t.height;var h=t.x;var c=t.y;var d=this.video.currentTime;var p="";if(e){p+="z-index:"+e+";"}if(l){p+=K(l,r-a,Math.min(0,a-d))}p+="text-align:"+["right","left","center"][i%3]+";";if(!n){var u=this.width-this.scale*(o.left+o.right);p+="max-width:"+u+"px;";if(!s){if(i%3===1){p+="margin-left:"+this.scale*o.left+"px;"}if(i%3===0){p+="margin-right:"+this.scale*o.right+"px;"}if(f>this.width-this.scale*(o.left+o.right)){p+="margin-left:"+this.scale*o.left+"px;";p+="margin-right:"+this.scale*o.right+"px;"}}}p+="width:"+f+"px;height:"+v+"px;left:"+h+"px;top:"+c+"px;";return p}function nt(t){var e=et.call(this,t);P(t,{$div:e});this._.$stage.appendChild(e);var a=e.getBoundingClientRect();var r=a.width;var i=a.height;P(t,{width:r,height:i});P(t,rt.call(this,t));e.style.cssText=it.call(this,t);j(t);N.call(this,t);return t}function st(){var t=this;var e=this.video.currentTime;for(var a=this._.stagings.length-1;a>=0;a--){var r=t._.stagings[a];var i=r.end;if(r.effect&&/scroll/.test(r.effect.name)){var n=r.effect;var s=n.y1;var o=n.y2;var l=n.delay;var f=((o||t._.resampledRes.height)-s)/(1e3/l);i=Math.min(i,r.start+f)}if(i=v[this._.index].start){if(ei[e+t>>1].end){t=e+t>>1}if(!t){return 0}for(var a=t;ar&&r>=i[a].start||a&&i[a-1].ende.length){var r=a.slice(e.length-1).join();a=a.slice(0,e.length-1);a.push(r)}var i={};for(var n=0;n0)a[r]=arguments[r+1];for(var i=0;i-10?1+s/10:1)*a.fs:s*1}}if(e==="t"){var T=s.t1;var E=s.accel;var F=s.tags;var j=s.t2||(a.end-a.start)*1e3;var L={};F.forEach(function(t){var e=Object.keys(t)[0];if(~O.indexOf(e)&&!(e==="clip"&&!t[e].dots)){P(L,R(t,e,a))}});return{t:{t1:T,t2:j,accel:E,tag:L}}}return n={},n[e]=s,n}var z=[null,1,2,3,null,7,8,9,null,4,5,6];var H=["r","a","an","pos","org","move","fade","fad","clip"];function I(t,e){return{name:t,borderStyle:e[t].style.BorderStyle,tag:e[t].tag,fragments:[]}}function S(t){var e=t.styles;var a=t.name;var r=t.parsed;var i=t.start;var n=t.end;var s;var o;var l;var f;var v;var h;var c=[];var d=I(a,e);var p={};for(var u=0;u=s.End){continue}if(!e[s.Style]){s.Style="Default"}var o=e[s.Style].style;var l=S({styles:e,name:s.Style,parsed:s.Text.parsed,start:s.Start,end:s.End});var f=l.alignment||o.Alignment;r=Math.min(r,s.Layer);i.push(P({layer:s.Layer,start:s.Start,end:s.End,margin:{left:s.MarginL||o.MarginL,right:s.MarginR||o.MarginR,vertical:s.MarginV||o.MarginV},effect:s.Effect},l,{alignment:f}))}for(var v=0;v0?1:-1;var u=l>0?1:-1;o=Math.abs(o);l=Math.abs(l);for(var g=Math.max(i,o-i);g=4&&e<=6){o.y=n+r/2}if(e>=7){o.y=n}}for(var l=s.childNodes.length-1;l>=0;l--){var f=s.childNodes[l];if(f.dataset.hasRotate==="true"){var v=o.x-i-f.offsetLeft;var h=o.y-n-f.offsetTop;f.style.cssText+=M.transform+"transform-origin:"+v+"px "+h+"px;"}}}function W(t,e){return"@"+M.animation+"keyframes "+t+" {"+e+"}\n"}var J=function t(){this.obj={}};J.prototype.set=function t(e,a,r){if(!this.obj[e]){this.obj[e]={}}this.obj[e][a]=r};J.prototype.setT=function t(e){var a=e.t1;var r=e.t2;var i=e.duration;var n=e.prop;var s=e.from;var o=e.to;this.set("0.000%",n,s);if(a/g,">").replace(/\s/g," ").replace(/\\h/g," ").replace(/\\N/g,"
").replace(/\\n/g,e===2?"
":" ")}function at(t){var d=this;var e=document.createElement("div");e.className="ASS-dialogue";var p=document.createDocumentFragment();var a=t.slices;var u=t.start;var g=t.end;a.forEach(function(h){var c=h.borderStyle;h.fragments.forEach(function(i){var t=i.text;var n=i.drawing;var e=i.animationName;var a=P({},h.tag,i.tag);var s="display:inline-block;";var r=d.video.currentTime;if(!n){s+='font-family:"'+a.fn+'",Arial;';s+="font-size:"+d.scale*G(a.fn,a.fs)+"px;";s+="color:"+q(a.a1+a.c1)+";";var o=/Yes/i.test(d.info.ScaledBorderAndShadow)?d.scale:1;if(c===1){s+="text-shadow:"+X(a,o)+";"}if(c===3){s+="background-color:"+q(a.a3+a.c3)+";"+"box-shadow:"+X(a,o)+";"}s+=a.b?"font-weight:"+(a.b===1?"bold":a.b)+";":"";s+=a.i?"font-style:italic;":"";s+=a.u||a.s?"text-decoration:"+(a.u?"underline":"")+" "+(a.s?"line-through":"")+";":"";s+=a.fsp?"letter-spacing:"+a.fsp+"px;":"";if(a.q===1||a.q===0||a.q===3){s+="word-break:break-all;white-space:normal;"}if(a.q===2){s+="word-break:normal;white-space:nowrap;"}}var l=D.some(function(t){return/^fsc[xy]$/.test(t)?a[t]!==100:!!a[t]});if(l){s+=M.transform+"transform:"+V(a)+";";if(!n){s+="transform-style:preserve-3d;word-break:normal;white-space:nowrap;"}}if(e){s+=Q(e,g-u,Math.min(0,u-r))}if(n&&a.pbo){var f=d.scale*-a.pbo*(a.fscy||100)/100;s+="vertical-align:"+f+"px;"}var v=/"fr[xyz]":[^0]/.test(JSON.stringify(a));et(t,a.q).split("
").forEach(function(t,e){var a=document.createElement("span");a.dataset.hasRotate=v;if(n){var r=tt.call(d,i,h.tag);a.style.cssText=r.cssText;a.appendChild(r.$svg)}else{if(e){p.appendChild(document.createElement("br"))}if(!t){return}a.innerHTML=t}a.style.cssText+=s;p.appendChild(a)})})});e.appendChild(p);return e}function rt(t){var e=t.layer;var a=t.margin;var o=t.width;var r=t.height;var i=t.alignment;var n=t.end;var l=this.width-(this.scale*(a.left+a.right)|0);var s=this.height;var f=this.scale*a.vertical|0;var v=this.video.currentTime*100;this._.space[e]=this._.space[e]||{left:{width:new Uint16Array(s+1),end:new Uint16Array(s+1)},center:{width:new Uint16Array(s+1),end:new Uint16Array(s+1)},right:{width:new Uint16Array(s+1),end:new Uint16Array(s+1)}};var h=this._.space[e];var c=["right","left","center"][i%3];var d=function(t){var e=h.left.width[t];var a=h.center.width[t];var r=h.right.width[t];var i=h.left.end[t];var n=h.center.end[t];var s=h.right.end[t];return c==="left"&&(i>v&&e||n>v&&a&&2*o+a>l||s>v&&r&&o+r>l)||c==="center"&&(i>v&&e&&2*e+o>l||n>v&&a||s>v&&r&&2*r+o>l)||c==="right"&&(i>v&&e&&e+o>l||n>v&&a&&2*o+a>l||s>v&&r)};var p=0;var u=0;var g=function(t){p=d(t)?0:p+1;if(p>=r){u=t;return true}return false};if(i<=3){for(var m=s-f-1;m>f;m--){if(g(m)){break}}}else if(i>=7){for(var y=f+1;y>1;x3){u-=r-1}for(var w=u;w=4&&r<=6){f=(this.height-n)/2}if(r>=7){f=s.vertical}l=e.lefttoright?-i:this.width}}else if(t.pos||a){var v=t.pos||{x:0,y:0};if(r%3===1){l=this.scale*v.x}if(r%3===2){l=this.scale*v.x-i/2}if(r%3===0){l=this.scale*v.x-i}if(r<=3){f=this.scale*v.y-n}if(r>=4&&r<=6){f=this.scale*v.y-n/2}if(r>=7){f=this.scale*v.y}}else{if(r%3===1){l=0}if(r%3===2){l=(this.width-i)/2}if(r%3===0){l=this.width-i-this.scale*s.right}var h=o.some(function(t){return t.fragments.some(function(t){var e=t.animationName;return e})});if(h){if(r<=3){f=this.height-n-s.vertical}if(r>=4&&r<=6){f=(this.height-n)/2}if(r>=7){f=s.vertical}}else{f=rt.call(this,t)}}return{x:l,y:f}}function nt(t){var e=t.layer;var a=t.start;var r=t.end;var i=t.alignment;var n=t.effect;var s=t.pos;var o=t.margin;var l=t.animationName;var f=t.width;var v=t.height;var h=t.x;var c=t.y;var d=this.video.currentTime;var p="";if(e){p+="z-index:"+e+";"}if(l){p+=Q(l,r-a,Math.min(0,a-d))}p+="text-align:"+["right","left","center"][i%3]+";";if(!n){var u=this.width-this.scale*(o.left+o.right);p+="max-width:"+u+"px;";if(!s){if(i%3===1){p+="margin-left:"+this.scale*o.left+"px;"}if(i%3===0){p+="margin-right:"+this.scale*o.right+"px;"}if(f>this.width-this.scale*(o.left+o.right)){p+="margin-left:"+this.scale*o.left+"px;";p+="margin-right:"+this.scale*o.right+"px;"}}}p+="width:"+f+"px;height:"+v+"px;left:"+h+"px;top:"+c+"px;";return p}function st(t){var e=at.call(this,t);P(t,{$div:e});this._.$stage.appendChild(e);var a=e.getBoundingClientRect();var r=a.width;var i=a.height;P(t,{width:r,height:i});P(t,it.call(this,t));e.style.cssText=nt.call(this,t);L(t);T.call(this,t);return t}function ot(){var t=this;var e=this.video.currentTime;for(var a=this._.stagings.length-1;a>=0;a--){var r=t._.stagings[a];var i=r.end;if(r.effect&&/scroll/.test(r.effect.name)){var n=r.effect;var s=n.y1;var o=n.y2;var l=n.delay;var f=((o||t._.resampledRes.height)-s)/(1e3/l);i=Math.min(i,r.start+f)}if(i=v[this._.index].start){if(ei[e+t>>1].end){t=e+t>>1}if(!t){return 0}for(var a=t;ar&&r>=i[a].start||a&&i[a-1].end