@zag-js/focus-visible 1.34.1 → 1.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,17 +1,44 @@
1
- 'use strict';
2
-
3
- var domQuery = require('@zag-js/dom-query');
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
4
19
 
5
20
  // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ getInteractionModality: () => getInteractionModality,
24
+ ignoreFocusEvent: () => ignoreFocusEvent,
25
+ isFocusVisible: () => isFocusVisible,
26
+ listenerMap: () => listenerMap,
27
+ setInteractionModality: () => setInteractionModality,
28
+ trackFocusVisible: () => trackFocusVisible,
29
+ trackInteractionModality: () => trackInteractionModality
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var import_dom_query = require("@zag-js/dom-query");
6
33
  function isValidKey(e) {
7
- return !(e.metaKey || !domQuery.isMac() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
34
+ return !(e.metaKey || !(0, import_dom_query.isMac)() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
8
35
  }
9
36
  var nonTextInputTypes = /* @__PURE__ */ new Set(["checkbox", "radio", "range", "color", "file", "image", "button", "submit", "reset"]);
10
37
  function isKeyboardFocusEvent(isTextInput, modality, e) {
11
- const eventTarget = e ? domQuery.getEventTarget(e) : null;
12
- const doc = domQuery.getDocument(eventTarget);
13
- const win = domQuery.getWindow(eventTarget);
14
- const activeElement = domQuery.getActiveElement(doc);
38
+ const eventTarget = e ? (0, import_dom_query.getEventTarget)(e) : null;
39
+ const doc = (0, import_dom_query.getDocument)(eventTarget);
40
+ const win = (0, import_dom_query.getWindow)(eventTarget);
41
+ const activeElement = (0, import_dom_query.getActiveElement)(doc);
15
42
  isTextInput = isTextInput || activeElement instanceof win.HTMLInputElement && !nonTextInputTypes.has(activeElement?.type) || activeElement instanceof win.HTMLTextAreaElement || activeElement instanceof win.HTMLElement && activeElement.isContentEditable;
16
43
  return !(isTextInput && modality === "keyboard" && e instanceof win.KeyboardEvent && !Reflect.has(FOCUS_VISIBLE_INPUT_KEYS, e.key));
17
44
  }
@@ -45,14 +72,14 @@ function handlePointerEvent(e) {
45
72
  }
46
73
  }
47
74
  function handleClickEvent(e) {
48
- if (domQuery.isVirtualClick(e)) {
75
+ if ((0, import_dom_query.isVirtualClick)(e)) {
49
76
  hasEventBeforeFocus = true;
50
77
  currentModality = "virtual";
51
78
  }
52
79
  }
53
80
  function handleFocusEvent(e) {
54
- const target = domQuery.getEventTarget(e);
55
- if (target === domQuery.getWindow(target) || target === domQuery.getDocument(target) || ignoreFocusEvent || !e.isTrusted) {
81
+ const target = (0, import_dom_query.getEventTarget)(e);
82
+ if (target === (0, import_dom_query.getWindow)(target) || target === (0, import_dom_query.getDocument)(target) || ignoreFocusEvent || !e.isTrusted) {
56
83
  return;
57
84
  }
58
85
  if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
@@ -63,15 +90,16 @@ function handleFocusEvent(e) {
63
90
  hasBlurredWindowRecently = false;
64
91
  }
65
92
  function handleWindowBlur() {
93
+ if (ignoreFocusEvent) return;
66
94
  hasEventBeforeFocus = false;
67
95
  hasBlurredWindowRecently = true;
68
96
  }
69
97
  function setupGlobalFocusEvents(root) {
70
- if (typeof window === "undefined" || listenerMap.get(domQuery.getWindow(root))) {
98
+ if (typeof window === "undefined" || listenerMap.get((0, import_dom_query.getWindow)(root))) {
71
99
  return;
72
100
  }
73
- const win = domQuery.getWindow(root);
74
- const doc = domQuery.getDocument(root);
101
+ const win = (0, import_dom_query.getWindow)(root);
102
+ const doc = (0, import_dom_query.getDocument)(root);
75
103
  let focus = win.HTMLElement.prototype.focus;
76
104
  function patchedFocus() {
77
105
  hasEventBeforeFocus = true;
@@ -108,8 +136,11 @@ function setupGlobalFocusEvents(root) {
108
136
  listenerMap.set(win, { focus });
109
137
  }
110
138
  var tearDownWindowFocusTracking = (root, loadListener) => {
111
- const win = domQuery.getWindow(root);
112
- const doc = domQuery.getDocument(root);
139
+ const win = (0, import_dom_query.getWindow)(root);
140
+ const doc = (0, import_dom_query.getDocument)(root);
141
+ if (loadListener) {
142
+ doc.removeEventListener("DOMContentLoaded", loadListener);
143
+ }
113
144
  const listenerData = listenerMap.get(win);
114
145
  if (!listenerData) {
115
146
  return;
@@ -170,11 +201,13 @@ function trackFocusVisible(props = {}) {
170
201
  changeHandlers.delete(handler);
171
202
  };
172
203
  }
173
-
174
- exports.getInteractionModality = getInteractionModality;
175
- exports.ignoreFocusEvent = ignoreFocusEvent;
176
- exports.isFocusVisible = isFocusVisible;
177
- exports.listenerMap = listenerMap;
178
- exports.setInteractionModality = setInteractionModality;
179
- exports.trackFocusVisible = trackFocusVisible;
180
- exports.trackInteractionModality = trackInteractionModality;
204
+ // Annotate the CommonJS export names for ESM import in node:
205
+ 0 && (module.exports = {
206
+ getInteractionModality,
207
+ ignoreFocusEvent,
208
+ isFocusVisible,
209
+ listenerMap,
210
+ setInteractionModality,
211
+ trackFocusVisible,
212
+ trackInteractionModality
213
+ });
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import { getWindow, getDocument, getEventTarget, getActiveElement, isVirtualClick, isMac } from '@zag-js/dom-query';
2
-
3
1
  // src/index.ts
2
+ import { getActiveElement, getDocument, getEventTarget, getWindow, isMac, isVirtualClick } from "@zag-js/dom-query";
4
3
  function isValidKey(e) {
5
4
  return !(e.metaKey || !isMac() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
6
5
  }
@@ -61,6 +60,7 @@ function handleFocusEvent(e) {
61
60
  hasBlurredWindowRecently = false;
62
61
  }
63
62
  function handleWindowBlur() {
63
+ if (ignoreFocusEvent) return;
64
64
  hasEventBeforeFocus = false;
65
65
  hasBlurredWindowRecently = true;
66
66
  }
@@ -108,6 +108,9 @@ function setupGlobalFocusEvents(root) {
108
108
  var tearDownWindowFocusTracking = (root, loadListener) => {
109
109
  const win = getWindow(root);
110
110
  const doc = getDocument(root);
111
+ if (loadListener) {
112
+ doc.removeEventListener("DOMContentLoaded", loadListener);
113
+ }
111
114
  const listenerData = listenerMap.get(win);
112
115
  if (!listenerData) {
113
116
  return;
@@ -168,5 +171,12 @@ function trackFocusVisible(props = {}) {
168
171
  changeHandlers.delete(handler);
169
172
  };
170
173
  }
171
-
172
- export { getInteractionModality, ignoreFocusEvent, isFocusVisible, listenerMap, setInteractionModality, trackFocusVisible, trackInteractionModality };
174
+ export {
175
+ getInteractionModality,
176
+ ignoreFocusEvent,
177
+ isFocusVisible,
178
+ listenerMap,
179
+ setInteractionModality,
180
+ trackFocusVisible,
181
+ trackInteractionModality
182
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/focus-visible",
3
- "version": "1.34.1",
3
+ "version": "1.35.1",
4
4
  "description": "Focus visible polyfill utility based on WICG",
5
5
  "keywords": [
6
6
  "js",
@@ -25,7 +25,7 @@
25
25
  "clean-package": "../../../clean-package.config.json",
26
26
  "main": "dist/index.js",
27
27
  "dependencies": {
28
- "@zag-js/dom-query": "1.34.1"
28
+ "@zag-js/dom-query": "1.35.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "clean-package": "2.2.0"