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.esm.js CHANGED
@@ -1,3 +1,46 @@
1
+ // src/common/AuditableComponent.ts
2
+ var AuditableComponent = class {
3
+ /**
4
+ * Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
5
+ */
6
+ getAuditDisableHint() {
7
+ return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
8
+ }
9
+ /**
10
+ * Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
11
+ * si l'audit est activé et que des contraintes manquent.
12
+ */
13
+ runAuditWarning(enabled = true) {
14
+ if (!enabled) return [];
15
+ const warnings = this.audit();
16
+ if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
17
+ console.warn(
18
+ `[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
19
+ ` + warnings.map((w) => ` - ${w}`).join("\n") + `
20
+ (${this.getAuditDisableHint()})`
21
+ );
22
+ }
23
+ return warnings;
24
+ }
25
+ /**
26
+ * Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
27
+ * pointe vers des éléments réellement présents dans le document.
28
+ */
29
+ checkAriaIdReferences(element, attrName, warnings) {
30
+ const rawValue = element.getAttribute(attrName)?.trim();
31
+ if (!rawValue) return false;
32
+ const doc = element.ownerDocument || document;
33
+ const ids = rawValue.split(/\s+/).filter(Boolean);
34
+ const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
35
+ if (!isValid) {
36
+ warnings.push(
37
+ `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
38
+ );
39
+ }
40
+ return isValid;
41
+ }
42
+ };
43
+
1
44
  // src/mask/BaseInputMask.ts
2
45
  function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
3
46
  const isSecondArgInput = Boolean(
@@ -16,8 +59,9 @@ function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOption
16
59
  options: inputOrOptions && typeof inputOrOptions === "object" && !("tagName" in inputOrOptions) ? inputOrOptions : {}
17
60
  };
18
61
  }
19
- var BaseInputMask = class {
62
+ var BaseInputMask = class extends AuditableComponent {
20
63
  constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
64
+ super();
21
65
  this.ghost = null;
22
66
  this.isWrapperCreated = false;
23
67
  this.isDestroyed = false;
@@ -28,6 +72,7 @@ var BaseInputMask = class {
28
72
  this.onCutHandler = () => {
29
73
  };
30
74
  this.mutationObserver = null;
75
+ this.focusSelectTimerId = null;
31
76
  this.onBaseCopy = (e) => {
32
77
  if (!this.options.copyRaw || this.options.disabled || this.input.type === "password") return;
33
78
  const start = this.input.selectionStart ?? 0;
@@ -46,7 +91,11 @@ var BaseInputMask = class {
46
91
  this.onBaseFocus = () => {
47
92
  this.isFocused = true;
48
93
  if (this.options.selectAllOnFocus && this.input.value.length > 0) {
49
- setTimeout(() => {
94
+ if (this.focusSelectTimerId !== null) {
95
+ clearTimeout(this.focusSelectTimerId);
96
+ }
97
+ this.focusSelectTimerId = window.setTimeout(() => {
98
+ this.focusSelectTimerId = null;
50
99
  if (!this.isDestroyed && document.activeElement === this.input) {
51
100
  this.input.select();
52
101
  }
@@ -65,7 +114,7 @@ var BaseInputMask = class {
65
114
  }
66
115
  };
67
116
  const { wrapper: providedWrapper, input, options } = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions);
68
- if (!input || !(input instanceof HTMLElement) || input.tagName !== "INPUT") {
117
+ if (!input || typeof input !== "object" || input.nodeType !== 1 || input.tagName !== "INPUT") {
69
118
  throw new Error(`[${new.target.name || "InputMask"}] input (HTMLInputElement) est requis.`);
70
119
  }
71
120
  this.input = input;
@@ -100,8 +149,10 @@ var BaseInputMask = class {
100
149
  const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
101
150
  const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
102
151
  const dataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
152
+ const dataAudit = this.getAttr("data-mask-audit");
103
153
  const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
104
154
  const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
155
+ const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
105
156
  const isPassword = this.input.type === "password";
106
157
  this.options = {
107
158
  ...otherOptions,
@@ -111,7 +162,8 @@ var BaseInputMask = class {
111
162
  copyRaw: isPassword ? false : options.copyRaw ?? dataCopyRaw ?? false,
112
163
  disabled: resolvedDisabled,
113
164
  align: optAlign ?? (dataAlign || void 0),
114
- emitNativeInput: options.emitNativeInput ?? true
165
+ emitNativeInput: options.emitNativeInput ?? true,
166
+ audit: resolvedAudit
115
167
  };
116
168
  if (this.options.showMaskOnFocus) {
117
169
  this.wrapper.classList.add("mask-focus-only");
@@ -190,6 +242,8 @@ var BaseInputMask = class {
190
242
  "data-mask-pad-decimals",
191
243
  "data-mask-auto-lowercase",
192
244
  "data-mask-cycle-suggestions",
245
+ "data-mask-default-tld",
246
+ "data-mask-tlds",
193
247
  "data-disabled",
194
248
  "data-mask-align",
195
249
  "data-align",
@@ -454,12 +508,58 @@ var BaseInputMask = class {
454
508
  getRawValue() {
455
509
  return this.input.value;
456
510
  }
511
+ /**
512
+ * Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
513
+ * et retourne la liste des contraintes manquantes.
514
+ */
515
+ audit() {
516
+ const warnings = [];
517
+ const doc = this.input.ownerDocument || document;
518
+ const ariaLabel = this.input.getAttribute("aria-label")?.trim();
519
+ const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
520
+ const hasWrappingLabel = Boolean(this.input.closest("label"));
521
+ const hasNativeLabels = Boolean(this.input.labels && this.input.labels.length > 0);
522
+ let hasExplicitLabelFor = false;
523
+ if (this.input.id && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
524
+ hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${CSS.escape(this.input.id)}"]`));
525
+ } else if (this.input.id) {
526
+ hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${this.input.id}"]`));
527
+ }
528
+ if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
529
+ warnings.push(
530
+ `\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
531
+ );
532
+ }
533
+ this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
534
+ const extraWarnings = this.getSpecificAuditWarnings();
535
+ warnings.push(...extraWarnings);
536
+ return warnings;
537
+ }
538
+ getAuditPrefix() {
539
+ return `Wulf.Mask.${this.constructor.name || "InputMask"}`;
540
+ }
541
+ getAuditTargetLabel() {
542
+ return this.input.id ? `#${this.input.id}` : this.input.name ? `input[name="${this.input.name}"]` : "<input>";
543
+ }
544
+ getAuditDisableHint() {
545
+ return 'Passez { audit: false } ou data-mask-audit="false" pour d\xE9sactiver cet avertissement';
546
+ }
547
+ /**
548
+ * Crochet permettant aux classes filles d'ajouter des vérifications d'audit spécifiques.
549
+ */
550
+ getSpecificAuditWarnings() {
551
+ return [];
552
+ }
457
553
  /**
458
554
  * Supprime les éléments fantômes, restaure les propriétés et nettoie les attributs.
459
555
  */
