Skip to content

Commit

Permalink
Carousel: import Tweenable from nimiq-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
danimoh committed Sep 17, 2019
1 parent ff086d6 commit 2639b2a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"@nimiq/iqons": "^1.1.1",
"@nimiq/utils": "^0.4.1",
"@nimiq/utils": "link:../nimiq.github.io/libraries/nimiq-utils",
"@storybook/addon-actions": "^4.0.0-alpha.14",
"@storybook/addon-knobs": "^4.0.0-alpha.14",
"@storybook/addon-links": "^4.0.0-alpha.14",
Expand Down
40 changes: 1 addition & 39 deletions src/components/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,7 @@
<script lang="ts">
import { Component, Prop, Watch, Vue } from 'vue-property-decorator';
import SmallPage from './SmallPage.vue';
class Tweenable {
public constructor(
public targetValue: number = 0,
public startValue: number = targetValue,
public tweenTime: number = 0,
public startTime: number = Date.now(),
public easing: (progress: number) => number = Tweenable.Easing.EASE_IN_OUT_CUBIC,
) {}
public get currentValue(): number {
const easedProgress = this.easing(this.progress);
return this.startValue + (this.targetValue - this.startValue) * easedProgress;
}
public get progress(): number {
if (this.tweenTime === 0) return 1;
return Math.min(1, (Date.now() - this.startTime) / this.tweenTime);
}
public get finished(): boolean {
return this.progress === 1;
}
public tweenTo(targetValue, tweenTime = this.tweenTime) {
if (targetValue === this.targetValue) return;
this.startValue = this.currentValue;
this.targetValue = targetValue;
this.startTime = Date.now();
this.tweenTime = tweenTime;
}
}
namespace Tweenable { // tslint:disable-line no-namespace
// see https://gist.github.com/gre/1650294 for more easing functions
export let Easing = { // tslint:disable-line variable-name
LINEAR: (t: number) => t,
EASE_IN_OUT_CUBIC: (t: number) => t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1,
};
}
import { Tweenable } from '@nimiq/utils';
@Component({components: {SmallPage}})
export default class Carousel extends Vue {
Expand Down
7 changes: 3 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,9 @@
resolved "https://registry.yarnpkg.com/@nimiq/style/-/style-0.7.3.tgz#4d867fa338242680c4ba9ffbe7ca0c4960bde7c3"
integrity sha512-uwVVO1OepSb4GV/mbDvV06/zsMKiB3/+YWvKkgOHpHb+SvVvt4rTFBszoNTVN/rbdhDN25nI5sMSidsXZ9izPw==

"@nimiq/utils@^0.4.1":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@nimiq/utils/-/utils-0.4.1.tgz#19b77441440d1fd8463315b2a98ffad23eeddb95"
integrity sha512-Zl/QfOA7/5EApkEAG7Di8sS/6jlvNhtX462iWot9RiC7tVeaeMk+5Q7WlT5g7dVXSCNyz5IFRYewFP5PlIojgw==
"@nimiq/utils@link:../nimiq.github.io/libraries/nimiq-utils":
version "0.0.0"
uid ""

"@nodelib/fs.stat@^1.0.1":
version "1.1.0"
Expand Down

0 comments on commit 2639b2a

Please sign in to comment.