diff --git a/src/shared/.eslintrc.json b/src/shared/.eslintrc.json new file mode 100644 index 0000000000..46f1957077 --- /dev/null +++ b/src/shared/.eslintrc.json @@ -0,0 +1,38 @@ +{ + "root": true, + "rules": { + "indent": [ 2, "tab", { "SwitchCase": 1 } ], + "semi": [ 2, "always" ], + "keyword-spacing": [ 2, { "before": true, "after": true } ], + "space-before-blocks": [ 2, "always" ], + "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], + "no-cond-assign": 0, + "no-unused-vars": 2, + "no-const-assign": 2, + "no-class-assign": 2, + "no-this-before-super": 2, + "no-unreachable": 2, + "valid-typeof": 2, + "quote-props": [ 2, "as-needed" ], + "arrow-spacing": 2, + "no-inner-declarations": 0 + }, + "env": { + "es6": true, + "browser": true, + "node": true, + "mocha": true + }, + "extends": [ + "eslint:recommended", + "plugin:import/errors", + "plugin:import/warnings" + ], + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "settings": { + "import/core-modules": [ "svelte" ] + } +} diff --git a/src/shared/transitions.js b/src/shared/transitions.js index a74e09711d..349c1b375c 100644 --- a/src/shared/transitions.js +++ b/src/shared/transitions.js @@ -4,13 +4,42 @@ export function linear ( t ) { return t; } +function generateKeyframes ( a, b, delta, duration, ease, fn, node, style ) { + var id = '__svelte' + ~~( Math.random() * 1e9 ); // TODO make this more robust + var keyframes = '@keyframes ' + id + '{\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; + + document.head.appendChild( style ); + + 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( ', ' ); +} + export function wrapTransition ( node, fn, params, intro, outgroup ) { var obj = fn( node, params, intro ); - var duration = obj.duration || 300; var ease = obj.easing || linear; - var transition = { + // TODO share