460
556
  destroy() {
461
557
  if (this.isDestroyed) return;
462
558
  this.isDestroyed = true;
559
+ if (this.focusSelectTimerId !== null) {
560
+ clearTimeout(this.focusSelectTimerId);
561
+ this.focusSelectTimerId = null;
562
+ }
463
563
  if (this.mutationObserver) {
464
564
  this.mutationObserver.disconnect();
465
565
  this.mutationObserver = null;
@@ -1221,6 +1321,9 @@ var InputMask = class extends BaseInputMask {
1221
1321
  this.onChangeNativeHandler = () => {
1222
1322
  };
1223
1323
  this.wasInputModeInferred = false;
1324
+ this.cutTimerId = null;
1325
+ this.pasteTimerId = null;
1326
+ this.resetTimerId = null;
1224
1327
  this.history = new MaskHistory();
1225
1328
  this.engine = new MaskEngine(this.options.mask || "", {
1226
1329
  placeholderChar: this.options.placeholderChar,
@@ -1228,12 +1331,7 @@ var InputMask = class extends BaseInputMask {
1228
1331
  strict: this.options.strict,
1229
1332
  autoLowercase: this.options.autoLowercase
1230
1333
  });
1231
- if (this.options.inferInputMode && !this.input.hasAttribute("inputmode")) {
1232
- if (this.engine.isNumericOnly()) {
1233
- this.input.inputMode = "numeric";
1234
- this.wasInputModeInferred = true;
1235
- }
1236
- }
1334
+ this.syncInferredInputMode();
1237
1335
  this.keyboard = new MaskKeyboard({
1238
1336
  getInput: () => this.input,
1239
1337
  getEngine: () => this.engine,
@@ -1246,6 +1344,19 @@ var InputMask = class extends BaseInputMask {
1246
1344
  this.bindEvents();
1247
1345
  this.lastValue = this.input.value;
1248
1346
  this.syncInitialValue();
1347
+ this.runAuditWarning(this.options.audit);
1348
+ }
1349
+ getSpecificAuditWarnings() {
1350
+ const warnings = [];
1351
+ const hasDescribedby = Boolean(this.input.getAttribute("aria-describedby")?.trim());
1352
+ const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
1353
+ const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
1354
+ if (!hasDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
1355
+ warnings.push(
1356
+ "Indication du format attendu manquante : d\xE9finissez aria-describedby, placeholder ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
1357
+ );
1358
+ }
1359
+ return warnings;
1249
1360
  }
1250
1361
  extractRawSnippet(snippet) {
1251
1362
  return this.engine.extractRaw(snippet);
@@ -1297,7 +1408,9 @@ var InputMask = class extends BaseInputMask {
1297
1408
  this.onScroll = this.onScroll.bind(this);
1298
1409
  this.onBeforeInput = this.onBeforeInput.bind(this);
1299
1410
  this.onCutHandler = () => {
1300
- setTimeout(() => {
1411
+ if (this.cutTimerId !== null) clearTimeout(this.cutTimerId);
1412
+ this.cutTimerId = window.setTimeout(() => {
1413
+ this.cutTimerId = null;
1301
1414
  if (this.isDestroyed) return;
1302
1415
  if (this.options.disabled) {
1303
1416
  this.checkValueChange();
@@ -1329,7 +1442,9 @@ var InputMask = class extends BaseInputMask {
1329
1442
  this.input.addEventListener("change", this.onChangeNativeHandler);
1330
1443
  if (this.input.form) {
1331
1444
  this.onFormResetHandler = () => {
1332
- setTimeout(() => {
1445
+ if (this.resetTimerId !== null) clearTimeout(this.resetTimerId);
1446
+ this.resetTimerId = window.setTimeout(() => {
1447
+ this.resetTimerId = null;
1333
1448
  if (this.isDestroyed) return;
1334
1449
  if (this.options.disabled) {
1335
1450
  this.checkValueChange();
@@ -1341,11 +1456,40 @@ var InputMask = class extends BaseInputMask {
1341
1456
  this.input.form.addEventListener("reset", this.onFormResetHandler);
1342
1457
  }
1343
1458
  }
1459
+ /**
1460
+ * Synchronise dynamiquement l'attribut inputmode="numeric" selon le motif actif
1461
+ * sans jamais écraser un inputmode défini explicitement par l'hôte.
1462
+ */
1463
+ syncInferredInputMode() {
1464
+ if (!this.options.inferInputMode) return;
1465
+ const isNum = !this.options.disabled && this.engine.isNumericOnly();
1466
+ if (isNum) {
1467
+ if (!this.input.hasAttribute("inputmode")) {
1468
+ this.input.inputMode = "numeric";
1469
+ this.wasInputModeInferred = true;
1470
+ }
1471
+ } else if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "numeric") {
1472
+ this.input.removeAttribute("inputmode");
1473
+ this.wasInputModeInferred = false;
1474
+ }
1475
+ }
1344
1476
  /**
1345
1477
  * Supprime tous les écouteurs et nettoie les attributs associés.
1346
1478
  */
1347
1479
  destroy() {
1348
1480
  if (this.isDestroyed) return;
1481
+ if (this.cutTimerId !== null) {
1482
+ clearTimeout(this.cutTimerId);
1483
+ this.cutTimerId = null;
1484
+ }
1485
+ if (this.pasteTimerId !== null) {
1486
+ clearTimeout(this.pasteTimerId);
1487
+ this.pasteTimerId = null;
1488
+ }
1489
+ if (this.resetTimerId !== null) {
1490
+ clearTimeout(this.resetTimerId);
1491
+ this.resetTimerId = null;
1492
+ }
1349
1493
  this.input.removeEventListener("beforeinput", this.onBeforeInput);
1350
1494
  this.input.removeEventListener("input", this.handleInput);
1351
1495
  this.input.removeEventListener("keydown", this.onKeyDown);
@@ -1407,6 +1551,7 @@ var InputMask = class extends BaseInputMask {
1407
1551
  this.history.clear();
1408
1552
  }
1409
1553
  this.setDisabled(true);
1554
+ this.syncInferredInputMode();
1410
1555
  return;
1411
1556
  }
1412
1557
  this.options.mask = newPattern;
@@ -1417,6 +1562,7 @@ var InputMask = class extends BaseInputMask {
1417
1562
  this.history.clear();
1418
1563
  }
1419
1564
  this.setDisabled(false);
1565
+ this.syncInferredInputMode();
1420
1566
  }
1421
1567
  handleAttributeMutation(attrName) {
1422
1568
  super.handleAttributeMutation(attrName);
@@ -1574,7 +1720,9 @@ var InputMask = class extends BaseInputMask {
1574
1720
  }
1575
1721
  onPaste(e) {
1576
1722
  if (this.options.disabled) {
1577
- setTimeout(() => {
1723
+ if (this.pasteTimerId !== null) clearTimeout(this.pasteTimerId);
1724
+ this.pasteTimerId = window.setTimeout(() => {
1725
+ this.pasteTimerId = null;
1578
1726
  if (!this.isDestroyed) this.checkValueChange();
1579
1727
  }, 0);
1580
1728
  return;
@@ -2058,6 +2206,7 @@ var InputAmountMask = class extends BaseInputMask {
2058
2206
  isValid: true
2059
2207
  });
2060
2208
  }
2209
+ this.runAuditWarning(this.options.audit);
2061
2210
  }
2062
2211
  extractRawSnippet(snippet) {
2063
2212
  const p = this.engine.parse(snippet);
@@ -2383,9 +2532,12 @@ var InputAmountMask = class extends BaseInputMask {
2383
2532
  var _EmailEngine = class _EmailEngine {
2384
2533
  constructor(options = {}) {
2385
2534
  this.defaultDomain = null;
2535
+ this.defaultTld = "__";
2386
2536
  this.domains = options.domains && options.domains.length > 0 ? options.domains : _EmailEngine.DEFAULT_DOMAINS;
2537
+ this.tlds = options.tlds && options.tlds.length > 0 ? options.tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2387
2538
  this.suggestOnAt = options.suggestOnAt ?? true;
2388
2539
  this.setDefaultDomain(options.defaultDomain ?? null);
2540
+ this.setDefaultTld(options.defaultTld !== void 0 ? options.defaultTld : "__");
2389
2541
  }
2390
2542
  /**
2391
2543
  * Définit ou modifie le domaine suggéré par défaut.
@@ -2399,6 +2551,35 @@ var _EmailEngine = class _EmailEngine {
2399
2551
  this.defaultDomain = null;
2400
2552
  }
2401
2553
  }
2554
+ /**
2555
+ * Définit ou modifie l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
2556
+ */
2557
+ setDefaultTld(tld) {
2558
+ if (tld === true) {
2559
+ this.defaultTld = this.tlds.length > 0 ? this.tlds[0] : null;
2560
+ } else if (typeof tld === "string" && tld.trim().length > 0) {
2561
+ this.defaultTld = tld.trim().replace(/^\./, "");
2562
+ } else {
2563
+ this.defaultTld = null;
2564
+ }
2565
+ }
2566
+ /**
2567
+ * Définit ou modifie la liste des extensions (TLD) proposées par ordre de priorité.
2568
+ */
2569
+ setTlds(tlds) {
2570
+ this.tlds = tlds && tlds.length > 0 ? tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2571
+ }
2572
+ /**
2573
+ * Retourne l'ensemble des extensions (TLD) correspondant au fragment saisi après le dernier point,
2574
+ * dans l'ordre exact fourni par l'utilisateur.
2575
+ */
2576
+ getMatchingTlds(tldInput) {
2577
+ const query = (tldInput ?? "").toLowerCase();
2578
+ if (query.length === 0) {
2579
+ return [...this.tlds];
2580
+ }
2581
+ return this.tlds.filter((t) => t.toLowerCase().startsWith(query) && t.toLowerCase() !== query);
2582
+ }
2402
2583
  /**
2403
2584
  * Retourne l'ensemble des domaines correspondant à la saisie courante.
2404
2585
  */
@@ -2419,10 +2600,10 @@ var _EmailEngine = class _EmailEngine {
2419
2600
  return this.domains.filter((d) => d.toLowerCase().startsWith(query) && d.toLowerCase() !== query);
2420
2601
  }
2421
2602
  /**
2422
- * Analyse la saisie courante et calcule la suggestion de domaine adaptée.
2603
+ * Analyse la saisie courante et calcule la suggestion de domaine ou d'extension (TLD) adaptée.
2423
2604
  *
2424
2605
  * @param input Saisie utilisateur
2425
- * @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines correspondent (permet le cyclage)
2606
+ * @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines/TLD correspondent (permet le cyclage)
2426
2607
  */
2427
2608
  getSuggestion(input, matchIndex = 0) {
2428
2609
  const val = input ?? "";
@@ -2431,30 +2612,104 @@ var _EmailEngine = class _EmailEngine {
2431
2612
  return {
2432
2613
  full: val ? `${val}@${this.defaultDomain}` : `@${this.defaultDomain}`,
2433
2614
  remaining: `@${this.defaultDomain}`,
2434
- matchedDomain: this.defaultDomain
2615
+ matchedDomain: this.defaultDomain,
2616
+ isHintOnly: false
2435
2617
  };
2436
2618
  }
2437
- return { full: val, remaining: "", matchedDomain: null };
2619
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2438
2620
  }
2439
2621
  const atIndex = val.indexOf("@");
2440
2622
  const localPart = val.substring(0, atIndex);
2441
2623
  const domainPart = val.substring(atIndex + 1);
2442
2624
  if (val.indexOf("@", atIndex + 1) !== -1) {
2443
- return { full: val, remaining: "", matchedDomain: null };
2625
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2444
2626
  }
2445
2627
  const matches = this.getMatchingDomains(input);
2446
- if (matches.length === 0) {
2447
- return { full: input, remaining: "", matchedDomain: null };
2628
+ if (matches.length > 0) {
2629
+ const safeIndex = (matchIndex % matches.length + matches.length) % matches.length;
2630
+ const matched = matches[safeIndex];
2631
+ const query = domainPart.toLowerCase();
2632
+ const remaining = matched.substring(query.length);
2633
+ return {
2634
+ full: `${localPart}@${matched}`,
2635
+ remaining,
2636
+ matchedDomain: matched,
2637
+ isHintOnly: false
2638
+ };
2448
2639
  }
2449
- const safeIndex = (matchIndex % matches.length + matches.length) % matches.length;
2450
- const matched = matches[safeIndex];
2451
- const query = domainPart.toLowerCase();
2452
- const remaining = matched.substring(query.length);
2453
- return {
2454
- full: `${localPart}@${matched}`,
2455
- remaining,
2456
- matchedDomain: matched
2457
- };
2640
+ if (domainPart.length === 0 || domainPart.startsWith(".")) {
2641
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2642
+ }
2643
+ const lowerDomain = domainPart.toLowerCase();
2644
+ if (this.domains.some((d) => d.toLowerCase() === lowerDomain)) {
2645
+ return { full: input, remaining: "", matchedDomain: domainPart, isHintOnly: false };
2646
+ }
2647
+ const lastDotIndex = domainPart.lastIndexOf(".");
2648
+ if (lastDotIndex === -1) {
2649
+ if (!this.defaultTld) {
2650
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2651
+ }
2652
+ const isHint = this.defaultTld.includes("_");
2653
+ const remaining = `.${this.defaultTld}`;
2654
+ const fullDomain = `${domainPart}.${this.defaultTld}`;
2655
+ return {
2656
+ full: isHint ? input : `${localPart}@${fullDomain}`,
2657
+ remaining,
2658
+ matchedDomain: isHint ? null : fullDomain,
2659
+ isHintOnly: isHint
2660
+ };
2661
+ }
2662
+ const hostPart = domainPart.substring(0, lastDotIndex);
2663
+ const tldPart = domainPart.substring(lastDotIndex + 1);
2664
+ if (!hostPart || hostPart.endsWith(".")) {
2665
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2666
+ }
2667
+ if (tldPart.length === 0) {
2668
+ if (this.defaultTld && !this.defaultTld.includes("_")) {
2669
+ const fullDomain = `${hostPart}.${this.defaultTld}`;
2670
+ return {
2671
+ full: `${localPart}@${fullDomain}`,
2672
+ remaining: this.defaultTld,
2673
+ matchedDomain: fullDomain,
2674
+ isHintOnly: false
2675
+ };
2676
+ }
2677
+ if (this.defaultTld && this.defaultTld.includes("_")) {
2678
+ return {
2679
+ full: input,
2680
+ remaining: this.defaultTld,
2681
+ matchedDomain: null,
2682
+ isHintOnly: true
2683
+ };
2684
+ }
2685
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2686
+ }
2687
+ const lowerTld = tldPart.toLowerCase();
2688
+ const matchingTlds = this.getMatchingTlds(tldPart);
2689
+ if (matchingTlds.length > 0) {
2690
+ const safeTldIndex = (matchIndex % matchingTlds.length + matchingTlds.length) % matchingTlds.length;
2691
+ const matchedTld = matchingTlds[safeTldIndex];
2692
+ const remaining = matchedTld.substring(lowerTld.length);
2693
+ const fullDomain = `${hostPart}.${matchedTld}`;
2694
+ return {
2695
+ full: `${localPart}@${fullDomain}`,
2696
+ remaining,
2697
+ matchedDomain: fullDomain,
2698
+ isHintOnly: false
2699
+ };
2700
+ }
2701
+ if (this.defaultTld && this.defaultTld.includes("_") && tldPart.length < this.defaultTld.length) {
2702
+ const remaining = this.defaultTld.substring(tldPart.length);
2703
+ if (remaining.includes("_")) {
2704
+ return {
2705
+ full: input,
2706
+ remaining,
2707
+ matchedDomain: null,
2708
+ isHintOnly: true
2709
+ };
2710
+ }
2711
+ }
2712
+ return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2458
2713
  }
2459
2714
  };
2460
2715
  _EmailEngine.DEFAULT_DOMAINS = [
@@ -2469,6 +2724,27 @@ _EmailEngine.DEFAULT_DOMAINS = [
2469
2724
  "laposte.net",
2470
2725
  "proton.me"
2471
2726
  ];
2727
+ _EmailEngine.DEFAULT_TLDS = [
2728
+ "com",
2729
+ "fr",
2730
+ "net",
2731
+ "org",
2732
+ "eu",
2733
+ "io",
2734
+ "co",
2735
+ "info",
2736
+ "biz",
2737
+ "me",
2738
+ "tv",
2739
+ "fi",
2740
+ "be",
2741
+ "ch",
2742
+ "ca",
2743
+ "uk",
2744
+ "de",
2745
+ "es",
2746
+ "it"
2747
+ ];
2472
2748
  var EmailEngine = _EmailEngine;
2473
2749
 
2474
2750
  // src/mask/InputEmailMask.ts
@@ -2482,6 +2758,10 @@ var InputEmailMask = class extends BaseInputMask {
2482
2758
  const dataAutoLower = wrap?.getAttribute("data-mask-auto-lowercase") === "true" || inp?.getAttribute("data-mask-auto-lowercase") === "true";
2483
2759
  const dataAriaAuto = wrap?.getAttribute("data-mask-aria-autocomplete") ?? inp?.getAttribute("data-mask-aria-autocomplete");
2484
2760
  const setAriaAutocomplete = opts.setAriaAutocomplete ?? (dataAriaAuto !== null ? dataAriaAuto !== "false" : true);
2761
+ const dataTlds = wrap?.getAttribute("data-mask-tlds") ?? inp?.getAttribute("data-mask-tlds");
2762
+ const parsedTlds = opts.tlds ?? (dataTlds ? dataTlds.split(",").map((s) => s.trim()).filter(Boolean) : void 0);
2763
+ const dataDefaultTld = wrap?.getAttribute("data-mask-default-tld") ?? inp?.getAttribute("data-mask-default-tld");
2764
+ const resolvedDefaultTld = opts.defaultTld !== void 0 ? opts.defaultTld : dataDefaultTld !== null ? dataDefaultTld === "false" || dataDefaultTld === "none" ? null : dataDefaultTld === "true" ? true : dataDefaultTld : void 0;
2485
2765
  const resolvedOptions = {
2486
2766
  completeOnTab: true,
2487
2767
  completeOnArrowRight: true,
@@ -2489,7 +2769,9 @@ var InputEmailMask = class extends BaseInputMask {
2489
2769
  cycleSuggestions: opts.cycleSuggestions ?? dataCycle ?? false,
2490
2770
  autoLowercase: opts.autoLowercase ?? dataAutoLower ?? false,
2491
2771
  setAriaAutocomplete,
2492
- ...opts
2772
+ ...opts,
2773
+ ...parsedTlds !== void 0 ? { tlds: parsedTlds } : {},
2774
+ ...resolvedDefaultTld !== void 0 ? { defaultTld: resolvedDefaultTld } : {}
2493
2775
  };
2494
2776
  super(wrap, inp, resolvedOptions);
2495
2777
  this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
@@ -2507,6 +2789,7 @@ var InputEmailMask = class extends BaseInputMask {
2507
2789
  if (!this.options.disabled) {
2508
2790
  this.updateSuggestion();
2509
2791
  }
2792
+ this.runAuditWarning(this.options.audit);
2510
2793
  }
2511
2794
  onNativeValueSet(_strVal) {
2512
2795
  if (this.options.disabled) return;
@@ -2602,7 +2885,7 @@ var InputEmailMask = class extends BaseInputMask {
2602
2885
  }
2603
2886
  handleKeyDown(e) {
2604
2887
  if (this.options.disabled) return;
2605
- const hasSuggestion = Boolean(this.currentSuggestion.remaining);
2888
+ const hasSuggestion = Boolean(this.currentSuggestion.remaining) && !this.currentSuggestion.isHintOnly;
2606
2889
  const cursor = this.input.selectionStart ?? 0;
2607
2890
  const isAtEnd = cursor === this.input.value.length;
2608
2891
  const isNotEmpty = this.input.value.length > 0;
@@ -2640,7 +2923,7 @@ var InputEmailMask = class extends BaseInputMask {
2640
2923
  * Valide et applique la suggestion courante dans le champ natif.
2641
2924
  */
2642
2925
  acceptSuggestion() {
2643
- if (!this.currentSuggestion.remaining || this.options.disabled || this.input.value.length === 0) return false;
2926
+ if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.input.value.length === 0) return false;
2644
2927
  const completed = this.currentSuggestion.full;
2645
2928
  this.setNativeValue(completed);
2646
2929
  this.input.setSelectionRange(completed.length, completed.length);
@@ -2661,6 +2944,21 @@ var InputEmailMask = class extends BaseInputMask {
2661
2944
  this.engine.setDefaultDomain(domain);
2662
2945
  this.updateSuggestion();
2663
2946
  }
2947
+ /**
2948
+ * Modifie dynamiquement l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
2949
+ */
2950
+ setDefaultTld(tld) {
2951
+ this.engine.setDefaultTld(tld);
2952
+ this.updateSuggestion();
2953
+ }
2954
+ /**
2955
+ * Modifie dynamiquement la liste des extensions (TLD) connues.
2956
+ */
2957
+ setTlds(tlds) {
2958
+ this.engine.setTlds(tlds);
2959
+ this.currentSuggestionIndex = 0;
2960
+ this.updateSuggestion();
2961
+ }
2664
2962
  handleFocus() {
2665
2963
  this.wrapper.classList.add("is-focused");
2666
2964
  this.syncGhostStyles();
@@ -2681,6 +2979,12 @@ var InputEmailMask = class extends BaseInputMask {
2681
2979
  this.options.cycleSuggestions = this.getAttr("data-mask-cycle-suggestions") === "true";
2682
2980
  } else if (attrName === "data-mask-auto-lowercase") {
2683
2981
  this.options.autoLowercase = this.getAttr("data-mask-auto-lowercase") === "true";
2982
+ } else if (attrName === "data-mask-default-tld") {
2983
+ const val = this.getAttr("data-mask-default-tld");
2984
+ this.setDefaultTld(val === null || val === "false" || val === "none" ? null : val === "true" ? true : val);
2985
+ } else if (attrName === "data-mask-tlds") {
2986
+ const val = this.getAttr("data-mask-tlds");
2987
+ this.setTlds(val ? val.split(",").map((s) => s.trim()).filter(Boolean) : null);
2684
2988
  } else if (attrName === "placeholder") {
2685
2989
  this.updateSuggestion();
2686
2990
  }
@@ -2688,7 +2992,7 @@ var InputEmailMask = class extends BaseInputMask {
2688
2992
  getDetail() {
2689
2993
  return {
2690
2994
  value: this.input.value,
2691
- suggestedValue: this.currentSuggestion.full,
2995
+ suggestedValue: this.currentSuggestion.isHintOnly ? "" : this.currentSuggestion.full,
2692
2996
  domain: this.currentSuggestion.matchedDomain
2693
2997
  };
2694
2998
  }