@zag-js/focus-visible 1.44.0 → 1.46.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 +29 -19
- package/dist/index.mjs +29 -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,31 @@ 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
|
-
|
|
141
|
+
writable: true,
|
|
142
|
+
value: patchedFocus2
|
|
146
143
|
});
|
|
144
|
+
return nativeFocus;
|
|
147
145
|
} catch {
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function setupGlobalFocusEvents(root) {
|
|
150
|
+
if (typeof window === "undefined" || listenerMap.get((0, import_dom_query.getWindow)(root))) {
|
|
151
|
+
return;
|
|
148
152
|
}
|
|
153
|
+
const win = (0, import_dom_query.getWindow)(root);
|
|
154
|
+
const doc = (0, import_dom_query.getDocument)(root);
|
|
155
|
+
const nativeFocus = patchFocusMethod(win);
|
|
149
156
|
doc.addEventListener("keydown", handleKeyboardEvent, true);
|
|
150
157
|
doc.addEventListener("keyup", handleKeyboardEvent, true);
|
|
151
158
|
doc.addEventListener("click", handleClickEvent, true);
|
|
@@ -167,7 +174,7 @@ function setupGlobalFocusEvents(root) {
|
|
|
167
174
|
},
|
|
168
175
|
{ once: true }
|
|
169
176
|
);
|
|
170
|
-
listenerMap.set(win, { focus });
|
|
177
|
+
listenerMap.set(win, { focus: nativeFocus });
|
|
171
178
|
}
|
|
172
179
|
var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
173
180
|
const win = (0, import_dom_query.getWindow)(root);
|
|
@@ -179,12 +186,15 @@ var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
|
179
186
|
if (!listenerData) {
|
|
180
187
|
return;
|
|
181
188
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
if (listenerData.focus) {
|
|
190
|
+
try {
|
|
191
|
+
Object.defineProperty(win.HTMLElement.prototype, "focus", {
|
|
192
|
+
configurable: true,
|
|
193
|
+
writable: true,
|
|
194
|
+
value: listenerData.focus
|
|
195
|
+
});
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
188
198
|
}
|
|
189
199
|
doc.removeEventListener("keydown", handleKeyboardEvent, true);
|
|
190
200
|
doc.removeEventListener("keyup", handleKeyboardEvent, true);
|
package/dist/index.mjs
CHANGED
|
@@ -98,24 +98,31 @@ 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
|
-
|
|
111
|
+
writable: true,
|
|
112
|
+
value: patchedFocus2
|
|
116
113
|
});
|
|
114
|
+
return nativeFocus;
|
|
117
115
|
} catch {
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function setupGlobalFocusEvents(root) {
|
|
120
|
+
if (typeof window === "undefined" || listenerMap.get(getWindow(root))) {
|
|
121
|
+
return;
|
|
118
122
|
}
|
|
123
|
+
const win = getWindow(root);
|
|
124
|
+
const doc = getDocument(root);
|
|
125
|
+
const nativeFocus = patchFocusMethod(win);
|
|
119
126
|
doc.addEventListener("keydown", handleKeyboardEvent, true);
|
|
120
127
|
doc.addEventListener("keyup", handleKeyboardEvent, true);
|
|
121
128
|
doc.addEventListener("click", handleClickEvent, true);
|
|
@@ -137,7 +144,7 @@ function setupGlobalFocusEvents(root) {
|
|
|
137
144
|
},
|
|
138
145
|
{ once: true }
|
|
139
146
|
);
|
|
140
|
-
listenerMap.set(win, { focus });
|
|
147
|
+
listenerMap.set(win, { focus: nativeFocus });
|
|
141
148
|
}
|
|
142
149
|
var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
143
150
|
const win = getWindow(root);
|
|
@@ -149,12 +156,15 @@ var tearDownWindowFocusTracking = (root, loadListener) => {
|
|
|
149
156
|
if (!listenerData) {
|
|
150
157
|
return;
|
|
151
158
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
if (listenerData.focus) {
|
|
160
|
+
try {
|
|
161
|
+
Object.defineProperty(win.HTMLElement.prototype, "focus", {
|
|
162
|
+
configurable: true,
|
|
163
|
+
writable: true,
|
|
164
|
+
value: listenerData.focus
|
|
165
|
+
});
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
158
168
|
}
|
|
159
169
|
doc.removeEventListener("keydown", handleKeyboardEvent, true);
|
|
160
170
|
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.46.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.46.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"clean-package": "2.2.0"
|