Socket
Socket
Sign inDemoInstall

funcurve

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

funcurve

A simple and funny way to get curve.


Version published
Weekly downloads
8
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Funcurve

🚀🚀Using bezier curve to build animation easily.

Build Status

Usage

Install

npm i funcurve

or

yarn add funcurve

Demo

import funcurve from 'funcurve';

const fc = funcurve({
  controlPoints: [
    { x: 100, y: 200 },
    { x: 400, y: 500 },
  ],
  onUpdate({ point }) {
    console.log(point.x, point.y);
  },
  onEnd({ point, finished }) {
    console.log(point.x, point.y, finished);
  },
}).start();

If you want't stop current running process, call stop(), after that onEnd callback will be fired with finished being false.

fc.stop();

A funcuve instance can call start serveral times. Before next process start, previous process will be stopped and call onEnd callback immediately.

fc.start();

setTimeout(() => {
  fc.start();
}, 500);

API

funcurve

funcurve(config: FuncurveConfig):IFuncurve returns a funcure instance.

config
keytypedescription
controlPointsPoint[]bezier control point array.
durationnumberthe duration(ms) of process, default value is 1000
onUpdateUpdateInfothe callback of each animation frame
onEndUpdateInfo&{finished:boolean}the callback of the end of process
export interface Point {
  x: number;
  y: number;
}

interface UpdateInfo {
  point: Point;
  progress: number;
}

export interface FuncurveConfig {
  controlPoints: Point[];
  duration?: number;
  onUpdate?(res: UpdateInfo): void;
  onEnd?(res: UpdateInfo & { finished?: boolean }): void;
}
UpdateInfo
keytypedescription
pointPointcurrent point of curve.
progressnumbercurrent progress. 0 - 1
finishedbooleanonEnd callback has an extra finished prop to indicate whether the process has finished.

IFuncurve

start()

Stop previous process and Start a new process.

stop()

Stop current process.

Principle

See Realize bezier curve

License

MIT

Keywords

FAQs

Package last updated on 04 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc