@limetech/lime-elements 33.14.0-next.11 → 33.14.0-next.15

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 (66) hide show
  1. package/dist/cjs/component-f7ef9087.js +2365 -0
  2. package/dist/cjs/lime-elements.cjs.js +1 -1
  3. package/dist/cjs/limel-list_2.cjs.entry.js +497 -0
  4. package/dist/cjs/limel-menu-list.cjs.entry.js +885 -0
  5. package/dist/cjs/limel-menu.cjs.entry.js +4 -4
  6. package/dist/cjs/limel-portal.cjs.entry.js +1935 -0
  7. package/dist/cjs/limel-tooltip-content.cjs.entry.js +5 -2
  8. package/dist/cjs/limel-tooltip.cjs.entry.js +1 -1
  9. package/dist/cjs/loader.cjs.js +1 -1
  10. package/dist/collection/collection-manifest.json +1 -0
  11. package/dist/collection/components/header/header.js +0 -1
  12. package/dist/collection/components/list/list-renderer.js +161 -163
  13. package/dist/collection/components/list/list.css +0 -10
  14. package/dist/collection/components/list/list.js +77 -125
  15. package/dist/collection/components/menu/menu.js +9 -9
  16. package/dist/collection/components/menu-list/menu-list-renderer-config.js +1 -0
  17. package/dist/collection/components/menu-list/menu-list-renderer.js +158 -0
  18. package/dist/collection/components/menu-list/menu-list.css +3397 -0
  19. package/dist/collection/components/menu-list/menu-list.js +288 -0
  20. package/dist/collection/components/menu-list/menu-list.types.js +1 -0
  21. package/dist/collection/components/menu-surface/menu-surface.js +84 -87
  22. package/dist/collection/components/popover/popover.js +0 -1
  23. package/dist/collection/components/tooltip/tooltip-content.css +25 -13
  24. package/dist/collection/components/tooltip/tooltip-content.js +4 -3
  25. package/dist/collection/components/tooltip/tooltip.css +0 -6
  26. package/dist/collection/components/tooltip/tooltip.js +31 -5
  27. package/dist/esm/component-2eb4e07b.js +2357 -0
  28. package/dist/esm/lime-elements.js +1 -1
  29. package/dist/esm/limel-list_2.entry.js +492 -0
  30. package/dist/esm/limel-menu-list.entry.js +881 -0
  31. package/dist/esm/limel-menu.entry.js +4 -4
  32. package/dist/esm/limel-portal.entry.js +1931 -0
  33. package/dist/esm/limel-tooltip-content.entry.js +5 -2
  34. package/dist/esm/limel-tooltip.entry.js +1 -1
  35. package/dist/esm/loader.js +1 -1
  36. package/dist/lime-elements/lime-elements.esm.js +1 -1
  37. package/dist/lime-elements/p-31299106.js +126 -0
  38. package/dist/lime-elements/p-6ea02589.entry.js +82 -0
  39. package/dist/lime-elements/{p-b0b18dfc.entry.js → p-8e4e13b3.entry.js} +1 -1
  40. package/dist/lime-elements/p-aeada929.entry.js +1 -0
  41. package/dist/lime-elements/{p-63e4f918.entry.js → p-cd5e3858.entry.js} +1 -1
  42. package/dist/lime-elements/p-d3aefa5f.entry.js +1 -0
  43. package/dist/lime-elements/p-f8c33335.entry.js +1 -0
  44. package/dist/types/components/header/header.d.ts +0 -1
  45. package/dist/types/components/list/list-item.types.d.ts +2 -1
  46. package/dist/types/components/list/list-renderer-config.d.ts +0 -1
  47. package/dist/types/components/list/list-renderer.d.ts +0 -1
  48. package/dist/types/components/list/list.d.ts +0 -7
  49. package/dist/types/components/list/list.types.d.ts +1 -1
  50. package/dist/types/components/menu/menu.d.ts +2 -3
  51. package/dist/types/components/menu/menu.types.d.ts +35 -3
  52. package/dist/types/components/menu-list/menu-list-renderer-config.d.ts +8 -0
  53. package/dist/types/components/menu-list/menu-list-renderer.d.ts +49 -0
  54. package/dist/types/components/menu-list/menu-list.d.ts +59 -0
  55. package/dist/types/components/menu-list/menu-list.types.d.ts +6 -0
  56. package/dist/types/components/menu-surface/menu-surface.d.ts +0 -1
  57. package/dist/types/components/popover/popover.d.ts +0 -1
  58. package/dist/types/components/tooltip/tooltip-content.d.ts +1 -1
  59. package/dist/types/components/tooltip/tooltip.d.ts +31 -5
  60. package/dist/types/components.d.ts +66 -5
  61. package/dist/types/interface.d.ts +1 -0
  62. package/package.json +2 -1
  63. package/dist/cjs/limel-list_3.cjs.entry.js +0 -5418
  64. package/dist/esm/limel-list_3.entry.js +0 -5412
  65. package/dist/lime-elements/p-a6a7dd00.entry.js +0 -1
  66. package/dist/lime-elements/p-e078c459.entry.js +0 -177
