Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/focus-visible

Package Overview
Dependencies
Maintainers
1
Versions
741
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/focus-visible - npm Package Compare versions

Comparing version 0.0.0-dev-20220616113129 to 0.0.0-dev-20220617070002

2

dist/index.d.ts

@@ -0,3 +1,5 @@

declare type Modality = "keyboard" | "pointer" | "virtual";
declare type FocusVisibleCallback = (isFocusVisible: boolean) => void;
export declare function trackFocusVisible(fn: FocusVisibleCallback): () => void;
export declare function trackInteractionModality(fn: (v: Modality | null) => void): () => void;
export {};

43

dist/index.js

@@ -23,3 +23,4 @@ "use strict";

__export(src_exports, {
trackFocusVisible: () => trackFocusVisible
trackFocusVisible: () => trackFocusVisible,
trackInteractionModality: () => trackInteractionModality
});

@@ -30,10 +31,11 @@ module.exports = __toCommonJS(src_exports);

var hasEventBeforeFocus = false;
var hasBlurredWindowRecently = false;
var handlers = /* @__PURE__ */ new Set();
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
function isValidKey(event) {
return !(event.metaKey || !isMac && event.altKey || event.ctrlKey);
}
function trigger(modality2, event) {
handlers.forEach((handler) => handler(modality2, event));
}
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
function isValidKey(e) {
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
}
function onKeyboardEvent(event) {

@@ -56,2 +58,13 @@ hasEventBeforeFocus = true;

}
function isVirtualClick(event) {
if (event.mozInputSource === 0 && event.isTrusted)
return true;
return event.detail === 0 && !event.pointerType;
}
function onClickEvent(e) {
if (isVirtualClick(e)) {
hasEventBeforeFocus = true;
modality = "virtual";
}
}
function onWindowFocus(event) {

@@ -61,13 +74,15 @@ if (event.target === window || event.target === document) {

}
if (!hasEventBeforeFocus) {
modality = "keyboard";
trigger("keyboard", event);
if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
modality = "virtual";
trigger("virtual", event);
}
hasEventBeforeFocus = false;
hasBlurredWindowRecently = false;
}
function onWindowBlur() {
hasEventBeforeFocus = false;
hasBlurredWindowRecently = true;
}
function isFocusVisible() {
return modality === "keyboard";
return modality != null && modality !== "pointer";
}

@@ -85,2 +100,3 @@ function setupGlobalFocusEvents() {

document.addEventListener("keyup", onKeyboardEvent, true);
document.addEventListener("click", onClickEvent, true);
window.addEventListener("focus", onWindowFocus, true);

@@ -108,1 +124,10 @@ window.addEventListener("blur", onWindowBlur, false);

}
function trackInteractionModality(fn) {
setupGlobalFocusEvents();
fn(modality);
const handler = () => fn(modality);
handlers.add(handler);
return () => {
handlers.delete(handler);
};
}
{
"name": "@zag-js/focus-visible",
"version": "0.0.0-dev-20220616113129",
"version": "0.0.0-dev-20220617070002",
"description": "Focus visible polyfill utility based on WICG",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc