Taps provide source agnostic sync access to the input. Either it comes from mouse and/or touch, it is the same API. It assumes multiple instances of taps making your code multi-touch by design. Providing sync access instead of event-based, for best usage in real-time applications.

Overview

mr-Taps

Taps provide source agnostic sync access to input. Either it comes from mouse and/or touch, it is the same API. It assumes multiple instances of taps making your code multi-touch by design.

Providing sync access instead of event based, for best usage in real-time applications.

GitHub license

🚀 Install

module: https://cdn.jsdelivr.net/npm/mr-tap/dist/mr-tap.module.min.js
nomodule: https://cdn.jsdelivr.net/npm/mr-tap/dist/mr-tap.min.js

npm install mr-observer
<script type='module' src='mr-tap.module.min.js'></script>
<script nomodule src='mr-tap.min.js'></script>

Use built files from dist directory for browser. It will load ES8+ version if it is supported (~94%). There are two versions: nomodule (global scope) and module (for import).

// create taps interface
const taps = new Taps();

function update() {
    requestAnimationFrame(update);

    // update taps on each frame
    taps.update();

    // access all taps
    for(const tap of taps) {
        // iterate through all taps
    }
}
requestAnimationFrame(update);

📜 API Documentation

Usage

Creating:

const taps = new Taps();

Updating:

function update() {
    requestAnimationFrame(update);

    // update taps on each frame
    taps.update();

    // application logic
}
requestAnimationFrame(update);

Accessing:

All taps:

// Taps - is an iterator
for(const tap in taps) {
    // all taps
}

Specific state taps, e.g. clicks:

for(const tap in taps.click) {
    // taps that are only clicks
}

Examples

Examples are multi-touch by design.

Clicking on objects:

for(const tap of taps.click) {
    const object = pickObject(tap.x, tap.y);
    if (! object) continue;
    object.interact();
}

Rendering taps:

// drawCircle(x, y, radius)

for(const tap of taps) {
    drawCircle(tap.x, tap.y, 32);
}

Selecting multiple objects using rect (RTS style):

// drawRect(left, top, right, bottom)

// draw selection rect
for(const tap of taps.drag) {
    drawRect(tap.sx, tap.sy, tap.x, tap.y);
}

// select objects on dragend
for(const tap of taps.dragend) {
    const objects = objectsInRect(tap.sx, tap.sy, tap.x, tap.y);
    // selected some objects
}

Dragging objects:

// pick an object from tap start position
// and remember against tap object
for(const tap of taps.dragstart) {
    const object = pickObject(tap.sx, tap.sy);
    if (! object) continue;

    tap.object = object;
    // remember difference of position between tap and object center
    tap.offsetX = object.x - tap.sx;
    tap.offsetY = object.y - tap.sy;
}

// position objects
for(const tap of taps.drag) {
    // tap might have no object associated
    if (! tap.object) continue;
    // position with offset to prevent object snapping
    tap.object.setPosition(tap.x + tap.offsetX, tap.y + tap.offsetY);
}

Throwing objects:

// pick objects
// position objects

// throw an object
for(const tap of taps.dragend) {
    // tap might have no object associated
    if (! tap.object) continue;
    // set linear velocity
    // multiply speed by deltaTime
    tap.object.setLinearVelocity(tap.dx * dt, tap.dy * dt);
}

Tap

Each tap is instantiated by the Taps interface, and provided through iterators. Tap is agnostic to the input source: mouse or touch. And behaves identical. Also, due to iterator pattern, it provides sync access instead of event driven, and is multi-touch by design.

Tap has states with two branching scenarios:

Click: start > click + up
Drag: start > dragstart + drag > drag > dragend + drag + up

States:

start - every tap starts with a start state.

click - some taps if not moved from initial position and have not been held for too long, on up state, will be considered click.
dragstart - some taps if moved from initial position or have been held for some time, will enter drag state, and once be in dragstart state.
drag - once tap is in dragstart state, it will be in drag state till the end of a tap.
dragend - if tap is in drag state, on up state instead of click it will be in dragend state.

up - every tap ends with up state.

Drag State

Tap enters drag state if moved far from start position, or held for long enough. It is possible to change default settings of 20 pixels and 200 millisecsonds:

taps.dragDistance = 20; // pixels
taps.dragDelay = 200; // milliseconds

Building

Builds library into two versions (normal and module) using Rollup, Babel and Terser.
Source file: src/index.js
Built versions normal (dist/mr-tap.min.js) and module (dist/mr-tap.module.min.js):

