diff --git a/src/shared/transitions.js b/src/shared/transitions.js index ded3a35b4d..f374ba52e4 100644 --- a/src/shared/transitions.js +++ b/src/shared/transitions.js @@ -4,37 +4,31 @@ export function linear(t) { return t; } -export function generateKeyframes( +export function generateRule( a, b, delta, duration, ease, - fn, - node, - style + fn ) { - var id = '__svelte' + ~~(Math.random() * 1e9); // TODO make this more robust - var keyframes = '@keyframes ' + id + '{\n'; + var keyframes = '{\n'; for (var p = 0; p <= 1; p += 16.666 / duration) { var t = a + delta * ease(p); keyframes += p * 100 + '%{' + fn(t) + '}\n'; } - keyframes += '100% {' + fn(b) + '}\n}'; - style.textContent += keyframes; + return keyframes + '100% {' + fn(b) + '}\n}'; +} - document.head.appendChild(style); +// https://github.com/darkskyapp/string-hash/blob/master/index.js +export function hash(str) { + var hash = 5381; + var i = str.length; - node.style.animation = (node.style.animation || '') - .split(',') - .filter(function(anim) { - // when introing, discard old animations if there are any - return anim && (delta < 0 || !/__svelte/.test(anim)); - }) - .concat(id + ' ' + duration + 'ms linear 1 forwards') - .join(', '); + while (i--) hash = (hash * 33) ^ str.charCodeAt(i); + return hash >>> 0; } export function wrapTransition(node, fn, params, intro, outgroup) { @@ -43,9 +37,10 @@ export function wrapTransition(node, fn, params, intro, outgroup) { var ease = obj.easing || linear; var cssText; - // TODO share