@everymatrix/general-registration 1.21.2 → 1.21.3

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.
@@ -1,266 +1,2176 @@
1
- import { i, r as registerStyles, N as TabindexMixin, l as FocusMixin, E as ElementMixin, T as ThemableMixin, C as ControllerMixin, P as PolymerElement, h as html, g as TooltipController } from './field-mixin.js';
1
+ import { o, i, d as dedupingMixin, u as usageStatistics, T as TabindexMixin, g as FocusMixin, P as PolymerElement, h as html } from './field-mixin.js';
2
2
  import { A as ActiveMixin } from './active-mixin.js';
3
3
 
4
- const button = i`
4
+ /**
5
+ * @license
6
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
7
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
8
+ */
9
+ function defineCustomElement(CustomElement) {
10
+ const defined = customElements.get(CustomElement.is);
11
+ if (!defined) {
12
+ customElements.define(CustomElement.is, CustomElement);
13
+ } else {
14
+ const definedVersion = defined.version;
15
+ if (definedVersion && CustomElement.version && definedVersion === CustomElement.version) {
16
+ // Just loading the same thing again
17
+ console.warn(`The component ${CustomElement.is} has been loaded twice`);
18
+ } else {
19
+ console.error(
20
+ `Tried to define ${CustomElement.is} version ${CustomElement.version} when version ${defined.version} is already in use. Something will probably break.`,
21
+ );
22
+ }
23
+ }
24
+ }
25
+
26
+ /**
27
+ * @license
28
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
29
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
30
+ */
31
+
32
+ /**
33
+ * Dummy custom element used for collecting
34
+ * development time usage statistics.
35
+ *
36
+ * @private
37
+ */
38
+ class Lumo extends HTMLElement {
39
+ static get is() {
40
+ return 'vaadin-lumo-styles';
41
+ }
42
+
43
+ static get version() {
44
+ return '24.2.3';
45
+ }
46
+ }
47
+
48
+ defineCustomElement(Lumo);
49
+
50
+ /**
51
+ * @license
52
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
53
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
54
+ */
55
+ /**
56
+ * @polymerMixin
57
+ */
58
+ const ThemePropertyMixin = (superClass) =>
59
+ class VaadinThemePropertyMixin extends superClass {
60
+ static get properties() {
61
+ return {
62
+ /**
63
+ * Helper property with theme attribute value facilitating propagation
64
+ * in shadow DOM.
65
+ *
66
+ * Enables the component implementation to propagate the `theme`
67
+ * attribute value to the sub-components in Shadow DOM by binding
68
+ * the sub-component's "theme" attribute to the `theme` property of
69
+ * the host.
70
+ *
71
+ * **NOTE:** Extending the mixin only provides the property for binding,
72
+ * and does not make the propagation alone.
73
+ *
74
+ * See [Styling Components: Sub-components](https://vaadin.com/docs/latest/styling/styling-components/#sub-components).
75
+ * page for more information.
76
+ *
77
+ * @protected
78
+ */
79
+ _theme: {
80
+ type: String,
81
+ readOnly: true,
82
+ },
83
+ };
84
+ }
85
+
86
+ static get observedAttributes() {
87
+ return [...super.observedAttributes, 'theme'];
88
+ }
89
+
90
+ /** @protected */
91
+ attributeChangedCallback(name, oldValue, newValue) {
92
+ super.attributeChangedCallback(name, oldValue, newValue);
93
+
94
+ if (name === 'theme') {
95
+ this._set_theme(newValue);
96
+ }
97
+ }
98
+ };
99
+
100
+ /**
101
+ * @license
102
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
103
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
104
+ */
105
+
106
+ /**
107
+ * @typedef {Object} Theme
108
+ * @property {string} themeFor
109
+ * @property {CSSResult[]} styles
110
+ * @property {string | string[]} [include]
111
+ * @property {string} [moduleId]
112
+ *
113
+ * @typedef {CSSResult[] | CSSResult} CSSResultGroup
114
+ */
115
+
116
+ /**
117
+ * @type {Theme[]}
118
+ */
119
+ const themeRegistry = [];
120
+
121
+ /**
122
+ * Check if the custom element type has themes applied.
123
+ * @param {Function} elementClass
124
+ * @returns {boolean}
125
+ */
126
+ function classHasThemes(elementClass) {
127
+ return elementClass && Object.prototype.hasOwnProperty.call(elementClass, '__themes');
128
+ }
129
+
130
+ /**
131
+ * Check if the custom element type has themes applied.
132
+ * @param {string} tagName
133
+ * @returns {boolean}
134
+ */
135
+ function hasThemes(tagName) {
136
+ return classHasThemes(customElements.get(tagName));
137
+ }
138
+
139
+ /**
140
+ * Flattens the styles into a single array of styles.
141
+ * @param {CSSResultGroup} styles
142
+ * @param {CSSResult[]} result
143
+ * @returns {CSSResult[]}
144
+ */
145
+ function flattenStyles(styles = []) {
146
+ return [styles].flat(Infinity).filter((style) => {
147
+ if (style instanceof o) {
148
+ return true;
149
+ }
150
+ console.warn('An item in styles is not of type CSSResult. Use `unsafeCSS` or `css`.');
151
+ return false;
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Registers CSS styles for a component type. Make sure to register the styles before
157
+ * the first instance of a component of the type is attached to DOM.
158
+ *
159
+ * @param {string} themeFor The local/tag name of the component type to register the styles for
160
+ * @param {CSSResultGroup} styles The CSS style rules to be registered for the component type
161
+ * matching themeFor and included in the local scope of each component instance
162
+ * @param {{moduleId?: string, include?: string | string[]}} options Additional options
163
+ * @return {void}
164
+ */
165
+ function registerStyles(themeFor, styles, options = {}) {
166
+ if (themeFor) {
167
+ if (hasThemes(themeFor)) {
168
+ console.warn(`The custom element definition for "${themeFor}"
169
+ was finalized before a style module was registered.
170
+ Make sure to add component specific style modules before
171
+ importing the corresponding custom element.`);
172
+ }
173
+ }
174
+
175
+ styles = flattenStyles(styles);
176
+
177
+ if (window.Vaadin && window.Vaadin.styleModules) {
178
+ window.Vaadin.styleModules.registerStyles(themeFor, styles, options);
179
+ } else {
180
+ themeRegistry.push({
181
+ themeFor,
182
+ styles,
183
+ include: options.include,
184
+ moduleId: options.moduleId,
185
+ });
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Returns all registered themes. By default the themeRegistry is returned as is.
191
+ * In case the style-modules adapter is imported, the themes are obtained from there instead
192
+ * @returns {Theme[]}
193
+ */
194
+ function getAllThemes() {
195
+ if (window.Vaadin && window.Vaadin.styleModules) {
196
+ return window.Vaadin.styleModules.getAllThemes();
197
+ }
198
+ return themeRegistry;
199
+ }
200
+
201
+ /**
202
+ * Returns true if the themeFor string matches the tag name
203
+ * @param {string} themeFor
204
+ * @param {string} tagName
205
+ * @returns {boolean}
206
+ */
207
+ function matchesThemeFor(themeFor, tagName) {
208
+ return (themeFor || '').split(' ').some((themeForToken) => {
209
+ return new RegExp(`^${themeForToken.split('*').join('.*')}$`, 'u').test(tagName);
210
+ });
211
+ }
212
+
213
+ /**
214
+ * Maps the moduleName to an include priority number which is used for
215
+ * determining the order in which styles are applied.
216
+ * @param {string} moduleName
217
+ * @returns {number}
218
+ */
219
+ function getIncludePriority(moduleName = '') {
220
+ let includePriority = 0;
221
+ if (moduleName.startsWith('lumo-') || moduleName.startsWith('material-')) {
222
+ includePriority = 1;
223
+ } else if (moduleName.startsWith('vaadin-')) {
224
+ includePriority = 2;
225
+ }
226
+ return includePriority;
227
+ }
228
+
229
+ /**
230
+ * Gets an array of CSSResults matching the include property of the theme.
231
+ * @param {Theme} theme
232
+ * @returns {CSSResult[]}
233
+ */
234
+ function getIncludedStyles(theme) {
235
+ const includedStyles = [];
236
+ if (theme.include) {
237
+ [].concat(theme.include).forEach((includeModuleId) => {
238
+ const includedTheme = getAllThemes().find((s) => s.moduleId === includeModuleId);
239
+ if (includedTheme) {
240
+ includedStyles.push(...getIncludedStyles(includedTheme), ...includedTheme.styles);
241
+ } else {
242
+ console.warn(`Included moduleId ${includeModuleId} not found in style registry`);
243
+ }
244
+ }, theme.styles);
245
+ }
246
+ return includedStyles;
247
+ }
248
+
249
+ /**
250
+ * Includes the styles to the template.
251
+ * @param {CSSResult[]} styles
252
+ * @param {HTMLTemplateElement} template
253
+ */
254
+ function addStylesToTemplate(styles, template) {
255
+ const styleEl = document.createElement('style');
256
+ styleEl.innerHTML = styles.map((style) => style.cssText).join('\n');
257
+ template.content.appendChild(styleEl);
258
+ }
259
+
260
+ /**
261
+ * Returns an array of themes that should be used for styling a component matching
262
+ * the tag name. The array is sorted by the include order.
263
+ * @param {string} tagName
264
+ * @returns {Theme[]}
265
+ */
266
+ function getThemes(tagName) {
267
+ const defaultModuleName = `${tagName}-default-theme`;
268
+
269
+ const themes = getAllThemes()
270
+ // Filter by matching themeFor properties
271
+ .filter((theme) => theme.moduleId !== defaultModuleName && matchesThemeFor(theme.themeFor, tagName))
272
+ .map((theme) => ({
273
+ ...theme,
274
+ // Prepend styles from included themes
275
+ styles: [...getIncludedStyles(theme), ...theme.styles],
276
+ // Map moduleId to includePriority
277
+ includePriority: getIncludePriority(theme.moduleId),
278
+ }))
279
+ // Sort by includePriority
280
+ .sort((themeA, themeB) => themeB.includePriority - themeA.includePriority);
281
+
282
+ if (themes.length > 0) {
283
+ return themes;
284
+ }
285
+ // No theme modules found, return the default module if it exists
286
+ return getAllThemes().filter((theme) => theme.moduleId === defaultModuleName);
287
+ }
288
+
289
+ /**
290
+ * @polymerMixin
291
+ * @mixes ThemePropertyMixin
292
+ */
293
+ const ThemableMixin = (superClass) =>
294
+ class VaadinThemableMixin extends ThemePropertyMixin(superClass) {
295
+ /**
296
+ * Covers PolymerElement based component styling
297
+ * @protected
298
+ */
299
+ static finalize() {
300
+ super.finalize();
301
+
302
+ // Make sure not to run the logic intended for PolymerElement when LitElement is used.
303
+ if (this.elementStyles) {
304
+ return;
305
+ }
306
+
307
+ const template = this.prototype._template;
308
+ if (!template || classHasThemes(this)) {
309
+ return;
310
+ }
311
+
312
+ addStylesToTemplate(this.getStylesForThis(), template);
313
+ }
314
+
315
+ /**
316
+ * Covers LitElement based component styling
317
+ *
318
+ * @protected
319
+ */
320
+ static finalizeStyles(styles) {
321
+ // The "styles" object originates from the "static get styles()" function of
322
+ // a LitElement based component. The theme styles are added after it
323
+ // so that they can override the component styles.
324
+ const themeStyles = this.getStylesForThis();
325
+ return styles ? [...super.finalizeStyles(styles), ...themeStyles] : themeStyles;
326
+ }
327
+
328
+ /**
329
+ * Get styles for the component type
330
+ *
331
+ * @private
332
+ */
333
+ static getStylesForThis() {
334
+ const parent = Object.getPrototypeOf(this.prototype);
335
+ const inheritedThemes = (parent ? parent.constructor.__themes : []) || [];
336
+ this.__themes = [...inheritedThemes, ...getThemes(this.is)];
337
+ const themeStyles = this.__themes.flatMap((theme) => theme.styles);
338
+ // Remove duplicates
339
+ return themeStyles.filter((style, index) => index === themeStyles.lastIndexOf(style));
340
+ }
341
+ };
342
+
343
+ /**
344
+ * @license
345
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
346
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
347
+ */
348
+
349
+ /**
350
+ * This is for use internally by Lumo and Material styles.
351
+ *
352
+ * @param {string} id the id to set on the created element, only for informational purposes
353
+ * @param {CSSResultGroup[]} styles the styles to add
354
+ */
355
+ const addGlobalThemeStyles = (id, ...styles) => {
356
+ const styleTag = document.createElement('style');
357
+ styleTag.id = id;
358
+ styleTag.textContent = styles
359
+ .map((style) => style.toString())
360
+ .join('\n')
361
+ .replace(':host', 'html');
362
+
363
+ document.head.insertAdjacentElement('afterbegin', styleTag);
364
+ };
365
+
366
+ const addLumoGlobalStyles = (id, ...styles) => {
367
+ addGlobalThemeStyles(`lumo-${id}`, styles);
368
+ };
369
+
370
+ /**
371
+ * @license
372
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
373
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
374
+ */
375
+
376
+ const colorBase = i`
377
+ :host {
378
+ /* Base (background) */
379
+ --lumo-base-color: #fff;
380
+
381
+ /* Tint */
382
+ --lumo-tint-5pct: hsla(0, 0%, 100%, 0.3);
383
+ --lumo-tint-10pct: hsla(0, 0%, 100%, 0.37);
384
+ --lumo-tint-20pct: hsla(0, 0%, 100%, 0.44);
385
+ --lumo-tint-30pct: hsla(0, 0%, 100%, 0.5);
386
+ --lumo-tint-40pct: hsla(0, 0%, 100%, 0.57);
387
+ --lumo-tint-50pct: hsla(0, 0%, 100%, 0.64);
388
+ --lumo-tint-60pct: hsla(0, 0%, 100%, 0.7);
389
+ --lumo-tint-70pct: hsla(0, 0%, 100%, 0.77);
390
+ --lumo-tint-80pct: hsla(0, 0%, 100%, 0.84);
391
+ --lumo-tint-90pct: hsla(0, 0%, 100%, 0.9);
392
+ --lumo-tint: #fff;
393
+
394
+ /* Shade */
395
+ --lumo-shade-5pct: hsla(214, 61%, 25%, 0.05);
396
+ --lumo-shade-10pct: hsla(214, 57%, 24%, 0.1);
397
+ --lumo-shade-20pct: hsla(214, 53%, 23%, 0.16);
398
+ --lumo-shade-30pct: hsla(214, 50%, 22%, 0.26);
399
+ --lumo-shade-40pct: hsla(214, 47%, 21%, 0.38);
400
+ --lumo-shade-50pct: hsla(214, 45%, 20%, 0.52);
401
+ --lumo-shade-60pct: hsla(214, 43%, 19%, 0.6);
402
+ --lumo-shade-70pct: hsla(214, 42%, 18%, 0.69);
403
+ --lumo-shade-80pct: hsla(214, 41%, 17%, 0.83);
404
+ --lumo-shade-90pct: hsla(214, 40%, 16%, 0.94);
405
+ --lumo-shade: hsl(214, 35%, 15%);
406
+
407
+ /* Contrast */
408
+ --lumo-contrast-5pct: var(--lumo-shade-5pct);
409
+ --lumo-contrast-10pct: var(--lumo-shade-10pct);
410
+ --lumo-contrast-20pct: var(--lumo-shade-20pct);
411
+ --lumo-contrast-30pct: var(--lumo-shade-30pct);
412
+ --lumo-contrast-40pct: var(--lumo-shade-40pct);
413
+ --lumo-contrast-50pct: var(--lumo-shade-50pct);
414
+ --lumo-contrast-60pct: var(--lumo-shade-60pct);
415
+ --lumo-contrast-70pct: var(--lumo-shade-70pct);
416
+ --lumo-contrast-80pct: var(--lumo-shade-80pct);
417
+ --lumo-contrast-90pct: var(--lumo-shade-90pct);
418
+ --lumo-contrast: var(--lumo-shade);
419
+
420
+ /* Text */
421
+ --lumo-header-text-color: var(--lumo-contrast);
422
+ --lumo-body-text-color: var(--lumo-contrast-90pct);
423
+ --lumo-secondary-text-color: var(--lumo-contrast-70pct);
424
+ --lumo-tertiary-text-color: var(--lumo-contrast-50pct);
425
+ --lumo-disabled-text-color: var(--lumo-contrast-30pct);
426
+
427
+ /* Primary */
428
+ --lumo-primary-color: hsl(214, 100%, 48%);
429
+ --lumo-primary-color-50pct: hsla(214, 100%, 49%, 0.76);
430
+ --lumo-primary-color-10pct: hsla(214, 100%, 60%, 0.13);
431
+ --lumo-primary-text-color: hsl(214, 100%, 43%);
432
+ --lumo-primary-contrast-color: #fff;
433
+
434
+ /* Error */
435
+ --lumo-error-color: hsl(3, 85%, 48%);
436
+ --lumo-error-color-50pct: hsla(3, 85%, 49%, 0.5);
437
+ --lumo-error-color-10pct: hsla(3, 85%, 49%, 0.1);
438
+ --lumo-error-text-color: hsl(3, 89%, 42%);
439
+ --lumo-error-contrast-color: #fff;
440
+
441
+ /* Success */
442
+ --lumo-success-color: hsl(145, 72%, 30%);
443
+ --lumo-success-color-50pct: hsla(145, 72%, 31%, 0.5);
444
+ --lumo-success-color-10pct: hsla(145, 72%, 31%, 0.1);
445
+ --lumo-success-text-color: hsl(145, 85%, 25%);
446
+ --lumo-success-contrast-color: #fff;
447
+
448
+ /* Warning */
449
+ --lumo-warning-color: hsl(48, 100%, 50%);
450
+ --lumo-warning-color-10pct: hsla(48, 100%, 50%, 0.25);
451
+ --lumo-warning-text-color: hsl(32, 100%, 30%);
452
+ --lumo-warning-contrast-color: var(--lumo-shade-90pct);
453
+ }
454
+
455
+ /* forced-colors mode adjustments */
456
+ @media (forced-colors: active) {
457
+ html {
458
+ --lumo-disabled-text-color: GrayText;
459
+ }
460
+ }
461
+ `;
462
+
463
+ addLumoGlobalStyles('color-props', colorBase);
464
+
465
+ const color = i`
466
+ [theme~='dark'] {
467
+ /* Base (background) */
468
+ --lumo-base-color: hsl(214, 35%, 21%);
469
+
470
+ /* Tint */
471
+ --lumo-tint-5pct: hsla(214, 65%, 85%, 0.06);
472
+ --lumo-tint-10pct: hsla(214, 60%, 80%, 0.14);
473
+ --lumo-tint-20pct: hsla(214, 64%, 82%, 0.23);
474
+ --lumo-tint-30pct: hsla(214, 69%, 84%, 0.32);
475
+ --lumo-tint-40pct: hsla(214, 73%, 86%, 0.41);
476
+ --lumo-tint-50pct: hsla(214, 78%, 88%, 0.5);
477
+ --lumo-tint-60pct: hsla(214, 82%, 90%, 0.58);
478
+ --lumo-tint-70pct: hsla(214, 87%, 92%, 0.69);
479
+ --lumo-tint-80pct: hsla(214, 91%, 94%, 0.8);
480
+ --lumo-tint-90pct: hsla(214, 96%, 96%, 0.9);
481
+ --lumo-tint: hsl(214, 100%, 98%);
482
+
483
+ /* Shade */
484
+ --lumo-shade-5pct: hsla(214, 0%, 0%, 0.07);
485
+ --lumo-shade-10pct: hsla(214, 4%, 2%, 0.15);
486
+ --lumo-shade-20pct: hsla(214, 8%, 4%, 0.23);
487
+ --lumo-shade-30pct: hsla(214, 12%, 6%, 0.32);
488
+ --lumo-shade-40pct: hsla(214, 16%, 8%, 0.41);
489
+ --lumo-shade-50pct: hsla(214, 20%, 10%, 0.5);
490
+ --lumo-shade-60pct: hsla(214, 24%, 12%, 0.6);
491
+ --lumo-shade-70pct: hsla(214, 28%, 13%, 0.7);
492
+ --lumo-shade-80pct: hsla(214, 32%, 13%, 0.8);
493
+ --lumo-shade-90pct: hsla(214, 33%, 13%, 0.9);
494
+ --lumo-shade: hsl(214, 33%, 13%);
495
+
496
+ /* Contrast */
497
+ --lumo-contrast-5pct: var(--lumo-tint-5pct);
498
+ --lumo-contrast-10pct: var(--lumo-tint-10pct);
499
+ --lumo-contrast-20pct: var(--lumo-tint-20pct);
500
+ --lumo-contrast-30pct: var(--lumo-tint-30pct);
501
+ --lumo-contrast-40pct: var(--lumo-tint-40pct);
502
+ --lumo-contrast-50pct: var(--lumo-tint-50pct);
503
+ --lumo-contrast-60pct: var(--lumo-tint-60pct);
504
+ --lumo-contrast-70pct: var(--lumo-tint-70pct);
505
+ --lumo-contrast-80pct: var(--lumo-tint-80pct);
506
+ --lumo-contrast-90pct: var(--lumo-tint-90pct);
507
+ --lumo-contrast: var(--lumo-tint);
508
+
509
+ /* Text */
510
+ --lumo-header-text-color: var(--lumo-contrast);
511
+ --lumo-body-text-color: var(--lumo-contrast-90pct);
512
+ --lumo-secondary-text-color: var(--lumo-contrast-70pct);
513
+ --lumo-tertiary-text-color: var(--lumo-contrast-50pct);
514
+ --lumo-disabled-text-color: var(--lumo-contrast-30pct);
515
+
516
+ /* Primary */
517
+ --lumo-primary-color: hsl(214, 90%, 48%);
518
+ --lumo-primary-color-50pct: hsla(214, 90%, 70%, 0.69);
519
+ --lumo-primary-color-10pct: hsla(214, 90%, 55%, 0.13);
520
+ --lumo-primary-text-color: hsl(214, 90%, 77%);
521
+ --lumo-primary-contrast-color: #fff;
522
+
523
+ /* Error */
524
+ --lumo-error-color: hsl(3, 79%, 49%);
525
+ --lumo-error-color-50pct: hsla(3, 75%, 62%, 0.5);
526
+ --lumo-error-color-10pct: hsla(3, 75%, 62%, 0.14);
527
+ --lumo-error-text-color: hsl(3, 100%, 80%);
528
+
529
+ /* Success */
530
+ --lumo-success-color: hsl(145, 72%, 30%);
531
+ --lumo-success-color-50pct: hsla(145, 92%, 51%, 0.5);
532
+ --lumo-success-color-10pct: hsla(145, 92%, 51%, 0.1);
533
+ --lumo-success-text-color: hsl(145, 85%, 46%);
534
+
535
+ /* Warning */
536
+ --lumo-warning-color: hsl(43, 100%, 48%);
537
+ --lumo-warning-color-10pct: hsla(40, 100%, 50%, 0.2);
538
+ --lumo-warning-text-color: hsl(45, 100%, 60%);
539
+ --lumo-warning-contrast-color: var(--lumo-shade-90pct);
540
+ }
541
+
542
+ html {
543
+ color: var(--lumo-body-text-color);
544
+ background-color: var(--lumo-base-color);
545
+ color-scheme: light;
546
+ }
547
+
548
+ [theme~='dark'] {
549
+ color: var(--lumo-body-text-color);
550
+ background-color: var(--lumo-base-color);
551
+ color-scheme: dark;
552
+ }
553
+
554
+ h1,
555
+ h2,
556
+ h3,
557
+ h4,
558
+ h5,
559
+ h6 {
560
+ color: var(--lumo-header-text-color);
561
+ }
562
+
563
+ a:where(:any-link) {
564
+ color: var(--lumo-primary-text-color);
565
+ }
566
+
567
+ a:not(:any-link) {
568
+ color: var(--lumo-disabled-text-color);
569
+ }
570
+
571
+ blockquote {
572
+ color: var(--lumo-secondary-text-color);
573
+ }
574
+
575
+ code,
576
+ pre {
577
+ background-color: var(--lumo-contrast-10pct);
578
+ border-radius: var(--lumo-border-radius-m);
579
+ }
580
+ `;
581
+
582
+ registerStyles('', color, { moduleId: 'lumo-color' });
583
+
584
+ /**
585
+ * @license
586
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
587
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
588
+ */
589
+
590
+ const sizing = i`
591
+ :host {
592
+ --lumo-size-xs: 1.625rem;
593
+ --lumo-size-s: 1.875rem;
594
+ --lumo-size-m: 2.25rem;
595
+ --lumo-size-l: 2.75rem;
596
+ --lumo-size-xl: 3.5rem;
597
+
598
+ /* Icons */
599
+ --lumo-icon-size-s: 1.25em;
600
+ --lumo-icon-size-m: 1.5em;
601
+ --lumo-icon-size-l: 2.25em;
602
+ /* For backwards compatibility */
603
+ --lumo-icon-size: var(--lumo-icon-size-m);
604
+ }
605
+ `;
606
+
607
+ addLumoGlobalStyles('sizing-props', sizing);
608
+
609
+ /**
610
+ * @license
611
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
612
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
613
+ */
614
+
615
+ const spacing = i`
616
+ :host {
617
+ /* Square */
618
+ --lumo-space-xs: 0.25rem;
619
+ --lumo-space-s: 0.5rem;
620
+ --lumo-space-m: 1rem;
621
+ --lumo-space-l: 1.5rem;
622
+ --lumo-space-xl: 2.5rem;
623
+
624
+ /* Wide */
625
+ --lumo-space-wide-xs: calc(var(--lumo-space-xs) / 2) var(--lumo-space-xs);
626
+ --lumo-space-wide-s: calc(var(--lumo-space-s) / 2) var(--lumo-space-s);
627
+ --lumo-space-wide-m: calc(var(--lumo-space-m) / 2) var(--lumo-space-m);
628
+ --lumo-space-wide-l: calc(var(--lumo-space-l) / 2) var(--lumo-space-l);
629
+ --lumo-space-wide-xl: calc(var(--lumo-space-xl) / 2) var(--lumo-space-xl);
630
+
631
+ /* Tall */
632
+ --lumo-space-tall-xs: var(--lumo-space-xs) calc(var(--lumo-space-xs) / 2);
633
+ --lumo-space-tall-s: var(--lumo-space-s) calc(var(--lumo-space-s) / 2);
634
+ --lumo-space-tall-m: var(--lumo-space-m) calc(var(--lumo-space-m) / 2);
635
+ --lumo-space-tall-l: var(--lumo-space-l) calc(var(--lumo-space-l) / 2);
636
+ --lumo-space-tall-xl: var(--lumo-space-xl) calc(var(--lumo-space-xl) / 2);
637
+ }
638
+ `;
639
+
640
+ addLumoGlobalStyles('spacing-props', spacing);
641
+
642
+ /**
643
+ * @license
644
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
645
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
646
+ */
647
+
648
+ const style = i`
649
+ :host {
650
+ /* Border radius */
651
+ --lumo-border-radius-s: 0.25em; /* Checkbox, badge, date-picker year indicator, etc */
652
+ --lumo-border-radius-m: var(--lumo-border-radius, 0.25em); /* Button, text field, menu overlay, etc */
653
+ --lumo-border-radius-l: 0.5em; /* Dialog, notification, etc */
654
+
655
+ /* Shadow */
656
+ --lumo-box-shadow-xs: 0 1px 4px -1px var(--lumo-shade-50pct);
657
+ --lumo-box-shadow-s: 0 2px 4px -1px var(--lumo-shade-20pct), 0 3px 12px -1px var(--lumo-shade-30pct);
658
+ --lumo-box-shadow-m: 0 2px 6px -1px var(--lumo-shade-20pct), 0 8px 24px -4px var(--lumo-shade-40pct);
659
+ --lumo-box-shadow-l: 0 3px 18px -2px var(--lumo-shade-20pct), 0 12px 48px -6px var(--lumo-shade-40pct);
660
+ --lumo-box-shadow-xl: 0 4px 24px -3px var(--lumo-shade-20pct), 0 18px 64px -8px var(--lumo-shade-40pct);
661
+
662
+ /* Clickable element cursor */
663
+ --lumo-clickable-cursor: default;
664
+ }
665
+ `;
666
+
667
+ /**
668
+ * Default values for component-specific custom properties.
669
+ */
670
+ i`
671
+ html {
672
+ --vaadin-checkbox-size: calc(var(--lumo-size-m) / 2);
673
+ --vaadin-radio-button-size: calc(var(--lumo-size-m) / 2);
674
+ --vaadin-input-field-border-radius: var(--lumo-border-radius-m);
675
+ }
676
+ `;
677
+
678
+ addLumoGlobalStyles('style-props', style);
679
+
680
+ /**
681
+ * @license
682
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
683
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
684
+ */
685
+
686
+ const font = i`
687
+ :host {
688
+ /* prettier-ignore */
689
+ --lumo-font-family: -apple-system, BlinkMacSystemFont, 'Roboto', 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
690
+
691
+ /* Font sizes */
692
+ --lumo-font-size-xxs: 0.75rem;
693
+ --lumo-font-size-xs: 0.8125rem;
694
+ --lumo-font-size-s: 0.875rem;
695
+ --lumo-font-size-m: 1rem;
696
+ --lumo-font-size-l: 1.125rem;
697
+ --lumo-font-size-xl: 1.375rem;
698
+ --lumo-font-size-xxl: 1.75rem;
699
+ --lumo-font-size-xxxl: 2.5rem;
700
+
701
+ /* Line heights */
702
+ --lumo-line-height-xs: 1.25;
703
+ --lumo-line-height-s: 1.375;
704
+ --lumo-line-height-m: 1.625;
705
+ }
706
+ `;
707
+
708
+ const typography = i`
709
+ body,
5
710
  :host {
6
- /* Sizing */
7
- --lumo-button-size: var(--lumo-size-m);
8
- min-width: calc(var(--lumo-button-size) * 2);
9
- height: var(--lumo-button-size);
10
- padding: 0 calc(var(--lumo-button-size) / 3 + var(--lumo-border-radius-m) / 2);
11
- margin: var(--lumo-space-xs) 0;
12
- box-sizing: border-box;
13
- /* Style */
14
711
  font-family: var(--lumo-font-family);
15
712
  font-size: var(--lumo-font-size-m);
16
- font-weight: 500;
17
- color: var(--_lumo-button-color, var(--lumo-primary-text-color));
18
- background-color: var(--_lumo-button-background-color, var(--lumo-contrast-5pct));
19
- border-radius: var(--lumo-border-radius-m);
20
- cursor: var(--lumo-clickable-cursor);
21
- -webkit-tap-highlight-color: transparent;
713
+ line-height: var(--lumo-line-height-m);
714
+ -webkit-text-size-adjust: 100%;
22
715
  -webkit-font-smoothing: antialiased;
23
716
  -moz-osx-font-smoothing: grayscale;
24
717
  }