npm install
npm run build
You might also like...

DiscordEmailVerifier - Quickly verify emails on your tokens for completely free using mail.tm's api.

DiscordEmailVerifier Quickly verify emails on your tokens for completely free using mail.tm's api. /* ❗ No, this code doesn't verify the email for you

Jun 7, 2022

Discuzz Open source Comment System

Discuzz  Open source Comment System

Discuzz Open source Comment System Table of contents Homepage Features Usage Firebase Web Component React Component Advanced usages Contributing Chang

Dec 24, 2022

SmartContract UI Open source Blockchain's Smart Contract Tool

SmartContract UI  Open source Blockchain's Smart Contract Tool

SmartContract UI Open source Blockchain's Smart Contract Tool Table of contents Homepage Features Usage Config ABI Import from deployed contract Selec

Dec 16, 2022

A JSONSchema validator that uses code generation to be extremely fast

is-my-json-valid A JSONSchema validator that uses code generation to be extremely fast. It passes the entire JSONSchema v4 test suite except for remot

Dec 31, 2022

Simple translation for your javascripts, yummy with your favorite templates engine like EJS.

jsperanto Simple translation for your javascripts, yummy with your favorite templates engine like EJS. Pluralization, interpolation & "nested lookup"

Oct 21, 2021

This is a project based on redux of reactjs.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Dec 18, 2021

Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is a powerful tool to sanitize and validate JS objects. It's designed to work both client-side and server-side and to be scalable wit

Oct 3, 2022

Creating a Blog API, with full CRUD using NodeJS, Express, Mongoose, and MongoDB.

Blog API Blog API that uses CRUD to create, login users, delete and update blog posts. https://blog-api12.herokuapp.com/ Installation Make a new folde

Jun 29, 2022

Email capture page using Notion API

Email capture page using Notion API

Notion Capture This starter shows how to use the new Notion API with Next.js. You can capture emails that will populate a Notion database. Live Demo •

Dec 25, 2022
Comments
  • Mouse and Button properties for a Tap

    Mouse and Button properties for a Tap

    When Tap originates from mouse input, it can be useful to identify such cases. So progressively apps can use the button property to apply logic to e.g.: only the right mouse button.

    opened by Maksims 0
Releases(0.1.0)
Owner
mrmaxm
WebGL, WebXR, full-stack, consulting
mrmaxm
Vue-input-validator - 🛡️ Highly extensible & customizable input validator for Vue 2

??️ Vue-input-validator demo! What is this package all about? By using this package, you can create input validators only with the help of a single di

null 14 May 26, 2022
[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.

jQuery Form Validator [DISCONTINUED] Validation framework that let's you configure, rather than code, your validation logic. I started writing this pl

Victor Jonsson 976 Dec 30, 2022
NP style edits and additionals for qb-phone, help from a few community members. NOT PROVIDING SUPPORT

qb-phone Phone for QB-Core Framework. Edited for a NP-Style look with a few extra things, This file has been edited with the changes noted NOTE NP doe

clmillzz 49 Jan 2, 2023
This is the code repository of the official mun testnet validator node source code.

How to join Munchain network Infrastructure **Recommended configuration:** - Number of CPUs: 4 - Memory: 16GB - OS: Ubuntu 22.04 LTS - Allow all incom

MUN Blockchain 16 Dec 15, 2022
FieldVal - multipurpose validation library. Supports both sync and async validation.

FieldVal-JS The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports. Documentation and Examples D

null 137 Sep 24, 2022
The best @jquery plugin to validate form fields. Designed to use with Bootstrap + Zurb Foundation + Pure + SemanticUI + UIKit + Your own frameworks.

FormValidation - Download http://formvalidation.io - The best jQuery plugin to validate form fields, designed to use with: Bootstrap Foundation Pure S

FormValidation 2.8k Mar 29, 2021
Enable browser autofill for any input field.

Autofill It Enable browser autofill for any input field. Get it on Chrome Web Store! A Google Chrome extension that sets autocomplete attributes of an

ygkn 5 Dec 15, 2022
🪄 Multi step forms with in built validations

react-wizardry is a data-driven smart wizard component for creating powerful forms with in built validations. Demo Features ⚡ Data driven API ✅ In bui

Prabhu Murthy 38 Aug 16, 2022
TypeScript-first schema validation for h3 and Nuxt applications

h3-zod Validate h3 and Nuxt 3 requests using zod schema's. Install npm install h3-zod Usage import { createServer } from 'http' import { createApp } f

Robert Soriano 48 Dec 28, 2022