blob: 88516afd722cbd93cf902aaee2127043cae1e0d1 [file] [log] [blame]
var subframeEnabled = false;
var supportsPath2D = typeof Path2D === 'function';
//supportsPath2D = false;
var cachedColors = {};
var colorMap = [];
var body;
function styleDiv(element){
element.style.position = 'absolute';
element.style.top = 0;
element.style.left = 0;
element.style.display = 'block';
element.style.verticalAlign = 'top';
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 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;
}
function rgbToHex(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(!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]]){
if(alpha != undefined){
colorArr[3] = alpha;
}
colorMap[colorArr[0]][colorArr[1]][colorArr[2]] = 'rgba('+colorArr.join(',')+')';
}
return colorMap[colorArr[0]][colorArr[1]][colorArr[2]];
}
}());
function createColorMap(){
var i;
var hex;
for(i=0;i<256;i+=1){
hex = i.toString(16);
colorMap[i] = hex.length == 1 ? '0' + hex : hex;
}
}
createColorMap();