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

smart-gesture

v1.2.5

Published

这是一个web版的鼠标手势组件,支持普通的鼠标手势和自定义图形手势, 在线 [demo](https://elemefe.github.io/smart-gesture/)

Downloads

11

Readme

smart-gesture

这是一个web版的鼠标手势组件,支持普通的鼠标手势和自定义图形手势, 在线 demo

安装

可通过npm安装

npm install --save smart-gesture

也可以直接使用dist/min/smart-gesture.min.js文件

普通鼠标手势

普通手势可识别上(U)下(D)左(L)右(R)4个方向的任意组合

basic-gesture

自定义图形手势

可识别任意的可以一笔画出的手势,默认有预设的4种图形,同时也能自定义图形。若自定义图形手势,可以通过增加样本集来提高识别率,推荐同一个手势对应2-3个样本集。

smart-gesture

预设图形图案

demo

Usage

import smartGesture from 'smart-gesture';
const options = {
  el: document.getElementById('test'),             
  onSwipe: (list) => {
    console.log(list);
  },
  onGesture: (res, points) => {
    console.log(res);
    document.getElementById('result').innerHTML = res.score > 2 ? res.name : '未识别';
  }
};

const gesture = new smartGesture(options);

或者直接在页面中引用dist/min/smart-gesture.min.js,会在window上暴露一个smartGesture方法

<script src="dist/min/smart-gesture.min.js"></script>
<script>
    let lastPoints = [];
    const options = {
      el: document.getElementById('test'),             
      onSwipe: (list) => {
        console.log(list);
      },
      onGesture: (res, points) => {
        console.log(res);
        document.getElementById('result').innerHTML = res.score > 2 ? res.name : '未识别';
      }
    };
    const gesture = new smartGesture(options);
</script>

Documentation

configuration

var gesture = new smartGesture({el: document.querySelector('#target'), ...});

可配置的参数如下:

  • el 应用手势识别的元素,类型为DOMElement。需要注意的是,由于用于显示鼠标轨迹的svg的positionabsolute, 所以为了保证鼠标轨迹的位置正常,建议对该元素设置position: relative。(default: body)

  • enablePath 是否显示鼠标轨迹,类型为Boolean。(default: true)

  • lineColor 鼠标轨迹的颜色,类型为String。(default: #666)

  • lineWidth 鼠标轨迹的宽度,类型为Number,单位px。(default: 4)

  • timeDelay 长按一定时间后才会触发手势识别,类型为Number,单位ms。(default: 600)

  • triggerMouseKey 触发手势识别的鼠标按键,类型为String,可选值left | right。(default: right)

  • gestures 初始化自定义图形集合。类型为Array | Object,若不想使用预设的手势,可以传空数组。(default: [所有预设的手势])

  • activeColor 开启手势时背景色。类型为String。(default: rgba(0, 0, 0, .05))

  • eventType 响应事件的类型。类型为String,可选值touch | mouse,当指定为touch时将捕获touch相关的事件,简单的说如果用于移动端请将参数设置为touch。(default: mouse)

  • onSwipe: function(directionList) 手势结束时调用,

    • directionList: 普通手势的识别结果,数组。
  • onGesture: function(result, points) 手势结束时调用

    • result: 自定义图形手势的识别结果,值为一个对象,包含namescore两个key。

    • points: 包含该次手势的轨迹的点的集合构成的数组。可以配合addGesture方法来实现自定义手势功能。

Methods

  • .addGesture(gesture) 添加自定义图形模板

    • gesture: 自定义图形模板
      • type: Object
      • gesture.name:String: 模板名称
      • gesture.points:Array: 点集合
  • .refresh(options) 重新刷新实例的options

    • options: smartGesture参数对象
  • .destroy() 销毁当前的实例

Development

npm i
npm run dev

Resources

smart-gesture for React: react-smart-gesture

smart-gesture for Vue: vue-smart-gesture

smart-gesture for ReactNative: react-native-smart-gesture

Contribution

请在提交 PR 前阅读我们的贡献指南

License

MIT