@scouterna/ui-webc 3.2.0 → 4.0.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.
Files changed (147) hide show
  1. package/dist/cjs/{index-BPpKjjvS.js → index-Vd3hlPvW.js} +35 -4
  2. package/dist/cjs/{inputMixin-D0IzcaXz.js → inputMixin-BsRV69ob.js} +1 -1
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/scout-app-bar.cjs.entry.js +2 -2
  5. package/dist/cjs/scout-avatar.cjs.entry.js +39 -0
  6. package/dist/cjs/scout-bottom-bar-item.cjs.entry.js +2 -2
  7. package/dist/cjs/scout-bottom-bar.cjs.entry.js +2 -2
  8. package/dist/cjs/scout-button.cjs.entry.js +1 -1
  9. package/dist/cjs/scout-card.cjs.entry.js +1 -1
  10. package/dist/cjs/scout-checkbox_2.cjs.entry.js +2 -2
  11. package/dist/cjs/scout-divider.cjs.entry.js +1 -1
  12. package/dist/cjs/scout-drawer.cjs.entry.js +841 -0
  13. package/dist/cjs/scout-field.cjs.entry.js +1 -1
  14. package/dist/cjs/scout-input.cjs.entry.js +2 -2
  15. package/dist/cjs/scout-link.cjs.entry.js +1 -1
  16. package/dist/cjs/scout-list-view-item.cjs.entry.js +2 -2
  17. package/dist/cjs/scout-list-view-subheader.cjs.entry.js +1 -1
  18. package/dist/cjs/scout-list-view.cjs.entry.js +7 -5
  19. package/dist/cjs/scout-loader.cjs.entry.js +1 -1
  20. package/dist/cjs/scout-segmented-control.cjs.entry.js +88 -0
  21. package/dist/cjs/scout-select.cjs.entry.js +3 -3
  22. package/dist/cjs/scout-stack.cjs.entry.js +3 -3
  23. package/dist/cjs/scout-switch.cjs.entry.js +3 -3
  24. package/dist/cjs/scout-tabs-tab.cjs.entry.js +2 -2
  25. package/dist/cjs/scout-tabs.cjs.entry.js +3 -3
  26. package/dist/cjs/ui-webc.cjs.js +2 -2
  27. package/dist/collection/collection-manifest.json +3 -0
  28. package/dist/collection/components/app-bar/app-bar.css +5 -1
  29. package/dist/collection/components/avatar/assets/fallbackImage.png +0 -0
  30. package/dist/collection/components/avatar/avatar.css +7 -0
  31. package/dist/collection/components/avatar/avatar.js +88 -0
  32. package/dist/collection/components/bottom-bar/bottom-bar.css +7 -2
  33. package/dist/collection/components/bottom-bar-item/bottom-bar-item.css +16 -2
  34. package/dist/collection/components/drawer/drawer.css +157 -0
  35. package/dist/collection/components/drawer/drawer.js +323 -0
  36. package/dist/collection/components/list-view/list-view.css +7 -2
  37. package/dist/collection/components/list-view/list-view.js +6 -4
  38. package/dist/collection/components/list-view-item/list-view-item.css +16 -4
  39. package/dist/collection/components/segmented-control/segmented-control.css +68 -0
  40. package/dist/collection/components/segmented-control/segmented-control.js +185 -0
  41. package/dist/collection/components/select/select.js +1 -1
  42. package/dist/collection/components/stack/stack.js +2 -2
  43. package/dist/collection/components/switch/switch.js +1 -1
  44. package/dist/collection/components/tabs/tabs.js +2 -2
  45. package/dist/collection/components/tabs-tab/tabs-tab.js +1 -1
  46. package/dist/components/index.js +1 -1
  47. package/dist/components/p-7UFtpiQE.js +1 -0
  48. package/dist/components/p-CWxftSWo.js +1 -0
  49. package/dist/components/p-DLiFilsh.js +1 -0
  50. package/dist/components/{p-CYcNS38J.js → p-DYpc8Wxz.js} +1 -1
  51. package/dist/components/scout-app-bar.js +1 -1
  52. package/dist/components/scout-avatar.d.ts +11 -0
  53. package/dist/components/scout-avatar.js +1 -0
  54. package/dist/components/scout-bottom-bar-item.js +1 -1
  55. package/dist/components/scout-bottom-bar.js +1 -1
  56. package/dist/components/scout-button.js +1 -1
  57. package/dist/components/scout-card.js +1 -1
  58. package/dist/components/scout-checkbox.js +1 -1
  59. package/dist/components/scout-divider.js +1 -1
  60. package/dist/components/scout-drawer.d.ts +11 -0
  61. package/dist/components/scout-drawer.js +1 -0
  62. package/dist/components/scout-field.js +1 -1
  63. package/dist/components/scout-input.js +1 -1
  64. package/dist/components/scout-link.js +1 -1
  65. package/dist/components/scout-list-view-item.js +1 -1
  66. package/dist/components/scout-list-view-subheader.js +1 -1
  67. package/dist/components/scout-list-view.js +1 -1
  68. package/dist/components/scout-loader.js +1 -1
  69. package/dist/components/scout-radio-button.js +1 -1
  70. package/dist/components/scout-segmented-control.d.ts +11 -0
  71. package/dist/components/scout-segmented-control.js +1 -0
  72. package/dist/components/scout-select.js +1 -1
  73. package/dist/components/scout-stack.js +1 -1
  74. package/dist/components/scout-switch.js +1 -1
  75. package/dist/components/scout-tabs-tab.js +1 -1
  76. package/dist/components/scout-tabs.js +1 -1
  77. package/dist/custom-elements.json +475 -1
  78. package/dist/esm/{index-CBq_WkdR.js → index-BtN0bCWb.js} +35 -5
  79. package/dist/esm/{inputMixin-CArDsEiI.js → inputMixin-DC4hF1Lp.js} +1 -1
  80. package/dist/esm/loader.js +3 -3
  81. package/dist/esm/scout-app-bar.entry.js +2 -2
  82. package/dist/esm/scout-avatar.entry.js +37 -0
  83. package/dist/esm/scout-bottom-bar-item.entry.js +2 -2
  84. package/dist/esm/scout-bottom-bar.entry.js +2 -2
  85. package/dist/esm/scout-button.entry.js +1 -1
  86. package/dist/esm/scout-card.entry.js +1 -1
  87. package/dist/esm/scout-checkbox_2.entry.js +2 -2
  88. package/dist/esm/scout-divider.entry.js +1 -1
  89. package/dist/esm/scout-drawer.entry.js +839 -0
  90. package/dist/esm/scout-field.entry.js +1 -1
  91. package/dist/esm/scout-input.entry.js +2 -2
  92. package/dist/esm/scout-link.entry.js +1 -1
  93. package/dist/esm/scout-list-view-item.entry.js +2 -2
  94. package/dist/esm/scout-list-view-subheader.entry.js +1 -1
  95. package/dist/esm/scout-list-view.entry.js +7 -5
  96. package/dist/esm/scout-loader.entry.js +1 -1
  97. package/dist/esm/scout-segmented-control.entry.js +86 -0
  98. package/dist/esm/scout-select.entry.js +3 -3
  99. package/dist/esm/scout-stack.entry.js +3 -3
  100. package/dist/esm/scout-switch.entry.js +3 -3
  101. package/dist/esm/scout-tabs-tab.entry.js +2 -2
  102. package/dist/esm/scout-tabs.entry.js +3 -3
  103. package/dist/esm/ui-webc.js +3 -3
  104. package/dist/types/components/avatar/avatar.d.ts +16 -0
  105. package/dist/types/components/drawer/drawer.d.ts +53 -0
  106. package/dist/types/components/segmented-control/segmented-control.d.ts +40 -0
  107. package/dist/types/components/tabs/tabs.d.ts +1 -1
  108. package/dist/types/components.d.ts +252 -0
  109. package/dist/ui-webc/assets/fallbackImage.png +0 -0
  110. package/dist/ui-webc/p-0b313ae9.entry.js +1 -0
  111. package/dist/ui-webc/p-1c5b40f5.entry.js +1 -0
  112. package/dist/ui-webc/p-214dc4e4.entry.js +1 -0
  113. package/dist/ui-webc/{p-a153023c.entry.js → p-2d773911.entry.js} +1 -1
  114. package/dist/ui-webc/{p-c0696c1f.entry.js → p-4d676928.entry.js} +1 -1
  115. package/dist/ui-webc/p-4d905b20.entry.js +1 -0
  116. package/dist/ui-webc/{p-f8a4ef3d.entry.js → p-5b0e6de5.entry.js} +1 -1
  117. package/dist/ui-webc/p-6bd3258b.entry.js +1 -0
  118. package/dist/ui-webc/p-6fea31a0.entry.js +1 -0
  119. package/dist/ui-webc/{p-6287efe7.entry.js → p-70c0acea.entry.js} +1 -1
  120. package/dist/ui-webc/p-74bd1d24.entry.js +1 -0
  121. package/dist/ui-webc/{p-0e444b1f.entry.js → p-8c81f27f.entry.js} +1 -1
  122. package/dist/ui-webc/{p-ff537388.entry.js → p-9c8d24b2.entry.js} +1 -1
  123. package/dist/ui-webc/p-9e3739c6.entry.js +1 -0
  124. package/dist/ui-webc/p-BtN0bCWb.js +2 -0
  125. package/dist/ui-webc/{p-6xDaXBJm.js → p-DMdnqqlQ.js} +1 -1
  126. package/dist/ui-webc/{p-b699617e.entry.js → p-a26bd0db.entry.js} +1 -1
  127. package/dist/ui-webc/{p-a2c09e05.entry.js → p-cec7a021.entry.js} +1 -1
  128. package/dist/ui-webc/p-d0fc1cd6.entry.js +1 -0
  129. package/dist/ui-webc/p-d76c67a5.entry.js +1 -0
  130. package/dist/ui-webc/{p-8f5965aa.entry.js → p-d88cbd78.entry.js} +1 -1
  131. package/dist/ui-webc/{p-f8099e5b.entry.js → p-db109100.entry.js} +1 -1
  132. package/dist/ui-webc/{p-6825e415.entry.js → p-ee796725.entry.js} +1 -1
  133. package/dist/ui-webc/{p-189879c2.entry.js → p-f1fb33e9.entry.js} +1 -1
  134. package/dist/ui-webc/ui-webc.css +2 -2
  135. package/dist/ui-webc/ui-webc.esm.js +1 -1
  136. package/package.json +3 -2
  137. package/dist/components/p-CXXyN7aY.js +0 -1
  138. package/dist/components/p-CpD1flSg.js +0 -1
  139. package/dist/components/p-a16hBieR.js +0 -1
  140. package/dist/ui-webc/p-60cd6c7e.entry.js +0 -1
  141. package/dist/ui-webc/p-78126f74.entry.js +0 -1
  142. package/dist/ui-webc/p-CBq_WkdR.js +0 -2
  143. package/dist/ui-webc/p-c4f7cfa2.entry.js +0 -1
  144. package/dist/ui-webc/p-cdc127de.entry.js +0 -1
  145. package/dist/ui-webc/p-db40c987.entry.js +0 -1
  146. package/dist/ui-webc/p-f799b2d8.entry.js +0 -1
  147. package/dist/ui-webc/p-fe2020a1.entry.js +0 -1
