Skip to content

Commit

Permalink
0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Oct 2, 2018
1 parent c755467 commit f45ba45
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 120 deletions.
138 changes: 79 additions & 59 deletions dist/ass.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)/);
Expand Down Expand Up @@ -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'];

Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;"
);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) + ";") : '';
Expand Down Expand Up @@ -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)
))
);
};
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
};
Expand Down
Loading

0 comments on commit f45ba45

Please sign in to comment.