@@ -0,0 +1,2365 @@
1
+ 'use strict';
2
+
3
+ const component = require('./component-f532119f.js');
4
+ const ponyfill = require('./ponyfill-98ca4766.js');
5
+ const keyboard = require('./keyboard-9477d3a8.js');
6
+ const util = require('./util-b0f5741e.js');
7
+
8
+ /**
9
+ * @license
10
+ * Copyright 2018 Google Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in
20
+ * all copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ * THE SOFTWARE.
29
+ */
30
+ var cssClasses$1 = {
31
+ ANCHOR: 'mdc-menu-surface--anchor',
32
+ ANIMATING_CLOSED: 'mdc-menu-surface--animating-closed',
33
+ ANIMATING_OPEN: 'mdc-menu-surface--animating-open',
34
+ FIXED: 'mdc-menu-surface--fixed',
35
+ IS_OPEN_BELOW: 'mdc-menu-surface--is-open-below',
36
+ OPEN: 'mdc-menu-surface--open',
37
+ ROOT: 'mdc-menu-surface',
38
+ };
39
+ // tslint:disable:object-literal-sort-keys
40
+ var strings$1 = {
41
+ CLOSED_EVENT: 'MDCMenuSurface:closed',
42
+ CLOSING_EVENT: 'MDCMenuSurface:closing',
43
+ OPENED_EVENT: 'MDCMenuSurface:opened',
44
+ FOCUSABLE_ELEMENTS: [
45
+ 'button:not(:disabled)',
46
+ '[href]:not([aria-disabled="true"])',
47
+ 'input:not(:disabled)',
48
+ 'select:not(:disabled)',
49
+ 'textarea:not(:disabled)',
50
+ '[tabindex]:not([tabindex="-1"]):not([aria-disabled="true"])',
51
+ ].join(', '),
52
+ };
53
+ // tslint:enable:object-literal-sort-keys
54
+ var numbers$1 = {
55
+ /** Total duration of menu-surface open animation. */
56
+ TRANSITION_OPEN_DURATION: 120,
57
+ /** Total duration of menu-surface close animation. */
58
+ TRANSITION_CLOSE_DURATION: 75,
59
+ /** Margin left to the edge of the viewport when menu-surface is at maximum possible height. Also used as a viewport margin. */
60
+ MARGIN_TO_EDGE: 32,
61
+ /** Ratio of anchor width to menu-surface width for switching from corner positioning to center positioning. */
62
+ ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO: 0.67,
63
+ };
64
+ /**
65
+ * Enum for bits in the {@see Corner) bitmap.
66
+ */
67
+ var CornerBit;
68
+ (function (CornerBit) {
69
+ CornerBit[CornerBit["BOTTOM"] = 1] = "BOTTOM";
70
+ CornerBit[CornerBit["CENTER"] = 2] = "CENTER";
71
+ CornerBit[CornerBit["RIGHT"] = 4] = "RIGHT";
72
+ CornerBit[CornerBit["FLIP_RTL"] = 8] = "FLIP_RTL";
73
+ })(CornerBit || (CornerBit = {}));
74
+ /**
75
+ * Enum for representing an element corner for positioning the menu-surface.
76
+ *
77
+ * The START constants map to LEFT if element directionality is left
78
+ * to right and RIGHT if the directionality is right to left.
79
+ * Likewise END maps to RIGHT or LEFT depending on the directionality.
80
+ */
81
+ exports.Corner = void 0;
82
+ (function (Corner) {
83
+ Corner[Corner["TOP_LEFT"] = 0] = "TOP_LEFT";
84
+ Corner[Corner["TOP_RIGHT"] = 4] = "TOP_RIGHT";
85
+ Corner[Corner["BOTTOM_LEFT"] = 1] = "BOTTOM_LEFT";
86
+ Corner[Corner["BOTTOM_RIGHT"] = 5] = "BOTTOM_RIGHT";
87
+ Corner[Corner["TOP_START"] = 8] = "TOP_START";
88
+ Corner[Corner["TOP_END"] = 12] = "TOP_END";
89
+ Corner[Corner["BOTTOM_START"] = 9] = "BOTTOM_START";
90
+ Corner[Corner["BOTTOM_END"] = 13] = "BOTTOM_END";
91
+ })(exports.Corner || (exports.Corner = {}));
92
+
93
+ /*! *****************************************************************************
94
+ Copyright (c) Microsoft Corporation.
95
+
96
+ Permission to use, copy, modify, and/or distribute this software for any
97
+ purpose with or without fee is hereby granted.
98
+
99
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
100
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
101
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
102
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
103
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
104
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
105
+ PERFORMANCE OF THIS SOFTWARE.
106
+ ***************************************************************************** */
107
+ /* global Reflect, Promise */
108
+
109
+ var extendStatics$1 = function(d, b) {
110
+ extendStatics$1 = Object.setPrototypeOf ||
111
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
112
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
113
+ return extendStatics$1(d, b);
114
+ };
115
+
116
+ function __extends$1(d, b) {
117
+ if (typeof b !== "function" && b !== null)
118
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
119
+ extendStatics$1(d, b);
120
+ function __() { this.constructor = d; }
121
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
122
+ }
123
+
124
+ var __assign$1 = function() {
125
+ __assign$1 = Object.assign || function __assign(t) {
126
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
127
+ s = arguments[i];
128
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
129
+ }
130
+ return t;
131
+ };
132
+ return __assign$1.apply(this, arguments);
133
+ };
134
+
135
+ /**
136
+ * @license
137
+ * Copyright 2018 Google Inc.
138
+ *
139
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
140
+ * of this software and associated documentation files (the "Software"), to deal
141
+ * in the Software without restriction, including without limitation the rights
142
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
143
+ * copies of the Software, and to permit persons to whom the Software is
144
+ * furnished to do so, subject to the following conditions:
145
+ *
146
+ * The above copyright notice and this permission notice shall be included in
147
+ * all copies or substantial portions of the Software.
148
+ *
149
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
152
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
153
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
154
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
155
+ * THE SOFTWARE.
156
+ */
157
+ var _a, _b;
158
+ var cssClasses = {
159
+ LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
160
+ LIST_ITEM_CLASS: 'mdc-list-item',
161
+ LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
162
+ LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
163
+ LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
164
+ LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
165
+ ROOT: 'mdc-list',
166
+ };
167
+ var evolutionClassNameMap = (_a = {},
168
+ _a["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-list-item--activated',
169
+ _a["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-list-item',
170
+ _a["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-list-item--disabled',
171
+ _a["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-list-item--selected',
172
+ _a["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-list-item__primary-text',
173
+ _a["" + cssClasses.ROOT] = 'mdc-list',
174
+ _a);
175
+ var deprecatedClassNameMap = (_b = {},
176
+ _b["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-deprecated-list-item--activated',
177
+ _b["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-deprecated-list-item',
178
+ _b["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-deprecated-list-item--disabled',
179
+ _b["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-deprecated-list-item--selected',
180
+ _b["" + cssClasses.LIST_ITEM_TEXT_CLASS] = 'mdc-deprecated-list-item__text',
181
+ _b["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-deprecated-list-item__primary-text',
182
+ _b["" + cssClasses.ROOT] = 'mdc-deprecated-list',
183
+ _b);
184
+ var strings = {
185
+ ACTION_EVENT: 'MDCList:action',
186
+ ARIA_CHECKED: 'aria-checked',
187
+ ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
188
+ ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
189
+ ARIA_CURRENT: 'aria-current',
190
+ ARIA_DISABLED: 'aria-disabled',
191
+ ARIA_ORIENTATION: 'aria-orientation',
192
+ ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
193
+ ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
194
+ ARIA_SELECTED: 'aria-selected',
195
+ ARIA_INTERACTIVE_ROLES_SELECTOR: '[role="listbox"], [role="menu"]',
196
+ ARIA_MULTI_SELECTABLE_SELECTOR: '[aria-multiselectable="true"]',
197
+ CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
198
+ CHECKBOX_SELECTOR: 'input[type="checkbox"]',
199
+ CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a\n ",
200
+ DEPRECATED_SELECTOR: '.mdc-deprecated-list',
201
+ FOCUSABLE_CHILD_ELEMENTS: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"radio\"]:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"checkbox\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"radio\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"checkbox\"]:not(:disabled)\n ",
202
+ RADIO_SELECTOR: 'input[type="radio"]',
203
+ SELECTED_ITEM_SELECTOR: '[aria-selected="true"], [aria-current="true"]',
204
+ };
205
+ var numbers = {
206
+ UNSET_INDEX: -1,
207
+ TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
208
+ };
209
+ var evolutionAttribute = 'evolution';
210
+
211
+ /**
212
+ * @license
213
+ * Copyright 2020 Google Inc.
214
+ *
215
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
216
+ * of this software and associated documentation files (the "Software"), to deal
217
+ * in the Software without restriction, including without limitation the rights
218
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
219
+ * copies of the Software, and to permit persons to whom the Software is
220
+ * furnished to do so, subject to the following conditions:
221
+ *
222
+ * The above copyright notice and this permission notice shall be included in
223
+ * all copies or substantial portions of the Software.
224
+ *
225
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
226
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
227
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
228
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
229
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
230
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
231
+ * THE SOFTWARE.
232
+ */
233
+ var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
234
+ /**
235
+ * Ensures that preventDefault is only called if the containing element
236
+ * doesn't consume the event, and it will cause an unintended scroll.
237
+ *
238
+ * @param evt keyboard event to be prevented.
239
+ */
240
+ var preventDefaultEvent = function (evt) {
241
+ var target = evt.target;
242
+ if (!target) {
243
+ return;
244
+ }
245
+ var tagName = ("" + target.tagName).toLowerCase();
246
+ if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
247
+ evt.preventDefault();
248
+ }
249
+ };
250
+
251
+ /**
252
+ * @license
253
+ * Copyright 2020 Google Inc.
254
+ *
255
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
256
+ * of this software and associated documentation files (the "Software"), to deal
257
+ * in the Software without restriction, including without limitation the rights
258
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
259
+ * copies of the Software, and to permit persons to whom the Software is
260
+ * furnished to do so, subject to the following conditions:
261
+ *
262
+ * The above copyright notice and this permission notice shall be included in
263
+ * all copies or substantial portions of the Software.
264
+ *
265
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
266
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
267
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
268
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
269
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
270
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
271
+ * THE SOFTWARE.
272
+ */
273
+ /**
274
+ * Initializes a state object for typeahead. Use the same reference for calls to
275
+ * typeahead functions.
276
+ *
277
+ * @return The current state of the typeahead process. Each state reference
278
+ * represents a typeahead instance as the reference is typically mutated
279
+ * in-place.
280
+ */
281
+ function initState() {
282
+ var state = {
283
+ bufferClearTimeout: 0,
284
+ currentFirstChar: '',
285
+ sortedIndexCursor: 0,
286
+ typeaheadBuffer: '',
287
+ };
288
+ return state;
289
+ }
290
+ /**
291
+ * Initializes typeahead state by indexing the current list items by primary
292
+ * text into the sortedIndexByFirstChar data structure.
293
+ *
294
+ * @param listItemCount numer of items in the list
295
+ * @param getPrimaryTextByItemIndex function that returns the primary text at a
296
+ * given index
297
+ *
298
+ * @return Map that maps the first character of the primary text to the full
299
+ * list text and it's index
300
+ */
301
+ function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
302
+ var sortedIndexByFirstChar = new Map();
303
+ // Aggregate item text to index mapping
304
+ for (var i = 0; i < listItemCount; i++) {
305
+ var primaryText = getPrimaryTextByItemIndex(i).trim();
306
+ if (!primaryText) {
307
+ continue;
308
+ }
309
+ var firstChar = primaryText[0].toLowerCase();
310
+ if (!sortedIndexByFirstChar.has(firstChar)) {
311
+ sortedIndexByFirstChar.set(firstChar, []);
312
+ }
313
+ sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
314
+ }
315
+ // Sort the mapping
316
+ // TODO(b/157162694): Investigate replacing forEach with Map.values()
317
+ sortedIndexByFirstChar.forEach(function (values) {
318
+ values.sort(function (first, second) {
319
+ return first.index - second.index;
320
+ });
321
+ });
322
+ return sortedIndexByFirstChar;
323
+ }
324
+ /**
325
+ * Given the next desired character from the user, it attempts to find the next
326
+ * list option matching the buffer. Wraps around if at the end of options.
327
+ *
328
+ * @param opts Options and accessors
329
+ * - nextChar - the next character to match against items
330
+ * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
331
+ * - focusedItemIndex - the index of the currently focused item
332
+ * - focusItemAtIndex - function that focuses a list item at given index
333
+ * - skipFocus - whether or not to focus the matched item
334
+ * - isItemAtIndexDisabled - function that determines whether an item at a
335
+ * given index is disabled
336
+ * @param state The typeahead state instance. See `initState`.
337
+ *
338
+ * @return The index of the matched item, or -1 if no match.
339
+ */
340
+ function matchItem(opts, state) {
341
+ var nextChar = opts.nextChar, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, focusedItemIndex = opts.focusedItemIndex, skipFocus = opts.skipFocus, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
342
+ clearTimeout(state.bufferClearTimeout);
343
+ state.bufferClearTimeout = setTimeout(function () {
344
+ clearBuffer(state);
345
+ }, numbers.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
346
+ state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
347
+ var index;
348
+ if (state.typeaheadBuffer.length === 1) {
349
+ index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
350
+ }
351
+ else {
352
+ index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
353
+ }
354
+ if (index !== -1 && !skipFocus) {
355
+ focusItemAtIndex(index);
356
+ }
357
+ return index;
358
+ }
359
+ /**
360
+ * Matches the user's single input character in the buffer to the
361
+ * next option that begins with such character. Wraps around if at
362
+ * end of options. Returns -1 if no match is found.
363
+ */
364
+ function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
365
+ var firstChar = state.typeaheadBuffer[0];
366
+ var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
367
+ if (!itemsMatchingFirstChar) {
368
+ return -1;
369
+ }
370
+ // Has the same firstChar been recently matched?
371
+ // Also, did starting index remain the same between key presses?
372
+ // If both hold true, simply increment index.
373
+ if (firstChar === state.currentFirstChar &&
374
+ itemsMatchingFirstChar[state.sortedIndexCursor].index ===
375
+ focusedItemIndex) {
376
+ state.sortedIndexCursor =
377
+ (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
378
+ var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
379
+ if (!isItemAtIndexDisabled(newIndex)) {
380
+ return newIndex;
381
+ }
382
+ }
383
+ // If we're here, it means one of the following happened:
384
+ // - either firstChar or startingIndex has changed, invalidating the
385
+ // cursor.
386
+ // - The next item of typeahead is disabled, so we have to look further.
387
+ state.currentFirstChar = firstChar;
388
+ var newCursorPosition = -1;
389
+ var cursorPosition;
390
+ // Find the first non-disabled item as a fallback.
391
+ for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
392
+ if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
393
+ newCursorPosition = cursorPosition;
394
+ break;
395
+ }
396
+ }
397
+ // Advance cursor to first item matching the firstChar that is positioned
398
+ // after starting item. Cursor is unchanged from fallback if there's no
399
+ // such item.
400
+ for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
401
+ if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex &&
402
+ !isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
403
+ newCursorPosition = cursorPosition;
404
+ break;
405
+ }
406
+ }
407
+ if (newCursorPosition !== -1) {
408
+ state.sortedIndexCursor = newCursorPosition;
409
+ return itemsMatchingFirstChar[state.sortedIndexCursor].index;
410
+ }
411
+ return -1;
412
+ }
413
+ /**
414
+ * Attempts to find the next item that matches all of the typeahead buffer.
415
+ * Wraps around if at end of options. Returns -1 if no match is found.
416
+ */
417
+ function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
418
+ var firstChar = state.typeaheadBuffer[0];
419
+ var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
420
+ if (!itemsMatchingFirstChar) {
421
+ return -1;
422
+ }
423
+ // Do nothing if text already matches
424
+ var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
425
+ if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 &&
426
+ !isItemAtIndexDisabled(startingItem.index)) {
427
+ return startingItem.index;
428
+ }
429
+ // Find next item that matches completely; if no match, we'll eventually
430
+ // loop around to same position
431
+ var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
432
+ var nextCursorPosition = -1;
433
+ while (cursorPosition !== state.sortedIndexCursor) {
434
+ var currentItem = itemsMatchingFirstChar[cursorPosition];
435
+ var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
436
+ var isEnabled = !isItemAtIndexDisabled(currentItem.index);
437
+ if (matches && isEnabled) {
438
+ nextCursorPosition = cursorPosition;
439
+ break;
440
+ }
441
+ cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
442
+ }
443
+ if (nextCursorPosition !== -1) {
444
+ state.sortedIndexCursor = nextCursorPosition;
445
+ return itemsMatchingFirstChar[state.sortedIndexCursor].index;
446
+ }
447
+ return -1;
448
+ }
449
+ /**
450
+ * Whether or not the given typeahead instaance state is currently typing.
451
+ *
452
+ * @param state The typeahead state instance. See `initState`.
453
+ */
454
+ function isTypingInProgress(state) {
455
+ return state.typeaheadBuffer.length > 0;
456
+ }
457
+ /**
458
+ * Clears the typeahaed buffer so that it resets item matching to the first
459
+ * character.
460
+ *
461
+ * @param state The typeahead state instance. See `initState`.
462
+ */
463
+ function clearBuffer(state) {
464
+ state.typeaheadBuffer = '';
465
+ }
466
+ /**
467
+ * Given a keydown event, it calculates whether or not to automatically focus a
468
+ * list item depending on what was typed mimicing the typeahead functionality of
469
+ * a standard <select> element that is open.
470
+ *
471
+ * @param opts Options and accessors
472
+ * - event - the KeyboardEvent to handle and parse
473
+ * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
474
+ * - focusedItemIndex - the index of the currently focused item
475
+ * - focusItemAtIndex - function that focuses a list item at given index
476
+ * - isItemAtFocusedIndexDisabled - whether or not the currently focused item
477
+ * is disabled
478
+ * - isTargetListItem - whether or not the event target is a list item
479
+ * @param state The typeahead state instance. See `initState`.
480
+ *
481
+ * @returns index of the item matched by the keydown. -1 if not matched.
482
+ */
483
+ function handleKeydown(opts, state) {
484
+ var event = opts.event, isTargetListItem = opts.isTargetListItem, focusedItemIndex = opts.focusedItemIndex, focusItemAtIndex = opts.focusItemAtIndex, sortedIndexByFirstChar = opts.sortedIndexByFirstChar, isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
485
+ var isArrowLeft = keyboard.normalizeKey(event) === 'ArrowLeft';
486
+ var isArrowUp = keyboard.normalizeKey(event) === 'ArrowUp';
487
+ var isArrowRight = keyboard.normalizeKey(event) === 'ArrowRight';
488
+ var isArrowDown = keyboard.normalizeKey(event) === 'ArrowDown';
489
+ var isHome = keyboard.normalizeKey(event) === 'Home';
490
+ var isEnd = keyboard.normalizeKey(event) === 'End';
491
+ var isEnter = keyboard.normalizeKey(event) === 'Enter';
492
+ var isSpace = keyboard.normalizeKey(event) === 'Spacebar';
493
+ if (event.ctrlKey || event.metaKey || isArrowLeft || isArrowUp ||
494
+ isArrowRight || isArrowDown || isHome || isEnd || isEnter) {
495
+ return -1;
496
+ }
497
+ var isCharacterKey = !isSpace && event.key.length === 1;
498
+ if (isCharacterKey) {
499
+ preventDefaultEvent(event);
500
+ var matchItemOpts = {
501
+ focusItemAtIndex: focusItemAtIndex,
502
+ focusedItemIndex: focusedItemIndex,
503
+ nextChar: event.key.toLowerCase(),
504
+ sortedIndexByFirstChar: sortedIndexByFirstChar,
505
+ skipFocus: false,
506
+ isItemAtIndexDisabled: isItemAtIndexDisabled,
507
+ };
508
+ return matchItem(matchItemOpts, state);
509
+ }
510
+ if (!isSpace) {
511
+ return -1;
512
+ }
513
+ if (isTargetListItem) {
514
+ preventDefaultEvent(event);
515
+ }
516
+ var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
517
+ if (typeaheadOnListItem) {
518
+ var matchItemOpts = {
519
+ focusItemAtIndex: focusItemAtIndex,
520
+ focusedItemIndex: focusedItemIndex,
521
+ nextChar: ' ',
522
+ sortedIndexByFirstChar: sortedIndexByFirstChar,
523
+ skipFocus: false,
524
+ isItemAtIndexDisabled: isItemAtIndexDisabled,
525
+ };
526
+ // space participates in typeahead matching if in rapid typing mode
527
+ return matchItem(matchItemOpts, state);
528
+ }
529
+ return -1;
530
+ }
531
+
532
+ /**
533
+ * @license
534
+ * Copyright 2018 Google Inc.
535
+ *
536
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
537
+ * of this software and associated documentation files (the "Software"), to deal
538
+ * in the Software without restriction, including without limitation the rights
539
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
540
+ * copies of the Software, and to permit persons to whom the Software is
541
+ * furnished to do so, subject to the following conditions:
542
+ *
543
+ * The above copyright notice and this permission notice shall be included in
544
+ * all copies or substantial portions of the Software.
545
+ *
546
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
547
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
548
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
549
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
550
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
551
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
552
+ * THE SOFTWARE.
553
+ */
554
+ function isNumberArray(selectedIndex) {
555
+ return selectedIndex instanceof Array;
556
+ }
557
+ var MDCListFoundation = /** @class */ (function (_super) {
558
+ __extends$1(MDCListFoundation, _super);
559
+ function MDCListFoundation(adapter) {
560
+ var _this = _super.call(this, __assign$1(__assign$1({}, MDCListFoundation.defaultAdapter), adapter)) || this;
561
+ _this.wrapFocus_ = false;
562
+ _this.isVertical_ = true;
563
+ _this.isSingleSelectionList_ = false;
564
+ _this.selectedIndex_ = numbers.UNSET_INDEX;
565
+ _this.focusedItemIndex = numbers.UNSET_INDEX;
566
+ _this.useActivatedClass_ = false;
567
+ _this.useSelectedAttr_ = false;
568
+ _this.ariaCurrentAttrValue_ = null;
569
+ _this.isCheckboxList_ = false;
570
+ _this.isRadioList_ = false;
571
+ _this.hasTypeahead = false;
572
+ // Transiently holds current typeahead prefix from user.
573
+ _this.typeaheadState = initState();
574
+ _this.sortedIndexByFirstChar = new Map();
575
+ return _this;
576
+ }
577
+ Object.defineProperty(MDCListFoundation, "strings", {
578
+ get: function () {
579
+ return strings;
580
+ },
581
+ enumerable: false,
582
+ configurable: true
583
+ });
584
+ Object.defineProperty(MDCListFoundation, "cssClasses", {
585
+ get: function () {
586
+ return cssClasses;
587
+ },
588
+ enumerable: false,
589
+ configurable: true
590
+ });
591
+ Object.defineProperty(MDCListFoundation, "numbers", {
592
+ get: function () {
593
+ return numbers;
594
+ },
595
+ enumerable: false,
596
+ configurable: true
597
+ });
598
+ Object.defineProperty(MDCListFoundation, "defaultAdapter", {
599
+ get: function () {
600
+ return {
601
+ addClassForElementIndex: function () { return undefined; },
602
+ focusItemAtIndex: function () { return undefined; },
603
+ getAttributeForElementIndex: function () { return null; },
604
+ getFocusedElementIndex: function () { return 0; },
605
+ getListItemCount: function () { return 0; },
606
+ hasCheckboxAtIndex: function () { return false; },
607
+ hasRadioAtIndex: function () { return false; },
608
+ isCheckboxCheckedAtIndex: function () { return false; },
609
+ isFocusInsideList: function () { return false; },
610
+ isRootFocused: function () { return false; },
611
+ listItemAtIndexHasClass: function () { return false; },
612
+ notifyAction: function () { return undefined; },
613
+ removeClassForElementIndex: function () { return undefined; },
614
+ setAttributeForElementIndex: function () { return undefined; },
615
+ setCheckedCheckboxOrRadioAtIndex: function () { return undefined; },
616
+ setTabIndexForListItemChildren: function () { return undefined; },
617
+ getPrimaryTextAtIndex: function () { return ''; },
618
+ };
619
+ },
620
+ enumerable: false,
621
+ configurable: true
622
+ });
623
+ MDCListFoundation.prototype.layout = function () {
624
+ if (this.adapter.getListItemCount() === 0) {
625
+ return;
626
+ }
627
+ // TODO(b/172274142): consider all items when determining the list's type.
628
+ if (this.adapter.hasCheckboxAtIndex(0)) {
629
+ this.isCheckboxList_ = true;
630
+ }
631
+ else if (this.adapter.hasRadioAtIndex(0)) {
632
+ this.isRadioList_ = true;
633
+ }
634
+ else {
635
+ this.maybeInitializeSingleSelection();
636
+ }
637
+ if (this.hasTypeahead) {
638
+ this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
639
+ }
640
+ };
641
+ /**
642
+ * Sets the private wrapFocus_ variable.
643
+ */
644
+ MDCListFoundation.prototype.setWrapFocus = function (value) {
645
+ this.wrapFocus_ = value;
646
+ };
647
+ /**
648
+ * Sets the isVertical_ private variable.
649
+ */
650
+ MDCListFoundation.prototype.setVerticalOrientation = function (value) {
651
+ this.isVertical_ = value;
652
+ };
653
+ /**
654
+ * Sets the isSingleSelectionList_ private variable.
655
+ */
656
+ MDCListFoundation.prototype.setSingleSelection = function (value) {
657
+ this.isSingleSelectionList_ = value;
658
+ if (value) {
659
+ this.maybeInitializeSingleSelection();
660
+ }
661
+ };
662
+ /**
663
+ * Automatically determines whether the list is single selection list. If so,
664
+ * initializes the internal state to match the selected item.
665
+ */
666
+ MDCListFoundation.prototype.maybeInitializeSingleSelection = function () {
667
+ var listItemsCount = this.adapter.getListItemCount();
668
+ for (var i = 0; i < listItemsCount; i++) {
669
+ var hasSelectedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_SELECTED_CLASS);
670
+ var hasActivatedClass = this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_ACTIVATED_CLASS);
671
+ if (!(hasSelectedClass || hasActivatedClass)) {
672
+ continue;
673
+ }
674
+ if (hasActivatedClass) {
675
+ this.setUseActivatedClass(true);
676
+ }
677
+ this.isSingleSelectionList_ = true;
678
+ this.selectedIndex_ = i;
679
+ return;
680
+ }
681
+ };
682
+ /**
683
+ * Sets whether typeahead is enabled on the list.
684
+ * @param hasTypeahead Whether typeahead is enabled.
685
+ */
686
+ MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
687
+ this.hasTypeahead = hasTypeahead;
688
+ if (hasTypeahead) {
689
+ this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
690
+ }
691
+ };
692
+ /**
693
+ * @return Whether typeahead is currently matching a user-specified prefix.
694
+ */
695
+ MDCListFoundation.prototype.isTypeaheadInProgress = function () {
696
+ return this.hasTypeahead &&
697
+ isTypingInProgress(this.typeaheadState);
698
+ };
699
+ /**
700
+ * Sets the useActivatedClass_ private variable.
701
+ */
702
+ MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
703
+ this.useActivatedClass_ = useActivated;
704
+ };
705
+ /**
706
+ * Sets the useSelectedAttr_ private variable.
707
+ */
708
+ MDCListFoundation.prototype.setUseSelectedAttribute = function (useSelected) {
709
+ this.useSelectedAttr_ = useSelected;
710
+ };
711
+ MDCListFoundation.prototype.getSelectedIndex = function () {
712
+ return this.selectedIndex_;
713
+ };
714
+ MDCListFoundation.prototype.setSelectedIndex = function (index) {
715
+ if (!this.isIndexValid_(index)) {
716
+ return;
717
+ }
718
+ if (this.isCheckboxList_) {
719
+ this.setCheckboxAtIndex_(index);
720
+ }
721
+ else if (this.isRadioList_) {
722
+ this.setRadioAtIndex_(index);
723
+ }
724
+ else {
725
+ this.setSingleSelectionAtIndex_(index);
726
+ }
727
+ };
728
+ /**
729
+ * Focus in handler for the list items.
730
+ */
731
+ MDCListFoundation.prototype.handleFocusIn = function (_, listItemIndex) {
732
+ if (listItemIndex >= 0) {
733
+ this.focusedItemIndex = listItemIndex;
734
+ this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '0');
735
+ this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
736
+ }
737
+ };
738
+ /**
739
+ * Focus out handler for the list items.
740
+ */
741
+ MDCListFoundation.prototype.handleFocusOut = function (_, listItemIndex) {
742
+ var _this = this;
743
+ if (listItemIndex >= 0) {
744
+ this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '-1');
745
+ this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
746
+ }
747
+ /**
748
+ * Between Focusout & Focusin some browsers do not have focus on any
749
+ * element. Setting a delay to wait till the focus is moved to next element.
750
+ */
751
+ setTimeout(function () {
752
+ if (!_this.adapter.isFocusInsideList()) {
753
+ _this.setTabindexToFirstSelectedOrFocusedItem();
754
+ }
755
+ }, 0);
756
+ };
757
+ /**
758
+ * Key handler for the list.
759
+ */
760
+ MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
761
+ var _this = this;
762
+ var isArrowLeft = keyboard.normalizeKey(event) === 'ArrowLeft';
763
+ var isArrowUp = keyboard.normalizeKey(event) === 'ArrowUp';
764
+ var isArrowRight = keyboard.normalizeKey(event) === 'ArrowRight';
765
+ var isArrowDown = keyboard.normalizeKey(event) === 'ArrowDown';
766
+ var isHome = keyboard.normalizeKey(event) === 'Home';
767
+ var isEnd = keyboard.normalizeKey(event) === 'End';
768
+ var isEnter = keyboard.normalizeKey(event) === 'Enter';
769
+ var isSpace = keyboard.normalizeKey(event) === 'Spacebar';
770
+ // Have to check both upper and lower case, because having caps lock on affects the value.
771
+ var isLetterA = event.key === 'A' || event.key === 'a';
772
+ if (this.adapter.isRootFocused()) {
773
+ if (isArrowUp || isEnd) {
774
+ event.preventDefault();
775
+ this.focusLastElement();
776
+ }
777
+ else if (isArrowDown || isHome) {
778
+ event.preventDefault();
779
+ this.focusFirstElement();
780
+ }
781
+ if (this.hasTypeahead) {
782
+ var handleKeydownOpts = {
783
+ event: event,
784
+ focusItemAtIndex: function (index) {
785
+ _this.focusItemAtIndex(index);
786
+ },
787
+ focusedItemIndex: -1,
788
+ isTargetListItem: isRootListItem,
789
+ sortedIndexByFirstChar: this.sortedIndexByFirstChar,
790
+ isItemAtIndexDisabled: function (index) {
791
+ return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS);
792
+ },
793
+ };
794
+ handleKeydown(handleKeydownOpts, this.typeaheadState);
795
+ }
796
+ return;
797
+ }
798
+ var currentIndex = this.adapter.getFocusedElementIndex();
799
+ if (currentIndex === -1) {
800
+ currentIndex = listItemIndex;
801
+ if (currentIndex < 0) {
802
+ // If this event doesn't have a mdc-list-item ancestor from the
803
+ // current list (not from a sublist), return early.
804
+ return;
805
+ }
806
+ }
807
+ if ((this.isVertical_ && isArrowDown) ||
808
+ (!this.isVertical_ && isArrowRight)) {
809
+ preventDefaultEvent(event);
810
+ this.focusNextElement(currentIndex);
811
+ }
812
+ else if ((this.isVertical_ && isArrowUp) || (!this.isVertical_ && isArrowLeft)) {
813
+ preventDefaultEvent(event);
814
+ this.focusPrevElement(currentIndex);
815
+ }
816
+ else if (isHome) {
817
+ preventDefaultEvent(event);
818
+ this.focusFirstElement();
819
+ }
820
+ else if (isEnd) {
821
+ preventDefaultEvent(event);
822
+ this.focusLastElement();
823
+ }
824
+ else if (isLetterA && event.ctrlKey && this.isCheckboxList_) {
825
+ event.preventDefault();
826
+ this.toggleAll(this.selectedIndex_ === numbers.UNSET_INDEX ? [] : this.selectedIndex_);
827
+ }
828
+ else if (isEnter || isSpace) {
829
+ if (isRootListItem) {
830
+ // Return early if enter key is pressed on anchor element which triggers
831
+ // synthetic MouseEvent event.
832
+ var target = event.target;
833
+ if (target && target.tagName === 'A' && isEnter) {
834
+ return;
835
+ }
836
+ preventDefaultEvent(event);
837
+ if (this.adapter.listItemAtIndexHasClass(currentIndex, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
838
+ return;
839
+ }
840
+ if (!this.isTypeaheadInProgress()) {
841
+ if (this.isSelectableList_()) {
842
+ this.setSelectedIndexOnAction_(currentIndex);
843
+ }
844
+ this.adapter.notifyAction(currentIndex);
845
+ }
846
+ }
847
+ }
848
+ if (this.hasTypeahead) {
849
+ var handleKeydownOpts = {
850
+ event: event,
851
+ focusItemAtIndex: function (index) {
852
+ _this.focusItemAtIndex(index);
853
+ },
854
+ focusedItemIndex: this.focusedItemIndex,
855
+ isTargetListItem: isRootListItem,
856
+ sortedIndexByFirstChar: this.sortedIndexByFirstChar,
857
+ isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); },
858
+ };
859
+ handleKeydown(handleKeydownOpts, this.typeaheadState);
860
+ }
861
+ };
862
+ /**
863
+ * Click handler for the list.
864
+ */
865
+ MDCListFoundation.prototype.handleClick = function (index, toggleCheckbox) {
866
+ if (index === numbers.UNSET_INDEX) {
867
+ return;
868
+ }
869
+ if (this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS)) {
870
+ return;
871
+ }
872
+ if (this.isSelectableList_()) {
873
+ this.setSelectedIndexOnAction_(index, toggleCheckbox);
874
+ }
875
+ this.adapter.notifyAction(index);
876
+ };
877
+ /**
878
+ * Focuses the next element on the list.
879
+ */
880
+ MDCListFoundation.prototype.focusNextElement = function (index) {
881
+ var count = this.adapter.getListItemCount();
882
+ var nextIndex = index + 1;
883
+ if (nextIndex >= count) {
884
+ if (this.wrapFocus_) {
885
+ nextIndex = 0;
886
+ }
887
+ else {
888
+ // Return early because last item is already focused.
889
+ return index;
890
+ }
891
+ }
892
+ this.focusItemAtIndex(nextIndex);
893
+ return nextIndex;
894
+ };
895
+ /**
896
+ * Focuses the previous element on the list.
897
+ */
898
+ MDCListFoundation.prototype.focusPrevElement = function (index) {
899
+ var prevIndex = index - 1;
900
+ if (prevIndex < 0) {
901
+ if (this.wrapFocus_) {
902
+ prevIndex = this.adapter.getListItemCount() - 1;
903
+ }
904
+ else {
905
+ // Return early because first item is already focused.
906
+ return index;
907
+ }
908
+ }
909
+ this.focusItemAtIndex(prevIndex);
910
+ return prevIndex;
911
+ };
912
+ MDCListFoundation.prototype.focusFirstElement = function () {
913
+ this.focusItemAtIndex(0);
914
+ return 0;
915
+ };
916
+ MDCListFoundation.prototype.focusLastElement = function () {
917
+ var lastIndex = this.adapter.getListItemCount() - 1;
918
+ this.focusItemAtIndex(lastIndex);
919
+ return lastIndex;
920
+ };
921
+ MDCListFoundation.prototype.focusInitialElement = function () {
922
+ var initialIndex = this.getFirstSelectedOrFocusedItemIndex();
923
+ this.focusItemAtIndex(initialIndex);
924
+ return initialIndex;
925
+ };
926
+ /**
927
+ * @param itemIndex Index of the list item
928
+ * @param isEnabled Sets the list item to enabled or disabled.
929
+ */
930
+ MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
931
+ if (!this.isIndexValid_(itemIndex)) {
932
+ return;
933
+ }
934
+ if (isEnabled) {
935
+ this.adapter.removeClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
936
+ this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'false');
937
+ }
938
+ else {
939
+ this.adapter.addClassForElementIndex(itemIndex, cssClasses.LIST_ITEM_DISABLED_CLASS);
940
+ this.adapter.setAttributeForElementIndex(itemIndex, strings.ARIA_DISABLED, 'true');
941
+ }
942
+ };
943
+ MDCListFoundation.prototype.setSingleSelectionAtIndex_ = function (index) {
944
+ if (this.selectedIndex_ === index) {
945
+ return;
946
+ }
947
+ var selectedClassName = cssClasses.LIST_ITEM_SELECTED_CLASS;
948
+ if (this.useActivatedClass_) {
949
+ selectedClassName = cssClasses.LIST_ITEM_ACTIVATED_CLASS;
950
+ }
951
+ if (this.selectedIndex_ !== numbers.UNSET_INDEX) {
952
+ this.adapter.removeClassForElementIndex(this.selectedIndex_, selectedClassName);
953
+ }
954
+ this.setAriaForSingleSelectionAtIndex_(index);
955
+ this.setTabindexAtIndex(index);
956
+ if (index !== numbers.UNSET_INDEX) {
957
+ this.adapter.addClassForElementIndex(index, selectedClassName);
958
+ }
959
+ this.selectedIndex_ = index;
960
+ };
961
+ /**
962
+ * Sets aria attribute for single selection at given index.
963
+ */
964
+ MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex_ = function (index) {
965
+ // Detect the presence of aria-current and get the value only during list
966
+ // initialization when it is in unset state.
967
+ if (this.selectedIndex_ === numbers.UNSET_INDEX) {
968
+ this.ariaCurrentAttrValue_ =
969
+ this.adapter.getAttributeForElementIndex(index, strings.ARIA_CURRENT);
970
+ }
971
+ var isAriaCurrent = this.ariaCurrentAttrValue_ !== null;
972
+ var ariaAttribute = isAriaCurrent ? strings.ARIA_CURRENT : strings.ARIA_SELECTED;
973
+ if (this.selectedIndex_ !== numbers.UNSET_INDEX) {
974
+ this.adapter.setAttributeForElementIndex(this.selectedIndex_, ariaAttribute, 'false');
975
+ }
976
+ if (index !== numbers.UNSET_INDEX) {
977
+ var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue_ : 'true';
978
+ this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
979
+ }
980
+ };
981
+ /**
982
+ * Returns the attribute to use for indicating selection status.
983
+ */
984
+ MDCListFoundation.prototype.getSelectionAttribute = function () {
985
+ return this.useSelectedAttr_ ? strings.ARIA_SELECTED : strings.ARIA_CHECKED;
986
+ };
987
+ /**
988
+ * Toggles radio at give index. Radio doesn't change the checked state if it
989
+ * is already checked.
990
+ */
991
+ MDCListFoundation.prototype.setRadioAtIndex_ = function (index) {
992
+ var selectionAttribute = this.getSelectionAttribute();
993
+ this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
994
+ if (this.selectedIndex_ !== numbers.UNSET_INDEX) {
995
+ this.adapter.setAttributeForElementIndex(this.selectedIndex_, selectionAttribute, 'false');
996
+ }
997
+ this.adapter.setAttributeForElementIndex(index, selectionAttribute, 'true');
998
+ this.selectedIndex_ = index;
999
+ };
1000
+ MDCListFoundation.prototype.setCheckboxAtIndex_ = function (index) {
1001
+ var selectionAttribute = this.getSelectionAttribute();
1002
+ for (var i = 0; i < this.adapter.getListItemCount(); i++) {
1003
+ var isChecked = false;
1004
+ if (index.indexOf(i) >= 0) {
1005
+ isChecked = true;
1006
+ }
1007
+ this.adapter.setCheckedCheckboxOrRadioAtIndex(i, isChecked);
1008
+ this.adapter.setAttributeForElementIndex(i, selectionAttribute, isChecked ? 'true' : 'false');
1009
+ }
1010
+ this.selectedIndex_ = index;
1011
+ };
1012
+ MDCListFoundation.prototype.setTabindexAtIndex = function (index) {
1013
+ if (this.focusedItemIndex === numbers.UNSET_INDEX && index !== 0) {
1014
+ // If some list item was selected set first list item's tabindex to -1.
1015
+ // Generally, tabindex is set to 0 on first list item of list that has no
1016
+ // preselected items.
1017
+ this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
1018
+ }
1019
+ else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
1020
+ this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
1021
+ }
1022
+ // Set the previous selection's tabindex to -1. We need this because
1023
+ // in selection menus that are not visible, programmatically setting an
1024
+ // option will not change focus but will change where tabindex should be 0.
1025
+ if (!(this.selectedIndex_ instanceof Array) &&
1026
+ this.selectedIndex_ !== index) {
1027
+ this.adapter.setAttributeForElementIndex(this.selectedIndex_, 'tabindex', '-1');
1028
+ }
1029
+ if (index !== numbers.UNSET_INDEX) {
1030
+ this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
1031
+ }
1032
+ };
1033
+ /**
1034
+ * @return Return true if it is single selectin list, checkbox list or radio
1035
+ * list.
1036
+ */
1037
+ MDCListFoundation.prototype.isSelectableList_ = function () {
1038
+ return this.isSingleSelectionList_ || this.isCheckboxList_ ||
1039
+ this.isRadioList_;
1040
+ };
1041
+ MDCListFoundation.prototype.setTabindexToFirstSelectedOrFocusedItem = function () {
1042
+ var targetIndex = this.getFirstSelectedOrFocusedItemIndex();
1043
+ this.setTabindexAtIndex(targetIndex);
1044
+ };
1045
+ MDCListFoundation.prototype.getFirstSelectedOrFocusedItemIndex = function () {
1046
+ var targetIndex = this.focusedItemIndex >= 0 ? this.focusedItemIndex : 0;
1047
+ if (this.isSelectableList_()) {
1048
+ if (typeof this.selectedIndex_ === 'number' &&
1049
+ this.selectedIndex_ !== numbers.UNSET_INDEX) {
1050
+ targetIndex = this.selectedIndex_;
1051
+ }
1052
+ else if (isNumberArray(this.selectedIndex_) &&
1053
+ this.selectedIndex_.length > 0) {
1054
+ targetIndex = this.selectedIndex_.reduce(function (currentIndex, minIndex) { return Math.min(currentIndex, minIndex); });
1055
+ }
1056
+ }
1057
+ return targetIndex;
1058
+ };
1059
+ MDCListFoundation.prototype.isIndexValid_ = function (index) {
1060
+ var _this = this;
1061
+ if (index instanceof Array) {
1062
+ if (!this.isCheckboxList_) {
1063
+ throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
1064
+ }
1065
+ if (index.length === 0) {
1066
+ return true;
1067
+ }
1068
+ else {
1069
+ return index.some(function (i) { return _this.isIndexInRange_(i); });
1070
+ }
1071
+ }
1072
+ else if (typeof index === 'number') {
1073
+ if (this.isCheckboxList_) {
1074
+ throw new Error("MDCListFoundation: Expected array of index for checkbox based list but got number: " + index);
1075
+ }
1076
+ return this.isIndexInRange_(index) ||
1077
+ this.isSingleSelectionList_ && index === numbers.UNSET_INDEX;
1078
+ }
1079
+ else {
1080
+ return false;
1081
+ }
1082
+ };
1083
+ MDCListFoundation.prototype.isIndexInRange_ = function (index) {
1084
+ var listSize = this.adapter.getListItemCount();
1085
+ return index >= 0 && index < listSize;
1086
+ };
1087
+ /**
1088
+ * Sets selected index on user action, toggles checkbox / radio based on
1089
+ * toggleCheckbox value. User interaction should not toggle list item(s) when
1090
+ * disabled.
1091
+ */
1092
+ MDCListFoundation.prototype.setSelectedIndexOnAction_ = function (index, toggleCheckbox) {
1093
+ if (toggleCheckbox === void 0) { toggleCheckbox = true; }
1094
+ if (this.isCheckboxList_) {
1095
+ this.toggleCheckboxAtIndex_(index, toggleCheckbox);
1096
+ }
1097
+ else {
1098
+ this.setSelectedIndex(index);
1099
+ }
1100
+ };
1101
+ MDCListFoundation.prototype.toggleCheckboxAtIndex_ = function (index, toggleCheckbox) {
1102
+ var selectionAttribute = this.getSelectionAttribute();
1103
+ var isChecked = this.adapter.isCheckboxCheckedAtIndex(index);
1104
+ if (toggleCheckbox) {
1105
+ isChecked = !isChecked;
1106
+ this.adapter.setCheckedCheckboxOrRadioAtIndex(index, isChecked);
1107
+ }
1108
+ this.adapter.setAttributeForElementIndex(index, selectionAttribute, isChecked ? 'true' : 'false');
1109
+ // If none of the checkbox items are selected and selectedIndex is not
1110
+ // initialized then provide a default value.
1111
+ var selectedIndexes = this.selectedIndex_ === numbers.UNSET_INDEX ?
1112
+ [] :
1113
+ this.selectedIndex_.slice();
1114
+ if (isChecked) {
1115
+ selectedIndexes.push(index);
1116
+ }
1117
+ else {
1118
+ selectedIndexes = selectedIndexes.filter(function (i) { return i !== index; });
1119
+ }
1120
+ this.selectedIndex_ = selectedIndexes;
1121
+ };
1122
+ MDCListFoundation.prototype.focusItemAtIndex = function (index) {
1123
+ this.adapter.focusItemAtIndex(index);
1124
+ this.focusedItemIndex = index;
1125
+ };
1126
+ MDCListFoundation.prototype.toggleAll = function (currentlySelectedIndexes) {
1127
+ var count = this.adapter.getListItemCount();
1128
+ // If all items are selected, deselect everything.
1129
+ if (currentlySelectedIndexes.length === count) {
1130
+ this.setCheckboxAtIndex_([]);
1131
+ }
1132
+ else {
1133
+ // Otherwise select all enabled options.
1134
+ var allIndexes = [];
1135
+ for (var i = 0; i < count; i++) {
1136
+ if (!this.adapter.listItemAtIndexHasClass(i, cssClasses.LIST_ITEM_DISABLED_CLASS) ||
1137
+ currentlySelectedIndexes.indexOf(i) > -1) {
1138
+ allIndexes.push(i);
1139
+ }
1140
+ }
1141
+ this.setCheckboxAtIndex_(allIndexes);
1142
+ }
1143
+ };
1144
+ /**
1145
+ * Given the next desired character from the user, adds it to the typeahead
1146
+ * buffer. Then, attempts to find the next option matching the buffer. Wraps
1147
+ * around if at the end of options.
1148
+ *
1149
+ * @param nextChar The next character to add to the prefix buffer.
1150
+ * @param startingIndex The index from which to start matching. Only relevant
1151
+ * when starting a new match sequence. To start a new match sequence,
1152
+ * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
1153
+ * to clear after a set interval defined in list foundation. Defaults to
1154
+ * the currently focused index.
1155
+ * @return The index of the matched item, or -1 if no match.
1156
+ */
1157
+ MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
1158
+ var _this = this;
1159
+ if (skipFocus === void 0) { skipFocus = false; }
1160
+ var opts = {
1161
+ focusItemAtIndex: function (index) {
1162
+ _this.focusItemAtIndex(index);
1163
+ },
1164
+ focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
1165
+ nextChar: nextChar,
1166
+ sortedIndexByFirstChar: this.sortedIndexByFirstChar,
1167
+ skipFocus: skipFocus,
1168
+ isItemAtIndexDisabled: function (index) { return _this.adapter.listItemAtIndexHasClass(index, cssClasses.LIST_ITEM_DISABLED_CLASS); }
1169
+ };
1170
+ return matchItem(opts, this.typeaheadState);
1171
+ };
1172
+ /**
1173
+ * Initializes the MDCListTextAndIndex data structure by indexing the current
1174
+ * list items by primary text.
1175
+ *
1176
+ * @return The primary texts of all the list items sorted by first character.
1177
+ */
1178
+ MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
1179
+ return initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
1180
+ };
1181
+ /**
1182
+ * Clears the typeahead buffer.
1183
+ */
1184
+ MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
1185
+ clearBuffer(this.typeaheadState);
1186
+ };
1187
+ return MDCListFoundation;
1188
+ }(component.MDCFoundation));
1189
+
1190
+ /**
1191
+ * @license
1192
+ * Copyright 2018 Google Inc.
1193
+ *
1194
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1195
+ * of this software and associated documentation files (the "Software"), to deal
1196
+ * in the Software without restriction, including without limitation the rights
1197
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1198
+ * copies of the Software, and to permit persons to whom the Software is
1199
+ * furnished to do so, subject to the following conditions:
1200
+ *
1201
+ * The above copyright notice and this permission notice shall be included in
1202
+ * all copies or substantial portions of the Software.
1203
+ *
1204
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1205
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1206
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1207
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1208
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1209
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1210
+ * THE SOFTWARE.
1211
+ */
1212
+ var MDCList = /** @class */ (function (_super) {
1213
+ __extends$1(MDCList, _super);
1214
+ function MDCList() {
1215
+ return _super !== null && _super.apply(this, arguments) || this;
1216
+ }
1217
+ Object.defineProperty(MDCList.prototype, "vertical", {
1218
+ set: function (value) {
1219
+ this.foundation.setVerticalOrientation(value);
1220
+ },
1221
+ enumerable: false,
1222
+ configurable: true
1223
+ });
1224
+ Object.defineProperty(MDCList.prototype, "listElements", {
1225
+ get: function () {
1226
+ return Array.from(this.root.querySelectorAll("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS]));
1227
+ },
1228
+ enumerable: false,
1229
+ configurable: true
1230
+ });
1231
+ Object.defineProperty(MDCList.prototype, "wrapFocus", {
1232
+ set: function (value) {
1233
+ this.foundation.setWrapFocus(value);
1234
+ },
1235
+ enumerable: false,
1236
+ configurable: true
1237
+ });
1238
+ Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
1239
+ /**
1240
+ * @return Whether typeahead is currently matching a user-specified prefix.
1241
+ */
1242
+ get: function () {
1243
+ return this.foundation.isTypeaheadInProgress();
1244
+ },
1245
+ enumerable: false,
1246
+ configurable: true
1247
+ });
1248
+ Object.defineProperty(MDCList.prototype, "hasTypeahead", {
1249
+ /**
1250
+ * Sets whether typeahead functionality is enabled on the list.
1251
+ * @param hasTypeahead Whether typeahead is enabled.
1252
+ */
1253
+ set: function (hasTypeahead) {
1254
+ this.foundation.setHasTypeahead(hasTypeahead);
1255
+ },
1256
+ enumerable: false,
1257
+ configurable: true
1258
+ });
1259
+ Object.defineProperty(MDCList.prototype, "singleSelection", {
1260
+ set: function (isSingleSelectionList) {
1261
+ this.foundation.setSingleSelection(isSingleSelectionList);
1262
+ },
1263
+ enumerable: false,
1264
+ configurable: true
1265
+ });
1266
+ Object.defineProperty(MDCList.prototype, "selectedIndex", {
1267
+ get: function () {
1268
+ return this.foundation.getSelectedIndex();
1269
+ },
1270
+ set: function (index) {
1271
+ this.foundation.setSelectedIndex(index);
1272
+ },
1273
+ enumerable: false,
1274
+ configurable: true
1275
+ });
1276
+ MDCList.attachTo = function (root) {
1277
+ return new MDCList(root);
1278
+ };
1279
+ MDCList.prototype.initialSyncWithDOM = function () {
1280
+ this.isEvolutionEnabled =
1281
+ evolutionAttribute in this.root.dataset;
1282
+ if (this.isEvolutionEnabled) {
1283
+ this.classNameMap = evolutionClassNameMap;
1284
+ }
1285
+ else if (ponyfill.matches(this.root, strings.DEPRECATED_SELECTOR)) {
1286
+ this.classNameMap = deprecatedClassNameMap;
1287
+ }
1288
+ else {
1289
+ this.classNameMap =
1290
+ Object.values(cssClasses)
1291
+ .reduce(function (obj, className) {
1292
+ obj[className] = className;
1293
+ return obj;
1294
+ }, {});
1295
+ }
1296
+ this.handleClick = this.handleClickEvent.bind(this);
1297
+ this.handleKeydown = this.handleKeydownEvent.bind(this);
1298
+ this.focusInEventListener = this.handleFocusInEvent.bind(this);
1299
+ this.focusOutEventListener = this.handleFocusOutEvent.bind(this);
1300
+ this.listen('keydown', this.handleKeydown);
1301
+ this.listen('click', this.handleClick);
1302
+ this.listen('focusin', this.focusInEventListener);
1303
+ this.listen('focusout', this.focusOutEventListener);
1304
+ this.layout();
1305
+ this.initializeListType();
1306
+ this.ensureFocusable();
1307
+ };
1308
+ MDCList.prototype.destroy = function () {
1309
+ this.unlisten('keydown', this.handleKeydown);
1310
+ this.unlisten('click', this.handleClick);
1311
+ this.unlisten('focusin', this.focusInEventListener);
1312
+ this.unlisten('focusout', this.focusOutEventListener);
1313
+ };
1314
+ MDCList.prototype.layout = function () {
1315
+ var direction = this.root.getAttribute(strings.ARIA_ORIENTATION);
1316
+ this.vertical = direction !== strings.ARIA_ORIENTATION_HORIZONTAL;
1317
+ var itemSelector = "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ":not([tabindex])";
1318
+ var childSelector = strings.FOCUSABLE_CHILD_ELEMENTS;
1319
+ // List items need to have at least tabindex=-1 to be focusable.
1320
+ var itemEls = this.root.querySelectorAll(itemSelector);
1321
+ if (itemEls.length) {
1322
+ Array.prototype.forEach.call(itemEls, function (el) {
1323
+ el.setAttribute('tabindex', '-1');
1324
+ });
1325
+ }
1326
+ // Child button/a elements are not tabbable until the list item is focused.
1327
+ var focusableChildEls = this.root.querySelectorAll(childSelector);
1328
+ if (focusableChildEls.length) {
1329
+ Array.prototype.forEach.call(focusableChildEls, function (el) {
1330
+ el.setAttribute('tabindex', '-1');
1331
+ });
1332
+ }
1333
+ if (this.isEvolutionEnabled) {
1334
+ this.foundation.setUseSelectedAttribute(true);
1335
+ }
1336
+ this.foundation.layout();
1337
+ };
1338
+ /**
1339
+ * Extracts the primary text from a list item.
1340
+ * @param item The list item element.
1341
+ * @return The primary text in the element.
1342
+ */
1343
+ MDCList.prototype.getPrimaryText = function (item) {
1344
+ var _a;
1345
+ var primaryText = item.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS]);
1346
+ if (this.isEvolutionEnabled || primaryText) {
1347
+ return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : '';
1348
+ }
1349
+ var singleLineText = item.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_TEXT_CLASS]);
1350
+ return (singleLineText && singleLineText.textContent) || '';
1351
+ };
1352
+ /**
1353
+ * Initialize selectedIndex value based on pre-selected list items.
1354
+ */
1355
+ MDCList.prototype.initializeListType = function () {
1356
+ var _this = this;
1357
+ this.isInteractive =
1358
+ ponyfill.matches(this.root, strings.ARIA_INTERACTIVE_ROLES_SELECTOR);
1359
+ if (this.isEvolutionEnabled && this.isInteractive) {
1360
+ var selection = Array.from(this.root.querySelectorAll(strings.SELECTED_ITEM_SELECTOR), function (listItem) { return _this.listElements.indexOf(listItem); });
1361
+ if (ponyfill.matches(this.root, strings.ARIA_MULTI_SELECTABLE_SELECTOR)) {
1362
+ this.selectedIndex = selection;
1363
+ }
1364
+ else if (selection.length > 0) {
1365
+ this.selectedIndex = selection[0];
1366
+ }
1367
+ return;
1368
+ }
1369
+ var checkboxListItems = this.root.querySelectorAll(strings.ARIA_ROLE_CHECKBOX_SELECTOR);
1370
+ var radioSelectedListItem = this.root.querySelector(strings.ARIA_CHECKED_RADIO_SELECTOR);
1371
+ if (checkboxListItems.length) {
1372
+ var preselectedItems = this.root.querySelectorAll(strings.ARIA_CHECKED_CHECKBOX_SELECTOR);
1373
+ this.selectedIndex = Array.from(preselectedItems, function (listItem) { return _this.listElements.indexOf(listItem); });
1374
+ }
1375
+ else if (radioSelectedListItem) {
1376
+ this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
1377
+ }
1378
+ };
1379
+ /**
1380
+ * Updates the list item at itemIndex to the desired isEnabled state.
1381
+ * @param itemIndex Index of the list item
1382
+ * @param isEnabled Sets the list item to enabled or disabled.
1383
+ */
1384
+ MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
1385
+ this.foundation.setEnabled(itemIndex, isEnabled);
1386
+ };
1387
+ /**
1388
+ * Given the next desired character from the user, adds it to the typeahead
1389
+ * buffer. Then, attempts to find the next option matching the buffer. Wraps
1390
+ * around if at the end of options.
1391
+ *
1392
+ * @param nextChar The next character to add to the prefix buffer.
1393
+ * @param startingIndex The index from which to start matching. Defaults to
1394
+ * the currently focused index.
1395
+ * @return The index of the matched item.
1396
+ */
1397
+ MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
1398
+ return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */ true);
1399
+ };
1400
+ MDCList.prototype.getDefaultFoundation = function () {
1401
+ var _this = this;
1402
+ // DO NOT INLINE this variable. For backward compatibility, foundations take
1403
+ // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
1404
+ // methods, we need a separate, strongly typed adapter variable.
1405
+ var adapter = {
1406
+ addClassForElementIndex: function (index, className) {
1407
+ var element = _this.listElements[index];
1408
+ if (element) {
1409
+ element.classList.add(_this.classNameMap[className]);
1410
+ }
1411
+ },
1412
+ focusItemAtIndex: function (index) {
1413
+ var element = _this.listElements[index];
1414
+ if (element) {
1415
+ element.focus();
1416
+ }
1417
+ },
1418
+ getAttributeForElementIndex: function (index, attr) {
1419
+ return _this.listElements[index].getAttribute(attr);
1420
+ },
1421
+ getFocusedElementIndex: function () {
1422
+ return _this.listElements.indexOf(document.activeElement);
1423
+ },
1424
+ getListItemCount: function () { return _this.listElements.length; },
1425
+ getPrimaryTextAtIndex: function (index) {
1426
+ return _this.getPrimaryText(_this.listElements[index]);
1427
+ },
1428
+ hasCheckboxAtIndex: function (index) {
1429
+ var listItem = _this.listElements[index];
1430
+ return !!listItem.querySelector(strings.CHECKBOX_SELECTOR);
1431
+ },
1432
+ hasRadioAtIndex: function (index) {
1433
+ var listItem = _this.listElements[index];
1434
+ return !!listItem.querySelector(strings.RADIO_SELECTOR);
1435
+ },
1436
+ isCheckboxCheckedAtIndex: function (index) {
1437
+ var listItem = _this.listElements[index];
1438
+ var toggleEl = listItem.querySelector(strings.CHECKBOX_SELECTOR);
1439
+ return toggleEl.checked;
1440
+ },
1441
+ isFocusInsideList: function () {
1442
+ return _this.root !== document.activeElement &&
1443
+ _this.root.contains(document.activeElement);
1444
+ },
1445
+ isRootFocused: function () { return document.activeElement === _this.root; },
1446
+ listItemAtIndexHasClass: function (index, className) {
1447
+ return _this.listElements[index].classList.contains(_this.classNameMap[className]);
1448
+ },
1449
+ notifyAction: function (index) {
1450
+ _this.emit(strings.ACTION_EVENT, { index: index }, /** shouldBubble */ true);
1451
+ },
1452
+ removeClassForElementIndex: function (index, className) {
1453
+ var element = _this.listElements[index];
1454
+ if (element) {
1455
+ element.classList.remove(_this.classNameMap[className]);
1456
+ }
1457
+ },
1458
+ setAttributeForElementIndex: function (index, attr, value) {
1459
+ var element = _this.listElements[index];
1460
+ if (element) {
1461
+ element.setAttribute(attr, value);
1462
+ }
1463
+ },
1464
+ setCheckedCheckboxOrRadioAtIndex: function (index, isChecked) {
1465
+ var listItem = _this.listElements[index];
1466
+ var toggleEl = listItem.querySelector(strings.CHECKBOX_RADIO_SELECTOR);
1467
+ toggleEl.checked = isChecked;
1468
+ var event = document.createEvent('Event');
1469
+ event.initEvent('change', true, true);
1470
+ toggleEl.dispatchEvent(event);
1471
+ },
1472
+ setTabIndexForListItemChildren: function (listItemIndex, tabIndexValue) {
1473
+ var element = _this.listElements[listItemIndex];
1474
+ var selector = strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX;
1475
+ Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) {
1476
+ el.setAttribute('tabindex', tabIndexValue);
1477
+ });
1478
+ },
1479
+ };
1480
+ return new MDCListFoundation(adapter);
1481
+ };
1482
+ /**
1483
+ * Ensures that at least one item is focusable if the list is interactive and
1484
+ * doesn't specify a suitable tabindex.
1485
+ */
1486
+ MDCList.prototype.ensureFocusable = function () {
1487
+ if (this.isEvolutionEnabled && this.isInteractive) {
1488
+ if (!this.root.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) {
1489
+ var index = this.initialFocusIndex();
1490
+ if (index !== -1) {
1491
+ this.listElements[index].tabIndex = 0;
1492
+ }
1493
+ }
1494
+ }
1495
+ };
1496
+ MDCList.prototype.initialFocusIndex = function () {
1497
+ if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) {
1498
+ return this.selectedIndex[0];
1499
+ }
1500
+ if (typeof this.selectedIndex === 'number' &&
1501
+ this.selectedIndex !== numbers.UNSET_INDEX) {
1502
+ return this.selectedIndex;
1503
+ }
1504
+ var el = this.root.querySelector("." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[cssClasses.LIST_ITEM_DISABLED_CLASS] + ")");
1505
+ if (el === null) {
1506
+ return -1;
1507
+ }
1508
+ return this.getListItemIndex(el);
1509
+ };
1510
+ /**
1511
+ * Used to figure out which list item this event is targetting. Or returns -1
1512
+ * if there is no list item
1513
+ */
1514
+ MDCList.prototype.getListItemIndex = function (el) {
1515
+ var nearestParent = ponyfill.closest(el, "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS] + ", ." + this.classNameMap[cssClasses.ROOT]);
1516
+ // Get the index of the element if it is a list item.
1517
+ if (nearestParent &&
1518
+ ponyfill.matches(nearestParent, "." + this.classNameMap[cssClasses.LIST_ITEM_CLASS])) {
1519
+ return this.listElements.indexOf(nearestParent);
1520
+ }
1521
+ return -1;
1522
+ };
1523
+ /**
1524
+ * Used to figure out which element was clicked before sending the event to
1525
+ * the foundation.
1526
+ */
1527
+ MDCList.prototype.handleFocusInEvent = function (evt) {
1528
+ var index = this.getListItemIndex(evt.target);
1529
+ this.foundation.handleFocusIn(evt, index);
1530
+ };
1531
+ /**
1532
+ * Used to figure out which element was clicked before sending the event to
1533
+ * the foundation.
1534
+ */
1535
+ MDCList.prototype.handleFocusOutEvent = function (evt) {
1536
+ var index = this.getListItemIndex(evt.target);
1537
+ this.foundation.handleFocusOut(evt, index);
1538
+ };
1539
+ /**
1540
+ * Used to figure out which element was focused when keydown event occurred
1541
+ * before sending the event to the foundation.
1542
+ */
1543
+ MDCList.prototype.handleKeydownEvent = function (evt) {
1544
+ var index = this.getListItemIndex(evt.target);
1545
+ var target = evt.target;
1546
+ this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[cssClasses.LIST_ITEM_CLASS]), index);
1547
+ };
1548
+ /**
1549
+ * Used to figure out which element was clicked before sending the event to
1550
+ * the foundation.
1551
+ */
1552
+ MDCList.prototype.handleClickEvent = function (evt) {
1553
+ var index = this.getListItemIndex(evt.target);
1554
+ var target = evt.target;
1555
+ // Toggle the checkbox only if it's not the target of the event, or the
1556
+ // checkbox will have 2 change events.
1557
+ var toggleCheckbox = !ponyfill.matches(target, strings.CHECKBOX_RADIO_SELECTOR);
1558
+ this.foundation.handleClick(index, toggleCheckbox);
1559
+ };
1560
+ return MDCList;
1561
+ }(component.MDCComponent));
1562
+
1563
+ /*! *****************************************************************************
1564
+ Copyright (c) Microsoft Corporation.
1565
+
1566
+ Permission to use, copy, modify, and/or distribute this software for any
1567
+ purpose with or without fee is hereby granted.
1568
+
1569
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1570
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1571
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1572
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1573
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1574
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1575
+ PERFORMANCE OF THIS SOFTWARE.
1576
+ ***************************************************************************** */
1577
+ /* global Reflect, Promise */
1578
+
1579
+ var extendStatics = function(d, b) {
1580
+ extendStatics = Object.setPrototypeOf ||
1581
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1582
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1583
+ return extendStatics(d, b);
1584
+ };
1585
+
1586
+ function __extends(d, b) {
1587
+ if (typeof b !== "function" && b !== null)
1588
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1589
+ extendStatics(d, b);
1590
+ function __() { this.constructor = d; }
1591
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1592
+ }
1593
+
1594
+ var __assign = function() {
1595
+ __assign = Object.assign || function __assign(t) {
1596
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1597
+ s = arguments[i];
1598
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1599
+ }
1600
+ return t;
1601
+ };
1602
+ return __assign.apply(this, arguments);
1603
+ };
1604
+
1605
+ function __values(o) {
1606
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1607
+ if (m) return m.call(o);
1608
+ if (o && typeof o.length === "number") return {
1609
+ next: function () {
1610
+ if (o && i >= o.length) o = void 0;
1611
+ return { value: o && o[i++], done: !o };
1612
+ }
1613
+ };
1614
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1615
+ }
1616
+
1617
+ /**
1618
+ * @license
1619
+ * Copyright 2018 Google Inc.
1620
+ *
1621
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1622
+ * of this software and associated documentation files (the "Software"), to deal
1623
+ * in the Software without restriction, including without limitation the rights
1624
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1625
+ * copies of the Software, and to permit persons to whom the Software is
1626
+ * furnished to do so, subject to the following conditions:
1627
+ *
1628
+ * The above copyright notice and this permission notice shall be included in
1629
+ * all copies or substantial portions of the Software.
1630
+ *
1631
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1632
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1633
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1634
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1635
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1636
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1637
+ * THE SOFTWARE.
1638
+ */
1639
+ var MDCMenuSurfaceFoundation = /** @class */ (function (_super) {
1640
+ __extends(MDCMenuSurfaceFoundation, _super);
1641
+ function MDCMenuSurfaceFoundation(adapter) {
1642
+ var _this = _super.call(this, __assign(__assign({}, MDCMenuSurfaceFoundation.defaultAdapter), adapter)) || this;
1643
+ _this.isSurfaceOpen = false;
1644
+ _this.isQuickOpen = false;
1645
+ _this.isHoistedElement = false;
1646
+ _this.isFixedPosition = false;
1647
+ _this.isHorizontallyCenteredOnViewport = false;
1648
+ _this.maxHeight = 0;
1649
+ _this.openAnimationEndTimerId = 0;
1650
+ _this.closeAnimationEndTimerId = 0;
1651
+ _this.animationRequestId = 0;
1652
+ _this.anchorCorner = exports.Corner.TOP_START;
1653
+ /**
1654
+ * Corner of the menu surface to which menu surface is attached to anchor.
1655
+ *
1656
+ * Anchor corner --->+----------+
1657
+ * | ANCHOR |
1658
+ * +----------+
1659
+ * Origin corner --->+--------------+
1660
+ * | |
1661
+ * | |
1662
+ * | MENU SURFACE |
1663
+ * | |
1664
+ * | |
1665
+ * +--------------+
1666
+ */
1667
+ _this.originCorner = exports.Corner.TOP_START;
1668
+ _this.anchorMargin = { top: 0, right: 0, bottom: 0, left: 0 };
1669
+ _this.position = { x: 0, y: 0 };
1670
+ return _this;
1671
+ }
1672
+ Object.defineProperty(MDCMenuSurfaceFoundation, "cssClasses", {
1673
+ get: function () {
1674
+ return cssClasses$1;
1675
+ },
1676
+ enumerable: false,
1677
+ configurable: true
1678
+ });
1679
+ Object.defineProperty(MDCMenuSurfaceFoundation, "strings", {
1680
+ get: function () {
1681
+ return strings$1;
1682
+ },
1683
+ enumerable: false,
1684
+ configurable: true
1685
+ });
1686
+ Object.defineProperty(MDCMenuSurfaceFoundation, "numbers", {
1687
+ get: function () {
1688
+ return numbers$1;
1689
+ },
1690
+ enumerable: false,
1691
+ configurable: true
1692
+ });
1693
+ Object.defineProperty(MDCMenuSurfaceFoundation, "Corner", {
1694
+ get: function () {
1695
+ return exports.Corner;
1696
+ },
1697
+ enumerable: false,
1698
+ configurable: true
1699
+ });
1700
+ Object.defineProperty(MDCMenuSurfaceFoundation, "defaultAdapter", {
1701
+ /**
1702
+ * @see {@link MDCMenuSurfaceAdapter} for typing information on parameters and return types.
1703
+ */
1704
+ get: function () {
1705
+ // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
1706
+ return {
1707
+ addClass: function () { return undefined; },
1708
+ removeClass: function () { return undefined; },
1709
+ hasClass: function () { return false; },
1710
+ hasAnchor: function () { return false; },
1711
+ isElementInContainer: function () { return false; },
1712
+ isFocused: function () { return false; },
1713
+ isRtl: function () { return false; },
1714
+ getInnerDimensions: function () { return ({ height: 0, width: 0 }); },
1715
+ getAnchorDimensions: function () { return null; },
1716
+ getWindowDimensions: function () { return ({ height: 0, width: 0 }); },
1717
+ getBodyDimensions: function () { return ({ height: 0, width: 0 }); },
1718
+ getWindowScroll: function () { return ({ x: 0, y: 0 }); },
1719
+ setPosition: function () { return undefined; },
1720
+ setMaxHeight: function () { return undefined; },
1721
+ setTransformOrigin: function () { return undefined; },
1722
+ saveFocus: function () { return undefined; },
1723
+ restoreFocus: function () { return undefined; },
1724
+ notifyClose: function () { return undefined; },
1725
+ notifyOpen: function () { return undefined; },
1726
+ notifyClosing: function () { return undefined; },
1727
+ };
1728
+ // tslint:enable:object-literal-sort-keys
1729
+ },
1730
+ enumerable: false,
1731
+ configurable: true
1732
+ });
1733
+ MDCMenuSurfaceFoundation.prototype.init = function () {
1734
+ var _a = MDCMenuSurfaceFoundation.cssClasses, ROOT = _a.ROOT, OPEN = _a.OPEN;
1735
+ if (!this.adapter.hasClass(ROOT)) {
1736
+ throw new Error(ROOT + " class required in root element.");
1737
+ }
1738
+ if (this.adapter.hasClass(OPEN)) {
1739
+ this.isSurfaceOpen = true;
1740
+ }
1741
+ };
1742
+ MDCMenuSurfaceFoundation.prototype.destroy = function () {
1743
+ clearTimeout(this.openAnimationEndTimerId);
1744
+ clearTimeout(this.closeAnimationEndTimerId);
1745
+ // Cancel any currently running animations.
1746
+ cancelAnimationFrame(this.animationRequestId);
1747
+ };
1748
+ /**
1749
+ * @param corner Default anchor corner alignment of top-left menu surface corner.
1750
+ */
1751
+ MDCMenuSurfaceFoundation.prototype.setAnchorCorner = function (corner) {
1752
+ this.anchorCorner = corner;
1753
+ };
1754
+ /**
1755
+ * Flip menu corner horizontally.
1756
+ */
1757
+ MDCMenuSurfaceFoundation.prototype.flipCornerHorizontally = function () {
1758
+ this.originCorner = this.originCorner ^ CornerBit.RIGHT;
1759
+ };
1760
+ /**
1761
+ * @param margin Set of margin values from anchor.
1762
+ */
1763
+ MDCMenuSurfaceFoundation.prototype.setAnchorMargin = function (margin) {
1764
+ this.anchorMargin.top = margin.top || 0;
1765
+ this.anchorMargin.right = margin.right || 0;
1766
+ this.anchorMargin.bottom = margin.bottom || 0;
1767
+ this.anchorMargin.left = margin.left || 0;
1768
+ };
1769
+ /** Used to indicate if the menu-surface is hoisted to the body. */
1770
+ MDCMenuSurfaceFoundation.prototype.setIsHoisted = function (isHoisted) {
1771
+ this.isHoistedElement = isHoisted;
1772
+ };
1773
+ /** Used to set the menu-surface calculations based on a fixed position menu. */
1774
+ MDCMenuSurfaceFoundation.prototype.setFixedPosition = function (isFixedPosition) {
1775
+ this.isFixedPosition = isFixedPosition;
1776
+ };
1777
+ /** Sets the menu-surface position on the page. */
1778
+ MDCMenuSurfaceFoundation.prototype.setAbsolutePosition = function (x, y) {
1779
+ this.position.x = this.isFinite(x) ? x : 0;
1780
+ this.position.y = this.isFinite(y) ? y : 0;
1781
+ };
1782
+ /** Sets whether menu-surface should be horizontally centered to viewport. */
1783
+ MDCMenuSurfaceFoundation.prototype.setIsHorizontallyCenteredOnViewport = function (isCentered) {
1784
+ this.isHorizontallyCenteredOnViewport = isCentered;
1785
+ };
1786
+ MDCMenuSurfaceFoundation.prototype.setQuickOpen = function (quickOpen) {
1787
+ this.isQuickOpen = quickOpen;
1788
+ };
1789
+ /**
1790
+ * Sets maximum menu-surface height on open.
1791
+ * @param maxHeight The desired max-height. Set to 0 (default) to
1792
+ * automatically calculate max height based on available viewport space.
1793
+ */
1794
+ MDCMenuSurfaceFoundation.prototype.setMaxHeight = function (maxHeight) {
1795
+ this.maxHeight = maxHeight;
1796
+ };
1797
+ MDCMenuSurfaceFoundation.prototype.isOpen = function () {
1798
+ return this.isSurfaceOpen;
1799
+ };
1800
+ /**
1801
+ * Open the menu surface.
1802
+ */
1803
+ MDCMenuSurfaceFoundation.prototype.open = function () {
1804
+ var _this = this;
1805
+ if (this.isSurfaceOpen) {
1806
+ return;
1807
+ }
1808
+ this.adapter.saveFocus();
1809
+ if (this.isQuickOpen) {
1810
+ this.isSurfaceOpen = true;
1811
+ this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1812
+ this.dimensions = this.adapter.getInnerDimensions();
1813
+ this.autoposition();
1814
+ this.adapter.notifyOpen();
1815
+ }
1816
+ else {
1817
+ this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_OPEN);
1818
+ this.animationRequestId = requestAnimationFrame(function () {
1819
+ _this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1820
+ _this.dimensions = _this.adapter.getInnerDimensions();
1821
+ _this.autoposition();
1822
+ _this.openAnimationEndTimerId = setTimeout(function () {
1823
+ _this.openAnimationEndTimerId = 0;
1824
+ _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_OPEN);
1825
+ _this.adapter.notifyOpen();
1826
+ }, numbers$1.TRANSITION_OPEN_DURATION);
1827
+ });
1828
+ this.isSurfaceOpen = true;
1829
+ }
1830
+ };
1831
+ /**
1832
+ * Closes the menu surface.
1833
+ */
1834
+ MDCMenuSurfaceFoundation.prototype.close = function (skipRestoreFocus) {
1835
+ var _this = this;
1836
+ if (skipRestoreFocus === void 0) { skipRestoreFocus = false; }
1837
+ if (!this.isSurfaceOpen) {
1838
+ return;
1839
+ }
1840
+ this.adapter.notifyClosing();
1841
+ if (this.isQuickOpen) {
1842
+ this.isSurfaceOpen = false;
1843
+ if (!skipRestoreFocus) {
1844
+ this.maybeRestoreFocus();
1845
+ }
1846
+ this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1847
+ this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
1848
+ this.adapter.notifyClose();
1849
+ return;
1850
+ }
1851
+ this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_CLOSED);
1852
+ requestAnimationFrame(function () {
1853
+ _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.OPEN);
1854
+ _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
1855
+ _this.closeAnimationEndTimerId = setTimeout(function () {
1856
+ _this.closeAnimationEndTimerId = 0;
1857
+ _this.adapter.removeClass(MDCMenuSurfaceFoundation.cssClasses.ANIMATING_CLOSED);
1858
+ _this.adapter.notifyClose();
1859
+ }, numbers$1.TRANSITION_CLOSE_DURATION);
1860
+ });
1861
+ this.isSurfaceOpen = false;
1862
+ if (!skipRestoreFocus) {
1863
+ this.maybeRestoreFocus();
1864
+ }
1865
+ };
1866
+ /** Handle clicks and close if not within menu-surface element. */
1867
+ MDCMenuSurfaceFoundation.prototype.handleBodyClick = function (evt) {
1868
+ var el = evt.target;
1869
+ if (this.adapter.isElementInContainer(el)) {
1870
+ return;
1871
+ }
1872
+ this.close();
1873
+ };
1874
+ /** Handle keys that close the surface. */
1875
+ MDCMenuSurfaceFoundation.prototype.handleKeydown = function (evt) {
1876
+ var keyCode = evt.keyCode, key = evt.key;
1877
+ var isEscape = key === 'Escape' || keyCode === 27;
1878
+ if (isEscape) {
1879
+ this.close();
1880
+ }
1881
+ };
1882
+ MDCMenuSurfaceFoundation.prototype.autoposition = function () {
1883
+ var _a;
1884
+ // Compute measurements for autoposition methods reuse.
1885
+ this.measurements = this.getAutoLayoutmeasurements();
1886
+ var corner = this.getoriginCorner();
1887
+ var maxMenuSurfaceHeight = this.getMenuSurfaceMaxHeight(corner);
1888
+ var verticalAlignment = this.hasBit(corner, CornerBit.BOTTOM) ? 'bottom' : 'top';
1889
+ var horizontalAlignment = this.hasBit(corner, CornerBit.RIGHT) ? 'right' : 'left';
1890
+ var horizontalOffset = this.getHorizontalOriginOffset(corner);
1891
+ var verticalOffset = this.getVerticalOriginOffset(corner);
1892
+ var _b = this.measurements, anchorSize = _b.anchorSize, surfaceSize = _b.surfaceSize;
1893
+ var position = (_a = {},
1894
+ _a[horizontalAlignment] = horizontalOffset,
1895
+ _a[verticalAlignment] = verticalOffset,
1896
+ _a);
1897
+ // Center align when anchor width is comparable or greater than menu surface, otherwise keep corner.
1898
+ if (anchorSize.width / surfaceSize.width > numbers$1.ANCHOR_TO_MENU_SURFACE_WIDTH_RATIO) {
1899
+ horizontalAlignment = 'center';
1900
+ }
1901
+ // If the menu-surface has been hoisted to the body, it's no longer relative to the anchor element
1902
+ if (this.isHoistedElement || this.isFixedPosition) {
1903
+ this.adjustPositionForHoistedElement(position);
1904
+ }
1905
+ this.adapter.setTransformOrigin(horizontalAlignment + " " + verticalAlignment);
1906
+ this.adapter.setPosition(position);
1907
+ this.adapter.setMaxHeight(maxMenuSurfaceHeight ? maxMenuSurfaceHeight + 'px' : '');
1908
+ // If it is opened from the top then add is-open-below class
1909
+ if (!this.hasBit(corner, CornerBit.BOTTOM)) {
1910
+ this.adapter.addClass(MDCMenuSurfaceFoundation.cssClasses.IS_OPEN_BELOW);
1911
+ }
1912
+ };
1913
+ /**
1914
+ * @return Measurements used to position menu surface popup.
1915
+ */
1916
+ MDCMenuSurfaceFoundation.prototype.getAutoLayoutmeasurements = function () {
1917
+ var anchorRect = this.adapter.getAnchorDimensions();
1918
+ var bodySize = this.adapter.getBodyDimensions();
1919
+ var viewportSize = this.adapter.getWindowDimensions();
1920
+ var windowScroll = this.adapter.getWindowScroll();
1921
+ if (!anchorRect) {
1922
+ // tslint:disable:object-literal-sort-keys Positional properties are more readable when they're grouped together
1923
+ anchorRect = {
1924
+ top: this.position.y,
1925
+ right: this.position.x,
1926
+ bottom: this.position.y,
1927
+ left: this.position.x,
1928
+ width: 0,
1929
+ height: 0,
1930
+ };
1931
+ // tslint:enable:object-literal-sort-keys
1932
+ }
1933
+ return {
1934
+ anchorSize: anchorRect,
1935
+ bodySize: bodySize,
1936
+ surfaceSize: this.dimensions,
1937
+ viewportDistance: {
1938
+ // tslint:disable:object-literal-sort-keys Positional properties are more readable when they're grouped together
1939
+ top: anchorRect.top,
1940
+ right: viewportSize.width - anchorRect.right,
1941
+ bottom: viewportSize.height - anchorRect.bottom,
1942
+ left: anchorRect.left,
1943
+ // tslint:enable:object-literal-sort-keys
1944
+ },
1945
+ viewportSize: viewportSize,
1946
+ windowScroll: windowScroll,
1947
+ };
1948
+ };
1949
+ /**
1950
+ * Computes the corner of the anchor from which to animate and position the
1951
+ * menu surface.
1952
+ *
1953
+ * Only LEFT or RIGHT bit is used to position the menu surface ignoring RTL
1954
+ * context. E.g., menu surface will be positioned from right side on TOP_END.
1955
+ */
1956
+ MDCMenuSurfaceFoundation.prototype.getoriginCorner = function () {
1957
+ var corner = this.originCorner;
1958
+ var _a = this.measurements, viewportDistance = _a.viewportDistance, anchorSize = _a.anchorSize, surfaceSize = _a.surfaceSize;
1959
+ var MARGIN_TO_EDGE = MDCMenuSurfaceFoundation.numbers.MARGIN_TO_EDGE;
1960
+ var isAnchoredToBottom = this.hasBit(this.anchorCorner, CornerBit.BOTTOM);
1961
+ var availableTop;
1962
+ var availableBottom;
1963
+ if (isAnchoredToBottom) {
1964
+ availableTop =
1965
+ viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.bottom;
1966
+ availableBottom =
1967
+ viewportDistance.bottom - MARGIN_TO_EDGE - this.anchorMargin.bottom;
1968
+ }
1969
+ else {
1970
+ availableTop =
1971
+ viewportDistance.top - MARGIN_TO_EDGE + this.anchorMargin.top;
1972
+ availableBottom = viewportDistance.bottom - MARGIN_TO_EDGE +
1973
+ anchorSize.height - this.anchorMargin.top;
1974
+ }
1975
+ var isAvailableBottom = availableBottom - surfaceSize.height > 0;
1976
+ if (!isAvailableBottom && availableTop > availableBottom) {
1977
+ // Attach bottom side of surface to the anchor.
1978
+ corner = this.setBit(corner, CornerBit.BOTTOM);
1979
+ }
1980
+ var isRtl = this.adapter.isRtl();
1981
+ var isFlipRtl = this.hasBit(this.anchorCorner, CornerBit.FLIP_RTL);
1982
+ var hasRightBit = this.hasBit(this.anchorCorner, CornerBit.RIGHT) ||
1983
+ this.hasBit(corner, CornerBit.RIGHT);
1984
+ // Whether surface attached to right side of anchor element.
1985
+ var isAnchoredToRight = false;
1986
+ // Anchored to start
1987
+ if (isRtl && isFlipRtl) {
1988
+ isAnchoredToRight = !hasRightBit;
1989
+ }
1990
+ else {
1991
+ // Anchored to right
1992
+ isAnchoredToRight = hasRightBit;
1993
+ }
1994
+ var availableLeft;
1995
+ var availableRight;
1996
+ if (isAnchoredToRight) {
1997
+ availableLeft =
1998
+ viewportDistance.left + anchorSize.width + this.anchorMargin.right;
1999
+ availableRight = viewportDistance.right - this.anchorMargin.right;
2000
+ }
2001
+ else {
2002
+ availableLeft = viewportDistance.left + this.anchorMargin.left;
2003
+ availableRight =
2004
+ viewportDistance.right + anchorSize.width - this.anchorMargin.left;
2005
+ }
2006
+ var isAvailableLeft = availableLeft - surfaceSize.width > 0;
2007
+ var isAvailableRight = availableRight - surfaceSize.width > 0;
2008
+ var isOriginCornerAlignedToEnd = this.hasBit(corner, CornerBit.FLIP_RTL) &&
2009
+ this.hasBit(corner, CornerBit.RIGHT);
2010
+ if (isAvailableRight && isOriginCornerAlignedToEnd && isRtl ||
2011
+ !isAvailableLeft && isOriginCornerAlignedToEnd) {
2012
+ // Attach left side of surface to the anchor.
2013
+ corner = this.unsetBit(corner, CornerBit.RIGHT);
2014
+ }
2015
+ else if (isAvailableLeft && isAnchoredToRight && isRtl ||
2016
+ (isAvailableLeft && !isAnchoredToRight && hasRightBit) ||
2017
+ (!isAvailableRight && availableLeft >= availableRight)) {
2018
+ // Attach right side of surface to the anchor.
2019
+ corner = this.setBit(corner, CornerBit.RIGHT);
2020
+ }
2021
+ return corner;
2022
+ };
2023
+ /**
2024
+ * @param corner Origin corner of the menu surface.
2025
+ * @return Maximum height of the menu surface, based on available space. 0 indicates should not be set.
2026
+ */
2027
+ MDCMenuSurfaceFoundation.prototype.getMenuSurfaceMaxHeight = function (corner) {
2028
+ if (this.maxHeight > 0) {
2029
+ return this.maxHeight;
2030
+ }
2031
+ var viewportDistance = this.measurements.viewportDistance;
2032
+ var maxHeight = 0;
2033
+ var isBottomAligned = this.hasBit(corner, CornerBit.BOTTOM);
2034
+ var isBottomAnchored = this.hasBit(this.anchorCorner, CornerBit.BOTTOM);
2035
+ var MARGIN_TO_EDGE = MDCMenuSurfaceFoundation.numbers.MARGIN_TO_EDGE;
2036
+ // When maximum height is not specified, it is handled from CSS.
2037
+ if (isBottomAligned) {
2038
+ maxHeight = viewportDistance.top + this.anchorMargin.top - MARGIN_TO_EDGE;
2039
+ if (!isBottomAnchored) {
2040
+ maxHeight += this.measurements.anchorSize.height;
2041
+ }
2042
+ }
2043
+ else {
2044
+ maxHeight = viewportDistance.bottom - this.anchorMargin.bottom +
2045
+ this.measurements.anchorSize.height - MARGIN_TO_EDGE;
2046
+ if (isBottomAnchored) {
2047
+ maxHeight -= this.measurements.anchorSize.height;
2048
+ }
2049
+ }
2050
+ return maxHeight;
2051
+ };
2052
+ /**
2053
+ * @param corner Origin corner of the menu surface.
2054
+ * @return Horizontal offset of menu surface origin corner from corresponding anchor corner.
2055
+ */
2056
+ MDCMenuSurfaceFoundation.prototype.getHorizontalOriginOffset = function (corner) {
2057
+ var anchorSize = this.measurements.anchorSize;
2058
+ // isRightAligned corresponds to using the 'right' property on the surface.
2059
+ var isRightAligned = this.hasBit(corner, CornerBit.RIGHT);
2060
+ var avoidHorizontalOverlap = this.hasBit(this.anchorCorner, CornerBit.RIGHT);
2061
+ if (isRightAligned) {
2062
+ var rightOffset = avoidHorizontalOverlap ?
2063
+ anchorSize.width - this.anchorMargin.left :
2064
+ this.anchorMargin.right;
2065
+ // For hoisted or fixed elements, adjust the offset by the difference
2066
+ // between viewport width and body width so when we calculate the right
2067
+ // value (`adjustPositionForHoistedElement`) based on the element
2068
+ // position, the right property is correct.
2069
+ if (this.isHoistedElement || this.isFixedPosition) {
2070
+ return rightOffset -
2071
+ (this.measurements.viewportSize.width -
2072
+ this.measurements.bodySize.width);
2073
+ }
2074
+ return rightOffset;
2075
+ }
2076
+ return avoidHorizontalOverlap ? anchorSize.width - this.anchorMargin.right :
2077
+ this.anchorMargin.left;
2078
+ };
2079
+ /**
2080
+ * @param corner Origin corner of the menu surface.
2081
+ * @return Vertical offset of menu surface origin corner from corresponding anchor corner.
2082
+ */
2083
+ MDCMenuSurfaceFoundation.prototype.getVerticalOriginOffset = function (corner) {
2084
+ var anchorSize = this.measurements.anchorSize;
2085
+ var isBottomAligned = this.hasBit(corner, CornerBit.BOTTOM);
2086
+ var avoidVerticalOverlap = this.hasBit(this.anchorCorner, CornerBit.BOTTOM);
2087
+ var y = 0;
2088
+ if (isBottomAligned) {
2089
+ y = avoidVerticalOverlap ? anchorSize.height - this.anchorMargin.top :
2090
+ -this.anchorMargin.bottom;
2091
+ }
2092
+ else {
2093
+ y = avoidVerticalOverlap ?
2094
+ (anchorSize.height + this.anchorMargin.bottom) :
2095
+ this.anchorMargin.top;
2096
+ }
2097
+ return y;
2098
+ };
2099
+ /** Calculates the offsets for positioning the menu-surface when the menu-surface has been hoisted to the body. */
2100
+ MDCMenuSurfaceFoundation.prototype.adjustPositionForHoistedElement = function (position) {
2101
+ var e_1, _a;
2102
+ var _b = this.measurements, windowScroll = _b.windowScroll, viewportDistance = _b.viewportDistance, surfaceSize = _b.surfaceSize, viewportSize = _b.viewportSize;
2103
+ var props = Object.keys(position);
2104
+ try {
2105
+ for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
2106
+ var prop = props_1_1.value;
2107
+ var value = position[prop] || 0;
2108
+ if (this.isHorizontallyCenteredOnViewport &&
2109
+ (prop === 'left' || prop === 'right')) {
2110
+ position[prop] = (viewportSize.width - surfaceSize.width) / 2;
2111
+ continue;
2112
+ }
2113
+ // Hoisted surfaces need to have the anchor elements location on the page added to the
2114
+ // position properties for proper alignment on the body.
2115
+ value += viewportDistance[prop];
2116
+ // Surfaces that are absolutely positioned need to have additional calculations for scroll
2117
+ // and bottom positioning.
2118
+ if (!this.isFixedPosition) {
2119
+ if (prop === 'top') {
2120
+ value += windowScroll.y;
2121
+ }
2122
+ else if (prop === 'bottom') {
2123
+ value -= windowScroll.y;
2124
+ }
2125
+ else if (prop === 'left') {
2126
+ value += windowScroll.x;
2127
+ }
2128
+ else { // prop === 'right'
2129
+ value -= windowScroll.x;
2130
+ }
2131
+ }
2132
+ position[prop] = value;
2133
+ }
2134
+ }
2135
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2136
+ finally {
2137
+ try {
2138
+ if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
2139
+ }
2140
+ finally { if (e_1) throw e_1.error; }
2141
+ }
2142
+ };
2143
+ /**
2144
+ * The last focused element when the menu surface was opened should regain focus, if the user is
2145
+ * focused on or within the menu surface when it is closed.
2146
+ */
2147
+ MDCMenuSurfaceFoundation.prototype.maybeRestoreFocus = function () {
2148
+ var isRootFocused = this.adapter.isFocused();
2149
+ var childHasFocus = document.activeElement &&
2150
+ this.adapter.isElementInContainer(document.activeElement);
2151
+ if (isRootFocused || childHasFocus) {
2152
+ this.adapter.restoreFocus();
2153
+ }
2154
+ };
2155
+ MDCMenuSurfaceFoundation.prototype.hasBit = function (corner, bit) {
2156
+ return Boolean(corner & bit); // tslint:disable-line:no-bitwise
2157
+ };
2158
+ MDCMenuSurfaceFoundation.prototype.setBit = function (corner, bit) {
2159
+ return corner | bit; // tslint:disable-line:no-bitwise
2160
+ };
2161
+ MDCMenuSurfaceFoundation.prototype.unsetBit = function (corner, bit) {
2162
+ return corner ^ bit;
2163
+ };
2164
+ /**
2165
+ * isFinite that doesn't force conversion to number type.
2166
+ * Equivalent to Number.isFinite in ES2015, which is not supported in IE.
2167
+ */
2168
+ MDCMenuSurfaceFoundation.prototype.isFinite = function (num) {
2169
+ return typeof num === 'number' && isFinite(num);
2170
+ };
2171
+ return MDCMenuSurfaceFoundation;
2172
+ }(component.MDCFoundation));
2173
+
2174
+ /**
2175
+ * @license
2176
+ * Copyright 2018 Google Inc.
2177
+ *
2178
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
2179
+ * of this software and associated documentation files (the "Software"), to deal
2180
+ * in the Software without restriction, including without limitation the rights
2181
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2182
+ * copies of the Software, and to permit persons to whom the Software is
2183
+ * furnished to do so, subject to the following conditions:
2184
+ *
2185
+ * The above copyright notice and this permission notice shall be included in
2186
+ * all copies or substantial portions of the Software.
2187
+ *
2188
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2189
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2190
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2191
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2192
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2193
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2194
+ * THE SOFTWARE.
2195
+ */
2196
+ var MDCMenuSurface = /** @class */ (function (_super) {
2197
+ __extends(MDCMenuSurface, _super);
2198
+ function MDCMenuSurface() {
2199
+ return _super !== null && _super.apply(this, arguments) || this;
2200
+ }
2201
+ MDCMenuSurface.attachTo = function (root) {
2202
+ return new MDCMenuSurface(root);
2203
+ };
2204
+ MDCMenuSurface.prototype.initialSyncWithDOM = function () {
2205
+ var _this = this;
2206
+ var parentEl = this.root.parentElement;
2207
+ this.anchorElement = parentEl && parentEl.classList.contains(cssClasses$1.ANCHOR) ? parentEl : null;
2208
+ if (this.root.classList.contains(cssClasses$1.FIXED)) {
2209
+ this.setFixedPosition(true);
2210
+ }
2211
+ this.handleKeydown = function (event) {
2212
+ _this.foundation.handleKeydown(event);
2213
+ };
2214
+ this.handleBodyClick = function (event) {
2215
+ _this.foundation.handleBodyClick(event);
2216
+ };
2217
+ // capture so that no race between handleBodyClick and quickOpen when
2218
+ // menusurface opened on button click which registers this listener
2219
+ this.registerBodyClickListener = function () {
2220
+ document.body.addEventListener('click', _this.handleBodyClick, { capture: true });
2221
+ };
2222
+ this.deregisterBodyClickListener = function () {
2223
+ document.body.removeEventListener('click', _this.handleBodyClick, { capture: true });
2224
+ };
2225
+ this.listen('keydown', this.handleKeydown);
2226
+ this.listen(strings$1.OPENED_EVENT, this.registerBodyClickListener);
2227
+ this.listen(strings$1.CLOSED_EVENT, this.deregisterBodyClickListener);
2228
+ };
2229
+ MDCMenuSurface.prototype.destroy = function () {
2230
+ this.unlisten('keydown', this.handleKeydown);
2231
+ this.unlisten(strings$1.OPENED_EVENT, this.registerBodyClickListener);
2232
+ this.unlisten(strings$1.CLOSED_EVENT, this.deregisterBodyClickListener);
2233
+ _super.prototype.destroy.call(this);
2234
+ };
2235
+ MDCMenuSurface.prototype.isOpen = function () {
2236
+ return this.foundation.isOpen();
2237
+ };
2238
+ MDCMenuSurface.prototype.open = function () {
2239
+ this.foundation.open();
2240
+ };
2241
+ MDCMenuSurface.prototype.close = function (skipRestoreFocus) {
2242
+ if (skipRestoreFocus === void 0) { skipRestoreFocus = false; }
2243
+ this.foundation.close(skipRestoreFocus);
2244
+ };
2245
+ Object.defineProperty(MDCMenuSurface.prototype, "quickOpen", {
2246
+ set: function (quickOpen) {
2247
+ this.foundation.setQuickOpen(quickOpen);
2248
+ },
2249
+ enumerable: false,
2250
+ configurable: true
2251
+ });
2252
+ /** Sets the foundation to use page offsets for an positioning when the menu is hoisted to the body. */
2253
+ MDCMenuSurface.prototype.setIsHoisted = function (isHoisted) {
2254
+ this.foundation.setIsHoisted(isHoisted);
2255
+ };
2256
+ /** Sets the element that the menu-surface is anchored to. */
2257
+ MDCMenuSurface.prototype.setMenuSurfaceAnchorElement = function (element) {
2258
+ this.anchorElement = element;
2259
+ };
2260
+ /** Sets the menu-surface to position: fixed. */
2261
+ MDCMenuSurface.prototype.setFixedPosition = function (isFixed) {
2262
+ if (isFixed) {
2263
+ this.root.classList.add(cssClasses$1.FIXED);
2264
+ }
2265
+ else {
2266
+ this.root.classList.remove(cssClasses$1.FIXED);
2267
+ }
2268
+ this.foundation.setFixedPosition(isFixed);
2269
+ };
2270
+ /** Sets the absolute x/y position to position based on. Requires the menu to be hoisted. */
2271
+ MDCMenuSurface.prototype.setAbsolutePosition = function (x, y) {
2272
+ this.foundation.setAbsolutePosition(x, y);
2273
+ this.setIsHoisted(true);
2274
+ };
2275
+ /**
2276
+ * @param corner Default anchor corner alignment of top-left surface corner.
2277
+ */
2278
+ MDCMenuSurface.prototype.setAnchorCorner = function (corner) {
2279
+ this.foundation.setAnchorCorner(corner);
2280
+ };
2281
+ MDCMenuSurface.prototype.setAnchorMargin = function (margin) {
2282
+ this.foundation.setAnchorMargin(margin);
2283
+ };
2284
+ MDCMenuSurface.prototype.getDefaultFoundation = function () {
2285
+ var _this = this;
2286
+ // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
2287
+ // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
2288
+ // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
2289
+ var adapter = {
2290
+ addClass: function (className) { return _this.root.classList.add(className); },
2291
+ removeClass: function (className) { return _this.root.classList.remove(className); },
2292
+ hasClass: function (className) { return _this.root.classList.contains(className); },
2293
+ hasAnchor: function () { return !!_this.anchorElement; },
2294
+ notifyClose: function () {
2295
+ return _this.emit(MDCMenuSurfaceFoundation.strings.CLOSED_EVENT, {});
2296
+ },
2297
+ notifyClosing: function () {
2298
+ _this.emit(MDCMenuSurfaceFoundation.strings.CLOSING_EVENT, {});
2299
+ },
2300
+ notifyOpen: function () {
2301
+ return _this.emit(MDCMenuSurfaceFoundation.strings.OPENED_EVENT, {});
2302
+ },
2303
+ isElementInContainer: function (el) { return _this.root.contains(el); },
2304
+ isRtl: function () {
2305
+ return getComputedStyle(_this.root).getPropertyValue('direction') === 'rtl';
2306
+ },
2307
+ setTransformOrigin: function (origin) {
2308
+ var propertyName = util.getCorrectPropertyName(window, 'transform') + "-origin";
2309
+ _this.root.style.setProperty(propertyName, origin);
2310
+ },
2311
+ isFocused: function () { return document.activeElement === _this.root; },
2312
+ saveFocus: function () {
2313
+ _this.previousFocus =
2314
+ document.activeElement;
2315
+ },
2316
+ restoreFocus: function () {
2317
+ if (_this.root.contains(document.activeElement)) {
2318
+ if (_this.previousFocus && _this.previousFocus.focus) {
2319
+ _this.previousFocus.focus();
2320
+ }
2321
+ }
2322
+ },
2323
+ getInnerDimensions: function () {
2324
+ return {
2325
+ width: _this.root.offsetWidth,
2326
+ height: _this.root.offsetHeight
2327
+ };
2328
+ },
2329
+ getAnchorDimensions: function () { return _this.anchorElement ?
2330
+ _this.anchorElement.getBoundingClientRect() :
2331
+ null; },
2332
+ getWindowDimensions: function () {
2333
+ return { width: window.innerWidth, height: window.innerHeight };
2334
+ },
2335
+ getBodyDimensions: function () {
2336
+ return { width: document.body.clientWidth, height: document.body.clientHeight };
2337
+ },
2338
+ getWindowScroll: function () {
2339
+ return { x: window.pageXOffset, y: window.pageYOffset };
2340
+ },
2341
+ setPosition: function (position) {
2342
+ var rootHTML = _this.root;
2343
+ rootHTML.style.left = 'left' in position ? position.left + "px" : '';
2344
+ rootHTML.style.right = 'right' in position ? position.right + "px" : '';
2345
+ rootHTML.style.top = 'top' in position ? position.top + "px" : '';
2346
+ rootHTML.style.bottom =
2347
+ 'bottom' in position ? position.bottom + "px" : '';
2348
+ },
2349
+ setMaxHeight: function (height) {
2350
+ _this.root.style.maxHeight = height;
2351
+ },
2352
+ };
2353
+ // tslint:enable:object-literal-sort-keys
2354
+ return new MDCMenuSurfaceFoundation(adapter);
2355
+ };
2356
+ return MDCMenuSurface;
2357
+ }(component.MDCComponent));
2358
+
2359
+ exports.MDCList = MDCList;
2360
+ exports.MDCListFoundation = MDCListFoundation;
2361
+ exports.MDCMenuSurface = MDCMenuSurface;
2362
+ exports.MDCMenuSurfaceFoundation = MDCMenuSurfaceFoundation;
2363
+ exports.cssClasses = cssClasses;
2364
+ exports.numbers = numbers;
2365
+ exports.strings = strings;