wulf.js 1.9.3 → 2.0.0

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 (79) hide show
  1. package/README.md +118 -78
  2. package/changelog.md +60 -0
  3. package/dist/focus-trap.esm.js +202 -136
  4. package/dist/focus-trap.esm.js.map +3 -3
  5. package/dist/focus-trap.global.js +203 -137
  6. package/dist/focus-trap.global.js.map +3 -3
  7. package/dist/focus-trap.global.min.js +4 -4
  8. package/dist/focus-trap.global.min.js.map +4 -4
  9. package/dist/index.esm.js +2130 -858
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +2124 -852
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +4 -4
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.css +1 -1
  16. package/dist/mask.css.map +2 -2
  17. package/dist/mask.esm.js +686 -330
  18. package/dist/mask.esm.js.map +3 -3
  19. package/dist/mask.global.js +687 -331
  20. package/dist/mask.global.js.map +3 -3
  21. package/dist/mask.global.min.js +4 -4
  22. package/dist/mask.global.min.js.map +4 -4
  23. package/dist/mask.layered.css +1 -0
  24. package/dist/mask.layered.css.map +7 -0
  25. package/dist/masonry.css +1 -1
  26. package/dist/masonry.css.map +2 -2
  27. package/dist/masonry.esm.js +248 -77
  28. package/dist/masonry.esm.js.map +3 -3
  29. package/dist/masonry.global.js +249 -78
  30. package/dist/masonry.global.js.map +3 -3
  31. package/dist/masonry.global.min.js +4 -4
  32. package/dist/masonry.global.min.js.map +4 -4
  33. package/dist/masonry.layered.css +1 -0
  34. package/dist/masonry.layered.css.map +7 -0
  35. package/dist/scroll.css +1 -1
  36. package/dist/scroll.css.map +2 -2
  37. package/dist/scroll.esm.js +462 -129
  38. package/dist/scroll.esm.js.map +3 -3
  39. package/dist/scroll.global.js +463 -130
  40. package/dist/scroll.global.js.map +3 -3
  41. package/dist/scroll.global.min.js +4 -4
  42. package/dist/scroll.global.min.js.map +4 -4
  43. package/dist/scroll.layered.css +1 -0
  44. package/dist/scroll.layered.css.map +7 -0
  45. package/dist/shortcut.esm.js +164 -48
  46. package/dist/shortcut.esm.js.map +3 -3
  47. package/dist/shortcut.global.js +165 -49
  48. package/dist/shortcut.global.js.map +3 -3
  49. package/dist/shortcut.global.min.js +2 -2
  50. package/dist/shortcut.global.min.js.map +4 -4
  51. package/dist/toast.css +1 -1
  52. package/dist/toast.css.map +2 -2
  53. package/dist/toast.esm.js +489 -124
  54. package/dist/toast.esm.js.map +3 -3
  55. package/dist/toast.global.js +490 -125
  56. package/dist/toast.global.js.map +3 -3
  57. package/dist/toast.global.min.js +3 -3
  58. package/dist/toast.global.min.js.map +4 -4
  59. package/dist/toast.layered.css +1 -0
  60. package/dist/toast.layered.css.map +7 -0
  61. package/dist/types/common/dom.d.ts +38 -0
  62. package/dist/types/focus-trap/FocusTrap.d.ts +14 -6
  63. package/dist/types/focus-trap/types.d.ts +2 -2
  64. package/dist/types/index.d.ts +10 -0
  65. package/dist/types/mask/BaseInputMask.d.ts +20 -0
  66. package/dist/types/mask/InputAmountMask.d.ts +2 -0
  67. package/dist/types/mask/InputEmailMask.d.ts +16 -1
  68. package/dist/types/mask/MaskEngine.d.ts +4 -0
  69. package/dist/types/masonry/Masonry.d.ts +10 -3
  70. package/dist/types/scroll/ScrollBlock.d.ts +31 -3
  71. package/dist/types/scroll/types.d.ts +13 -1
  72. package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
  73. package/dist/types/shortcut/ShortcutManager.d.ts +1 -0
  74. package/dist/types/toast/Toast.d.ts +4 -0
  75. package/dist/types/toast/ToastInstance.d.ts +22 -10
  76. package/dist/types/toast/ToastManager.d.ts +37 -4
  77. package/dist/types/toast/i18n/types.d.ts +2 -0
  78. package/dist/types/toast/types.d.ts +9 -2
  79. package/package.json +16 -3
@@ -35,6 +35,41 @@ var __WulfIIFE = (() => {
35
35
  resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
36
36
  });
37
37
 
