1834,6,154,17,533,26,201,32,235,40,782,40,315,40,315,36,1029,24,213,22,107,20,543,20,281,22,336,28,808,25,1256,24,615,27,397,24,142,26,268,22,3718,22,6543,22,3166,38,1994,36,2830,26,1051,27,1741,22,3525,22,3925,22,4123,36,1755,34,2503,27,625,27,1695,27,1846,27,1774,27,1727,27,1821,27,1281,27,1957,27,688,28,884,8,147,35,655,47,431,54,270,33,3850,20,110,30,433,30,313,32,654,33,654,32,401,28,522,28,504,32,433,32,275,32,766,33,741,32,504,29,309,29,717,30,424,30,629,30,165,30,840,30,470,29,247,29,68,33,504,22,412,25,1741,21,5381,21,882,27,655,27,624,27,611,27,840,27,1659,27,1700,25,474,25,615,29,1697,29,1111,29,3021,29,2908,25,2703,25,2795,25,1999,25,2337,25,2456,25,1667,29,576,29,988,29,380,27,380,29,2965,29,3119,29,3673,29,2219,29,2172,29,3255,29,6100,29,3119,29,2826,29,3567,26,1283,31,1724,26,860,31,718,26,789,31,759,26,1348,31,4882,26,4939,31,726,26,2080,31,839,26,791,26,2655,26,1016,26,2192,31,1256,26,1004,26,1150,26,2094,31,2951,26,1208,26,1836,26,2807,27,3221,27,1081,27,2952,27,627,27,507,27,696,27,751,27,731,27,2445,27,923,27,1001,27,1767,27,1032,24,3391,28,1311,30,654,30,1516,31,692,30,654,28,569,34,654,36,494,30,654,28,1164,32,1109,24,252,27,299,23,3237,23,622,27,374,27,1533,27,1655,27,1798,27,1652,27,1321,27,858,27,477,27,473,27,477,27,448,27,1256,27,392,27,1134,27,1193,27,448,28,880,28,779,28,845,28,1393,28,813,28,1033,28,716,28,1073,28,3613,28,1239,28,1137,28,685,28,1088,28,1066,28,1420,28,771,28,1115,28,817,28,1842,28,1390,28,945,28,1419,28,1335,27,1274,27,1004,27,1776,27,38502,32,1228,32,773,32,935,32,371,32,547,27,846,27,1453,27,668,27,1216,27,550,27,946,27,407,27,650,27,1430,27,648,27,761,27,646,27,541,29,5038,29,2658,29,2831,29,2680,29,5587,29,1894,29,2790,29,2742,29,8643,29,2564,29,3278,29,1476,29,3170,29,1536,29,1686,29,1692,29,1241,29,2540,29,3127,29,2370,29,1287,29,3102,29,6173,27,2790
_info
{"project":"lsg-avatar","branch":"master","version":71,"versionDate":"2024-05-23T08:08:36.000Z","fromVersion":0,"reset":true,"checksumDocs":"242-405406"}
avatar/avatar.ls
(function(){
return {
toLSG: include('toLSG/toLSG'),
toLS: include('toLS/toLS'),
toJS: include('toJS/toJS'),
toIMG: include('toIMG/toIMG'),
validate: include('validate/validate'),
random: include('random/random'),
definition: include('definition/definition'),
'default': include('default/default'),
getOptionColor: include('getOptionColor/getOptionColor'),
getOptionSvg: include('getOptionSvg/getOptionSvg'),
getOptionLabel: include('getOptionLabel/getOptionLabel'),
getCategorySvg: include('getCategorySvg/getCategorySvg')
};
})();
avatar/default/default.ls
(function(){
return function(set){
var def;
def = include("/sets/" + set + "/default");
if (!def) {
return console.error("lsg-avatar default: could not find '" + set + "' set");
}
return def;
};
})();
avatar/definition/definition.ls
(function(){
return function(set){
var definition;
definition = include("/sets/" + set + "/definition");
if (!definition) {
return console.error("lsg-avatar definition: could not find '" + set + "' set");
}
return definition;
};
})();
avatar/getCategorySvg/getCategorySvg.ls
(function(){
return function(o, cat){
var set, def, category, svg, colors, opt, ref$, id, color;
set = o.set;
def = include("/sets/" + o.set + "/definition");
if (!def) {
return console.info("lsg-avatar getCategorySvg: no set '" + set + "'");
}
if (!def[o.set].categories[cat]) {
return console.info("lsg-avatar getCategorySvg: no cat '" + cat + "'");
}
category = def[o.set].categories[cat];
svg = null;
colors = null;
for (opt in ref$ = o[cat]) {
id = ref$[opt];
color = Avatar.getOptionColor(set, cat, opt, id);
if (color) {
if (!colors) {
colors = [];
}
colors.push(color);
}
}
for (opt in ref$ = o[cat]) {
id = ref$[opt];
if (Avatar.getOptionSvg(set, cat, opt, id, colors)) {
svg = Avatar.getOptionSvg(set, cat, opt, id, colors);
}
}
if (!svg) {} else {
return svg;
}
};
})();
avatar/getOptionColor/getOptionColor.ls
(function(){
return function(set, cat, opt, id){
var def, ref$;
def = include("/sets/" + set + "/definition");
if (!def) {
return console.info("lsg-avatar getOptionColor: no set '" + set + "'");
}
return (ref$ = _.find(def[set].categories[cat].options[opt].ids, {
id: id
})) != null ? ref$.color : void 8;
};
})();
avatar/getOptionLabel/getOptionLabel.ls
(function(){
return function(set, cat, opt, id){
var def, ref$;
def = include("/sets/" + set + "/definition");
if (!def) {
return console.info("lsg-avatar getOptionLabel: no set '" + set + "'");
}
return (ref$ = _.find(def[set].categories[cat].options[opt].ids, {
id: id
})) != null ? ref$.label : void 8;
};
})();
avatar/getOptionSvg/getOptionSvg.ls
(function(){
return function(set, cat, opt, id, colors){
var def, ref$, svg, $svg, i$, len$, i, color, div;
def = include("/sets/" + set + "/definition");
if (!def) {
return console.info("lsg-avatar getOptionSvg: no set '" + set + "'");
}
colors = colors || [Color.black, Color.grey[500]];
if (!_.isArray(colors)) {
colors = [colors];
}
id = _.find((ref$ = def[set].categories[cat].options[opt]) != null ? ref$.ids : void 8, {
id: id
});
if (!(id.svg || id.front || id.back)) {
return null;
}
if (id.back) {
svg = include("/sets/" + set + "/svg/" + id.back.svg + ".svg");
} else if (id.front) {
svg = include("/sets/" + set + "/svg/" + id.front.svg + ".svg");
} else {
svg = include("/sets/" + set + "/svg/" + id.svg + ".svg");
}
$svg = $(svg);
$svg.css({
width: '100%',
height: '100%'
});
if (colors != null && colors.length) {
for (i$ = 0, len$ = colors.length; i$ < len$; ++i$) {
i = i$;
color = colors[i$];
id = "#color" + (i + 1);
$svg.find(id).attr({
fill: color
});
}
}
div = $('
').append($svg);
return div;
};
})();
avatar/random/random.ls
(function(){
return function(set){
var random;
random = include("/sets/" + set + "/random")();
if (!random) {
return console.error("lsg-avatar random: could not find '" + set + "' set");
}
return random;
};
})();
avatar/toIMG/toIMG.ls
(function(){
return function(avatar){
return include("/lib/util/avatarWithCache/avatar")(avatar);
};
})();
avatar/toJS/toJS.ls
(function(){
return function(string){
var error, js;
try {
string = Livescript.compile(string, {
bare: true
}).replace('// Generated by LiveScript 1.4.0\n', '');
} catch (e$) {
error = e$;
setTimeout(function(){
return helpers.errorHandler(error, '/../lsg-avatar/avatar/toJS/toJS/');
});
}
try {
js = eval(string);
} catch (e$) {
error = e$;
setTimeout(function(){
return helpers.errorHandler(error, '/../lsg-avatar/avatar/toJS/toJS/');
});
}
if (!js) {
return;
}
if (!_.isArray(js.objects)) {
js.objects = [js.objects];
}
return js;
};
})();
avatar/toLS/toLS.ls
(function(){
return function(o){
var errors, ls, k, v, k2, v2;
errors = [];
ls = '';
for (k in o) {
v = o[k];
if (_.isString(v)) {
ls += k + ": '" + v + "'\n";
} else {
ls += k + ": ";
for (k2 in v) {
v2 = v[k2];
ls += k2 + ": '" + v2 + "' ";
}
ls += '\n';
}
}
return ls;
};
})();
avatar/toLSG/toLSG.ls
(function(){
return function(avatar){
var set, parser, lsg;
set = avatar.set;
parser = set === 'human'
? include("/sets/human/parser")
: set === 'monster' ? include("/sets/monster/parser") : void 8;
if (!parser) {
return console.error("lsg-avatar parser: could not find '" + set + "' set");
}
lsg = parser(avatar);
return lsg;
};
})();
avatar/validate/validate.ls
(function(){
return function(o){
var set, def, d, o2, errors, catId, ref$, cat, optId, ref1$, opt, id, ref2$;
o = o || {};
set = o.set || "human";
def = include("/sets/" + set + "/definition");
if (!def) {
return console.info("lsg-avatar validate: no def '" + set + "'");
}
d = include("/sets/" + set + "/default");
o2 = {
set: set
};
errors = [];
for (catId in ref$ = def[set].categories) {
cat = ref$[catId];
o2[catId] = {};
for (optId in ref1$ = cat.options) {
opt = ref1$[optId];
id = _.find(opt.ids, {
id: (ref2$ = o[catId]) != null ? ref2$[optId] : void 8
});
if (!id) {
errors.push(catId + "/" + optId);
id = _.find(opt.ids, {
id: d[catId][optId]
});
}
o2[catId][optId] = id.id;
}
}
if (_.isEqual(o, o2)) {
return {
avatar: o
};
} else {
return {
error: true,
errors: errors,
avatar: o2
};
}
};
})();
avatarTalk/avatarTalk.ls
(function(){
return function(o){
var ref$, ref1$, interval, active, update, reset, setSize, stop, start, toggle, div, mouth;
o = o || {};
o.size = o.size || "2.5em";
o.type = (ref$ = o.type) === "m1" || ref$ === "m2" || ref$ === "m3" || ref$ === "f1" || ref$ === "f2" || ref$ === "f3"
? o.type
: ((ref$ = o.type) != null ? ref$.indexOf("m") : void 8) === 0
? "m2"
: ((ref1$ = o.type) != null ? ref1$.indexOf("f") : void 8) === 0 ? "f1" : "m1";
interval = null;
active = false;
update = include("update/update")(o);
reset = function(){
return update(null, null, 0);
};
setSize = function(s){
o.size = s;
return div.css({
width: o.size,
height: o.size
});
};
stop = function(){
active = false;
clearInterval(interval);
return reset();
};
start = function(){
active = true;
clearInterval(interval);
return interval = setInterval(update, 100);
};
toggle = function(){
active = !active;
if (active) {
return start();
} else {
return stop();
}
};
div = Div().addClass("avatar avatarTalk").css({
width: o.size,
height: o.size
}).append(include("face/face")(o), include("eyes/eyes")(o), mouth = include("mouth/mouth")(o));
div.update = update;
div.reset = reset;
div.setSize = setSize;
div.start = start;
div.stop = stop;
div.toggle = toggle;
return div;
};
})();
avatarTalk/eyes/eyes.ls
(function(){
return function(o){
var svg, last, getDuration, duration, blink;
svg = null;
last = new Date();
getDuration = function(){
return Math.round(Math.random() * 10000 + 2000);
};
duration = getDuration();
blink = function(){
return requestAnimationFrame(function(){
var t;
if (!svg.isVisible()) {
return;
}
t = new Date();
if (t - last > duration) {
last = t;
duration = getDuration();
svg.replaceWith(svg = include("svg/svg")(o, true));
setTimeout(function(){
return svg.replaceWith(svg = include("svg/svg")(o));
}, 100);
}
return blink();
});
};
svg = include("svg/svg")(o);
blink();
return svg;
};
})();
avatarTalk/eyes/svg/svg.ls
(function(){
return function(o, closed){
return SvgIcon({
svg: o.gender === "f" && closed
? path("/avatarTalk/svg/female-eyes-closed.svg")
: o.gender === "f"
? path("/avatarTalk/svg/female-eyes-open.svg")
: closed
? path("/avatarTalk/svg/male-eyes-closed.svg")
: path("/avatarTalk/svg/male-eyes-open.svg"),
width: "100%",
height: "100%"
}).css({
position: "absolute",
top: 0,
left: 0
});
};
})();
avatarTalk/face/face.ls
(function(){
return function(o){
return SvgIcon({
svg: path("/avatarTalk/svg/" + o.type + ".svg"),
width: "100%",
height: "100%"
});
};
})();
avatarTalk/mouth/mouth.ls
(function(){
return function(o){
o.currentMouth = o.currentMouth || "x";
o.mouthSvg = SvgIcon({
svg: path("/avatarTalk/svg/mouth-" + o.currentMouth + ".svg"),
width: "100%",
height: "100%"
}).css({
position: "absolute",
top: 0,
left: 0
});
return o.mouthSvg;
};
})();
avatarTalk/svg/f1.svg
avatarTalk/svg/f2.svg
avatarTalk/svg/f3.svg
avatarTalk/svg/female-eyes-closed.svg
avatarTalk/svg/female-eyes-open.svg
avatarTalk/svg/hair-o.svg
avatarTalk/svg/headset.svg
avatarTalk/svg/m1.svg
avatarTalk/svg/m2.svg
avatarTalk/svg/m3.svg
avatarTalk/svg/male-eyes-closed.svg
avatarTalk/svg/male-eyes-open.svg
avatarTalk/svg/mouth-a.svg
avatarTalk/svg/mouth-b.svg
avatarTalk/svg/mouth-c.svg
avatarTalk/svg/mouth-d.svg
avatarTalk/svg/mouth-e.svg
avatarTalk/svg/mouth-f.svg
avatarTalk/svg/mouth-g.svg
avatarTalk/svg/mouth-h.svg
avatarTalk/svg/mouth-x.svg
avatarTalk/update/update.ls
(function(){
return function(o){
var mouths, setMouth, getDuration, lastFrameAt, frameDuration, update;
mouths = ["x", "a", "b", "c", "d", "e", "f", "g", "h"];
setMouth = function(mouth){
var nextMouth;
nextMouth = mouth || _.sample(mouths);
if (nextMouth !== o.currentMouth) {
o.currentMouth = nextMouth;
return o.mouthSvg.replaceWith(o.mouthSvg = include("../mouth/mouth")(o));
}
};
getDuration = function(){
return Math.round(Math.random() * 50 + 50);
};
lastFrameAt = null;
frameDuration = getDuration();
update = function(p, d, a){
var talking, t;
talking = p != null && d != null && p === d
? false
: a == null || (a != null ? a.vol : void 8) > 0.7 ? true : void 8;
t = new Date();
if (!talking) {
return setMouth("x");
} else if (!lastFrameAt || t - lastFrameAt > frameDuration) {
frameDuration = getDuration();
lastFrameAt = t;
return setMouth();
}
};
return update;
};
})();
init.ls
(function(){
return function(){
if (typeof Avatar == 'undefined' || Avatar === null) {
return window.Avatar = include('avatar/avatar');
}
};
})();
lib/util/avatarWithCache/avatar.ls
(function(){
var cached, timeout;
cached = {};
timeout = undefined;
return function(avatar){
var cacheId, src, noCache, lsg, svg, image;
cacheId = include("/lib/util/md5/md5")(JSON.stringify(avatar));
src = cached[cacheId];
if (!src) {
noCache = true;
lsg = include("/avatar/toLSG/toLSG")(avatar);
svg = LSG2.toSVG(lsg).outerHTML;
src = include("convertToImageSrc/convert")(svg);
cached[cacheId] = src;
}
image = document.createElement("img").addClass("avatar").attr({
src: src
}).css({
display: "inline-block",
width: "2.5em",
height: "2.5em"
});
requestAnimationFrame(function(){
return include("cleanupCache/cache")(cached);
});
return image;
};
})();
lib/util/avatarWithCache/cleanupCache/cache.ls
(function(){
var timeout;
timeout = undefined;
return function(cached){
var max, delay, onTimeout;
max = 200;
delay = 2000;
onTimeout = function(){
var i, x, n, results$ = [];
timeout = undefined;
i = 0;
x = _.keys(cached).length - max;
for (n in cached) {
i++;
delete cached[n];
if (i >= x) {
break;
}
}
return results$;
};
if (!timeout && _.keys(cached).length >= max) {
return timeout = setTimeout(onTimeout, delay);
}
};
})();
lib/util/avatarWithCache/convertToImageSrc/convert.ls
(function(){
return function(svg){
var src;
if (!_.startsWith(svg, "