@patternfly/pfe-core 2.4.0 → 3.0.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/README.md +0 -1
- package/controllers/cascade-controller.d.ts +6 -0
- package/controllers/cascade-controller.js +5 -3
- package/controllers/cascade-controller.js.map +1 -1
- package/controllers/floating-dom-controller.d.ts +2 -2
- package/controllers/floating-dom-controller.js +84 -81
- package/controllers/floating-dom-controller.js.map +1 -1
- package/controllers/internals-controller.d.ts +86 -41
- package/controllers/internals-controller.js +322 -36
- package/controllers/internals-controller.js.map +1 -1
- package/controllers/light-dom-controller.js.map +1 -1
- package/controllers/listbox-controller.d.ts +58 -0
- package/controllers/listbox-controller.js +250 -0
- package/controllers/listbox-controller.js.map +1 -0
- package/controllers/logger.d.ts +27 -3
- package/controllers/logger.js +50 -9
- package/controllers/logger.js.map +1 -1
- package/controllers/overflow-controller.d.ts +10 -3
- package/controllers/overflow-controller.js +75 -44
- package/controllers/overflow-controller.js.map +1 -1
- package/controllers/perf-controller.js.map +1 -1
- package/controllers/property-observer-controller.js +2 -3
- package/controllers/property-observer-controller.js.map +1 -1
- package/controllers/roving-tabindex-controller.d.ts +42 -24
- package/controllers/roving-tabindex-controller.js +167 -140
- package/controllers/roving-tabindex-controller.js.map +1 -1
- package/controllers/scroll-spy-controller.js +91 -93
- package/controllers/scroll-spy-controller.js.map +1 -1
- package/controllers/slot-controller.d.ts +18 -20
- package/controllers/slot-controller.js +89 -91
- package/controllers/slot-controller.js.map +1 -1
- package/controllers/style-controller.js.map +1 -1
- package/controllers/tabs-aria-controller.d.ts +29 -0
- package/controllers/tabs-aria-controller.js +95 -0
- package/controllers/tabs-aria-controller.js.map +1 -0
- package/controllers/timestamp-controller.js +68 -70
- package/controllers/timestamp-controller.js.map +1 -1
- package/core.d.ts +3 -0
- package/core.js.map +1 -1
- package/custom-elements.json +3245 -1317
- package/decorators/bound.js.map +1 -1
- package/decorators/cascades.d.ts +1 -0
- package/decorators/cascades.js +1 -0
- package/decorators/cascades.js.map +1 -1
- package/decorators/deprecation.js.map +1 -1
- package/decorators/initializer.js.map +1 -1
- package/decorators/observed.js.map +1 -1
- package/decorators/time.js.map +1 -1
- package/decorators/trace.js.map +1 -1
- package/functions/containsDeep.d.ts +6 -0
- package/functions/containsDeep.js +21 -0
- package/functions/containsDeep.js.map +1 -0
- package/functions/context.d.ts +9 -0
- package/functions/context.js +17 -0
- package/functions/context.js.map +1 -0
- package/functions/debounce.js.map +1 -1
- package/functions/isElementInView.js.map +1 -1
- package/package.json +7 -4
- package/functions/deprecatedCustomEvent.d.ts +0 -5
- package/functions/deprecatedCustomEvent.js +0 -12
- package/functions/deprecatedCustomEvent.js.map +0 -1
|
@@ -1,201 +1,228 @@
|
|
|
1
|
+
var _RovingTabindexController_instances, _a, _RovingTabindexController_activeItem, _RovingTabindexController_itemsContainer, _RovingTabindexController_items, _RovingTabindexController_gainedInitialFocus, _RovingTabindexController_focusableItems_get, _RovingTabindexController_activeIndex_get, _RovingTabindexController_itemIndex_get, _RovingTabindexController_options, _RovingTabindexController_initContainer, _RovingTabindexController_onKeydown;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
1
3
|
const isFocusableElement = (el) => !!el &&
|
|
2
|
-
!el.hasAttribute('disabled') &&
|
|
3
4
|
!el.ariaHidden &&
|
|
4
5
|
!el.hasAttribute('hidden');
|
|
5
6
|
/**
|
|
6
7
|
* Implements roving tabindex, as described in WAI-ARIA practices, [Managing Focus Within
|
|
7
|
-
* Components Using a Roving
|
|
8
|
-
*
|
|
8
|
+
* Components Using a Roving tabindex][rti]
|
|
9
|
+
*
|
|
10
|
+
* [rti]: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex
|
|
9
11
|
*/
|
|
10
12
|
export class RovingTabindexController {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** closest ancestor containing items */
|
|
14
|
-
#itemsContainer;
|
|
15
|
-
/** array of all focusable elements */
|
|
16
|
-
#items = [];
|
|
17
|
-
/**
|
|
18
|
-
* finds focusable items from a group of items
|
|
19
|
-
*/
|
|
20
|
-
get #focusableItems() {
|
|
21
|
-
return this.#items.filter(isFocusableElement);
|
|
13
|
+
static of(host, options) {
|
|
14
|
+
return new _a(host, options);
|
|
22
15
|
}
|
|
23
16
|
/**
|
|
24
|
-
*
|
|
17
|
+
* active item of array of items
|
|
25
18
|
*/
|
|
26
|
-
get
|
|
27
|
-
return
|
|
19
|
+
get activeItem() {
|
|
20
|
+
return __classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f");
|
|
28
21
|
}
|
|
29
22
|
/**
|
|
30
|
-
*
|
|
23
|
+
* all items from array
|
|
31
24
|
*/
|
|
32
|
-
get
|
|
33
|
-
return this
|
|
25
|
+
get items() {
|
|
26
|
+
return __classPrivateFieldGet(this, _RovingTabindexController_items, "f");
|
|
34
27
|
}
|
|
35
28
|
/**
|
|
36
|
-
*
|
|
29
|
+
* all focusable items from array
|
|
37
30
|
*/
|
|
38
|
-
get
|
|
39
|
-
return this
|
|
31
|
+
get focusableItems() {
|
|
32
|
+
return __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get);
|
|
40
33
|
}
|
|
41
34
|
/**
|
|
42
35
|
* first item in array of focusable items
|
|
43
36
|
*/
|
|
44
37
|
get firstItem() {
|
|
45
|
-
return this
|
|
38
|
+
return __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)[0];
|
|
46
39
|
}
|
|
47
40
|
/**
|
|
48
41
|
* last item in array of focusable items
|
|
49
42
|
*/
|
|
50
43
|
get lastItem() {
|
|
51
|
-
return this
|
|
44
|
+
return __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).at(-1);
|
|
52
45
|
}
|
|
53
46
|
/**
|
|
54
47
|
* next item after active item in array of focusable items
|
|
55
48
|
*/
|
|
56
49
|
get nextItem() {
|
|
57
|
-
return (this
|
|
58
|
-
: this
|
|
50
|
+
return (__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) >= __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).length - 1 ? this.firstItem
|
|
51
|
+
: __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)[__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) + 1]);
|
|
59
52
|
}
|
|
60
53
|
/**
|
|
61
54
|
* previous item after active item in array of focusable items
|
|
62
55
|
*/
|
|
63
56
|
get prevItem() {
|
|
64
|
-
return (this
|
|
57
|
+
return (__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) > 0 ? __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)[__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_activeIndex_get) - 1]
|
|
65
58
|
: this.lastItem);
|
|
66
59
|
}
|
|
67
|
-
constructor(host) {
|
|
60
|
+
constructor(host, options) {
|
|
61
|
+
_RovingTabindexController_instances.add(this);
|
|
68
62
|
this.host = host;
|
|
63
|
+
/** active focusable element */
|
|
64
|
+
_RovingTabindexController_activeItem.set(this, void 0);
|
|
65
|
+
/** closest ancestor containing items */
|
|
66
|
+
_RovingTabindexController_itemsContainer.set(this, void 0);
|
|
67
|
+
/** array of all focusable elements */
|
|
68
|
+
_RovingTabindexController_items.set(this, []);
|
|
69
|
+
/** flags whether the host's element has gained focus at least once */
|
|
70
|
+
_RovingTabindexController_gainedInitialFocus.set(this, false);
|
|
71
|
+
_RovingTabindexController_options.set(this, void 0);
|
|
72
|
+
/**
|
|
73
|
+
* handles keyboard navigation
|
|
74
|
+
*/
|
|
75
|
+
_RovingTabindexController_onKeydown.set(this, (event) => {
|
|
76
|
+
if (!(event instanceof KeyboardEvent) ||
|
|
77
|
+
event.ctrlKey ||
|
|
78
|
+
event.altKey ||
|
|
79
|
+
event.metaKey ||
|
|
80
|
+
!__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).length ||
|
|
81
|
+
!event.composedPath().some(x => __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).includes(x))) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const orientation = __classPrivateFieldGet(this, _RovingTabindexController_options, "f").getHTMLElement()?.getAttribute('aria-orientation');
|
|
85
|
+
const item = this.activeItem;
|
|
86
|
+
let shouldPreventDefault = false;
|
|
87
|
+
const horizontalOnly = !item ? false
|
|
88
|
+
: item.tagName === 'SELECT' ||
|
|
89
|
+
item.getAttribute('role') === 'spinbutton' || orientation === 'horizontal';
|
|
90
|
+
const verticalOnly = orientation === 'vertical';
|
|
91
|
+
switch (event.key) {
|
|
92
|
+
case 'ArrowLeft':
|
|
93
|
+
if (verticalOnly) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.setActiveItem(this.prevItem);
|
|
97
|
+
shouldPreventDefault = true;
|
|
98
|
+
break;
|
|
99
|
+
case 'ArrowRight':
|
|
100
|
+
if (verticalOnly) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.setActiveItem(this.nextItem);
|
|
104
|
+
shouldPreventDefault = true;
|
|
105
|
+
break;
|
|
106
|
+
case 'ArrowUp':
|
|
107
|
+
if (horizontalOnly) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.setActiveItem(this.prevItem);
|
|
111
|
+
shouldPreventDefault = true;
|
|
112
|
+
break;
|
|
113
|
+
case 'ArrowDown':
|
|
114
|
+
if (horizontalOnly) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.setActiveItem(this.nextItem);
|
|
118
|
+
shouldPreventDefault = true;
|
|
119
|
+
break;
|
|
120
|
+
case 'Home':
|
|
121
|
+
this.setActiveItem(this.firstItem);
|
|
122
|
+
shouldPreventDefault = true;
|
|
123
|
+
break;
|
|
124
|
+
case 'End':
|
|
125
|
+
this.setActiveItem(this.lastItem);
|
|
126
|
+
shouldPreventDefault = true;
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
if (shouldPreventDefault) {
|
|
132
|
+
event.stopPropagation();
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
__classPrivateFieldSet(this, _RovingTabindexController_options, {
|
|
137
|
+
getHTMLElement: options?.getHTMLElement ??
|
|
138
|
+
options?.getElement ??
|
|
139
|
+
(() => host instanceof HTMLElement ? host : null),
|
|
140
|
+
getItems: options?.getItems,
|
|
141
|
+
getItemContainer: options?.getItemContainer,
|
|
142
|
+
}, "f");
|
|
143
|
+
const instance = _a.hosts.get(host);
|
|
144
|
+
if (instance) {
|
|
145
|
+
return instance;
|
|
146
|
+
}
|
|
147
|
+
_a.hosts.set(host, this);
|
|
69
148
|
this.host.addController(this);
|
|
149
|
+
this.updateItems();
|
|
70
150
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
!this.#focusableItems.length ||
|
|
79
|
-
!event.composedPath().some(x => this.#focusableItems.includes(x))) {
|
|
80
|
-
return;
|
|
151
|
+
hostUpdated() {
|
|
152
|
+
const oldContainer = __classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f");
|
|
153
|
+
const newContainer = __classPrivateFieldGet(this, _RovingTabindexController_options, "f").getHTMLElement();
|
|
154
|
+
if (oldContainer !== newContainer) {
|
|
155
|
+
oldContainer?.removeEventListener('keydown', __classPrivateFieldGet(this, _RovingTabindexController_onKeydown, "f"));
|
|
156
|
+
_a.elements.delete(oldContainer);
|
|
157
|
+
this.updateItems();
|
|
81
158
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const horizontalOnly = !item ? false
|
|
85
|
-
: item.tagName === 'SELECT' ||
|
|
86
|
-
item.getAttribute('role') === 'spinbutton';
|
|
87
|
-
switch (event.key) {
|
|
88
|
-
case 'ArrowLeft':
|
|
89
|
-
this.focusOnItem(this.prevItem);
|
|
90
|
-
shouldPreventDefault = true;
|
|
91
|
-
break;
|
|
92
|
-
case 'ArrowRight':
|
|
93
|
-
this.focusOnItem(this.nextItem);
|
|
94
|
-
shouldPreventDefault = true;
|
|
95
|
-
break;
|
|
96
|
-
case 'ArrowUp':
|
|
97
|
-
if (horizontalOnly) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
this.focusOnItem(this.prevItem);
|
|
101
|
-
shouldPreventDefault = true;
|
|
102
|
-
break;
|
|
103
|
-
case 'ArrowDown':
|
|
104
|
-
if (horizontalOnly) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
this.focusOnItem(this.nextItem);
|
|
108
|
-
shouldPreventDefault = true;
|
|
109
|
-
break;
|
|
110
|
-
case 'Home':
|
|
111
|
-
this.focusOnItem(this.firstItem);
|
|
112
|
-
shouldPreventDefault = true;
|
|
113
|
-
break;
|
|
114
|
-
case 'PageUp':
|
|
115
|
-
if (horizontalOnly) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
this.focusOnItem(this.firstItem);
|
|
119
|
-
shouldPreventDefault = true;
|
|
120
|
-
break;
|
|
121
|
-
case 'End':
|
|
122
|
-
this.focusOnItem(this.lastItem);
|
|
123
|
-
shouldPreventDefault = true;
|
|
124
|
-
break;
|
|
125
|
-
case 'PageDown':
|
|
126
|
-
if (horizontalOnly) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
this.focusOnItem(this.lastItem);
|
|
130
|
-
shouldPreventDefault = true;
|
|
131
|
-
break;
|
|
132
|
-
default:
|
|
133
|
-
break;
|
|
159
|
+
if (newContainer) {
|
|
160
|
+
__classPrivateFieldGet(this, _RovingTabindexController_instances, "m", _RovingTabindexController_initContainer).call(this, newContainer);
|
|
134
161
|
}
|
|
135
|
-
|
|
136
|
-
event.stopPropagation();
|
|
137
|
-
event.preventDefault();
|
|
138
|
-
}
|
|
139
|
-
};
|
|
162
|
+
}
|
|
140
163
|
/**
|
|
141
|
-
*
|
|
164
|
+
* removes event listeners from items container
|
|
142
165
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
item.tabIndex = 0;
|
|
149
|
-
this.#activeItem = item;
|
|
150
|
-
}
|
|
166
|
+
hostDisconnected() {
|
|
167
|
+
__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f")?.removeEventListener('keydown', __classPrivateFieldGet(this, _RovingTabindexController_onKeydown, "f"));
|
|
168
|
+
__classPrivateFieldSet(this, _RovingTabindexController_itemsContainer, undefined, "f");
|
|
169
|
+
__classPrivateFieldSet(this, _RovingTabindexController_gainedInitialFocus, false, "f");
|
|
151
170
|
}
|
|
152
171
|
/**
|
|
153
|
-
*
|
|
172
|
+
* Sets the active item and focuses it
|
|
154
173
|
*/
|
|
155
|
-
|
|
156
|
-
this
|
|
157
|
-
this
|
|
174
|
+
setActiveItem(item) {
|
|
175
|
+
__classPrivateFieldSet(this, _RovingTabindexController_activeItem, item, "f");
|
|
176
|
+
for (const item of __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get)) {
|
|
177
|
+
item.tabIndex = __classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f") === item ? 0 : -1;
|
|
178
|
+
}
|
|
158
179
|
this.host.requestUpdate();
|
|
180
|
+
if (__classPrivateFieldGet(this, _RovingTabindexController_gainedInitialFocus, "f")) {
|
|
181
|
+
__classPrivateFieldGet(this, _RovingTabindexController_activeItem, "f")?.focus();
|
|
182
|
+
}
|
|
159
183
|
}
|
|
160
184
|
/**
|
|
161
185
|
* Focuses next focusable item
|
|
162
186
|
*/
|
|
163
|
-
updateItems(items) {
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
187
|
+
updateItems(items = __classPrivateFieldGet(this, _RovingTabindexController_options, "f").getItems?.() ?? []) {
|
|
188
|
+
__classPrivateFieldSet(this, _RovingTabindexController_items, items, "f");
|
|
189
|
+
const sequence = [...__classPrivateFieldGet(this, _RovingTabindexController_items, "f").slice(__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_itemIndex_get) - 1), ...__classPrivateFieldGet(this, _RovingTabindexController_items, "f").slice(0, __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_itemIndex_get) - 1)];
|
|
190
|
+
const first = sequence.find(item => __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).includes(item));
|
|
191
|
+
const [focusableItem] = __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get);
|
|
192
|
+
const activeItem = focusableItem ?? first ?? this.firstItem;
|
|
193
|
+
this.setActiveItem(activeItem);
|
|
194
|
+
}
|
|
195
|
+
/** @deprecated use setActiveItem */
|
|
196
|
+
focusOnItem(item) {
|
|
197
|
+
this.setActiveItem(item);
|
|
167
198
|
}
|
|
168
199
|
/**
|
|
169
200
|
* from array of HTML items, and sets active items
|
|
201
|
+
* @deprecated: use getItems and getItemContainer option functions
|
|
170
202
|
*/
|
|
171
|
-
initItems(items, itemsContainer
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.#activeItem = focusableItem;
|
|
176
|
-
for (const item of focusableItems) {
|
|
177
|
-
item.tabIndex = this.#activeItem === item ? 0 : -1;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* removes listener on previous contained and applies it to new container
|
|
181
|
-
*/
|
|
182
|
-
if (!this.#itemsContainer || itemsContainer !== this.#itemsContainer) {
|
|
183
|
-
this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);
|
|
184
|
-
this.#itemsContainer = itemsContainer;
|
|
185
|
-
this.hostConnected();
|
|
203
|
+
initItems(items, itemsContainer) {
|
|
204
|
+
const element = itemsContainer ?? __classPrivateFieldGet(this, _RovingTabindexController_options, "f")?.getItemContainer?.() ?? __classPrivateFieldGet(this, _RovingTabindexController_options, "f").getHTMLElement();
|
|
205
|
+
if (element) {
|
|
206
|
+
__classPrivateFieldGet(this, _RovingTabindexController_instances, "m", _RovingTabindexController_initContainer).call(this, element);
|
|
186
207
|
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* adds event listeners to items container
|
|
190
|
-
*/
|
|
191
|
-
hostConnected() {
|
|
192
|
-
this.#itemsContainer?.addEventListener('keydown', this.#onKeydown);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* removes event listeners from items container
|
|
196
|
-
*/
|
|
197
|
-
hostDisconnected() {
|
|
198
|
-
this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);
|
|
208
|
+
this.updateItems(items);
|
|
199
209
|
}
|
|
200
210
|
}
|
|
211
|
+
_a = RovingTabindexController, _RovingTabindexController_activeItem = new WeakMap(), _RovingTabindexController_itemsContainer = new WeakMap(), _RovingTabindexController_items = new WeakMap(), _RovingTabindexController_gainedInitialFocus = new WeakMap(), _RovingTabindexController_options = new WeakMap(), _RovingTabindexController_onKeydown = new WeakMap(), _RovingTabindexController_instances = new WeakSet(), _RovingTabindexController_focusableItems_get = function _RovingTabindexController_focusableItems_get() {
|
|
212
|
+
return __classPrivateFieldGet(this, _RovingTabindexController_items, "f").filter(isFocusableElement);
|
|
213
|
+
}, _RovingTabindexController_activeIndex_get = function _RovingTabindexController_activeIndex_get() {
|
|
214
|
+
return !!__classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get) && !!this.activeItem ? __classPrivateFieldGet(this, _RovingTabindexController_instances, "a", _RovingTabindexController_focusableItems_get).indexOf(this.activeItem) : -1;
|
|
215
|
+
}, _RovingTabindexController_itemIndex_get = function _RovingTabindexController_itemIndex_get() {
|
|
216
|
+
return this.activeItem ? __classPrivateFieldGet(this, _RovingTabindexController_items, "f").indexOf(this.activeItem) : -1;
|
|
217
|
+
}, _RovingTabindexController_initContainer = function _RovingTabindexController_initContainer(container) {
|
|
218
|
+
_a.elements.set(container, this);
|
|
219
|
+
__classPrivateFieldSet(this, _RovingTabindexController_itemsContainer, container, "f");
|
|
220
|
+
__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f").addEventListener('keydown', __classPrivateFieldGet(this, _RovingTabindexController_onKeydown, "f"));
|
|
221
|
+
__classPrivateFieldGet(this, _RovingTabindexController_itemsContainer, "f").addEventListener('focusin', () => {
|
|
222
|
+
__classPrivateFieldSet(this, _RovingTabindexController_gainedInitialFocus, true, "f");
|
|
223
|
+
}, { once: true });
|
|
224
|
+
};
|
|
225
|
+
RovingTabindexController.hosts = new WeakMap();
|
|
226
|
+
/** @internal */
|
|
227
|
+
RovingTabindexController.elements = new WeakMap();
|
|
201
228
|
//# sourceMappingURL=roving-tabindex-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roving-tabindex-controller.js","sourceRoot":"","sources":["roving-tabindex-controller.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,CAAC,EAAW,EAAqB,EAAE,CAC5D,CAAC,CAAC,EAAE;IACJ,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;IAC5B,CAAC,EAAE,CAAC,UAAU;IACd,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AAE7B;;;;GAIG;AACH,MAAM,OAAO,wBAAwB;IAGnC,+BAA+B;IAC/B,WAAW,CAAY;IAEvB,wCAAwC;IACxC,eAAe,CAAe;IAE9B,sCAAsC;IACtC,MAAM,GAAe,EAAE,CAAC;IAExB;;OAEG;IACH,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAChD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ED;;OAEG;IACH,aAAa;QACX,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,IAAI,CAAC,eAAe,EAAE,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACxE,CAAC;CACF","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nconst isFocusableElement = (el: Element): el is HTMLElement =>\n !!el &&\n !el.hasAttribute('disabled') &&\n !el.ariaHidden &&\n !el.hasAttribute('hidden');\n\n/**\n * Implements roving tabindex, as described in WAI-ARIA practices, [Managing Focus Within\n * Components Using a Roving\n * tabindex](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex)\n */\nexport class RovingTabindexController<\n ItemType extends HTMLElement = HTMLElement,\n> implements ReactiveController {\n /** active focusable element */\n #activeItem?: ItemType;\n\n /** closest ancestor containing items */\n #itemsContainer?: HTMLElement;\n\n /** array of all focusable elements */\n #items: ItemType[] = [];\n\n /**\n * finds focusable items from a group of items\n */\n get #focusableItems(): ItemType[] {\n return this.#items.filter(isFocusableElement);\n }\n\n /**\n * index of active item in array of focusable items\n */\n get #activeIndex(): number {\n return !!this.#focusableItems && !!this.activeItem ? this.#focusableItems.indexOf(this.activeItem) : -1;\n }\n\n /**\n * index of active item in array of items\n */\n get #itemIndex(): number {\n return this.activeItem ? this.#items.indexOf(this.activeItem) : -1;\n }\n\n /**\n * active item of array of items\n */\n get activeItem(): ItemType | undefined {\n return this.#activeItem;\n }\n\n /**\n * first item in array of focusable items\n */\n get firstItem(): ItemType | undefined {\n return this.#focusableItems[0];\n }\n\n /**\n * last item in array of focusable items\n */\n get lastItem(): ItemType | undefined {\n return this.#focusableItems.at(-1);\n }\n\n /**\n * next item after active item in array of focusable items\n */\n get nextItem(): ItemType | undefined {\n return (\n this.#activeIndex >= this.#focusableItems.length - 1 ? this.firstItem\n : this.#focusableItems[this.#activeIndex + 1]\n );\n }\n\n /**\n * previous item after active item in array of focusable items\n */\n get prevItem(): ItemType | undefined {\n return (\n this.#activeIndex > 0 ? this.#focusableItems[this.#activeIndex - 1]\n : this.lastItem\n );\n }\n\n constructor(public host: ReactiveControllerHost & HTMLElement) {\n this.host.addController(this);\n }\n\n /**\n * handles keyboard navigation\n */\n #onKeydown = (event: KeyboardEvent) => {\n if (event.ctrlKey ||\n event.altKey ||\n event.metaKey ||\n !this.#focusableItems.length ||\n !event.composedPath().some(x =>\n this.#focusableItems.includes(x as ItemType))) {\n return;\n }\n const item = this.activeItem;\n let shouldPreventDefault = false;\n const horizontalOnly =\n !item ? false\n : item.tagName === 'SELECT' ||\n item.getAttribute('role') === 'spinbutton';\n\n\n switch (event.key) {\n case 'ArrowLeft':\n this.focusOnItem(this.prevItem);\n shouldPreventDefault = true;\n break;\n case 'ArrowRight':\n this.focusOnItem(this.nextItem);\n shouldPreventDefault = true;\n break;\n case 'ArrowUp':\n if (horizontalOnly) {\n return;\n }\n this.focusOnItem(this.prevItem);\n shouldPreventDefault = true;\n break;\n case 'ArrowDown':\n if (horizontalOnly) {\n return;\n }\n this.focusOnItem(this.nextItem);\n shouldPreventDefault = true;\n break;\n case 'Home':\n this.focusOnItem(this.firstItem);\n shouldPreventDefault = true;\n break;\n case 'PageUp':\n if (horizontalOnly) {\n return;\n }\n this.focusOnItem(this.firstItem);\n shouldPreventDefault = true;\n break;\n case 'End':\n this.focusOnItem(this.lastItem);\n shouldPreventDefault = true;\n break;\n case 'PageDown':\n if (horizontalOnly) {\n return;\n }\n this.focusOnItem(this.lastItem);\n shouldPreventDefault = true;\n break;\n default:\n break;\n }\n\n if (shouldPreventDefault) {\n event.stopPropagation();\n event.preventDefault();\n }\n };\n\n /**\n * sets tabindex of item based on whether or not it is active\n */\n updateActiveItem(item?: ItemType): void {\n if (item) {\n if (!!this.#activeItem && item !== this.#activeItem) {\n this.#activeItem.tabIndex = -1;\n }\n item.tabIndex = 0;\n this.#activeItem = item;\n }\n }\n\n /**\n * focuses on an item and sets it as active\n */\n focusOnItem(item?: ItemType): void {\n this.updateActiveItem(item || this.firstItem);\n this.#activeItem?.focus();\n this.host.requestUpdate();\n }\n\n /**\n * Focuses next focusable item\n */\n updateItems(items: ItemType[]) {\n const sequence = [...items.slice(this.#itemIndex), ...items.slice(0, this.#itemIndex)];\n const first = sequence.find(item => this.#focusableItems.includes(item));\n this.focusOnItem(first || this.firstItem);\n }\n\n /**\n * from array of HTML items, and sets active items\n */\n initItems(items: ItemType[], itemsContainer: HTMLElement = this.host) {\n this.#items = items ?? [];\n const focusableItems = this.#focusableItems;\n const [focusableItem] = focusableItems;\n this.#activeItem = focusableItem;\n for (const item of focusableItems) {\n item.tabIndex = this.#activeItem === item ? 0 : -1;\n }\n /**\n * removes listener on previous contained and applies it to new container\n */\n if (!this.#itemsContainer || itemsContainer !== this.#itemsContainer) {\n this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);\n this.#itemsContainer = itemsContainer;\n this.hostConnected();\n }\n }\n\n /**\n * adds event listeners to items container\n */\n hostConnected() {\n this.#itemsContainer?.addEventListener('keydown', this.#onKeydown);\n }\n\n /**\n * removes event listeners from items container\n */\n hostDisconnected() {\n this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"roving-tabindex-controller.js","sourceRoot":"","sources":["roving-tabindex-controller.ts"],"names":[],"mappings":";;AAGA,MAAM,kBAAkB,GAAG,CAAC,EAAW,EAAqB,EAAE,CAC5D,CAAC,CAAC,EAAE;IACJ,CAAC,EAAE,CAAC,UAAU;IACd,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AAU7B;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAKnC,MAAM,CAAC,EAAE,CACP,IAA4B,EAC5B,OAAuE;QAEvE,OAAO,IAAI,EAAwB,CAAC,IAAI,EAAE,OAAO,CA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O,uBAAA,IAAI,uCAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAChD,CAAC;IAMC,OAAO,CAAC,CAAC,uBAAA,IAAI,yFAAgB,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAA,IAAI,yFAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC;IAMC,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAA,IAAI,uCAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC,6FAqGc,SAAkB;IAC/B,EAAwB,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACvD,uBAAA,IAAI,4CAAmB,SAAS,MAAA,CAAC;IACjC,uBAAA,IAAI,gDAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,uBAAA,IAAI,2CAAW,CAAC,CAAC;IAClE,uBAAA,IAAI,gDAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE;QACpD,uBAAA,IAAI,gDAAuB,IAAI,MAAA,CAAC;IAClC,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACrB,CAAC;AAvJc,8BAAK,GAAG,IAAI,OAAO,EAAoD,AAAlE,CAAmE;AASvF,gBAAgB;AACT,iCAAQ,GAAG,IAAI,OAAO,EAAqC,AAAnD,CAAoD","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport type { RequireProps } from '../core.js';\n\nconst isFocusableElement = (el: Element): el is HTMLElement =>\n !!el &&\n !el.ariaHidden &&\n !el.hasAttribute('hidden');\n\nexport interface RovingTabindexControllerOptions<Item extends HTMLElement> {\n /** @deprecated use getHTMLElement */\n getElement?: () => Element | null;\n getHTMLElement?: () => HTMLElement | null;\n getItems?: () => Item[];\n getItemContainer?: () => HTMLElement;\n}\n\n/**\n * Implements roving tabindex, as described in WAI-ARIA practices, [Managing Focus Within\n * Components Using a Roving tabindex][rti]\n *\n * [rti]: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex\n */\nexport class RovingTabindexController<\n Item extends HTMLElement = HTMLElement,\n> implements ReactiveController {\n private static hosts = new WeakMap<ReactiveControllerHost, RovingTabindexController>();\n\n static of<Item extends HTMLElement>(\n host: ReactiveControllerHost,\n options: RovingTabindexControllerOptions<Item> & { getItems(): Item[] },\n ) {\n return new RovingTabindexController(host, options);\n }\n\n /** @internal */\n static elements = new WeakMap<Element, RovingTabindexController>();\n\n /** active focusable element */\n #activeItem?: Item;\n\n /** closest ancestor containing items */\n #itemsContainer?: Element;\n\n /** array of all focusable elements */\n #items: Item[] = [];\n\n /** flags whether the host's element has gained focus at least once */\n #gainedInitialFocus = false;\n\n /**\n * finds focusable items from a group of items\n */\n get #focusableItems(): Item[] {\n return this.#items.filter(isFocusableElement);\n }\n\n /**\n * index of active item in array of focusable items\n */\n get #activeIndex(): number {\n return !!this.#focusableItems && !!this.activeItem ? this.#focusableItems.indexOf(this.activeItem) : -1;\n }\n\n /**\n * index of active item in array of items\n */\n get #itemIndex(): number {\n return this.activeItem ? this.#items.indexOf(this.activeItem) : -1;\n }\n\n /**\n * active item of array of items\n */\n get activeItem(): Item | undefined {\n return this.#activeItem;\n }\n\n /**\n * all items from array\n */\n get items() {\n return this.#items;\n }\n\n /**\n * all focusable items from array\n */\n get focusableItems() {\n return this.#focusableItems;\n }\n\n /**\n * first item in array of focusable items\n */\n get firstItem(): Item | undefined {\n return this.#focusableItems[0];\n }\n\n /**\n * last item in array of focusable items\n */\n get lastItem(): Item | undefined {\n return this.#focusableItems.at(-1);\n }\n\n /**\n * next item after active item in array of focusable items\n */\n get nextItem(): Item | undefined {\n return (\n this.#activeIndex >= this.#focusableItems.length - 1 ? this.firstItem\n : this.#focusableItems[this.#activeIndex + 1]\n );\n }\n\n /**\n * previous item after active item in array of focusable items\n */\n get prevItem(): Item | undefined {\n return (\n this.#activeIndex > 0 ? this.#focusableItems[this.#activeIndex - 1]\n : this.lastItem\n );\n }\n\n #options: RequireProps<RovingTabindexControllerOptions<Item>, 'getHTMLElement'>;\n\n constructor(\n public host: ReactiveControllerHost,\n options?: RovingTabindexControllerOptions<Item>,\n ) {\n this.#options = {\n getHTMLElement: options?.getHTMLElement ??\n (options?.getElement as (() => HTMLElement | null)) ??\n (() => host instanceof HTMLElement ? host : null),\n getItems: options?.getItems,\n getItemContainer: options?.getItemContainer,\n };\n const instance = RovingTabindexController.hosts.get(host);\n if (instance) {\n return instance as RovingTabindexController<Item>;\n }\n RovingTabindexController.hosts.set(host, this);\n this.host.addController(this);\n this.updateItems();\n }\n\n hostUpdated() {\n const oldContainer = this.#itemsContainer;\n const newContainer = this.#options.getHTMLElement();\n if (oldContainer !== newContainer) {\n oldContainer?.removeEventListener('keydown', this.#onKeydown);\n RovingTabindexController.elements.delete(oldContainer!);\n this.updateItems();\n }\n if (newContainer) {\n this.#initContainer(newContainer);\n }\n }\n\n /**\n * removes event listeners from items container\n */\n hostDisconnected() {\n this.#itemsContainer?.removeEventListener('keydown', this.#onKeydown);\n this.#itemsContainer = undefined;\n this.#gainedInitialFocus = false;\n }\n\n #initContainer(container: Element) {\n RovingTabindexController.elements.set(container, this);\n this.#itemsContainer = container;\n this.#itemsContainer.addEventListener('keydown', this.#onKeydown);\n this.#itemsContainer.addEventListener('focusin', () => {\n this.#gainedInitialFocus = true;\n }, { once: true });\n }\n\n /**\n * handles keyboard navigation\n */\n #onKeydown = (event: Event) => {\n if (!(event instanceof KeyboardEvent) ||\n event.ctrlKey ||\n event.altKey ||\n event.metaKey ||\n !this.#focusableItems.length ||\n !event.composedPath().some(x =>\n this.#focusableItems.includes(x as Item))) {\n return;\n }\n\n const orientation = this.#options.getHTMLElement()?.getAttribute('aria-orientation');\n\n const item = this.activeItem;\n let shouldPreventDefault = false;\n const horizontalOnly =\n !item ? false\n : item.tagName === 'SELECT' ||\n item.getAttribute('role') === 'spinbutton' || orientation === 'horizontal';\n const verticalOnly = orientation === 'vertical';\n switch (event.key) {\n case 'ArrowLeft':\n if (verticalOnly) {\n return;\n }\n this.setActiveItem(this.prevItem);\n shouldPreventDefault = true;\n break;\n case 'ArrowRight':\n if (verticalOnly) {\n return;\n }\n\n this.setActiveItem(this.nextItem);\n shouldPreventDefault = true;\n break;\n case 'ArrowUp':\n if (horizontalOnly) {\n return;\n }\n this.setActiveItem(this.prevItem);\n shouldPreventDefault = true;\n break;\n case 'ArrowDown':\n if (horizontalOnly) {\n return;\n }\n this.setActiveItem(this.nextItem);\n shouldPreventDefault = true;\n break;\n case 'Home':\n this.setActiveItem(this.firstItem);\n shouldPreventDefault = true;\n break;\n case 'End':\n this.setActiveItem(this.lastItem);\n shouldPreventDefault = true;\n break;\n default:\n break;\n }\n\n if (shouldPreventDefault) {\n event.stopPropagation();\n event.preventDefault();\n }\n };\n\n /**\n * Sets the active item and focuses it\n */\n setActiveItem(item?: Item): void {\n this.#activeItem = item;\n for (const item of this.#focusableItems) {\n item.tabIndex = this.#activeItem === item ? 0 : -1;\n }\n this.host.requestUpdate();\n if (this.#gainedInitialFocus) {\n this.#activeItem?.focus();\n }\n }\n\n /**\n * Focuses next focusable item\n */\n updateItems(items: Item[] = this.#options.getItems?.() ?? []) {\n this.#items = items;\n const sequence = [...this.#items.slice(this.#itemIndex - 1), ...this.#items.slice(0, this.#itemIndex - 1)];\n const first = sequence.find(item => this.#focusableItems.includes(item));\n const [focusableItem] = this.#focusableItems;\n const activeItem = focusableItem ?? first ?? this.firstItem;\n this.setActiveItem(activeItem);\n }\n\n /** @deprecated use setActiveItem */\n focusOnItem(item?: Item): void {\n this.setActiveItem(item);\n }\n\n /**\n * from array of HTML items, and sets active items\n * @deprecated: use getItems and getItemContainer option functions\n */\n initItems(items: Item[], itemsContainer?: Element) {\n const element = itemsContainer ?? this.#options?.getItemContainer?.() ?? this.#options.getHTMLElement();\n if (element) {\n this.#initContainer(element);\n }\n this.updateItems(items);\n }\n}\n"]}
|
|
@@ -1,122 +1,120 @@
|
|
|
1
|
+
var _ScrollSpyController_instances, _ScrollSpyController_tagNames, _ScrollSpyController_activeAttribute, _ScrollSpyController_io, _ScrollSpyController_passedLinks, _ScrollSpyController_force, _ScrollSpyController_intersected, _ScrollSpyController_root, _ScrollSpyController_rootMargin, _ScrollSpyController_threshold, _ScrollSpyController_rootNode, _ScrollSpyController_getHash, _ScrollSpyController_linkChildren_get, _ScrollSpyController_initIo, _ScrollSpyController_markPassed, _ScrollSpyController_setActive, _ScrollSpyController_nextIntersection, _ScrollSpyController_onIo;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
1
3
|
export class ScrollSpyController {
|
|
2
|
-
#tagNames;
|
|
3
|
-
#activeAttribute;
|
|
4
|
-
#io;
|
|
5
|
-
/** Which link's targets have already scrolled past? */
|
|
6
|
-
#passedLinks = new Set();
|
|
7
|
-
/** Ignore intersections? */
|
|
8
|
-
#force = false;
|
|
9
|
-
/** Has the intersection observer found an element? */
|
|
10
|
-
#intersected = false;
|
|
11
|
-
#root;
|
|
12
|
-
#rootMargin;
|
|
13
|
-
#threshold;
|
|
14
|
-
#rootNode;
|
|
15
|
-
#getHash;
|
|
16
|
-
get #linkChildren() {
|
|
17
|
-
return Array.from(this.host.querySelectorAll(this.#tagNames.join(',')))
|
|
18
|
-
.filter(this.#getHash);
|
|
19
|
-
}
|
|
20
4
|
get root() {
|
|
21
|
-
return this
|
|
5
|
+
return __classPrivateFieldGet(this, _ScrollSpyController_root, "f");
|
|
22
6
|
}
|
|
23
7
|
set root(v) {
|
|
24
|
-
this
|
|
25
|
-
this
|
|
26
|
-
this
|
|
8
|
+
__classPrivateFieldSet(this, _ScrollSpyController_root, v, "f");
|
|
9
|
+
__classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
|
|
10
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
|
|
27
11
|
}
|
|
28
12
|
get rootMargin() {
|
|
29
|
-
return this
|
|
13
|
+
return __classPrivateFieldGet(this, _ScrollSpyController_rootMargin, "f");
|
|
30
14
|
}
|
|
31
15
|
set rootMargin(v) {
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
this
|
|
16
|
+
__classPrivateFieldSet(this, _ScrollSpyController_rootMargin, v, "f");
|
|
17
|
+
__classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
|
|
18
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
|
|
35
19
|
}
|
|
36
20
|
get threshold() {
|
|
37
|
-
return this
|
|
21
|
+
return __classPrivateFieldGet(this, _ScrollSpyController_threshold, "f");
|
|
38
22
|
}
|
|
39
23
|
set threshold(v) {
|
|
40
|
-
this
|
|
41
|
-
this
|
|
42
|
-
this
|
|
24
|
+
__classPrivateFieldSet(this, _ScrollSpyController_threshold, v, "f");
|
|
25
|
+
__classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
|
|
26
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
|
|
43
27
|
}
|
|
44
28
|
constructor(host, options) {
|
|
29
|
+
_ScrollSpyController_instances.add(this);
|
|
45
30
|
this.host = host;
|
|
31
|
+
_ScrollSpyController_tagNames.set(this, void 0);
|
|
32
|
+
_ScrollSpyController_activeAttribute.set(this, void 0);
|
|
33
|
+
_ScrollSpyController_io.set(this, void 0);
|
|
34
|
+
/** Which link's targets have already scrolled past? */
|
|
35
|
+
_ScrollSpyController_passedLinks.set(this, new Set());
|
|
36
|
+
/** Ignore intersections? */
|
|
37
|
+
_ScrollSpyController_force.set(this, false);
|
|
38
|
+
/** Has the intersection observer found an element? */
|
|
39
|
+
_ScrollSpyController_intersected.set(this, false);
|
|
40
|
+
_ScrollSpyController_root.set(this, void 0);
|
|
41
|
+
_ScrollSpyController_rootMargin.set(this, void 0);
|
|
42
|
+
_ScrollSpyController_threshold.set(this, void 0);
|
|
43
|
+
_ScrollSpyController_rootNode.set(this, void 0);
|
|
44
|
+
_ScrollSpyController_getHash.set(this, void 0);
|
|
46
45
|
host.addController(this);
|
|
47
|
-
this
|
|
48
|
-
this
|
|
49
|
-
this
|
|
50
|
-
this
|
|
51
|
-
this
|
|
52
|
-
this
|
|
53
|
-
this
|
|
46
|
+
__classPrivateFieldSet(this, _ScrollSpyController_tagNames, options.tagNames, "f");
|
|
47
|
+
__classPrivateFieldSet(this, _ScrollSpyController_root, options.root, "f");
|
|
48
|
+
__classPrivateFieldSet(this, _ScrollSpyController_rootMargin, options.rootMargin, "f");
|
|
49
|
+
__classPrivateFieldSet(this, _ScrollSpyController_activeAttribute, options.activeAttribute ?? 'active', "f");
|
|
50
|
+
__classPrivateFieldSet(this, _ScrollSpyController_threshold, options.threshold ?? 0.85, "f");
|
|
51
|
+
__classPrivateFieldSet(this, _ScrollSpyController_rootNode, options.rootNode ?? host.getRootNode(), "f");
|
|
52
|
+
__classPrivateFieldSet(this, _ScrollSpyController_getHash, options?.getHash ?? ((el) => el.getAttribute('href')), "f");
|
|
54
53
|
}
|
|
55
54
|
hostConnected() {
|
|
56
|
-
this
|
|
57
|
-
}
|
|
58
|
-
#initIo() {
|
|
59
|
-
const rootNode = this.#rootNode;
|
|
60
|
-
if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {
|
|
61
|
-
const { rootMargin, threshold, root } = this;
|
|
62
|
-
this.#io = new IntersectionObserver(r => this.#onIo(r), { root, rootMargin, threshold });
|
|
63
|
-
this.#linkChildren
|
|
64
|
-
.map(x => this.#getHash(x))
|
|
65
|
-
.filter((x) => !!x)
|
|
66
|
-
.map(x => rootNode.getElementById(x.replace('#', '')))
|
|
67
|
-
.filter((x) => !!x)
|
|
68
|
-
.forEach(target => this.#io?.observe(target));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
#markPassed(link, force) {
|
|
72
|
-
if (force) {
|
|
73
|
-
this.#passedLinks.add(link);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
this.#passedLinks.delete(link);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
#setActive(link) {
|
|
80
|
-
for (const child of this.#linkChildren) {
|
|
81
|
-
child.toggleAttribute(this.#activeAttribute, child === link);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async #nextIntersection() {
|
|
85
|
-
this.#intersected = false;
|
|
86
|
-
// safeguard the loop
|
|
87
|
-
setTimeout(() => this.#intersected = false, 3000);
|
|
88
|
-
while (!this.#intersected) {
|
|
89
|
-
await new Promise(requestAnimationFrame);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async #onIo(entries) {
|
|
93
|
-
if (!this.#force) {
|
|
94
|
-
for (const { target, boundingClientRect, intersectionRect } of entries) {
|
|
95
|
-
const selector = `:is(${this.#tagNames.join(',')})[href="#${target.id}"]`;
|
|
96
|
-
const link = this.host.querySelector(selector);
|
|
97
|
-
if (link) {
|
|
98
|
-
this.#markPassed(link, boundingClientRect.top < intersectionRect.top);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const link = [...this.#passedLinks];
|
|
102
|
-
const last = link.at(-1);
|
|
103
|
-
this.#setActive(last ?? this.#linkChildren.at(0));
|
|
104
|
-
}
|
|
105
|
-
this.#intersected = true;
|
|
55
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
|
|
106
56
|
}
|
|
107
57
|
/** Explicitly set the active item */
|
|
108
58
|
async setActive(link) {
|
|
109
|
-
this
|
|
110
|
-
this
|
|
59
|
+
__classPrivateFieldSet(this, _ScrollSpyController_force, true, "f");
|
|
60
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_setActive).call(this, link);
|
|
111
61
|
let sawActive = false;
|
|
112
|
-
for (const child of this
|
|
113
|
-
this
|
|
62
|
+
for (const child of __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)) {
|
|
63
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_markPassed).call(this, child, !sawActive);
|
|
114
64
|
if (child === link) {
|
|
115
65
|
sawActive = true;
|
|
116
66
|
}
|
|
117
67
|
}
|
|
118
|
-
await this
|
|
119
|
-
this
|
|
68
|
+
await __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_nextIntersection).call(this);
|
|
69
|
+
__classPrivateFieldSet(this, _ScrollSpyController_force, false, "f");
|
|
120
70
|
}
|
|
121
71
|
}
|
|
72
|
+
_ScrollSpyController_tagNames = new WeakMap(), _ScrollSpyController_activeAttribute = new WeakMap(), _ScrollSpyController_io = new WeakMap(), _ScrollSpyController_passedLinks = new WeakMap(), _ScrollSpyController_force = new WeakMap(), _ScrollSpyController_intersected = new WeakMap(), _ScrollSpyController_root = new WeakMap(), _ScrollSpyController_rootMargin = new WeakMap(), _ScrollSpyController_threshold = new WeakMap(), _ScrollSpyController_rootNode = new WeakMap(), _ScrollSpyController_getHash = new WeakMap(), _ScrollSpyController_instances = new WeakSet(), _ScrollSpyController_linkChildren_get = function _ScrollSpyController_linkChildren_get() {
|
|
73
|
+
return Array.from(this.host.querySelectorAll(__classPrivateFieldGet(this, _ScrollSpyController_tagNames, "f").join(',')))
|
|
74
|
+
.filter(__classPrivateFieldGet(this, _ScrollSpyController_getHash, "f"));
|
|
75
|
+
}, _ScrollSpyController_initIo = function _ScrollSpyController_initIo() {
|
|
76
|
+
const rootNode = __classPrivateFieldGet(this, _ScrollSpyController_rootNode, "f");
|
|
77
|
+
if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {
|
|
78
|
+
const { rootMargin, threshold, root } = this;
|
|
79
|
+
__classPrivateFieldSet(this, _ScrollSpyController_io, new IntersectionObserver(r => __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_onIo).call(this, r), { root, rootMargin, threshold }), "f");
|
|
80
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)
|
|
81
|
+
.map(x => __classPrivateFieldGet(this, _ScrollSpyController_getHash, "f").call(this, x))
|
|
82
|
+
.filter((x) => !!x)
|
|
83
|
+
.map(x => rootNode.getElementById(x.replace('#', '')))
|
|
84
|
+
.filter((x) => !!x)
|
|
85
|
+
.forEach(target => __classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.observe(target));
|
|
86
|
+
}
|
|
87
|
+
}, _ScrollSpyController_markPassed = function _ScrollSpyController_markPassed(link, force) {
|
|
88
|
+
if (force) {
|
|
89
|
+
__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f").add(link);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f").delete(link);
|
|
93
|
+
}
|
|
94
|
+
}, _ScrollSpyController_setActive = function _ScrollSpyController_setActive(link) {
|
|
95
|
+
for (const child of __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)) {
|
|
96
|
+
child.toggleAttribute(__classPrivateFieldGet(this, _ScrollSpyController_activeAttribute, "f"), child === link);
|
|
97
|
+
}
|
|
98
|
+
}, _ScrollSpyController_nextIntersection = async function _ScrollSpyController_nextIntersection() {
|
|
99
|
+
__classPrivateFieldSet(this, _ScrollSpyController_intersected, false, "f");
|
|
100
|
+
// safeguard the loop
|
|
101
|
+
setTimeout(() => __classPrivateFieldSet(this, _ScrollSpyController_intersected, false, "f"), 3000);
|
|
102
|
+
while (!__classPrivateFieldGet(this, _ScrollSpyController_intersected, "f")) {
|
|
103
|
+
await new Promise(requestAnimationFrame);
|
|
104
|
+
}
|
|
105
|
+
}, _ScrollSpyController_onIo = async function _ScrollSpyController_onIo(entries) {
|
|
106
|
+
if (!__classPrivateFieldGet(this, _ScrollSpyController_force, "f")) {
|
|
107
|
+
for (const { target, boundingClientRect, intersectionRect } of entries) {
|
|
108
|
+
const selector = `:is(${__classPrivateFieldGet(this, _ScrollSpyController_tagNames, "f").join(',')})[href="#${target.id}"]`;
|
|
109
|
+
const link = this.host.querySelector(selector);
|
|
110
|
+
if (link) {
|
|
111
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_markPassed).call(this, link, boundingClientRect.top < intersectionRect.top);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const link = [...__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f")];
|
|
115
|
+
const last = link.at(-1);
|
|
116
|
+
__classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_setActive).call(this, last ?? __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get).at(0));
|
|
117
|
+
}
|
|
118
|
+
__classPrivateFieldSet(this, _ScrollSpyController_intersected, true, "f");
|
|
119
|
+
};
|
|
122
120
|
//# sourceMappingURL=scroll-spy-controller.js.map
|