@italia/accordion 0.1.0-alpha.2 → 1.0.0-alpha.4

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,19 +1,1805 @@
1
- import { _ as __decorate, a as __metadata } from '../form-control-ddGGHusp.js';
2
- import { property, customElement } from 'lit/decorators.js';
3
- import { html, nothing } from 'lit';
1
+ import { s as styles$1, _ as __decorate$1, a as __metadata$1 } from '../accordion-DrJ-1sEg.js';
2
+ import { state, query, property, queryAssignedElements, customElement } from 'lit/decorators.js';
3
+ import { css, html, LitElement, nothing } from 'lit';
4
4
  import { unsafeStatic, html as html$1 } from 'lit/static-html.js';
5
- import { ItCollapse } from './it-collapse.js';
6
- import { s as styles } from '../accordion-Du1RVx-L.js';
7
- import 'lit/directive.js';
8
- import 'lit/directives/when.js';
5
+ import { directive, Directive } from 'lit/directive.js';
6
+ import { when } from 'lit/directives/when.js';
9
7
 
10
- let ItAccordionItem = class ItAccordionItem extends ItCollapse {
8
+ /******************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
23
+
24
+
25
+ function __decorate(decorators, target, key, desc) {
26
+ var c = arguments.length, r = c < 3 ? target : desc, d;
27
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
30
+ }
31
+
32
+ function __metadata(metadataKey, metadataValue) {
33
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
34
+ }
35
+
36
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
37
+ var e = new Error(message);
38
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
39
+ };
40
+
41
+ class SetAttributesDirective extends Directive {
42
+ update(part, [attributes]) {
43
+ const el = part.element;
44
+ for (const [name, value] of Object.entries(attributes)) {
45
+ if (value != null)
46
+ el.setAttribute(name, value);
47
+ else
48
+ el.removeAttribute(name);
49
+ }
50
+ return null;
51
+ }
52
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
+ render(_attributes) {
54
+ return null;
55
+ }
56
+ }
57
+ /* How to use:
58
+
59
+ <textarea ${setAttributes(this._ariaAttributes)} ... />
60
+ */
61
+ directive(SetAttributesDirective);
62
+
63
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
64
+
65
+ const connectedElements = new Set();
66
+ if (window && !window.translations) {
67
+ window.translations = new Map();
68
+ }
69
+ const { translations } = window;
70
+ let fallback;
71
+ // TODO: We need some way for users to be able to set these on the server.
72
+ let documentDirection = 'ltr';
73
+ // Fallback for server.
74
+ let documentLanguage = 'en';
75
+ const isClient = typeof MutationObserver !== 'undefined' &&
76
+ typeof document !== 'undefined' &&
77
+ typeof document.documentElement !== 'undefined';
78
+ /** Updates all localized elements that are currently connected */
79
+ function update() {
80
+ if (isClient) {
81
+ documentDirection = document.documentElement.dir || 'ltr';
82
+ documentLanguage = document.documentElement.lang || navigator.language;
83
+ }
84
+ [...connectedElements.keys()].forEach((el) => {
85
+ const litEl = el;
86
+ if (typeof litEl.requestUpdate === 'function') {
87
+ litEl.requestUpdate();
88
+ }
89
+ });
90
+ }
91
+ if (isClient) {
92
+ const documentElementObserver = new MutationObserver(update);
93
+ documentDirection = document.documentElement.dir || 'ltr';
94
+ documentLanguage = document.documentElement.lang || navigator.language;
95
+ // Watch for changes on <html lang>
96
+ documentElementObserver.observe(document.documentElement, {
97
+ attributes: true,
98
+ attributeFilter: ['dir', 'lang'],
99
+ });
100
+ }
101
+ /** Registers one or more translations */
102
+ function registerTranslation(...translation) {
103
+ translation.forEach((t) => {
104
+ const code = t.$code.toLowerCase();
105
+ if (translations.has(code)) {
106
+ // Merge translations that share the same language code
107
+ translations.set(code, { ...translations.get(code), ...t });
108
+ }
109
+ else {
110
+ translations.set(code, t);
111
+ }
112
+ // The first translation that's registered is the fallback
113
+ if (!fallback) {
114
+ fallback = t;
115
+ }
116
+ });
117
+ update();
118
+ }
119
+ window.registerTranslation = registerTranslation;
120
+ /**
121
+ * Localize Reactive Controller for components built with Lit
122
+ *
123
+ * To use this controller, import the class and instantiate it in a custom element constructor:
124
+ *
125
+ * private localize = new LocalizeController(this);
126
+ *
127
+ * This will add the element to the set and make it respond to changes to <html dir|lang> automatically. To make it
128
+ * respond to changes to its own dir|lang properties, make it a property:
129
+ *
130
+ * @property() dir: string;
131
+ * @property() lang: string;
132
+ *
133
+ * To use a translation method, call it like this:
134
+ *
135
+ * ${this.localize.term('term_key_here')}
136
+ * ${this.localize.date('2021-12-03')}
137
+ * ${this.localize.number(1000000)}
138
+ */
139
+ class LocalizeController {
140
+ constructor(host) {
141
+ this.host = host;
142
+ this.host.addController(this);
143
+ }
144
+ hostConnected() {
145
+ connectedElements.add(this.host);
146
+ }
147
+ hostDisconnected() {
148
+ connectedElements.delete(this.host);
149
+ }
150
+ /**
151
+ * Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to
152
+ * lowercase.
153
+ */
154
+ dir() {
155
+ return `${this.host.dir || documentDirection}`.toLowerCase();
156
+ }
157
+ /**
158
+ * Gets the host element's language as determined by the `lang` attribute. The return value is transformed to
159
+ * lowercase.
160
+ */
161
+ lang() {
162
+ return `${this.host.lang || documentLanguage}`.toLowerCase();
163
+ }
164
+ // eslint-disable-next-line class-methods-use-this
165
+ getTranslationData(lang) {
166
+ // Convert "en_US" to "en-US". Note that both underscores and dashes are allowed per spec, but underscores result in
167
+ // a RangeError by the call to `new Intl.Locale()`. See: https://unicode.org/reports/tr35/#unicode-locale-identifier
168
+ const locale = new Intl.Locale(lang.replace(/_/g, '-'));
169
+ const language = locale?.language.toLowerCase();
170
+ const region = locale?.region?.toLowerCase() ?? '';
171
+ const primary = translations.get(`${language}-${region}`);
172
+ const secondary = translations.get(language);
173
+ return { locale, language, region, primary, secondary };
174
+ }
175
+ /** Determines if the specified term exists, optionally checking the fallback translation. */
176
+ exists(key, options) {
177
+ const { primary, secondary } = this.getTranslationData(options.lang ?? this.lang());
178
+ const mergedOptions = {
179
+ includeFallback: false,
180
+ ...options,
181
+ };
182
+ if ((primary && primary[key]) ||
183
+ (secondary && secondary[key]) ||
184
+ (mergedOptions.includeFallback && fallback && fallback[key])) {
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+ /** Outputs a translated term. */
190
+ term(key, ...args) {
191
+ const { primary, secondary } = this.getTranslationData(this.lang());
192
+ let term;
193
+ // Look for a matching term using regionCode, code, then the fallback
194
+ if (primary && primary[key]) {
195
+ term = primary[key];
196
+ }
197
+ else if (secondary && secondary[key]) {
198
+ term = secondary[key];
199
+ }
200
+ else if (fallback && fallback[key]) {
201
+ term = fallback[key];
202
+ }
203
+ else {
204
+ // eslint-disable-next-line no-console
205
+ console.error(`No translation found for: ${String(key)}`);
206
+ return String(key);
207
+ }
208
+ if (typeof term === 'function') {
209
+ return term(...args);
210
+ }
211
+ return term;
212
+ }
213
+ /** Outputs a localized date in the specified format. */
214
+ date(dateToFormat, options) {
215
+ const date = new Date(dateToFormat);
216
+ return new Intl.DateTimeFormat(this.lang(), options).format(date);
217
+ }
218
+ /** Outputs a localized number in the specified format. */
219
+ number(numberToFormat, options) {
220
+ const num = Number(numberToFormat);
221
+ return Number.isNaN(num) ? '' : new Intl.NumberFormat(this.lang(), options).format(num);
222
+ }
223
+ /** Outputs a localized time in relative format. */
224
+ relativeTime(value, unit, options) {
225
+ return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);
226
+ }
227
+ }
228
+
229
+ /**
230
+ * @param Base The base class.
231
+ * @returns A mix-in implementing `localizations` method.
232
+ *
233
+ *@example
234
+ * <!-- Terms -->
235
+ ${this.$localize.term('hello')}
236
+ or
237
+ ${this.$t('hello')}
238
+
239
+ <!-- Dates -->
240
+ ${this.$localize.date('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}
241
+ or
242
+ ${this.$d('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}
243
+
244
+ <!-- Numbers/currency -->
245
+ ${this.$localize.number(1000, { style: 'currency', currency: 'USD'})}
246
+ or
247
+ ${this.$n(1000,{ style: 'currency', currency: 'USD'})}
248
+
249
+ <!-- Determining language -->
250
+ ${this.$localize.lang()}
251
+
252
+ <!-- Determining directionality, e.g. 'ltr' or 'rtl' -->
253
+ ${this.$localize.dir()}
254
+
255
+
256
+ *** HOW TO DEFINE TRANSLATIONS: ***
257
+ // Simple terms
258
+ upload: 'Upload',
259
+
260
+ // Terms with placeholders
261
+ greetUser: (name: string) => `Hello, ${name}!`,
262
+
263
+ // Plurals
264
+ numFilesSelected: (count: number) => {
265
+ if (count === 0) return 'No files selected';
266
+ if (count === 1) return '1 file selected';
267
+ return `${count} files selected`;
268
+ }
269
+ */
270
+ const LocalizeMixin = (Base) => class extends Base {
271
+ constructor() {
272
+ super(...arguments);
273
+ this.localize = new LocalizeController(this);
274
+ }
275
+ // Provide default values to avoid definite assignment errors and avoid decorators
276
+ // commentati perchè danno problemi su React.js. Sono attributi nativi, e assegnare un valore di default a react da fastidio
277
+ // dir: string = '';
278
+ // lang: string = '';
279
+ /**
280
+ * Restituisce tutta l'utility di traduzione
281
+ *
282
+
283
+ *
284
+ * @returns tutta l'utility di traduzione
285
+ *
286
+ * @example
287
+ * this.$localize.lang() -> ritorna la lingua corrente
288
+ * this.$localize.dir() -> ritorna la direzione della lingua corrente
289
+ */
290
+ get $localize() {
291
+ return this.localize;
292
+ }
293
+ /**
294
+ * Restituisce una stringa localizzata a partire da una chiave di termine.
295
+ *
296
+ * Utilizza il `LocalizeController` per accedere al dizionario corrente e
297
+ * tradurre la chiave fornita secondo la lingua attiva.
298
+ *
299
+ * @param t - La chiave del termine da localizzare (es. 'hello', 'submit', ecc.).
300
+ * @returns La stringa tradotta in base alla lingua attiva. Se la chiave non è trovata, restituisce la chiave stessa.
301
+ *
302
+ * @example
303
+ * this.$t('hello'); // → "Ciao" (in locale it-IT)
304
+ */
305
+ $t(t) {
306
+ // format term
307
+ return this.localize.term(t);
308
+ }
309
+ /**
310
+ * Formatta una data in base alla localizzazione attiva.
311
+ *
312
+ * Utilizza il `LocalizeController` per restituire una stringa localizzata
313
+ * secondo le opzioni fornite (es. mese esteso, anno, ecc.).
314
+ *
315
+ * @param n - La data da formattare come stringa compatibile (es. ISO o con timezone, es. '2021-09-15 14:00:00 ET').
316
+ * @param p - Le opzioni di formattazione per `Intl.DateTimeFormat` (es. { year: 'numeric', month: 'long', day: 'numeric' }).
317
+ * @returns Una stringa rappresentante la data formattata secondo la localizzazione attiva.
318
+ *
319
+ * @example
320
+ * this.$d('2021-09-15 14:00:00 ET', { year: 'numeric', month: 'long', day: 'numeric' });
321
+ * // → "15 settembre 2021" (in locale it-IT)
322
+ */
323
+ $d(d, p) {
324
+ // format date
325
+ return this.localize.date(d, p);
326
+ }
327
+ /**
328
+ * Formatta un numero secondo le impostazioni locali dell'utente corrente.
329
+ *
330
+ * Utilizza il `LocalizeController` per applicare formattazione numerica,
331
+ * incluse opzioni come separatori, decimali, valute, ecc.
332
+ *
333
+ * @param d - Il numero da formattare.
334
+ * @param p - Le opzioni di formattazione (es. { style: 'currency', currency: 'EUR' }).
335
+ * @returns Una stringa rappresentante il numero formattato secondo la localizzazione attiva.
336
+ *
337
+ * @example
338
+ * this.$n(1234.56, { style: 'currency', currency: 'USD' }); // → "$1,234.56" (in locale en-US)
339
+ */
340
+ $n(d, p) {
341
+ return this.localize.number(d, p);
342
+ }
343
+ };
344
+
345
+ /* eslint-disable no-console */
346
+ class Logger {
347
+ constructor(tag) {
348
+ this.tag = tag;
349
+ }
350
+ format(level, msg) {
351
+ return [`[${this.tag}] ${msg}`];
352
+ }
353
+ warn(msg) {
354
+ console.warn(...this.format('warn', msg));
355
+ }
356
+ error(msg) {
357
+ console.error(...this.format('error', msg));
358
+ }
359
+ info(msg) {
360
+ console.info(...this.format('info', msg));
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Factory function per creare una base class estendibile
366
+ * con stili personalizzati.
367
+ */
368
+ class BaseComponent extends LitElement {
369
+ constructor() {
370
+ super();
371
+ this.composeClass = clsx;
372
+ this.logger = new Logger(this.tagName.toLowerCase());
373
+ }
374
+ get _ariaAttributes() {
375
+ const attributes = {};
376
+ for (const attr of this.getAttributeNames()) {
377
+ if (attr === 'it-role') {
378
+ attributes.role = this.getAttribute(attr);
379
+ }
380
+ else if (attr.startsWith('it-aria-')) {
381
+ attributes[attr.replace(/^it-/, '')] = this.getAttribute(attr);
382
+ }
383
+ }
384
+ return attributes;
385
+ }
386
+ // eslint-disable-next-line class-methods-use-this
387
+ generateId(prefix) {
388
+ return `${prefix}-${Math.random().toString(36).slice(2)}`;
389
+ }
390
+ // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
391
+ addFocus(element) {
392
+ // new TrackFocus(element); // per il momento è stato disattivato perchè ci sono le pseudo classi ::focus-visible per fare quello che fa TrackFocus. Si possono aggiungere regole css in bsi-italia 3 dato che stiamo facendo una breaking release di bsi.
393
+ }
394
+ // eslint-disable-next-line class-methods-use-this
395
+ getActiveElement() {
396
+ let active = document.activeElement;
397
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
398
+ active = active.shadowRoot.activeElement;
399
+ }
400
+ return active;
401
+ }
402
+ get focusElement() {
403
+ return this;
404
+ }
405
+ // eslint-disable-next-line class-methods-use-this
406
+ get prefersReducedMotion() {
407
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
408
+ }
409
+ connectedCallback() {
410
+ super.connectedCallback();
411
+ // generate internal _id
412
+ const prefix = this.id?.length > 0 ? this.id : this.tagName.toLowerCase();
413
+ this._id = this.generateId(prefix);
414
+ }
415
+ }
416
+ const BaseLocalizedComponent = LocalizeMixin(BaseComponent);
417
+
418
+ //
419
+ // We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As
420
+ // elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is
421
+ // added and removed from the form's set, respectively.
422
+ //
423
+ const formCollections = new WeakMap();
424
+ //
425
+ // We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and
426
+ // restore the original behavior when they disconnect.
427
+ //
428
+ const reportValidityOverloads = new WeakMap();
429
+ const checkValidityOverloads = new WeakMap();
430
+ //
431
+ // We store a Set of controls that users have interacted with. This allows us to determine the interaction state
432
+ // without littering the DOM with additional data attributes.
433
+ //
434
+ const userInteractedControls = new WeakSet();
435
+ //
436
+ // We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.
437
+ //
438
+ const interactions = new WeakMap();
439
+ /** A reactive controller to allow form controls to participate in form submission, validation, etc. */
440
+ class FormControlController {
441
+ constructor(host, options) {
442
+ this.submittedOnce = false;
443
+ this.handleFormData = (event) => {
444
+ // console.log('handleFormData');
445
+ const disabled = this.options.disabled(this.host);
446
+ const name = this.options.name(this.host);
447
+ const value = this.options.value(this.host);
448
+ const tagName = this.host.tagName.toLowerCase();
449
+ // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by
450
+ // injecting the name/value on a temporary button, so we can just skip them here.
451
+ const isButton = tagName === 'it-button';
452
+ if (this.host.isConnected &&
453
+ !disabled &&
454
+ !isButton &&
455
+ typeof name === 'string' &&
456
+ name.length > 0 &&
457
+ typeof value !== 'undefined') {
458
+ switch (tagName) {
459
+ case 'it-radio':
460
+ if (this.host.checked) {
461
+ event.formData.append(name, value);
462
+ }
463
+ break;
464
+ case 'it-checkbox':
465
+ if (this.host.checked) {
466
+ if (event.formData.getAll(name).indexOf(value) < 0) {
467
+ // handle group checkbox
468
+ event.formData.append(name, value);
469
+ }
470
+ }
471
+ break;
472
+ case 'it-checkbox-group':
473
+ // non settare valori in formData, perchè ogni singola checkbox setta il suo valore
474
+ break;
475
+ default:
476
+ if (Array.isArray(value)) {
477
+ value.forEach((val) => {
478
+ event.formData.append(name, val.toString());
479
+ });
480
+ }
481
+ else {
482
+ event.formData.append(name, value.toString());
483
+ }
484
+ }
485
+ }
486
+ };
487
+ this.handleFormSubmit = (event) => {
488
+ const disabled = this.options.disabled(this.host);
489
+ const reportValidity = this.options.reportValidity;
490
+ // Update the interacted state for all controls when the form is submitted
491
+ if (this.form && !this.form.noValidate) {
492
+ formCollections.get(this.form)?.forEach((control) => {
493
+ this.setUserInteracted(control, true);
494
+ });
495
+ }
496
+ const resReportValidity = reportValidity(this.host);
497
+ if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
498
+ event.preventDefault();
499
+ // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
500
+ // Scroll al primo controllo non valido
501
+ const formControls = formCollections.get(this.form);
502
+ if (formControls) {
503
+ for (const control of formControls) {
504
+ if (!control.validity?.valid) {
505
+ // Scroll smooth verso il controllo non valido
506
+ control.scrollIntoView({
507
+ behavior: 'smooth',
508
+ block: 'center',
509
+ });
510
+ break;
511
+ }
512
+ }
513
+ }
514
+ }
515
+ this.submittedOnce = true;
516
+ };
517
+ this.handleFormReset = () => {
518
+ this.options.setValue(this.host, '');
519
+ this.submittedOnce = false;
520
+ this.setUserInteracted(this.host, false);
521
+ interactions.set(this.host, []);
522
+ };
523
+ this.handleInteraction = (event) => {
524
+ const emittedEvents = interactions.get(this.host);
525
+ if (!emittedEvents.includes(event.type)) {
526
+ emittedEvents.push(event.type);
527
+ }
528
+ // Mark it as user-interacted as soon as all associated events have been emitted
529
+ if (emittedEvents.length === this.options.assumeInteractionOn.length) {
530
+ this.setUserInteracted(this.host, true);
531
+ }
532
+ };
533
+ this.checkFormValidity = () => {
534
+ // console.log('checkFormValidity');
535
+ //
536
+ // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation
537
+ // Allow the user to simply check if the form is valid and handling validity in their own way.
538
+ //
539
+ // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
540
+ // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
541
+ // be necessary once we can use ElementInternals.
542
+ //
543
+ // Note that we're also honoring the form's novalidate attribute.
544
+ //
545
+ if (this.form && !this.form.noValidate) {
546
+ // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
547
+ // elements that support the constraint validation API.
548
+ const elements = this.form.querySelectorAll('*');
549
+ for (const element of elements) {
550
+ if (typeof element.checkValidity === 'function') {
551
+ if (!element.checkValidity()) {
552
+ return false;
553
+ }
554
+ }
555
+ }
556
+ }
557
+ return true;
558
+ };
559
+ this.reportFormValidity = () => {
560
+ // console.log('reportFormValidity');
561
+ //
562
+ // FormControl work hard to act like regular form controls. They support the Constraint Validation API
563
+ // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also
564
+ // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using
565
+ // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.
566
+ //
567
+ // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
568
+ // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
569
+ // be necessary once we can use ElementInternals.
570
+ //
571
+ // Note that we're also honoring the form's novalidate attribute.
572
+ //
573
+ if (this.form && !this.form.noValidate) {
574
+ // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
575
+ // elements that support the constraint validation API.
576
+ const elements = this.form.querySelectorAll('*');
577
+ for (const element of elements) {
578
+ if (typeof element.reportValidity === 'function') {
579
+ if (!element.reportValidity()) {
580
+ return false;
581
+ }
582
+ }
583
+ }
584
+ }
585
+ return true;
586
+ };
587
+ (this.host = host).addController(this);
588
+ this.options = {
589
+ form: (input) => {
590
+ // If there's a form attribute, use it to find the target form by id
591
+ // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.
592
+ const formId = input.form;
593
+ if (formId) {
594
+ const root = input.getRootNode();
595
+ const form = root.querySelector(`#${formId}`);
596
+ if (form) {
597
+ return form;
598
+ }
599
+ }
600
+ return input.closest('form');
601
+ },
602
+ name: (input) => input.name,
603
+ value: (input) => input.value,
604
+ disabled: (input) => input.disabled ?? false,
605
+ reportValidity: (input) => typeof input.reportValidity === 'function' ? input.reportValidity() : true,
606
+ checkValidity: (input) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),
607
+ setValue: (input, value) => {
608
+ // eslint-disable-next-line no-param-reassign
609
+ input.value = value;
610
+ },
611
+ assumeInteractionOn: ['it-input'],
612
+ ...options,
613
+ };
614
+ }
615
+ hostConnected() {
616
+ const form = this.options.form(this.host);
617
+ if (form) {
618
+ this.attachForm(form);
619
+ }
620
+ // Listen for interactions
621
+ interactions.set(this.host, []);
622
+ this.options.assumeInteractionOn.forEach((event) => {
623
+ this.host.addEventListener(event, this.handleInteraction);
624
+ });
625
+ }
626
+ hostDisconnected() {
627
+ this.detachForm();
628
+ // Clean up interactions
629
+ interactions.delete(this.host);
630
+ this.options.assumeInteractionOn.forEach((event) => {
631
+ this.host.removeEventListener(event, this.handleInteraction);
632
+ });
633
+ }
634
+ hostUpdated() {
635
+ const form = this.options.form(this.host);
636
+ // Detach if the form no longer exists
637
+ if (!form) {
638
+ this.detachForm();
639
+ }
640
+ // If the form has changed, reattach it
641
+ if (form && this.form !== form) {
642
+ this.detachForm();
643
+ this.attachForm(form);
644
+ }
645
+ if (this.host.hasUpdated) {
646
+ this.setValidity(this.host.validity.valid);
647
+ }
648
+ }
649
+ attachForm(form) {
650
+ if (form) {
651
+ this.form = form;
652
+ // Add this element to the form's collection
653
+ if (formCollections.has(this.form)) {
654
+ formCollections.get(this.form).add(this.host);
655
+ }
656
+ else {
657
+ formCollections.set(this.form, new Set([this.host]));
658
+ }
659
+ this.form.addEventListener('formdata', this.handleFormData);
660
+ this.form.addEventListener('submit', this.handleFormSubmit);
661
+ this.form.addEventListener('reset', this.handleFormReset);
662
+ // Overload the form's reportValidity() method so it looks at FormControl
663
+ if (!reportValidityOverloads.has(this.form)) {
664
+ reportValidityOverloads.set(this.form, this.form.reportValidity);
665
+ this.form.reportValidity = () => this.reportFormValidity();
666
+ }
667
+ // Overload the form's checkValidity() method so it looks at FormControl
668
+ if (!checkValidityOverloads.has(this.form)) {
669
+ checkValidityOverloads.set(this.form, this.form.checkValidity);
670
+ this.form.checkValidity = () => this.checkFormValidity();
671
+ }
672
+ }
673
+ else {
674
+ this.form = undefined;
675
+ }
676
+ }
677
+ detachForm() {
678
+ if (!this.form)
679
+ return;
680
+ const formCollection = formCollections.get(this.form);
681
+ if (!formCollection) {
682
+ return;
683
+ }
684
+ this.submittedOnce = false;
685
+ // Remove this host from the form's collection
686
+ formCollection.delete(this.host);
687
+ // Check to make sure there's no other form controls in the collection. If we do this
688
+ // without checking if any other controls are still in the collection, then we will wipe out the
689
+ // validity checks for all other elements.
690
+ // see: https://github.com/shoelace-style/shoelace/issues/1703
691
+ if (formCollection.size <= 0) {
692
+ this.form.removeEventListener('formdata', this.handleFormData);
693
+ this.form.removeEventListener('submit', this.handleFormSubmit);
694
+ this.form.removeEventListener('reset', this.handleFormReset);
695
+ // Remove the overload and restore the original method
696
+ if (reportValidityOverloads.has(this.form)) {
697
+ this.form.reportValidity = reportValidityOverloads.get(this.form);
698
+ reportValidityOverloads.delete(this.form);
699
+ }
700
+ if (checkValidityOverloads.has(this.form)) {
701
+ this.form.checkValidity = checkValidityOverloads.get(this.form);
702
+ checkValidityOverloads.delete(this.form);
703
+ }
704
+ // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,
705
+ // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.
706
+ // First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.
707
+ this.form = undefined;
708
+ }
709
+ }
710
+ // eslint-disable-next-line class-methods-use-this
711
+ setUserInteracted(el, hasInteracted) {
712
+ if (hasInteracted) {
713
+ userInteractedControls.add(el);
714
+ }
715
+ else {
716
+ userInteractedControls.delete(el);
717
+ }
718
+ el.requestUpdate();
719
+ }
720
+ doAction(type, submitter) {
721
+ // console.log('doaction', type);
722
+ if (this.form) {
723
+ const button = document.createElement('button');
724
+ button.type = type;
725
+ button.style.position = 'absolute';
726
+ button.style.width = '0';
727
+ button.style.height = '0';
728
+ button.style.clipPath = 'inset(50%)';
729
+ button.style.overflow = 'hidden';
730
+ button.style.whiteSpace = 'nowrap';
731
+ // Pass name, value, and form attributes through to the temporary button
732
+ if (submitter) {
733
+ button.name = submitter.name;
734
+ button.value = submitter.value;
735
+ ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {
736
+ if (submitter.hasAttribute(attr)) {
737
+ button.setAttribute(attr, submitter.getAttribute(attr));
738
+ }
739
+ });
740
+ }
741
+ this.form.append(button);
742
+ button.click();
743
+ button.remove();
744
+ }
745
+ }
746
+ /** Returns the associated `<form>` element, if one exists. */
747
+ getForm() {
748
+ return this.form ?? null;
749
+ }
750
+ /** Resets the form, restoring all the control to their default value */
751
+ reset(submitter) {
752
+ this.doAction('reset', submitter);
753
+ }
754
+ /** Submits the form, triggering validation and form data injection. */
755
+ submit(submitter) {
756
+ // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
757
+ // native submit button into the form, "click" it, then remove it to simulate a standard form submission.
758
+ this.doAction('submit', submitter);
759
+ }
760
+ /**
761
+ * Synchronously sets the form control's validity. Call this when you know the future validity but need to update
762
+ * the host element immediately, i.e. before Lit updates the component in the next update.
763
+ */
764
+ setValidity(isValid) {
765
+ const host = this.host;
766
+ const hasInteracted = Boolean(userInteractedControls.has(host));
767
+ const required = Boolean(host.required);
768
+ //
769
+ // We're mapping the following "states" to data attributes. In the future, we can use ElementInternals.states to
770
+ // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.
771
+ //
772
+ // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011
773
+ //
774
+ host.toggleAttribute('data-required', required);
775
+ host.toggleAttribute('data-optional', !required);
776
+ host.toggleAttribute('data-invalid', !isValid);
777
+ host.toggleAttribute('data-valid', isValid);
778
+ host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
779
+ host.toggleAttribute('data-user-valid', isValid && hasInteracted);
780
+ }
781
+ userInteracted() {
782
+ const hasInteracted = Boolean(userInteractedControls.has(this.host));
783
+ return hasInteracted;
784
+ }
785
+ /**
786
+ * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
787
+ * that affects constraint validation changes so the component receives the correct validity states.
788
+ */
789
+ updateValidity() {
790
+ const host = this.host;
791
+ this.setValidity(host.validity.valid);
792
+ }
793
+ /**
794
+ * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.
795
+ * If the `it-invalid` event will be cancelled then the original `invalid`
796
+ * event (which may have been passed as argument) will also be cancelled.
797
+ * If no original `invalid` event has been passed then the `it-invalid`
798
+ * event will be cancelled before being dispatched.
799
+ */
800
+ emitInvalidEvent(originalInvalidEvent) {
801
+ const itInvalidEvent = new CustomEvent('it-invalid', {
802
+ bubbles: false,
803
+ composed: false,
804
+ cancelable: true,
805
+ detail: {},
806
+ });
807
+ if (!originalInvalidEvent) {
808
+ itInvalidEvent.preventDefault();
809
+ }
810
+ if (!this.host.dispatchEvent(itInvalidEvent)) {
811
+ originalInvalidEvent?.preventDefault();
812
+ }
813
+ }
814
+ }
815
+
816
+ const translation = {
817
+ $code: 'it',
818
+ $name: 'Italiano',
819
+ $dir: 'ltr',
820
+ validityRequired: 'Questo campo è obbligatorio.',
821
+ validityGroupRequired: "Scegli almeno un'opzione",
822
+ validityPattern: 'Il valore non corrisponde al formato richiesto.',
823
+ validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
824
+ validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
825
+ };
826
+
827
+ registerTranslation(translation);
828
+ class FormControl extends BaseLocalizedComponent {
829
+ constructor() {
830
+ super(...arguments);
831
+ this.formControlController = new FormControlController(this, {
832
+ assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],
833
+ });
834
+ // TODO: verificare se serve davvero con il fatto che usiamo form-controller
835
+ // static formAssociated = true;
836
+ // @property()
837
+ // internals = this.attachInternals();
838
+ this._touched = false;
839
+ /** The name of the input, submitted as a name/value pair with form data. */
840
+ this.name = '';
841
+ /** The current value of the input, submitted as a name/value pair with form data. */
842
+ this.value = '';
843
+ /** If the input is disabled. */
844
+ this.disabled = false;
845
+ /**
846
+ * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you
847
+ * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in
848
+ * the same document or shadow root for this to work.
849
+ */
850
+ this.form = '';
851
+ /** If you implement your custom validation and you won't to trigger default validation */
852
+ this.customValidation = false;
853
+ /** If your input is invalid from your custom validition, set this attribute with message validation */
854
+ this.validationText = '';
855
+ /**
856
+ * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is
857
+ * implied, allowing any numeric value. Only applies to date and number input types.
858
+ */
859
+ this.step = 'any';
860
+ /** The input's minimum length. */
861
+ this.minlength = -1;
862
+ /** The input's maximum length. */
863
+ this.maxlength = -1;
864
+ /** If the input is required. */
865
+ this.required = false;
866
+ /* For grouped input, like checkbox-group */
867
+ this.isInGroup = false;
868
+ this.validationMessage = '';
869
+ }
870
+ /** Gets the validity state object */
871
+ get validity() {
872
+ return this.inputElement?.validity;
873
+ }
874
+ /** Gets the associated form, if one exists. */
875
+ getForm() {
876
+ return this.formControlController.getForm();
877
+ }
878
+ // Form validation methods
879
+ checkValidity() {
880
+ const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
881
+ return inputValid;
882
+ }
883
+ /** Checks for validity and shows the browser's validation message if the control is invalid. */
884
+ reportValidity() {
885
+ // const ret = this.inputElement.checkValidity();
886
+ const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
887
+ this.handleValidationMessages();
888
+ return ret; // this.inputElement.reportValidity();
889
+ }
890
+ /** Sets a custom validation message. Pass an empty string to restore validity. */
891
+ setCustomValidity(message) {
892
+ this.inputElement.setCustomValidity(message);
893
+ this.validationMessage = this.inputElement.validationMessage;
894
+ this.formControlController.updateValidity();
895
+ }
896
+ // Handlers
897
+ _handleReady() {
898
+ requestAnimationFrame(() => {
899
+ this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));
900
+ });
901
+ }
902
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
903
+ _handleInput(e) {
904
+ this.handleValidationMessages();
905
+ this.dispatchEvent(new CustomEvent('it-input', {
906
+ detail: { value: this.inputElement.value, el: this.inputElement },
907
+ bubbles: true,
908
+ composed: true,
909
+ }));
910
+ }
911
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
912
+ _handleBlur(e) {
913
+ this._touched = true;
914
+ this.handleValidationMessages();
915
+ this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));
916
+ }
917
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
918
+ _handleFocus(e) {
919
+ this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));
920
+ }
921
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
922
+ _handleClick(e) {
923
+ this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));
924
+ }
925
+ /*
926
+ Override default browser validation messages
927
+ */
928
+ handleValidationMessages() {
929
+ if (!this.customValidation) {
930
+ const _v = this.inputElement.validity;
931
+ const isRequiredHandledByGroup = this.isInGroup === true;
932
+ if (_v.valueMissing && !isRequiredHandledByGroup) {
933
+ this.setCustomValidity(this.$t('validityRequired'));
934
+ }
935
+ else if (_v.patternMismatch) {
936
+ this.setCustomValidity(this.$t('validityPattern'));
937
+ }
938
+ else if (_v.tooShort) {
939
+ this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));
940
+ }
941
+ else if (_v.tooLong) {
942
+ this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));
943
+ }
944
+ else {
945
+ /* nothing. Usa il messaggio di errore della validazione
946
+ di default del browser per altri errori di validità come:
947
+ - typeMismatch
948
+ - rangeUnderflow
949
+ - rangeOverflow
950
+ - stepMismatch
951
+ - badInput */
952
+ const otherConstraintErrors = _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;
953
+ if (!otherConstraintErrors) {
954
+ this.setCustomValidity('');
955
+ }
956
+ }
957
+ }
958
+ this.validationMessage = this.inputElement.validationMessage;
959
+ }
960
+ _handleInvalid(event) {
961
+ this.formControlController.setValidity(false);
962
+ this.formControlController.emitInvalidEvent(event);
963
+ }
964
+ _handleChange(e) {
965
+ const target = e.target;
966
+ let value;
967
+ if (target instanceof HTMLInputElement) {
968
+ switch (target.type) {
969
+ case 'checkbox':
970
+ case 'radio':
971
+ value = target.checked;
972
+ break;
973
+ case 'file':
974
+ value = target.files; // FileList
975
+ break;
976
+ default:
977
+ value = target.value;
978
+ }
979
+ }
980
+ else if (target instanceof HTMLSelectElement) {
981
+ if (target.multiple) {
982
+ value = Array.from(target.selectedOptions).map((o) => o.value);
983
+ }
984
+ else {
985
+ value = target.value;
986
+ }
987
+ }
988
+ else {
989
+ // textarea o altri input con value
990
+ value = target.value;
991
+ }
992
+ this.dispatchEvent(new CustomEvent('it-change', {
993
+ detail: { value, el: target },
994
+ bubbles: true,
995
+ composed: true,
996
+ }));
997
+ }
998
+ updated(changedProperties) {
999
+ super.updated?.(changedProperties);
1000
+ if (this.customValidation) {
1001
+ this.setCustomValidity(this.validationText ?? '');
1002
+ }
1003
+ else if (this.formControlController.userInteracted()) {
1004
+ this.formControlController.updateValidity();
1005
+ }
1006
+ }
1007
+ }
1008
+ __decorate([
1009
+ state(),
1010
+ __metadata("design:type", Object)
1011
+ ], FormControl.prototype, "_touched", void 0);
1012
+ __decorate([
1013
+ query('.it-form__control'),
1014
+ __metadata("design:type", HTMLInputElement)
1015
+ ], FormControl.prototype, "inputElement", void 0);
1016
+ __decorate([
1017
+ property({ type: String, reflect: true }) // from FormControl
1018
+ ,
1019
+ __metadata("design:type", Object)
1020
+ ], FormControl.prototype, "name", void 0);
1021
+ __decorate([
1022
+ property({ reflect: true }),
1023
+ __metadata("design:type", Object)
1024
+ ], FormControl.prototype, "value", void 0);
1025
+ __decorate([
1026
+ property({ type: Boolean, reflect: true }) // from FormControl
1027
+ ,
1028
+ __metadata("design:type", Object)
1029
+ ], FormControl.prototype, "disabled", void 0);
1030
+ __decorate([
1031
+ property({ reflect: true, type: String }),
1032
+ __metadata("design:type", Object)
1033
+ ], FormControl.prototype, "form", void 0);
1034
+ __decorate([
1035
+ property({ type: Boolean, reflect: true, attribute: 'custom-validation' }),
1036
+ __metadata("design:type", Object)
1037
+ ], FormControl.prototype, "customValidation", void 0);
1038
+ __decorate([
1039
+ property({ attribute: 'validity-message', reflect: true }),
1040
+ __metadata("design:type", String)
1041
+ ], FormControl.prototype, "validationText", void 0);
1042
+ __decorate([
1043
+ property(),
1044
+ __metadata("design:type", String)
1045
+ ], FormControl.prototype, "pattern", void 0);
1046
+ __decorate([
1047
+ property(),
1048
+ __metadata("design:type", Object)
1049
+ ], FormControl.prototype, "min", void 0);
1050
+ __decorate([
1051
+ property(),
1052
+ __metadata("design:type", Object)
1053
+ ], FormControl.prototype, "max", void 0);
1054
+ __decorate([
1055
+ property(),
1056
+ __metadata("design:type", Object)
1057
+ ], FormControl.prototype, "step", void 0);
1058
+ __decorate([
1059
+ property({ type: Number }),
1060
+ __metadata("design:type", Object)
1061
+ ], FormControl.prototype, "minlength", void 0);
1062
+ __decorate([
1063
+ property({ type: Number }),
1064
+ __metadata("design:type", Object)
1065
+ ], FormControl.prototype, "maxlength", void 0);
1066
+ __decorate([
1067
+ property({ type: Boolean, reflect: true }) // from FormControl
1068
+ ,
1069
+ __metadata("design:type", Object)
1070
+ ], FormControl.prototype, "required", void 0);
1071
+ __decorate([
1072
+ property({ type: Boolean }),
1073
+ __metadata("design:type", Object)
1074
+ ], FormControl.prototype, "isInGroup", void 0);
1075
+ __decorate([
1076
+ state(),
1077
+ __metadata("design:type", Object)
1078
+ ], FormControl.prototype, "validationMessage", void 0);
1079
+
1080
+ if (typeof window !== 'undefined') {
1081
+ window._itAnalytics = window._itAnalytics || {};
1082
+ window._itAnalytics = {
1083
+ ...window._itAnalytics,
1084
+ version: '1.0.0-alpha.4',
1085
+ };
1086
+ }
1087
+
1088
+ const isMouseEvent = (event) => event instanceof MouseEvent;
1089
+ const isKeyboardEvent = (event) => event instanceof KeyboardEvent;
1090
+
1091
+ var styles = css`/***************************** 1 ****************************************/
1092
+ /***************************** 2 ****************************************/
1093
+ /***************************** 1 ****************************************/
1094
+ /***************************** 2 ****************************************/
1095
+ /***************************** 1 ****************************************/
1096
+ /***************************** 2 ****************************************/
1097
+ /***************************** 3 ****************************************/
1098
+ /***************************** 1 ****************************************/
1099
+ /***************************** 2 ****************************************/
1100
+ /***************************** 3 ****************************************/
1101
+ /***************************** NEUTRAL 1 ****************************************/
1102
+ /***************************** NEUTRAL 2 ****************************************/
1103
+ /***************************** NEUTRAL 2 / 3 ****************************************/
1104
+ .btn {
1105
+ --bs-btn-padding-x: var(--bs-spacing-s);
1106
+ --bs-btn-padding-y: var(--bs-spacing-xs);
1107
+ --bs-btn-font-family: var(--bs-font-sans);
1108
+ --bs-btn-font-weight: var(--bs-font-weight-solid);
1109
+ --bs-btn-font-size: var(--bs-label-font-size);
1110
+ --bs-btn-line-height: var(--bs-font-line-height-3);
1111
+ --bs-btn-text-color: var(--bs-color-text-primary);
1112
+ --bs-btn-background: transparent;
1113
+ --bs-btn-border-size: 0;
1114
+ --bs-btn-border-color: transparent;
1115
+ --bs-btn-border-radius: var(--bs-radius-smooth);
1116
+ --bs-btn-outline-border-size: 2px;
1117
+ --bs-btn-outline-border-color: transparent;
1118
+ --bs-btn-disabled-opacity: 0.5;
1119
+ }
1120
+
1121
+ .btn {
1122
+ display: inline-block;
1123
+ padding: var(--bs-btn-padding-y) var(--bs-btn-padding-x);
1124
+ border: var(--bs-btn-border-width) solid var(--bs-btn-border-color);
1125
+ border-radius: var(--bs-btn-border-radius);
1126
+ background: var(--bs-btn-background);
1127
+ box-shadow: var(--bs-btn-box-shadow, none);
1128
+ color: var(--bs-btn-text-color);
1129
+ font-family: var(--bs-btn-font-family);
1130
+ font-size: var(--bs-btn-font-size);
1131
+ font-weight: var(--bs-btn-font-weight);
1132
+ line-height: var(--bs-btn-line-height);
1133
+ text-align: center;
1134
+ text-decoration: none;
1135
+ vertical-align: middle;
1136
+ white-space: initial;
1137
+ width: auto;
1138
+ transition: all var(--bs-transition-instant) ease-in-out;
1139
+ user-select: none;
1140
+ }
1141
+ .btn:hover {
1142
+ color: var(--bs-btn-text-color);
1143
+ }
1144
+ .btn:disabled, .btn.disabled {
1145
+ opacity: var(--bs-btn-disabled-opacity);
1146
+ cursor: not-allowed;
1147
+ pointer-events: none;
1148
+ }
1149
+ .btn:focus-visible {
1150
+ border-color: var(--bs-btn-hover-border-color);
1151
+ outline: 0;
1152
+ }
1153
+ .btn-check:focus-visible + .btn {
1154
+ border-color: var(--bs-btn-hover-border-color);
1155
+ outline: 0;
1156
+ }
1157
+
1158
+ .btn-link {
1159
+ --bs-btn-background: transparent;
1160
+ --bs-btn-border-color: transparent;
1161
+ text-decoration: underline;
1162
+ }
1163
+ .btn-link:hover {
1164
+ color: var(--bs-color-link-hover);
1165
+ }
1166
+
1167
+ .btn-xs {
1168
+ --bs-btn-padding-x: var(--bs-spacing-xs);
1169
+ --bs-btn-padding-y: var(--bs-spacing-xs);
1170
+ --bs-btn-font-size: var(--bs-label-font-size-s);
1171
+ --bs-btn-line-height: var(--bs-font-line-height-1);
1172
+ --bs-rounded-icon-size: 20px;
1173
+ }
1174
+
1175
+ .btn-lg {
1176
+ --bs-btn-padding-x: var(--bs-spacing-m);
1177
+ --bs-btn-padding-y: var(--bs-spacing-s);
1178
+ --bs-btn-font-size: var(--bs-label-font-size-m);
1179
+ --bs-btn-line-height: var(--bs-font-line-height-5);
1180
+ }
1181
+
1182
+ .btn-progress {
1183
+ position: relative;
1184
+ }
1185
+
1186
+ .btn-icon {
1187
+ display: inline-flex;
1188
+ flex-direction: row;
1189
+ align-items: center;
1190
+ justify-content: center;
1191
+ gap: var(--bs-icon-spacing);
1192
+ }
1193
+
1194
+ .btn-full {
1195
+ align-self: stretch;
1196
+ width: inherit;
1197
+ border: none;
1198
+ box-shadow: none;
1199
+ }
1200
+ @media (min-width: 992px) {
1201
+ .btn-full {
1202
+ display: flex;
1203
+ flex: 1;
1204
+ flex-direction: row;
1205
+ align-items: center;
1206
+ justify-content: center;
1207
+ margin: 0;
1208
+ }
1209
+ }
1210
+
1211
+ .btn:disabled:hover,
1212
+ .btn.disabled:hover {
1213
+ cursor: not-allowed;
1214
+ }
1215
+
1216
+ .btn-primary,
1217
+ a.btn-primary {
1218
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1219
+ --bs-btn-background: var(--bs-color-background-primary);
1220
+ }
1221
+ .btn-primary:hover,
1222
+ a.btn-primary:hover {
1223
+ --bs-btn-background: var(--bs-color-background-primary-hover);
1224
+ }
1225
+ .btn-primary:active,
1226
+ a.btn-primary:active {
1227
+ --bs-btn-background: var(--bs-color-background-primary-active);
1228
+ }
1229
+ .btn-primary.btn-progress,
1230
+ a.btn-primary.btn-progress {
1231
+ border-color: hsl(210, 76%, 67%);
1232
+ opacity: 1;
1233
+ background-color: hsl(210, 76%, 67%);
1234
+ }
1235
+
1236
+ .btn-secondary,
1237
+ a.btn-secondary {
1238
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1239
+ --bs-btn-background: var(--bs-color-background-secondary);
1240
+ }
1241
+ .btn-secondary:hover,
1242
+ a.btn-secondary:hover {
1243
+ --bs-btn-background: var(--bs-color-background-secondary-hover);
1244
+ }
1245
+ .btn-secondary:active,
1246
+ a.btn-secondary:active {
1247
+ --bs-btn-background: var(--bs-color-background-secondary-active);
1248
+ }
1249
+ .btn-secondary:disabled.btn-progress, .btn-secondary.disabled.btn-progress,
1250
+ a.btn-secondary:disabled.btn-progress,
1251
+ a.btn-secondary.disabled.btn-progress {
1252
+ border-color: hsl(210, 12%, 52%);
1253
+ opacity: 1;
1254
+ background-color: hsl(210, 12%, 52%);
1255
+ }
1256
+
1257
+ .btn-success,
1258
+ a.btn-success {
1259
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1260
+ --bs-btn-background: var(--bs-color-background-success);
1261
+ }
1262
+ .btn-success:hover,
1263
+ a.btn-success:hover {
1264
+ --bs-btn-background: var(--bs-color-background-success-hover);
1265
+ }
1266
+ .btn-success:active,
1267
+ a.btn-success:active {
1268
+ --bs-btn-background: var(--bs-color-background-success-active);
1269
+ }
1270
+
1271
+ .btn-warning,
1272
+ a.btn-warning {
1273
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1274
+ --bs-btn-background: var(--bs-color-background-warning);
1275
+ }
1276
+ .btn-warning:hover,
1277
+ a.btn-warning:hover {
1278
+ --bs-btn-background: var(--bs-color-background-warning-hover);
1279
+ }
1280
+ .btn-warning:active,
1281
+ a.btn-warning:active {
1282
+ --bs-btn-background: var(--bs-color-background-warning-active);
1283
+ }
1284
+
1285
+ .btn-danger,
1286
+ a.btn-danger {
1287
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1288
+ --bs-btn-background: var(--bs-color-background-danger);
1289
+ }
1290
+ .btn-danger:hover,
1291
+ a.btn-danger:hover {
1292
+ --bs-btn-background: var(--bs-color-background-danger-hover);
1293
+ }
1294
+ .btn-danger:active,
1295
+ a.btn-danger:active {
1296
+ --bs-btn-background: var(--bs-color-background-danger-active);
1297
+ }
1298
+
1299
+ .btn[class*=btn-outline-] {
1300
+ --bs-btn-box-shadow: inset 0 0 0 var(--bs-btn-outline-border-size) var(--bs-btn-outline-border-color);
1301
+ }
1302
+
1303
+ .btn-outline-primary,
1304
+ a.btn-outline-primary {
1305
+ --bs-btn-outline-border-color: var(--bs-color-border-primary);
1306
+ --bs-btn-text-color: var(--bs-color-text-primary);
1307
+ }
1308
+ .btn-outline-primary:hover,
1309
+ a.btn-outline-primary:hover {
1310
+ --bs-btn-outline-border-color: var(--bs-color-border-primary-hover);
1311
+ --bs-btn-text-color: var(--bs-color-link-hover);
1312
+ }
1313
+ .btn-outline-primary:active,
1314
+ a.btn-outline-primary:active {
1315
+ --bs-btn-outline-border-color: var(--bs-color-border-primary-active);
1316
+ --bs-btn-text-color: var(--bs-color-link-active);
1317
+ }
1318
+ .btn-outline-secondary,
1319
+ a.btn-outline-secondary {
1320
+ --bs-btn-outline-border-color: var(--bs-color-border-secondary);
1321
+ --bs-btn-text-color: var(--bs-color-text-secondary);
1322
+ }
1323
+ .btn-outline-secondary:hover,
1324
+ a.btn-outline-secondary:hover {
1325
+ --bs-btn-outline-border-color: var(--bs-color-border-secondary-hover);
1326
+ --bs-btn-text-color: var(--bs-color-text-secondary-hover);
1327
+ }
1328
+ .btn-outline-secondary:active,
1329
+ a.btn-outline-secondary:active {
1330
+ --bs-btn-outline-border-color: var(--bs-color-border-secondary-active);
1331
+ --bs-btn-text-color: var(--bs-color-text-secondary-active);
1332
+ }
1333
+ .btn-outline-success,
1334
+ a.btn-outline-success {
1335
+ --bs-btn-outline-border-color: var(--bs-color-border-success);
1336
+ --bs-btn-text-color: var(--bs-color-text-success);
1337
+ }
1338
+ .btn-outline-success:hover,
1339
+ a.btn-outline-success:hover {
1340
+ --bs-btn-outline-border-color: var(--bs-color-border-success-hover);
1341
+ --bs-btn-text-color: var(--bs-color-text-success-hover);
1342
+ }
1343
+ .btn-outline-success:active,
1344
+ a.btn-outline-success:active {
1345
+ --bs-btn-outline-border-color: var(--bs-color-border-success-active);
1346
+ --bs-btn-text-color: var(--bs-color-text-success-active);
1347
+ }
1348
+ .btn-outline-warning,
1349
+ a.btn-outline-warning {
1350
+ --bs-btn-outline-border-color: var(--bs-color-border-warning);
1351
+ --bs-btn-text-color: var(--bs-color-text-warning);
1352
+ }
1353
+ .btn-outline-warning:hover,
1354
+ a.btn-outline-warning:hover {
1355
+ --bs-btn-outline-border-color: var(--bs-color-border-warning-hover);
1356
+ --bs-btn-text-color: var(--bs-color-text-warning-hover);
1357
+ }
1358
+ .btn-outline-warning:active,
1359
+ a.btn-outline-warning:active {
1360
+ --bs-btn-outline-border-color: var(--bs-color-border-warning-active);
1361
+ --bs-btn-text-color: var(--bs-color-text-warning-active);
1362
+ }
1363
+ .btn-outline-danger,
1364
+ a.btn-outline-danger {
1365
+ --bs-btn-outline-border-color: var(--bs-color-border-danger);
1366
+ --bs-btn-text-color: var(--bs-color-text-danger);
1367
+ }
1368
+ .btn-outline-danger:hover,
1369
+ a.btn-outline-danger:hover {
1370
+ --bs-btn-outline-border-color: var(--bs-color-border-danger-hover);
1371
+ --bs-btn-text-color: var(--bs-color-text-danger-hover);
1372
+ }
1373
+ .btn-outline-danger:active,
1374
+ a.btn-outline-danger:active {
1375
+ --bs-btn-outline-border-color: var(--bs-color-border-danger-active);
1376
+ --bs-btn-text-color: var(--bs-color-text-danger-active);
1377
+ }
1378
+
1379
+ .bg-dark .btn-link {
1380
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1381
+ }
1382
+ .bg-dark a.btn-primary,
1383
+ .bg-dark .btn-primary {
1384
+ --bs-btn-text-color: var(--bs-color-text-primary);
1385
+ --bs-btn-background: var(--bs-color-background-inverse);
1386
+ }
1387
+ .bg-dark a.btn-primary:hover,
1388
+ .bg-dark .btn-primary:hover {
1389
+ --bs-btn-background: color-mix(in srgb, var(--bs-color-background-inverse) 85%, black);
1390
+ }
1391
+ .bg-dark a.btn-primary:active,
1392
+ .bg-dark .btn-primary:active {
1393
+ --bs-btn-background: color-mix(in srgb, var(--bs-color-background-inverse) 80%, black);
1394
+ }
1395
+ .bg-dark a.btn-secondary,
1396
+ .bg-dark .btn-secondary {
1397
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1398
+ --bs-btn-background: var(--bs-color-background-secondary);
1399
+ }
1400
+ .bg-dark a.btn-secondary:hover, .bg-dark a.btn-secondary:active,
1401
+ .bg-dark .btn-secondary:hover,
1402
+ .bg-dark .btn-secondary:active {
1403
+ --bs-btn-background: color-mix(in srgb, var(--bs-color-background-secondary) 85%, black);
1404
+ }
1405
+ .bg-dark .btn-outline-primary,
1406
+ .bg-dark a.btn-outline-primary {
1407
+ --bs-btn-outline-border-color: var(--bs-color-border-inverse);
1408
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1409
+ }
1410
+ .bg-dark .btn-outline-primary:hover,
1411
+ .bg-dark a.btn-outline-primary:hover {
1412
+ --bs-btn-boxshadow-color-darken: color-mix(in srgb, var(--bs-color-border-inverse) 80%, black);
1413
+ --bs-btn-boxshadow-color-desaturated: color-mix(in srgb, var(--bs-btn-boxshadow-color-darken) 80%, gray);
1414
+ --bs-btn-outline-border-color: var(--bs-btn-boxshadow-color-desaturated);
1415
+ }
1416
+ .bg-dark .btn-outline-secondary,
1417
+ .bg-dark a.btn-outline-secondary {
1418
+ --bs-btn-text-color: var(--bs-color-text-inverse);
1419
+ }
1420
+ .bg-dark .btn-outline-secondary:hover, .bg-dark .btn-outline-secondary:active,
1421
+ .bg-dark a.btn-outline-secondary:hover,
1422
+ .bg-dark a.btn-outline-secondary:active {
1423
+ --bs-btn-boxshadow-color-darken: color-mix(in srgb, var(--bs-color-background-secondary) 80%, black);
1424
+ --bs-btn-boxshadow-color-desaturated: color-mix(in srgb, var(--bs-btn-boxshadow-color-darken) 80%, gray);
1425
+ --bs-btn-outline-border-color: var(--bs-btn-boxshadow-color-desaturated);
1426
+ }
1427
+
1428
+ .btn-close {
1429
+ position: relative;
1430
+ box-sizing: content-box;
1431
+ width: 2.5rem;
1432
+ height: 2.5rem;
1433
+ padding: 0;
1434
+ border: 0;
1435
+ opacity: 0.5;
1436
+ background-color: transparent;
1437
+ color: var(--bs-color-text-base);
1438
+ }
1439
+ .btn-close .icon {
1440
+ position: absolute;
1441
+ top: 50%;
1442
+ left: 50%;
1443
+ transform: translate(-50%, -50%);
1444
+ }
1445
+ .btn-close:hover {
1446
+ opacity: 1;
1447
+ text-decoration: none;
1448
+ }
1449
+ .btn-close:focus {
1450
+ opacity: 1;
1451
+ }
1452
+ .btn-close:disabled, .btn-close.disabled {
1453
+ opacity: var(--bs-btn-disabled-opacity);
1454
+ pointer-events: none;
1455
+ user-select: none;
1456
+ }
1457
+
1458
+ .btn-close-white {
1459
+ filter: invert(1) grayscale(100%) brightness(200%);
1460
+ }
1461
+
1462
+ :host {
1463
+ display: inline-flex;
1464
+ }
1465
+
1466
+ .collapse-wrapper {
1467
+ width: 100%;
1468
+ }
1469
+
1470
+ .collapse-content {
1471
+ overflow: hidden;
1472
+ height: 0;
1473
+ }
1474
+
1475
+ .collapse-item {
1476
+ width: fit-content;
1477
+ }
1478
+
1479
+ button,
1480
+ [role=button] {
1481
+ cursor: pointer;
1482
+ }`;
1483
+
1484
+ // Base class without @customElement decorator for inheritance
1485
+ class ItCollapseBase extends BaseComponent {
1486
+ constructor() {
1487
+ super(...arguments);
1488
+ this.variant = 'primary';
1489
+ this.size = '';
1490
+ this.outline = false;
1491
+ this.expanded = false;
1492
+ this.isAccordion = false;
1493
+ this.as = 'button';
1494
+ this.defaultOpen = false;
1495
+ this.isAnimating = false;
1496
+ this.animationDuration = 350; // ms
1497
+ this._triggerId = this.generateId('it-collapse-trigger');
1498
+ this._contentId = this.generateId('it-collapse-content');
1499
+ this.handleTriggerAction = (e) => {
1500
+ if (this.isAnimating) {
1501
+ e.preventDefault();
1502
+ e.stopPropagation();
1503
+ return;
1504
+ }
1505
+ if (isKeyboardEvent(e) && (e.key === 'Enter' || e.key === ' ')) {
1506
+ e.preventDefault();
1507
+ this.toggle();
1508
+ }
1509
+ else if (isMouseEvent(e)) {
1510
+ e.preventDefault();
1511
+ this.toggle();
1512
+ }
1513
+ };
1514
+ this._onTriggerSlotChange = () => {
1515
+ // Aggiorna gli attributi ARIA quando il contenuto dello slot cambia
1516
+ this.updateAriaAttributes();
1517
+ // Forza un aggiornamento per il rendering, i getter sono stale altrimenti
1518
+ this.requestUpdate();
1519
+ };
1520
+ }
1521
+ get triggerElement() {
1522
+ return this.triggerElements.length > 0 ? this.triggerElements[0] : null;
1523
+ }
1524
+ connectedCallback() {
1525
+ super.connectedCallback?.();
1526
+ // Initialize from default-open
1527
+ if (this.defaultOpen && !this.expanded) {
1528
+ this.expanded = this.defaultOpen;
1529
+ }
1530
+ }
1531
+ async toggle() {
1532
+ // Blocca toggle durante animazione
1533
+ if (this.isAnimating)
1534
+ return;
1535
+ const nextValue = !this.expanded;
1536
+ this.expanded = nextValue;
1537
+ this.dispatchEvent(new CustomEvent('it-collapse-toggle', {
1538
+ detail: {
1539
+ expanded: this.expanded,
1540
+ id: this.contentElement?.id,
1541
+ },
1542
+ bubbles: true,
1543
+ composed: true,
1544
+ cancelable: true,
1545
+ }));
1546
+ }
1547
+ setInitialState() {
1548
+ if (this.contentElement) {
1549
+ if (this.expanded) {
1550
+ this.contentElement.style.height = 'auto';
1551
+ this.contentElement.style.visibility = 'visible';
1552
+ }
1553
+ else {
1554
+ this.contentElement.style.height = '0px';
1555
+ this.contentElement.style.visibility = 'hidden';
1556
+ }
1557
+ }
1558
+ }
1559
+ cleanupAnimation() {
1560
+ if (this.animation) {
1561
+ try {
1562
+ this.animation.cancel();
1563
+ }
1564
+ catch {
1565
+ /* ignore */
1566
+ }
1567
+ this.animation = undefined;
1568
+ }
1569
+ this.isAnimating = false;
1570
+ }
1571
+ firstUpdated() {
1572
+ this.updateAriaAttributes();
1573
+ // Set initial state and ensure overflow is hidden
1574
+ this.setInitialState();
1575
+ }
1576
+ updated(changedProperties) {
1577
+ if (changedProperties.has('defaultOpen')) {
1578
+ if (this.defaultOpen && !this.expanded) {
1579
+ this.expanded = this.defaultOpen;
1580
+ }
1581
+ }
1582
+ if (changedProperties.has('expanded')) {
1583
+ this.updateAriaAttributes();
1584
+ this.updateBackgroundStyles();
1585
+ const prev = changedProperties.get('expanded');
1586
+ // React to expanded property changes
1587
+ if (!this.isAnimating && prev !== undefined && prev !== this.expanded) {
1588
+ if (this.expanded) {
1589
+ this.performExpand();
1590
+ }
1591
+ else {
1592
+ this.performCollapse();
1593
+ }
1594
+ }
1595
+ }
1596
+ // Se cambiano le proprietà di background, aggiorna gli stili
1597
+ if (changedProperties.has('backgroundActive') ||
1598
+ changedProperties.has('backgroundHover') ||
1599
+ changedProperties.has('leftIcon')) {
1600
+ this.updateBackgroundStyles();
1601
+ }
1602
+ }
1603
+ updateAriaAttributes() {
1604
+ if (this.triggerElement) {
1605
+ if (this.triggerElement.tagName.toLowerCase() === 'button' ||
1606
+ this.triggerElement.getAttribute('role') === 'button') {
1607
+ const buttonElement = this.triggerElement;
1608
+ buttonElement.id = this._triggerId;
1609
+ buttonElement.setAttribute('aria-expanded', String(this.expanded));
1610
+ buttonElement.setAttribute('aria-controls', this._contentId);
1611
+ buttonElement.addEventListener('click', this.handleTriggerAction.bind(this));
1612
+ buttonElement.addEventListener('keyup', this.handleTriggerAction.bind(this));
1613
+ if (!this.expanded) {
1614
+ buttonElement.classList.add('collapsed');
1615
+ }
1616
+ else {
1617
+ buttonElement.classList.remove('collapsed');
1618
+ }
1619
+ }
1620
+ }
1621
+ // Aggiorna anche gli stili e le icone di chi implementa questo metodo via estensione
1622
+ this.updateBackgroundStyles();
1623
+ }
1624
+ // eslint-disable-next-line class-methods-use-this
1625
+ updateBackgroundStyles() { }
1626
+ performExpand() {
1627
+ if (!this.contentElement)
1628
+ return;
1629
+ this.cleanupAnimation();
1630
+ this.isAnimating = true;
1631
+ // Ensure overflow is hidden during animation
1632
+ this.contentElement.style.overflow = 'hidden';
1633
+ this.contentElement.style.visibility = 'visible';
1634
+ const startHeight = this.contentElement.offsetHeight;
1635
+ const endHeight = this.contentElement.scrollHeight;
1636
+ const duration = this.prefersReducedMotion ? 0 : this.animationDuration;
1637
+ this.animation = this.contentElement.animate([{ height: `${startHeight}px` }, { height: `${endHeight}px` }], {
1638
+ duration,
1639
+ easing: 'ease',
1640
+ });
1641
+ this.animation.finished
1642
+ .then(() => {
1643
+ this.contentElement.style.height = 'auto';
1644
+ // Keep overflow hidden as per CSS
1645
+ this.contentElement.style.overflow = 'hidden';
1646
+ })
1647
+ .catch(() => {
1648
+ // Animation cancelled
1649
+ })
1650
+ .finally(() => {
1651
+ this.cleanupAnimation();
1652
+ });
1653
+ }
1654
+ performCollapse() {
1655
+ if (!this.contentElement)
1656
+ return;
1657
+ this.cleanupAnimation();
1658
+ this.isAnimating = true;
1659
+ const el = this.contentElement;
1660
+ // Ensure overflow is hidden during animation
1661
+ el.style.overflow = 'hidden';
1662
+ const startHeight = el.scrollHeight;
1663
+ const endHeight = 0;
1664
+ const duration = this.prefersReducedMotion ? 0 : this.animationDuration;
1665
+ el.style.height = `${startHeight}px`;
1666
+ this.animation = el.animate([{ height: `${startHeight}px` }, { height: `${endHeight}px` }], {
1667
+ duration,
1668
+ easing: 'ease',
1669
+ });
1670
+ this.animation.finished
1671
+ .then(() => {
1672
+ el.style.height = '0px';
1673
+ el.style.visibility = 'hidden';
1674
+ el.style.overflow = 'hidden';
1675
+ })
1676
+ .catch(() => {
1677
+ // Animation cancelled
1678
+ })
1679
+ .finally(() => {
1680
+ this.cleanupAnimation();
1681
+ });
1682
+ }
1683
+ renderDefaultTrigger() {
1684
+ const buttonClasses = this.composeClass('btn', this.className, {
1685
+ collapsed: !this.expanded,
1686
+ [`btn-${this.variant}`]: !!this.variant && !this.outline,
1687
+ [`btn-outline-${this.variant}`]: !!this.variant && this.outline,
1688
+ [`btn-${this.size}`]: !!this.size,
1689
+ });
1690
+ const part = this.composeClass('button', 'focusable', {
1691
+ [this.variant]: this.variant?.length > 0,
1692
+ outline: this.outline,
1693
+ });
1694
+ const defaultButtonElement = html `<button
1695
+ type="button"
1696
+ part="${part}"
1697
+ variant="${this.variant}"
1698
+ class="${buttonClasses}"
1699
+ aria-expanded="${this.expanded}"
1700
+ aria-controls="${this._contentId}"
1701
+ id="${this._triggerId}"
1702
+ @click=${this.handleTriggerAction}
1703
+ @keyup=${this.handleTriggerAction}
1704
+ >
1705
+ <slot name="label"></slot>
1706
+ </button>`;
1707
+ if (!this.as || this.as === 'button') {
1708
+ return defaultButtonElement;
1709
+ }
1710
+ const tagName = this.isValidTag(this.as) ? this.as : 'button';
1711
+ const Tag = unsafeStatic(tagName);
1712
+ return html `${html$1 `<${Tag} part="${part}" role="button" aria-expanded="${this.expanded}" aria-controls="${this._contentId}" id="${this._triggerId}" @click=${this.handleTriggerAction}
1713
+ @keyup=${this.handleTriggerAction} tabindex="0" class="${buttonClasses}"><slot name="label"></slot></${Tag}>`}`;
1714
+ }
1715
+ hasSlottedTrigger() {
1716
+ return !!this.triggerElement;
1717
+ }
1718
+ // eslint-disable-next-line class-methods-use-this
1719
+ isValidTag(tag) {
1720
+ const safeTags = ['div', 'span', 'li', 'p', 'a', 'button'];
1721
+ return safeTags.includes(tag.toLowerCase());
1722
+ }
1723
+ render() {
1724
+ // Nota sull'estensione: quando passi this.renderDefaultTrigger come callback a when
1725
+ // la funzione viene chiamata senza contesto (this viene perso) — devi chiamare il metodo tramite closure
1726
+ // che mantiene il contesto, es. () => this.renderDefaultTrigger().
1727
+ const hasCustomTrigger = this.hasSlottedTrigger();
1728
+ const classPrefix = this.isAccordion ? 'accordion-' : 'collapse-';
1729
+ return html `
1730
+ <div class="${classPrefix}item" part="${classPrefix}item">
1731
+ <div class="collapse-wrapper">
1732
+ ${when(!hasCustomTrigger, () => this.renderDefaultTrigger())}
1733
+ <slot name="trigger" @slotchange=${this._onTriggerSlotChange} part="trigger"></slot>
1734
+ <div
1735
+ class="collapse-content"
1736
+ part="content"
1737
+ role="region"
1738
+ aria-labelledby="${this._triggerId}"
1739
+ id="${this._contentId}"
1740
+ >
1741
+ <div class="${classPrefix}body">
1742
+ <slot name="content"></slot>
1743
+ </div>
1744
+ </div>
1745
+ </div>
1746
+ </div>
1747
+ `;
1748
+ }
1749
+ }
1750
+ ItCollapseBase.styles = styles;
1751
+ ItCollapseBase.shadowRootOptions = {
1752
+ ...BaseComponent.shadowRootOptions,
1753
+ delegatesFocus: true,
1754
+ };
1755
+ __decorate([
1756
+ property({ type: String, reflect: true }),
1757
+ __metadata("design:type", Object)
1758
+ ], ItCollapseBase.prototype, "variant", void 0);
1759
+ __decorate([
1760
+ property({ type: String, reflect: true }),
1761
+ __metadata("design:type", Object)
1762
+ ], ItCollapseBase.prototype, "size", void 0);
1763
+ __decorate([
1764
+ property({ type: Boolean, reflect: true }),
1765
+ __metadata("design:type", Object)
1766
+ ], ItCollapseBase.prototype, "outline", void 0);
1767
+ __decorate([
1768
+ property({ type: Boolean, reflect: true }),
1769
+ __metadata("design:type", Object)
1770
+ ], ItCollapseBase.prototype, "expanded", void 0);
1771
+ __decorate([
1772
+ property({ type: String, reflect: true }),
1773
+ __metadata("design:type", String)
1774
+ ], ItCollapseBase.prototype, "as", void 0);
1775
+ __decorate([
1776
+ property({ type: Boolean, attribute: 'default-open', reflect: true }),
1777
+ __metadata("design:type", Object)
1778
+ ], ItCollapseBase.prototype, "defaultOpen", void 0);
1779
+ __decorate([
1780
+ query('.collapse-content'),
1781
+ __metadata("design:type", HTMLElement)
1782
+ ], ItCollapseBase.prototype, "contentElement", void 0);
1783
+ __decorate([
1784
+ queryAssignedElements({ slot: 'trigger' }),
1785
+ __metadata("design:type", Array)
1786
+ ], ItCollapseBase.prototype, "triggerElements", void 0);
1787
+
1788
+ // TODO: quando si sviluppa collapse come componente standalone, decoupling dalle classi di accordion, e aggiornare il part name
1789
+ let ItCollapse = class ItCollapse extends ItCollapseBase {
1790
+ };
1791
+ ItCollapse = __decorate([
1792
+ customElement('it-collapse')
1793
+ ], ItCollapse);
1794
+
1795
+ let ItAccordionItem = class ItAccordionItem extends ItCollapseBase {
11
1796
  constructor() {
12
1797
  super(...arguments);
13
1798
  this.as = 'h2';
14
1799
  this.leftIcon = false;
15
1800
  this.backgroundActive = false;
16
1801
  this.backgroundHover = false;
1802
+ this.isAccordion = true;
17
1803
  }
18
1804
  setParentBackground(backgroundActive, backgroundHover) {
19
1805
  this.backgroundActive = backgroundActive;
@@ -61,6 +1847,11 @@ let ItAccordionItem = class ItAccordionItem extends ItCollapse {
61
1847
  `}
62
1848
  `;
63
1849
  }
1850
+ // eslint-disable-next-line class-methods-use-this
1851
+ isValidTag(tag) {
1852
+ const safeTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
1853
+ return safeTags.includes(tag.toLowerCase());
1854
+ }
64
1855
  updateBackgroundStyles() {
65
1856
  // Aggiorna l'icona sinistra se presente
66
1857
  if (this.leftIcon) {
@@ -96,24 +1887,24 @@ let ItAccordionItem = class ItAccordionItem extends ItCollapse {
96
1887
  };
97
1888
  // Eredita tutte le proprietà da ItCollapse
98
1889
  // Aggiunge solo alias semantici per le proprietà accordion
99
- ItAccordionItem.styles = styles;
100
- __decorate([
1890
+ ItAccordionItem.styles = styles$1;
1891
+ __decorate$1([
101
1892
  property({ type: String }),
102
- __metadata("design:type", String)
1893
+ __metadata$1("design:type", String)
103
1894
  ], ItAccordionItem.prototype, "as", void 0);
104
- __decorate([
1895
+ __decorate$1([
105
1896
  property({ type: Boolean, attribute: 'left-icon', reflect: true }),
106
- __metadata("design:type", Object)
1897
+ __metadata$1("design:type", Object)
107
1898
  ], ItAccordionItem.prototype, "leftIcon", void 0);
108
- __decorate([
1899
+ __decorate$1([
109
1900
  property({ type: Boolean, attribute: 'background-active', reflect: true }),
110
- __metadata("design:type", Object)
1901
+ __metadata$1("design:type", Object)
111
1902
  ], ItAccordionItem.prototype, "backgroundActive", void 0);
112
- __decorate([
1903
+ __decorate$1([
113
1904
  property({ type: Boolean, attribute: 'background-hover', reflect: true }),
114
- __metadata("design:type", Object)
1905
+ __metadata$1("design:type", Object)
115
1906
  ], ItAccordionItem.prototype, "backgroundHover", void 0);
116
- ItAccordionItem = __decorate([
1907
+ ItAccordionItem = __decorate$1([
117
1908
  customElement('it-accordion-item')
118
1909
  ], ItAccordionItem);
119
1910