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

piano.js

v0.4.4

Published

Customizable virtual keyboard written in pure ES6

Downloads

42

Readme

Customizable virtual keyboard written in plain JavaScript. See the demo.

The easiest way to put a keyboard in front of your users. Piano is a simple and extensible On-Screen keyboard. It allows to provide elegant solution for virtual keyboard in a touch application.

Tested in Electron and Chrome kiosk.

js-standard-style Join the chat at https://gitter.im/soixantecircuits/piano

Piano is still under active development (but has successfully been used in production work).

Table of contents

Installation

Get the packages

npm i -S piano.js
# or
yarn add piano.js

Or download piano and at least the default layout .

Load the library

// Add the CSS
require('piano.js/piano.css')

// Require piano wherever you want to use it
const Piano = require('piano.js')

// Choose the layouts you want
const azerty = require('piano.js/layouts/azerty')
const qwerty = require('piano.js/layouts/qwerty')

or

<!-- Load the library -->
<script src="path/to/piano.js"></script>
<!-- And at least the default layout -->
<script src="path/to/layouts/default.js"></script>

Use it

// Instantiate Piano
const keyboard = new Piano({
  layouts: {
    'azerty': azerty,
    'qwerty': qwerty
  },
  slideContent: true
})
// See the 'Options' section for more details about this
<input type="text"
  data-piano data-piano-scale="1.5"
  data-piano-layout="azerty"
/>

Optionally, you can listen to piano events in your code

<input type="text"
  data-piano-event-id="do-stuff"
/>
document
  .querySelector('[data-piano-event-id="do-stuff"]')
  .addEventListener('do-stuff', doStuffCallback)

Method

addTarget()

addTarget method allow to dynamically add an input trigger for your on screen screen keyboard.

addTarget(element, options)

You need to provide a domElement and basic options object :

{
  layout: 'azerty',
  animationIn: 'bounceInUp',
  animationOut: 'fadeOutUp',
  scale: 1.0
}

So if you already have your keyboard instance and an element in the DOM namde #dynamic-piano you can:

let options = {
    layout: 'azerty',
    animationIn: 'bounceInUp',
    animationOut: 'fadeOutUp',
    scale: 1.0
  }
keyboard.addTarget(document.querySelector('#dynamic-piano'), options)

Usage

Positionning / styling

You can define positionning with the data-piano-position attribute. You can use the following:

  • 'left', 'center', 'right' -> x axis
  • 'top', 'middle', 'bottom' -> y axis

For example:

<input type="text" data-piano data-piano-position="left, center" />

Or, with the absolute keyword, you can define absolute x and y positions:

<input type="text" data-piano data-piano-position="absolute, 100, 150" />

Default positions are 'center, bottom'.

Submit

You can define a data-piano-event-id attribute on your element and then listen to it. For example, if you have a data-piano-event-id="input-event":

element.addEventListener('input-event', function (event) {
  console.log('element with id "%s" submitted.', event.target.id)
})

Animations

Piano provide has built-in but yet optionnal support for Animate.css.

By default, it will add fadeInUp and fadeOutDown classes to your container. Just load the animate.css stylesheet and you'll have nice animations. You can also use the data-piano-animation-in and data-piano-animation-out attributes to define custom classes to toggle on hide/show.

You can also choose to create your own animations, and thus just use the classes toggled by piano to trigger them.

Touch events

By default, Piano uses click events, even for touch devices. This is because any decent browser will emulate touch events into click, and touch events make an approximation of the pointer's contact position. Of course, you can override this in the options.

Options

You can pass options to your new Piano() call. Here they are:

  • triggerEvents: Array of event triggers you want Piano to react (see Touch events)
  • slideContent: bool [true, false], default to false. Allow to define if the content should slide
  • slideContainer: string ['.demo-container'], no default. Allow to define the part of the DOM you want to slide
  • onHidden: function, default to empty function. Allow to call a function when the keyboard is hidden
  • onBeforeHidden: function, default to empty function. Allow to call a function before the keyboard is hidden

Layouts

Soon.

Development

We use gulp to develop, to contribute to piano, just use gulp develop. It will watch src/piano and serve it over localhost on port 8080.

Create a feature-[name-of-the-feature] branch and make PR on the dev branch. Please use the standard js coding style.

To Do

  • Support accentuation. (partial support for now).