@zag-js/focus-visible 1.44.0 → 1.45.0
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +27 -19
- package/dist/index.mjs +27 -19
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
type Modality = "keyboard" | "pointer" | "virtual";
|
|
2
2
|
type RootNode = Document | ShadowRoot | Node;
|
|
3
3
|
interface GlobalListenerData {
|
|
4
|
-
focus
|
|
4
|
+
/** Unset when the prototype's `focus` could not be read, so there is nothing to restore. */
|
|
5
|
+
focus: VoidFunction | undefined;
|
|
5
6
|
}
|
|
6
7
|
declare let listenerMap: Map<Window, GlobalListenerData>;
|
|
7
8
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
type Modality = "keyboard" | "pointer" | "virtual";
|
|
2
2
|
type RootNode = Document | ShadowRoot | Node;
|
|
3
3
|
interface GlobalListenerData {
|
|
4
|
-
focus
|
|
4
|
+
/** Unset when the prototype's `focus` could not be read, so there is nothing to restore. */
|
|
5
|
+
focus: VoidFunction | undefined;
|
|
5
6
|
}
|
|
6
7
|
declare let listenerMap: Map<Window, GlobalListenerData>;
|
|
7
8
|
/**
|
package/dist/index.js
CHANGED
|
@@ -128,24 +128,30 @@ function handleWindowBlur() {
|
|
|
128
128
|
pendingLabelControl = null;
|
|
129
129
|
hasBlurredWindowRecently = true;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
if (typeof window === "undefined" || listenerMap.get((0, import_dom_query.getWindow)(root))) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const win = (0, import_dom_query.getWindow)(root);
|
|
136
|
-
const doc = (0, import_dom_query.getDocument)(root);
|
|
137
|
-
let focus = win.HTMLElement.prototype.focus;
|
|
138
|
-
function patchedFocus() {
|
|
139
|
-
hasEventBeforeFocus = true;
|
|
140
|
-
focus.apply(this, arguments);
|
|
141
|
-
}
|
|
131
|
+
function patchFocusMethod(win) {
|
|
142
132
|
try {
|
|
133
|
+
let patchedFocus2 = function() {
|
|
134
|
+
hasEventBeforeFocus = true;
|
|
135
|
+
nativeFocus.apply(this, arguments);
|
|
136
|
+
};
|
|
137
|
+
var patchedFocus = patchedFocus2;
|
|
138
|
+
const nativeFocus = win.HTMLElement.prototype.focus;
|
|
143
139
|
Object.defineProperty(win.HTMLElement.prototype, "focus", {
|
|
144
140
|
configurable: true,
|
|
145
|
-
value:
|
|
141
|
+
value: patchedFocus2
|
|
146
142
|
});
|
|
143
|
+
return nativeFocus;
|
|
147
144
|
} catch {
|
|
145
|
+
return void 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function setupGlobalFocusEvents(root) {
|
|
149
|
+
if (typeof window === "undefined" || listenerMap.get((0, import_dom_query.getWindow)(root))) {
|
|
150
|
+
return;
|
|
148
151
|
}
|
|
152
|
+
const win = (0, import_dom_query.getWindow)(root);
|
|
153
|
+
const doc = (0, import_dom_query.getDocument)(root);
|
|
154
|
+
const nativeFocus = patchFocusMethod(win);
|
|
149
155
|
doc.addEventListener("keydown", handleKeyboardEvent, true);
|
|
150
156
|
doc.addEventListener("keyup", handleKeyboardEvent, true);
|
|
151
157
|
doc.addEventListener("click", handleClickEvent, true);
|
|
@@ -167,7 +173,7 @@ function setupGlobalFocusEvents(root) {
|
|
|
167
173
|
},
|
|
168
174
|
{ once: true }
|
|
169
175
|
);
|
|
170
|
-
listenerMap.set(win, { focus });
|
|
176
|
+
listenerMap.set(win, { focus: nativeFocus });
|
|
171
177
|
}
|
|
172
178
|
var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
173
179
|
const win = (0, import_dom_query.getWindow)(root);
|
|
@@ -179,12 +185,14 @@ var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
|
179
185
|
if (!listenerData) {
|
|
180
186
|
return;
|
|
181
187
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
if (listenerData.focus) {
|
|
189
|
+
try {
|
|
190
|
+
Object.defineProperty(win.HTMLElement.prototype, "focus", {
|
|
191
|
+
configurable: true,
|
|
192
|
+
value: listenerData.focus
|
|
193
|
+
});
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
188
196
|
}
|
|
189
197
|
doc.removeEventListener("keydown", handleKeyboardEvent, true);
|
|
190
198
|
doc.removeEventListener("keyup", handleKeyboardEvent, true);
|
package/dist/index.mjs
CHANGED
|
@@ -98,24 +98,30 @@ function handleWindowBlur() {
|
|
|
98
98
|
pendingLabelControl = null;
|
|
99
99
|
hasBlurredWindowRecently = true;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
if (typeof window === "undefined" || listenerMap.get(getWindow(root))) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const win = getWindow(root);
|
|
106
|
-
const doc = getDocument(root);
|
|
107
|
-
let focus = win.HTMLElement.prototype.focus;
|
|
108
|
-
function patchedFocus() {
|
|
109
|
-
hasEventBeforeFocus = true;
|
|
110
|
-
focus.apply(this, arguments);
|
|
111
|
-
}
|
|
101
|
+
function patchFocusMethod(win) {
|
|
112
102
|
try {
|
|
103
|
+
let patchedFocus2 = function() {
|
|
104
|
+
hasEventBeforeFocus = true;
|
|
105
|
+
nativeFocus.apply(this, arguments);
|
|
106
|
+
};
|
|
107
|
+
var patchedFocus = patchedFocus2;
|
|
108
|
+
const nativeFocus = win.HTMLElement.prototype.focus;
|
|
113
109
|
Object.defineProperty(win.HTMLElement.prototype, "focus", {
|
|
114
110
|
configurable: true,
|
|
115
|
-
value:
|
|
111
|
+
value: patchedFocus2
|
|
116
112
|
});
|
|
113
|
+
return nativeFocus;
|
|
117
114
|
} catch {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function setupGlobalFocusEvents(root) {
|
|
119
|
+
if (typeof window === "undefined" || listenerMap.get(getWindow(root))) {
|
|
120
|
+
return;
|
|
118
121
|
}
|
|
122
|
+
const win = getWindow(root);
|
|
123
|
+
const doc = getDocument(root);
|
|
124
|
+
const nativeFocus = patchFocusMethod(win);
|
|
119
125
|
doc.addEventListener("keydown", handleKeyboardEvent, true);
|
|
120
126
|
doc.addEventListener("keyup", handleKeyboardEvent, true);
|
|
121
127
|
doc.addEventListener("click", handleClickEvent, true);
|
|
@@ -137,7 +143,7 @@ function setupGlobalFocusEvents(root) {
|
|
|
137
143
|
},
|
|
138
144
|
{ once: true }
|
|
139
145
|
);
|
|
140
|
-
listenerMap.set(win, { focus });
|
|
146
|
+
listenerMap.set(win, { focus: nativeFocus });
|
|
141
147
|
}
|
|
142
148
|
var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
143
149
|
const win = getWindow(root);
|
|
@@ -149,12 +155,14 @@ var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
|
149
155
|
if (!listenerData) {
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
if (listenerData.focus) {
|
|
159
|
+
try {
|
|
160
|
+
Object.defineProperty(win.HTMLElement.prototype, "focus", {
|
|
161
|
+
configurable: true,
|
|
162
|
+
value: listenerData.focus
|
|
163
|
+
});
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
158
166
|
}
|
|
159
167
|
doc.removeEventListener("keydown", handleKeyboardEvent, true);
|
|
160
168
|
doc.removeEventListener("keyup", handleKeyboardEvent, true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/focus-visible",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.45.0",
|
|
4
4
|
"description": "Focus visible polyfill utility based on WICG",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"clean-package": "../../../clean-package.config.json",
|
|
29
29
|
"main": "dist/index.js",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@zag-js/dom-query": "1.
|
|
31
|
+
"@zag-js/dom-query": "1.45.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"clean-package": "2.2.0"
|