@@ -709,7 +709,6 @@ async function ensureDeps(opts: EuroPlateOptions, log: Logger, BADGE: BadgeFn =
709709 // —————————————————————————————————————
710710 const msg = err instanceof Error ? err . message : JSON . stringify ( err ?? "unknown" ) ;
711711 BADGE ( "EPV[Deps]" , `Error during ensureDeps: ${ msg } ` , "err" ) ;
712- log . error ?.( "ensureDeps failed:" , err ) ;
713712 } finally {
714713 // —————————————————————————————————————
715714 // Log tempo di completamento / debug telemetria
@@ -1208,7 +1207,7 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
12081207 } catch { }
12091208 ( el as any ) . _imInstance = null ;
12101209 } , 0 ) ;
1211- log . debug ?. ( " mask:clear (hard)") ;
1210+ BADGE ( "EuroPlate" , " mask:clear (hard)" , "debug ") ;
12121211 }
12131212 const hardClearMaskDebounced = debounce ( hardClearMask , timings . clear ) ;
12141213
@@ -1219,13 +1218,13 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
12191218
12201219 const applyMaskDebounced = debounce ( ( inputEl : HTMLInputElement , country : string ) => {
12211220 if ( ! hasIMBound ( ) ) {
1222- log . warn ?. ( " Inputmask non disponibile: salto applyMask") ;
1221+ BADGE ( "EuroPlate" , " Inputmask non disponibile: salto applyMask" , "warn ") ;
12231222 return ;
12241223 }
12251224 const IM = getIMBound ( ) ! as IMGlobal ; // tipo: IMGlobal
12261225
12271226 if ( ! IM ) {
1228- log . warn ?. ( "AGAIN: Inputmask non disponibile: RETURN!") ;
1227+ BADGE ( "EuroPlate" , " Inputmask non disponibile (again) : RETURN!" , "warn ") ;
12291228 return ;
12301229 }
12311230
@@ -1277,9 +1276,42 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
12771276
12781277 instance . mask ( inputEl ) ;
12791278 ( inputEl as any ) . _imInstance = instance ;
1280- log . debug ?. ( "mask:apply" , country , optsIM . mask ) ;
1279+ BADGE ( "EuroPlate" , JSON . stringify ( { logMsg : "mask:apply" , country, mask : optsIM . mask } , null , 2 ) , "debug" ) ;
12811280 } , timings . debounce ) ;
12821281
1282+ function clearStatusUI ( input : HTMLInputElement , status ?: HTMLElement , wrap ?: HTMLElement | null ) {
1283+ // input & wrapper: rimuovi classi stato
1284+ input . classList . remove ( "valid" , "invalid" ) ;
1285+ if ( wrap ) wrap . classList . remove ( "valid" , "invalid" ) ;
1286+ input . setAttribute ( "aria-invalid" , "false" ) ;
1287+ input . setCustomValidity ( "" ) ;
1288+
1289+ if ( ! status ) return ;
1290+
1291+ // inline: togli proprio data-state → niente padding via :has()
1292+ // // ✨ chiave: sparisce lo stato → niente :has([data-state]) nel CSS
1293+ status . removeAttribute ( "data-state" ) ;
1294+
1295+ // pulisci icona/testo se presenti
1296+ const iconEl = status . querySelector ( ".s-icon" ) as HTMLElement | null ;
1297+ const textEl = status . querySelector ( ".s-text" ) as HTMLElement | null ;
1298+ // reset eventuale .pill ok/err
1299+ if ( iconEl ) {
1300+ iconEl . className = "s-icon" ;
1301+ iconEl . textContent = "" ;
1302+ }
1303+ if ( textEl ) {
1304+ textEl . textContent = "" ;
1305+ textEl . style . display = "none" ;
1306+ }
1307+
1308+ // block mode: neutro
1309+ if ( status . classList . contains ( "status" ) ) {
1310+ status . className = "status" ;
1311+ status . textContent = "" ;
1312+ }
1313+ }
1314+
12831315 // setValidityUI
12841316 function setValidityUI ( ok : boolean | null , msg : string , matchCountry : CountryKey | null , input : HTMLInputElement , status : HTMLElement | undefined , lang : Lang , wrap ?: HTMLElement | null ) {
12851317 // INPUT: classi + aria
@@ -1424,7 +1456,7 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
14241456 //setValidityUI(true as any, "", null, input, statusEl, lang, wrapperEl);
14251457 //input.classList.remove("valid", "invalid");
14261458 //wrapperEl?.classList.remove("valid", "invalid");
1427- setValidityUI ( null , "" , null , input , statusEl , lang , wrapperEl ) ; // 👈 idle
1459+ clearStatusUI ( input , statusEl , wrapperEl ) ; // 👈 niente stato
14281460 if ( selected === "AUTO" ) {
14291461 hardClearMaskDebounced ( input ) ;
14301462 input . placeholder = placeholders . auto || "" ;
@@ -1445,7 +1477,7 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
14451477 if ( v2 !== raw ) input . value = raw = v2 ;
14461478 }
14471479 // non validiamo finche nn c e un risultato minimo
1448- if ( raw . trim ( ) ?. length <= 2 ) return { ok : false , value : raw } ;
1480+ if ( raw . trim ( ) ?. length <= 2 ) return { ok : false , value : raw } ;
14491481
14501482 const countries = selected === "AUTO" ? allowed : [ selected ] ;
14511483 const res = validatePlate ( raw , countries , { vehicleType } ) ;
@@ -1527,22 +1559,49 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
15271559 let next : "AUTO" | CountryKey = "AUTO" ;
15281560 if ( code !== "AUTO" ) {
15291561 const n = normalize ( String ( code || "" ) ) ;
1530- if ( isCountryKey ( n ) ) next = n ;
1531- else next = "AUTO" ;
1562+ next = isCountryKey ( n ) ? ( n as CountryKey ) : "AUTO" ;
15321563 }
1564+
1565+ // salva il precedente per sicurezza (se ti serve altrove)
1566+ const prev = selected ;
15331567 selected = next ;
15341568
1569+ // flag + placeholder
1570+ setFlag ( selected , flagIcon , flagLabel , lang ) ;
1571+ updatePlaceholderForCurrentSelection ( selected , input , EuroMod , lang ) ;
15351572 // flag + placeholder
15361573 setFlag ( selected , flagIcon , flagLabel , lang ) ;
15371574 updatePlaceholderForCurrentSelection ( selected , input , EuroMod , lang ) ;
15381575
1539- // mask
1576+ // ⚠️ IMPORTANTISSIMO: rimuovi SUBITO la vecchia mask (no debounce)
1577+ hardClearMask ( input ) ; // usa la versione NON debounced
1578+
1579+ const hasText = ! ! input . value . trim ( ) ;
1580+ const short = hasText && input . value . trim ( ) . length <= 2 ;
1581+
15401582 if ( selected === "AUTO" ) {
1541- hardClearMaskDebounced ( input ) ;
1583+ // AUTO: niente mask
1584+ if ( ! hasText ) {
1585+ clearStatusUI ( input , statusEl , wrapperEl ) ; // stato neutro
1586+ } else {
1587+ // opzionale: riallinea subito contro allowed
1588+ validateNow ( ) ;
1589+ }
15421590 } else {
1543- const v = fmtFor ( selected , input . value ) ;
1544- if ( input . value !== v ) input . value = v ;
1591+ // NON-AUTO: applica la NUOVA mask SEMPRE (anche a campo vuoto)
1592+ if ( hasText ) {
1593+ const v = fmtFor ( selected , input . value ) ;
1594+ if ( input . value !== v ) input . value = v ;
1595+ }
15451596 applyMaskDebounced ( input , selected ) ;
1597+
1598+ // stato neutro se vuoto o corto
1599+ if ( ! hasText || short ) {
1600+ clearStatusUI ( input , statusEl , wrapperEl ) ;
1601+ } else {
1602+ // se vuoi allineare subito (facoltativo)
1603+ validateNow ( ) ;
1604+ }
15461605 }
15471606
15481607 // chiudi dropdown
@@ -1608,7 +1667,7 @@ export function createEuroPlate(EuroMod: any, opts: EuroPlateOptions): EuroPlate
16081667 renderDropdown ( ) ;
16091668 selectCountry ( mode , ! ! autoFocusOnInit ) ; // 👈 niente autofocus all’avvio // ok: la funzione normalizza e imposta selected ("AUTO" | CountryKey)
16101669
1611- log . notify ?. ( "EuroPlate pronto ✅" , "success " ) ;
1670+ BADGE ( "EuroPlate" , "Pronto ✅", "ok " ) ;
16121671
16131672 return instance ;
16141673}
0 commit comments