wulf.js 1.8.4 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +93 -21
  2. package/changelog.md +76 -0
  3. package/dist/focus-trap.cjs.js +430 -0
  4. package/dist/focus-trap.cjs.js.map +7 -0
  5. package/dist/focus-trap.esm.js +407 -0
  6. package/dist/focus-trap.esm.js.map +7 -0
  7. package/dist/focus-trap.global.js +433 -0
  8. package/dist/focus-trap.global.js.map +7 -0
  9. package/dist/focus-trap.global.min.js +6 -0
  10. package/dist/focus-trap.global.min.js.map +7 -0
  11. package/dist/index.cjs.js +1177 -59
  12. package/dist/index.cjs.js.map +3 -3
  13. package/dist/index.esm.js +1177 -59
  14. package/dist/index.esm.js.map +3 -3
  15. package/dist/index.global.js +1177 -59
  16. package/dist/index.global.js.map +3 -3
  17. package/dist/index.global.min.js +4 -1
  18. package/dist/index.global.min.js.map +4 -4
  19. package/dist/mask.cjs.js +337 -33
  20. package/dist/mask.cjs.js.map +3 -3
  21. package/dist/mask.css +1 -1
  22. package/dist/mask.css.map +2 -2
  23. package/dist/mask.esm.js +337 -33
  24. package/dist/mask.esm.js.map +3 -3
  25. package/dist/mask.global.js +337 -33
  26. package/dist/mask.global.js.map +3 -3
  27. package/dist/mask.global.min.js +4 -1
  28. package/dist/mask.global.min.js.map +4 -4
  29. package/dist/masonry.cjs.js +296 -10
  30. package/dist/masonry.cjs.js.map +3 -3
  31. package/dist/masonry.esm.js +296 -10
  32. package/dist/masonry.esm.js.map +3 -3
  33. package/dist/masonry.global.js +296 -10
  34. package/dist/masonry.global.js.map +3 -3
  35. package/dist/masonry.global.min.js +4 -1
  36. package/dist/masonry.global.min.js.map +4 -4
  37. package/dist/scroll.cjs.js +332 -9
  38. package/dist/scroll.cjs.js.map +3 -3
  39. package/dist/scroll.esm.js +332 -9
  40. package/dist/scroll.esm.js.map +3 -3
  41. package/dist/scroll.global.js +332 -9
  42. package/dist/scroll.global.js.map +3 -3
  43. package/dist/scroll.global.min.js +4 -1
  44. package/dist/scroll.global.min.js.map +4 -4
  45. package/dist/toast.cjs.js +289 -7
  46. package/dist/toast.cjs.js.map +3 -3
  47. package/dist/toast.css +1 -1
  48. package/dist/toast.css.map +2 -2
  49. package/dist/toast.esm.js +289 -7
  50. package/dist/toast.esm.js.map +3 -3
  51. package/dist/toast.global.js +289 -7
  52. package/dist/toast.global.js.map +3 -3
  53. package/dist/toast.global.min.js +4 -1
  54. package/dist/toast.global.min.js.map +4 -4
  55. package/dist/types/common/AuditableComponent.d.ts +45 -0
  56. package/dist/types/common/LocalizedComponent.d.ts +54 -0
  57. package/dist/types/common/i18n.d.ts +39 -0
  58. package/dist/types/focus-trap/FocusTrap.d.ts +64 -0
  59. package/dist/types/focus-trap/index.d.ts +3 -0
  60. package/dist/types/focus-trap/types.d.ts +45 -0
  61. package/dist/types/index.d.ts +5 -0
  62. package/dist/types/mask/BaseInputMask.d.ts +15 -1
  63. package/dist/types/mask/EmailEngine.d.ts +24 -2
  64. package/dist/types/mask/InputEmailMask.d.ts +8 -0
  65. package/dist/types/mask/InputMask.d.ts +9 -0
  66. package/dist/types/mask/types.d.ts +5 -2
  67. package/dist/types/masonry/Masonry.d.ts +18 -1
  68. package/dist/types/masonry/i18n/en.d.ts +2 -0
  69. package/dist/types/masonry/i18n/fr.d.ts +2 -0
  70. package/dist/types/masonry/i18n/index.d.ts +9 -0
  71. package/dist/types/masonry/i18n/types.d.ts +7 -0
  72. package/dist/types/masonry/index.d.ts +1 -0
  73. package/dist/types/masonry/types.d.ts +15 -5
  74. package/dist/types/scroll/ScrollBlock.d.ts +21 -1
  75. package/dist/types/scroll/i18n/en.d.ts +2 -0
  76. package/dist/types/scroll/i18n/fr.d.ts +2 -0
  77. package/dist/types/scroll/i18n/index.d.ts +9 -0
  78. package/dist/types/scroll/i18n/types.d.ts +11 -0
  79. package/dist/types/scroll/index.d.ts +2 -0
  80. package/dist/types/scroll/types.d.ts +9 -3
  81. package/dist/types/toast/Toast.d.ts +8 -1
  82. package/dist/types/toast/ToastInstance.d.ts +9 -1
  83. package/dist/types/toast/i18n/en.d.ts +2 -0
  84. package/dist/types/toast/i18n/fr.d.ts +2 -0
  85. package/dist/types/toast/i18n/index.d.ts +9 -0
  86. package/dist/types/toast/i18n/types.d.ts +7 -0
  87. package/dist/types/toast/index.d.ts +1 -0
  88. package/dist/types/toast/types.d.ts +12 -3
  89. package/package.json +9 -3