@@ -0,0 +1,839 @@
1
+ import { r as registerInstance, c as createEvent, d as getElement, h } from './index-BtN0bCWb.js';
2
+
3
+ /**
4
+ * defines a focus group
5
+ */
6
+ var FOCUS_GROUP = 'data-focus-lock';
7
+ /**
8
+ * disables element discovery inside a group marked by key
9
+ */
10
+ var FOCUS_DISABLED = 'data-focus-lock-disabled';
11
+ /**
12
+ * allows uncontrolled focus within the marked area, effectively disabling focus lock for it's content
13
+ */
14
+ var FOCUS_ALLOW = 'data-no-focus-lock';
15
+ /**
16
+ * instructs autofocus engine to pick default autofocus inside a given node
17
+ * can be set on the element or container
18
+ */
19
+ var FOCUS_AUTO = 'data-autofocus-inside';
20
+ /**
21
+ * instructs autofocus to ignore elements within a given node
22
+ * can be set on the element or container
23
+ */
24
+ var FOCUS_NO_AUTOFOCUS = 'data-no-autofocus';
25
+
26
+ /*
27
+ IE11 support
28
+ */
29
+ var toArray = function (a) {
30
+ var ret = Array(a.length);
31
+ for (var i = 0; i < a.length; ++i) {
32
+ ret[i] = a[i];
33
+ }
34
+ return ret;
35
+ };
36
+ var asArray = function (a) { return (Array.isArray(a) ? a : [a]); };
37
+ var getFirst = function (a) { return (Array.isArray(a) ? a[0] : a); };
38
+
39
+ var isElementHidden = function (node) {
40
+ // we can measure only "elements"
41
+ // consider others as "visible"
42
+ if (node.nodeType !== Node.ELEMENT_NODE) {
43
+ return false;
44
+ }
45
+ var computedStyle = window.getComputedStyle(node, null);
46
+ if (!computedStyle || !computedStyle.getPropertyValue) {
47
+ return false;
48
+ }
49
+ return (computedStyle.getPropertyValue('display') === 'none' || computedStyle.getPropertyValue('visibility') === 'hidden');
50
+ };
51
+ var getParentNode = function (node) {
52
+ // DOCUMENT_FRAGMENT_NODE can also point on ShadowRoot. In this case .host will point on the next node
53
+ return node.parentNode && node.parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE
54
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ node.parentNode.host
56
+ : node.parentNode;
57
+ };
58
+ var isTopNode = function (node) {
59
+ // @ts-ignore
60
+ return node === document || (node && node.nodeType === Node.DOCUMENT_NODE);
61
+ };
62
+ var isVisibleUncached = function (node, checkParent) {
63
+ return !node || isTopNode(node) || (!isElementHidden(node) && checkParent(getParentNode(node)));
64
+ };
65
+ var isVisibleCached = function (visibilityCache, node) {
66
+ var cached = visibilityCache.get(node);
67
+ if (cached !== undefined) {
68
+ return cached;
69
+ }
70
+ var result = isVisibleUncached(node, isVisibleCached.bind(undefined, visibilityCache));
71
+ visibilityCache.set(node, result);
72
+ return result;
73
+ };
74
+ var isAutoFocusAllowedUncached = function (node, checkParent) {
75
+ return node && !isTopNode(node) ? (isAutoFocusAllowed(node) ? checkParent(getParentNode(node)) : false) : true;
76
+ };
77
+ var isAutoFocusAllowedCached = function (cache, node) {
78
+ var cached = cache.get(node);
79
+ if (cached !== undefined) {
80
+ return cached;
81
+ }
82
+ var result = isAutoFocusAllowedUncached(node, isAutoFocusAllowedCached.bind(undefined, cache));
83
+ cache.set(node, result);
84
+ return result;
85
+ };
86
+ var getDataset = function (node) {
87
+ // @ts-ignore
88
+ return node.dataset;
89
+ };
90
+ var isHTMLButtonElement = function (node) { return node.tagName === 'BUTTON'; };
91
+ var isHTMLInputElement = function (node) { return node.tagName === 'INPUT'; };
92
+ var isRadioElement = function (node) {
93
+ return isHTMLInputElement(node) && node.type === 'radio';
94
+ };
95
+ var notHiddenInput = function (node) {
96
+ return !((isHTMLInputElement(node) || isHTMLButtonElement(node)) && (node.type === 'hidden' || node.disabled));
97
+ };
98
+ var isAutoFocusAllowed = function (node) {
99
+ var attribute = node.getAttribute(FOCUS_NO_AUTOFOCUS);
100
+ return ![true, 'true', ''].includes(attribute);
101
+ };
102
+ var isGuard = function (node) { var _a; return Boolean(node && ((_a = getDataset(node)) === null || _a === void 0 ? void 0 : _a.focusGuard)); };
103
+ var isNotAGuard = function (node) { return !isGuard(node); };
104
+ var isDefined = function (x) { return Boolean(x); };
105
+
106
+ var tabSort = function (a, b) {
107
+ var tabDiff = a.tabIndex - b.tabIndex;
108
+ var indexDiff = a.index - b.index;
109
+ if (tabDiff) {
110
+ if (!a.tabIndex) {
111
+ return 1;
112
+ }
113
+ if (!b.tabIndex) {
114
+ return -1;
115
+ }
116
+ }
117
+ return tabDiff || indexDiff;
118
+ };
119
+ var orderByTabIndex = function (nodes, filterNegative, keepGuards) {
120
+ return toArray(nodes)
121
+ .map(function (node, index) { return ({
122
+ node: node,
123
+ index: index,
124
+ tabIndex: node.tabIndex,
125
+ }); })
126
+ .filter(function (data) { return !filterNegative || data.tabIndex >= 0; })
127
+ .sort(tabSort);
128
+ };
129
+
130
+ /**
131
+ * list of the object to be considered as focusable
132
+ */
133
+ var tabbables = [
134
+ 'button:enabled',
135
+ 'select:enabled',
136
+ 'textarea:enabled',
137
+ 'input:enabled',
138
+ // elements with explicit roles will also use explicit tabindex
139
+ // '[role="button"]',
140
+ 'a[href]',
141
+ 'area[href]',
142
+ 'summary',
143
+ 'iframe',
144
+ 'object',
145
+ 'embed',
146
+ 'audio[controls]',
147
+ 'video[controls]',
148
+ '[tabindex]',
149
+ '[contenteditable]',
150
+ '[autofocus]',
151
+ ];
152
+
153
+ var queryTabbables = tabbables.join(',');
154
+ var getFocusablesWithShadowDom = function (parent, withGuards) {
155
+ return toArray((parent.shadowRoot || parent).children).reduce(function (acc, child) {
156
+ return acc.concat(child.matches(queryTabbables) ? [child] : [], getFocusablesWithShadowDom(child));
157
+ }, []);
158
+ };
159
+ var getFocusablesWithIFrame = function (parent, withGuards) {
160
+ var _a;
161
+ // contentDocument of iframe will be null if current origin cannot access it
162
+ if (parent instanceof HTMLIFrameElement && ((_a = parent.contentDocument) === null || _a === void 0 ? void 0 : _a.body)) {
163
+ return getFocusables([parent.contentDocument.body]);
164
+ }
165
+ return [parent];
166
+ };
167
+ var getFocusables = function (parents, withGuards) {
168
+ return parents.reduce(function (acc, parent) {
169
+ var _a;
170
+ var focusableWithShadowDom = getFocusablesWithShadowDom(parent);
171
+ var focusableWithIframes = (_a = []).concat.apply(_a, focusableWithShadowDom.map(function (node) { return getFocusablesWithIFrame(node); }));
172
+ return acc.concat(
173
+ // add all tabbables inside and within shadow DOMs in DOM order
174
+ focusableWithIframes,
175
+ // add if node is tabbable itself
176
+ parent.parentNode
177
+ ? toArray(parent.parentNode.querySelectorAll(queryTabbables)).filter(function (node) { return node === parent; })
178
+ : []);
179
+ }, []);
180
+ };
181
+ /**
182
+ * return a list of focusable nodes within an area marked as "auto-focusable"
183
+ * @param parent
184
+ */
185
+ var getParentAutofocusables = function (parent) {
186
+ var parentFocus = parent.querySelectorAll("[".concat(FOCUS_AUTO, "]"));
187
+ return toArray(parentFocus)
188
+ .map(function (node) { return getFocusables([node]); })
189
+ .reduce(function (acc, nodes) { return acc.concat(nodes); }, []);
190
+ };
191
+
192
+ /**
193
+ * given list of focusable elements keeps the ones user can interact with
194
+ * @param nodes
195
+ * @param visibilityCache
196
+ */
197
+ var filterFocusable = function (nodes, visibilityCache) {
198
+ return toArray(nodes)
199
+ .filter(function (node) { return isVisibleCached(visibilityCache, node); })
200
+ .filter(function (node) { return notHiddenInput(node); });
201
+ };
202
+ var filterAutoFocusable = function (nodes, cache) {
203
+ if (cache === void 0) { cache = new Map(); }
204
+ return toArray(nodes).filter(function (node) { return isAutoFocusAllowedCached(cache, node); });
205
+ };
206
+ /**
207
+ * only tabbable ones
208
+ * (but with guards which would be ignored)
209
+ */
210
+ var getTabbableNodes = function (topNodes, visibilityCache, withGuards) {
211
+ return orderByTabIndex(filterFocusable(getFocusables(topNodes), visibilityCache), true);
212
+ };
213
+ /**
214
+ * actually anything "focusable", not only tabbable
215
+ * (without guards, as long as they are not expected to be focused)
216
+ */
217
+ var getAllTabbableNodes = function (topNodes, visibilityCache) {
218
+ return orderByTabIndex(filterFocusable(getFocusables(topNodes), visibilityCache), false);
219
+ };
220
+ /**
221
+ * return list of nodes which are expected to be auto-focused
222
+ * @param topNode
223
+ * @param visibilityCache
224
+ */
225
+ var parentAutofocusables = function (topNode, visibilityCache) {
226
+ return filterFocusable(getParentAutofocusables(topNode), visibilityCache);
227
+ };
228
+ /*
229
+ * Determines if element is contained in scope, including nested shadow DOMs
230
+ */
231
+ var contains = function (scope, element) {
232
+ if (scope.shadowRoot) {
233
+ return contains(scope.shadowRoot, element);
234
+ }
235
+ else {
236
+ if (Object.getPrototypeOf(scope).contains !== undefined &&
237
+ Object.getPrototypeOf(scope).contains.call(scope, element)) {
238
+ return true;
239
+ }
240
+ return toArray(scope.children).some(function (child) {
241
+ var _a;
242
+ if (child instanceof HTMLIFrameElement) {
243
+ var iframeBody = (_a = child.contentDocument) === null || _a === void 0 ? void 0 : _a.body;
244
+ if (iframeBody) {
245
+ return contains(iframeBody, element);
246
+ }
247
+ return false;
248
+ }
249
+ return contains(child, element);
250
+ });
251
+ }
252
+ };
253
+
254
+ /**
255
+ * in case of multiple nodes nested inside each other
256
+ * keeps only top ones
257
+ * this is O(nlogn)
258
+ * @param nodes
259
+ * @returns {*}
260
+ */
261
+ var filterNested = function (nodes) {
262
+ var contained = new Set();
263
+ var l = nodes.length;
264
+ for (var i = 0; i < l; i += 1) {
265
+ for (var j = i + 1; j < l; j += 1) {
266
+ var position = nodes[i].compareDocumentPosition(nodes[j]);
267
+ /* eslint-disable no-bitwise */
268
+ if ((position & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0) {
269
+ contained.add(j);
270
+ }
271
+ if ((position & Node.DOCUMENT_POSITION_CONTAINS) > 0) {
272
+ contained.add(i);
273
+ }
274
+ /* eslint-enable */
275
+ }
276
+ }
277
+ return nodes.filter(function (_, index) { return !contained.has(index); });
278
+ };
279
+ /**
280
+ * finds top most parent for a node
281
+ * @param node
282
+ * @returns {*}
283
+ */
284
+ var getTopParent = function (node) {
285
+ return node.parentNode ? getTopParent(node.parentNode) : node;
286
+ };
287
+ /**
288
+ * returns all "focus containers" inside a given node
289
+ * @param node
290
+ * @returns {T}
291
+ */
292
+ var getAllAffectedNodes = function (node) {
293
+ var nodes = asArray(node);
294
+ return nodes.filter(Boolean).reduce(function (acc, currentNode) {
295
+ var group = currentNode.getAttribute(FOCUS_GROUP);
296
+ acc.push.apply(acc, (group
297
+ ? filterNested(toArray(getTopParent(currentNode).querySelectorAll("[".concat(FOCUS_GROUP, "=\"").concat(group, "\"]:not([").concat(FOCUS_DISABLED, "=\"disabled\"])"))))
298
+ : [currentNode]));
299
+ return acc;
300
+ }, []);
301
+ };
302
+
303
+ var safeProbe = function (cb) {
304
+ try {
305
+ return cb();
306
+ }
307
+ catch (e) {
308
+ return undefined;
309
+ }
310
+ };
311
+
312
+ /**
313
+ * returns active element from document or from nested shadowdoms
314
+ */
315
+ var getActiveElement = function (inDocument) {
316
+ if (inDocument === void 0) { inDocument = document; }
317
+ if (!inDocument || !inDocument.activeElement) {
318
+ return undefined;
319
+ }
320
+ var activeElement = inDocument.activeElement;
321
+ return (activeElement.shadowRoot
322
+ ? getActiveElement(activeElement.shadowRoot)
323
+ : activeElement instanceof HTMLIFrameElement && safeProbe(function () { return activeElement.contentWindow.document; })
324
+ ? getActiveElement(activeElement.contentWindow.document)
325
+ : activeElement);
326
+ };
327
+
328
+ var focusInFrame = function (frame, activeElement) { return frame === activeElement; };
329
+ var focusInsideIframe = function (topNode, activeElement) {
330
+ return Boolean(toArray(topNode.querySelectorAll('iframe')).some(function (node) { return focusInFrame(node, activeElement); }));
331
+ };
332
+ /**
333
+ * @returns {Boolean} true, if the current focus is inside given node or nodes
334
+ */
335
+ var focusInside = function (topNode, activeElement) {
336
+ // const activeElement = document && getActiveElement();
337
+ if (activeElement === void 0) { activeElement = getActiveElement(getFirst(topNode).ownerDocument); }
338
+ if (!activeElement || (activeElement.dataset && activeElement.dataset.focusGuard)) {
339
+ return false;
340
+ }
341
+ return getAllAffectedNodes(topNode).some(function (node) {
342
+ return contains(node, activeElement) || focusInsideIframe(node, activeElement);
343
+ });
344
+ };
345
+
346
+ /**
347
+ * focus is hidden FROM the focus-lock
348
+ * ie contained inside a node focus-lock shall ignore
349
+ * @returns {boolean} focus is currently is in "allow" area
350
+ */
351
+ var focusIsHidden = function (inDocument) {
352
+ if (inDocument === void 0) { inDocument = document; }
353
+ var activeElement = getActiveElement(inDocument);
354
+ if (!activeElement) {
355
+ return false;
356
+ }
357
+ // this does not support setting FOCUS_ALLOW within shadow dom
358
+ return toArray(inDocument.querySelectorAll("[".concat(FOCUS_ALLOW, "]"))).some(function (node) { return contains(node, activeElement); });
359
+ };
360
+
361
+ var findSelectedRadio = function (node, nodes) {
362
+ return nodes
363
+ .filter(isRadioElement)
364
+ .filter(function (el) { return el.name === node.name; })
365
+ .filter(function (el) { return el.checked; })[0] || node;
366
+ };
367
+ var correctNode = function (node, nodes) {
368
+ if (isRadioElement(node) && node.name) {
369
+ return findSelectedRadio(node, nodes);
370
+ }
371
+ return node;
372
+ };
373
+ /**
374
+ * giving a set of radio inputs keeps only selected (tabbable) ones
375
+ * @param nodes
376
+ */
377
+ var correctNodes = function (nodes) {
378
+ // IE11 has no Set(array) constructor
379
+ var resultSet = new Set();
380
+ nodes.forEach(function (node) { return resultSet.add(correctNode(node, nodes)); });
381
+ // using filter to support IE11
382
+ return nodes.filter(function (node) { return resultSet.has(node); });
383
+ };
384
+
385
+ var pickFirstFocus = function (nodes) {
386
+ if (nodes[0] && nodes.length > 1) {
387
+ return correctNode(nodes[0], nodes);
388
+ }
389
+ return nodes[0];
390
+ };
391
+ var pickFocusable = function (nodes, index) {
392
+ if (nodes.length > 1) {
393
+ return nodes.indexOf(correctNode(nodes[index], nodes));
394
+ }
395
+ return index;
396
+ };
397
+
398
+ var NEW_FOCUS = 'NEW_FOCUS';
399
+ /**
400
+ * Main solver for the "find next focus" question
401
+ * @param innerNodes
402
+ * @param outerNodes
403
+ * @param activeElement
404
+ * @param lastNode
405
+ * @returns {number|string|undefined|*}
406
+ */
407
+ var newFocus = function (innerNodes, outerNodes, activeElement, lastNode) {
408
+ var cnt = innerNodes.length;
409
+ var firstFocus = innerNodes[0];
410
+ var lastFocus = innerNodes[cnt - 1];
411
+ var isOnGuard = isGuard(activeElement);
412
+ // focus is inside
413
+ if (activeElement && innerNodes.indexOf(activeElement) >= 0) {
414
+ return undefined;
415
+ }
416
+ var activeIndex = activeElement !== undefined ? outerNodes.indexOf(activeElement) : -1;
417
+ var lastIndex = lastNode ? outerNodes.indexOf(lastNode) : activeIndex;
418
+ var lastNodeInside = lastNode ? innerNodes.indexOf(lastNode) : -1;
419
+ var indexDiff = activeIndex - lastIndex;
420
+ var firstNodeIndex = outerNodes.indexOf(firstFocus);
421
+ var lastNodeIndex = outerNodes.indexOf(lastFocus);
422
+ var correctedNodes = correctNodes(outerNodes);
423
+ var correctedIndex = activeElement !== undefined ? correctedNodes.indexOf(activeElement) : -1;
424
+ var correctedIndexDiff = correctedIndex - (lastNode ? correctedNodes.indexOf(lastNode) : activeIndex);
425
+ var returnFirstNode = pickFocusable(innerNodes, 0);
426
+ var returnLastNode = pickFocusable(innerNodes, cnt - 1);
427
+ // new focus
428
+ if (activeIndex === -1 || lastNodeInside === -1) {
429
+ return NEW_FOCUS;
430
+ }
431
+ // old focus
432
+ if (!indexDiff && lastNodeInside >= 0) {
433
+ return lastNodeInside;
434
+ }
435
+ // first element
436
+ if (activeIndex <= firstNodeIndex && isOnGuard && Math.abs(indexDiff) > 1) {
437
+ return returnLastNode;
438
+ }
439
+ // last element
440
+ if (activeIndex >= lastNodeIndex && isOnGuard && Math.abs(indexDiff) > 1) {
441
+ return returnFirstNode;
442
+ }
443
+ // jump out, but not on the guard
444
+ if (indexDiff && Math.abs(correctedIndexDiff) > 1) {
445
+ return lastNodeInside;
446
+ }
447
+ // focus above lock
448
+ if (activeIndex <= firstNodeIndex) {
449
+ return returnLastNode;
450
+ }
451
+ // focus below lock
452
+ if (activeIndex > lastNodeIndex) {
453
+ return returnFirstNode;
454
+ }
455
+ // index is inside tab order, but outside Lock
456
+ if (indexDiff) {
457
+ if (Math.abs(indexDiff) > 1) {
458
+ return lastNodeInside;
459
+ }
460
+ return (cnt + lastNodeInside + indexDiff) % cnt;
461
+ }
462
+ // do nothing
463
+ return undefined;
464
+ };
465
+
466
+ var findAutoFocused = function (autoFocusables) {
467
+ return function (node) {
468
+ var _a;
469
+ var autofocus = (_a = getDataset(node)) === null || _a === void 0 ? void 0 : _a.autofocus;
470
+ return (
471
+ // @ts-expect-error
472
+ node.autofocus ||
473
+ //
474
+ (autofocus !== undefined && autofocus !== 'false') ||
475
+ //
476
+ autoFocusables.indexOf(node) >= 0);
477
+ };
478
+ };
479
+ var pickAutofocus = function (nodesIndexes, orderedNodes, groups) {
480
+ var nodes = nodesIndexes.map(function (_a) {
481
+ var node = _a.node;
482
+ return node;
483
+ });
484
+ var autoFocusable = filterAutoFocusable(nodes.filter(findAutoFocused(groups)));
485
+ if (autoFocusable && autoFocusable.length) {
486
+ return pickFirstFocus(autoFocusable);
487
+ }
488
+ return pickFirstFocus(filterAutoFocusable(orderedNodes));
489
+ };
490
+
491
+ var getParents = function (node, parents) {
492
+ if (parents === void 0) { parents = []; }
493
+ parents.push(node);
494
+ if (node.parentNode) {
495
+ getParents(node.parentNode.host || node.parentNode, parents);
496
+ }
497
+ return parents;
498
+ };
499
+ /**
500
+ * finds a parent for both nodeA and nodeB
501
+ * @param nodeA
502
+ * @param nodeB
503
+ * @returns {boolean|*}
504
+ */
505
+ var getCommonParent = function (nodeA, nodeB) {
506
+ var parentsA = getParents(nodeA);
507
+ var parentsB = getParents(nodeB);
508
+ // tslint:disable-next-line:prefer-for-of
509
+ for (var i = 0; i < parentsA.length; i += 1) {
510
+ var currentParent = parentsA[i];
511
+ if (parentsB.indexOf(currentParent) >= 0) {
512
+ return currentParent;
513
+ }
514
+ }
515
+ return false;
516
+ };
517
+ var getTopCommonParent = function (baseActiveElement, leftEntry, rightEntries) {
518
+ var activeElements = asArray(baseActiveElement);
519
+ var leftEntries = asArray(leftEntry);
520
+ var activeElement = activeElements[0];
521
+ var topCommon = false;
522
+ leftEntries.filter(Boolean).forEach(function (entry) {
523
+ topCommon = getCommonParent(topCommon || entry, entry) || topCommon;
524
+ rightEntries.filter(Boolean).forEach(function (subEntry) {
525
+ var common = getCommonParent(activeElement, subEntry);
526
+ if (common) {
527
+ if (!topCommon || contains(common, topCommon)) {
528
+ topCommon = common;
529
+ }
530
+ else {
531
+ topCommon = getCommonParent(common, topCommon);
532
+ }
533
+ }
534
+ });
535
+ });
536
+ // TODO: add assert here?
537
+ return topCommon;
538
+ };
539
+ /**
540
+ * return list of nodes which are expected to be autofocused inside a given top nodes
541
+ * @param entries
542
+ * @param visibilityCache
543
+ */
544
+ var allParentAutofocusables = function (entries, visibilityCache) {
545
+ return entries.reduce(function (acc, node) { return acc.concat(parentAutofocusables(node, visibilityCache)); }, []);
546
+ };
547
+
548
+ var reorderNodes = function (srcNodes, dstNodes) {
549
+ var remap = new Map();
550
+ // no Set(dstNodes) for IE11 :(
551
+ dstNodes.forEach(function (entity) { return remap.set(entity.node, entity); });
552
+ // remap to dstNodes
553
+ return srcNodes.map(function (node) { return remap.get(node); }).filter(isDefined);
554
+ };
555
+ /**
556
+ * given top node(s) and the last active element return the element to be focused next
557
+ * @param topNode
558
+ * @param lastNode
559
+ */
560
+ var getFocusMerge = function (topNode, lastNode) {
561
+ var activeElement = getActiveElement(asArray(topNode).length > 0 ? document : getFirst(topNode).ownerDocument);
562
+ var entries = getAllAffectedNodes(topNode).filter(isNotAGuard);
563
+ var commonParent = getTopCommonParent(activeElement || topNode, topNode, entries);
564
+ var visibilityCache = new Map();
565
+ var anyFocusable = getAllTabbableNodes(entries, visibilityCache);
566
+ var innerElements = getTabbableNodes(entries, visibilityCache).filter(function (_a) {
567
+ var node = _a.node;
568
+ return isNotAGuard(node);
569
+ });
570
+ if (!innerElements[0]) {
571
+ innerElements = anyFocusable;
572
+ if (!innerElements[0]) {
573
+ return undefined;
574
+ }
575
+ }
576
+ var outerNodes = getAllTabbableNodes([commonParent], visibilityCache).map(function (_a) {
577
+ var node = _a.node;
578
+ return node;
579
+ });
580
+ var orderedInnerElements = reorderNodes(outerNodes, innerElements);
581
+ var innerNodes = orderedInnerElements.map(function (_a) {
582
+ var node = _a.node;
583
+ return node;
584
+ });
585
+ var newId = newFocus(innerNodes, outerNodes, activeElement, lastNode);
586
+ if (newId === NEW_FOCUS) {
587
+ var focusNode = pickAutofocus(anyFocusable, innerNodes, allParentAutofocusables(entries, visibilityCache));
588
+ if (focusNode) {
589
+ return { node: focusNode };
590
+ }
591
+ else {
592
+ console.warn('focus-lock: cannot find any node to move focus into');
593
+ return undefined;
594
+ }
595
+ }
596
+ if (newId === undefined) {
597
+ return newId;
598
+ }
599
+ return orderedInnerElements[newId];
600
+ };
601
+
602
+ var focusOn = function (target, focusOptions) {
603
+ if ('focus' in target) {
604
+ target.focus(focusOptions);
605
+ }
606
+ if ('contentWindow' in target && target.contentWindow) {
607
+ target.contentWindow.focus();
608
+ }
609
+ };
610
+ var guardCount = 0;
611
+ var lockDisabled = false;
612
+ /**
613
+ * Sets focus at a given node. The last focused element will help to determine which element(first or last) should be focused.
614
+ * HTML markers (see {@link import('./constants').FOCUS_AUTO} constants) can control autofocus
615
+ * @param topNode
616
+ * @param lastNode
617
+ * @param options
618
+ */
619
+ var setFocus = function (topNode, lastNode, options) {
620
+ if (options === void 0) { options = {}; }
621
+ var focusable = getFocusMerge(topNode, lastNode);
622
+ if (lockDisabled) {
623
+ return;
624
+ }
625
+ if (focusable) {
626
+ if (guardCount > 2) {
627
+ // tslint:disable-next-line:no-console
628
+ console.error('FocusLock: focus-fighting detected. Only one focus management system could be active. ' +
629
+ 'See https://github.com/theKashey/focus-lock/#focus-fighting');
630
+ lockDisabled = true;
631
+ setTimeout(function () {
632
+ lockDisabled = false;
633
+ }, 1);
634
+ return;
635
+ }
636
+ guardCount++;
637
+ focusOn(focusable.node, options.focusOptions);
638
+ guardCount--;
639
+ }
640
+ };
641
+
642
+ var lastActiveTrap = 0;
643
+ var lastActiveFocus = null;
644
+
645
+ var focusOnBody = function focusOnBody() {
646
+ return document && document.activeElement === document.body;
647
+ };
648
+
649
+ var isFreeFocus = function isFreeFocus() {
650
+ return focusOnBody() || focusIsHidden();
651
+ };
652
+
653
+ var activateTrap = function activateTrap() {
654
+ var result = false;
655
+
656
+ if (lastActiveTrap) {
657
+ var observed = lastActiveTrap;
658
+
659
+ if (!isFreeFocus()) {
660
+ if (observed && !focusInside(observed)) {
661
+ result = setFocus(observed, lastActiveFocus);
662
+ }
663
+
664
+ lastActiveFocus = document.activeElement;
665
+ }
666
+ }
667
+
668
+ return result;
669
+ };
670
+
671
+ var reducePropsToState = function reducePropsToState(propsList) {
672
+ return propsList.filter(function (node) {
673
+ return node;
674
+ }).slice(-1)[0];
675
+ };
676
+
677
+ var handleStateChangeOnClient = function handleStateChangeOnClient(trap) {
678
+ lastActiveTrap = trap;
679
+
680
+ if (trap) {
681
+ activateTrap();
682
+ }
683
+ };
684
+
685
+ var instances = [];
686
+
687
+ var emitChange = function emitChange(event) {
688
+ if (handleStateChangeOnClient(reducePropsToState(instances))) {
689
+ event && event.preventDefault();
690
+ return true;
691
+ }
692
+
693
+ return false;
694
+ };
695
+
696
+ var attachHandler = function attachHandler() {
697
+ document.addEventListener('focusin', emitChange);
698
+ };
699
+
700
+ var detachHandler = function detachHandler() {
701
+ document.removeEventListener('focusin', emitChange);
702
+ };
703
+
704
+ var focusLock = {
705
+ on: function on(domNode) {
706
+ if (instances.length === 0) {
707
+ attachHandler();
708
+ }
709
+
710
+ if (instances.indexOf(domNode) < 0) {
711
+ instances.push(domNode);
712
+ emitChange();
713
+ }
714
+ },
715
+ off: function off(domNode) {
716
+ instances = instances.filter(function (node) {
717
+ return node !== domNode;
718
+ });
719
+ emitChange();
720
+
721
+ if (instances.length === 0) {
722
+ detachHandler();
723
+ }
724
+ }
725
+ };
726
+
727
+ const drawerCss = () => `.drawer{width:100%}.drawer--container{position:fixed;bottom:0;right:0;left:0;height:90%;width:100%;transform:translateY(100%);background-color:#fefefe;box-shadow:0 0 20px 3px var(--color-gray-200);border-top-left-radius:var(--spacing-5);border-top-right-radius:var(--spacing-5);overflow:hidden;margin:0;z-index:101}@keyframes drawerOpen{from{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes drawerClose{from{transform:translateY(0)}to{transform:translateY(100%)}}.open{animation:drawerOpen 0.3s ease-in-out forwards}.close{animation:drawerClose 0.3s ease-in-out forwards}@media screen and (min-width: 901px){@keyframes drawerOpen{from{transform:translateX(100%)}to{transform:translateX(0)}}@keyframes drawerClose{from{transform:translateX(0)}to{transform:translateX(100%)}}.drawer--container{top:0;bottom:0;right:0;left:auto;left:initial;height:100%;max-height:100%;max-width:90%;min-height:600px;width:430px;transform:translateX(100%);border-top-left-radius:var(--spacing-5);border-bottom-left-radius:var(--spacing-5);border-top-right-radius:0}.open{animation:drawerOpen 0.3s ease-in-out forwards}.close{animation:drawerClose 0.3s ease-in-out forwards}}.backdrop{position:fixed;top:0;bottom:0;left:0;right:0;transition:opacity 0.2s;z-index:100}.backdrop-hidden{opacity:0}.backdrop-visible{opacity:0.6;pointer-events:all;background-color:var(--color-gray-200)}.header--wrapper{display:flex;position:relative;width:100%;height:var(--spacing-20);flex-direction:row;justify-content:center;align-items:center}.heading{font:var(--type-body-lg);font-weight:600;color:var(--color-text-base)}.content--wrapper{padding:0 var(--spacing-7)}button{z-index:2;pointer-events:all;cursor:pointer;background:none;box-shadow:none;position:absolute;border:none;width:24px;height:24px;padding:24px;display:flex;align-items:center;justify-content:center}.exit-button{right:var(--spacing-3)}.back-button{left:var(--spacing-3)}.visually-hidden{clip:rect(0 0 0 0);clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px}`;
728
+
729
+ const backIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrow-left"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l14 0" /><path d="M5 12l6 6" /><path d="M5 12l6 -6" /></svg>';
730
+ const exitIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 6l-12 12" /><path d="M6 6l12 12" /></svg>';
731
+ const ScoutDrawer = class {
732
+ constructor(hostRef) {
733
+ registerInstance(this, hostRef);
734
+ this.backButtonClicked = createEvent(this, "backButtonClicked");
735
+ this.exitButtonClicked = createEvent(this, "exitButtonClicked");
736
+ }
737
+ get rootElement() { return getElement(this); }
738
+ /**
739
+ * Open/close state of the drawer.
740
+ */
741
+ open = false;
742
+ /**
743
+ * Heading within the sheet.
744
+ */
745
+ heading = "";
746
+ /**
747
+ * Render back button.
748
+ */
749
+ showBackButton = false;
750
+ /**
751
+ * Back button label.
752
+ */
753
+ backButtonLabel = "";
754
+ /**
755
+ * Render exit button.
756
+ */
757
+ showExitButton = false;
758
+ /**
759
+ * Exit button label.
760
+ */
761
+ exitButtonLabel = "";
762
+ /**
763
+ * Disable backdrop for the drawer.
764
+ */
765
+ disableBackdrop = false;
766
+ /**
767
+ * Disable drawer content padding. Use only if you have specific use case and you need to use full width.
768
+ */
769
+ disableContentPadding = false;
770
+ drawerState = "closed";
771
+ focusedNode = null;
772
+ componentWillLoad() {
773
+ this.focusedNode = document.activeElement;
774
+ }
775
+ componentDidLoad() {
776
+ if (this.open) {
777
+ this.setDrawerOpenState(true);
778
+ }
779
+ }
780
+ disconnectedCallback() {
781
+ }
782
+ /**
783
+ * Fired when clicking backButton (<-)
784
+ */
785
+ backButtonClicked;
786
+ /**
787
+ * Fired when clicking backButton (X). Also sent when clicking the backdrop.
788
+ */
789
+ exitButtonClicked;
790
+ onBackButtonClick() {
791
+ this.backButtonClicked.emit();
792
+ }
793
+ onExitButtonClick() {
794
+ this.exitButtonClicked.emit();
795
+ }
796
+ setDrawerOpenState(open) {
797
+ const drawer = this.rootElement.shadowRoot.querySelector(".drawer--container");
798
+ if (!drawer) {
799
+ this.drawerState = open ? "opening" : "closing";
800
+ }
801
+ if (open) {
802
+ this.drawerState = "opening";
803
+ focusLock.on(drawer);
804
+ }
805
+ else {
806
+ focusLock.off(drawer);
807
+ this.drawerState = "closing";
808
+ }
809
+ }
810
+ render() {
811
+ const shouldRenderHeader = this.heading || this.showBackButton || this.showExitButton;
812
+ const getDrawerStateClass = (state) => {
813
+ switch (state) {
814
+ case "opening":
815
+ case "open":
816
+ return "open";
817
+ case "closing":
818
+ return "close";
819
+ }
820
+ };
821
+ return (h("div", { class: "drawer" }, !this.disableBackdrop && (
822
+ // biome-ignore lint/a11y/noStaticElementInteractions: <closable backdrop>
823
+ // biome-ignore lint/a11y/useKeyWithClickEvents: <closable backdrop>
824
+ h("div", { onClick: () => {
825
+ this.onExitButtonClick();
826
+ }, class: `backdrop ${this.drawerState !== "closed" ? "backdrop-visible" : "backdrop-hidden"}` })), h("div", { class: `drawer--container ${getDrawerStateClass(this.drawerState)}`, onAnimationEnd: () => {
827
+ this.drawerState = this.open ? "open" : "closed";
828
+ } }, shouldRenderHeader && (h("div", { class: "header--wrapper" }, this.showBackButton && (h("button", { type: "button", class: "back-button", onClick: () => this.onBackButtonClick() }, h("span", { class: "icon", innerHTML: backIcon }), h("span", { class: "visually-hidden" }, this.backButtonLabel))), this.showExitButton && (h("button", { type: "button", class: "exit-button", onClick: () => this.onExitButtonClick() }, h("span", { class: "icon", innerHTML: exitIcon }), h("span", { class: "visually-hidden" }, this.exitButtonLabel))), this.heading && h("h3", { class: "heading" }, this.heading))), h("div", { class: !this.disableContentPadding && `content--wrapper` }, h("slot", null)))));
829
+ }
830
+ static get delegatesFocus() { return true; }
831
+ static get watchers() { return {
832
+ "open": [{
833
+ "setDrawerOpenState": 0
834
+ }]
835
+ }; }
836
+ };
837
+ ScoutDrawer.style = drawerCss();
838
+
839
+ export { ScoutDrawer as scout_drawer };