@digipair/skill-web-spectrum 0.94.0-4 → 0.95.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/flow.cjs.js → flow.cjs.js} +24 -21
- package/{dist/flow.esm.js → flow.esm.js} +24 -21
- package/focus-visible.cjs.js +289 -0
- package/focus-visible.esm.js +287 -0
- package/{dist/index.cjs.js → index.cjs.js} +4479 -4139
- package/index.d.ts +1 -0
- package/{dist/index.esm.js → index.esm.js} +4479 -4139
- package/{dist → libs/skill-web-spectrum}/src/index.d.ts +0 -1
- package/{dist → libs/skill-web-spectrum}/src/lib/skill-web-spectrum.d.ts +0 -1
- package/package.json +6 -22
- package/README.md +0 -7
- package/dist/focus-visible.cjs.js +0 -297
- package/dist/focus-visible.esm.js +0 -295
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lib/skill-web-spectrum.d.ts.map +0 -1
- package/dist/src/lib/skill-web-spectrum.spec.d.ts +0 -2
- package/dist/src/lib/skill-web-spectrum.spec.d.ts.map +0 -1
- /package/{dist/index.d.ts → index.cjs.d.ts} +0 -0
- /package/{dist/schema.fr.json → schema.fr.json} +0 -0
- /package/{dist/schema.json → schema.json} +0 -0
|
@@ -20,6 +20,7 @@ function _defineProperties$2(target, props) {
|
|
|
20
20
|
}
|
|
21
21
|
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
22
22
|
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
23
24
|
return Constructor;
|
|
24
25
|
}
|
|
25
26
|
var SizeCache = /*#__PURE__*/ function() {
|
|
@@ -89,6 +90,7 @@ function _defineProperties$1(target, props) {
|
|
|
89
90
|
}
|
|
90
91
|
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
91
92
|
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
93
|
+
if (staticProps) _defineProperties$1(Constructor, staticProps);
|
|
92
94
|
return Constructor;
|
|
93
95
|
}
|
|
94
96
|
function _define_property$1(obj, key, value) {
|
|
@@ -105,7 +107,7 @@ function _define_property$1(obj, key, value) {
|
|
|
105
107
|
return obj;
|
|
106
108
|
}
|
|
107
109
|
function dim1(direction) {
|
|
108
|
-
return direction ===
|
|
110
|
+
return direction === "horizontal" ? "width" : "height";
|
|
109
111
|
}
|
|
110
112
|
var BaseLayout = /*#__PURE__*/ function() {
|
|
111
113
|
function BaseLayout(hostSink, config) {
|
|
@@ -159,16 +161,16 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
159
161
|
*/ this._last = -1;
|
|
160
162
|
/**
|
|
161
163
|
* Length in the scrolling direction.
|
|
162
|
-
*/ this._sizeDim =
|
|
164
|
+
*/ this._sizeDim = "height";
|
|
163
165
|
/**
|
|
164
166
|
* Length in the non-scrolling direction.
|
|
165
|
-
*/ this._secondarySizeDim =
|
|
167
|
+
*/ this._secondarySizeDim = "width";
|
|
166
168
|
/**
|
|
167
169
|
* Position in the scrolling direction.
|
|
168
|
-
*/ this._positionDim =
|
|
170
|
+
*/ this._positionDim = "top";
|
|
169
171
|
/**
|
|
170
172
|
* Position in the non-scrolling direction.
|
|
171
|
-
*/ this._secondaryPositionDim =
|
|
173
|
+
*/ this._secondaryPositionDim = "left";
|
|
172
174
|
/**
|
|
173
175
|
* Current scroll offset in pixels.
|
|
174
176
|
*/ this._scrollPosition = 0;
|
|
@@ -200,7 +202,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
200
202
|
key: "_getDefaultConfig",
|
|
201
203
|
value: function _getDefaultConfig() {
|
|
202
204
|
return {
|
|
203
|
-
direction:
|
|
205
|
+
direction: "vertical"
|
|
204
206
|
};
|
|
205
207
|
}
|
|
206
208
|
},
|
|
@@ -245,13 +247,13 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
245
247
|
},
|
|
246
248
|
set: function set(dir) {
|
|
247
249
|
// Force it to be either horizontal or vertical.
|
|
248
|
-
dir = dir ===
|
|
250
|
+
dir = dir === "horizontal" ? dir : "vertical";
|
|
249
251
|
if (dir !== this._direction) {
|
|
250
252
|
this._direction = dir;
|
|
251
|
-
this._sizeDim = dir ===
|
|
252
|
-
this._secondarySizeDim = dir ===
|
|
253
|
-
this._positionDim = dir ===
|
|
254
|
-
this._secondaryPositionDim = dir ===
|
|
253
|
+
this._sizeDim = dir === "horizontal" ? "width" : "height";
|
|
254
|
+
this._secondarySizeDim = dir === "horizontal" ? "height" : "width";
|
|
255
|
+
this._positionDim = dir === "horizontal" ? "left" : "top";
|
|
256
|
+
this._secondaryPositionDim = dir === "horizontal" ? "top" : "left";
|
|
255
257
|
this._triggerReflow();
|
|
256
258
|
}
|
|
257
259
|
}
|
|
@@ -417,7 +419,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
417
419
|
var _this_pin = this.pin, index = _this_pin.index, block = _this_pin.block;
|
|
418
420
|
this._scrollPosition = this._calculateScrollIntoViewPosition({
|
|
419
421
|
index: index,
|
|
420
|
-
block: block ||
|
|
422
|
+
block: block || "start"
|
|
421
423
|
}) - this.offsetWithinScroller[this._positionDim];
|
|
422
424
|
this._scrollError = lastScrollPosition - this._scrollPosition;
|
|
423
425
|
}
|
|
@@ -441,13 +443,13 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
441
443
|
var index = Math.min(this.items.length, Math.max(0, options.index));
|
|
442
444
|
var itemStartPosition = this._getItemPosition(index)[this._positionDim];
|
|
443
445
|
var scrollPosition = itemStartPosition;
|
|
444
|
-
if (block !==
|
|
446
|
+
if (block !== "start") {
|
|
445
447
|
var itemSize = this._getItemSize(index)[this._sizeDim];
|
|
446
|
-
if (block ===
|
|
448
|
+
if (block === "center") {
|
|
447
449
|
scrollPosition = itemStartPosition - 0.5 * this._viewDim1 + 0.5 * itemSize;
|
|
448
450
|
} else {
|
|
449
451
|
var itemEndPosition = itemStartPosition - this._viewDim1 + itemSize;
|
|
450
|
-
if (block ===
|
|
452
|
+
if (block === "end") {
|
|
451
453
|
scrollPosition = itemEndPosition;
|
|
452
454
|
} else {
|
|
453
455
|
// block === 'nearest'
|
|
@@ -470,7 +472,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
470
472
|
key: "_sendUnpinnedMessage",
|
|
471
473
|
value: function _sendUnpinnedMessage() {
|
|
472
474
|
this._hostSink({
|
|
473
|
-
type:
|
|
475
|
+
type: "unpinned"
|
|
474
476
|
});
|
|
475
477
|
}
|
|
476
478
|
},
|
|
@@ -478,7 +480,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
478
480
|
key: "_sendVisibilityChangedMessage",
|
|
479
481
|
value: function _sendVisibilityChangedMessage() {
|
|
480
482
|
this._hostSink({
|
|
481
|
-
type:
|
|
483
|
+
type: "visibilityChanged",
|
|
482
484
|
firstVisible: this._firstVisible,
|
|
483
485
|
lastVisible: this._lastVisible
|
|
484
486
|
});
|
|
@@ -495,7 +497,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
495
497
|
}
|
|
496
498
|
var _obj;
|
|
497
499
|
var message = {
|
|
498
|
-
type:
|
|
500
|
+
type: "stateChanged",
|
|
499
501
|
scrollSize: (_obj = {}, _define_property$1(_obj, this._sizeDim, this._scrollSize), _define_property$1(_obj, this._secondarySizeDim, null), _obj),
|
|
500
502
|
range: {
|
|
501
503
|
first: this._first,
|
|
@@ -605,6 +607,7 @@ function _defineProperties(target, props) {
|
|
|
605
607
|
}
|
|
606
608
|
function _create_class(Constructor, protoProps, staticProps) {
|
|
607
609
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
610
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
608
611
|
return Constructor;
|
|
609
612
|
}
|
|
610
613
|
function _define_property(obj, key, value) {
|
|
@@ -726,13 +729,13 @@ var flow = function(config) {
|
|
|
726
729
|
}, config);
|
|
727
730
|
};
|
|
728
731
|
function leadingMargin(direction) {
|
|
729
|
-
return direction ===
|
|
732
|
+
return direction === "horizontal" ? "marginLeft" : "marginTop";
|
|
730
733
|
}
|
|
731
734
|
function trailingMargin(direction) {
|
|
732
|
-
return direction ===
|
|
735
|
+
return direction === "horizontal" ? "marginRight" : "marginBottom";
|
|
733
736
|
}
|
|
734
737
|
function offset(direction) {
|
|
735
|
-
return direction ===
|
|
738
|
+
return direction === "horizontal" ? "xOffset" : "yOffset";
|
|
736
739
|
}
|
|
737
740
|
function collapseMargins(a, b) {
|
|
738
741
|
var _Math, _Math1;
|
|
@@ -18,6 +18,7 @@ function _defineProperties$2(target, props) {
|
|
|
18
18
|
}
|
|
19
19
|
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
20
20
|
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
21
|
+
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
21
22
|
return Constructor;
|
|
22
23
|
}
|
|
23
24
|
var SizeCache = /*#__PURE__*/ function() {
|
|
@@ -87,6 +88,7 @@ function _defineProperties$1(target, props) {
|
|
|
87
88
|
}
|
|
88
89
|
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
89
90
|
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
91
|
+
if (staticProps) _defineProperties$1(Constructor, staticProps);
|
|
90
92
|
return Constructor;
|
|
91
93
|
}
|
|
92
94
|
function _define_property$1(obj, key, value) {
|
|
@@ -103,7 +105,7 @@ function _define_property$1(obj, key, value) {
|
|
|
103
105
|
return obj;
|
|
104
106
|
}
|
|
105
107
|
function dim1(direction) {
|
|
106
|
-
return direction ===
|
|
108
|
+
return direction === "horizontal" ? "width" : "height";
|
|
107
109
|
}
|
|
108
110
|
var BaseLayout = /*#__PURE__*/ function() {
|
|
109
111
|
function BaseLayout(hostSink, config) {
|
|
@@ -157,16 +159,16 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
157
159
|
*/ this._last = -1;
|
|
158
160
|
/**
|
|
159
161
|
* Length in the scrolling direction.
|
|
160
|
-
*/ this._sizeDim =
|
|
162
|
+
*/ this._sizeDim = "height";
|
|
161
163
|
/**
|
|
162
164
|
* Length in the non-scrolling direction.
|
|
163
|
-
*/ this._secondarySizeDim =
|
|
165
|
+
*/ this._secondarySizeDim = "width";
|
|
164
166
|
/**
|
|
165
167
|
* Position in the scrolling direction.
|
|
166
|
-
*/ this._positionDim =
|
|
168
|
+
*/ this._positionDim = "top";
|
|
167
169
|
/**
|
|
168
170
|
* Position in the non-scrolling direction.
|
|
169
|
-
*/ this._secondaryPositionDim =
|
|
171
|
+
*/ this._secondaryPositionDim = "left";
|
|
170
172
|
/**
|
|
171
173
|
* Current scroll offset in pixels.
|
|
172
174
|
*/ this._scrollPosition = 0;
|
|
@@ -198,7 +200,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
198
200
|
key: "_getDefaultConfig",
|
|
199
201
|
value: function _getDefaultConfig() {
|
|
200
202
|
return {
|
|
201
|
-
direction:
|
|
203
|
+
direction: "vertical"
|
|
202
204
|
};
|
|
203
205
|
}
|
|
204
206
|
},
|
|
@@ -243,13 +245,13 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
243
245
|
},
|
|
244
246
|
set: function set(dir) {
|
|
245
247
|
// Force it to be either horizontal or vertical.
|
|
246
|
-
dir = dir ===
|
|
248
|
+
dir = dir === "horizontal" ? dir : "vertical";
|
|
247
249
|
if (dir !== this._direction) {
|
|
248
250
|
this._direction = dir;
|
|
249
|
-
this._sizeDim = dir ===
|
|
250
|
-
this._secondarySizeDim = dir ===
|
|
251
|
-
this._positionDim = dir ===
|
|
252
|
-
this._secondaryPositionDim = dir ===
|
|
251
|
+
this._sizeDim = dir === "horizontal" ? "width" : "height";
|
|
252
|
+
this._secondarySizeDim = dir === "horizontal" ? "height" : "width";
|
|
253
|
+
this._positionDim = dir === "horizontal" ? "left" : "top";
|
|
254
|
+
this._secondaryPositionDim = dir === "horizontal" ? "top" : "left";
|
|
253
255
|
this._triggerReflow();
|
|
254
256
|
}
|
|
255
257
|
}
|
|
@@ -415,7 +417,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
415
417
|
var _this_pin = this.pin, index = _this_pin.index, block = _this_pin.block;
|
|
416
418
|
this._scrollPosition = this._calculateScrollIntoViewPosition({
|
|
417
419
|
index: index,
|
|
418
|
-
block: block ||
|
|
420
|
+
block: block || "start"
|
|
419
421
|
}) - this.offsetWithinScroller[this._positionDim];
|
|
420
422
|
this._scrollError = lastScrollPosition - this._scrollPosition;
|
|
421
423
|
}
|
|
@@ -439,13 +441,13 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
439
441
|
var index = Math.min(this.items.length, Math.max(0, options.index));
|
|
440
442
|
var itemStartPosition = this._getItemPosition(index)[this._positionDim];
|
|
441
443
|
var scrollPosition = itemStartPosition;
|
|
442
|
-
if (block !==
|
|
444
|
+
if (block !== "start") {
|
|
443
445
|
var itemSize = this._getItemSize(index)[this._sizeDim];
|
|
444
|
-
if (block ===
|
|
446
|
+
if (block === "center") {
|
|
445
447
|
scrollPosition = itemStartPosition - 0.5 * this._viewDim1 + 0.5 * itemSize;
|
|
446
448
|
} else {
|
|
447
449
|
var itemEndPosition = itemStartPosition - this._viewDim1 + itemSize;
|
|
448
|
-
if (block ===
|
|
450
|
+
if (block === "end") {
|
|
449
451
|
scrollPosition = itemEndPosition;
|
|
450
452
|
} else {
|
|
451
453
|
// block === 'nearest'
|
|
@@ -468,7 +470,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
468
470
|
key: "_sendUnpinnedMessage",
|
|
469
471
|
value: function _sendUnpinnedMessage() {
|
|
470
472
|
this._hostSink({
|
|
471
|
-
type:
|
|
473
|
+
type: "unpinned"
|
|
472
474
|
});
|
|
473
475
|
}
|
|
474
476
|
},
|
|
@@ -476,7 +478,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
476
478
|
key: "_sendVisibilityChangedMessage",
|
|
477
479
|
value: function _sendVisibilityChangedMessage() {
|
|
478
480
|
this._hostSink({
|
|
479
|
-
type:
|
|
481
|
+
type: "visibilityChanged",
|
|
480
482
|
firstVisible: this._firstVisible,
|
|
481
483
|
lastVisible: this._lastVisible
|
|
482
484
|
});
|
|
@@ -493,7 +495,7 @@ var BaseLayout = /*#__PURE__*/ function() {
|
|
|
493
495
|
}
|
|
494
496
|
var _obj;
|
|
495
497
|
var message = {
|
|
496
|
-
type:
|
|
498
|
+
type: "stateChanged",
|
|
497
499
|
scrollSize: (_obj = {}, _define_property$1(_obj, this._sizeDim, this._scrollSize), _define_property$1(_obj, this._secondarySizeDim, null), _obj),
|
|
498
500
|
range: {
|
|
499
501
|
first: this._first,
|
|
@@ -603,6 +605,7 @@ function _defineProperties(target, props) {
|
|
|
603
605
|
}
|
|
604
606
|
function _create_class(Constructor, protoProps, staticProps) {
|
|
605
607
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
608
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
606
609
|
return Constructor;
|
|
607
610
|
}
|
|
608
611
|
function _define_property(obj, key, value) {
|
|
@@ -724,13 +727,13 @@ var flow = function(config) {
|
|
|
724
727
|
}, config);
|
|
725
728
|
};
|
|
726
729
|
function leadingMargin(direction) {
|
|
727
|
-
return direction ===
|
|
730
|
+
return direction === "horizontal" ? "marginLeft" : "marginTop";
|
|
728
731
|
}
|
|
729
732
|
function trailingMargin(direction) {
|
|
730
|
-
return direction ===
|
|
733
|
+
return direction === "horizontal" ? "marginRight" : "marginBottom";
|
|
731
734
|
}
|
|
732
735
|
function offset(direction) {
|
|
733
|
-
return direction ===
|
|
736
|
+
return direction === "horizontal" ? "xOffset" : "yOffset";
|
|
734
737
|
}
|
|
735
738
|
function collapseMargins(a, b) {
|
|
736
739
|
var _Math, _Math1;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _mergeNamespaces(n, m) {
|
|
4
|
+
m.forEach(function (e) {
|
|
5
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
6
|
+
if (k !== 'default' && !(k in n)) {
|
|
7
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
8
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return e[k]; }
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return Object.freeze(n);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
19
|
+
|
|
20
|
+
var focusVisible$2 = {
|
|
21
|
+
exports: {}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
(function (module, exports) {
|
|
25
|
+
(function(global, factory) {
|
|
26
|
+
factory() ;
|
|
27
|
+
})(commonjsGlobal, function() {
|
|
28
|
+
/**
|
|
29
|
+
* Applies the :focus-visible polyfill at the given scope.
|
|
30
|
+
* A scope in this case is either the top-level Document or a Shadow Root.
|
|
31
|
+
*
|
|
32
|
+
* @param {(Document|ShadowRoot)} scope
|
|
33
|
+
* @see https://github.com/WICG/focus-visible
|
|
34
|
+
*/ function applyFocusVisiblePolyfill(scope) {
|
|
35
|
+
var hadKeyboardEvent = true;
|
|
36
|
+
var hadFocusVisibleRecently = false;
|
|
37
|
+
var hadFocusVisibleRecentlyTimeout = null;
|
|
38
|
+
var inputTypesAllowlist = {
|
|
39
|
+
text: true,
|
|
40
|
+
search: true,
|
|
41
|
+
url: true,
|
|
42
|
+
tel: true,
|
|
43
|
+
email: true,
|
|
44
|
+
password: true,
|
|
45
|
+
number: true,
|
|
46
|
+
date: true,
|
|
47
|
+
month: true,
|
|
48
|
+
week: true,
|
|
49
|
+
time: true,
|
|
50
|
+
datetime: true,
|
|
51
|
+
"datetime-local": true
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Helper function for legacy browsers and iframes which sometimes focus
|
|
55
|
+
* elements like document, body, and non-interactive SVG.
|
|
56
|
+
* @param {Element} el
|
|
57
|
+
*/ function isValidFocusTarget(el) {
|
|
58
|
+
if (el && el !== document && el.nodeName !== "HTML" && el.nodeName !== "BODY" && "classList" in el && "contains" in el.classList) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Computes whether the given element should automatically trigger the
|
|
65
|
+
* `focus-visible` class being added, i.e. whether it should always match
|
|
66
|
+
* `:focus-visible` when focused.
|
|
67
|
+
* @param {Element} el
|
|
68
|
+
* @return {boolean}
|
|
69
|
+
*/ function focusTriggersKeyboardModality(el) {
|
|
70
|
+
var type = el.type;
|
|
71
|
+
var tagName = el.tagName;
|
|
72
|
+
if (tagName === "INPUT" && inputTypesAllowlist[type] && !el.readOnly) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (tagName === "TEXTAREA" && !el.readOnly) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (el.isContentEditable) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Add the `focus-visible` class to the given element if it was not added by
|
|
85
|
+
* the author.
|
|
86
|
+
* @param {Element} el
|
|
87
|
+
*/ function addFocusVisibleClass(el) {
|
|
88
|
+
if (el.classList.contains("focus-visible")) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
el.classList.add("focus-visible");
|
|
92
|
+
el.setAttribute("data-focus-visible-added", "");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Remove the `focus-visible` class from the given element if it was not
|
|
96
|
+
* originally added by the author.
|
|
97
|
+
* @param {Element} el
|
|
98
|
+
*/ function removeFocusVisibleClass(el) {
|
|
99
|
+
if (!el.hasAttribute("data-focus-visible-added")) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
el.classList.remove("focus-visible");
|
|
103
|
+
el.removeAttribute("data-focus-visible-added");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* If the most recent user interaction was via the keyboard;
|
|
107
|
+
* and the key press did not include a meta, alt/option, or control key;
|
|
108
|
+
* then the modality is keyboard. Otherwise, the modality is not keyboard.
|
|
109
|
+
* Apply `focus-visible` to any current active element and keep track
|
|
110
|
+
* of our keyboard modality state with `hadKeyboardEvent`.
|
|
111
|
+
* @param {KeyboardEvent} e
|
|
112
|
+
*/ function onKeyDown(e) {
|
|
113
|
+
if (e.metaKey || e.altKey || e.ctrlKey) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (isValidFocusTarget(scope.activeElement)) {
|
|
117
|
+
addFocusVisibleClass(scope.activeElement);
|
|
118
|
+
}
|
|
119
|
+
hadKeyboardEvent = true;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* If at any point a user clicks with a pointing device, ensure that we change
|
|
123
|
+
* the modality away from keyboard.
|
|
124
|
+
* This avoids the situation where a user presses a key on an already focused
|
|
125
|
+
* element, and then clicks on a different element, focusing it with a
|
|
126
|
+
* pointing device, while we still think we're in keyboard modality.
|
|
127
|
+
* @param {Event} e
|
|
128
|
+
*/ function onPointerDown(e) {
|
|
129
|
+
hadKeyboardEvent = false;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* On `focus`, add the `focus-visible` class to the target if:
|
|
133
|
+
* - the target received focus as a result of keyboard navigation, or
|
|
134
|
+
* - the event target is an element that will likely require interaction
|
|
135
|
+
* via the keyboard (e.g. a text box)
|
|
136
|
+
* @param {Event} e
|
|
137
|
+
*/ function onFocus(e) {
|
|
138
|
+
// Prevent IE from focusing the document or HTML element.
|
|
139
|
+
if (!isValidFocusTarget(e.target)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (hadKeyboardEvent || focusTriggersKeyboardModality(e.target)) {
|
|
143
|
+
addFocusVisibleClass(e.target);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* On `blur`, remove the `focus-visible` class from the target.
|
|
148
|
+
* @param {Event} e
|
|
149
|
+
*/ function onBlur(e) {
|
|
150
|
+
if (!isValidFocusTarget(e.target)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (e.target.classList.contains("focus-visible") || e.target.hasAttribute("data-focus-visible-added")) {
|
|
154
|
+
// To detect a tab/window switch, we look for a blur event followed
|
|
155
|
+
// rapidly by a visibility change.
|
|
156
|
+
// If we don't see a visibility change within 100ms, it's probably a
|
|
157
|
+
// regular focus change.
|
|
158
|
+
hadFocusVisibleRecently = true;
|
|
159
|
+
window.clearTimeout(hadFocusVisibleRecentlyTimeout);
|
|
160
|
+
hadFocusVisibleRecentlyTimeout = window.setTimeout(function() {
|
|
161
|
+
hadFocusVisibleRecently = false;
|
|
162
|
+
}, 100);
|
|
163
|
+
removeFocusVisibleClass(e.target);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* If the user changes tabs, keep track of whether or not the previously
|
|
168
|
+
* focused element had .focus-visible.
|
|
169
|
+
* @param {Event} e
|
|
170
|
+
*/ function onVisibilityChange(e) {
|
|
171
|
+
if (document.visibilityState === "hidden") {
|
|
172
|
+
// If the tab becomes active again, the browser will handle calling focus
|
|
173
|
+
// on the element (Safari actually calls it twice).
|
|
174
|
+
// If this tab change caused a blur on an element with focus-visible,
|
|
175
|
+
// re-apply the class when the user switches back to the tab.
|
|
176
|
+
if (hadFocusVisibleRecently) {
|
|
177
|
+
hadKeyboardEvent = true;
|
|
178
|
+
}
|
|
179
|
+
addInitialPointerMoveListeners();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Add a group of listeners to detect usage of any pointing devices.
|
|
184
|
+
* These listeners will be added when the polyfill first loads, and anytime
|
|
185
|
+
* the window is blurred, so that they are active when the window regains
|
|
186
|
+
* focus.
|
|
187
|
+
*/ function addInitialPointerMoveListeners() {
|
|
188
|
+
document.addEventListener("mousemove", onInitialPointerMove);
|
|
189
|
+
document.addEventListener("mousedown", onInitialPointerMove);
|
|
190
|
+
document.addEventListener("mouseup", onInitialPointerMove);
|
|
191
|
+
document.addEventListener("pointermove", onInitialPointerMove);
|
|
192
|
+
document.addEventListener("pointerdown", onInitialPointerMove);
|
|
193
|
+
document.addEventListener("pointerup", onInitialPointerMove);
|
|
194
|
+
document.addEventListener("touchmove", onInitialPointerMove);
|
|
195
|
+
document.addEventListener("touchstart", onInitialPointerMove);
|
|
196
|
+
document.addEventListener("touchend", onInitialPointerMove);
|
|
197
|
+
}
|
|
198
|
+
function removeInitialPointerMoveListeners() {
|
|
199
|
+
document.removeEventListener("mousemove", onInitialPointerMove);
|
|
200
|
+
document.removeEventListener("mousedown", onInitialPointerMove);
|
|
201
|
+
document.removeEventListener("mouseup", onInitialPointerMove);
|
|
202
|
+
document.removeEventListener("pointermove", onInitialPointerMove);
|
|
203
|
+
document.removeEventListener("pointerdown", onInitialPointerMove);
|
|
204
|
+
document.removeEventListener("pointerup", onInitialPointerMove);
|
|
205
|
+
document.removeEventListener("touchmove", onInitialPointerMove);
|
|
206
|
+
document.removeEventListener("touchstart", onInitialPointerMove);
|
|
207
|
+
document.removeEventListener("touchend", onInitialPointerMove);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* When the polfyill first loads, assume the user is in keyboard modality.
|
|
211
|
+
* If any event is received from a pointing device (e.g. mouse, pointer,
|
|
212
|
+
* touch), turn off keyboard modality.
|
|
213
|
+
* This accounts for situations where focus enters the page from the URL bar.
|
|
214
|
+
* @param {Event} e
|
|
215
|
+
*/ function onInitialPointerMove(e) {
|
|
216
|
+
// Work around a Safari quirk that fires a mousemove on <html> whenever the
|
|
217
|
+
// window blurs, even if you're tabbing out of the page. ¯\_(ツ)_/¯
|
|
218
|
+
if (e.target.nodeName && e.target.nodeName.toLowerCase() === "html") {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
hadKeyboardEvent = false;
|
|
222
|
+
removeInitialPointerMoveListeners();
|
|
223
|
+
}
|
|
224
|
+
// For some kinds of state, we are interested in changes at the global scope
|
|
225
|
+
// only. For example, global pointer input, global key presses and global
|
|
226
|
+
// visibility change should affect the state at every scope:
|
|
227
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
228
|
+
document.addEventListener("mousedown", onPointerDown, true);
|
|
229
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
230
|
+
document.addEventListener("touchstart", onPointerDown, true);
|
|
231
|
+
document.addEventListener("visibilitychange", onVisibilityChange, true);
|
|
232
|
+
addInitialPointerMoveListeners();
|
|
233
|
+
// For focus and blur, we specifically care about state changes in the local
|
|
234
|
+
// scope. This is because focus / blur events that originate from within a
|
|
235
|
+
// shadow root are not re-dispatched from the host element if it was already
|
|
236
|
+
// the active element in its own scope:
|
|
237
|
+
scope.addEventListener("focus", onFocus, true);
|
|
238
|
+
scope.addEventListener("blur", onBlur, true);
|
|
239
|
+
// We detect that a node is a ShadowRoot by ensuring that it is a
|
|
240
|
+
// DocumentFragment and also has a host property. This check covers native
|
|
241
|
+
// implementation and polyfill implementation transparently. If we only cared
|
|
242
|
+
// about the native implementation, we could just check if the scope was
|
|
243
|
+
// an instance of a ShadowRoot.
|
|
244
|
+
if (scope.nodeType === Node.DOCUMENT_FRAGMENT_NODE && scope.host) {
|
|
245
|
+
// Since a ShadowRoot is a special kind of DocumentFragment, it does not
|
|
246
|
+
// have a root element to add a class to. So, we add this attribute to the
|
|
247
|
+
// host element instead:
|
|
248
|
+
scope.host.setAttribute("data-js-focus-visible", "");
|
|
249
|
+
} else if (scope.nodeType === Node.DOCUMENT_NODE) {
|
|
250
|
+
document.documentElement.classList.add("js-focus-visible");
|
|
251
|
+
document.documentElement.setAttribute("data-js-focus-visible", "");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// It is important to wrap all references to global window and document in
|
|
255
|
+
// these checks to support server-side rendering use cases
|
|
256
|
+
// @see https://github.com/WICG/focus-visible/issues/199
|
|
257
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
258
|
+
// Make the polyfill helper globally available. This can be used as a signal
|
|
259
|
+
// to interested libraries that wish to coordinate with the polyfill for e.g.,
|
|
260
|
+
// applying the polyfill to a shadow root:
|
|
261
|
+
window.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;
|
|
262
|
+
// Notify interested libraries of the polyfill's presence, in case the
|
|
263
|
+
// polyfill was loaded lazily:
|
|
264
|
+
var event;
|
|
265
|
+
try {
|
|
266
|
+
event = new CustomEvent("focus-visible-polyfill-ready");
|
|
267
|
+
} catch (error) {
|
|
268
|
+
// IE11 does not support using CustomEvent as a constructor directly:
|
|
269
|
+
event = document.createEvent("CustomEvent");
|
|
270
|
+
event.initCustomEvent("focus-visible-polyfill-ready", false, false, {});
|
|
271
|
+
}
|
|
272
|
+
window.dispatchEvent(event);
|
|
273
|
+
}
|
|
274
|
+
if (typeof document !== "undefined") {
|
|
275
|
+
// Apply the polyfill to the global document, so that no JavaScript
|
|
276
|
+
// coordination is required to use the polyfill in the top-level document:
|
|
277
|
+
applyFocusVisiblePolyfill(document);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}());
|
|
281
|
+
|
|
282
|
+
var focusVisible = focusVisible$2.exports;
|
|
283
|
+
|
|
284
|
+
var focusVisible$1 = /*#__PURE__*/_mergeNamespaces({
|
|
285
|
+
__proto__: null,
|
|
286
|
+
'default': focusVisible
|
|
287
|
+
}, [focusVisible$2.exports]);
|
|
288
|
+
|
|
289
|
+
exports.focusVisible = focusVisible$1;
|