25
718
 
26
- /* Set only for the internal parts so we don't affect the host vertical alignment */
27
- [part='label'],
28
- [part='prefix'],
29
- [part='suffix'] {
719
+ small,
720
+ [theme~='font-size-s'] {
721
+ font-size: var(--lumo-font-size-s);
722
+ line-height: var(--lumo-line-height-s);
723
+ }
724
+
725
+ [theme~='font-size-xs'] {
726
+ font-size: var(--lumo-font-size-xs);
30
727
  line-height: var(--lumo-line-height-xs);
31
728
  }
32
729
 
33
- [part='label'] {
34
- padding: calc(var(--lumo-button-size) / 6) 0;
35
- }
730
+ :where(h1, h2, h3, h4, h5, h6) {
731
+ font-weight: 600;
732
+ line-height: var(--lumo-line-height-xs);
733
+ margin-block: 0;
734
+ }
735
+
736
+ :where(h1) {
737
+ font-size: var(--lumo-font-size-xxxl);
738
+ }
739
+
740
+ :where(h2) {
741
+ font-size: var(--lumo-font-size-xxl);
742
+ }
743
+
744
+ :where(h3) {
745
+ font-size: var(--lumo-font-size-xl);
746
+ }
747
+
748
+ :where(h4) {
749
+ font-size: var(--lumo-font-size-l);
750
+ }
751
+
752
+ :where(h5) {
753
+ font-size: var(--lumo-font-size-m);
754
+ }
755
+
756
+ :where(h6) {
757
+ font-size: var(--lumo-font-size-xs);
758
+ text-transform: uppercase;
759
+ letter-spacing: 0.03em;
760
+ }
761
+
762
+ p,
763
+ blockquote {
764
+ margin-top: 0.5em;
765
+ margin-bottom: 0.75em;
766
+ }
767
+
768
+ a {
769
+ text-decoration: none;
770
+ }
771
+
772
+ a:where(:any-link):hover {
773
+ text-decoration: underline;
774
+ }
775
+
776
+ hr {
777
+ display: block;
778
+ align-self: stretch;
779
+ height: 1px;
780
+ border: 0;
781
+ padding: 0;
782
+ margin: var(--lumo-space-s) calc(var(--lumo-border-radius-m) / 2);
783
+ background-color: var(--lumo-contrast-10pct);
784
+ }
785
+
786
+ blockquote {
787
+ border-left: 2px solid var(--lumo-contrast-30pct);
788
+ }
789
+
790
+ b,
791
+ strong {
792
+ font-weight: 600;
793
+ }
794
+
795
+ /* RTL specific styles */
796
+ blockquote[dir='rtl'] {
797
+ border-left: none;
798
+ border-right: 2px solid var(--lumo-contrast-30pct);
799
+ }
800
+ `;
801
+
802
+ registerStyles('', typography, { moduleId: 'lumo-typography' });
803
+ addLumoGlobalStyles('typography-props', font);
804
+
805
+ const button = i`
806
+ :host {
807
+ /* Sizing */
808
+ --lumo-button-size: var(--lumo-size-m);
809
+ min-width: calc(var(--lumo-button-size) * 2);
810
+ height: var(--lumo-button-size);
811
+ padding: 0 calc(var(--lumo-button-size) / 3 + var(--lumo-border-radius-m) / 2);
812
+ margin: var(--lumo-space-xs) 0;
813
+ box-sizing: border-box;
814
+ /* Style */
815
+ font-family: var(--lumo-font-family);
816
+ font-size: var(--lumo-font-size-m);
817
+ font-weight: 500;
818
+ color: var(--_lumo-button-color, var(--lumo-primary-text-color));
819
+ background-color: var(--_lumo-button-background-color, var(--lumo-contrast-5pct));
820
+ border-radius: var(--lumo-border-radius-m);
821
+ cursor: var(--lumo-clickable-cursor);
822
+ -webkit-tap-highlight-color: transparent;
823
+ -webkit-font-smoothing: antialiased;
824
+ -moz-osx-font-smoothing: grayscale;
825
+ flex-shrink: 0;
826
+ }
827
+
828
+ /* Set only for the internal parts so we don't affect the host vertical alignment */
829
+ [part='label'],
830
+ [part='prefix'],
831
+ [part='suffix'] {
832
+ line-height: var(--lumo-line-height-xs);
833
+ }
834
+
835
+ [part='label'] {
836
+ padding: calc(var(--lumo-button-size) / 6) 0;
837
+ }
838
+
839
+ :host([theme~='small']) {
840
+ font-size: var(--lumo-font-size-s);
841
+ --lumo-button-size: var(--lumo-size-s);
842
+ }
843
+
844
+ :host([theme~='large']) {
845
+ font-size: var(--lumo-font-size-l);
846
+ --lumo-button-size: var(--lumo-size-l);
847
+ }
848
+
849
+ /* For interaction states */
850
+ :host::before,
851
+ :host::after {
852
+ content: '';
853
+ /* We rely on the host always being relative */
854
+ position: absolute;
855
+ z-index: 1;
856
+ inset: 0;
857
+ background-color: currentColor;
858
+ border-radius: inherit;
859
+ opacity: 0;
860
+ pointer-events: none;
861
+ }
862
+
863
+ /* Hover */
864
+
865
+ @media (any-hover: hover) {
866
+ :host(:hover)::before {
867
+ opacity: 0.02;
868
+ }
869
+ }
870
+
871
+ /* Active */
872
+
873
+ :host::after {
874
+ transition: opacity 1.4s, transform 0.1s;
875
+ filter: blur(8px);
876
+ }
877
+
878
+ :host([active])::before {
879
+ opacity: 0.05;
880
+ transition-duration: 0s;
881
+ }
882
+
883
+ :host([active])::after {
884
+ opacity: 0.1;
885
+ transition-duration: 0s, 0s;
886
+ transform: scale(0);
887
+ }
888
+
889
+ /* Keyboard focus */
890
+
891
+ :host([focus-ring]) {
892
+ box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
893
+ }
894
+
895
+ :host([theme~='primary'][focus-ring]) {
896
+ box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px var(--lumo-primary-color-50pct);
897
+ }
898
+
899
+ /* Types (primary, tertiary, tertiary-inline */
900
+
901
+ :host([theme~='tertiary']),
902
+ :host([theme~='tertiary-inline']) {
903
+ background-color: transparent !important;
904
+ min-width: 0;
905
+ }
906
+
907
+ :host([theme~='tertiary']) {
908
+ padding: 0 calc(var(--lumo-button-size) / 6);
909
+ }
910
+
911
+ :host([theme~='tertiary-inline'])::before {
912
+ display: none;
913
+ }
914
+
915
+ :host([theme~='tertiary-inline']) {
916
+ margin: 0;
917
+ height: auto;
918
+ padding: 0;
919
+ line-height: inherit;
920
+ font-size: inherit;
921
+ }
922
+
923
+ :host([theme~='tertiary-inline']) [part='label'] {
924
+ padding: 0;
925
+ overflow: visible;
926
+ line-height: inherit;
927
+ }
928
+
929
+ :host([theme~='primary']) {
930
+ background-color: var(--_lumo-button-primary-background-color, var(--lumo-primary-color));
931
+ color: var(--_lumo-button-primary-color, var(--lumo-primary-contrast-color));
932
+ font-weight: 600;
933
+ min-width: calc(var(--lumo-button-size) * 2.5);
934
+ }
935
+
936
+ :host([theme~='primary'])::before {
937
+ background-color: black;
938
+ }
939
+
940
+ @media (any-hover: hover) {
941
+ :host([theme~='primary']:hover)::before {
942
+ opacity: 0.05;
943
+ }
944
+ }
945
+
946
+ :host([theme~='primary'][active])::before {
947
+ opacity: 0.1;
948
+ }
949
+
950
+ :host([theme~='primary'][active])::after {
951
+ opacity: 0.2;
952
+ }
953
+
954
+ /* Colors (success, error, contrast) */
955
+
956
+ :host([theme~='success']) {
957
+ color: var(--lumo-success-text-color);
958
+ }
959
+
960
+ :host([theme~='success'][theme~='primary']) {
961
+ background-color: var(--lumo-success-color);
962
+ color: var(--lumo-success-contrast-color);
963
+ }
964
+
965
+ :host([theme~='error']) {
966
+ color: var(--lumo-error-text-color);
967
+ }
968
+
969
+ :host([theme~='error'][theme~='primary']) {
970
+ background-color: var(--lumo-error-color);
971
+ color: var(--lumo-error-contrast-color);
972
+ }
973
+
974
+ :host([theme~='contrast']) {
975
+ color: var(--lumo-contrast);
976
+ }
977
+
978
+ :host([theme~='contrast'][theme~='primary']) {
979
+ background-color: var(--lumo-contrast);
980
+ color: var(--lumo-base-color);
981
+ }
982
+
983
+ /* Disabled state. Keep selectors after other color variants. */
984
+
985
+ :host([disabled]) {
986
+ pointer-events: none;
987
+ color: var(--lumo-disabled-text-color);
988
+ }
989
+
990
+ :host([theme~='primary'][disabled]) {
991
+ background-color: var(--lumo-contrast-30pct);
992
+ color: var(--lumo-base-color);
993
+ }
994
+
995
+ :host([theme~='primary'][disabled]) [part] {
996
+ opacity: 0.7;
997
+ }
998
+
999
+ /* Icons */
1000
+
1001
+ [part] ::slotted(vaadin-icon) {
1002
+ display: inline-block;
1003
+ width: var(--lumo-icon-size-m);
1004
+ height: var(--lumo-icon-size-m);
1005
+ }
1006
+
1007
+ /* Vaadin icons are based on a 16x16 grid (unlike Lumo and Material icons with 24x24), so they look too big by default */
1008
+ [part] ::slotted(vaadin-icon[icon^='vaadin:']) {
1009
+ padding: 0.25em;
1010
+ box-sizing: border-box !important;
1011
+ }
1012
+
1013
+ [part='prefix'] {
1014
+ margin-left: -0.25em;
1015
+ margin-right: 0.25em;
1016
+ }
1017
+
1018
+ [part='suffix'] {
1019
+ margin-left: 0.25em;
1020
+ margin-right: -0.25em;
1021
+ }
1022
+
1023
+ /* Icon-only */
1024
+
1025
+ :host([theme~='icon']:not([theme~='tertiary-inline'])) {
1026
+ min-width: var(--lumo-button-size);
1027
+ padding-left: calc(var(--lumo-button-size) / 4);
1028
+ padding-right: calc(var(--lumo-button-size) / 4);
1029
+ }
1030
+
1031
+ :host([theme~='icon']) [part='prefix'],
1032
+ :host([theme~='icon']) [part='suffix'] {
1033
+ margin-left: 0;
1034
+ margin-right: 0;
1035
+ }
1036
+
1037
+ /* RTL specific styles */
1038
+
1039
+ :host([dir='rtl']) [part='prefix'] {
1040
+ margin-left: 0.25em;
1041
+ margin-right: -0.25em;
1042
+ }
1043
+
1044
+ :host([dir='rtl']) [part='suffix'] {
1045
+ margin-left: -0.25em;
1046
+ margin-right: 0.25em;
1047
+ }
1048
+
1049
+ :host([dir='rtl'][theme~='icon']) [part='prefix'],
1050
+ :host([dir='rtl'][theme~='icon']) [part='suffix'] {
1051
+ margin-left: 0;
1052
+ margin-right: 0;
1053
+ }
1054
+ `;
1055
+
1056
+ registerStyles('vaadin-button', button, { moduleId: 'lumo-button' });
1057
+
1058
+ /**
1059
+ * @license
1060
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
1061
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1062
+ */
1063
+
1064
+ /**
1065
+ * @typedef ReactiveController
1066
+ * @type {import('lit').ReactiveController}
1067
+ */
1068
+
1069
+ /**
1070
+ * A mixin for connecting controllers to the element.
1071
+ *
1072
+ * @polymerMixin
1073
+ */
1074
+ const ControllerMixin = dedupingMixin((superClass) => {
1075
+ // If the superclass extends from LitElement,
1076
+ // use its own controllers implementation.
1077
+ if (typeof superClass.prototype.addController === 'function') {
1078
+ return superClass;
1079
+ }
1080
+
1081
+ return class ControllerMixinClass extends superClass {
1082
+ constructor() {
1083
+ super();
1084
+
1085
+ /**
1086
+ * @type {Set<ReactiveController>}
1087
+ */
1088
+ this.__controllers = new Set();
1089
+ }
1090
+
1091
+ /** @protected */
1092
+ connectedCallback() {
1093
+ super.connectedCallback();
1094
+
1095
+ this.__controllers.forEach((c) => {
1096
+ if (c.hostConnected) {
1097
+ c.hostConnected();
1098
+ }
1099
+ });
1100
+ }
1101
+
1102
+ /** @protected */
1103
+ disconnectedCallback() {
1104
+ super.disconnectedCallback();
1105
+
1106
+ this.__controllers.forEach((c) => {
1107
+ if (c.hostDisconnected) {
1108
+ c.hostDisconnected();
1109
+ }
1110
+ });
1111
+ }
1112
+
1113
+ /**
1114
+ * Registers a controller to participate in the element update cycle.
1115
+ *
1116
+ * @param {ReactiveController} controller
1117
+ * @protected
1118
+ */
1119
+ addController(controller) {
1120
+ this.__controllers.add(controller);
1121
+ // Call hostConnected if a controller is added after the element is attached.
1122
+ if (this.$ !== undefined && this.isConnected && controller.hostConnected) {
1123
+ controller.hostConnected();
1124
+ }
1125
+ }
1126
+
1127
+ /**
1128
+ * Removes a controller from the element.
1129
+ *
1130
+ * @param {ReactiveController} controller
1131
+ * @protected
1132
+ */
1133
+ removeController(controller) {
1134
+ this.__controllers.delete(controller);
1135
+ }
1136
+ };
1137
+ });
1138
+
1139
+ /**
1140
+ * @license
1141
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1142
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
1143
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
1144
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
1145
+ * Code distributed by Google as part of the polymer project is also
1146
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
1147
+ */
1148
+
1149
+ /**
1150
+ * Async interface wrapper around `requestIdleCallback`. Falls back to
1151
+ * `setTimeout` on browsers that do not support `requestIdleCallback`.
1152
+ *
1153
+ * @namespace
1154
+ * @summary Async interface wrapper around `requestIdleCallback`.
1155
+ */
1156
+ const idlePeriod = {
1157
+ /**
1158
+ * Enqueues a function called at `requestIdleCallback` timing.
1159
+ *
1160
+ * @memberof idlePeriod
1161
+ * @param {function(!IdleDeadline):void} fn Callback to run
1162
+ * @return {number} Handle used for canceling task
1163
+ */
1164
+ run(fn) {
1165
+ return window.requestIdleCallback ? window.requestIdleCallback(fn) : window.setTimeout(fn, 16);
1166
+ },
1167
+ /**
1168
+ * Cancels a previously enqueued `idlePeriod` callback.
1169
+ *
1170
+ * @memberof idlePeriod
1171
+ * @param {number} handle Handle returned from `run` of callback to cancel
1172
+ * @return {void}
1173
+ */
1174
+ cancel(handle) {
1175
+ if (window.cancelIdleCallback) {
1176
+ window.cancelIdleCallback(handle);
1177
+ } else {
1178
+ window.clearTimeout(handle);
1179
+ }
1180
+ },
1181
+ };
1182
+
1183
+ /**
1184
+ @license
1185
+ Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1186
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
1187
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
1188
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
1189
+ Code distributed by Google as part of the polymer project is also
1190
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
1191
+ */
1192
+
1193
+ const debouncerQueue = new Set();
1194
+
1195
+ /**
1196
+ * @summary Collapse multiple callbacks into one invocation after a timer.
1197
+ */
1198
+ class Debouncer {
1199
+ /**
1200
+ * Creates a debouncer if no debouncer is passed as a parameter
1201
+ * or it cancels an active debouncer otherwise. The following
1202
+ * example shows how a debouncer can be called multiple times within a
1203
+ * microtask and "debounced" such that the provided callback function is
1204
+ * called once. Add this method to a custom element:
1205
+ *
1206
+ * ```js
1207
+ * import {microTask} from '@vaadin/component-base/src/async.js';
1208
+ * import {Debouncer} from '@vaadin/component-base/src/debounce.js';
1209
+ * // ...
1210
+ *
1211
+ * _debounceWork() {
1212
+ * this._debounceJob = Debouncer.debounce(this._debounceJob,
1213
+ * microTask, () => this._doWork());
1214
+ * }
1215
+ * ```
1216
+ *
1217
+ * If the `_debounceWork` method is called multiple times within the same
1218
+ * microtask, the `_doWork` function will be called only once at the next
1219
+ * microtask checkpoint.
1220
+ *
1221
+ * Note: In testing it is often convenient to avoid asynchrony. To accomplish
1222
+ * this with a debouncer, you can use `enqueueDebouncer` and
1223
+ * `flush`. For example, extend the above example by adding
1224
+ * `enqueueDebouncer(this._debounceJob)` at the end of the
1225
+ * `_debounceWork` method. Then in a test, call `flush` to ensure
1226
+ * the debouncer has completed.
1227
+ *
1228
+ * @param {Debouncer?} debouncer Debouncer object.
1229
+ * @param {!AsyncInterface} asyncModule Object with Async interface
1230
+ * @param {function()} callback Callback to run.
1231
+ * @return {!Debouncer} Returns a debouncer object.
1232
+ */
1233
+ static debounce(debouncer, asyncModule, callback) {
1234
+ if (debouncer instanceof Debouncer) {
1235
+ // Cancel the async callback, but leave in debouncerQueue if it was
1236
+ // enqueued, to maintain 1.x flush order
1237
+ debouncer._cancelAsync();
1238
+ } else {
1239
+ debouncer = new Debouncer();
1240
+ }
1241
+ debouncer.setConfig(asyncModule, callback);
1242
+ return debouncer;
1243
+ }
1244
+
1245
+ constructor() {
1246
+ this._asyncModule = null;
1247
+ this._callback = null;
1248
+ this._timer = null;
1249
+ }
1250
+
1251
+ /**
1252
+ * Sets the scheduler; that is, a module with the Async interface,
1253
+ * a callback and optional arguments to be passed to the run function
1254
+ * from the async module.
1255
+ *
1256
+ * @param {!AsyncInterface} asyncModule Object with Async interface.
1257
+ * @param {function()} callback Callback to run.
1258
+ * @return {void}
1259
+ */
1260
+ setConfig(asyncModule, callback) {
1261
+ this._asyncModule = asyncModule;
1262
+ this._callback = callback;
1263
+ this._timer = this._asyncModule.run(() => {
1264
+ this._timer = null;
1265
+ debouncerQueue.delete(this);
1266
+ this._callback();
1267
+ });
1268
+ }
1269
+
1270
+ /**
1271
+ * Cancels an active debouncer and returns a reference to itself.
1272
+ *
1273
+ * @return {void}
1274
+ */
1275
+ cancel() {
1276
+ if (this.isActive()) {
1277
+ this._cancelAsync();
1278
+ // Canceling a debouncer removes its spot from the flush queue,
1279
+ // so if a debouncer is manually canceled and re-debounced, it
1280
+ // will reset its flush order (this is a very minor difference from 1.x)
1281
+ // Re-debouncing via the `debounce` API retains the 1.x FIFO flush order
1282
+ debouncerQueue.delete(this);
1283
+ }
1284
+ }
1285
+
1286
+ /**
1287
+ * Cancels a debouncer's async callback.
1288
+ *
1289
+ * @return {void}
1290
+ */
1291
+ _cancelAsync() {
1292
+ if (this.isActive()) {
1293
+ this._asyncModule.cancel(/** @type {number} */ (this._timer));
1294
+ this._timer = null;
1295
+ }
1296
+ }
1297
+
1298
+ /**
1299
+ * Flushes an active debouncer and returns a reference to itself.
1300
+ *
1301
+ * @return {void}
1302
+ */
1303
+ flush() {
1304
+ if (this.isActive()) {
1305
+ this.cancel();
1306
+ this._callback();
1307
+ }
1308
+ }
1309
+
1310
+ /**
1311
+ * Returns true if the debouncer is active.
1312
+ *
1313
+ * @return {boolean} True if active.
1314
+ */
1315
+ isActive() {
1316
+ return this._timer != null;
1317
+ }
1318
+ }
1319
+
1320
+ /**
1321
+ * Adds a `Debouncer` to a list of globally flushable tasks.
1322
+ *
1323
+ * @param {!Debouncer} debouncer Debouncer to enqueue
1324
+ * @return {void}
1325
+ */
1326
+ function enqueueDebouncer(debouncer) {
1327
+ debouncerQueue.add(debouncer);
1328
+ }
1329
+
1330
+ /**
1331
+ * @license
1332
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
1333
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1334
+ */
1335
+
1336
+ /**
1337
+ * Array of Vaadin custom element classes that have been subscribed to the dir changes.
1338
+ */
1339
+ const directionSubscribers = [];
1340
+
1341
+ function alignDirs(element, documentDir, elementDir = element.getAttribute('dir')) {
1342
+ if (documentDir) {
1343
+ element.setAttribute('dir', documentDir);
1344
+ } else if (elementDir != null) {
1345
+ element.removeAttribute('dir');
1346
+ }
1347
+ }
1348
+
1349
+ function getDocumentDir() {
1350
+ return document.documentElement.getAttribute('dir');
1351
+ }
1352
+
1353
+ function directionUpdater() {
1354
+ const documentDir = getDocumentDir();
1355
+ directionSubscribers.forEach((element) => {
1356
+ alignDirs(element, documentDir);
1357
+ });
1358
+ }
1359
+
1360
+ const directionObserver = new MutationObserver(directionUpdater);
1361
+ directionObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['dir'] });
1362
+
1363
+ /**
1364
+ * A mixin to handle `dir` attribute based on the one set on the `<html>` element.
1365
+ *
1366
+ * @polymerMixin
1367
+ */
1368
+ const DirMixin = (superClass) =>
1369
+ class VaadinDirMixin extends superClass {
1370
+ static get properties() {
1371
+ return {
1372
+ /**
1373
+ * @protected
1374
+ */
1375
+ dir: {
1376
+ type: String,
1377
+ value: '',
1378
+ reflectToAttribute: true,
1379
+ converter: {
1380
+ fromAttribute: (attr) => {
1381
+ return !attr ? '' : attr;
1382
+ },
1383
+ toAttribute: (prop) => {
1384
+ return prop === '' ? null : prop;
1385
+ },
1386
+ },
1387
+ },
1388
+ };
1389
+ }
1390
+
1391
+ /**
1392
+ * @return {boolean}
1393
+ * @protected
1394
+ */
1395
+ get __isRTL() {
1396
+ return this.getAttribute('dir') === 'rtl';
1397
+ }
1398
+
1399
+ /** @protected */
1400
+ connectedCallback() {
1401
+ super.connectedCallback();
1402
+
1403
+ if (!this.hasAttribute('dir') || this.__restoreSubscription) {
1404
+ this.__subscribe();
1405
+ alignDirs(this, getDocumentDir(), null);
1406
+ }
1407
+ }
1408
+
1409
+ /** @protected */
1410
+ attributeChangedCallback(name, oldValue, newValue) {
1411
+ super.attributeChangedCallback(name, oldValue, newValue);
1412
+ if (name !== 'dir') {
1413
+ return;
1414
+ }
1415
+
1416
+ const documentDir = getDocumentDir();
1417
+
1418
+ // New value equals to the document direction and the element is not subscribed to the changes
1419
+ const newValueEqlDocDir = newValue === documentDir && directionSubscribers.indexOf(this) === -1;
1420
+ // Value was emptied and the element is not subscribed to the changes
1421
+ const newValueEmptied = !newValue && oldValue && directionSubscribers.indexOf(this) === -1;
1422
+ // New value is different and the old equals to document direction and the element is not subscribed to the changes
1423
+ const newDiffValue = newValue !== documentDir && oldValue === documentDir;
1424
+
1425
+ if (newValueEqlDocDir || newValueEmptied) {
1426
+ this.__subscribe();
1427
+ alignDirs(this, documentDir, newValue);
1428
+ } else if (newDiffValue) {
1429
+ this.__unsubscribe();
1430
+ }
1431
+ }
1432
+
1433
+ /** @protected */
1434
+ disconnectedCallback() {
1435
+ super.disconnectedCallback();
1436
+ this.__restoreSubscription = directionSubscribers.includes(this);
1437
+ this.__unsubscribe();
1438
+ }
1439
+
1440
+ /** @protected */
1441
+ _valueToNodeAttribute(node, value, attribute) {
1442
+ // Override default Polymer attribute reflection to match native behavior of HTMLElement.dir property
1443
+ // If the property contains an empty string then it should not create an empty attribute
1444
+ if (attribute === 'dir' && value === '' && !node.hasAttribute('dir')) {
1445
+ return;
1446
+ }
1447
+ super._valueToNodeAttribute(node, value, attribute);
1448
+ }
1449
+
1450
+ /** @protected */
1451
+ _attributeToProperty(attribute, value, type) {
1452
+ // Override default Polymer attribute reflection to match native behavior of HTMLElement.dir property
1453
+ // If the attribute is removed, then the dir property should contain an empty string instead of null
1454
+ if (attribute === 'dir' && !value) {
1455
+ this.dir = '';
1456
+ } else {
1457
+ super._attributeToProperty(attribute, value, type);
1458
+ }
1459
+ }
1460
+
1461
+ /** @private */
1462
+ __subscribe() {
1463
+ if (!directionSubscribers.includes(this)) {
1464
+ directionSubscribers.push(this);
1465
+ }
1466
+ }
1467
+
1468
+ /** @private */
1469
+ __unsubscribe() {
1470
+ if (directionSubscribers.includes(this)) {
1471
+ directionSubscribers.splice(directionSubscribers.indexOf(this), 1);
1472
+ }
1473
+ }
1474
+ };
1475
+
1476
+ /**
1477
+ * @license
1478
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
1479
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1480
+ */
1481
+
1482
+ if (!window.Vaadin) {
1483
+ window.Vaadin = {};
1484
+ }
1485
+
1486
+ /**
1487
+ * Array of Vaadin custom element classes that have been finalized.
1488
+ */
1489
+ if (!window.Vaadin.registrations) {
1490
+ window.Vaadin.registrations = [];
1491
+ }
1492
+
1493
+ if (!window.Vaadin.developmentModeCallback) {
1494
+ window.Vaadin.developmentModeCallback = {};
1495
+ }
1496
+
1497
+ window.Vaadin.developmentModeCallback['vaadin-usage-statistics'] = function () {
1498
+ usageStatistics();
1499
+ };
1500
+
1501
+ let statsJob;
1502
+
1503
+ const registered = new Set();
1504
+
1505
+ /**
1506
+ * @polymerMixin
1507
+ * @mixes DirMixin
1508
+ */
1509
+ const ElementMixin = (superClass) =>
1510
+ class VaadinElementMixin extends DirMixin(superClass) {
1511
+ static get version() {
1512
+ return '24.2.3';
1513
+ }
1514
+
1515
+ /** @protected */
1516
+ static finalize() {
1517
+ super.finalize();
1518
+
1519
+ const { is } = this;
1520
+
1521
+ // Registers a class prototype for telemetry purposes.
1522
+ if (is && !registered.has(is)) {
1523
+ window.Vaadin.registrations.push(this);
1524
+ registered.add(is);
1525
+
1526
+ if (window.Vaadin.developmentModeCallback) {
1527
+ statsJob = Debouncer.debounce(statsJob, idlePeriod, () => {
1528
+ window.Vaadin.developmentModeCallback['vaadin-usage-statistics']();
1529
+ });
1530
+ enqueueDebouncer(statsJob);
1531
+ }
1532
+ }
1533
+ }
1534
+
1535
+ constructor() {
1536
+ super();
1537
+
1538
+ if (document.doctype === null) {
1539
+ console.warn(
1540
+ 'Vaadin components require the "standards mode" declaration. Please add <!DOCTYPE html> to the HTML document.',
1541
+ );
1542
+ }
1543
+ }
1544
+ };
1545
+
1546
+ /**
1547
+ * @license
1548
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
1549
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1550
+ */
1551
+
1552
+ /**
1553
+ * Returns true if the given node is an empty text node, false otherwise.
1554
+ *
1555
+ * @param {Node} node
1556
+ * @return {boolean}
1557
+ */
1558
+ function isEmptyTextNode(node) {
1559
+ return node.nodeType === Node.TEXT_NODE && node.textContent.trim() === '';
1560
+ }
1561
+
1562
+ /**
1563
+ * @license
1564
+ * Copyright (c) 2023 Vaadin Ltd.
1565
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1566
+ */
1567
+
1568
+ /**
1569
+ * A helper for observing slot changes.
1570
+ */
1571
+ class SlotObserver {
1572
+ constructor(slot, callback) {
1573
+ /** @type HTMLSlotElement */
1574
+ this.slot = slot;
1575
+
1576
+ /** @type Function */
1577
+ this.callback = callback;
1578
+
1579
+ /** @type {Node[]} */
1580
+ this._storedNodes = [];
36
1581
 
37
- :host([theme~='small']) {
38
- font-size: var(--lumo-font-size-s);
39
- --lumo-button-size: var(--lumo-size-s);
1582
+ this._connected = false;
1583
+ this._scheduled = false;
1584
+
1585
+ this._boundSchedule = () => {
1586
+ this._schedule();
1587
+ };
1588
+
1589
+ this.connect();
1590
+ this._schedule();
40
1591
  }
41
1592
 
42
- :host([theme~='large']) {
43
- font-size: var(--lumo-font-size-l);
44
- --lumo-button-size: var(--lumo-size-l);
1593
+ /**
1594
+ * Activates an observer. This method is automatically called when
1595
+ * a `SlotObserver` is created. It should only be called to re-activate
1596
+ * an observer that has been deactivated via the `disconnect` method.
1597
+ */
1598
+ connect() {
1599
+ this.slot.addEventListener('slotchange', this._boundSchedule);
1600
+ this._connected = true;
45
1601
  }
46
1602
 
47
- /* For interaction states */
48
- :host::before,
49
- :host::after {
50
- content: '';
51
- /* We rely on the host always being relative */
52
- position: absolute;
53
- z-index: 1;
54
- top: 0;
55
- right: 0;
56
- bottom: 0;
57
- left: 0;
58
- background-color: currentColor;
59
- border-radius: inherit;
60
- opacity: 0;
61
- pointer-events: none;
1603
+ /**
1604
+ * Deactivates the observer. After calling this method the observer callback
1605
+ * will not be called when changes to slotted nodes occur. The `connect` method
1606
+ * may be subsequently called to reactivate the observer.
1607
+ */
1608
+ disconnect() {
1609
+ this.slot.removeEventListener('slotchange', this._boundSchedule);
1610
+ this._connected = false;
62
1611
  }
63
1612
 
64
- /* Hover */
1613
+ /** @private */
1614
+ _schedule() {
1615
+ if (!this._scheduled) {
1616
+ this._scheduled = true;
65
1617
 
66
- @media (any-hover: hover) {
67
- :host(:hover)::before {
68
- opacity: 0.02;
1618
+ queueMicrotask(() => {
1619
+ this.flush();
1620
+ });
69
1621
  }
70
1622
  }
71
1623
 
72
- /* Active */
1624
+ /**
1625
+ * Run the observer callback synchronously.
1626
+ */
1627
+ flush() {
1628
+ if (!this._connected) {
1629
+ return;
1630
+ }
73
1631
 
74
- :host::after {
75
- transition: opacity 1.4s, transform 0.1s;
76
- filter: blur(8px);
77
- }
1632
+ this._scheduled = false;
78
1633
 
79
- :host([active])::before {
80
- opacity: 0.05;
81
- transition-duration: 0s;
1634
+ this._processNodes();
82
1635
  }
83
1636
 
84
- :host([active])::after {
85
- opacity: 0.1;
86
- transition-duration: 0s, 0s;
87
- transform: scale(0);
88
- }
1637
+ /** @private */
1638
+ _processNodes() {
1639
+ const currentNodes = this.slot.assignedNodes({ flatten: true });
89
1640
 
90
- /* Keyboard focus */
1641
+ let addedNodes = [];
1642
+ const removedNodes = [];
1643
+ const movedNodes = [];
91
1644
 
92
- :host([focus-ring]) {
93
- box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
1645
+ if (currentNodes.length) {
1646
+ addedNodes = currentNodes.filter((node) => !this._storedNodes.includes(node));
1647
+ }
1648
+
1649
+ if (this._storedNodes.length) {
1650
+ this._storedNodes.forEach((node, index) => {
1651
+ const idx = currentNodes.indexOf(node);
1652
+ if (idx === -1) {
1653
+ removedNodes.push(node);
1654
+ } else if (idx !== index) {
1655
+ movedNodes.push(node);
1656
+ }
1657
+ });
1658
+ }
1659
+
1660
+ if (addedNodes.length || removedNodes.length || movedNodes.length) {
1661
+ this.callback({ addedNodes, movedNodes, removedNodes });
1662
+ }
1663
+
1664
+ this._storedNodes = currentNodes;
94
1665
  }
1666
+ }
95
1667
 
96
- :host([theme~='primary'][focus-ring]) {
97
- box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px var(--lumo-primary-color-50pct);
1668
+ /**
1669
+ * @license
1670
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
1671
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1672
+ */
1673
+
1674
+ let uniqueId = 0;
1675
+
1676
+ /**
1677
+ * Returns a unique integer id.
1678
+ *
1679
+ * @return {number}
1680
+ */
1681
+ function generateUniqueId() {
1682
+ // eslint-disable-next-line no-plusplus
1683
+ return uniqueId++;
1684
+ }
1685
+
1686
+ /**
1687
+ * @license
1688
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
1689
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1690
+ */
1691
+
1692
+ /**
1693
+ * A controller for providing content to slot element and observing changes.
1694
+ */
1695
+ class SlotController extends EventTarget {
1696
+ /**
1697
+ * Ensure that every instance has unique ID.
1698
+ *
1699
+ * @param {HTMLElement} host
1700
+ * @param {string} slotName
1701
+ * @return {string}
1702
+ * @protected
1703
+ */
1704
+ static generateId(host, slotName) {
1705
+ const prefix = slotName || 'default';
1706
+ return `${prefix}-${host.localName}-${generateUniqueId()}`;
98
1707
  }
99
1708
 
100
- /* Types (primary, tertiary, tertiary-inline */
1709
+ constructor(host, slotName, tagName, config = {}) {
1710
+ super();
101
1711
 
102
- :host([theme~='tertiary']),
103
- :host([theme~='tertiary-inline']) {
104
- background-color: transparent !important;
105
- min-width: 0;
1712
+ const { initializer, multiple, observe, useUniqueId } = config;
1713
+
1714
+ this.host = host;
1715
+ this.slotName = slotName;
1716
+ this.tagName = tagName;
1717
+ this.observe = typeof observe === 'boolean' ? observe : true;
1718
+ this.multiple = typeof multiple === 'boolean' ? multiple : false;
1719
+ this.slotInitializer = initializer;
1720
+
1721
+ if (multiple) {
1722
+ this.nodes = [];
1723
+ }
1724
+
1725
+ // Only generate the default ID if requested by the controller.
1726
+ if (useUniqueId) {
1727
+ this.defaultId = this.constructor.generateId(host, slotName);
1728
+ }
106
1729
  }
107
1730
 
108
- :host([theme~='tertiary']) {
109
- padding: 0 calc(var(--lumo-button-size) / 6);
1731
+ hostConnected() {
1732
+ if (!this.initialized) {
1733
+ if (this.multiple) {
1734
+ this.initMultiple();
1735
+ } else {
1736
+ this.initSingle();
1737
+ }
1738
+
1739
+ if (this.observe) {
1740
+ this.observeSlot();
1741
+ }
1742
+
1743
+ this.initialized = true;
1744
+ }
110
1745
  }
111
1746
 
112
- :host([theme~='tertiary-inline'])::before {
113
- display: none;
1747
+ /** @protected */
1748
+ initSingle() {
1749
+ let node = this.getSlotChild();
1750
+
1751
+ if (!node) {
1752
+ node = this.attachDefaultNode();
1753
+ this.initNode(node);
1754
+ } else {
1755
+ this.node = node;
1756
+ this.initAddedNode(node);
1757
+ }
114
1758
  }
115
1759
 
116
- :host([theme~='tertiary-inline']) {
117
- margin: 0;
118
- height: auto;
119
- padding: 0;
120
- line-height: inherit;
121
- font-size: inherit;
1760
+ /** @protected */
1761
+ initMultiple() {
1762
+ const children = this.getSlotChildren();
1763
+
1764
+ if (children.length === 0) {
1765
+ const defaultNode = this.attachDefaultNode();
1766
+ if (defaultNode) {
1767
+ this.nodes = [defaultNode];
1768
+ this.initNode(defaultNode);
1769
+ }
1770
+ } else {
1771
+ this.nodes = children;
1772
+ children.forEach((node) => {
1773
+ this.initAddedNode(node);
1774
+ });
1775
+ }
122
1776
  }
123
1777
 
124
- :host([theme~='tertiary-inline']) [part='label'] {
125
- padding: 0;
126
- overflow: visible;
127
- line-height: inherit;
1778
+ /**
1779
+ * Create and attach default node using the provided tag name, if any.
1780
+ * @return {Node | undefined}
1781
+ * @protected
1782
+ */
1783
+ attachDefaultNode() {
1784
+ const { host, slotName, tagName } = this;
1785
+
1786
+ // Check if the node was created previously and if so, reuse it.
1787
+ let node = this.defaultNode;
1788
+
1789
+ // Tag name is optional, sometimes we don't init default content.
1790
+ if (!node && tagName) {
1791
+ node = document.createElement(tagName);
1792
+ if (node instanceof Element) {
1793
+ if (slotName !== '') {
1794
+ node.setAttribute('slot', slotName);
1795
+ }
1796
+ this.node = node;
1797
+ this.defaultNode = node;
1798
+ }
1799
+ }
1800
+
1801
+ if (node) {
1802
+ host.appendChild(node);
1803
+ }
1804
+
1805
+ return node;
128
1806
  }
129
1807
 
130
- :host([theme~='primary']) {
131
- background-color: var(--_lumo-button-primary-background-color, var(--lumo-primary-color));
132
- color: var(--_lumo-button-primary-color, var(--lumo-primary-contrast-color));
133
- font-weight: 600;
134
- min-width: calc(var(--lumo-button-size) * 2.5);
1808
+ /**
1809
+ * Return the list of nodes matching the slot managed by the controller.
1810
+ * @return {Node}
1811
+ */
1812
+ getSlotChildren() {
1813
+ const { slotName } = this;
1814
+ return Array.from(this.host.childNodes).filter((node) => {
1815
+ // Either an element (any slot) or a text node (only un-named slot).
1816
+ return (
1817
+ (node.nodeType === Node.ELEMENT_NODE && node.slot === slotName) ||
1818
+ (node.nodeType === Node.TEXT_NODE && node.textContent.trim() && slotName === '')
1819
+ );
1820
+ });
135
1821
  }
136
1822
 
137
- :host([theme~='primary'])::before {
138
- background-color: black;
1823
+ /**
1824
+ * Return a reference to the node managed by the controller.
1825
+ * @return {Node}
1826
+ */
1827
+ getSlotChild() {
1828
+ return this.getSlotChildren()[0];
139
1829
  }
140
1830
 
141
- @media (any-hover: hover) {
142
- :host([theme~='primary']:hover)::before {
143
- opacity: 0.05;
1831
+ /**
1832
+ * Run `slotInitializer` for the node managed by the controller.
1833
+ *
1834
+ * @param {Node} node
1835
+ * @protected
1836
+ */
1837
+ initNode(node) {
1838
+ const { slotInitializer } = this;
1839
+ // Don't try to bind `this` to initializer (normally it's arrow function).
1840
+ // Instead, pass the host as a first argument to access component's state.
1841
+ if (slotInitializer) {
1842
+ slotInitializer(node, this.host);
144
1843
  }
145
1844
  }
146
1845
 
147
- :host([theme~='primary'][active])::before {
148
- opacity: 0.1;
1846
+ /**
1847
+ * Override to initialize the newly added custom node.
1848
+ *
1849
+ * @param {Node} _node
1850
+ * @protected
1851
+ */
1852
+ initCustomNode(_node) {}
1853
+
1854
+ /**
1855
+ * Override to teardown slotted node when it's removed.
1856
+ *
1857
+ * @param {Node} _node
1858
+ * @protected
1859
+ */
1860
+ teardownNode(_node) {}
1861
+
1862
+ /**
1863
+ * Run both `initCustomNode` and `initNode` for a custom slotted node.
1864
+ *
1865
+ * @param {Node} node
1866
+ * @protected
1867
+ */
1868
+ initAddedNode(node) {
1869
+ if (node !== this.defaultNode) {
1870
+ this.initCustomNode(node);
1871
+ this.initNode(node);
1872
+ }
149
1873
  }
150
1874
 
151
- :host([theme~='primary'][active])::after {
152
- opacity: 0.2;
1875
+ /**
1876
+ * Setup the observer to manage slot content changes.
1877
+ * @protected
1878
+ */
1879
+ observeSlot() {
1880
+ const { slotName } = this;
1881
+ const selector = slotName === '' ? 'slot:not([name])' : `slot[name=${slotName}]`;
1882
+ const slot = this.host.shadowRoot.querySelector(selector);
1883
+
1884
+ this.__slotObserver = new SlotObserver(slot, ({ addedNodes, removedNodes }) => {
1885
+ const current = this.multiple ? this.nodes : [this.node];
1886
+
1887
+ // Calling `slot.assignedNodes()` includes whitespace text nodes in case of default slot:
1888
+ // unlike comment nodes, they are not filtered out. So we need to manually ignore them.
1889
+ const newNodes = addedNodes.filter((node) => !isEmptyTextNode(node) && !current.includes(node));
1890
+
1891
+ if (removedNodes.length) {
1892
+ this.nodes = current.filter((node) => !removedNodes.includes(node));
1893
+
1894
+ removedNodes.forEach((node) => {
1895
+ this.teardownNode(node);
1896
+ });
1897
+ }
1898
+
1899
+ if (newNodes && newNodes.length > 0) {
1900
+ if (this.multiple) {
1901
+ // Remove default node if exists
1902
+ if (this.defaultNode) {
1903
+ this.defaultNode.remove();
1904
+ }
1905
+ this.nodes = [...current, ...newNodes].filter((node) => node !== this.defaultNode);
1906
+ newNodes.forEach((node) => {
1907
+ this.initAddedNode(node);
1908
+ });
1909
+ } else {
1910
+ // Remove previous node if exists
1911
+ if (this.node) {
1912
+ this.node.remove();
1913
+ }
1914
+ this.node = newNodes[0];
1915
+ this.initAddedNode(this.node);
1916
+ }
1917
+ }
1918
+ });
153
1919
  }
1920
+ }
154
1921
 
155
- /* Colors (success, error, contrast) */
1922
+ /**
1923
+ * @license
1924
+ * Copyright (c) 2022 - 2023 Vaadin Ltd.
1925
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
1926
+ */
156
1927
 
157
- :host([theme~='success']) {
158
- color: var(--lumo-success-text-color);
1928
+ /**
1929
+ * A controller that manages the slotted tooltip element.
1930
+ */
1931
+ class TooltipController extends SlotController {
1932
+ constructor(host) {
1933
+ // Do not provide slot factory to create tooltip lazily.
1934
+ super(host, 'tooltip');
1935
+
1936
+ this.setTarget(host);
159
1937
  }
160
1938
 
161
- :host([theme~='success'][theme~='primary']) {
162
- background-color: var(--lumo-success-color);
163
- color: var(--lumo-success-contrast-color);
1939
+ /**
1940
+ * Override to initialize the newly added custom tooltip.
1941
+ *
1942
+ * @param {Node} tooltipNode
1943
+ * @protected
1944
+ * @override
1945
+ */
1946
+ initCustomNode(tooltipNode) {
1947
+ tooltipNode.target = this.target;
1948
+
1949
+ if (this.ariaTarget !== undefined) {
1950
+ tooltipNode.ariaTarget = this.ariaTarget;
1951
+ }
1952
+
1953
+ if (this.context !== undefined) {
1954
+ tooltipNode.context = this.context;
1955
+ }
1956
+
1957
+ if (this.manual !== undefined) {
1958
+ tooltipNode.manual = this.manual;
1959
+ }
1960
+
1961
+ if (this.opened !== undefined) {
1962
+ tooltipNode.opened = this.opened;
1963
+ }
1964
+
1965
+ if (this.position !== undefined) {
1966
+ tooltipNode._position = this.position;
1967
+ }
1968
+
1969
+ if (this.shouldShow !== undefined) {
1970
+ tooltipNode.shouldShow = this.shouldShow;
1971
+ }
1972
+
1973
+ this.__notifyChange();
164
1974
  }
165
1975
 
166
- :host([theme~='error']) {
167
- color: var(--lumo-error-text-color);
1976
+ /**
1977
+ * Override to notify the host when the tooltip is removed.
1978
+ *
1979
+ * @param {Node} tooltipNode
1980
+ * @protected
1981
+ * @override
1982
+ */
1983
+ teardownNode() {
1984
+ this.__notifyChange();
168
1985
  }
169
1986
 
170
- :host([theme~='error'][theme~='primary']) {
171
- background-color: var(--lumo-error-color);
172
- color: var(--lumo-error-contrast-color);
1987
+ /**
1988
+ * Set an HTML element for linking with the tooltip overlay
1989
+ * via `aria-describedby` attribute used by screen readers.
1990
+ * @param {HTMLElement} ariaTarget
1991
+ */
1992
+ setAriaTarget(ariaTarget) {
1993
+ this.ariaTarget = ariaTarget;
1994
+
1995
+ const tooltipNode = this.node;
1996
+ if (tooltipNode) {
1997
+ tooltipNode.ariaTarget = ariaTarget;
1998
+ }
173
1999
  }
174
2000
 
175
- :host([theme~='contrast']) {
176
- color: var(--lumo-contrast);
2001
+ /**
2002
+ * Set a context object to be used by generator.
2003
+ * @param {object} context
2004
+ */
2005
+ setContext(context) {
2006
+ this.context = context;
2007
+
2008
+ const tooltipNode = this.node;
2009
+ if (tooltipNode) {
2010
+ tooltipNode.context = context;
2011
+ }
177
2012
  }
178
2013
 
179
- :host([theme~='contrast'][theme~='primary']) {
180
- background-color: var(--lumo-contrast);
181
- color: var(--lumo-base-color);
2014
+ /**
2015
+ * Toggle manual state on the slotted tooltip.
2016
+ * @param {boolean} manual
2017
+ */
2018
+ setManual(manual) {
2019
+ this.manual = manual;
2020
+
2021
+ const tooltipNode = this.node;
2022
+ if (tooltipNode) {
2023
+ tooltipNode.manual = manual;
2024
+ }
182
2025
  }
183
2026
 
184
- /* Disabled state. Keep selectors after other color variants. */
2027
+ /**
2028
+ * Toggle opened state on the slotted tooltip.
2029
+ * @param {boolean} opened
2030
+ */
2031
+ setOpened(opened) {
2032
+ this.opened = opened;
185
2033
 
186
- :host([disabled]) {
187
- pointer-events: none;
188
- color: var(--lumo-disabled-text-color);
2034
+ const tooltipNode = this.node;
2035
+ if (tooltipNode) {
2036
+ tooltipNode.opened = opened;
2037
+ }
189
2038
  }
190
2039
 
191
- :host([theme~='primary'][disabled]) {
192
- background-color: var(--lumo-contrast-30pct);
193
- color: var(--lumo-base-color);
2040
+ /**
2041
+ * Set default position for the slotted tooltip.
2042
+ * This can be overridden by setting the position
2043
+ * using corresponding property or attribute.
2044
+ * @param {string} position
2045
+ */
2046
+ setPosition(position) {
2047
+ this.position = position;
2048
+
2049
+ const tooltipNode = this.node;
2050
+ if (tooltipNode) {
2051
+ tooltipNode._position = position;
2052
+ }
194
2053
  }
195
2054
 
196
- :host([theme~='primary'][disabled]) [part] {
197
- opacity: 0.7;
2055
+ /**
2056
+ * Set function used to detect whether to show
2057
+ * the tooltip based on a condition.
2058
+ * @param {Function} shouldShow
2059
+ */
2060
+ setShouldShow(shouldShow) {
2061
+ this.shouldShow = shouldShow;
2062
+
2063
+ const tooltipNode = this.node;
2064
+ if (tooltipNode) {
2065
+ tooltipNode.shouldShow = shouldShow;
2066
+ }
198
2067
  }
199
2068
 
200
- /* Icons */
2069
+ /**
2070
+ * Set an HTML element to attach the tooltip to.
2071
+ * @param {HTMLElement} target
2072
+ */
2073
+ setTarget(target) {
2074
+ this.target = target;
201
2075
 
202
- [part] ::slotted(vaadin-icon),
203
- [part] ::slotted(iron-icon) {
204
- display: inline-block;
205
- width: var(--lumo-icon-size-m);
206
- height: var(--lumo-icon-size-m);
2076
+ const tooltipNode = this.node;
2077
+ if (tooltipNode) {
2078
+ tooltipNode.target = target;
2079
+ }
207
2080
  }
208
2081
 
209
- /* Vaadin icons are based on a 16x16 grid (unlike Lumo and Material icons with 24x24), so they look too big by default */
210
- [part] ::slotted(vaadin-icon[icon^='vaadin:']),
211
- [part] ::slotted(iron-icon[icon^='vaadin:']) {
212
- padding: 0.25em;
213
- box-sizing: border-box !important;
2082
+ /** @private */
2083
+ __notifyChange() {
2084
+ this.dispatchEvent(new CustomEvent('tooltip-changed', { detail: { node: this.node } }));
214
2085
  }
2086
+ }
215
2087
 
216
- [part='prefix'] {
217
- margin-left: -0.25em;
218
- margin-right: 0.25em;
219
- }
2088
+ /**
2089
+ * @license
2090
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
2091
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
2092
+ */
220
2093
 
221
- [part='suffix'] {
222
- margin-left: 0.25em;
223
- margin-right: -0.25em;
2094
+ const buttonStyles = i`
2095
+ :host {
2096
+ display: inline-block;
2097
+ position: relative;
2098
+ outline: none;
2099
+ white-space: nowrap;
2100
+ -webkit-user-select: none;
2101
+ -moz-user-select: none;
2102
+ user-select: none;
224
2103
  }
225
2104
 
226
- /* Icon-only */
227
-
228
- :host([theme~='icon']:not([theme~='tertiary-inline'])) {
229
- min-width: var(--lumo-button-size);
230
- padding-left: calc(var(--lumo-button-size) / 4);
231
- padding-right: calc(var(--lumo-button-size) / 4);
2105
+ :host([hidden]) {
2106
+ display: none !important;
232
2107
  }
233
2108
 
234
- :host([theme~='icon']) [part='prefix'],
235
- :host([theme~='icon']) [part='suffix'] {
236
- margin-left: 0;
237
- margin-right: 0;
2109
+ /* Aligns the button with form fields when placed on the same line.
2110
+ Note, to make it work, the form fields should have the same "::before" pseudo-element. */
2111
+ .vaadin-button-container::before {
2112
+ content: '\\2003';
2113
+ display: inline-block;
2114
+ width: 0;
2115
+ max-height: 100%;
238
2116
  }
239
2117
 
240
- /* RTL specific styles */
2118
+ .vaadin-button-container {
2119
+ display: inline-flex;
2120
+ align-items: center;
2121
+ justify-content: center;
2122
+ text-align: center;
2123
+ width: 100%;
2124
+ height: 100%;
2125
+ min-height: inherit;
2126
+ text-shadow: inherit;
2127
+ }
241
2128
 
242
- :host([dir='rtl']) [part='prefix'] {
243
- margin-left: 0.25em;
244
- margin-right: -0.25em;
2129
+ [part='prefix'],
2130
+ [part='suffix'] {
2131
+ flex: none;
245
2132
  }
246
2133
 
247
- :host([dir='rtl']) [part='suffix'] {
248
- margin-left: -0.25em;
249
- margin-right: 0.25em;
2134
+ [part='label'] {
2135
+ white-space: nowrap;
2136
+ overflow: hidden;
2137
+ text-overflow: ellipsis;
250
2138
  }
251
2139
 
252
- :host([dir='rtl'][theme~='icon']) [part='prefix'],
253
- :host([dir='rtl'][theme~='icon']) [part='suffix'] {
254
- margin-left: 0;
255
- margin-right: 0;
2140
+ @media (forced-colors: active) {
2141
+ :host {
2142
+ outline: 1px solid;
2143
+ outline-offset: -1px;
2144
+ }
2145
+
2146
+ :host([focused]) {
2147
+ outline-width: 2px;
2148
+ }
2149
+
2150
+ :host([disabled]) {
2151
+ outline-color: GrayText;
2152
+ }
256
2153
  }
257
2154
  `;
258
2155
 
259
- registerStyles('vaadin-button', button, { moduleId: 'lumo-button' });
2156
+ const buttonTemplate = (html) => html`
2157
+ <div class="vaadin-button-container">
2158
+ <span part="prefix" aria-hidden="true">
2159
+ <slot name="prefix"></slot>
2160
+ </span>
2161
+ <span part="label">
2162
+ <slot></slot>
2163
+ </span>
2164
+ <span part="suffix" aria-hidden="true">
2165
+ <slot name="suffix"></slot>
2166
+ </span>
2167
+ </div>
2168
+ <slot name="tooltip"></slot>
2169
+ `;
260
2170
 
261
2171
  /**
262
2172
  * @license
263
- * Copyright (c) 2017 - 2022 Vaadin Ltd.
2173
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
264
2174
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
265
2175
  */
266
2176
 
@@ -283,7 +2193,9 @@ const ButtonMixin = (superClass) =>
283
2193
  * @protected
284
2194
  */
285
2195
  tabindex: {
2196
+ type: Number,
286
2197
  value: 0,
2198
+ reflectToAttribute: true,
287
2199
  },
288
2200
  };
289
2201
  }
@@ -329,6 +2241,10 @@ const ButtonMixin = (superClass) =>
329
2241
  _onKeyDown(event) {
330
2242
  super._onKeyDown(event);
331
2243
 
2244
+ if (event.altKey || event.shiftKey || event.ctrlKey || event.metaKey) {
2245
+ return;
2246
+ }
2247
+
332
2248
  if (this._activeKeys.includes(event.key)) {
333
2249
  event.preventDefault();
334
2250
 
@@ -341,10 +2257,12 @@ const ButtonMixin = (superClass) =>
341
2257
 
342
2258
  /**
343
2259
  * @license
344
- * Copyright (c) 2017 - 2022 Vaadin Ltd.
2260
+ * Copyright (c) 2017 - 2023 Vaadin Ltd.
345
2261
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
346
2262
  */
347
2263
 
2264
+ registerStyles('vaadin-button', buttonStyles, { moduleId: 'vaadin-button-styles' });
2265
+
348
2266
  /**
349
2267
  * `<vaadin-button>` is an accessible and customizable button that allows users to perform actions.
350
2268
  *
@@ -371,8 +2289,9 @@ const ButtonMixin = (superClass) =>
371
2289
  * `focus-ring` | Set when the button is focused using the keyboard.
372
2290
  * `focused` | Set when the button is focused.
373
2291
  *
374
- * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
2292
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
375
2293
  *
2294
+ * @customElement
376
2295
  * @extends HTMLElement
377
2296
  * @mixes ButtonMixin
378
2297
  * @mixes ControllerMixin
@@ -385,66 +2304,7 @@ class Button extends ButtonMixin(ElementMixin(ThemableMixin(ControllerMixin(Poly
385
2304
  }
386
2305
 
387
2306
  static get template() {
388
- return html`
389
- <style>
390
- :host {
391
- display: inline-block;
392
- position: relative;
393
- outline: none;
394
- white-space: nowrap;
395
- -webkit-user-select: none;
396
- -moz-user-select: none;
397
- user-select: none;
398
- }
399
-
400
- :host([hidden]) {
401
- display: none !important;
402
- }
403
-
404
- /* Aligns the button with form fields when placed on the same line.
405
- Note, to make it work, the form fields should have the same "::before" pseudo-element. */
406
- .vaadin-button-container::before {
407
- content: '\\2003';
408
- display: inline-block;
409
- width: 0;
410
- max-height: 100%;
411
- }
412
-
413
- .vaadin-button-container {
414
- display: inline-flex;
415
- align-items: center;
416
- justify-content: center;
417
- text-align: center;
418
- width: 100%;
419
- height: 100%;
420
- min-height: inherit;
421
- text-shadow: inherit;
422
- }
423
-
424
- [part='prefix'],
425
- [part='suffix'] {
426
- flex: none;
427
- }
428
-
429
- [part='label'] {
430
- white-space: nowrap;
431
- overflow: hidden;
432
- text-overflow: ellipsis;
433
- }
434
- </style>
435
- <div class="vaadin-button-container">
436
- <span part="prefix" aria-hidden="true">
437
- <slot name="prefix"></slot>
438
- </span>
439
- <span part="label">
440
- <slot></slot>
441
- </span>
442
- <span part="suffix" aria-hidden="true">
443
- <slot name="suffix"></slot>
444
- </span>
445
- </div>
446
- <slot name="tooltip"></slot>
447
- `;
2307
+ return buttonTemplate(html);
448
2308
  }
449
2309
 
450
2310
  /** @protected */
@@ -456,6 +2316,6 @@ class Button extends ButtonMixin(ElementMixin(ThemableMixin(ControllerMixin(Poly
456
2316
  }
457
2317
  }
458
2318
 
459
- customElements.define(Button.is, Button);
2319
+ defineCustomElement(Button);
460
2320
 
461
2321
  export { Button as B, button as b };