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

@argab/swipe

v3.0.1

Published

Makes DOM elements controlled on swipe and touch.

Downloads

9

Readme


The Library provides handlers for touchstart, touchend, and touchmove event listeners that apply to DOM elements.

Create Sidebars, Dropdowns, and any kind of UI element that is controlled by a touch event.

Simple usage example


import {SwipeElement, SwipeService} from '@argab/swipe'

const el = document.getElementById('#swipe')

const swipe = new SwipeService(el, {
    direction: 'left', // up|down|left|right
    onStart: () => {
    }, // do smth on touchsart
    onEnd: () => {
    }, // do smth on touchend
    onMove: () => {
    }, // do smth on touchmove
    fixed: true, // the swipe element will be returned 
                 // to it`s stating position on touchend
    fixedTimeout: 200,
})

const swipeEl = new SwipeElement(el, swipe)

swipe.validate() && swipeEl.addListeners()
Note that in order to make an element movable on touch,
You must apply absolute positioning or fixed CSS styling to it.

Integration with Vue.js


import {VueSwipeDirective} from '@argab/swipe'

const app = createApp({})

app.directive('swipe', VueSwipeDirective)

Now you can apply a simple swipe elements on Vue Templates:

simple swipe gif


<template>
    <transition name="ui-sidebar-transition">
        <div
            v-show="show"
            class="ui-sidebar"
            :class="swipe && 'ui-sidebar-swipe'"
            v-swipe.left.fixed:200="swipe && {
                onEnd: ({threshold}) => {
                    if (threshold <= 50) {
                        $listener.setup('sidebar', {showSwiped: false})
                        return show = false
                    }
                },
            }"
        >
            <h1>Simple Swipe</h1>
            <slot/>
        </div>
    </transition>
</template>

<script>
export default {
    props: {
        swipe: Boolean
    },
    data: () => ({
        show: true,
    }),
    mounted () {
        this.swipe && this.$listener.on('sidebar', {
            state: {
                showSwiped: (show) => this.show = Boolean(show)
            }
        })
        this.swipe && this.$listener.setup('sidebar', {
            swipe: true,
            showSwiped: false,
        })
    },
    beforeDestroy () {
        this.$listener.reset('sidebar')
    }
}
</script>

<style lang="scss">
.ui-sidebar {
    height: 100vh;
    width: 100%;
    background-color: #2E3440;
    color: #fff;
    padding: 20px;

    &-swipe {
        position: fixed;
        top: 0;
        left: 0
    }
}

.ui-sidebar-transition-enter-active,
.ui-sidebar-transition-leave-enter {
    transform: translateX(0);
    transition: all .2s linear;
}

.ui-sidebar-transition-enter,
.ui-sidebar-transition-leave-to {
    transform: translateX(-100%);
}
</style>

API

SwipeService's properties

| Name | Data Type | Arguments | Return | Default | Description | |----------------|-----------|-----------------------------------|----------------------|---------|-----------------------------------------------------------------------------------------| | direction | String | up|down|left|right | | | Target Element's moving direction | | fixed | Boolean | true|false | | false | Target Element will be returned to it's stating position on touchend | | fixedTimeout | Number | milliseconds | | 0 | Timeout before Target Element returned to it's stating position | | onStart | Function | Object | undefined | | On touchstart event handler | | onEnd | Function | Object | undefined | | On touchend event handler | | onMove | Function | Object | false|undefined | | On touchmove event handler. Returning FALSE forces embedded handler to stop execution |

Event Handler's (onStart, onEnd, onMove) arguments

| Argument | Data Type | Example | Description | |----------------|-----------|---------------------------------------------------|------------------------------------------------------------------------------------------------------------------| | x | Number | | Target Event's absolute coordinate | | y | Number | | Target Event's absolute coordinate | | period | Number | | The period in milliseconds that left from touchstart event | | dir | Object | {up: true, down: false, left: true, right: false} | Target Element's direction data | | event | Object | | Target Event's data | | startX | Number | | Target Event's starting position's absolute coordinate | | startY | Number | | Target Event's starting position's absolute coordinate | | diff | Object | {x: 0, y: 0} | Difference between Target Event's absolute coordinate and Target Event's starting position's absolute coordinate | | threshold | Number | 0-100% | The offset in percentage from the initial position of the Target Element |


Try out another powerful package from the author:

Request Service - This Library can totally organize working with REST API in your whole project.

Please, don't forget to paste into author's github repository

this support will inspire to create more powerful things for You.