package/dist/mask.cjs.js CHANGED
@@ -35,6 +35,49 @@ __export(index_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
+ // src/common/AuditableComponent.ts
39
+ var AuditableComponent = class {
40
+ /**
41
+ * Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
42
+ */
43
+ getAuditDisableHint() {
44
+ return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
45
+ }
46
+ /**
47
+ * Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
48
+ * si l'audit est activé et que des contraintes manquent.
49
+ */
50
+ runAuditWarning(enabled = true) {
51
+ if (!enabled) return [];
52
+ const warnings = this.audit();
53
+ if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
54
+ console.warn(
55
+ `[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
56
+ ` + warnings.map((w) => ` - ${w}`).join("\n") + `
57
+ (${this.getAuditDisableHint()})`
58
+ );
59
+ }
60
+ return warnings;
61
+ }
62
+ /**
63
+ * Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
64
+ * pointe vers des éléments réellement présents dans le document.
65
+ */
66
+ checkAriaIdReferences(element, attrName, warnings) {
67
+ const rawValue = element.getAttribute(attrName)?.trim();
68
+ if (!rawValue) return false;
69
+ const doc = element.ownerDocument || document;
70
+ const ids = rawValue.split(/\s+/).filter(Boolean);
71
+ const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
72
+ if (!isValid) {
73
+ warnings.push(
74
+ `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
75
+ );
76
+ }
77
+ return isValid;
78
+ }
79
+ };
80
+
38
81
  // src/mask/BaseInputMask.ts
39
82
  function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
40
83
  const isSecondArgInput = Boolean(
@@ -53,8 +96,9 @@ function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOption
53
96
  options: inputOrOptions && typeof inputOrOptions === "object" && !("tagName" in inputOrOptions) ? inputOrOptions : {}
54
97
  };
55
98
  }
56
- var BaseInputMask = class {
99
+ var BaseInputMask = class extends AuditableComponent {
57
100
  constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
101
+ super();
58
102
  this.ghost = null;
59
103
  this.isWrapperCreated = false;
60
104
  this.isDestroyed = false;
@@ -65,6 +109,7 @@ var BaseInputMask = class {
65
109
  this.onCutHandler = () => {
66
110
  };
67
111
  this.mutationObserver = null;
112
+ this.focusSelectTimerId = null;
68
113
  this.onBaseCopy = (e) => {
69
114
  if (!this.options.copyRaw || this.options.disabled || this.input.type === "password") return;
70
115
  const start = this.input.selectionStart ?? 0;
@@ -83,7 +128,11 @@ var BaseInputMask = class {
83
128
  this.onBaseFocus = () => {
84
129
  this.isFocused = true;
85
130
  if (this.options.selectAllOnFocus && this.input.value.length > 0) {
86
- setTimeout(() => {
131
+ if (this.focusSelectTimerId !== null) {
132
+ clearTimeout(this.focusSelectTimerId);
133
+ }
134
+ this.focusSelectTimerId = window.setTimeout(() => {
135
+ this.focusSelectTimerId = null;
87
136
  if (!this.isDestroyed && document.activeElement === this.input) {
88
137
  this.input.select();
89
138
  }
@@ -102,7 +151,7 @@ var BaseInputMask = class {
102
151
  }
103
152
  };
104
153
  const { wrapper: providedWrapper, input, options } = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions);
105
- if (!input || !(input instanceof HTMLElement) || input.tagName !== "INPUT") {
154
+ if (!input || typeof input !== "object" || input.nodeType !== 1 || input.tagName !== "INPUT") {
106
155
  throw new Error(`[${new.target.name || "InputMask"}] input (HTMLInputElement) est requis.`);
107
156
  }
108
157
  this.input = input;
@@ -137,8 +186,10 @@ var BaseInputMask = class {
137
186
  const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
138
187
  const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
139
188
  const dataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
189
+ const dataAudit = this.getAttr("data-mask-audit");
140
190
  const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
141
191
  const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
192
+ const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
142
193
  const isPassword = this.input.type === "password";
143
194
  this.options = {
144
195
  ...otherOptions,
@@ -148,7 +199,8 @@ var BaseInputMask = class {
148
199
  copyRaw: isPassword ? false : options.copyRaw ?? dataCopyRaw ?? false,
149
200
  disabled: resolvedDisabled,
150
201
  align: optAlign ?? (dataAlign || void 0),
151
- emitNativeInput: options.emitNativeInput ?? true
202
+ emitNativeInput: options.emitNativeInput ?? true,
203
+ audit: resolvedAudit
152
204
  };
153
205
  if (this.options.showMaskOnFocus) {
154
206
  this.wrapper.classList.add("mask-focus-only");
@@ -227,6 +279,8 @@ var BaseInputMask = class {
227
279
  "data-mask-pad-decimals",
228
280
  "data-mask-auto-lowercase",
229
281
  "data-mask-cycle-suggestions",
282
+ "data-mask-default-tld",
283
+ "data-mask-tlds",
230
284
  "data-disabled",
231
285
  "data-mask-align",
232
286
  "data-align",
@@ -491,12 +545,58 @@ var BaseInputMask = class {
491
545
  getRawValue() {
492
546
  return this.input.value;
493
547
  }
548
+ /**
549
+ * Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
550
+ * et retourne la liste des contraintes manquantes.
551
+ */
552
+ audit() {
553
+ const warnings = [];
554
+ const doc = this.input.ownerDocument || document;
555
+ const ariaLabel = this.input.getAttribute("aria-label")?.trim();
556
+ const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
557
+ const hasWrappingLabel = Boolean(this.input.closest("label"));
558
+ const hasNativeLabels = Boolean(this.input.labels && this.input.labels.length > 0);
559
+ let hasExplicitLabelFor = false;
560
+ if (this.input.id && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
561
+ hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${CSS.escape(this.input.id)}"]`));
562
+ } else if (this.input.id) {
563
+ hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${this.input.id}"]`));
564
+ }
565
+ if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
566
+ warnings.push(
567
+ `\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
568
+ );
569
+ }
570
+ this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
571
+ const extraWarnings = this.getSpecificAuditWarnings();
572
+ warnings.push(...extraWarnings);
573
+ return warnings;
574
+ }
575
+ getAuditPrefix() {
576
+ return `Wulf.Mask.${this.constructor.name || "InputMask"}`;
577
+ }
578
+ getAuditTargetLabel() {
579
+ return this.input.id ? `#${this.input.id}` : this.input.name ? `input[name="${this.input.name}"]` : "<input>";
580
+ }
581
+ getAuditDisableHint() {
582
+ return 'Passez { audit: false } ou data-mask-audit="false" pour d\xE9sactiver cet avertissement';
583
+ }
584
+ /**
585
+ * Crochet permettant aux classes filles d'ajouter des vérifications d'audit spécifiques.
586
+ */
587
+ getSpecificAuditWarnings() {
588
+ return [];
589
+ }
494
590
  /**
495
591
  * Supprime les éléments fantômes, restaure les propriétés et nettoie les attributs.
496
592
  */
497
593
  destroy() {
498
594
  if (this.isDestroyed) return;
499
595
  this.isDestroyed = true;
596
+ if (this.focusSelectTimerId !== null) {
597
+ clearTimeout(this.focusSelectTimerId);
598
+ this.focusSelectTimerId = null;
599
+ }
500
600
  if (this.mutationObserver) {
501
601
  this.mutationObserver.disconnect();
502
602
  this.mutationObserver = null;
@@ -1258,6 +1358,9 @@ var InputMask = class extends BaseInputMask {
1258
1358
  this.onChangeNativeHandler = () => {
1259
1359
  };
1260
1360
  this.wasInputModeInferred = false;
1361
+ this.cutTimerId = null;
1362
+ this.pasteTimerId = null;
1363
+ this.resetTimerId = null;
1261
1364
  this.history = new MaskHistory();
1262
1365
  this.engine = new MaskEngine(this.options.mask || "", {
1263
1366
  placeholderChar: this.options.placeholderChar,
@@ -1265,12 +1368,7 @@ var InputMask = class extends BaseInputMask {
1265
1368
  strict: this.options.strict,
1266
1369
  autoLowercase: this.options.autoLowercase
1267
1370
  });
1268
- if (this.options.inferInputMode && !this.input.hasAttribute("inputmode")) {
1269
- if (this.engine.isNumericOnly()) {
1270
- this.input.inputMode = "numeric";
1271
- this.wasInputModeInferred = true;
1272
- }
1273
- }
1371
+ this.syncInferredInputMode();
1274
1372
  this.keyboard = new MaskKeyboard({
1275
1373
  getInput: () => this.input,
1276
1374
  getEngine: () => this.engine,
@@ -1283,6 +1381,19 @@ var InputMask = class extends BaseInputMask {
1283
1381
  this.bindEvents();
1284
1382
  this.lastValue = this.input.value;
1285
1383
  this.syncInitialValue();
1384
+ this.runAuditWarning(this.options.audit);
1385
+ }
1386
+ getSpecificAuditWarnings() {
1387
+ const warnings = [];
1388
+ const hasDescribedby = Boolean(this.input.getAttribute("aria-describedby")?.trim());
1389
+ const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
1390
+ const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
1391
+ if (!hasDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
1392
+ warnings.push(
1393
+ "Indication du format attendu manquante : d\xE9finissez aria-describedby, placeholder ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
1394
+ );
1395
+ }
1396
+ return warnings;
1286
1397
  }
1287
1398
  extractRawSnippet(snippet) {
1288
1399
  return this.engine.extractRaw(snippet);
@@ -1334,7 +1445,9 @@ var InputMask = class extends BaseInputMask {
1334
1445
  this.onScroll = this.onScroll.bind(this);
1335
1446
  this.onBeforeInput = this.onBeforeInput.bind(this);
1336
1447
  this.onCutHandler = () => {
1337
- setTimeout(() => {
1448
+ if (this.cutTimerId !== null) clearTimeout(this.cutTimerId);
1449
+ this.cutTimerId = window.setTimeout(() => {
1450
+ this.cutTimerId = null;
1338
1451
  if (this.isDestroyed) return;
1339
1452
  if (this.options.disabled) {
1340
1453
  this.checkValueChange();
@@ -1366,7 +1479,9 @@ var InputMask = class extends BaseInputMask {
1366
1479
  this.input.addEventListener("change", this.onChangeNativeHandler);
1367
1480
  if (this.input.form) {
1368
1481
  this.onFormResetHandler = () => {
1369
- setTimeout(() => {
1482
+ if (this.resetTimerId !== null) clearTimeout(this.resetTimerId);
1483
+ this.resetTimerId = window.setTimeout(() => {
1484
+ this.resetTimerId = null;
1370
1485
  if (this.isDestroyed) return;
1371
1486
  if (this.options.disabled) {
1372
1487
  this.checkValueChange();
@@ -1378,11 +1493,40 @@ var InputMask = class extends BaseInputMask {
1378
1493
  this.input.form.addEventListener("reset", this.onFormResetHandler);
1379
1494
  }
1380
1495
  }
1496
+ /**
1497
+ * Synchronise dynamiquement l'attribut inputmode="numeric" selon le motif actif
1498
+ * sans jamais écraser un inputmode défini explicitement par l'hôte.
1499
+ */
1500
+ syncInferredInputMode() {
1501
+ if (!this.options.inferInputMode) return;
1502
+ const isNum = !this.options.disabled && this.engine.isNumericOnly();
1503
+ if (isNum) {
1504
+ if (!this.input.hasAttribute("inputmode")) {
1505
+ this.input.inputMode = "numeric";
1506
+ this.wasInputModeInferred = true;
1507
+ }
1508
+ } else if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "numeric") {
1509
+ this.input.removeAttribute("inputmode");
1510
+ this.wasInputModeInferred = false;
1511
+ }
1512
+ }
1381
1513
  /**
1382
1514
  * Supprime tous les écouteurs et nettoie les attributs associés.
1383
1515
  */
1384
1516
  destroy() {
1385
1517
  if (this.isDestroyed) return;
1518
+ if (this.cutTimerId !== null) {
1519
+ clearTimeout(this.cutTimerId);
1520
+ this.cutTimerId = null;
1521
+ }
1522
+ if (this.pasteTimerId !== null) {
1523
+ clearTimeout(this.pasteTimerId);
1524
+ this.pasteTimerId = null;
1525
+ }
1526
+ if (this.resetTimerId !== null) {
1527
+ clearTimeout(this.resetTimerId);
1528
+ this.resetTimerId = null;
1529
+ }
1386
1530
  this.input.removeEventListener("beforeinput", this.onBeforeInput);
1387
1531
  this.input.removeEventListener("input", this.handleInput);
1388
1532
  this.input.removeEventListener("keydown", this.onKeyDown);
@@ -1444,6 +1588,7 @@ var InputMask = class extends BaseInputMask {
1444
1588
  this.history.clear();
1445
1589
  }
1446
1590
  this.setDisabled(true);
1591
+ this.syncInferredInputMode();
1447
1592
  return;
1448
1593
  }
1449
1594
  this.options.mask = newPattern;
@@ -1454,6 +1599,7 @@ var InputMask = class extends BaseInputMask {
1454
1599
  this.history.clear();
1455
1600
  }
1456
1601
  this.setDisabled(false);
1602
+ this.syncInferredInputMode();
1457
1603
  }
1458
1604
  handleAttributeMutation(attrName) {
1459
1605
  super.handleAttributeMutation(attrName);
@@ -1611,7 +1757,9 @@ var InputMask = class extends BaseInputMask {
1611
1757
  }
1612
1758
  onPaste(e) {
1613
1759
  if (this.options.disabled) {
1614
- setTimeout(() => {
1760
+ if (this.pasteTimerId !== null) clearTimeout(this.pasteTimerId);
1761
+ this.pasteTimerId = window.setTimeout(() => {
1762
+ this.pasteTimerId = null;
1615
1763
  if (!this.isDestroyed) this.checkValueChange();
1616
1764
  }, 0);
1617
1765
  return;
@@ -2095,6 +2243,7 @@ var InputAmountMask = class extends BaseInputMask {
2095
2243
  isValid: true
2096
2244
  });
2097
2245
  }
2246
+ this.runAuditWarning(this.options.audit);
2098
2247
  }
2099
2248
  extractRawSnippet(snippet) {
2100
2249
  const p = this.engine.parse(snippet);
@@ -2420,9 +2569,12 @@ var InputAmountMask = class extends BaseInputMask {
2420
2569
  var _EmailEngine = class _EmailEngine {
2421
2570
  constructor(options = {}) {
2422
2571
  this.defaultDomain = null;
2572
+ this.defaultTld = "__";
2423
2573
  this.domains = options.domains && options.domains.length > 0 ? options.domains : _EmailEngine.DEFAULT_DOMAINS;
2574
+ this.tlds = options.tlds && options.tlds.length > 0 ? options.tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2424
2575
  this.suggestOnAt = options.suggestOnAt ?? true;
2425
2576
  this.setDefaultDomain(options.defaultDomain ?? null);
2577
+ this.setDefaultTld(options.defaultTld !== void 0 ? options.defaultTld : "__");
2426
2578
  }
2427
2579
  /**
2428
2580
  * Définit ou modifie le domaine suggéré par défaut.
@@ -2436,6 +2588,35 @@ var _EmailEngine = class _EmailEngine {
2436
2588
  this.defaultDomain = null;
2437
2589
  }
2438
2590
  }
2591
+ /**
2592
+ * Définit ou modifie l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
2593
+ */
2594
+ setDefaultTld(tld) {
2595
+ if (tld === true) {
2596
+ this.defaultTld = this.tlds.length > 0 ? this.tlds[0] : null;
2597
+ } else if (typeof tld === "string" && tld.trim().length > 0) {
2598
+ this.defaultTld = tld.trim().replace(/^\./, "");
2599
+ } else {
2600
+ this.defaultTld = null;
2601
+ }
2602
+ }
2603
+ /**
2604
+ * Définit ou modifie la liste des extensions (TLD) proposées par ordre de priorité.
2605
+ */
2606
+ setTlds(tlds) {
2607
+ this.tlds = tlds && tlds.length > 0 ? tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2608
+ }
2609
+ /**
2610
+ * Retourne l'ensemble des extensions (TLD) correspondant au fragment saisi après le dernier point,
2611
+ * dans l'ordre exact fourni par l'utilisateur.
2612
+ */
2613
+ getMatchingTlds(tldInput) {
2614
+ const query = (tldInput ?? "").toLowerCase();
2615
+ if (query.length === 0) {
2616
+ return [...this.tlds];
2617
+ }
2618
+ return this.tlds.filter((t) => t.toLowerCase().startsWith(query) && t.toLowerCase() !== query);
2619
+ }
2439
2620
  /**
2440
2621
  * Retourne l'ensemble des domaines correspondant à la saisie courante.
2441
2622
  */
@@ -2456,10 +2637,10 @@ var _EmailEngine = class _EmailEngine {
2456
2637
  return this.domains.filter((d) => d.toLowerCase().startsWith(query) && d.toLowerCase() !== query);
2457
2638
  }
2458
2639
  /**
2459
- * Analyse la saisie courante et calcule la suggestion de domaine adaptée.
2640
+ * Analyse la saisie courante et calcule la suggestion de domaine ou d'extension (TLD) adaptée.
2460
2641
  *
2461
2642
  * @param input Saisie utilisateur
2462
- * @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines correspondent (permet le cyclage)
2643
+ * @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines/TLD correspondent (permet le cyclage)
2463
2644
  */
2464
2645
  getSuggestion(input, matchIndex = 0) {
2465
2646
  const val = input ?? "";
@@ -2468,30 +2649,104 @@ var _EmailEngine = class _EmailEngine {
2468
2649
  return {
2469
2650
  full: val ? `${val}@${this.defaultDomain}` : `@${this.defaultDomain}`,
2470
2651
  remaining: `@${this.defaultDomain}`,
2471
- matchedDomain: this.defaultDomain
2652
+ matchedDomain: this.defaultDomain,
2653
+ isHintOnly: false
2472
2654
  };
2473
2655
  }
2474
- return { full: val, remaining: "", matchedDomain: null };
2656
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2475
2657
  }
2476
2658
  const atIndex = val.indexOf("@");
2477
2659
  const localPart = val.substring(0, atIndex);
2478
2660
  const domainPart = val.substring(atIndex + 1);
2479
2661
  if (val.indexOf("@", atIndex + 1) !== -1) {
2480
- return { full: val, remaining: "", matchedDomain: null };
2662
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2481
2663
  }
2482
2664
  const matches = this.getMatchingDomains(input);
2483
- if (matches.length === 0) {
2484
- return { full: input, remaining: "", matchedDomain: null };
2665
+ if (matches.length > 0) {
2666
+ const safeIndex = (matchIndex % matches.length + matches.length) % matches.length;
2667
+ const matched = matches[safeIndex];
2668
+ const query = domainPart.toLowerCase();
2669
+ const remaining = matched.substring(query.length);
2670
+ return {
2671
+ full: `${localPart}@${matched}`,
2672
+ remaining,
2673
+ matchedDomain: matched,
2674
+ isHintOnly: false
2675
+ };
2485
2676
  }
2486
- const safeIndex = (matchIndex % matches.length + matches.length) % matches.length;
2487
- const matched = matches[safeIndex];
2488
- const query = domainPart.toLowerCase();
2489
- const remaining = matched.substring(query.length);
2490
- return {
2491
- full: `${localPart}@${matched}`,
2492
- remaining,
2493
- matchedDomain: matched
2494
- };
2677
+ if (domainPart.length === 0 || domainPart.startsWith(".")) {
2678
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2679
+ }
2680
+ const lowerDomain = domainPart.toLowerCase();
2681
+ if (this.domains.some((d) => d.toLowerCase() === lowerDomain)) {
2682
+ return { full: input, remaining: "", matchedDomain: domainPart, isHintOnly: false };
2683
+ }
2684
+ const lastDotIndex = domainPart.lastIndexOf(".");
2685
+ if (lastDotIndex === -1) {
2686
+ if (!this.defaultTld) {
2687
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2688
+ }
2689
+ const isHint = this.defaultTld.includes("_");
2690
+ const remaining = `.${this.defaultTld}`;
2691
+ const fullDomain = `${domainPart}.${this.defaultTld}`;
2692
+ return {
2693
+ full: isHint ? input : `${localPart}@${fullDomain}`,
2694
+ remaining,
2695
+ matchedDomain: isHint ? null : fullDomain,
2696
+ isHintOnly: isHint
2697
+ };
2698
+ }
2699
+ const hostPart = domainPart.substring(0, lastDotIndex);
2700
+ const tldPart = domainPart.substring(lastDotIndex + 1);
2701
+ if (!hostPart || hostPart.endsWith(".")) {
2702
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2703
+ }
2704
+ if (tldPart.length === 0) {
2705
+ if (this.defaultTld && !this.defaultTld.includes("_")) {
2706
+ const fullDomain = `${hostPart}.${this.defaultTld}`;
2707
+ return {
2708
+ full: `${localPart}@${fullDomain}`,
2709
+ remaining: this.defaultTld,
2710
+ matchedDomain: fullDomain,
2711
+ isHintOnly: false
2712
+ };
2713
+ }
2714
+ if (this.defaultTld && this.defaultTld.includes("_")) {
2715
+ return {
2716
+ full: input,
2717
+ remaining: this.defaultTld,
2718
+ matchedDomain: null,
2719
+ isHintOnly: true
2720
+ };
2721
+ }
2722
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2723
+ }
2724
+ const lowerTld = tldPart.toLowerCase();
2725
+ const matchingTlds = this.getMatchingTlds(tldPart);
2726
+ if (matchingTlds.length > 0) {
2727
+ const safeTldIndex = (matchIndex % matchingTlds.length + matchingTlds.length) % matchingTlds.length;
2728
+ const matchedTld = matchingTlds[safeTldIndex];
2729
+ const remaining = matchedTld.substring(lowerTld.length);
2730
+ const fullDomain = `${hostPart}.${matchedTld}`;
2731
+ return {
2732
+ full: `${localPart}@${fullDomain}`,
2733
+ remaining,
2734
+ matchedDomain: fullDomain,
2735
+ isHintOnly: false
2736
+ };
2737
+ }
2738
+ if (this.defaultTld && this.defaultTld.includes("_") && tldPart.length < this.defaultTld.length) {
2739
+ const remaining = this.defaultTld.substring(tldPart.length);
2740
+ if (remaining.includes("_")) {
2741
+ return {
2742
+ full: input,
2743
+ remaining,
2744
+ matchedDomain: null,
2745
+ isHintOnly: true
2746
+ };
2747
+ }
2748
+ }
2749
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2495
2750
  }
2496
2751
  };
2497
2752
  _EmailEngine.DEFAULT_DOMAINS = [
@@ -2506,6 +2761,27 @@ _EmailEngine.DEFAULT_DOMAINS = [
2506
2761
  "laposte.net",
2507
2762
  "proton.me"
2508
2763
  ];
2764
+ _EmailEngine.DEFAULT_TLDS = [
2765
+ "com",
2766
+ "fr",
2767
+ "net",
2768
+ "org",
2769
+ "eu",
2770
+ "io",
2771
+ "co",
2772
+ "info",
2773
+ "biz",
2774
+ "me",
2775
+ "tv",
2776
+ "fi",
2777
+ "be",
2778
+ "ch",
2779
+ "ca",
2780
+ "uk",
2781
+ "de",
2782
+ "es",
2783
+ "it"
2784
+ ];
2509
2785
  var EmailEngine = _EmailEngine;
2510
2786
 
2511
2787
  // src/mask/InputEmailMask.ts
@@ -2519,6 +2795,10 @@ var InputEmailMask = class extends BaseInputMask {
2519
2795
  const dataAutoLower = wrap?.getAttribute("data-mask-auto-lowercase") === "true" || inp?.getAttribute("data-mask-auto-lowercase") === "true";
2520
2796
  const dataAriaAuto = wrap?.getAttribute("data-mask-aria-autocomplete") ?? inp?.getAttribute("data-mask-aria-autocomplete");
2521
2797
  const setAriaAutocomplete = opts.setAriaAutocomplete ?? (dataAriaAuto !== null ? dataAriaAuto !== "false" : true);
2798
+ const dataTlds = wrap?.getAttribute("data-mask-tlds") ?? inp?.getAttribute("data-mask-tlds");
2799
+ const parsedTlds = opts.tlds ?? (dataTlds ? dataTlds.split(",").map((s) => s.trim()).filter(Boolean) : void 0);
2800
+ const dataDefaultTld = wrap?.getAttribute("data-mask-default-tld") ?? inp?.getAttribute("data-mask-default-tld");
2801
+ const resolvedDefaultTld = opts.defaultTld !== void 0 ? opts.defaultTld : dataDefaultTld !== null ? dataDefaultTld === "false" || dataDefaultTld === "none" ? null : dataDefaultTld === "true" ? true : dataDefaultTld : void 0;
2522
2802
  const resolvedOptions = {
2523
2803
  completeOnTab: true,
2524
2804
  completeOnArrowRight: true,
@@ -2526,7 +2806,9 @@ var InputEmailMask = class extends BaseInputMask {
2526
2806
  cycleSuggestions: opts.cycleSuggestions ?? dataCycle ?? false,
2527
2807
  autoLowercase: opts.autoLowercase ?? dataAutoLower ?? false,
2528
2808
  setAriaAutocomplete,
2529
- ...opts
2809
+ ...opts,
2810
+ ...parsedTlds !== void 0 ? { tlds: parsedTlds } : {},
2811
+ ...resolvedDefaultTld !== void 0 ? { defaultTld: resolvedDefaultTld } : {}
2530
2812
  };
2531
2813
  super(wrap, inp, resolvedOptions);
2532
2814
  this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
@@ -2544,6 +2826,7 @@ var InputEmailMask = class extends BaseInputMask {
2544
2826
  if (!this.options.disabled) {
2545
2827
  this.updateSuggestion();
2546
2828
  }
2829
+ this.runAuditWarning(this.options.audit);
2547
2830
  }
2548
2831
  onNativeValueSet(_strVal) {
2549
2832
  if (this.options.disabled) return;
@@ -2639,7 +2922,7 @@ var InputEmailMask = class extends BaseInputMask {
2639
2922
  }
2640
2923
  handleKeyDown(e) {
2641
2924
  if (this.options.disabled) return;
2642
- const hasSuggestion = Boolean(this.currentSuggestion.remaining);
2925
+ const hasSuggestion = Boolean(this.currentSuggestion.remaining) && !this.currentSuggestion.isHintOnly;
2643
2926
  const cursor = this.input.selectionStart ?? 0;
2644
2927
  const isAtEnd = cursor === this.input.value.length;
2645
2928
  const isNotEmpty = this.input.value.length > 0;
@@ -2677,7 +2960,7 @@ var InputEmailMask = class extends BaseInputMask {
2677
2960
  * Valide et applique la suggestion courante dans le champ natif.
2678
2961
  */
2679
2962
  acceptSuggestion() {
2680
- if (!this.currentSuggestion.remaining || this.options.disabled || this.input.value.length === 0) return false;
2963
+ if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.input.value.length === 0) return false;
2681
2964
  const completed = this.currentSuggestion.full;
2682
2965
  this.setNativeValue(completed);
2683
2966
  this.input.setSelectionRange(completed.length, completed.length);
@@ -2698,6 +2981,21 @@ var InputEmailMask = class extends BaseInputMask {
2698
2981
  this.engine.setDefaultDomain(domain);
2699
2982
  this.updateSuggestion();
2700
2983
  }
2984
+ /**
2985
+ * Modifie dynamiquement l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
2986
+ */
2987
+ setDefaultTld(tld) {
2988
+ this.engine.setDefaultTld(tld);
2989
+ this.updateSuggestion();
2990
+ }
2991
+ /**
2992
+ * Modifie dynamiquement la liste des extensions (TLD) connues.
2993
+ */
2994
+ setTlds(tlds) {
2995
+ this.engine.setTlds(tlds);
2996
+ this.currentSuggestionIndex = 0;
2997
+ this.updateSuggestion();
2998
+ }
2701
2999
  handleFocus() {
2702
3000
  this.wrapper.classList.add("is-focused");
2703
3001
  this.syncGhostStyles();
@@ -2718,6 +3016,12 @@ var InputEmailMask = class extends BaseInputMask {
2718
3016
  this.options.cycleSuggestions = this.getAttr("data-mask-cycle-suggestions") === "true";
2719
3017
  } else if (attrName === "data-mask-auto-lowercase") {
2720
3018
  this.options.autoLowercase = this.getAttr("data-mask-auto-lowercase") === "true";
3019
+ } else if (attrName === "data-mask-default-tld") {
3020
+ const val = this.getAttr("data-mask-default-tld");
3021
+ this.setDefaultTld(val === null || val === "false" || val === "none" ? null : val === "true" ? true : val);
3022
+ } else if (attrName === "data-mask-tlds") {
3023
+ const val = this.getAttr("data-mask-tlds");
3024
+ this.setTlds(val ? val.split(",").map((s) => s.trim()).filter(Boolean) : null);
2721
3025
  } else if (attrName === "placeholder") {
2722
3026
  this.updateSuggestion();
2723
3027
  }
@@ -2725,7 +3029,7 @@ var InputEmailMask = class extends BaseInputMask {
2725
3029
  getDetail() {
2726
3030
  return {
2727
3031
  value: this.input.value,
2728
- suggestedValue: this.currentSuggestion.full,
3032
+ suggestedValue: this.currentSuggestion.isHintOnly ? "" : this.currentSuggestion.full,
2729
3033
  domain: this.currentSuggestion.matchedDomain
2730
3034
  };
2731
3035
  }