{"id":19533949,"url":"https://github.com/rafgraph/detect-pointer-events","last_synced_at":"2025-07-23T17:32:07.398Z","repository":{"id":66154995,"uuid":"62766049","full_name":"rafgraph/detect-pointer-events","owner":"rafgraph","description":"Detect if the browser supports the Pointer Events API","archived":false,"fork":false,"pushed_at":"2020-09-12T00:47:59.000Z","size":36,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-01T17:48:51.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://detect-it-v1.rafgraph.dev#detect-pointer-events","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafgraph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-07T01:50:34.000Z","updated_at":"2023-03-09T01:40:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"60535ec3-3aeb-408a-97ef-02064eb8414c","html_url":"https://github.com/rafgraph/detect-pointer-events","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/rafgraph/detect-pointer-events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-pointer-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-pointer-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-pointer-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-pointer-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafgraph","download_url":"https://codeload.github.com/rafgraph/detect-pointer-events/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-pointer-events/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266719682,"owners_count":23973813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T02:11:17.408Z","updated_at":"2025-07-23T17:32:07.376Z","avatar_url":"https://github.com/rafgraph.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detect Pointer Events\n\nDetect if the browser supports the pointer events api.\n\n[Live detection test][liveDetectionTest]\n\nExports a reference to a singleton object (a micro state machine with an update function) with its state set to if the browser supports the pointer events api, (and if so does the api require a prefix, is it running on a touch device, and how many touch points does the device have), as well as an `update()` function which re-runs the tests and updates the object's state. There is also a `prefix(value)` function which will return the `value` and only add a prefix to it if it's required.\n\nNote that `detect-pointer-events` is one of the micro state machines used by [`detect-it`][detectItRepo] to determine if a device is `mouseOnly`, `touchOnly`, or `hybrid`.\n\n*For more information on the pointer events api, please see [MDN's Pointer Events][mdnPointerEvents], or the [W3C Pointer Events specification][w3cSpecLatest].*\n\n\n### `detectPointerEvents` micro state machine\n```javascript\nconst detectPointerEvents = {\n  hasApi: boolean,\n  requiresPrefix: boolean,\n  hasTouch: boolean,\n  maxTouchPoints: whole number,\n\n  // re-run all the detection tests and update state\n  update() {...},\n\n  // prefix the passed in value only if requiresPrefix === true\n  prefix(value) {...},\n}\n```\n\n### Installing `detect-pointer-events`\n```terminal\n$ npm install detect-pointer-events\n```\n\n### Using `detect-pointer-events`\n```javascript\nimport detectPointerEvents from 'detect-pointer-events';\n```\n```javascript\n// using the state\ndetectPointerEvents.hasApi === true; // pointer events api is present in the browser\ndetectPointerEvents.requiresPrefix === true; // use of pointer events requires the Microsoft prefix\ndetectPointerEvents.hasTouch === true; // pointer events running on a touch capable device\ndetectPointerEvents.maxTouchPoints; // maximum number of touch points supported by the device\n\n// updating the state - most apps won't need to use this at all\ndetectPointerEvents.update();\n\n// prefixing pointer events\ndetectPointerEvents.prefix(value) // returns the value and only adds the prefix if requiresPrefix\n\n// for example, this will add an event listener for 'MSPointerDown' if requiresPrefix === true,\n// otherwise it will add an event listener for 'pointerdown'\nelement.addEventListener(detectPointerEvents.prefix('pointerdown'), function...)\n```\n\n```javascript\n/*\n * note that in the case of a browser that doesn't support pointer events,\n * including when using a legacy computer and browser, the default state will be:\n */\nconst detectPointerEvents = {\n  hasApi: false,\n  requiresPrefix: undefined,\n  hasTouch: undefined,\n  maxTouchPoints: undefined,\n}\n```\n\nFor reference, here is the [pointer events prefix map][prefixMap] used by the `prefix()` function.\n\nNote that the `update()` function is run once at the time of import to set the object's initial state, and generally doesn't need to be run again. If it doesn't have access to the `window`, then the state will be `undefined` (`detect-pointer-events` will not throw an error), and you will have to call the `update()` function manually at a later time to update its state.\n\n\n### Part of the [`detect-it`][detectItRepo] family\n- [`detect-it`][detectItRepo]\n  - [`detect-hover`][detectHoverRepo]\n  - [`detect-pointer`][detectPointerRepo]\n  - [`detect-touch-events`][detectTouchEventsRepo]\n  - **`detect-pointer-events`**\n  - [`detect-passive-events`][detectPassiveEventsRepo]\n\n\n\u003c!-- links --\u003e\n[liveDetectionTest]: https://detect-it-v1.rafgraph.dev/#detect-pointer-events\n[w3cSpecLatest]: https://www.w3.org/TR/pointerevents/\n[mdnPointerEvents]: https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events\n[prefixMap]: https://github.com/rafgraph/detect-pointer-events/blob/main/src/index.js#L1\n[detectItRepo]: https://github.com/rafgraph/detect-it/tree/v1.1.0\n[detectHoverRepo]: https://github.com/rafgraph/detect-hover\n[detectPointerRepo]: https://github.com/rafgraph/detect-pointer\n[detectTouchEventsRepo]: https://github.com/rafgraph/detect-touch-events\n[detectPassiveEventsRepo]: https://github.com/rafgraph/detect-passive-events\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafgraph%2Fdetect-pointer-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafgraph%2Fdetect-pointer-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafgraph%2Fdetect-pointer-events/lists"}