{"id":19533959,"url":"https://github.com/rafgraph/detect-hover","last_synced_at":"2025-04-26T14:34:37.037Z","repository":{"id":60775044,"uuid":"62663999","full_name":"rafgraph/detect-hover","owner":"rafgraph","description":"JavaScript wrapper for hover and any-hover media queries","archived":false,"fork":false,"pushed_at":"2020-09-12T00:45:40.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-18T08:02:39.113Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://detect-it.rafgraph.dev#detect-hover","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}},"created_at":"2016-07-05T19:32:49.000Z","updated_at":"2023-03-09T01:40:39.000Z","dependencies_parsed_at":"2022-10-04T16:16:36.762Z","dependency_job_id":null,"html_url":"https://github.com/rafgraph/detect-hover","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-hover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-hover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-hover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-hover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafgraph","download_url":"https://codeload.github.com/rafgraph/detect-hover/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251001273,"owners_count":21520918,"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","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:29.223Z","updated_at":"2025-04-26T14:34:36.803Z","avatar_url":"https://github.com/rafgraph.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detect Hover\n\nJavaScript wrapper for `hover` and `any-hover` media queries.\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 the results of the `hover` and `any-hover` media queries, as well as an `update()` function which re-runs the tests and updates the object's state.\n\nNote that `detect-hover` 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 `hover` and `any-hover` media queries, please see the [W3C Media Queries Level 4 specification][w3cSpecLatest]. For information on browser compatibility, please see [Can I Use matchMedia][canIUseMatchMedia].*\n\n\n### `detectHover` micro state machine\n```javascript\nconst detectHover = {\n  // mutually exclusive (only one will be true)\n  hover: boolean,\n  none: boolean,\n\n  // not mutually exclusive\n  anyHover: boolean,\n  anyNone: boolean,\n\n  // re-run all the detection tests and update state\n  update() {...},\n}\n```\n\n### Installing `detect-hover`\n```terminal\n$ npm install detect-hover\n```\n\n### Using `detect-hover`\n```javascript\nimport detectHover from 'detect-hover';\n```\n```javascript\n// using the state\ndetectHover.hover === true; // primary pointing system can hover\ndetectHover.none === true; // primary pointing system can’t hover, or there is no pointing system\n\n/*\n * identical to the hover media feature, but they correspond to the\n * union of capabilities of all the pointing devices available to the user -\n * more than one of their values can be true, if different pointing devices have\n * different characteristics\n */\ndetectHover.anyHover === true;\ndetectHover.anyNone === true;\n\n\n// updating the state - most apps won't need to use this at all\ndetectHover.update();\n```\n\n```javascript\n/*\n * note that in the case of a legacy computer and browser, one that\n * doesn't support detect-hover's detection tests, the default state will be:\n */\nconst detectHover = {\n  hover: undefined,\n  none: undefined,\n  anyHover: undefined,\n  anyNone: undefined,\n}\n```\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` or the browser doesn't support the `matchMedia()` function (all modern browser do), then the state will be `undefined` (`detect-hover` will not throw an error). If `detect-hover` doesn't have access to the `window` at the time of import, you will have to call the `update()` function manually at a later time to update its state.\n\nNote that the hover on-demand value was removed from the [July 6th 2016 W3C Media Queries Level 4][w3cSpec7-6-2016] draft specification, but was included in the [previous draft (January 26th 2016)][w3cSpec1-26-2016] of the spec. Any device that registers as having hover on-demand capabilities will show up as hover `none` in `detectHover`'s state. As a side note, hover on-demand is pretty much useless for practical purposes, and Android touch only devices register that they can hover on-demand, which is achieved via a long press - I view this as a feature that is a bug.\n\n### Part of the [`detect-it`][detectItRepo] family\n- [`detect-it`][detectItRepo]\n  - **`detect-hover`**\n  - [`detect-pointer`][detectPointerRepo]\n  - [`detect-touch-events`][detectTouchEventsRepo]\n  - [`detect-passive-events`][detectPassiveEventsRepo]\n\n\n\u003c!-- links --\u003e\n[liveDetectionTest]: https://detect-it.rafgraph.dev/#detect-hover\n[w3cSpecLatest]: https://www.w3.org/TR/mediaqueries-4/#hover\n[w3cSpec7-6-2016]: https://www.w3.org/TR/2016/WD-mediaqueries-4-20160706/#hover\n[w3cSpec1-26-2016]: https://www.w3.org/TR/2016/WD-mediaqueries-4-20160126/#hover\n[canIUseMatchMedia]: https://caniuse.com/#feat=matchmedia\n[detectItRepo]: https://github.com/rafgraph/detect-it\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-hover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafgraph%2Fdetect-hover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafgraph%2Fdetect-hover/lists"}