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

@wessberg/pointer-events

v1.0.9

Published

A Level 2 spec-compliant Pointer Events polyfill with first-class Shadow DOM support

Downloads

7,854

Readme

A Level 2 spec-compliant Pointer Events polyfill with first-class Shadow DOM support

Description

This polyfill brings Level 2 Pointer Events to all browsers! The Pointer Events specification provides a unified model for handling input from a pointer such as a mouse, a touch, and a pen.

Gone are the complexities of handling both MouseEvents and TouchEvents and juggling the differences between them. The primary design goals of this polyfill are to be as spec-compliant as possible, and to support modern web technologies such as Shadow DOM.

Features

  • Spec-compliant
  • Shadow DOM support
  • Performant
  • Feature-complete

Table of Contents

Install

NPM

$ npm install @wessberg/pointer-events

Yarn

$ yarn add @wessberg/pointer-events

Usage

To use the Polyfill, simply import it:

import "@wessberg/pointer-events";

However, it is strongly suggested that you only include the polyfill for browsers that doesn't already support Pointer Events. One way to do so is with an async import:

if (!("PointerEvent" in window)) {
	await import("@wessberg/pointer-events");
}

Alternatively, you can use Polyfill.app which uses this polyfill and takes care of only loading the polyfill if needed as well as adding the language features that the polyfill depends on (See dependencies).

touch-action support

This polyfill supports the following Pointer Events (Level 2) touch-action values, as well as those defined in the latest Draft Community Report:

  • none
  • pan-x
  • pan-y
  • pan-left
  • pan-right
  • pan-up
  • pan-down
  • auto
  • manipulation (will be treated the same ast auto)

Upon pointer contact, the polyfill will walk up the DOM tree from the target element and look for elements that has either:

  • A style attribute including a touch-action property.
  • An element with a touch-action attribute.
  • Or, an element with a CSSStyleDeclaration with a touchAction property.

This means that either of the following approaches will work:

<!-- Works just fine when given in the 'style' attribute -->
<div style="touch-action: pan-y"></div>
<!-- Works just fine when given as an attribute of the name 'touch-action' -->
<div touch-action="pan-y"></div>
// Works jut fine when given as a style property
element.style.touchAction = "pan-y";

See this section for information about why touch-action values provided in stylesheets won't be discovered by the polyfill.

Dependencies & Browser support

This polyfill is distributed in ES3-compatible syntax, but is using some modern APIs and language features which must be available:

  • EventTarget
  • Set
  • Map
  • Object.defineProperty
  • Object.defineProperties
  • Array.from
  • Array.prototype.some
  • Array.prototype.every
  • String.prototype.includes
  • Constructable Events
  • EventTarget.prototype.addEventListener
  • EventTarget.prototype.removeEventListener
  • EventTarget.prototype.dispatchEvent
  • Document.prototype.elementFromPoint
  • window.getComputedStyle
  • ShadowRoot.prototype.elementFromPoint*

*: This is only relevant if you're using Shadow DOM (in which case a Shadow DOM polyfill will most likely polyfill the prototype method).

For by far the most browsers, these features will already be natively available. Generally, I would highly recommend using something like Polyfill.app which takes care of this stuff automatically.

Contributing

Do you want to contribute? Awesome! Please follow these recommendations.

Maintainers

| | | --------------------------------------------------------------------------------------------------------------------------------- | | Frederik Wessberg@FredWessbergLead Developer |

Backers

Patreon

Become a backer and get your name, avatar, and Twitter handle listed here.

FAQ

There are several polyfills for Pointer events already. Why another one?

Yes, there are several, including PEP and Points. This polyfill was made because neither were built with Shadow DOM (v1) support in mind. For example, Points assumes a single document-level root and relies on document.elementFromPoint which will never reach within Shadow roots. And, PEP relies on /deep/ selectors, something that has been removed from the platform. I found that none of the existing polyfills I attempted "just worked" and decided to try it out for myself. There may well be parts of this polyfill that is less aligned with the spec than other polyfills, and such issues will be ironed out over time.

Are there any known quirks?

For now, just one: The touch-action CSS property needs to be provided from either inline styles or an attribute of the same name. This is because polyfilling CSS is hard and really bad for performance.

License

MIT © Frederik Wessberg (@FredWessberg) (Website)