npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-femtotween

v1.0.0

Published

Vue 3 Composition API reactivity wrapper for femtoTween

Downloads

4

Readme

vue-femtotween

This is a small wrapper over the femtotween tweening package to expose it as a Vue 3 Composition API composable that works with Vue Refs.

Installation

npm install vue-femtotween
import { useTween } from "vue-femtotween";

UMD:

import "vue-femtotween/dist/umd.js";

VueFemtotween.useTween(. . .

Usage

The package exposes a single entrypoint function, useTween, as well as re-exporting the easing functions offered by femtoTween.

const useTween: <T extends number | number[]>(
  source: Ref<T>,
  options: TweenOptions,
  callback?: ((newValue: number) => void) | undefined
) => TweenValue<T>;
  • source is a Ref either containing a number or a number[].

    • Ref<number>: Changing the value will result in tweening from whatever the current tweening value is, to the new target value.
    • Ref<number[]>: Changing the value at an individual index tweens it independently from other values in the array.
  • TweenOptions are as follows:

    export interface TweenOptions {
      /**
       * Time in ms for the tween - default: `400`
       */
      time?: number;
    
      /**
       * Callback function called when tweening is done.
       */
      done?: () => void;
    
      /**
       * Function used for easing - default: `easeInOutQuart`. See {@link https://github.com/pearofducks/femtoTween/blob/master/ease.js femtoTween easing functions}.
       */
      easeFunc?: (value: number) => number;
    
      /**
       * Optional transform/truncation of tweened value to a specified precision. See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed Number.toFixed()}
       */
      precision?: number;
    }

    With the exception of precision, these are the same options passed to femtoTween's tween function. precision is added as a convenience feature.

  • callback is an optional callback function that can be passed in, and will be called with the new tween value at each tween frame.

  • The return value type is TweenValue<T> which is defined as:

    export type Stoppable = {
      stop: () => void;
    };
    
    export type TweenValue<T extends number | number[]> = Ref<T> & Stoppable;

    Essentially, just a Ref that also has a stop function exposed.

    The Ref returned from useTween will update its value as tweening progresses. Calling stop stops the active tween. Changing the source's value will result in a new tween to the new target value.

Example

import { defineComponent, ref } from "vue";

import { linear, useTween } from "vue-femtotween";

const source = ref(0);

const tweenValue = useTween(source, {
  easeFunc: linear,
  time: 1000,
  precision: 0,
});

tweenValue is a reactive value that updates at each tween frame. Changing the value of source results in a new tween, causing tweenValue to tween to the new target. These Refs could then be used in a component template:

<div style="width: 10em">
  <div>
    <div>tweenValue - {{ tweenValue }}</div>

    <progress :value="tweenValue / 1000" max="1" style="width: 100%" />
  </div>

  <input v-model="source" min="0" max="1000" type="range" style="width: 100%" />
</div>