38
+ // src/common/dom.ts
39
+ function getSafeWulfNamespace() {
40
+ if (typeof window === "undefined") return null;
41
+ const win = window;
42
+ const existing = win.Wulf;
43
+ if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
44
+ const fresh = {};
45
+ win.Wulf = fresh;
46
+ return fresh;
47
+ }
48
+ return existing;
49
+ }
50
+ function safeCssEscape(value) {
51
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
52
+ return CSS.escape(value);
53
+ }
54
+ return String(value).replace(/["\\\u0000-\u001F\u007F]/g, "\\$&");
55
+ }
56
+ function safeMove(parent, node, referenceNode = null) {
57
+ const moveBefore = parent.moveBefore;
58
+ if (typeof moveBefore === "function" && node.isConnected && parent.isConnected && typeof parent.getRootNode === "function" && typeof node.getRootNode === "function" && parent.getRootNode() === node.getRootNode()) {
59
+ try {
60
+ moveBefore.call(parent, node, referenceNode);
61
+ return;
62
+ } catch {
63
+ }
64
+ }
65
+ parent.insertBefore(node, referenceNode);
66
+ }
67
+ function isImeComposing(event) {
68
+ return Boolean(
69
+ event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
70
+ );
71
+ }
72
+
38
73
  // src/common/AuditableComponent.ts
39
74
  var AuditableComponent = class {
40
75
  /**
@@ -67,8 +102,11 @@ var __WulfIIFE = (() => {
67
102
  const rawValue = element.getAttribute(attrName)?.trim();
68
103
  if (!rawValue) return false;
69
104
  const doc = element.ownerDocument || document;
105
+ const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
70
106
  const ids = rawValue.split(/\s+/).filter(Boolean);
71
- const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
107
+ const isValid = ids.length > 0 && ids.every(
108
+ (id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
109
+ );
72
110
  if (!isValid) {
73
111
  warnings.push(
74
112
  `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
@@ -79,6 +117,7 @@ var __WulfIIFE = (() => {
79
117
  };
80
118
 
81
119
  // src/mask/BaseInputMask.ts
120
+ var VALID_ALIGNS = /* @__PURE__ */ new Set(["left", "right", "center"]);
82
121
  function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
83
122
  const isSecondArgInput = Boolean(
84
123
  inputOrOptions && typeof inputOrOptions === "object" && "tagName" in inputOrOptions && inputOrOptions.tagName === "INPUT"
@@ -97,59 +136,27 @@ var __WulfIIFE = (() => {
97
136
  };
98
137
  }
99
138
  var BaseInputMask = class extends AuditableComponent {
139
+ wrapper;
140
+ input;
141
+ options;
142
+ ghost = null;
143
+ isWrapperCreated = false;
144
+ wasWrapperFallbackStyled = false;
145
+ wasAlignSet = false;
146
+ hadInitialDataAlign = false;
147
+ isDestroyed = false;
148
+ isFocused = false;
149
+ isDispatchingNativeInput = false;
150
+ lastTrackedValue = "";
151
+ nativeValueDescriptor = null;
152
+ onCutHandler = () => {
153
+ };
154
+ onFormResetHandler;
155
+ mutationObserver = null;
156
+ focusSelectTimerId = null;
157
+ abortController = new AbortController();
100
158
  constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
101
159
  super();
102
- this.ghost = null;
103
- this.isWrapperCreated = false;
104
- this.isDestroyed = false;
105
- this.isFocused = false;
106
- this.isDispatchingNativeInput = false;
107
- this.lastTrackedValue = "";
108
- this.nativeValueDescriptor = null;
109
- this.onCutHandler = () => {
110
- };
111
- this.mutationObserver = null;
112
- this.focusSelectTimerId = null;
113
- this.onBaseCopy = (e) => {
114
- if (!this.options.copyRaw || this.options.disabled || this.input.type === "password") return;
115
- const start = this.input.selectionStart ?? 0;
116
- const end = this.input.selectionEnd ?? start;
117
- let textToCopy = "";
118
- if (start !== end) {
119
- textToCopy = this.extractRawSnippet(this.input.value.slice(start, end));
120
- } else {
121
- textToCopy = this.getRawValue();
122
- }
123
- if (textToCopy && e.clipboardData) {
124
- e.preventDefault();
125
- e.clipboardData.setData("text/plain", textToCopy);
126
- }
127
- };
128
- this.onBaseFocus = () => {
129
- this.isFocused = true;
130
- if (this.options.selectAllOnFocus && this.input.value.length > 0) {
131
- if (this.focusSelectTimerId !== null) {
132
- clearTimeout(this.focusSelectTimerId);
133
- }
134
- this.focusSelectTimerId = window.setTimeout(() => {
135
- this.focusSelectTimerId = null;
136
- if (!this.isDestroyed && document.activeElement === this.input) {
137
- this.input.select();
138
- }
139
- }, 0);
140
- }
141
- };
142
- this.onBaseBlur = () => {
143
- this.isFocused = false;
144
- };
145
- /**
146
- * Synchronise le défilement horizontal du ghost avec celui du champ d'entrée natif.
147
- */
148
- this.onScroll = () => {
149
- if (this.ghost) {
150
- this.ghost.scrollLeft = this.input.scrollLeft;
151
- }
152
- };
153
160
  const { wrapper: providedWrapper, input, options } = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions);
154
161
  if (!input || typeof input !== "object" || input.nodeType !== 1 || input.tagName !== "INPUT") {
155
162
  throw new Error(`[${new.target.name || "InputMask"}] input (HTMLInputElement) est requis.`);
@@ -159,20 +166,26 @@ var __WulfIIFE = (() => {
159
166
  const shouldCreateWrapper = Boolean(options.createWrapper ?? dataCreateWrapper);
160
167
  let effectiveWrapper = providedWrapper;
161
168
  if (!effectiveWrapper && shouldCreateWrapper) {
162
- const span = document.createElement("span");
169
+ const doc = this.input.ownerDocument || document;
170
+ const span = doc.createElement("span");
163
171
  span.className = "wulf-mask-wrapper";
164
- span.style.display = "inline-grid";
165
- span.style.gridTemplateColumns = "1fr";
166
- span.style.gridTemplateRows = "1fr";
167
- span.style.verticalAlign = "middle";
168
- span.style.boxSizing = "border-box";
169
- span.style.position = "relative";
170
172
  if (this.input.parentNode) {
171
173
  this.input.parentNode.insertBefore(span, this.input);
172
174
  }
173
- span.appendChild(this.input);
174
- this.input.style.gridArea = "1 / 1 / 2 / 2";
175
- this.input.style.boxSizing = "border-box";
175
+ safeMove(span, this.input, null);
176
+ const view = doc.defaultView || (typeof window !== "undefined" ? window : null);
177
+ const needsFallbackStyles = !span.isConnected || !view || view.getComputedStyle(span).display !== "inline-grid";
178
+ if (needsFallbackStyles) {
179
+ span.style.display = "inline-grid";
180
+ span.style.gridTemplateColumns = "1fr";
181
+ span.style.gridTemplateRows = "1fr";
182
+ span.style.verticalAlign = "middle";
183
+ span.style.boxSizing = "border-box";
184
+ span.style.position = "relative";
185
+ this.input.style.gridArea = "1 / 1 / 2 / 2";
186
+ this.input.style.boxSizing = "border-box";
187
+ this.wasWrapperFallbackStyled = true;
188
+ }
176
189
  effectiveWrapper = span;
177
190
  this.isWrapperCreated = true;
178
191
  }
@@ -185,12 +198,15 @@ var __WulfIIFE = (() => {
185
198
  const dataDisabled = this.hasAttr("data-disabled");
186
199
  const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
187
200
  const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
188
- const dataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
201
+ const rawDataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
202
+ const dataAlign = rawDataAlign && VALID_ALIGNS.has(rawDataAlign) ? rawDataAlign : null;
203
+ this.hadInitialDataAlign = this.wrapper.hasAttribute("data-align");
189
204
  const dataAudit = this.getAttr("data-mask-audit");
190
205
  const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
206
+ const validOptAlign = optAlign && VALID_ALIGNS.has(optAlign) ? optAlign : void 0;
191
207
  const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
192
208
  const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
193
- const isPassword = this.input.type === "password";
209
+ const isPassword = this.isPasswordInput();
194
210
  this.options = {
195
211
  ...otherOptions,
196
212
  createWrapper: shouldCreateWrapper,
@@ -198,7 +214,7 @@ var __WulfIIFE = (() => {
198
214
  selectAllOnFocus: options.selectAllOnFocus ?? dataSelectAll ?? false,
199
215
  copyRaw: isPassword ? false : options.copyRaw ?? dataCopyRaw ?? false,
200
216
  disabled: resolvedDisabled,
201
- align: optAlign ?? (dataAlign || void 0),
217
+ align: validOptAlign ?? (dataAlign || void 0),
202
218
  emitNativeInput: options.emitNativeInput ?? true,
203
219
  audit: resolvedAudit
204
220
  };
@@ -245,16 +261,54 @@ var __WulfIIFE = (() => {
245
261
  * Attache les écouteurs de base pour focus/blur, copie brute et sélection.
246
262
  */
247
263
  bindBaseEvents() {
248
- this.input.addEventListener("copy", this.onBaseCopy);
249
- this.input.addEventListener("focus", this.onBaseFocus);
250
- this.input.addEventListener("blur", this.onBaseBlur);
264
+ const { signal } = this.abortController;
265
+ this.input.addEventListener("copy", this.onBaseCopy, { signal });
266
+ this.input.addEventListener("focus", this.onBaseFocus, { signal });
267
+ this.input.addEventListener("blur", this.onBaseBlur, { signal });
251
268
  }
269
+ onBaseCopy = (e) => {
270
+ if (!this.options.copyRaw || this.options.disabled || this.input.type === "password") return;
271
+ const start = this.input.selectionStart ?? 0;
272
+ const end = this.input.selectionEnd ?? start;
273
+ let textToCopy = "";
274
+ if (start !== end) {
275
+ textToCopy = this.extractRawSnippet(this.input.value.slice(start, end));
276
+ } else {
277
+ textToCopy = this.getRawValue();
278
+ }
279
+ if (textToCopy && e.clipboardData) {
280
+ e.preventDefault();
281
+ e.clipboardData.setData("text/plain", textToCopy);
282
+ }
283
+ };
252
284
  /**
253
285
  * Extrait la valeur brute d'un extrait de chaîne sélectionné.
254
286
  */
255
287
  extractRawSnippet(snippet) {
256
288
  return snippet;
257
289
  }
290
+ onBaseFocus = () => {
291
+ this.isFocused = true;
292
+ if (this.options.selectAllOnFocus && this.input.value.length > 0) {
293
+ if (this.focusSelectTimerId !== null) {
294
+ clearTimeout(this.focusSelectTimerId);
295
+ }
296
+ this.focusSelectTimerId = window.setTimeout(() => {
297
+ this.focusSelectTimerId = null;
298
+ if (!this.isDestroyed && document.activeElement === this.input) {
299
+ this.input.select();
300
+ }
301
+ }, 0);
302
+ }
303
+ };
304
+ onBaseBlur = () => {
305
+ this.isFocused = false;
306
+ if (this.isPasswordInput()) {
307
+ this.lastTrackedValue = "";
308
+ this.clearGhost();
309
+ this.wrapper.removeAttribute("data-mask");
310
+ }
311
+ };
258
312
  /**
259
313
  * Initialise l'observation des modifications dynamiques des attributs data-* et placeholder.
260
314
  */
@@ -293,21 +347,41 @@ var __WulfIIFE = (() => {
293
347
  this.mutationObserver.observe(this.input, config);
294
348
  }
295
349
  }
350
+ /**
351
+ * Indique si le champ natif sous-jacent est de type mot de passe.
352
+ */
353
+ isPasswordInput() {
354
+ return (this.input.type || "").toLowerCase() === "password";
355
+ }
356
+ /**
357
+ * Calcule une empreinte non réversible pour détecter les changements sans conserver de secret en RAM.
358
+ */
359
+ computePasswordDigest(val) {
360
+ let hash = 2166136261;
361
+ for (let i = 0; i < val.length; i++) {
362
+ hash ^= val.charCodeAt(i);
363
+ hash = Math.imul(hash, 16777619);
364
+ }
365
+ return `__pwd:${(hash >>> 0).toString(36)}:${val.length}`;
366
+ }
296
367
  /**
297
368
  * Modifie dynamiquement l'alignement du champ et du masque fantôme.
298
369
  */
299
370
  setAlign(align) {
300
- const targetAlign = align || void 0;
371
+ const normalized = align && VALID_ALIGNS.has(align) ? align : null;
372
+ const targetAlign = normalized || void 0;
301
373
  const currentAttr = this.wrapper.getAttribute("data-align");
302
- if (this.options.align === targetAlign && currentAttr === (align || null)) {
374
+ const hasExpectedClass = normalized ? this.wrapper.classList.contains(`align-${normalized}`) : !this.wrapper.classList.contains("align-left") && !this.wrapper.classList.contains("align-right") && !this.wrapper.classList.contains("align-center");
375
+ if (this.options.align === targetAlign && currentAttr === normalized && hasExpectedClass) {
303
376
  return;
304
377
  }
305
378
  this.options.align = targetAlign;
306
379
  this.wrapper.classList.remove("align-left", "align-right", "align-center");
307
- if (align) {
308
- this.wrapper.classList.add(`align-${align}`);
309
- if (this.wrapper.getAttribute("data-align") !== align) {
310
- this.wrapper.setAttribute("data-align", align);
380
+ if (normalized) {
381
+ this.wrapper.classList.add(`align-${normalized}`);
382
+ this.wasAlignSet = true;
383
+ if (this.wrapper.getAttribute("data-align") !== normalized) {
384
+ this.wrapper.setAttribute("data-align", normalized);
311
385
  }
312
386
  } else {
313
387
  if (this.wrapper.hasAttribute("data-align")) {
@@ -333,14 +407,18 @@ var __WulfIIFE = (() => {
333
407
  } else if (attrName === "data-mask-select-on-focus") {
334
408
  this.options.selectAllOnFocus = this.getAttr("data-mask-select-on-focus") === "true";
335
409
  } else if (attrName === "data-mask-copy-raw") {
336
- this.options.copyRaw = this.input.type === "password" ? false : this.getAttr("data-mask-copy-raw") === "true";
410
+ this.options.copyRaw = this.isPasswordInput() ? false : this.getAttr("data-mask-copy-raw") === "true";
337
411
  } else if (attrName === "type") {
338
- if (this.input.type === "password") {
412
+ if (this.isPasswordInput()) {
339
413
  this.options.copyRaw = false;
414
+ this.lastTrackedValue = "";
415
+ this.clearGhost();
416
+ this.wrapper.removeAttribute("data-mask");
340
417
  this.onPasswordModeDetected();
341
418
  }
342
419
  } else if (attrName === "data-mask-align" || attrName === "data-align") {
343
- const align = this.getAttr("data-mask-align") || this.getAttr("data-align");
420
+ const rawAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
421
+ const align = rawAlign && VALID_ALIGNS.has(rawAlign) ? rawAlign : null;
344
422
  if (align !== (this.options.align ?? null)) {
345
423
  this.setAlign(align);
346
424
  }
@@ -368,15 +446,42 @@ var __WulfIIFE = (() => {
368
446
  if (existing) {
369
447
  existing.remove();
370
448
  }
371
- this.ghost = document.createElement("div");
449
+ const doc = this.input.ownerDocument || document;
450
+ this.ghost = doc.createElement("div");
372
451
  this.ghost.className = "mask-ghost";
373
452
  this.ghost.setAttribute("aria-hidden", "true");
374
453
  this.ghost.style.display = "flex";
375
454
  this.ghost.style.alignItems = "center";
376
455
  this.wrapper.appendChild(this.ghost);
377
456
  this.wrapper.classList.add("has-ghost");
457
+ const view = doc.defaultView || (typeof window !== "undefined" ? window : null);
458
+ if (!this.wrapper.isConnected || !view || view.getComputedStyle(this.ghost).pointerEvents !== "none") {
459
+ this.ghost.style.gridArea = "1 / 1 / 2 / 2";
460
+ this.ghost.style.pointerEvents = "none";
461
+ }
378
462
  this.syncGhostStyles();
379
463
  }
464
+ /**
465
+ * Met à jour atomiquement le contenu du conteneur fantôme et synchronise .has-visible-ghost.
466
+ */
467
+ setGhostContent(...nodes) {
468
+ if (!this.ghost) return;
469
+ if (typeof this.ghost.replaceChildren === "function") {
470
+ this.ghost.replaceChildren(...nodes);
471
+ } else {
472
+ this.ghost.textContent = "";
473
+ for (const n of nodes) {
474
+ this.ghost.appendChild(typeof n === "string" ? document.createTextNode(n) : n);
475
+ }
476
+ }
477
+ this.wrapper.classList.toggle("has-visible-ghost", nodes.length > 0);
478
+ }
479
+ /**
480
+ * Vide atomiquement le conteneur fantôme et rétablit l'affichage du placeholder natif.
481
+ */
482
+ clearGhost() {
483
+ this.setGhostContent();
484
+ }
380
485
  /**
381
486
  * Clone fidèlement la géométrie typographique et les espacements de l'input natif
382
487
  * sur le conteneur fantôme pour garantir un alignement sub-pixel absolu quel que soit
@@ -409,12 +514,17 @@ var __WulfIIFE = (() => {
409
514
  this.ghost.style.textAlign = style.textAlign;
410
515
  this.ghost.style.direction = style.direction;
411
516
  const isRtl = style.direction === "rtl" || this.input.getAttribute("dir") === "rtl" || this.wrapper.getAttribute("dir") === "rtl";
412
- if (style.textAlign === "right" || style.textAlign === "end" || isRtl && style.textAlign !== "left" && style.textAlign !== "center") {
413
- this.ghost.style.justifyContent = "flex-end";
414
- } else if (style.textAlign === "center") {
517
+ const textAlign = style.textAlign;
518
+ if (textAlign === "right") {
519
+ this.ghost.style.justifyContent = "right";
520
+ } else if (textAlign === "left") {
521
+ this.ghost.style.justifyContent = "left";
522
+ } else if (textAlign === "center") {
415
523
  this.ghost.style.justifyContent = "center";
524
+ } else if (textAlign === "end") {
525
+ this.ghost.style.justifyContent = isRtl ? "left" : "right";
416
526
  } else {
417
- this.ghost.style.justifyContent = "flex-start";
527
+ this.ghost.style.justifyContent = isRtl ? "right" : "left";
418
528
  }
419
529
  }
420
530
  /**
@@ -438,15 +548,23 @@ var __WulfIIFE = (() => {
438
548
  this.isDispatchingNativeInput = true;
439
549
  try {
440
550
  const tracker = this.input._valueTracker;
441
- if (tracker && typeof tracker.setValue === "function") {
551
+ if (!this.isPasswordInput() && tracker && typeof tracker.setValue === "function") {
442
552
  tracker.setValue(this.lastTrackedValue);
443
553
  }
444
- this.lastTrackedValue = this.input.value;
554
+ this.lastTrackedValue = this.isPasswordInput() ? "" : this.input.value;
445
555
  this.input.dispatchEvent(new Event("input", { bubbles: true, cancelable: false }));
446
556
  } finally {
447
557
  this.isDispatchingNativeInput = false;
448
558
  }
449
559
  }
560
+ /**
561
+ * Synchronise le défilement horizontal du ghost avec celui du champ d'entrée natif.
562
+ */
563
+ onScroll = () => {
564
+ if (this.ghost) {
565
+ this.ghost.scrollLeft = this.input.scrollLeft;
566
+ }
567
+ };
450
568
  /**
451
569
  * Intercepte les modifications directes de la propriété input.value (ex: input.value = '').
452
570
  */
@@ -558,15 +676,19 @@ var __WulfIIFE = (() => {
558
676
  audit() {
559
677
  const warnings = [];
560
678
  const doc = this.input.ownerDocument || document;
679
+ const root = typeof this.input.getRootNode === "function" ? this.input.getRootNode() : doc;
680
+ const labelRoot = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : doc;
561
681
  const ariaLabel = this.input.getAttribute("aria-label")?.trim();
562
682
  const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
563
683
  const hasWrappingLabel = Boolean(this.input.closest("label"));
564
684
  const hasNativeLabels = Boolean(this.input.labels && this.input.labels.length > 0);
565
685
  let hasExplicitLabelFor = false;
566
- if (this.input.id && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
567
- hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${CSS.escape(this.input.id)}"]`));
568
- } else if (this.input.id) {
569
- hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${this.input.id}"]`));
686
+ if (this.input.id) {
687
+ try {
688
+ hasExplicitLabelFor = Boolean(labelRoot.querySelector(`label[for="${safeCssEscape(this.input.id)}"]`));
689
+ } catch {
690
+ hasExplicitLabelFor = false;
691
+ }
570
692
  }
571
693
  if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
572
694
  warnings.push(
@@ -612,25 +734,41 @@ var __WulfIIFE = (() => {
612
734
  this.mutationObserver.disconnect();
613
735
  this.mutationObserver = null;
614
736
  }
615
- this.input.removeEventListener("copy", this.onBaseCopy);
616
- this.input.removeEventListener("focus", this.onBaseFocus);
617
- this.input.removeEventListener("blur", this.onBaseBlur);
737
+ this.abortController.abort();
738
+ this.lastTrackedValue = "";
618
739
  this.unhookValueProperty();
619
740
  if (this.ghost) {
620
741
  this.ghost.remove();
621
742
  this.ghost = null;
622
743
  }
623
744
  if (this.isWrapperCreated && this.wrapper) {
624
- this.input.style.gridArea = "";
625
- this.input.style.boxSizing = "";
626
- if (this.wrapper.parentNode) {
745
+ if (this.wasWrapperFallbackStyled) {
746
+ this.input.style.gridArea = "";
747
+ this.input.style.boxSizing = "";
748
+ }
749
+ if (this.wrapper.parentElement) {
750
+ safeMove(this.wrapper.parentElement, this.input, this.wrapper);
751
+ } else if (this.wrapper.parentNode) {
627
752
  this.wrapper.parentNode.insertBefore(this.input, this.wrapper);
628
753
  }
629
754
  this.wrapper.remove();
630
755
  } else if (this.wrapper) {
631
756
  this.wrapper.removeAttribute("data-mask");
632
757
  this.wrapper.removeAttribute("data-disabled");
633
- this.wrapper.classList.remove("is-complete", "is-focused", "mask-focus-only", "has-selection", "has-ghost");
758
+ if (this.wasAlignSet && !this.hadInitialDataAlign) {
759
+ this.wrapper.removeAttribute("data-align");
760
+ }
761
+ if (this.wasAlignSet) {
762
+ this.wrapper.classList.remove("align-left", "align-right", "align-center");
763
+ }
764
+ this.wrapper.classList.remove(
765
+ "is-complete",
766
+ "is-focused",
767
+ "mask-focus-only",
768
+ "has-selection",
769
+ "has-ghost",
770
+ "has-visible-ghost"
771
+ );
634
772
  }
635
773
  }
636
774
  };
@@ -644,19 +782,34 @@ var __WulfIIFE = (() => {
644
782
  "#": { pattern: /[a-zA-Z0-9]/, transform: (c) => c.toUpperCase() }
645
783
  };
646
784
  var MaskEngine = class _MaskEngine {
785
+ pattern;
786
+ patterns = [];
787
+ subEngines = [];
788
+ activeEngine = null;
789
+ placeholderChar;
790
+ tokens;
791
+ slots = [];
792
+ fullMaskTemplate = "";
793
+ prefixSlotsCount = 0;
794
+ prefixString = "";
795
+ strict = true;
796
+ autoLowercase = false;
647
797
  constructor(pattern, options = {}) {
648
- this.patterns = [];
649
- this.subEngines = [];
650
- this.activeEngine = null;
651
- this.slots = [];
652
- this.fullMaskTemplate = "";
653
- this.prefixSlotsCount = 0;
654
- this.prefixString = "";
655
- this.strict = true;
656
- this.autoLowercase = false;
657
798
  const opts = options || {};
658
- this.placeholderChar = opts.placeholderChar || "_";
659
- this.tokens = { ...DEFAULT_TOKENS, ...opts.tokens || {} };
799
+ const rawPlaceholder = String(opts.placeholderChar || "_");
800
+ this.placeholderChar = Array.from(rawPlaceholder)[0] || "_";
801
+ const tokenMap = /* @__PURE__ */ Object.create(null);
802
+ for (const [k, v] of Object.entries(DEFAULT_TOKENS)) {
803
+ tokenMap[k] = v;
804
+ }
805
+ if (opts.tokens && typeof opts.tokens === "object") {
806
+ for (const [k, v] of Object.entries(opts.tokens)) {
807
+ if (k !== "__proto__" && k !== "constructor" && k !== "prototype" && v) {
808
+ tokenMap[k] = v;
809
+ }
810
+ }
811
+ }
812
+ this.tokens = tokenMap;
660
813
  this.strict = opts.strict !== false;
661
814
  this.autoLowercase = opts.autoLowercase ?? false;
662
815
  this.pattern = "";
@@ -716,7 +869,7 @@ var __WulfIIFE = (() => {
716
869
  i++;
717
870
  char = this.pattern[i];
718
871
  }
719
- const token = !isEscaped ? this.tokens[char] : void 0;
872
+ const token = !isEscaped && Object.hasOwn(this.tokens, char) ? this.tokens[char] : void 0;
720
873
  if (token) {
721
874
  isPrefixMode = false;
722
875
  this.slots.push({
@@ -763,7 +916,7 @@ var __WulfIIFE = (() => {
763
916
  return p.length > 0 && trimmed.toLowerCase().startsWith(p.trim().toLowerCase());
764
917
  });
765
918
  const candidates = withMatchingPrefix.length > 0 ? withMatchingPrefix : this.subEngines;
766
- const maxCandidate = [...candidates].sort((a, b) => b.getEditableCount() - a.getEditableCount())[0];
919
+ const maxCandidate = candidates.toSorted((a, b) => b.getEditableCount() - a.getEditableCount())[0];
767
920
  const raw = maxCandidate ? maxCandidate.extractRaw(trimmed) : trimmed;
768
921
  const rawLen = raw.length;
769
922
  for (const eng of candidates) {
@@ -819,6 +972,18 @@ var __WulfIIFE = (() => {
819
972
  */
820
973
  setStrict(strict) {
821
974
  this.strict = strict;
975
+ for (const sub of this.subEngines) {
976
+ sub.setStrict(strict);
977
+ }
978
+ }
979
+ /**
980
+ * Active ou désactive dynamiquement la mise en minuscules automatique.
981
+ */
982
+ setAutoLowercase(autoLowercase) {
983
+ this.autoLowercase = autoLowercase;
984
+ for (const sub of this.subEngines) {
985
+ sub.setAutoLowercase(autoLowercase);
986
+ }
822
987
  }
823
988
  /**
824
989
  * Indique si le masque est en mode strict.
@@ -1043,9 +1208,10 @@ var __WulfIIFE = (() => {
1043
1208
 
1044
1209
  // src/mask/MaskHistory.ts
1045
1210
  var MaskHistory = class {
1211
+ stack = [];
1212
+ index = -1;
1213
+ maxDepth;
1046
1214
  constructor(maxDepth = 50) {
1047
- this.stack = [];
1048
- this.index = -1;
1049
1215
  this.maxDepth = maxDepth;
1050
1216
  }
1051
1217
  /**
@@ -1123,6 +1289,7 @@ var __WulfIIFE = (() => {
1123
1289
 
1124
1290
  // src/mask/MaskKeyboard.ts
1125
1291
  var MaskKeyboard = class {
1292
+ delegate;
1126
1293
  constructor(delegate) {
1127
1294
  this.delegate = delegate;
1128
1295
  }
@@ -1130,6 +1297,7 @@ var __WulfIIFE = (() => {
1130
1297
  * Analyse et traite l'événement keydown de l'input.
1131
1298
  */
1132
1299
  handleKeyDown(e) {
1300
+ if (isImeComposing(e)) return;
1133
1301
  const input = this.delegate.getInput();
1134
1302
  const engine = this.delegate.getEngine();
1135
1303
  const history = this.delegate.getHistory();
@@ -1223,7 +1391,7 @@ var __WulfIIFE = (() => {
1223
1391
  input.setSelectionRange(minPos, minPos);
1224
1392
  return;
1225
1393
  }
1226
- if (e.key === "Home" && !e.shiftKey) {
1394
+ if (e.key === "Home" && minPos > 0 && !e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey) {
1227
1395
  e.preventDefault();
1228
1396
  input.setSelectionRange(minPos, minPos);
1229
1397
  return;
@@ -1328,6 +1496,23 @@ var __WulfIIFE = (() => {
1328
1496
 
1329
1497
  // src/mask/InputMask.ts
1330
1498
  var InputMask = class extends BaseInputMask {
1499
+ engine;
1500
+ history;
1501
+ keyboard;
1502
+ isComposing = false;
1503
+ isUndoingRedoing = false;
1504
+ isMouseDown = false;
1505
+ isApplyingMask = false;
1506
+ lastValue = "";
1507
+ lastInternalRemainingMask = "";
1508
+ isNotifying = false;
1509
+ hasPendingNotification = false;
1510
+ onChangeNativeHandler = () => {
1511
+ };
1512
+ wasInputModeInferred = false;
1513
+ cutTimerId = null;
1514
+ pasteTimerId = null;
1515
+ resetTimerId = null;
1331
1516
  constructor(targetOrWrapper, inputOrOptions, options) {
1332
1517
  const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
1333
1518
  const wrap = args.wrapper;
@@ -1360,20 +1545,6 @@ var __WulfIIFE = (() => {
1360
1545
  onComplete: opts.onComplete || opts.oncomplete
1361
1546
  };
1362
1547
  super(wrap, inp, resolvedOptions);
1363
- this.isComposing = false;
1364
- this.isUndoingRedoing = false;
1365
- this.isMouseDown = false;
1366
- this.isApplyingMask = false;
1367
- this.lastValue = "";
1368
- this.lastInternalRemainingMask = "";
1369
- this.isNotifying = false;
1370
- this.hasPendingNotification = false;
1371
- this.onChangeNativeHandler = () => {
1372
- };
1373
- this.wasInputModeInferred = false;
1374
- this.cutTimerId = null;
1375
- this.pasteTimerId = null;
1376
- this.resetTimerId = null;
1377
1548
  this.history = new MaskHistory();
1378
1549
  this.engine = new MaskEngine(this.options.mask || "", {
1379
1550
  placeholderChar: this.options.placeholderChar,
@@ -1392,16 +1563,17 @@ var __WulfIIFE = (() => {
1392
1563
  enforceMinCursor: () => this.enforceMinCursor()
1393
1564
  });
1394
1565
  this.bindEvents();
1395
- this.lastValue = this.input.value;
1566
+ this.lastValue = this.isPasswordInput() ? this.computePasswordDigest(this.input.value) : this.input.value;
1396
1567
  this.syncInitialValue();
1397
1568
  this.runAuditWarning(this.options.audit);
1398
1569
  }
1399
1570
  getSpecificAuditWarnings() {
1400
1571
  const warnings = [];
1401
- const hasDescribedby = Boolean(this.input.getAttribute("aria-describedby")?.trim());
1572
+ const describedbyWarnings = [];
1573
+ const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings);
1402
1574
  const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
1403
1575
  const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
1404
- if (!hasDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
1576
+ if (!hasValidDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
1405
1577
  warnings.push(
1406
1578
  "Indication du format attendu manquante : d\xE9finissez aria-describedby, placeholder ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
1407
1579
  );
@@ -1413,6 +1585,11 @@ var __WulfIIFE = (() => {
1413
1585
  }
1414
1586
  onPasswordModeDetected() {
1415
1587
  this.history.clear();
1588
+ this.lastValue = "";
1589
+ this.lastInternalRemainingMask = "";
1590
+ this.lastTrackedValue = "";
1591
+ this.clearGhost();
1592
+ this.wrapper.removeAttribute("data-mask");
1416
1593
  }
1417
1594
  /**
1418
1595
  * Formate statiquement une valeur selon un masque donné sans nécessiter d'élément DOM.
@@ -1436,11 +1613,12 @@ var __WulfIIFE = (() => {
1436
1613
  if (disabled) {
1437
1614
  this.wrapper.removeAttribute("data-mask");
1438
1615
  this.wrapper.classList.remove("is-complete", "has-selection");
1439
- if (this.ghost) this.ghost.textContent = "";
1616
+ this.clearGhost();
1440
1617
  this.checkValueChange();
1441
1618
  } else {
1442
1619
  this.applyMask(this.input.value, this.input.selectionStart ?? this.input.value.length);
1443
1620
  }
1621
+ this.syncInferredInputMode();
1444
1622
  }
1445
1623
  /**
1446
1624
  * Associe les écouteurs d'événements nécessaires.
@@ -1477,22 +1655,23 @@ var __WulfIIFE = (() => {
1477
1655
  if (this.isDestroyed) return;
1478
1656
  this.checkValueChange();
1479
1657
  };
1480
- this.input.addEventListener("beforeinput", this.onBeforeInput);
1481
- this.input.addEventListener("input", this.handleInput);
1482
- this.input.addEventListener("keydown", this.onKeyDown);
1483
- this.input.addEventListener("paste", this.onPaste);
1484
- this.input.addEventListener("focus", this.onFocus);
1485
- this.input.addEventListener("blur", this.onBlur);
1486
- this.input.addEventListener("click", this.onClick);
1487
- this.input.addEventListener("keyup", this.onKeyUp);
1488
- this.input.addEventListener("select", this.onSelect);
1489
- this.input.addEventListener("mousedown", this.onMouseDown);
1490
- window.addEventListener("mouseup", this.onMouseUp);
1491
- this.input.addEventListener("compositionstart", this.onCompositionStart);
1492
- this.input.addEventListener("compositionend", this.onCompositionEnd);
1493
- this.input.addEventListener("scroll", this.onScroll);
1494
- this.input.addEventListener("cut", this.onCutHandler);
1495
- this.input.addEventListener("change", this.onChangeNativeHandler);
1658
+ const { signal } = this.abortController;
1659
+ this.input.addEventListener("beforeinput", this.onBeforeInput, { signal });
1660
+ this.input.addEventListener("input", this.handleInput, { signal });
1661
+ this.input.addEventListener("keydown", this.onKeyDown, { signal });
1662
+ this.input.addEventListener("paste", this.onPaste, { signal });
1663
+ this.input.addEventListener("focus", this.onFocus, { signal });
1664
+ this.input.addEventListener("blur", this.onBlur, { signal });
1665
+ this.input.addEventListener("click", this.onClick, { signal });
1666
+ this.input.addEventListener("keyup", this.onKeyUp, { signal });
1667
+ this.input.addEventListener("select", this.onSelect, { signal });
1668
+ this.input.addEventListener("mousedown", this.onMouseDown, { signal });
1669
+ window.addEventListener("mouseup", this.onMouseUp, { signal });
1670
+ this.input.addEventListener("compositionstart", this.onCompositionStart, { signal });
1671
+ this.input.addEventListener("compositionend", this.onCompositionEnd, { signal });
1672
+ this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
1673
+ this.input.addEventListener("cut", this.onCutHandler, { signal });
1674
+ this.input.addEventListener("change", this.onChangeNativeHandler, { signal });
1496
1675
  if (this.input.form) {
1497
1676
  this.onFormResetHandler = () => {
1498
1677
  if (this.resetTimerId !== null) clearTimeout(this.resetTimerId);
@@ -1506,7 +1685,7 @@ var __WulfIIFE = (() => {
1506
1685
  }
1507
1686
  }, 0);
1508
1687
  };
1509
- this.input.form.addEventListener("reset", this.onFormResetHandler);
1688
+ this.input.form.addEventListener("reset", this.onFormResetHandler, { signal });
1510
1689
  }
1511
1690
  }
1512
1691
  /**
@@ -1543,29 +1722,12 @@ var __WulfIIFE = (() => {
1543
1722
  clearTimeout(this.resetTimerId);
1544
1723
  this.resetTimerId = null;
1545
1724
  }
1546
- this.input.removeEventListener("beforeinput", this.onBeforeInput);
1547
- this.input.removeEventListener("input", this.handleInput);
1548
- this.input.removeEventListener("keydown", this.onKeyDown);
1549
- this.input.removeEventListener("paste", this.onPaste);
1550
- this.input.removeEventListener("focus", this.onFocus);
1551
- this.input.removeEventListener("blur", this.onBlur);
1552
- this.input.removeEventListener("click", this.onClick);
1553
- this.input.removeEventListener("keyup", this.onKeyUp);
1554
- this.input.removeEventListener("select", this.onSelect);
1555
- this.input.removeEventListener("mousedown", this.onMouseDown);
1556
- window.removeEventListener("mouseup", this.onMouseUp);
1557
- this.input.removeEventListener("compositionstart", this.onCompositionStart);
1558
- this.input.removeEventListener("compositionend", this.onCompositionEnd);
1559
- this.input.removeEventListener("scroll", this.onScroll);
1560
- this.input.removeEventListener("cut", this.onCutHandler);
1561
- this.input.removeEventListener("change", this.onChangeNativeHandler);
1562
- if (this.input.form && this.onFormResetHandler) {
1563
- this.input.form.removeEventListener("reset", this.onFormResetHandler);
1564
- }
1565
1725
  if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "numeric") {
1566
1726
  this.input.removeAttribute("inputmode");
1567
1727
  }
1568
1728
  this.history.clear();
1729
+ this.lastValue = "";
1730
+ this.lastInternalRemainingMask = "";
1569
1731
  super.destroy();
1570
1732
  }
1571
1733
  /**
@@ -1639,6 +1801,7 @@ var __WulfIIFE = (() => {
1639
1801
  this.setStrict(strictVal !== "false");
1640
1802
  } else if (attrName === "data-mask-auto-lowercase") {
1641
1803
  this.options.autoLowercase = this.getAttr("data-mask-auto-lowercase") === "true";
1804
+ this.engine.setAutoLowercase(this.options.autoLowercase);
1642
1805
  this.engine.compile(this.options.mask || "");
1643
1806
  this.applyMask(this.input.value, this.input.selectionStart ?? this.input.value.length);
1644
1807
  } else if (attrName === "placeholder") {
@@ -1718,7 +1881,7 @@ var __WulfIIFE = (() => {
1718
1881
  if (this.options.disabled) return;
1719
1882
  if (this.isComposing) return;
1720
1883
  if (!this.engine.isStrict()) return;
1721
- if (e.inputType === "insertFromPaste") return;
1884
+ if (e.inputType === "insertFromPaste" || e.inputType === "insertReplacementText") return;
1722
1885
  if (e.inputType && e.inputType.startsWith("insert")) {
1723
1886
  const totalSlots = this.engine.getEditableCount();
1724
1887
  if (totalSlots > 0) {
@@ -1740,7 +1903,8 @@ var __WulfIIFE = (() => {
1740
1903
  if (this.isDispatchingNativeInput) return;
1741
1904
  if (this.isComposing) return;
1742
1905
  const hasOnInput = Boolean(this.options.onInput || this.options.oninput);
1743
- if (hasOnInput && this.input.value !== this.lastValue) {
1906
+ const currentComparison = this.isPasswordInput() ? this.computePasswordDigest(this.input.value) : this.input.value;
1907
+ if (hasOnInput && currentComparison !== this.lastValue) {
1744
1908
  this.checkValueChange();
1745
1909
  }
1746
1910
  if (this.options.disabled) {
@@ -1834,8 +1998,14 @@ var __WulfIIFE = (() => {
1834
1998
  }
1835
1999
  onBlur() {
1836
2000
  this.wrapper.classList.remove("is-focused", "has-selection");
1837
- if (this.input.type === "password") {
2001
+ if (this.isPasswordInput()) {
1838
2002
  this.history.clear();
2003
+ this.lastValue = "";
2004
+ this.lastInternalRemainingMask = "";
2005
+ this.lastTrackedValue = "";
2006
+ this.clearGhost();
2007
+ this.wrapper.removeAttribute("data-mask");
2008
+ return;
1839
2009
  }
1840
2010
  this.updateGhost(this.input.value);
1841
2011
  }
@@ -1889,26 +2059,25 @@ var __WulfIIFE = (() => {
1889
2059
  // ==========================================================================
1890
2060
  updateGhost(formatted) {
1891
2061
  if (!this.ghost) return;
1892
- if (this.options.disabled) {
1893
- this.ghost.textContent = "";
2062
+ if (this.options.disabled || this.isPasswordInput()) {
2063
+ this.clearGhost();
1894
2064
  return;
1895
2065
  }
1896
2066
  const isCleanEmpty = !formatted || formatted === this.engine.getPrefix();
1897
2067
  if (this.shouldHideGhostForPlaceholder(isCleanEmpty)) {
1898
- this.ghost.textContent = "";
2068
+ this.clearGhost();
1899
2069
  return;
1900
2070
  }
1901
2071
  const fullTemplate = this.engine.getFullMaskTemplate();
1902
2072
  const rest = fullTemplate.length > formatted.length ? fullTemplate.substring(formatted.length) : "";
1903
- this.ghost.textContent = "";
1904
- const spanTyped = document.createElement("span");
2073
+ const doc = this.input.ownerDocument || document;
2074
+ const spanTyped = doc.createElement("span");
1905
2075
  spanTyped.className = "mask-ghost-typed";
1906
2076
  spanTyped.textContent = formatted;
1907
- const spanRemaining = document.createElement("span");
2077
+ const spanRemaining = doc.createElement("span");
1908
2078
  spanRemaining.className = "mask-ghost-remaining";
1909
2079
  spanRemaining.textContent = rest;
1910
- this.ghost.appendChild(spanTyped);
1911
- this.ghost.appendChild(spanRemaining);
2080
+ this.setGhostContent(spanTyped, spanRemaining);
1912
2081
  this.ghost.scrollLeft = this.input.scrollLeft;
1913
2082
  }
1914
2083
  applyMask(rawOrPartial, cursorPosition, forceExactCursor = false) {
@@ -1919,10 +2088,17 @@ var __WulfIIFE = (() => {
1919
2088
  try {
1920
2089
  formatted = this.engine.format(rawOrPartial);
1921
2090
  const remainingMask = this.engine.getRemainingMask(formatted);
2091
+ const isPwd = this.isPasswordInput();
1922
2092
  this.input.value = formatted;
1923
- this.lastInternalRemainingMask = remainingMask;
1924
- this.wrapper.setAttribute("data-mask", remainingMask);
1925
- this.updateGhost(formatted);
2093
+ if (isPwd) {
2094
+ this.lastInternalRemainingMask = "";
2095
+ this.wrapper.removeAttribute("data-mask");
2096
+ this.clearGhost();
2097
+ } else {
2098
+ this.lastInternalRemainingMask = remainingMask;
2099
+ this.wrapper.setAttribute("data-mask", remainingMask);
2100
+ this.updateGhost(formatted);
2101
+ }
1926
2102
  const minPos = this.engine.getPrefixLength();
1927
2103
  let safeCursor;
1928
2104
  if (forceExactCursor || this.isUndoingRedoing) {
@@ -1934,7 +2110,7 @@ var __WulfIIFE = (() => {
1934
2110
  this.input.setSelectionRange(safeCursor, safeCursor);
1935
2111
  isCompleted = this.isComplete();
1936
2112
  this.wrapper.classList.toggle("is-complete", isCompleted);
1937
- if (this.input.type === "password") {
2113
+ if (isPwd) {
1938
2114
  this.options.copyRaw = false;
1939
2115
  this.history.clear();
1940
2116
  } else if (!this.isUndoingRedoing) {
@@ -1946,10 +2122,11 @@ var __WulfIIFE = (() => {
1946
2122
  this.checkValueChange();
1947
2123
  }
1948
2124
  syncInitialValue() {
2125
+ const isPwd = this.isPasswordInput();
1949
2126
  if (this.options.disabled) {
1950
2127
  this.wrapper.removeAttribute("data-mask");
1951
- if (this.ghost) this.ghost.textContent = "";
1952
- this.lastValue = this.input.value;
2128
+ this.clearGhost();
2129
+ this.lastValue = isPwd ? this.computePasswordDigest(this.input.value) : this.input.value;
1953
2130
  this.checkValueChange();
1954
2131
  return;
1955
2132
  }
@@ -1962,13 +2139,17 @@ var __WulfIIFE = (() => {
1962
2139
  if (minPos > 0) {
1963
2140
  this.applyMask("", minPos);
1964
2141
  } else {
1965
- if (this.input.type !== "password") {
2142
+ if (!isPwd) {
1966
2143
  this.history.push("", 0);
2144
+ const fullTemplate = this.engine.getFullMaskTemplate();
2145
+ this.lastInternalRemainingMask = fullTemplate;
2146
+ this.wrapper.setAttribute("data-mask", fullTemplate);
2147
+ this.updateGhost("");
2148
+ } else {
2149
+ this.lastInternalRemainingMask = "";
2150
+ this.wrapper.removeAttribute("data-mask");
2151
+ this.clearGhost();
1967
2152
  }
1968
- const fullTemplate = this.engine.getFullMaskTemplate();
1969
- this.lastInternalRemainingMask = fullTemplate;
1970
- this.wrapper.setAttribute("data-mask", fullTemplate);
1971
- this.updateGhost("");
1972
2153
  this.checkValueChange();
1973
2154
  }
1974
2155
  }
@@ -1978,8 +2159,10 @@ var __WulfIIFE = (() => {
1978
2159
  * Gère de manière sûre la réentrance pour permettre d'appeler setMask() directement dans le callback.
1979
2160
  */
1980
2161
  checkValueChange(forceNotify = false) {
2162
+ const isPwd = this.isPasswordInput();
1981
2163
  const currentVal = this.input.value;
1982
- if (currentVal === this.lastValue && !forceNotify && !this.hasPendingNotification) {
2164
+ const currentComparison = isPwd ? this.computePasswordDigest(currentVal) : currentVal;
2165
+ if (currentComparison === this.lastValue && !forceNotify && !this.hasPendingNotification) {
1983
2166
  return;
1984
2167
  }
1985
2168
  if (this.isNotifying) {
@@ -1990,12 +2173,12 @@ var __WulfIIFE = (() => {
1990
2173
  try {
1991
2174
  let iterations = 0;
1992
2175
  const MAX_NOTIFICATION_ITERATIONS = 10;
1993
- while ((this.input.value !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS) {
2176
+ while (((isPwd ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS) {
1994
2177
  iterations++;
1995
2178
  this.hasPendingNotification = false;
1996
2179
  forceNotify = false;
1997
2180
  const valToNotify = this.input.value;
1998
- this.lastValue = valToNotify;
2181
+ this.lastValue = isPwd ? this.computePasswordDigest(valToNotify) : valToNotify;
1999
2182
  const raw = this.options.disabled ? valToNotify : this.getRawValue();
2000
2183
  const totalSlots = this.options.disabled ? 0 : this.engine.getEditableCount();
2001
2184
  const isComplete = this.isComplete();
@@ -2033,6 +2216,7 @@ var __WulfIIFE = (() => {
2033
2216
 
2034
2217
  // src/mask/AmountEngine.ts
2035
2218
  var AmountEngine = class _AmountEngine {
2219
+ options;
2036
2220
  constructor(options = {}) {
2037
2221
  let currency = options.currency ?? "";
2038
2222
  if (!currency && options.unit) {
@@ -2245,6 +2429,16 @@ var __WulfIIFE = (() => {
2245
2429
 
2246
2430
  // src/mask/InputAmountMask.ts
2247
2431
  var InputAmountMask = class extends BaseInputMask {
2432
+ engine;
2433
+ history;
2434
+ isUndoingRedoing = false;
2435
+ isApplying = false;
2436
+ isComposing = false;
2437
+ lastValue = "";
2438
+ wasInputModeInferred = false;
2439
+ cutTimerId = null;
2440
+ resetTimerId = null;
2441
+ cursorTimerId = null;
2248
2442
  constructor(targetOrWrapper, inputOrOptions, options) {
2249
2443
  const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
2250
2444
  const wrap = args.wrapper;
@@ -2258,13 +2452,10 @@ var __WulfIIFE = (() => {
2258
2452
  ...opts
2259
2453
  };
2260
2454
  super(wrap, inp, resolvedOptions);
2261
- this.isUndoingRedoing = false;
2262
- this.isApplying = false;
2263
- this.isComposing = false;
2264
- this.lastValue = "";
2265
- this.cutTimerId = null;
2266
- this.resetTimerId = null;
2267
- this.input.inputMode = "decimal";
2455
+ if (!this.input.hasAttribute("inputmode")) {
2456
+ this.input.inputMode = "decimal";
2457
+ this.wasInputModeInferred = true;
2458
+ }
2268
2459
  this.history = new MaskHistory();
2269
2460
  this.engine = new AmountEngine(this.options);
2270
2461
  this.bindEvents();
@@ -2290,6 +2481,9 @@ var __WulfIIFE = (() => {
2290
2481
  }
2291
2482
  onPasswordModeDetected() {
2292
2483
  this.history.clear();
2484
+ this.lastValue = "";
2485
+ this.lastTrackedValue = "";
2486
+ this.clearGhost();
2293
2487
  }
2294
2488
  /**
2295
2489
  * Formate statiquement une valeur sans nécessiter d'élément DOM.
@@ -2305,7 +2499,9 @@ var __WulfIIFE = (() => {
2305
2499
  this.applyAmount(strVal, strVal.length);
2306
2500
  }
2307
2501
  onDisabledChange(disabled) {
2308
- if (!disabled) {
2502
+ if (disabled) {
2503
+ this.clearGhost();
2504
+ } else {
2309
2505
  this.applyAmount(this.input.value, this.input.selectionStart ?? this.input.value.length);
2310
2506
  }
2311
2507
  }
@@ -2328,15 +2524,16 @@ var __WulfIIFE = (() => {
2328
2524
  this.applyAmount(this.input.value, cur);
2329
2525
  }, 0);
2330
2526
  };
2331
- this.input.addEventListener("input", this.handleInput);
2332
- this.input.addEventListener("keydown", this.handleKeyDown);
2333
- this.input.addEventListener("blur", this.handleBlur);
2334
- this.input.addEventListener("focus", this.handleFocus);
2335
- this.input.addEventListener("click", this.handleClick);
2336
- this.input.addEventListener("scroll", this.onScroll);
2337
- this.input.addEventListener("cut", this.onCutHandler);
2338
- this.input.addEventListener("compositionstart", this.onCompositionStart);
2339
- this.input.addEventListener("compositionend", this.onCompositionEnd);
2527
+ const { signal } = this.abortController;
2528
+ this.input.addEventListener("input", this.handleInput, { signal });
2529
+ this.input.addEventListener("keydown", this.handleKeyDown, { signal });
2530
+ this.input.addEventListener("blur", this.handleBlur, { signal });
2531
+ this.input.addEventListener("focus", this.handleFocus, { signal });
2532
+ this.input.addEventListener("click", this.handleClick, { signal });
2533
+ this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
2534
+ this.input.addEventListener("cut", this.onCutHandler, { signal });
2535
+ this.input.addEventListener("compositionstart", this.onCompositionStart, { signal });
2536
+ this.input.addEventListener("compositionend", this.onCompositionEnd, { signal });
2340
2537
  if (this.input.form) {
2341
2538
  this.onFormResetHandler = () => {
2342
2539
  if (this.resetTimerId !== null) {
@@ -2349,7 +2546,7 @@ var __WulfIIFE = (() => {
2349
2546
  this.applyAmount(this.input.value, this.input.value.length);
2350
2547
  }, 0);
2351
2548
  };
2352
- this.input.form.addEventListener("reset", this.onFormResetHandler);
2549
+ this.input.form.addEventListener("reset", this.onFormResetHandler, { signal });
2353
2550
  }
2354
2551
  }
2355
2552
  onCompositionStart() {
@@ -2368,15 +2565,20 @@ var __WulfIIFE = (() => {
2368
2565
  const result = this.engine.format(val, cursor);
2369
2566
  this.setNativeValue(result.formatted);
2370
2567
  this.input.setSelectionRange(result.cursor, result.cursor);
2371
- if (this.input.type === "password") {
2568
+ const isPwd = this.isPasswordInput();
2569
+ if (isPwd) {
2372
2570
  this.options.copyRaw = false;
2373
2571
  this.history.clear();
2374
- } else if (!this.isUndoingRedoing) {
2375
- this.history.push(result.rawValue, result.cursor);
2572
+ this.clearGhost();
2573
+ } else {
2574
+ if (!this.isUndoingRedoing) {
2575
+ this.history.push(result.rawValue, result.cursor);
2576
+ }
2577
+ this.updateGhost(result);
2376
2578
  }
2377
- this.updateGhost(result);
2378
- if (this.lastValue !== result.formatted) {
2379
- this.lastValue = result.formatted;
2579
+ const nextComparison = isPwd ? this.computePasswordDigest(result.formatted) : result.formatted;
2580
+ if (this.lastValue !== nextComparison) {
2581
+ this.lastValue = nextComparison;
2380
2582
  this.notifyChange(result);
2381
2583
  }
2382
2584
  } finally {
@@ -2387,18 +2589,18 @@ var __WulfIIFE = (() => {
2387
2589
  if (!this.ghost) return;
2388
2590
  if (!result.formatted) {
2389
2591
  if (this.shouldHideGhostForPlaceholder(true)) {
2390
- this.ghost.textContent = "";
2592
+ this.clearGhost();
2391
2593
  return;
2392
2594
  }
2393
2595
  const hint = this.options.currency ? this.options.currencyPosition === "prefix" ? `${this.options.currency} 0` : `0 ${this.options.currency}` : "0,00";
2394
- this.ghost.textContent = "";
2395
- const span = document.createElement("span");
2596
+ const doc = this.input.ownerDocument || document;
2597
+ const span = doc.createElement("span");
2396
2598
  span.className = "mask-ghost-remaining";
2397
2599
  span.textContent = hint;
2398
- this.ghost.appendChild(span);
2600
+ this.setGhostContent(span);
2399
2601
  return;
2400
2602
  }
2401
- this.ghost.textContent = "";
2603
+ this.clearGhost();
2402
2604
  this.ghost.scrollLeft = this.input.scrollLeft;
2403
2605
  }
2404
2606
  handleInput() {
@@ -2409,7 +2611,7 @@ var __WulfIIFE = (() => {
2409
2611
  this.applyAmount(rawVal, cur);
2410
2612
  }
2411
2613
  handleKeyDown(e) {
2412
- if (this.options.disabled) return;
2614
+ if (this.options.disabled || isImeComposing(e)) return;
2413
2615
  if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z")) {
2414
2616
  e.preventDefault();
2415
2617
  if (e.shiftKey) this.redo();
@@ -2461,10 +2663,18 @@ var __WulfIIFE = (() => {
2461
2663
  }
2462
2664
  }
2463
2665
  }
2464
- setTimeout(() => this.enforceCursorBounds(), 0);
2666
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Home" || e.key === "End") {
2667
+ if (this.cursorTimerId !== null) {
2668
+ clearTimeout(this.cursorTimerId);
2669
+ }
2670
+ this.cursorTimerId = window.setTimeout(() => {
2671
+ this.cursorTimerId = null;
2672
+ this.enforceCursorBounds();
2673
+ }, 0);
2674
+ }
2465
2675
  }
2466
2676
  enforceCursorBounds() {
2467
- if (!this.input.value || this.options.disabled) return;
2677
+ if (this.isDestroyed || !this.isFocused || document.activeElement !== this.input || !this.input.value || this.options.disabled) return;
2468
2678
  const start = this.input.selectionStart ?? 0;
2469
2679
  const end = this.input.selectionEnd ?? 0;
2470
2680
  if (start !== end) return;
@@ -2495,8 +2705,12 @@ var __WulfIIFE = (() => {
2495
2705
  }
2496
2706
  handleBlur() {
2497
2707
  this.wrapper.classList.remove("is-focused");
2498
- if (this.input.type === "password") {
2708
+ if (this.isPasswordInput()) {
2499
2709
  this.history.clear();
2710
+ this.lastValue = "";
2711
+ this.lastTrackedValue = "";
2712
+ this.clearGhost();
2713
+ return;
2500
2714
  }
2501
2715
  if (this.options.padDecimalsOnBlur && !this.options.disabled && this.input.value.trim().length > 0) {
2502
2716
  const paddedResult = this.engine.format(this.input.value, this.input.value.length, true);
@@ -2592,30 +2806,62 @@ var __WulfIIFE = (() => {
2592
2806
  clearTimeout(this.resetTimerId);
2593
2807
  this.resetTimerId = null;
2594
2808
  }
2595
- this.input.removeEventListener("input", this.handleInput);
2596
- this.input.removeEventListener("keydown", this.handleKeyDown);
2597
- this.input.removeEventListener("blur", this.handleBlur);
2598
- this.input.removeEventListener("focus", this.handleFocus);
2599
- this.input.removeEventListener("click", this.handleClick);
2600
- this.input.removeEventListener("scroll", this.onScroll);
2601
- this.input.removeEventListener("cut", this.onCutHandler);
2602
- this.input.removeEventListener("compositionstart", this.onCompositionStart);
2603
- this.input.removeEventListener("compositionend", this.onCompositionEnd);
2604
- if (this.input.form && this.onFormResetHandler) {
2605
- this.input.form.removeEventListener("reset", this.onFormResetHandler);
2809
+ if (this.cursorTimerId !== null) {
2810
+ clearTimeout(this.cursorTimerId);
2811
+ this.cursorTimerId = null;
2812
+ }
2813
+ if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "decimal") {
2814
+ this.input.removeAttribute("inputmode");
2606
2815
  }
2816
+ this.lastValue = "";
2607
2817
  this.history.clear();
2608
2818
  super.destroy();
2609
2819
  }
2610
2820
  };
2611
2821
 
2612
2822
  // src/mask/EmailEngine.ts
2613
- var _EmailEngine = class _EmailEngine {
2823
+ var EmailEngine = class _EmailEngine {
2824
+ domains;
2825
+ tlds;
2826
+ suggestOnAt;
2827
+ defaultDomain = null;
2828
+ defaultTld = "__";
2829
+ static DEFAULT_DOMAINS = [
2830
+ "gmail.com",
2831
+ "outlook.com",
2832
+ "orange.fr",
2833
+ "free.fr",
2834
+ "sfr.fr",
2835
+ "yahoo.com",
2836
+ "hotmail.com",
2837
+ "icloud.com",
2838
+ "laposte.net",
2839
+ "proton.me"
2840
+ ];
2841
+ static DEFAULT_TLDS = [
2842
+ "com",
2843
+ "fr",
2844
+ "net",
2845
+ "org",
2846
+ "eu",
2847
+ "io",
2848
+ "co",
2849
+ "info",
2850
+ "biz",
2851
+ "me",
2852
+ "tv",
2853
+ "fi",
2854
+ "be",
2855
+ "ch",
2856
+ "ca",
2857
+ "uk",
2858
+ "de",
2859
+ "es",
2860
+ "it"
2861
+ ];
2614
2862
  constructor(options = {}) {
2615
- this.defaultDomain = null;
2616
- this.defaultTld = "__";
2617
2863
  this.domains = options.domains && options.domains.length > 0 ? options.domains : _EmailEngine.DEFAULT_DOMAINS;
2618
- this.tlds = options.tlds && options.tlds.length > 0 ? options.tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2864
+ this.tlds = options.tlds && options.tlds.length > 0 ? options.tlds.slice(0, 200).map((t) => String(t).trim().replace(/^\./, "").slice(0, 32)).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2619
2865
  this.suggestOnAt = options.suggestOnAt ?? true;
2620
2866
  this.setDefaultDomain(options.defaultDomain ?? null);
2621
2867
  this.setDefaultTld(options.defaultTld !== void 0 ? options.defaultTld : "__");
@@ -2648,7 +2894,7 @@ var __WulfIIFE = (() => {
2648
2894
  * Définit ou modifie la liste des extensions (TLD) proposées par ordre de priorité.
2649
2895
  */
2650
2896
  setTlds(tlds) {
2651
- this.tlds = tlds && tlds.length > 0 ? tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2897
+ this.tlds = tlds && tlds.length > 0 ? tlds.slice(0, 200).map((t) => String(t).trim().replace(/^\./, "").slice(0, 32)).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
2652
2898
  }
2653
2899
  /**
2654
2900
  * Retourne l'ensemble des extensions (TLD) correspondant au fragment saisi après le dernier point,
@@ -2719,22 +2965,22 @@ var __WulfIIFE = (() => {
2719
2965
  };
2720
2966
  }
2721
2967
  if (domainPart.length === 0 || domainPart.startsWith(".")) {
2722
- return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2968
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2723
2969
  }
2724
2970
  const lowerDomain = domainPart.toLowerCase();
2725
2971
  if (this.domains.some((d) => d.toLowerCase() === lowerDomain)) {
2726
- return { full: input, remaining: "", matchedDomain: domainPart, isHintOnly: false };
2972
+ return { full: val, remaining: "", matchedDomain: domainPart, isHintOnly: false };
2727
2973
  }
2728
2974
  const lastDotIndex = domainPart.lastIndexOf(".");
2729
2975
  if (lastDotIndex === -1) {
2730
2976
  if (!this.defaultTld) {
2731
- return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2977
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2732
2978
  }
2733
2979
  const isHint = this.defaultTld.includes("_");
2734
2980
  const remaining = `.${this.defaultTld}`;
2735
2981
  const fullDomain = `${domainPart}.${this.defaultTld}`;
2736
2982
  return {
2737
- full: isHint ? input : `${localPart}@${fullDomain}`,
2983
+ full: isHint ? val : `${localPart}@${fullDomain}`,
2738
2984
  remaining,
2739
2985
  matchedDomain: isHint ? null : fullDomain,
2740
2986
  isHintOnly: isHint
@@ -2743,7 +2989,7 @@ var __WulfIIFE = (() => {
2743
2989
  const hostPart = domainPart.substring(0, lastDotIndex);
2744
2990
  const tldPart = domainPart.substring(lastDotIndex + 1);
2745
2991
  if (!hostPart || hostPart.endsWith(".")) {
2746
- return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
2992
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2747
2993
  }
2748
2994
  if (tldPart.length === 0) {
2749
2995
  if (this.defaultTld && !this.defaultTld.includes("_")) {
@@ -2757,15 +3003,18 @@ var __WulfIIFE = (() => {
2757
3003
  }
2758
3004
  if (this.defaultTld && this.defaultTld.includes("_")) {
2759
3005
  return {
2760
- full: input,
3006
+ full: val,
2761
3007
  remaining: this.defaultTld,
2762
3008
  matchedDomain: null,
2763
3009
  isHintOnly: true
2764
3010
  };
2765
3011
  }
2766
- return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
3012
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2767
3013
  }
2768
3014
  const lowerTld = tldPart.toLowerCase();
3015
+ if (this.tlds.some((t) => t.toLowerCase() === lowerTld)) {
3016
+ return { full: val, remaining: "", matchedDomain: domainPart, isHintOnly: false };
3017
+ }
2769
3018
  const matchingTlds = this.getMatchingTlds(tldPart);
2770
3019
  if (matchingTlds.length > 0) {
2771
3020
  const safeTldIndex = (matchIndex % matchingTlds.length + matchingTlds.length) % matchingTlds.length;
@@ -2783,53 +3032,34 @@ var __WulfIIFE = (() => {
2783
3032
  const remaining = this.defaultTld.substring(tldPart.length);
2784
3033
  if (remaining.includes("_")) {
2785
3034
  return {
2786
- full: input,
3035
+ full: val,
2787
3036
  remaining,
2788
3037
  matchedDomain: null,
2789
3038
  isHintOnly: true
2790
3039
  };
2791
3040
  }
2792
3041
  }
2793
- return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
3042
+ return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
2794
3043
  }
2795
3044
  };
2796
- _EmailEngine.DEFAULT_DOMAINS = [
2797
- "gmail.com",
2798
- "outlook.com",
2799
- "orange.fr",
2800
- "free.fr",
2801
- "sfr.fr",
2802
- "yahoo.com",
2803
- "hotmail.com",
2804
- "icloud.com",
2805
- "laposte.net",
2806
- "proton.me"
2807
- ];
2808
- _EmailEngine.DEFAULT_TLDS = [
2809
- "com",
2810
- "fr",
2811
- "net",
2812
- "org",
2813
- "eu",
2814
- "io",
2815
- "co",
2816
- "info",
2817
- "biz",
2818
- "me",
2819
- "tv",
2820
- "fi",
2821
- "be",
2822
- "ch",
2823
- "ca",
2824
- "uk",
2825
- "de",
2826
- "es",
2827
- "it"
2828
- ];
2829
- var EmailEngine = _EmailEngine;
2830
3045
 
2831
3046
  // src/mask/InputEmailMask.ts
2832
3047
  var InputEmailMask = class extends BaseInputMask {
3048
+ engine;
3049
+ currentSuggestion = { full: "", remaining: "", matchedDomain: null };
3050
+ currentSuggestionIndex = 0;
3051
+ wasAriaAutocompleteSet = false;
3052
+ wasAutocorrectSet = false;
3053
+ wasAutocapitalizeSet = false;
3054
+ wasSpellcheckSet = false;
3055
+ wasInputModeInferred = false;
3056
+ isComposing = false;
3057
+ lastNotifiedValue = "";
3058
+ srStatusEl = null;
3059
+ srAnnounceTimerId = null;
3060
+ lastAnnouncedSuggestion = "";
3061
+ cutTimerId = null;
3062
+ resetTimerId = null;
2833
3063
  constructor(targetOrWrapper, inputOrOptions, options) {
2834
3064
  const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
2835
3065
  const wrap = args.wrapper;
@@ -2855,30 +3085,55 @@ var __WulfIIFE = (() => {
2855
3085
  ...resolvedDefaultTld !== void 0 ? { defaultTld: resolvedDefaultTld } : {}
2856
3086
  };
2857
3087
  super(wrap, inp, resolvedOptions);
2858
- this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
2859
- this.currentSuggestionIndex = 0;
2860
- this.wasAriaAutocompleteSet = false;
2861
- this.cutTimerId = null;
2862
- this.resetTimerId = null;
2863
- this.input.inputMode = "email";
3088
+ if (!this.input.hasAttribute("inputmode")) {
3089
+ this.input.inputMode = "email";
3090
+ this.wasInputModeInferred = true;
3091
+ }
3092
+ if (!this.input.hasAttribute("autocorrect")) {
3093
+ this.input.setAttribute("autocorrect", "off");
3094
+ this.wasAutocorrectSet = true;
3095
+ }
3096
+ if (!this.input.hasAttribute("autocapitalize")) {
3097
+ this.input.setAttribute("autocapitalize", "none");
3098
+ this.wasAutocapitalizeSet = true;
3099
+ }
3100
+ if (!this.input.hasAttribute("spellcheck")) {
3101
+ this.input.setAttribute("spellcheck", "false");
3102
+ this.wasSpellcheckSet = true;
3103
+ }
2864
3104
  if (this.options.setAriaAutocomplete && !this.input.hasAttribute("aria-autocomplete")) {
2865
3105
  this.input.setAttribute("aria-autocomplete", "inline");
2866
3106
  this.wasAriaAutocompleteSet = true;
2867
3107
  }
2868
3108
  this.engine = new EmailEngine(this.options);
3109
+ this.lastNotifiedValue = this.isPasswordInput() ? "" : this.input.value;
2869
3110
  this.bindEvents();
2870
- if (!this.options.disabled) {
3111
+ if (!this.options.disabled && !this.isPasswordInput()) {
2871
3112
  this.updateSuggestion();
2872
3113
  }
2873
3114
  this.runAuditWarning(this.options.audit);
2874
3115
  }
3116
+ onPasswordModeDetected() {
3117
+ if (this.srAnnounceTimerId !== null) {
3118
+ clearTimeout(this.srAnnounceTimerId);
3119
+ this.srAnnounceTimerId = null;
3120
+ }
3121
+ this.lastNotifiedValue = "";
3122
+ this.lastTrackedValue = "";
3123
+ this.lastAnnouncedSuggestion = "";
3124
+ this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
3125
+ if (this.srStatusEl) {
3126
+ this.srStatusEl.textContent = "";
3127
+ }
3128
+ this.clearGhost();
3129
+ }
2875
3130
  onNativeValueSet(_strVal) {
2876
- if (this.options.disabled) return;
3131
+ if (this.options.disabled || this.isComposing || this.isPasswordInput()) return;
2877
3132
  this.updateSuggestion();
2878
3133
  }
2879
3134
  onDisabledChange(disabled) {
2880
- if (disabled) {
2881
- if (this.ghost) this.ghost.textContent = "";
3135
+ if (disabled || this.isPasswordInput()) {
3136
+ this.clearGhost();
2882
3137
  } else {
2883
3138
  this.updateSuggestion();
2884
3139
  }
@@ -2894,16 +3149,26 @@ var __WulfIIFE = (() => {
2894
3149
  }
2895
3150
  this.cutTimerId = window.setTimeout(() => {
2896
3151
  this.cutTimerId = null;
2897
- if (this.isDestroyed || this.options.disabled) return;
3152
+ if (this.isDestroyed || this.options.disabled || this.isPasswordInput()) return;
2898
3153
  this.updateSuggestion();
2899
3154
  }, 0);
2900
3155
  };
2901
- this.input.addEventListener("input", this.handleInput);
2902
- this.input.addEventListener("keydown", this.handleKeyDown);
2903
- this.input.addEventListener("blur", this.handleBlur);
2904
- this.input.addEventListener("focus", this.handleFocus);
2905
- this.input.addEventListener("scroll", this.onScroll);
2906
- this.input.addEventListener("cut", this.onCutHandler);
3156
+ const { signal } = this.abortController;
3157
+ this.input.addEventListener("input", this.handleInput, { signal });
3158
+ this.input.addEventListener("keydown", this.handleKeyDown, { signal });
3159
+ this.input.addEventListener("blur", this.handleBlur, { signal });
3160
+ this.input.addEventListener("focus", this.handleFocus, { signal });
3161
+ this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
3162
+ this.input.addEventListener("cut", this.onCutHandler, { signal });
3163
+ this.input.addEventListener("compositionstart", () => {
3164
+ this.isComposing = true;
3165
+ }, { signal });
3166
+ this.input.addEventListener("compositionend", () => {
3167
+ this.isComposing = false;
3168
+ if (!this.isDestroyed && !this.options.disabled && !this.isPasswordInput()) {
3169
+ this.handleInput();
3170
+ }
3171
+ }, { signal });
2907
3172
  if (this.input.form) {
2908
3173
  this.onFormResetHandler = () => {
2909
3174
  if (this.resetTimerId !== null) {
@@ -2911,47 +3176,112 @@ var __WulfIIFE = (() => {
2911
3176
  }
2912
3177
  this.resetTimerId = window.setTimeout(() => {
2913
3178
  this.resetTimerId = null;
2914
- if (this.isDestroyed || this.options.disabled) return;
3179
+ if (this.isDestroyed || this.options.disabled || this.isPasswordInput()) return;
2915
3180
  this.updateSuggestion();
2916
3181
  }, 0);
2917
3182
  };
2918
- this.input.form.addEventListener("reset", this.onFormResetHandler);
3183
+ this.input.form.addEventListener("reset", this.onFormResetHandler, { signal });
2919
3184
  }
2920
3185
  }
2921
- updateSuggestion() {
2922
- if (this.options.disabled) {
2923
- if (this.ghost) this.ghost.textContent = "";
3186
+ ensureSrStatusEl() {
3187
+ if (this.srStatusEl && this.wrapper.contains(this.srStatusEl)) {
3188
+ return this.srStatusEl;
3189
+ }
3190
+ const doc = this.input.ownerDocument || (typeof document !== "undefined" ? document : null);
3191
+ if (!doc) return null;
3192
+ const status = doc.createElement("span");
3193
+ status.className = "wulf-mask-sr-status";
3194
+ status.setAttribute("aria-live", "polite");
3195
+ status.setAttribute("aria-atomic", "true");
3196
+ this.wrapper.appendChild(status);
3197
+ this.srStatusEl = status;
3198
+ return status;
3199
+ }
3200
+ scheduleSuggestionAnnouncement(immediate = false) {
3201
+ if (this.srAnnounceTimerId !== null) {
3202
+ clearTimeout(this.srAnnounceTimerId);
3203
+ this.srAnnounceTimerId = null;
3204
+ }
3205
+ if (!this.options.setAriaAutocomplete || !this.isFocused || this.isDestroyed || this.isPasswordInput()) {
3206
+ return;
3207
+ }
3208
+ const suggestion = this.currentSuggestion;
3209
+ if (!suggestion.remaining || suggestion.isHintOnly) {
3210
+ this.lastAnnouncedSuggestion = "";
3211
+ if (this.srStatusEl) {
3212
+ this.srStatusEl.textContent = "";
3213
+ }
3214
+ return;
3215
+ }
3216
+ const textToAnnounce = suggestion.full;
3217
+ if (textToAnnounce === this.lastAnnouncedSuggestion && !immediate) {
3218
+ return;
3219
+ }
3220
+ const run = () => {
3221
+ this.srAnnounceTimerId = null;
3222
+ if (this.isDestroyed || !this.isFocused || this.isPasswordInput()) return;
3223
+ this.lastAnnouncedSuggestion = textToAnnounce;
3224
+ const doc = this.input.ownerDocument || (typeof document !== "undefined" ? document : null);
3225
+ const docWithAriaNotify = doc;
3226
+ if (docWithAriaNotify && typeof docWithAriaNotify.ariaNotify === "function") {
3227
+ try {
3228
+ docWithAriaNotify.ariaNotify(textToAnnounce, { priority: "normal" });
3229
+ return;
3230
+ } catch {
3231
+ }
3232
+ }
3233
+ const statusEl = this.ensureSrStatusEl();
3234
+ if (statusEl) {
3235
+ statusEl.textContent = statusEl.textContent === textToAnnounce ? `${textToAnnounce}\xA0` : textToAnnounce;
3236
+ }
3237
+ };
3238
+ if (immediate) {
3239
+ run();
3240
+ } else {
3241
+ this.srAnnounceTimerId = window.setTimeout(run, 250);
3242
+ }
3243
+ }
3244
+ updateSuggestion(announceOptions) {
3245
+ if (this.options.disabled || this.isPasswordInput()) {
3246
+ this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
3247
+ this.clearGhost();
2924
3248
  return;
2925
3249
  }
2926
3250
  const val = this.input.value;
2927
3251
  this.currentSuggestion = this.engine.getSuggestion(val, this.currentSuggestionIndex);
2928
3252
  if (!this.ghost) return;
2929
3253
  if (this.shouldHideGhostForPlaceholder(val.length === 0)) {
2930
- this.ghost.textContent = "";
3254
+ this.clearGhost();
2931
3255
  } else if (this.currentSuggestion.remaining) {
2932
- this.ghost.textContent = "";
2933
- const spanTyped = document.createElement("span");
3256
+ const doc = this.input.ownerDocument || document;
3257
+ const spanTyped = doc.createElement("span");
2934
3258
  spanTyped.className = "mask-ghost-typed";
2935
3259
  spanTyped.textContent = val;
2936
- const spanRemaining = document.createElement("span");
3260
+ const spanRemaining = doc.createElement("span");
2937
3261
  spanRemaining.className = "mask-ghost-remaining";
2938
3262
  spanRemaining.textContent = this.currentSuggestion.remaining;
2939
- this.ghost.appendChild(spanTyped);
2940
- this.ghost.appendChild(spanRemaining);
3263
+ this.setGhostContent(spanTyped, spanRemaining);
2941
3264
  } else {
2942
- this.ghost.textContent = "";
3265
+ this.clearGhost();
2943
3266
  }
2944
3267
  this.ghost.scrollLeft = this.input.scrollLeft;
3268
+ if (announceOptions?.announce) {
3269
+ this.scheduleSuggestionAnnouncement(Boolean(announceOptions.immediate));
3270
+ }
2945
3271
  const detail = this.getDetail();
2946
3272
  if (this.options.onInput) {
2947
3273
  this.options.onInput(detail);
2948
3274
  }
2949
3275
  this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: true, detail }));
2950
- this.dispatchNativeInput();
3276
+ if (val !== this.lastNotifiedValue) {
3277
+ this.lastNotifiedValue = val;
3278
+ this.dispatchNativeInput();
3279
+ }
2951
3280
  }
2952
- handleInput() {
3281
+ handleInput(e) {
2953
3282
  if (this.isDispatchingNativeInput) return;
2954
- if (this.options.disabled) return;
3283
+ if (this.options.disabled || this.isPasswordInput()) return;
3284
+ if (this.isComposing || e && "isComposing" in e && e.isComposing) return;
2955
3285
  if (this.options.autoLowercase) {
2956
3286
  const start = this.input.selectionStart ?? 0;
2957
3287
  const end = this.input.selectionEnd ?? start;
@@ -2962,10 +3292,11 @@ var __WulfIIFE = (() => {
2962
3292
  }
2963
3293
  }
2964
3294
  this.currentSuggestionIndex = 0;
2965
- this.updateSuggestion();
3295
+ this.updateSuggestion({ announce: true, immediate: false });
2966
3296
  }
2967
3297
  handleKeyDown(e) {
2968
- if (this.options.disabled) return;
3298
+ if (this.options.disabled || this.isPasswordInput() || isImeComposing(e)) return;
3299
+ if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return;
2969
3300
  const hasSuggestion = Boolean(this.currentSuggestion.remaining) && !this.currentSuggestion.isHintOnly;
2970
3301
  const cursor = this.input.selectionStart ?? 0;
2971
3302
  const isAtEnd = cursor === this.input.value.length;
@@ -2974,13 +3305,13 @@ var __WulfIIFE = (() => {
2974
3305
  if (e.key === "ArrowDown") {
2975
3306
  e.preventDefault();
2976
3307
  this.currentSuggestionIndex++;
2977
- this.updateSuggestion();
3308
+ this.updateSuggestion({ announce: true, immediate: true });
2978
3309
  return;
2979
3310
  }
2980
3311
  if (e.key === "ArrowUp") {
2981
3312
  e.preventDefault();
2982
3313
  this.currentSuggestionIndex--;
2983
- this.updateSuggestion();
3314
+ this.updateSuggestion({ announce: true, immediate: true });
2984
3315
  return;
2985
3316
  }
2986
3317
  }
@@ -3047,6 +3378,20 @@ var __WulfIIFE = (() => {
3047
3378
  }
3048
3379
  handleBlur() {
3049
3380
  this.wrapper.classList.remove("is-focused");
3381
+ if (this.srAnnounceTimerId !== null) {
3382
+ clearTimeout(this.srAnnounceTimerId);
3383
+ this.srAnnounceTimerId = null;
3384
+ }
3385
+ this.lastAnnouncedSuggestion = "";
3386
+ if (this.srStatusEl) {
3387
+ this.srStatusEl.textContent = "";
3388
+ }
3389
+ if (this.isPasswordInput()) {
3390
+ this.lastNotifiedValue = "";
3391
+ this.lastTrackedValue = "";
3392
+ this.clearGhost();
3393
+ return;
3394
+ }
3050
3395
  this.updateSuggestion();
3051
3396
  const detail = this.getDetail();
3052
3397
  if (this.options.onChange) {
@@ -3092,18 +3437,31 @@ var __WulfIIFE = (() => {
3092
3437
  clearTimeout(this.resetTimerId);
3093
3438
  this.resetTimerId = null;
3094
3439
  }
3095
- this.input.removeEventListener("input", this.handleInput);
3096
- this.input.removeEventListener("keydown", this.handleKeyDown);
3097
- this.input.removeEventListener("blur", this.handleBlur);
3098
- this.input.removeEventListener("focus", this.handleFocus);
3099
- this.input.removeEventListener("scroll", this.onScroll);
3100
- this.input.removeEventListener("cut", this.onCutHandler);
3101
- if (this.input.form && this.onFormResetHandler) {
3102
- this.input.form.removeEventListener("reset", this.onFormResetHandler);
3440
+ if (this.srAnnounceTimerId !== null) {
3441
+ clearTimeout(this.srAnnounceTimerId);
3442
+ this.srAnnounceTimerId = null;
3443
+ }
3444
+ if (this.srStatusEl) {
3445
+ this.srStatusEl.remove();
3446
+ this.srStatusEl = null;
3447
+ }
3448
+ this.lastNotifiedValue = "";
3449
+ this.lastAnnouncedSuggestion = "";
3450
+ if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "email") {
3451
+ this.input.removeAttribute("inputmode");
3103
3452
  }
3104
3453
  if (this.wasAriaAutocompleteSet && this.input.getAttribute("aria-autocomplete") === "inline") {
3105
3454
  this.input.removeAttribute("aria-autocomplete");
3106
3455
  }
3456
+ if (this.wasAutocorrectSet && this.input.getAttribute("autocorrect") === "off") {
3457
+ this.input.removeAttribute("autocorrect");
3458
+ }
3459
+ if (this.wasAutocapitalizeSet && this.input.getAttribute("autocapitalize") === "none") {
3460
+ this.input.removeAttribute("autocapitalize");
3461
+ }
3462
+ if (this.wasSpellcheckSet && this.input.getAttribute("spellcheck") === "false") {
3463
+ this.input.removeAttribute("spellcheck");
3464
+ }
3107
3465
  super.destroy();
3108
3466
  }
3109
3467
  };
@@ -3120,14 +3478,12 @@ var __WulfIIFE = (() => {
3120
3478
  EmailEngine,
3121
3479
  InputEmailMask
3122
3480
  };
3123
- if (typeof window !== "undefined") {
3124
- const win = window;
3125
- const wulfNamespace = win.Wulf || {};
3126
- win.Wulf = wulfNamespace;
3481
+ var wulfNamespace = getSafeWulfNamespace();
3482
+ if (wulfNamespace) {
3127
3483
  wulfNamespace.Mask = Mask;
3128
3484
  }
3129
3485
  var index_default = InputMask;
3130
3486
  return __toCommonJS(index_exports);
3131
3487
  })();
3132
- if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.prototype.hasOwnProperty.call(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
3488
+ if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.hasOwn(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && __w[k] === undefined) { try { Object.defineProperty(__w, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { __w[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
3133
3489
  //# sourceMappingURL=mask.global.js.map