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

@dyrektrypt/handlers

v2.1.0

Published

Custom made event handlers for web development.

Downloads

6

Readme

handlers


A simple to learn and use API for custom event handlers in HTML5; supporting both Typescript and ES6.

See 'installation' for obtaining the API.

See 'usage' for learning how to use the API.

installation


Simply install the repository using npm.

#Assuming you are in your project's directory
npm i @dyrektrypt/handlers

And that's it! Now all you need to do is import desired custom handlers.

Please note:

  • For Typescript - the tsconfig property moduleResolution: node should be present in order to support npm imports.
  • For ES modules - code should be transpiled to UMD or similar variants by using either webpack, rollup or browserify.

usage


Custom handlers work by being built upon default HTML5 events; allowing for more complex detection oriented around elements.

Event handlers come with at least two functions:

  • create[Event]Handler - creates, binds and returns a handler constructed from passed parameters.
  • remove[Event]Handler - unbinds the previously constructed a handler from the custom event.

The current custom handlers are as follows:

  • ScaleEvent:
    • createScaleHandler - creates a handler binded to the ScaleEvent, in which is called and calculated on load and every resize to scale an element (like an SVG viewBox).
    • removeScaleHandler - unbinds the handler from the ScaleEvent.
  • ViewportEvent:
    • createViewportHandler - creates a handler binded to the ViewportEvent, in which is called every time an element appears or disappears of the screen.
    • removeViewportHandler - unbinds the handler from the ViewportEvent.

New custom handlers are always welcome!

To use handlers, create an instance of a desired handler by calling the correct function, which can be either:

  • createScaleHandler(element, scaleType, elementConfig, fontConfig?): () => void
    • element: HTMLElement - desired element to bind the event to.
    • scaleType: 'width' | 'height' - type of scaling, being either changing the 'width' or 'height' property.
    • elementConfig: ScaleEventConfig - controlled size of an elements height or width, in order to preserve size when scaling.
    • fontConfig?: ScaleEventConfig - optionally controlled size of an elements font, in order to preserve size when scaling.
  • createViewportHandler(element, callback, haltStart?): () => void
    • element: HTMLElement - desired element to bind the event to.
    • load: () => void - function to be called when the element appears in the pages viewport.
    • unload: () => void - optional function to be called when the element appears off of the pages viewport.
    • haltStart?: boolean - optional halting of firing the load function when the page loads and the element is on screen.

Noting interfaces being objects with properties:

  • ScaleEventConfig
    • scalePercentage: number - percentage for the desired property, calculated by: (pixels) / (page scale opposite) * 100.
    • scaleMin?: number - optional minimum pixels the desired property can scale to.
    • scaleMax?: number - optional maximum pixels the desired property can scale to.

An example of this:

HTML5

<div id="main-textbox">

ES6

import { createScaleHandler, removeScaleHandler } from '@dyrektrypt/handlers'

//Fetch 'main-textbox' element
let element = document.getElementById('main-textbox')

//Make the 'main-textbox' element scale
let scaleHandler = createScaleHandler(element, 'height',
{
    scalePercentage: 2.9304, //The element has scaling height of 40px for a page width of 1365px, calculated by: 40 / 1536 * 100
    scaleMin: 20, //The element will not scale below 20px
    scaleMax: 50 //The element will not scale above 50px
},
{
  scalePercentage: 2.0304, //The elements font has a scaling height of 40px, calculated the same way as the elements height
  scaleMin: 20, //The elements font will not scale below 20px
  scaleMax: 50 //The elements font will not scale above 50px
})

This will cause the main-textbox element to start scaling with a height of 40% for the changing width.

When scaling is no longer wanted, simply remove the handler with the removeScaleHandler function call: removeScaleHandler(scaleHandler)