@digipair/skill-web-spectrum 0.113.1 → 0.114.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.
@@ -0,0 +1,295 @@
1
+ function _mergeNamespaces(n, m) {
2
+ m.forEach(function (e) {
3
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
4
+ if (k !== 'default' && !(k in n)) {
5
+ var d = Object.getOwnPropertyDescriptor(e, k);
6
+ Object.defineProperty(n, k, d.get ? d : {
7
+ enumerable: true,
8
+ get: function () { return e[k]; }
9
+ });
10
+ }
11
+ });
12
+ });
13
+ return Object.freeze(n);
14
+ }
15
+
16
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
17
+ function getDefaultExportFromCjs(x) {
18
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
19
+ }
20
+
21
+ var focusVisible$2 = {
22
+ exports: {}
23
+ };
24
+
25
+ (function (module, exports) {
26
+ function _type_of(obj) {
27
+ "@swc/helpers - typeof";
28
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
29
+ }
30
+ (function(global, factory) {
31
+ (_type_of(exports)) === 'object' && 'object' !== 'undefined' ? factory() : factory();
32
+ })(commonjsGlobal, function() {
33
+ /**
34
+ * Applies the :focus-visible polyfill at the given scope.
35
+ * A scope in this case is either the top-level Document or a Shadow Root.
36
+ *
37
+ * @param {(Document|ShadowRoot)} scope
38
+ * @see https://github.com/WICG/focus-visible
39
+ */ function applyFocusVisiblePolyfill(scope) {
40
+ var hadKeyboardEvent = true;
41
+ var hadFocusVisibleRecently = false;
42
+ var hadFocusVisibleRecentlyTimeout = null;
43
+ var inputTypesAllowlist = {
44
+ text: true,
45
+ search: true,
46
+ url: true,
47
+ tel: true,
48
+ email: true,
49
+ password: true,
50
+ number: true,
51
+ date: true,
52
+ month: true,
53
+ week: true,
54
+ time: true,
55
+ datetime: true,
56
+ 'datetime-local': true
57
+ };
58
+ /**
59
+ * Helper function for legacy browsers and iframes which sometimes focus
60
+ * elements like document, body, and non-interactive SVG.
61
+ * @param {Element} el
62
+ */ function isValidFocusTarget(el) {
63
+ if (el && el !== document && el.nodeName !== 'HTML' && el.nodeName !== 'BODY' && 'classList' in el && 'contains' in el.classList) {
64
+ return true;
65
+ }
66
+ return false;
67
+ }
68
+ /**
69
+ * Computes whether the given element should automatically trigger the
70
+ * `focus-visible` class being added, i.e. whether it should always match
71
+ * `:focus-visible` when focused.
72
+ * @param {Element} el
73
+ * @return {boolean}
74
+ */ function focusTriggersKeyboardModality(el) {
75
+ var type = el.type;
76
+ var tagName = el.tagName;
77
+ if (tagName === 'INPUT' && inputTypesAllowlist[type] && !el.readOnly) {
78
+ return true;
79
+ }
80
+ if (tagName === 'TEXTAREA' && !el.readOnly) {
81
+ return true;
82
+ }
83
+ if (el.isContentEditable) {
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ /**
89
+ * Add the `focus-visible` class to the given element if it was not added by
90
+ * the author.
91
+ * @param {Element} el
92
+ */ function addFocusVisibleClass(el) {
93
+ if (el.classList.contains('focus-visible')) {
94
+ return;
95
+ }
96
+ el.classList.add('focus-visible');
97
+ el.setAttribute('data-focus-visible-added', '');
98
+ }
99
+ /**
100
+ * Remove the `focus-visible` class from the given element if it was not
101
+ * originally added by the author.
102
+ * @param {Element} el
103
+ */ function removeFocusVisibleClass(el) {
104
+ if (!el.hasAttribute('data-focus-visible-added')) {
105
+ return;
106
+ }
107
+ el.classList.remove('focus-visible');
108
+ el.removeAttribute('data-focus-visible-added');
109
+ }
110
+ /**
111
+ * If the most recent user interaction was via the keyboard;
112
+ * and the key press did not include a meta, alt/option, or control key;
113
+ * then the modality is keyboard. Otherwise, the modality is not keyboard.
114
+ * Apply `focus-visible` to any current active element and keep track
115
+ * of our keyboard modality state with `hadKeyboardEvent`.
116
+ * @param {KeyboardEvent} e
117
+ */ function onKeyDown(e) {
118
+ if (e.metaKey || e.altKey || e.ctrlKey) {
119
+ return;
120
+ }
121
+ if (isValidFocusTarget(scope.activeElement)) {
122
+ addFocusVisibleClass(scope.activeElement);
123
+ }
124
+ hadKeyboardEvent = true;
125
+ }
126
+ /**
127
+ * If at any point a user clicks with a pointing device, ensure that we change
128
+ * the modality away from keyboard.
129
+ * This avoids the situation where a user presses a key on an already focused
130
+ * element, and then clicks on a different element, focusing it with a
131
+ * pointing device, while we still think we're in keyboard modality.
132
+ * @param {Event} e
133
+ */ function onPointerDown(e) {
134
+ hadKeyboardEvent = false;
135
+ }
136
+ /**
137
+ * On `focus`, add the `focus-visible` class to the target if:
138
+ * - the target received focus as a result of keyboard navigation, or
139
+ * - the event target is an element that will likely require interaction
140
+ * via the keyboard (e.g. a text box)
141
+ * @param {Event} e
142
+ */ function onFocus(e) {
143
+ // Prevent IE from focusing the document or HTML element.
144
+ if (!isValidFocusTarget(e.target)) {
145
+ return;
146
+ }
147
+ if (hadKeyboardEvent || focusTriggersKeyboardModality(e.target)) {
148
+ addFocusVisibleClass(e.target);
149
+ }
150
+ }
151
+ /**
152
+ * On `blur`, remove the `focus-visible` class from the target.
153
+ * @param {Event} e
154
+ */ function onBlur(e) {
155
+ if (!isValidFocusTarget(e.target)) {
156
+ return;
157
+ }
158
+ if (e.target.classList.contains('focus-visible') || e.target.hasAttribute('data-focus-visible-added')) {
159
+ // To detect a tab/window switch, we look for a blur event followed
160
+ // rapidly by a visibility change.
161
+ // If we don't see a visibility change within 100ms, it's probably a
162
+ // regular focus change.
163
+ hadFocusVisibleRecently = true;
164
+ window.clearTimeout(hadFocusVisibleRecentlyTimeout);
165
+ hadFocusVisibleRecentlyTimeout = window.setTimeout(function() {
166
+ hadFocusVisibleRecently = false;
167
+ }, 100);
168
+ removeFocusVisibleClass(e.target);
169
+ }
170
+ }
171
+ /**
172
+ * If the user changes tabs, keep track of whether or not the previously
173
+ * focused element had .focus-visible.
174
+ * @param {Event} e
175
+ */ function onVisibilityChange(e) {
176
+ if (document.visibilityState === 'hidden') {
177
+ // If the tab becomes active again, the browser will handle calling focus
178
+ // on the element (Safari actually calls it twice).
179
+ // If this tab change caused a blur on an element with focus-visible,
180
+ // re-apply the class when the user switches back to the tab.
181
+ if (hadFocusVisibleRecently) {
182
+ hadKeyboardEvent = true;
183
+ }
184
+ addInitialPointerMoveListeners();
185
+ }
186
+ }
187
+ /**
188
+ * Add a group of listeners to detect usage of any pointing devices.
189
+ * These listeners will be added when the polyfill first loads, and anytime
190
+ * the window is blurred, so that they are active when the window regains
191
+ * focus.
192
+ */ function addInitialPointerMoveListeners() {
193
+ document.addEventListener('mousemove', onInitialPointerMove);
194
+ document.addEventListener('mousedown', onInitialPointerMove);
195
+ document.addEventListener('mouseup', onInitialPointerMove);
196
+ document.addEventListener('pointermove', onInitialPointerMove);
197
+ document.addEventListener('pointerdown', onInitialPointerMove);
198
+ document.addEventListener('pointerup', onInitialPointerMove);
199
+ document.addEventListener('touchmove', onInitialPointerMove);
200
+ document.addEventListener('touchstart', onInitialPointerMove);
201
+ document.addEventListener('touchend', onInitialPointerMove);
202
+ }
203
+ function removeInitialPointerMoveListeners() {
204
+ document.removeEventListener('mousemove', onInitialPointerMove);
205
+ document.removeEventListener('mousedown', onInitialPointerMove);
206
+ document.removeEventListener('mouseup', onInitialPointerMove);
207
+ document.removeEventListener('pointermove', onInitialPointerMove);
208
+ document.removeEventListener('pointerdown', onInitialPointerMove);
209
+ document.removeEventListener('pointerup', onInitialPointerMove);
210
+ document.removeEventListener('touchmove', onInitialPointerMove);
211
+ document.removeEventListener('touchstart', onInitialPointerMove);
212
+ document.removeEventListener('touchend', onInitialPointerMove);
213
+ }
214
+ /**
215
+ * When the polfyill first loads, assume the user is in keyboard modality.
216
+ * If any event is received from a pointing device (e.g. mouse, pointer,
217
+ * touch), turn off keyboard modality.
218
+ * This accounts for situations where focus enters the page from the URL bar.
219
+ * @param {Event} e
220
+ */ function onInitialPointerMove(e) {
221
+ // Work around a Safari quirk that fires a mousemove on <html> whenever the
222
+ // window blurs, even if you're tabbing out of the page. ¯\_(ツ)_/¯
223
+ if (e.target.nodeName && e.target.nodeName.toLowerCase() === 'html') {
224
+ return;
225
+ }
226
+ hadKeyboardEvent = false;
227
+ removeInitialPointerMoveListeners();
228
+ }
229
+ // For some kinds of state, we are interested in changes at the global scope
230
+ // only. For example, global pointer input, global key presses and global
231
+ // visibility change should affect the state at every scope:
232
+ document.addEventListener('keydown', onKeyDown, true);
233
+ document.addEventListener('mousedown', onPointerDown, true);
234
+ document.addEventListener('pointerdown', onPointerDown, true);
235
+ document.addEventListener('touchstart', onPointerDown, true);
236
+ document.addEventListener('visibilitychange', onVisibilityChange, true);
237
+ addInitialPointerMoveListeners();
238
+ // For focus and blur, we specifically care about state changes in the local
239
+ // scope. This is because focus / blur events that originate from within a
240
+ // shadow root are not re-dispatched from the host element if it was already
241
+ // the active element in its own scope:
242
+ scope.addEventListener('focus', onFocus, true);
243
+ scope.addEventListener('blur', onBlur, true);
244
+ // We detect that a node is a ShadowRoot by ensuring that it is a
245
+ // DocumentFragment and also has a host property. This check covers native
246
+ // implementation and polyfill implementation transparently. If we only cared
247
+ // about the native implementation, we could just check if the scope was
248
+ // an instance of a ShadowRoot.
249
+ if (scope.nodeType === Node.DOCUMENT_FRAGMENT_NODE && scope.host) {
250
+ // Since a ShadowRoot is a special kind of DocumentFragment, it does not
251
+ // have a root element to add a class to. So, we add this attribute to the
252
+ // host element instead:
253
+ scope.host.setAttribute('data-js-focus-visible', '');
254
+ } else if (scope.nodeType === Node.DOCUMENT_NODE) {
255
+ document.documentElement.classList.add('js-focus-visible');
256
+ document.documentElement.setAttribute('data-js-focus-visible', '');
257
+ }
258
+ }
259
+ // It is important to wrap all references to global window and document in
260
+ // these checks to support server-side rendering use cases
261
+ // @see https://github.com/WICG/focus-visible/issues/199
262
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
263
+ // Make the polyfill helper globally available. This can be used as a signal
264
+ // to interested libraries that wish to coordinate with the polyfill for e.g.,
265
+ // applying the polyfill to a shadow root:
266
+ window.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;
267
+ // Notify interested libraries of the polyfill's presence, in case the
268
+ // polyfill was loaded lazily:
269
+ var event;
270
+ try {
271
+ event = new CustomEvent('focus-visible-polyfill-ready');
272
+ } catch (error) {
273
+ // IE11 does not support using CustomEvent as a constructor directly:
274
+ event = document.createEvent('CustomEvent');
275
+ event.initCustomEvent('focus-visible-polyfill-ready', false, false, {});
276
+ }
277
+ window.dispatchEvent(event);
278
+ }
279
+ if (typeof document !== 'undefined') {
280
+ // Apply the polyfill to the global document, so that no JavaScript
281
+ // coordination is required to use the polyfill in the top-level document:
282
+ applyFocusVisiblePolyfill(document);
283
+ }
284
+ });
285
+ } (focusVisible$2, focusVisible$2.exports));
286
+
287
+ var focusVisibleExports = focusVisible$2.exports;
288
+ var focusVisible = /*@__PURE__*/getDefaultExportFromCjs(focusVisibleExports);
289
+
290
+ var focusVisible$1 = /*#__PURE__*/_mergeNamespaces({
291
+ __proto__: null,
292
+ default: focusVisible
293
+ }, [focusVisibleExports]);
294
+
295
+ export { focusVisible$1 as f };