blob: c1ac63b05c4d994842b0ec0f3a97b1259f1197d2 [file] [log] [blame]
var subframeEnabled = false;
var cachedColors = {};
var bm_rounder = Math.round;
var bm_rnd;
var bm_pow = Math.pow;
var bm_sqrt = Math.sqrt;
var bm_abs = Math.abs;
var bm_floor = Math.floor;
var bm_max = Math.max;
var bm_min = Math.min;
var defaultCurveSegments = 50;
var degToRads = Math.PI/180;
function roundValues(flag){
if(flag){
bm_rnd = Math.round;
}else{
bm_rnd = function(val){
return val;
};
}
}
roundValues(false);
function styleDiv(element){
element.style.position = 'absolute';
element.style.top = 0;
element.style.left = 0;
element.style.display = 'block';
element.style.transformOrigin = '0 0';
element.style.backfaceVisibility = element.style.webkitBackfaceVisibility = 'hidden';
//element.style.transformStyle = element.style.webkitTransformStyle = "preserve-3d";
styleUnselectableDiv(element);
}
function styleUnselectableDiv(element){
element.style.userSelect = 'none';
element.style.MozUserSelect = 'none';
element.style.webkitUserSelect = 'none';
element.style.oUserSelect = 'none';
}
function BMEnterFrameEvent(n,c,t,d){
this.type = n;
this.currentTime = c;
this.totalTime = t;
this.direction = d < 0 ? -1:1;
}
function BMCompleteEvent(n,d){
this.type = n;
this.direction = d < 0 ? -1:1;
}
function BMCompleteLoopEvent(n,c,t,d){
this.type = n;
this.currentLoop = c;
this.totalLoops = t;
this.direction = d < 0 ? -1:1;
}
function BMSegmentStartEvent(n,f,t){
this.type = n;
this.firstFrame = f;
this.totalFrames = t;
}
function _addEventListener(eventName, callback){
if (!this._cbs[eventName]){
this._cbs[eventName] = [];
}
this._cbs[eventName].push(callback);
}
function _removeEventListener(eventName,callback){
if (!callback){
this._cbs[eventName] = null;
}else if(this._cbs[eventName]){
var i = 0, len = this._cbs[eventName].length;
while(i<len){
if(this._cbs[eventName][i] === callback){
this._cbs[eventName].splice(i,1);
i -=1;
len -= 1;
}
i += 1;
}
if(!this._cbs[eventName].length){
this._cbs[eventName] = null;
}
}
}
function _triggerEvent(eventName, args){
if (this._cbs[eventName]) {
var len = this._cbs[eventName].length;
for (var i = 0; i < len; i++){
this._cbs[eventName][i](args);
}
}
}
function randomString(length, chars){
if(chars === undefined){
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
}
var i;
var result = '';
for (i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? '0' + hex : hex;
}
var rgbToHex = (function(){
var colorMap = [];
var i;
var hex;
for(i=0;i<256;i+=1){
hex = i.toString(16);
colorMap[i] = hex.length == 1 ? '0' + hex : hex;
}
return function(r, g, b) {
if(r<0){
r = 0;
}
if(g<0){
g = 0;
}
if(b<0){
b = 0;
}
return '#' + colorMap[r] + colorMap[g] + colorMap[b];
};
}());
function fillToRgba(hex,alpha){
if(!cachedColors[hex]){
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
cachedColors[hex] = parseInt(result[1], 16)+','+parseInt(result[2], 16)+','+parseInt(result[3], 16);
}
return 'rgba('+cachedColors[hex]+','+alpha+')';
}
var fillColorToString = (function(){
var colorMap = [];
return function(colorArr,alpha){
if(alpha !== undefined){
colorArr[3] = alpha;
}
if(!colorMap[colorArr[0]]){
colorMap[colorArr[0]] = {};
}
if(!colorMap[colorArr[0]][colorArr[1]]){
colorMap[colorArr[0]][colorArr[1]] = {};
}
if(!colorMap[colorArr[0]][colorArr[1]][colorArr[2]]){
colorMap[colorArr[0]][colorArr[1]][colorArr[2]] = {};
}
if(!colorMap[colorArr[0]][colorArr[1]][colorArr[2]][colorArr[3]]){
colorMap[colorArr[0]][colorArr[1]][colorArr[2]][colorArr[3]] = 'rgba(' + colorArr.join(',')+')';
}
return colorMap[colorArr[0]][colorArr[1]][colorArr[2]][colorArr[3]];
};
}());
function RenderedFrame(tr,o) {
this.tr = tr;
this.o = o;
}
function LetterProps(o,sw,sc,fc,m,p){
this.o = o;
this.sw = sw;
this.sc = sc;
this.fc = fc;
this.m = m;
this.props = p;
}
function iterateDynamicProperties(num){
var i, len = this.dynamicProperties;
for(i=0;i<len;i+=1){
this.dynamicProperties[i].getValue(num);
}
}