wulf.js 2.0.0 → 2.1.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.
- package/README.md +240 -4
- package/changelog.md +30 -0
- package/dist/focus-trap.esm.js +22 -7
- package/dist/focus-trap.esm.js.map +2 -2
- package/dist/focus-trap.global.js +22 -7
- package/dist/focus-trap.global.js.map +2 -2
- package/dist/focus-trap.global.min.js +2 -2
- package/dist/focus-trap.global.min.js.map +3 -3
- package/dist/index.esm.js +2950 -296
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2950 -296
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +2 -2
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.css +1 -1
- package/dist/mask.css.map +2 -2
- package/dist/mask.esm.js +2826 -171
- package/dist/mask.esm.js.map +4 -4
- package/dist/mask.global.js +2816 -161
- package/dist/mask.global.js.map +4 -4
- package/dist/mask.global.min.js +2 -2
- package/dist/mask.global.min.js.map +4 -4
- package/dist/mask.layered.css +1 -1
- package/dist/mask.layered.css.map +2 -2
- package/dist/masonry.esm.js +22 -7
- package/dist/masonry.esm.js.map +2 -2
- package/dist/masonry.global.js +22 -7
- package/dist/masonry.global.js.map +2 -2
- package/dist/masonry.global.min.js +2 -2
- package/dist/masonry.global.min.js.map +3 -3
- package/dist/scroll.esm.js +26 -11
- package/dist/scroll.esm.js.map +2 -2
- package/dist/scroll.global.js +26 -11
- package/dist/scroll.global.js.map +2 -2
- package/dist/scroll.global.min.js +2 -2
- package/dist/scroll.global.min.js.map +3 -3
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +25 -7
- package/dist/toast.esm.js.map +2 -2
- package/dist/toast.global.js +25 -7
- package/dist/toast.global.js.map +2 -2
- package/dist/toast.global.min.js +2 -2
- package/dist/toast.global.min.js.map +3 -3
- package/dist/toast.layered.css +1 -1
- package/dist/toast.layered.css.map +2 -2
- package/dist/types/common/AuditableComponent.d.ts +3 -3
- package/dist/types/mask/AmountEngine.d.ts +8 -0
- package/dist/types/mask/BaseInputMask.d.ts +18 -0
- package/dist/types/mask/DateUTCEngine.d.ts +187 -0
- package/dist/types/mask/InputAmountMask.d.ts +5 -0
- package/dist/types/mask/InputDateUTCMask.d.ts +110 -0
- package/dist/types/mask/InputEmailMask.d.ts +7 -0
- package/dist/types/mask/InputMask.d.ts +7 -5
- package/dist/types/mask/MaskEngine.d.ts +39 -7
- package/dist/types/mask/index.d.ts +12 -6
- package/dist/types/mask/paste.d.ts +18 -0
- package/dist/types/mask/types.d.ts +27 -2
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -24,9 +24,12 @@ var __WulfIIFE = (() => {
|
|
|
24
24
|
AmountEngine: () => AmountEngine,
|
|
25
25
|
AuditableComponent: () => AuditableComponent,
|
|
26
26
|
BaseInputMask: () => BaseInputMask,
|
|
27
|
+
DATE_UTC_PRESETS: () => DATE_UTC_PRESETS,
|
|
28
|
+
DateUTCEngine: () => DateUTCEngine,
|
|
27
29
|
EmailEngine: () => EmailEngine,
|
|
28
30
|
FocusTrap: () => focus_trap_exports,
|
|
29
31
|
InputAmountMask: () => InputAmountMask,
|
|
32
|
+
InputDateUTCMask: () => InputDateUTCMask,
|
|
30
33
|
InputEmailMask: () => InputEmailMask,
|
|
31
34
|
InputMask: () => InputMask,
|
|
32
35
|
LayoutEngine: () => LayoutEngine,
|
|
@@ -55,9 +58,10 @@ var __WulfIIFE = (() => {
|
|
|
55
58
|
isImeComposing: () => isImeComposing,
|
|
56
59
|
parseCssDurationMs: () => parseCssDurationMs,
|
|
57
60
|
prefersReducedMotion: () => prefersReducedMotion,
|
|
58
|
-
resolveMaskConstructorArgs: () => resolveMaskConstructorArgs,
|
|
59
61
|
safeCssEscape: () => safeCssEscape,
|
|
60
62
|
safeMove: () => safeMove,
|
|
63
|
+
sanitizePastedText: () => sanitizePastedText,
|
|
64
|
+
stripBidiAndInvisibles: () => stripBidiAndInvisibles,
|
|
61
65
|
waitForAnimations: () => waitForAnimations
|
|
62
66
|
});
|
|
63
67
|
|
|
@@ -66,8 +70,11 @@ var __WulfIIFE = (() => {
|
|
|
66
70
|
__export(mask_exports, {
|
|
67
71
|
AmountEngine: () => AmountEngine,
|
|
68
72
|
BaseInputMask: () => BaseInputMask,
|
|
73
|
+
DATE_UTC_PRESETS: () => DATE_UTC_PRESETS,
|
|
74
|
+
DateUTCEngine: () => DateUTCEngine,
|
|
69
75
|
EmailEngine: () => EmailEngine,
|
|
70
76
|
InputAmountMask: () => InputAmountMask,
|
|
77
|
+
InputDateUTCMask: () => InputDateUTCMask,
|
|
71
78
|
InputEmailMask: () => InputEmailMask,
|
|
72
79
|
InputMask: () => InputMask,
|
|
73
80
|
Mask: () => Mask,
|
|
@@ -75,7 +82,8 @@ var __WulfIIFE = (() => {
|
|
|
75
82
|
MaskHistory: () => MaskHistory,
|
|
76
83
|
MaskKeyboard: () => MaskKeyboard,
|
|
77
84
|
default: () => mask_default,
|
|
78
|
-
|
|
85
|
+
sanitizePastedText: () => sanitizePastedText,
|
|
86
|
+
stripBidiAndInvisibles: () => stripBidiAndInvisibles
|
|
79
87
|
});
|
|
80
88
|
|
|
81
89
|
// src/common/dom.ts
|
|
@@ -206,27 +214,52 @@ var __WulfIIFE = (() => {
|
|
|
206
214
|
return warnings;
|
|
207
215
|
}
|
|
208
216
|
/**
|
|
209
|
-
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
|
|
210
|
-
* pointe vers des éléments réellement présents dans le document.
|
|
217
|
+
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
|
|
218
|
+
* pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
|
|
211
219
|
*/
|
|
212
|
-
checkAriaIdReferences(element, attrName, warnings) {
|
|
220
|
+
checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
|
|
213
221
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
214
222
|
if (!rawValue) return false;
|
|
215
223
|
const doc = element.ownerDocument || document;
|
|
216
224
|
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
217
225
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
218
|
-
const
|
|
219
|
-
(id) =>
|
|
226
|
+
const targets = ids.map(
|
|
227
|
+
(id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
|
|
220
228
|
);
|
|
221
|
-
|
|
229
|
+
const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
|
|
230
|
+
if (!allFound) {
|
|
222
231
|
warnings.push(
|
|
223
232
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
224
233
|
);
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (requireNonEmptyText) {
|
|
237
|
+
const hasNonEmptyText = targets.some((el) => {
|
|
238
|
+
if (!el) return false;
|
|
239
|
+
const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
|
|
240
|
+
return text.length > 0;
|
|
241
|
+
});
|
|
242
|
+
if (!hasNonEmptyText) {
|
|
243
|
+
warnings.push(
|
|
244
|
+
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
|
|
245
|
+
);
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
225
248
|
}
|
|
226
|
-
return
|
|
249
|
+
return true;
|
|
227
250
|
}
|
|
228
251
|
};
|
|
229
252
|
|
|
253
|
+
// src/mask/paste.ts
|
|
254
|
+
var MAX_PASTE_LENGTH = 4096;
|
|
255
|
+
function stripBidiAndInvisibles(raw, maxLength = MAX_PASTE_LENGTH) {
|
|
256
|
+
const safeLimit = Math.max(0, maxLength);
|
|
257
|
+
return String(raw ?? "").slice(0, safeLimit).replace(/[\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
|
|
258
|
+
}
|
|
259
|
+
function sanitizePastedText(raw, maxLength = MAX_PASTE_LENGTH) {
|
|
260
|
+
return stripBidiAndInvisibles(raw, maxLength).replace(/[\u00A0\u202F\u2007]/g, " ").replace(/[\u2013\u2014\u2212]/g, "-").trim();
|
|
261
|
+
}
|
|
262
|
+
|
|
230
263
|
// src/mask/BaseInputMask.ts
|
|
231
264
|
var VALID_ALIGNS = /* @__PURE__ */ new Set(["left", "right", "center"]);
|
|
232
265
|
function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
@@ -264,6 +297,7 @@ var __WulfIIFE = (() => {
|
|
|
264
297
|
};
|
|
265
298
|
onFormResetHandler;
|
|
266
299
|
mutationObserver = null;
|
|
300
|
+
resizeObserver = null;
|
|
267
301
|
focusSelectTimerId = null;
|
|
268
302
|
abortController = new AbortController();
|
|
269
303
|
constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
@@ -279,7 +313,7 @@ var __WulfIIFE = (() => {
|
|
|
279
313
|
if (!effectiveWrapper && shouldCreateWrapper) {
|
|
280
314
|
const doc = this.input.ownerDocument || document;
|
|
281
315
|
const span = doc.createElement("span");
|
|
282
|
-
span.className = "wulf-mask-wrapper";
|
|
316
|
+
span.className = "wulf-mask-wrapper wulf-mask-wrapper--auto";
|
|
283
317
|
if (this.input.parentNode) {
|
|
284
318
|
this.input.parentNode.insertBefore(span, this.input);
|
|
285
319
|
}
|
|
@@ -309,21 +343,24 @@ var __WulfIIFE = (() => {
|
|
|
309
343
|
const dataDisabled = this.hasAttr("data-disabled");
|
|
310
344
|
const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
|
|
311
345
|
const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
|
|
346
|
+
const dataSensitive = this.getAttr("data-mask-sensitive") === "true";
|
|
312
347
|
const rawDataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
|
|
313
348
|
const dataAlign = rawDataAlign && VALID_ALIGNS.has(rawDataAlign) ? rawDataAlign : null;
|
|
314
349
|
this.hadInitialDataAlign = this.wrapper.hasAttribute("data-align");
|
|
315
350
|
const dataAudit = this.getAttr("data-mask-audit");
|
|
316
|
-
const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
|
|
351
|
+
const { disabled: optDisabled, align: optAlign, sensitive: optSensitive, ...otherOptions } = options;
|
|
317
352
|
const validOptAlign = optAlign && VALID_ALIGNS.has(optAlign) ? optAlign : void 0;
|
|
318
353
|
const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
|
|
319
354
|
const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
|
|
320
|
-
const
|
|
355
|
+
const resolvedSensitive = Boolean(optSensitive ?? dataSensitive);
|
|
356
|
+
const isSensitive = this.isPasswordInput() || resolvedSensitive;
|
|
321
357
|
this.options = {
|
|
322
358
|
...otherOptions,
|
|
323
359
|
createWrapper: shouldCreateWrapper,
|
|
324
360
|
showMaskOnFocus: options.showMaskOnFocus ?? dataFocusOnly ?? false,
|
|
325
361
|
selectAllOnFocus: options.selectAllOnFocus ?? dataSelectAll ?? false,
|
|
326
|
-
copyRaw:
|
|
362
|
+
copyRaw: isSensitive ? false : options.copyRaw ?? dataCopyRaw ?? false,
|
|
363
|
+
sensitive: resolvedSensitive,
|
|
327
364
|
disabled: resolvedDisabled,
|
|
328
365
|
align: validOptAlign ?? (dataAlign || void 0),
|
|
329
366
|
emitNativeInput: options.emitNativeInput ?? true,
|
|
@@ -378,7 +415,7 @@ var __WulfIIFE = (() => {
|
|
|
378
415
|
this.input.addEventListener("blur", this.onBaseBlur, { signal });
|
|
379
416
|
}
|
|
380
417
|
onBaseCopy = (e) => {
|
|
381
|
-
if (!this.options.copyRaw || this.options.disabled || this.
|
|
418
|
+
if (!this.options.copyRaw || this.options.disabled || this.isSensitiveField()) return;
|
|
382
419
|
const start = this.input.selectionStart ?? 0;
|
|
383
420
|
const end = this.input.selectionEnd ?? start;
|
|
384
421
|
let textToCopy = "";
|
|
@@ -398,6 +435,30 @@ var __WulfIIFE = (() => {
|
|
|
398
435
|
extractRawSnippet(snippet) {
|
|
399
436
|
return snippet;
|
|
400
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Extrait de manière compatible le texte brut du presse-papier lors d'un événement paste.
|
|
440
|
+
*/
|
|
441
|
+
getClipboardPlainText(e) {
|
|
442
|
+
if (!e.clipboardData) return "";
|
|
443
|
+
return e.clipboardData.getData("text") || e.clipboardData.getData("text/plain") || "";
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Applique l'hygiène Unicode O(N) puis le hook optionnel transformPaste de façon sécurisée et bornée.
|
|
447
|
+
*/
|
|
448
|
+
preparePastedText(rawClipboard, maxLength = MAX_PASTE_LENGTH) {
|
|
449
|
+
const sanitized = sanitizePastedText(rawClipboard, maxLength);
|
|
450
|
+
if (typeof this.options.transformPaste !== "function") {
|
|
451
|
+
return sanitized;
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
454
|
+
const transformed = this.options.transformPaste(sanitized);
|
|
455
|
+
if (typeof transformed === "string") {
|
|
456
|
+
return sanitizePastedText(transformed, maxLength);
|
|
457
|
+
}
|
|
458
|
+
} catch {
|
|
459
|
+
}
|
|
460
|
+
return sanitized;
|
|
461
|
+
}
|
|
401
462
|
onBaseFocus = () => {
|
|
402
463
|
this.isFocused = true;
|
|
403
464
|
if (this.options.selectAllOnFocus && this.input.value.length > 0) {
|
|
@@ -406,7 +467,7 @@ var __WulfIIFE = (() => {
|
|
|
406
467
|
}
|
|
407
468
|
this.focusSelectTimerId = window.setTimeout(() => {
|
|
408
469
|
this.focusSelectTimerId = null;
|
|
409
|
-
if (!this.isDestroyed &&
|
|
470
|
+
if (!this.isDestroyed && getDeepActiveElement(this.input.ownerDocument) === this.input) {
|
|
410
471
|
this.input.select();
|
|
411
472
|
}
|
|
412
473
|
}, 0);
|
|
@@ -414,7 +475,7 @@ var __WulfIIFE = (() => {
|
|
|
414
475
|
};
|
|
415
476
|
onBaseBlur = () => {
|
|
416
477
|
this.isFocused = false;
|
|
417
|
-
if (this.
|
|
478
|
+
if (this.isSensitiveField()) {
|
|
418
479
|
this.lastTrackedValue = "";
|
|
419
480
|
this.clearGhost();
|
|
420
481
|
this.wrapper.removeAttribute("data-mask");
|
|
@@ -441,11 +502,14 @@ var __WulfIIFE = (() => {
|
|
|
441
502
|
"data-mask-strict",
|
|
442
503
|
"data-mask-select-on-focus",
|
|
443
504
|
"data-mask-copy-raw",
|
|
505
|
+
"data-mask-sensitive",
|
|
444
506
|
"data-mask-pad-decimals",
|
|
445
507
|
"data-mask-auto-lowercase",
|
|
446
508
|
"data-mask-cycle-suggestions",
|
|
447
509
|
"data-mask-default-tld",
|
|
448
510
|
"data-mask-tlds",
|
|
511
|
+
"data-mask-format",
|
|
512
|
+
"data-mask-utc-indicator",
|
|
449
513
|
"data-disabled",
|
|
450
514
|
"data-mask-align",
|
|
451
515
|
"data-align",
|
|
@@ -464,6 +528,12 @@ var __WulfIIFE = (() => {
|
|
|
464
528
|
isPasswordInput() {
|
|
465
529
|
return (this.input.type || "").toLowerCase() === "password";
|
|
466
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* Indique si le champ relève du sanctuaire confidentiel (type="password" ou option sensitive: true).
|
|
533
|
+
*/
|
|
534
|
+
isSensitiveField() {
|
|
535
|
+
return this.isPasswordInput() || Boolean(this.options.sensitive);
|
|
536
|
+
}
|
|
467
537
|
/**
|
|
468
538
|
* Calcule une empreinte non réversible pour détecter les changements sans conserver de secret en RAM.
|
|
469
539
|
*/
|
|
@@ -518,9 +588,19 @@ var __WulfIIFE = (() => {
|
|
|
518
588
|
} else if (attrName === "data-mask-select-on-focus") {
|
|
519
589
|
this.options.selectAllOnFocus = this.getAttr("data-mask-select-on-focus") === "true";
|
|
520
590
|
} else if (attrName === "data-mask-copy-raw") {
|
|
521
|
-
this.options.copyRaw = this.
|
|
591
|
+
this.options.copyRaw = this.isSensitiveField() ? false : this.getAttr("data-mask-copy-raw") === "true";
|
|
592
|
+
} else if (attrName === "data-mask-sensitive") {
|
|
593
|
+
const nextSensitive = this.getAttr("data-mask-sensitive") === "true";
|
|
594
|
+
this.options.sensitive = nextSensitive;
|
|
595
|
+
if (this.isSensitiveField()) {
|
|
596
|
+
this.options.copyRaw = false;
|
|
597
|
+
this.lastTrackedValue = "";
|
|
598
|
+
this.clearGhost();
|
|
599
|
+
this.wrapper.removeAttribute("data-mask");
|
|
600
|
+
this.onPasswordModeDetected();
|
|
601
|
+
}
|
|
522
602
|
} else if (attrName === "type") {
|
|
523
|
-
if (this.
|
|
603
|
+
if (this.isSensitiveField()) {
|
|
524
604
|
this.options.copyRaw = false;
|
|
525
605
|
this.lastTrackedValue = "";
|
|
526
606
|
this.clearGhost();
|
|
@@ -571,6 +651,24 @@ var __WulfIIFE = (() => {
|
|
|
571
651
|
this.ghost.style.pointerEvents = "none";
|
|
572
652
|
}
|
|
573
653
|
this.syncGhostStyles();
|
|
654
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
655
|
+
this.resizeObserver?.disconnect();
|
|
656
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
657
|
+
if (!this.isDestroyed) {
|
|
658
|
+
this.syncGhostStyles();
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
this.resizeObserver.observe(this.input);
|
|
662
|
+
}
|
|
663
|
+
const docWithFonts = doc;
|
|
664
|
+
if (docWithFonts.fonts?.ready && typeof docWithFonts.fonts.ready.then === "function") {
|
|
665
|
+
docWithFonts.fonts.ready.then(() => {
|
|
666
|
+
if (!this.isDestroyed) {
|
|
667
|
+
this.syncGhostStyles();
|
|
668
|
+
}
|
|
669
|
+
}).catch(() => {
|
|
670
|
+
});
|
|
671
|
+
}
|
|
574
672
|
}
|
|
575
673
|
/**
|
|
576
674
|
* Met à jour atomiquement le contenu du conteneur fantôme et synchronise .has-visible-ghost.
|
|
@@ -607,6 +705,10 @@ var __WulfIIFE = (() => {
|
|
|
607
705
|
this.ghost.style.fontWeight = style.fontWeight;
|
|
608
706
|
this.ghost.style.fontStyle = style.fontStyle;
|
|
609
707
|
this.ghost.style.letterSpacing = style.letterSpacing;
|
|
708
|
+
this.ghost.style.wordSpacing = style.wordSpacing;
|
|
709
|
+
this.ghost.style.textIndent = style.textIndent;
|
|
710
|
+
this.ghost.style.fontKerning = style.fontKerning;
|
|
711
|
+
this.ghost.style.fontVariantNumeric = style.fontVariantNumeric;
|
|
610
712
|
this.ghost.style.lineHeight = style.lineHeight;
|
|
611
713
|
this.ghost.style.paddingTop = style.paddingTop;
|
|
612
714
|
this.ghost.style.paddingBottom = style.paddingBottom;
|
|
@@ -658,11 +760,12 @@ var __WulfIIFE = (() => {
|
|
|
658
760
|
if (this.options.emitNativeInput === false) return;
|
|
659
761
|
this.isDispatchingNativeInput = true;
|
|
660
762
|
try {
|
|
763
|
+
const isSensitive = this.isSensitiveField();
|
|
661
764
|
const tracker = this.input._valueTracker;
|
|
662
|
-
if (!
|
|
765
|
+
if (!isSensitive && tracker && typeof tracker.setValue === "function") {
|
|
663
766
|
tracker.setValue(this.lastTrackedValue);
|
|
664
767
|
}
|
|
665
|
-
this.lastTrackedValue =
|
|
768
|
+
this.lastTrackedValue = isSensitive ? "" : this.input.value;
|
|
666
769
|
this.input.dispatchEvent(new Event("input", { bubbles: true, cancelable: false }));
|
|
667
770
|
} finally {
|
|
668
771
|
this.isDispatchingNativeInput = false;
|
|
@@ -780,6 +883,37 @@ var __WulfIIFE = (() => {
|
|
|
780
883
|
getRawValue() {
|
|
781
884
|
return this.input.value;
|
|
782
885
|
}
|
|
886
|
+
/**
|
|
887
|
+
* Vérifie qu'un élément <label> possède un nom accessible non vide,
|
|
888
|
+
* en ignorant le texte éventuel des contrôles enfants (<input>, <select>, <textarea>, <button>).
|
|
889
|
+
*/
|
|
890
|
+
hasAccessibleLabelText(labelEl) {
|
|
891
|
+
if (!labelEl) return false;
|
|
892
|
+
const ariaLabel = labelEl.getAttribute("aria-label")?.trim();
|
|
893
|
+
if (ariaLabel) return true;
|
|
894
|
+
const collectText = (node) => {
|
|
895
|
+
if (node.nodeType === 3) {
|
|
896
|
+
return node.textContent || "";
|
|
897
|
+
}
|
|
898
|
+
if (node.nodeType === 1) {
|
|
899
|
+
const el = node;
|
|
900
|
+
const tag = el.tagName;
|
|
901
|
+
if (tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA" || tag === "BUTTON") {
|
|
902
|
+
return "";
|
|
903
|
+
}
|
|
904
|
+
if (el.getAttribute("aria-hidden") === "true") {
|
|
905
|
+
return "";
|
|
906
|
+
}
|
|
907
|
+
let acc = "";
|
|
908
|
+
for (let i = 0; i < el.childNodes.length; i++) {
|
|
909
|
+
acc += collectText(el.childNodes[i]);
|
|
910
|
+
}
|
|
911
|
+
return acc;
|
|
912
|
+
}
|
|
913
|
+
return "";
|
|
914
|
+
};
|
|
915
|
+
return collectText(labelEl).trim().length > 0;
|
|
916
|
+
}
|
|
783
917
|
/**
|
|
784
918
|
* Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
|
|
785
919
|
* et retourne la liste des contraintes manquantes.
|
|
@@ -790,23 +924,39 @@ var __WulfIIFE = (() => {
|
|
|
790
924
|
const root = typeof this.input.getRootNode === "function" ? this.input.getRootNode() : doc;
|
|
791
925
|
const labelRoot = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : doc;
|
|
792
926
|
const ariaLabel = this.input.getAttribute("aria-label")?.trim();
|
|
793
|
-
const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
|
|
794
|
-
const
|
|
795
|
-
const
|
|
927
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings, true);
|
|
928
|
+
const wrappingLabel = this.input.closest("label");
|
|
929
|
+
const hasWrappingLabel = this.hasAccessibleLabelText(wrappingLabel);
|
|
930
|
+
const hasNativeLabels = Boolean(
|
|
931
|
+
this.input.labels && Array.from(this.input.labels).some((lbl) => this.hasAccessibleLabelText(lbl))
|
|
932
|
+
);
|
|
796
933
|
let hasExplicitLabelFor = false;
|
|
797
934
|
if (this.input.id) {
|
|
798
935
|
try {
|
|
799
|
-
|
|
936
|
+
const explicitLabel = labelRoot.querySelector(`label[for="${safeCssEscape(this.input.id)}"]`);
|
|
937
|
+
hasExplicitLabelFor = this.hasAccessibleLabelText(explicitLabel);
|
|
800
938
|
} catch {
|
|
801
939
|
hasExplicitLabelFor = false;
|
|
802
940
|
}
|
|
803
941
|
}
|
|
804
942
|
if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
|
|
805
943
|
warnings.push(
|
|
806
|
-
`\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
|
|
944
|
+
`\xC9tiquetage accessible manquant : associez un <label for="id"> non vide (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
|
|
807
945
|
);
|
|
808
946
|
}
|
|
809
|
-
this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
|
|
947
|
+
this.checkAriaIdReferences(this.input, "aria-describedby", warnings, true);
|
|
948
|
+
if (this.input.hasAttribute("aria-errormessage")) {
|
|
949
|
+
this.checkAriaIdReferences(this.input, "aria-errormessage", warnings, true);
|
|
950
|
+
}
|
|
951
|
+
const rawTabIndex = this.input.getAttribute("tabindex");
|
|
952
|
+
if (rawTabIndex !== null) {
|
|
953
|
+
const parsedTabIndex = Number.parseInt(rawTabIndex, 10);
|
|
954
|
+
if (Number.isFinite(parsedTabIndex) && parsedTabIndex > 0) {
|
|
955
|
+
warnings.push(
|
|
956
|
+
`Attribut tabindex="${rawTabIndex}" positif d\xE9tect\xE9 : \xE9vitez les tabindex > 0 qui perturbent l'ordre de tabulation naturel (WCAG 2.4.3).`
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
810
960
|
const extraWarnings = this.getSpecificAuditWarnings();
|
|
811
961
|
warnings.push(...extraWarnings);
|
|
812
962
|
return warnings;
|
|
@@ -845,6 +995,10 @@ var __WulfIIFE = (() => {
|
|
|
845
995
|
this.mutationObserver.disconnect();
|
|
846
996
|
this.mutationObserver = null;
|
|
847
997
|
}
|
|
998
|
+
if (this.resizeObserver) {
|
|
999
|
+
this.resizeObserver.disconnect();
|
|
1000
|
+
this.resizeObserver = null;
|
|
1001
|
+
}
|
|
848
1002
|
this.abortController.abort();
|
|
849
1003
|
this.lastTrackedValue = "";
|
|
850
1004
|
this.unhookValueProperty();
|
|
@@ -885,6 +1039,7 @@ var __WulfIIFE = (() => {
|
|
|
885
1039
|
};
|
|
886
1040
|
|
|
887
1041
|
// src/mask/MaskEngine.ts
|
|
1042
|
+
var SEGMENT_SEPARATORS = /* @__PURE__ */ new Set(["/", "-", ".", ":"]);
|
|
888
1043
|
var DEFAULT_TOKENS = {
|
|
889
1044
|
"9": { pattern: /[0-9]/ },
|
|
890
1045
|
"a": { pattern: /[a-zA-Z]/ },
|
|
@@ -895,6 +1050,8 @@ var __WulfIIFE = (() => {
|
|
|
895
1050
|
var MaskEngine = class _MaskEngine {
|
|
896
1051
|
pattern;
|
|
897
1052
|
patterns = [];
|
|
1053
|
+
patternResolver = null;
|
|
1054
|
+
lastResolvedKey = "";
|
|
898
1055
|
subEngines = [];
|
|
899
1056
|
activeEngine = null;
|
|
900
1057
|
placeholderChar;
|
|
@@ -931,7 +1088,7 @@ var __WulfIIFE = (() => {
|
|
|
931
1088
|
* Fonction statique utilitaire permettant un formatage direct sans instanciation manuelle.
|
|
932
1089
|
*
|
|
933
1090
|
* @param value Valeur à formater (brute ou partiellement formatée)
|
|
934
|
-
* @param pattern Masque à appliquer (ex: "99 99 99 99 99"
|
|
1091
|
+
* @param pattern Masque à appliquer (ex: "99 99 99 99 99", tableau de masques ou résolveur dynamique)
|
|
935
1092
|
* @param options Options facultatives (placeholderChar, tokens, strict, autoLowercase)
|
|
936
1093
|
* @returns La valeur formatée selon le masque
|
|
937
1094
|
*/
|
|
@@ -941,17 +1098,69 @@ var __WulfIIFE = (() => {
|
|
|
941
1098
|
return engine.format(value ?? "");
|
|
942
1099
|
}
|
|
943
1100
|
/**
|
|
944
|
-
*
|
|
1101
|
+
* Indique si le gabarit repose sur une fonction résolveuse dynamique.
|
|
1102
|
+
*/
|
|
1103
|
+
isDynamicPattern() {
|
|
1104
|
+
return this.patternResolver !== null;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Résout et compile si besoin le gabarit dynamique pour la valeur fournie (avec mémoïsation).
|
|
1108
|
+
*/
|
|
1109
|
+
resolveForValue(input) {
|
|
1110
|
+
if (!this.patternResolver) return false;
|
|
1111
|
+
let resolved;
|
|
1112
|
+
try {
|
|
1113
|
+
resolved = this.patternResolver(String(input ?? "").slice(0, 4096));
|
|
1114
|
+
} catch {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
let normalized;
|
|
1118
|
+
let key;
|
|
1119
|
+
if (Array.isArray(resolved)) {
|
|
1120
|
+
normalized = resolved.slice(0, 32).map((p) => String(p ?? "").slice(0, 512));
|
|
1121
|
+
key = "A:" + normalized.join("\0");
|
|
1122
|
+
} else if (typeof resolved === "string") {
|
|
1123
|
+
normalized = resolved.slice(0, 512);
|
|
1124
|
+
key = "S:" + normalized;
|
|
1125
|
+
} else {
|
|
1126
|
+
return false;
|
|
1127
|
+
}
|
|
1128
|
+
if (key === this.lastResolvedKey) {
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
this.lastResolvedKey = key;
|
|
1132
|
+
this.compileStatic(normalized);
|
|
1133
|
+
return true;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Analyse le ou les gabarits (statiques ou résolus dynamiquement) et compile la liste des slots.
|
|
945
1137
|
*/
|
|
946
1138
|
compile(newPattern) {
|
|
1139
|
+
if (typeof newPattern === "function") {
|
|
1140
|
+
this.patternResolver = newPattern;
|
|
1141
|
+
this.lastResolvedKey = "";
|
|
1142
|
+
this.resolveForValue("");
|
|
1143
|
+
return this.slots;
|
|
1144
|
+
}
|
|
947
1145
|
if (newPattern !== void 0) {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1146
|
+
this.patternResolver = null;
|
|
1147
|
+
this.lastResolvedKey = "";
|
|
1148
|
+
return this.compileStatic(newPattern);
|
|
1149
|
+
}
|
|
1150
|
+
if (this.patternResolver) {
|
|
1151
|
+
this.lastResolvedKey = "";
|
|
1152
|
+
this.resolveForValue("");
|
|
1153
|
+
return this.slots;
|
|
1154
|
+
}
|
|
1155
|
+
return this.compileStatic(this.patterns.length > 0 ? this.patterns : this.pattern);
|
|
1156
|
+
}
|
|
1157
|
+
compileStatic(newPattern) {
|
|
1158
|
+
if (Array.isArray(newPattern)) {
|
|
1159
|
+
this.patterns = newPattern.slice(0, 32).map((p) => String(p ?? "").slice(0, 512));
|
|
1160
|
+
this.pattern = this.patterns[0] || "";
|
|
1161
|
+
} else {
|
|
1162
|
+
this.patterns = [];
|
|
1163
|
+
this.pattern = String(newPattern ?? "").slice(0, 512);
|
|
955
1164
|
}
|
|
956
1165
|
if (this.patterns.length > 0) {
|
|
957
1166
|
this.subEngines = this.patterns.map((p) => new _MaskEngine(p, {
|
|
@@ -983,14 +1192,15 @@ var __WulfIIFE = (() => {
|
|
|
983
1192
|
const token = !isEscaped && Object.hasOwn(this.tokens, char) ? this.tokens[char] : void 0;
|
|
984
1193
|
if (token) {
|
|
985
1194
|
isPrefixMode = false;
|
|
1195
|
+
const slotPlaceholder = token.placeholder ? Array.from(String(token.placeholder))[0] || this.placeholderChar : this.placeholderChar;
|
|
986
1196
|
this.slots.push({
|
|
987
1197
|
char,
|
|
988
1198
|
isStatic: false,
|
|
989
1199
|
isPrefix: false,
|
|
990
1200
|
token,
|
|
991
|
-
placeholder:
|
|
1201
|
+
placeholder: slotPlaceholder
|
|
992
1202
|
});
|
|
993
|
-
templateBuilder +=
|
|
1203
|
+
templateBuilder += slotPlaceholder;
|
|
994
1204
|
} else {
|
|
995
1205
|
this.slots.push({
|
|
996
1206
|
char,
|
|
@@ -1058,13 +1268,29 @@ var __WulfIIFE = (() => {
|
|
|
1058
1268
|
return this.activeEngine ? this.activeEngine.getFullMaskTemplate() : this.fullMaskTemplate;
|
|
1059
1269
|
}
|
|
1060
1270
|
/**
|
|
1061
|
-
* Nombre total de positions éditables
|
|
1271
|
+
* Nombre total de positions éditables du sous-moteur actif (pour isComplete et detail.totalSlots).
|
|
1062
1272
|
*/
|
|
1063
|
-
|
|
1273
|
+
getActiveEditableCount() {
|
|
1274
|
+
if (this.subEngines.length > 0) {
|
|
1275
|
+
const target = this.activeEngine ?? this.subEngines[0];
|
|
1276
|
+
return target.getActiveEditableCount();
|
|
1277
|
+
}
|
|
1278
|
+
return this.activeEngine ? this.activeEngine.getActiveEditableCount() : this.slots.filter((s) => !s.isStatic).length;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Capacité maximale de positions éditables parmi les gabarits configurés (pour le blocage de frappe / collage).
|
|
1282
|
+
*/
|
|
1283
|
+
getMaxEditableCount() {
|
|
1064
1284
|
if (this.subEngines.length > 0) {
|
|
1065
|
-
return Math.max(...this.subEngines.map((e) => e.
|
|
1285
|
+
return Math.max(...this.subEngines.map((e) => e.getMaxEditableCount()));
|
|
1066
1286
|
}
|
|
1067
|
-
return this.
|
|
1287
|
+
return this.getActiveEditableCount();
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Capacité maximale totale de positions éditables dans le masque (alias rétrocompatible de getMaxEditableCount).
|
|
1291
|
+
*/
|
|
1292
|
+
getEditableCount() {
|
|
1293
|
+
return this.getMaxEditableCount();
|
|
1068
1294
|
}
|
|
1069
1295
|
/**
|
|
1070
1296
|
* Indique si tous les emplacements éditables du masque acceptent exclusivement des chiffres numériques.
|
|
@@ -1102,15 +1328,199 @@ var __WulfIIFE = (() => {
|
|
|
1102
1328
|
isStrict() {
|
|
1103
1329
|
return this.strict;
|
|
1104
1330
|
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Normalise une chaîne issue du presse-papier en alignant et complétant à gauche par '0'
|
|
1333
|
+
* les segments numériques courts lorsque la structure correspond sans ambiguïté au gabarit.
|
|
1334
|
+
* N'altère jamais extractRaw() ni la saisie clavier.
|
|
1335
|
+
*/
|
|
1336
|
+
normalizePastedValue(pasted) {
|
|
1337
|
+
const rawPasted = String(pasted ?? "");
|
|
1338
|
+
if (!rawPasted) return rawPasted;
|
|
1339
|
+
this.resolveForValue(rawPasted);
|
|
1340
|
+
if (this.subEngines.length > 0) {
|
|
1341
|
+
const lowerPasted = rawPasted.toLowerCase();
|
|
1342
|
+
const withMatchingPrefix = this.subEngines.filter((e) => {
|
|
1343
|
+
const p = e.getPrefix();
|
|
1344
|
+
return p.length > 0 && lowerPasted.startsWith(p.trim().toLowerCase());
|
|
1345
|
+
});
|
|
1346
|
+
const candidates = withMatchingPrefix.length > 0 ? withMatchingPrefix : this.subEngines;
|
|
1347
|
+
let firstMatch = null;
|
|
1348
|
+
for (const eng of candidates) {
|
|
1349
|
+
const res = eng.tryNormalizeSegments(rawPasted);
|
|
1350
|
+
if (res.matched) {
|
|
1351
|
+
if (res.exactSegmentCount) {
|
|
1352
|
+
return res.normalized;
|
|
1353
|
+
}
|
|
1354
|
+
if (firstMatch === null) {
|
|
1355
|
+
firstMatch = res.normalized;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
return firstMatch !== null ? firstMatch : rawPasted;
|
|
1360
|
+
}
|
|
1361
|
+
return this.tryNormalizeSegments(rawPasted).normalized;
|
|
1362
|
+
}
|
|
1363
|
+
tryNormalizeSegments(pasted) {
|
|
1364
|
+
const fail = { matched: false, normalized: pasted, exactSegmentCount: false };
|
|
1365
|
+
if (!this.strict || this.slots.length === 0 || !pasted) {
|
|
1366
|
+
return fail;
|
|
1367
|
+
}
|
|
1368
|
+
let rest = pasted;
|
|
1369
|
+
if (this.prefixSlotsCount > 0) {
|
|
1370
|
+
let inputIdx = 0;
|
|
1371
|
+
while (inputIdx < pasted.length && (pasted[inputIdx] === " " || pasted[inputIdx] === " ")) {
|
|
1372
|
+
inputIdx++;
|
|
1373
|
+
}
|
|
1374
|
+
let pIdx = 0;
|
|
1375
|
+
while (inputIdx < pasted.length && pIdx < this.prefixSlotsCount) {
|
|
1376
|
+
const pChar = this.slots[pIdx].char;
|
|
1377
|
+
const inChar = pasted[inputIdx];
|
|
1378
|
+
if (inChar.toUpperCase() === pChar.toUpperCase()) {
|
|
1379
|
+
inputIdx++;
|
|
1380
|
+
pIdx++;
|
|
1381
|
+
} else if (pChar === " " && inChar !== " ") {
|
|
1382
|
+
pIdx++;
|
|
1383
|
+
} else {
|
|
1384
|
+
break;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
if (pIdx === this.prefixSlotsCount) {
|
|
1388
|
+
rest = pasted.slice(inputIdx);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
if (!rest) {
|
|
1392
|
+
return fail;
|
|
1393
|
+
}
|
|
1394
|
+
const segments = [];
|
|
1395
|
+
const separators = [];
|
|
1396
|
+
let currentSeg = [];
|
|
1397
|
+
let currentSep = "";
|
|
1398
|
+
let hasTrailingStatic = false;
|
|
1399
|
+
for (let i = this.prefixSlotsCount; i < this.slots.length; i++) {
|
|
1400
|
+
const slot = this.slots[i];
|
|
1401
|
+
if (slot.isStatic) {
|
|
1402
|
+
if (currentSeg.length > 0) {
|
|
1403
|
+
segments.push(currentSeg);
|
|
1404
|
+
currentSeg = [];
|
|
1405
|
+
currentSep = slot.char;
|
|
1406
|
+
} else {
|
|
1407
|
+
currentSep += slot.char;
|
|
1408
|
+
}
|
|
1409
|
+
} else {
|
|
1410
|
+
if (currentSep.length > 0) {
|
|
1411
|
+
separators.push(currentSep);
|
|
1412
|
+
currentSep = "";
|
|
1413
|
+
}
|
|
1414
|
+
currentSeg.push(slot);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
if (currentSeg.length > 0) {
|
|
1418
|
+
segments.push(currentSeg);
|
|
1419
|
+
} else if (currentSep.length > 0) {
|
|
1420
|
+
hasTrailingStatic = true;
|
|
1421
|
+
}
|
|
1422
|
+
if (hasTrailingStatic || segments.length < 2 || separators.length !== segments.length - 1) {
|
|
1423
|
+
return fail;
|
|
1424
|
+
}
|
|
1425
|
+
const coreSeps = [];
|
|
1426
|
+
for (const sep of separators) {
|
|
1427
|
+
const core = sep.trim();
|
|
1428
|
+
if (core.length !== 1 || !SEGMENT_SEPARATORS.has(core)) {
|
|
1429
|
+
return fail;
|
|
1430
|
+
}
|
|
1431
|
+
coreSeps.push(core);
|
|
1432
|
+
}
|
|
1433
|
+
const parts = [];
|
|
1434
|
+
const foundSeps = [];
|
|
1435
|
+
let blockStart = 0;
|
|
1436
|
+
for (let i = 0; i < rest.length; i++) {
|
|
1437
|
+
const ch = rest[i];
|
|
1438
|
+
if (SEGMENT_SEPARATORS.has(ch)) {
|
|
1439
|
+
parts.push(rest.slice(blockStart, i).trim());
|
|
1440
|
+
foundSeps.push(ch);
|
|
1441
|
+
blockStart = i + 1;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
parts.push(rest.slice(blockStart).trim());
|
|
1445
|
+
if (foundSeps.length === 0 || foundSeps.length > coreSeps.length) {
|
|
1446
|
+
return fail;
|
|
1447
|
+
}
|
|
1448
|
+
if (parts.length !== foundSeps.length + 1 || parts.length > segments.length || parts.some((p) => p.length === 0)) {
|
|
1449
|
+
return fail;
|
|
1450
|
+
}
|
|
1451
|
+
const matchesMaskOrder = foundSeps.every((sep, idx) => sep === coreSeps[idx]);
|
|
1452
|
+
const isHomogeneous = foundSeps.every((sep) => sep === foundSeps[0]);
|
|
1453
|
+
if (!matchesMaskOrder && !isHomogeneous) {
|
|
1454
|
+
return fail;
|
|
1455
|
+
}
|
|
1456
|
+
const exactSegmentCount = parts.length === segments.length;
|
|
1457
|
+
const paddedParts = [];
|
|
1458
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1459
|
+
const part = parts[i];
|
|
1460
|
+
const segSlots = segments[i];
|
|
1461
|
+
if (part.length > segSlots.length) {
|
|
1462
|
+
return fail;
|
|
1463
|
+
}
|
|
1464
|
+
const isNumericSeg = segSlots.every(
|
|
1465
|
+
(s) => Boolean(s.token && s.token.pattern.test("0") && !s.token.pattern.test("a") && !s.token.pattern.test("Z"))
|
|
1466
|
+
);
|
|
1467
|
+
if (isNumericSeg) {
|
|
1468
|
+
const isClosedBySep = i < parts.length - 1;
|
|
1469
|
+
const isTerminalTwoDigitEligible = i === parts.length - 1 && exactSegmentCount && segments.length <= 3 && segSlots.length === 2;
|
|
1470
|
+
const shouldPad = part.length < segSlots.length && (isClosedBySep || isTerminalTwoDigitEligible);
|
|
1471
|
+
const offset = shouldPad ? segSlots.length - part.length : 0;
|
|
1472
|
+
for (let k = 0; k < part.length; k++) {
|
|
1473
|
+
const ch = part[k];
|
|
1474
|
+
if (ch < "0" || ch > "9" || !segSlots[offset + k].token.pattern.test(ch)) {
|
|
1475
|
+
return fail;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
paddedParts.push(shouldPad ? "0".repeat(segSlots.length - part.length) + part : part);
|
|
1479
|
+
} else {
|
|
1480
|
+
if (part.length !== segSlots.length) {
|
|
1481
|
+
return fail;
|
|
1482
|
+
}
|
|
1483
|
+
for (let k = 0; k < part.length; k++) {
|
|
1484
|
+
if (!segSlots[k].token || !segSlots[k].token.pattern.test(part[k])) {
|
|
1485
|
+
return fail;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
paddedParts.push(part);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
let normalized = this.prefixSlotsCount > 0 ? this.prefixString : "";
|
|
1492
|
+
for (let i = 0; i < paddedParts.length; i++) {
|
|
1493
|
+
if (i > 0) {
|
|
1494
|
+
normalized += separators[i - 1];
|
|
1495
|
+
}
|
|
1496
|
+
normalized += paddedParts[i];
|
|
1497
|
+
}
|
|
1498
|
+
return {
|
|
1499
|
+
matched: true,
|
|
1500
|
+
normalized,
|
|
1501
|
+
exactSegmentCount
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Filtre et extrait les caractères éditables sans déclencher de ré-évaluation dynamique du gabarit.
|
|
1506
|
+
* Utile pour mesurer une sélection partielle ou mapper le curseur sans effet de bord.
|
|
1507
|
+
*/
|
|
1508
|
+
extractRawForCurrentPattern(input) {
|
|
1509
|
+
return this.extractRawInternal(input);
|
|
1510
|
+
}
|
|
1105
1511
|
/**
|
|
1106
1512
|
* Filtre et extrait uniquement les caractères éditables valides d'une chaîne.
|
|
1107
1513
|
* Gère intelligemment la présence ou l'absence des séparateurs statiques et du préfixe.
|
|
1108
1514
|
*/
|
|
1109
1515
|
extractRaw(input) {
|
|
1516
|
+
this.resolveForValue(input);
|
|
1517
|
+
return this.extractRawInternal(input);
|
|
1518
|
+
}
|
|
1519
|
+
extractRawInternal(input) {
|
|
1110
1520
|
if (this.subEngines.length > 0) {
|
|
1111
1521
|
const engine = this.selectEngine(input);
|
|
1112
1522
|
if (engine !== this) {
|
|
1113
|
-
return engine.
|
|
1523
|
+
return engine.extractRawInternal(input);
|
|
1114
1524
|
}
|
|
1115
1525
|
}
|
|
1116
1526
|
const maxInputLen = Math.max(4096, this.slots.length * 4);
|
|
@@ -1177,6 +1587,7 @@ var __WulfIIFE = (() => {
|
|
|
1177
1587
|
* Si aucune donnée éditable n'est présente, retourne le préfixe statique fixe s'il existe.
|
|
1178
1588
|
*/
|
|
1179
1589
|
format(rawValue) {
|
|
1590
|
+
this.resolveForValue(rawValue);
|
|
1180
1591
|
if (this.subEngines.length > 0) {
|
|
1181
1592
|
const engine = this.selectEngine(rawValue);
|
|
1182
1593
|
if (engine !== this) {
|
|
@@ -1186,7 +1597,7 @@ var __WulfIIFE = (() => {
|
|
|
1186
1597
|
const maxInputLen = Math.max(4096, this.slots.length * 4);
|
|
1187
1598
|
const rawStr = String(rawValue ?? "").slice(0, maxInputLen);
|
|
1188
1599
|
if (!this.slots.length) return rawStr;
|
|
1189
|
-
const cleanRaw = this.
|
|
1600
|
+
const cleanRaw = this.extractRawInternal(rawStr);
|
|
1190
1601
|
if (cleanRaw.length === 0) {
|
|
1191
1602
|
return this.prefixString;
|
|
1192
1603
|
}
|
|
@@ -1248,7 +1659,7 @@ var __WulfIIFE = (() => {
|
|
|
1248
1659
|
const safeInput = String(inputValue ?? "");
|
|
1249
1660
|
const safeFormatted = String(formatted ?? "");
|
|
1250
1661
|
if (inputCursor <= 0 || !safeFormatted) return minPos;
|
|
1251
|
-
const rawBeforeCursor = this.
|
|
1662
|
+
const rawBeforeCursor = this.extractRawInternal(safeInput.slice(0, inputCursor));
|
|
1252
1663
|
const targetRawCount = rawBeforeCursor.length;
|
|
1253
1664
|
if (targetRawCount === 0) {
|
|
1254
1665
|
return Math.max(minPos, Math.min(this.getNextEditablePosition(0), safeFormatted.length));
|
|
@@ -1431,10 +1842,25 @@ var __WulfIIFE = (() => {
|
|
|
1431
1842
|
if (isPrintableChar && !hasSelection) {
|
|
1432
1843
|
const slots = engine.getSlots();
|
|
1433
1844
|
const isAlreadyOnSep = cursor < slots.length && slots[cursor].isStatic && slots[cursor].char === e.key;
|
|
1434
|
-
|
|
1845
|
+
let justAfterSepIdx = -1;
|
|
1846
|
+
if (cursor > 0 && cursor - 1 < slots.length) {
|
|
1847
|
+
if (slots[cursor - 1].isStatic && slots[cursor - 1].char === e.key) {
|
|
1848
|
+
justAfterSepIdx = cursor - 1;
|
|
1849
|
+
} else {
|
|
1850
|
+
let k = cursor - 1;
|
|
1851
|
+
while (k >= minPos && slots[k].isStatic) {
|
|
1852
|
+
if (slots[k].char === e.key) {
|
|
1853
|
+
justAfterSepIdx = k;
|
|
1854
|
+
break;
|
|
1855
|
+
}
|
|
1856
|
+
k--;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
const isJustAfterSep = justAfterSepIdx !== -1;
|
|
1435
1861
|
if (isAlreadyOnSep || isJustAfterSep) {
|
|
1436
1862
|
e.preventDefault();
|
|
1437
|
-
const baseIdx = isAlreadyOnSep ? cursor :
|
|
1863
|
+
const baseIdx = isAlreadyOnSep ? cursor : justAfterSepIdx;
|
|
1438
1864
|
const nextEditable = engine.getNextEditablePosition(baseIdx + 1);
|
|
1439
1865
|
this.delegate.applyMask(input.value, nextEditable, true);
|
|
1440
1866
|
return;
|
|
@@ -1457,7 +1883,7 @@ var __WulfIIFE = (() => {
|
|
|
1457
1883
|
segStart++;
|
|
1458
1884
|
const segLength = nextSepIdx - segStart;
|
|
1459
1885
|
const currentSegVal = input.value.slice(segStart, cursor);
|
|
1460
|
-
const isNumericSegment = slots.slice(segStart, nextSepIdx).every((s) =>
|
|
1886
|
+
const isNumericSegment = slots.slice(segStart, nextSepIdx).every((s) => Boolean(s.token && s.token.pattern.test("0") && !s.token.pattern.test("a") && !s.token.pattern.test("Z")));
|
|
1461
1887
|
if (isNumericSegment && segLength > currentSegVal.length && currentSegVal.length > 0) {
|
|
1462
1888
|
const missingCount = segLength - currentSegVal.length;
|
|
1463
1889
|
const paddedSeg = "0".repeat(missingCount) + currentSegVal;
|
|
@@ -1473,19 +1899,27 @@ var __WulfIIFE = (() => {
|
|
|
1473
1899
|
}
|
|
1474
1900
|
}
|
|
1475
1901
|
if (isPrintableChar && engine.isStrict()) {
|
|
1476
|
-
const
|
|
1902
|
+
const isDynamic = engine.isDynamicPattern();
|
|
1903
|
+
const currentRaw = engine.extractRaw(input.value);
|
|
1904
|
+
const selectedRaw = selectionEnd > cursor ? engine.extractRawForCurrentPattern(input.value.slice(cursor, selectionEnd)) : "";
|
|
1905
|
+
if (isDynamic) {
|
|
1906
|
+
const candidate = input.value.slice(0, cursor) + e.key + input.value.slice(selectionEnd);
|
|
1907
|
+
engine.resolveForValue(candidate);
|
|
1908
|
+
}
|
|
1909
|
+
const totalSlots = engine.getMaxEditableCount();
|
|
1477
1910
|
if (totalSlots > 0) {
|
|
1478
|
-
const
|
|
1479
|
-
let availableCapacity = totalSlots - currentRaw.length;
|
|
1480
|
-
if (selectionEnd > cursor) {
|
|
1481
|
-
const selectedRaw = engine.extractRaw(input.value.slice(cursor, selectionEnd));
|
|
1482
|
-
availableCapacity = totalSlots - (currentRaw.length - selectedRaw.length);
|
|
1483
|
-
}
|
|
1911
|
+
const availableCapacity = totalSlots - (currentRaw.length - selectedRaw.length);
|
|
1484
1912
|
if (availableCapacity <= 0) {
|
|
1913
|
+
if (isDynamic) {
|
|
1914
|
+
engine.resolveForValue(input.value);
|
|
1915
|
+
}
|
|
1485
1916
|
e.preventDefault();
|
|
1486
1917
|
return;
|
|
1487
1918
|
}
|
|
1488
1919
|
}
|
|
1920
|
+
if (isDynamic) {
|
|
1921
|
+
engine.resolveForValue(input.value);
|
|
1922
|
+
}
|
|
1489
1923
|
}
|
|
1490
1924
|
if (selectionEnd > cursor) {
|
|
1491
1925
|
if (e.key === "Backspace" || e.key === "Delete") {
|
|
@@ -1624,6 +2058,7 @@ var __WulfIIFE = (() => {
|
|
|
1624
2058
|
cutTimerId = null;
|
|
1625
2059
|
pasteTimerId = null;
|
|
1626
2060
|
resetTimerId = null;
|
|
2061
|
+
lastInputType = "";
|
|
1627
2062
|
constructor(targetOrWrapper, inputOrOptions, options) {
|
|
1628
2063
|
const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
|
|
1629
2064
|
const wrap = args.wrapper;
|
|
@@ -1674,20 +2109,26 @@ var __WulfIIFE = (() => {
|
|
|
1674
2109
|
enforceMinCursor: () => this.enforceMinCursor()
|
|
1675
2110
|
});
|
|
1676
2111
|
this.bindEvents();
|
|
1677
|
-
this.lastValue = this.
|
|
2112
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
1678
2113
|
this.syncInitialValue();
|
|
1679
2114
|
this.runAuditWarning(this.options.audit);
|
|
1680
2115
|
}
|
|
1681
2116
|
getSpecificAuditWarnings() {
|
|
1682
2117
|
const warnings = [];
|
|
1683
2118
|
const describedbyWarnings = [];
|
|
1684
|
-
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings);
|
|
2119
|
+
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings, true);
|
|
1685
2120
|
const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
|
|
1686
2121
|
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
1687
|
-
if (!hasValidDescribedby && !
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
2122
|
+
if (!hasValidDescribedby && !hasAriaPlaceholder && !this.options.disabled) {
|
|
2123
|
+
if (hasPlaceholder) {
|
|
2124
|
+
warnings.push(
|
|
2125
|
+
"Indication du format attendu fragile : l'attribut placeholder seul dispara\xEEt \xE0 la saisie et est masqu\xE9 par le gabarit fant\xF4me ; utilisez aria-describedby ou aria-placeholder (WCAG 3.3.2)."
|
|
2126
|
+
);
|
|
2127
|
+
} else {
|
|
2128
|
+
warnings.push(
|
|
2129
|
+
"Indication du format attendu manquante : d\xE9finissez aria-describedby ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
1691
2132
|
}
|
|
1692
2133
|
return warnings;
|
|
1693
2134
|
}
|
|
@@ -1706,7 +2147,7 @@ var __WulfIIFE = (() => {
|
|
|
1706
2147
|
* Formate statiquement une valeur selon un masque donné sans nécessiter d'élément DOM.
|
|
1707
2148
|
*
|
|
1708
2149
|
* @param value Valeur à formater (ex: "0123456789")
|
|
1709
|
-
* @param mask Gabarit de masque (ex: "99 99 99 99 99")
|
|
2150
|
+
* @param mask Gabarit de masque (ex: "99 99 99 99 99", tableau ou résolveur dynamique)
|
|
1710
2151
|
* @param options Options facultatives du masque (tokens, placeholderChar, strict, etc.)
|
|
1711
2152
|
* @returns Valeur formatée (ex: "01 23 45 67 89")
|
|
1712
2153
|
*/
|
|
@@ -1717,7 +2158,8 @@ var __WulfIIFE = (() => {
|
|
|
1717
2158
|
if (this.options.disabled) {
|
|
1718
2159
|
this.checkValueChange();
|
|
1719
2160
|
} else {
|
|
1720
|
-
this.
|
|
2161
|
+
const transformed = this.applyTransformInput(strVal, "programmatic", "");
|
|
2162
|
+
this.applyMask(transformed, transformed.length);
|
|
1721
2163
|
}
|
|
1722
2164
|
}
|
|
1723
2165
|
onDisabledChange(disabled) {
|
|
@@ -1894,10 +2336,13 @@ var __WulfIIFE = (() => {
|
|
|
1894
2336
|
super.handleAttributeMutation(attrName);
|
|
1895
2337
|
if (attrName === "data-mask") {
|
|
1896
2338
|
const rawAttr = this.getAttr("data-mask");
|
|
2339
|
+
if (rawAttr === null && (this.isSensitiveField() || typeof this.options.mask === "function")) {
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
1897
2342
|
if (rawAttr === this.lastInternalRemainingMask) {
|
|
1898
2343
|
return;
|
|
1899
2344
|
}
|
|
1900
|
-
const currentMaskStr = Array.isArray(this.options.mask) ? this.options.mask.join("|") : this.options.mask || "";
|
|
2345
|
+
const currentMaskStr = typeof this.options.mask === "function" ? "" : Array.isArray(this.options.mask) ? this.options.mask.join("|") : this.options.mask || "";
|
|
1901
2346
|
if (rawAttr === currentMaskStr) {
|
|
1902
2347
|
return;
|
|
1903
2348
|
}
|
|
@@ -1919,6 +2364,19 @@ var __WulfIIFE = (() => {
|
|
|
1919
2364
|
this.updateGhost(this.input.value);
|
|
1920
2365
|
}
|
|
1921
2366
|
}
|
|
2367
|
+
applyTransformInput(value, source, inputType) {
|
|
2368
|
+
if (typeof this.options.transformInput !== "function") {
|
|
2369
|
+
return value;
|
|
2370
|
+
}
|
|
2371
|
+
try {
|
|
2372
|
+
const res = this.options.transformInput(value, { source, inputType });
|
|
2373
|
+
if (typeof res === "string") {
|
|
2374
|
+
return source === "paste" ? sanitizePastedText(res, 4096) : stripBidiAndInvisibles(res, 4096);
|
|
2375
|
+
}
|
|
2376
|
+
} catch {
|
|
2377
|
+
}
|
|
2378
|
+
return value;
|
|
2379
|
+
}
|
|
1922
2380
|
/**
|
|
1923
2381
|
* Affecte une nouvelle valeur manuellement (formatée ou brute).
|
|
1924
2382
|
*/
|
|
@@ -1929,7 +2387,8 @@ var __WulfIIFE = (() => {
|
|
|
1929
2387
|
this.checkValueChange();
|
|
1930
2388
|
return;
|
|
1931
2389
|
}
|
|
1932
|
-
this.
|
|
2390
|
+
const transformed = this.applyTransformInput(safeVal, "programmatic", "");
|
|
2391
|
+
this.applyMask(transformed, transformed.length);
|
|
1933
2392
|
}
|
|
1934
2393
|
/**
|
|
1935
2394
|
* Retourne la valeur brute sans séparateurs.
|
|
@@ -1938,12 +2397,14 @@ var __WulfIIFE = (() => {
|
|
|
1938
2397
|
return this.engine.extractRaw(this.input.value);
|
|
1939
2398
|
}
|
|
1940
2399
|
/**
|
|
1941
|
-
* Indique si tous les emplacements éditables sont renseignés.
|
|
2400
|
+
* Indique si tous les emplacements éditables du gabarit actif sont renseignés.
|
|
1942
2401
|
*/
|
|
1943
2402
|
isComplete() {
|
|
1944
2403
|
if (this.options.disabled) return true;
|
|
1945
2404
|
const raw = this.getRawValue();
|
|
1946
|
-
|
|
2405
|
+
const activeSlots = this.engine.getActiveEditableCount();
|
|
2406
|
+
if (activeSlots === 0) return true;
|
|
2407
|
+
return raw.length >= activeSlots;
|
|
1947
2408
|
}
|
|
1948
2409
|
/**
|
|
1949
2410
|
* Callback d'écoute directe ou getter/setter pour onInput.
|
|
@@ -1989,32 +2450,45 @@ var __WulfIIFE = (() => {
|
|
|
1989
2450
|
this.wrapper.classList.toggle("has-selection", hasSelection);
|
|
1990
2451
|
}
|
|
1991
2452
|
onBeforeInput(e) {
|
|
2453
|
+
this.lastInputType = e.inputType || "";
|
|
1992
2454
|
if (this.options.disabled) return;
|
|
1993
2455
|
if (this.isComposing) return;
|
|
1994
2456
|
if (!this.engine.isStrict()) return;
|
|
1995
2457
|
if (e.inputType === "insertFromPaste" || e.inputType === "insertReplacementText") return;
|
|
1996
2458
|
if (e.inputType && e.inputType.startsWith("insert")) {
|
|
1997
|
-
const
|
|
2459
|
+
const currentVal = this.input.value;
|
|
2460
|
+
const isDynamic = this.engine.isDynamicPattern();
|
|
2461
|
+
const currentRaw = this.engine.extractRaw(currentVal);
|
|
2462
|
+
const start = this.input.selectionStart ?? 0;
|
|
2463
|
+
const end = this.input.selectionEnd ?? start;
|
|
2464
|
+
const selectedRaw = end > start ? this.engine.extractRawForCurrentPattern(currentVal.slice(start, end)) : "";
|
|
2465
|
+
if (isDynamic) {
|
|
2466
|
+
const candidate = currentVal.slice(0, start) + (e.data ?? "") + currentVal.slice(end);
|
|
2467
|
+
this.engine.resolveForValue(candidate);
|
|
2468
|
+
}
|
|
2469
|
+
const totalSlots = this.engine.getMaxEditableCount();
|
|
1998
2470
|
if (totalSlots > 0) {
|
|
1999
|
-
const
|
|
2000
|
-
const start = this.input.selectionStart ?? 0;
|
|
2001
|
-
const end = this.input.selectionEnd ?? start;
|
|
2002
|
-
let availableCapacity = Math.max(0, totalSlots - currentRaw.length);
|
|
2003
|
-
if (end > start) {
|
|
2004
|
-
const selectedRaw = this.engine.extractRaw(this.input.value.slice(start, end));
|
|
2005
|
-
availableCapacity = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
2006
|
-
}
|
|
2471
|
+
const availableCapacity = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
2007
2472
|
if (availableCapacity <= 0) {
|
|
2473
|
+
if (isDynamic) {
|
|
2474
|
+
this.engine.resolveForValue(currentVal);
|
|
2475
|
+
}
|
|
2008
2476
|
e.preventDefault();
|
|
2477
|
+
return;
|
|
2009
2478
|
}
|
|
2010
2479
|
}
|
|
2480
|
+
if (isDynamic) {
|
|
2481
|
+
this.engine.resolveForValue(currentVal);
|
|
2482
|
+
}
|
|
2011
2483
|
}
|
|
2012
2484
|
}
|
|
2013
2485
|
handleInput(e) {
|
|
2014
2486
|
if (this.isDispatchingNativeInput) return;
|
|
2015
2487
|
if (this.isComposing) return;
|
|
2488
|
+
const inputType = e?.inputType || this.lastInputType || "";
|
|
2489
|
+
this.lastInputType = "";
|
|
2016
2490
|
const hasOnInput = Boolean(this.options.onInput || this.options.oninput);
|
|
2017
|
-
const currentComparison = this.
|
|
2491
|
+
const currentComparison = this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
2018
2492
|
if (hasOnInput && currentComparison !== this.lastValue) {
|
|
2019
2493
|
this.checkValueChange();
|
|
2020
2494
|
}
|
|
@@ -2022,17 +2496,20 @@ var __WulfIIFE = (() => {
|
|
|
2022
2496
|
this.checkValueChange();
|
|
2023
2497
|
return;
|
|
2024
2498
|
}
|
|
2499
|
+
const rawInputVal = this.input.value;
|
|
2500
|
+
const oldCursor = this.input.selectionStart ?? rawInputVal.length;
|
|
2501
|
+
const transformedVal = this.applyTransformInput(rawInputVal, "input", inputType);
|
|
2502
|
+
const effectiveCursor = transformedVal !== rawInputVal ? oldCursor >= rawInputVal.length ? transformedVal.length : Math.min(oldCursor, transformedVal.length) : oldCursor;
|
|
2025
2503
|
const prevState = this.history.getCurrent();
|
|
2026
|
-
const
|
|
2504
|
+
const newRaw = this.engine.extractRaw(transformedVal);
|
|
2505
|
+
const totalSlots = this.engine.getMaxEditableCount();
|
|
2027
2506
|
if (totalSlots > 0 && this.engine.isStrict() && prevState && prevState.raw.length >= totalSlots) {
|
|
2028
|
-
const newRaw = this.engine.extractRaw(this.input.value);
|
|
2029
2507
|
if (newRaw.length > totalSlots) {
|
|
2030
2508
|
this.applyMask(prevState.raw, prevState.cursor);
|
|
2031
2509
|
return;
|
|
2032
2510
|
}
|
|
2033
2511
|
}
|
|
2034
|
-
|
|
2035
|
-
this.applyMask(this.input.value, oldCursor);
|
|
2512
|
+
this.applyMask(transformedVal, effectiveCursor);
|
|
2036
2513
|
this.checkSelection();
|
|
2037
2514
|
}
|
|
2038
2515
|
onKeyDown(e) {
|
|
@@ -2057,15 +2534,15 @@ var __WulfIIFE = (() => {
|
|
|
2057
2534
|
}
|
|
2058
2535
|
e.preventDefault();
|
|
2059
2536
|
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
2060
|
-
const
|
|
2061
|
-
const pastedText =
|
|
2537
|
+
const preparedText = this.preparePastedText(this.getClipboardPlainText(e), 4096);
|
|
2538
|
+
const pastedText = this.applyTransformInput(preparedText, "paste", "insertFromPaste");
|
|
2062
2539
|
if (!pastedText) return;
|
|
2063
2540
|
const minPos = this.engine.getPrefixLength();
|
|
2064
2541
|
const selStart = this.input.selectionStart ?? 0;
|
|
2065
2542
|
const selEnd = this.input.selectionEnd ?? selStart;
|
|
2066
2543
|
const currentVal = this.input.value;
|
|
2067
|
-
const totalSlots = this.engine.getEditableCount();
|
|
2068
2544
|
const currentRaw = this.getRawValue();
|
|
2545
|
+
const totalSlots = this.engine.getMaxEditableCount();
|
|
2069
2546
|
const prefix = this.engine.getPrefix();
|
|
2070
2547
|
const cleanPrefix = prefix.replace(/[\s.-]+/g, "").toUpperCase();
|
|
2071
2548
|
const cleanPasted = pastedText.replace(/[\s.-]+/g, "").toUpperCase();
|
|
@@ -2080,17 +2557,38 @@ var __WulfIIFE = (() => {
|
|
|
2080
2557
|
}
|
|
2081
2558
|
let availableCapacity = Math.max(0, totalSlots - currentRaw.length);
|
|
2082
2559
|
if (effectiveStart !== effectiveEnd) {
|
|
2083
|
-
const selectedRaw = this.engine.
|
|
2560
|
+
const selectedRaw = this.engine.extractRawForCurrentPattern(currentVal.slice(effectiveStart, effectiveEnd));
|
|
2084
2561
|
availableCapacity = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
2085
2562
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2563
|
+
const normalizedPasted = this.engine.normalizePastedValue(pastedText);
|
|
2564
|
+
const activeSlots = this.engine.getActiveEditableCount();
|
|
2565
|
+
const isCurrentComplete = activeSlots > 0 && currentRaw.length >= activeSlots;
|
|
2566
|
+
if (this.engine.isStrict() && (availableCapacity <= 0 || selStart === selEnd && isCurrentComplete)) {
|
|
2567
|
+
const pastedRawLen = this.engine.extractRaw(normalizedPasted).length;
|
|
2568
|
+
const targetMaxSlots = this.engine.getMaxEditableCount();
|
|
2569
|
+
if (selStart === selEnd && targetMaxSlots > 0 && pastedRawLen === targetMaxSlots && (availableCapacity <= 0 || pastedRawLen > availableCapacity)) {
|
|
2570
|
+
effectiveStart = 0;
|
|
2571
|
+
effectiveEnd = currentVal.length;
|
|
2572
|
+
} else if (availableCapacity <= 0) {
|
|
2573
|
+
this.engine.resolveForValue(currentVal);
|
|
2574
|
+
return;
|
|
2575
|
+
} else {
|
|
2576
|
+
this.engine.resolveForValue(currentVal);
|
|
2577
|
+
}
|
|
2088
2578
|
}
|
|
2089
2579
|
let combined;
|
|
2090
2580
|
let newCursorPos;
|
|
2091
2581
|
if (effectiveStart === 0 && effectiveEnd === currentVal.length) {
|
|
2092
|
-
combined =
|
|
2093
|
-
newCursorPos =
|
|
2582
|
+
combined = normalizedPasted;
|
|
2583
|
+
newCursorPos = normalizedPasted.length;
|
|
2584
|
+
} else if (currentRaw.length === 0 && effectiveStart === minPos && effectiveEnd === currentVal.length) {
|
|
2585
|
+
if (minPos > 0 && normalizedPasted.toUpperCase().startsWith(prefix.toUpperCase())) {
|
|
2586
|
+
combined = normalizedPasted;
|
|
2587
|
+
newCursorPos = normalizedPasted.length;
|
|
2588
|
+
} else {
|
|
2589
|
+
combined = currentVal.slice(0, effectiveStart) + normalizedPasted;
|
|
2590
|
+
newCursorPos = combined.length;
|
|
2591
|
+
}
|
|
2094
2592
|
} else {
|
|
2095
2593
|
combined = currentVal.slice(0, effectiveStart) + pastedText + currentVal.slice(effectiveEnd);
|
|
2096
2594
|
newCursorPos = effectiveStart + pastedText.length;
|
|
@@ -2109,7 +2607,7 @@ var __WulfIIFE = (() => {
|
|
|
2109
2607
|
}
|
|
2110
2608
|
onBlur() {
|
|
2111
2609
|
this.wrapper.classList.remove("is-focused", "has-selection");
|
|
2112
|
-
if (this.
|
|
2610
|
+
if (this.isSensitiveField()) {
|
|
2113
2611
|
this.history.clear();
|
|
2114
2612
|
this.lastValue = "";
|
|
2115
2613
|
this.lastInternalRemainingMask = "";
|
|
@@ -2170,7 +2668,7 @@ var __WulfIIFE = (() => {
|
|
|
2170
2668
|
// ==========================================================================
|
|
2171
2669
|
updateGhost(formatted) {
|
|
2172
2670
|
if (!this.ghost) return;
|
|
2173
|
-
if (this.options.disabled || this.
|
|
2671
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
2174
2672
|
this.clearGhost();
|
|
2175
2673
|
return;
|
|
2176
2674
|
}
|
|
@@ -2198,10 +2696,13 @@ var __WulfIIFE = (() => {
|
|
|
2198
2696
|
let isCompleted = false;
|
|
2199
2697
|
try {
|
|
2200
2698
|
formatted = this.engine.format(rawOrPartial);
|
|
2699
|
+
if (this.engine.isDynamicPattern()) {
|
|
2700
|
+
this.syncInferredInputMode();
|
|
2701
|
+
}
|
|
2201
2702
|
const remainingMask = this.engine.getRemainingMask(formatted);
|
|
2202
|
-
const
|
|
2203
|
-
this.
|
|
2204
|
-
if (
|
|
2703
|
+
const isSensitive = this.isSensitiveField();
|
|
2704
|
+
this.setNativeValue(formatted);
|
|
2705
|
+
if (isSensitive) {
|
|
2205
2706
|
this.lastInternalRemainingMask = "";
|
|
2206
2707
|
this.wrapper.removeAttribute("data-mask");
|
|
2207
2708
|
this.clearGhost();
|
|
@@ -2221,7 +2722,7 @@ var __WulfIIFE = (() => {
|
|
|
2221
2722
|
this.input.setSelectionRange(safeCursor, safeCursor);
|
|
2222
2723
|
isCompleted = this.isComplete();
|
|
2223
2724
|
this.wrapper.classList.toggle("is-complete", isCompleted);
|
|
2224
|
-
if (
|
|
2725
|
+
if (isSensitive) {
|
|
2225
2726
|
this.options.copyRaw = false;
|
|
2226
2727
|
this.history.clear();
|
|
2227
2728
|
} else if (!this.isUndoingRedoing) {
|
|
@@ -2233,24 +2734,25 @@ var __WulfIIFE = (() => {
|
|
|
2233
2734
|
this.checkValueChange();
|
|
2234
2735
|
}
|
|
2235
2736
|
syncInitialValue() {
|
|
2236
|
-
const
|
|
2737
|
+
const isSensitive = this.isSensitiveField();
|
|
2237
2738
|
if (this.options.disabled) {
|
|
2238
2739
|
this.wrapper.removeAttribute("data-mask");
|
|
2239
2740
|
this.clearGhost();
|
|
2240
|
-
this.lastValue =
|
|
2741
|
+
this.lastValue = isSensitive ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
2241
2742
|
this.checkValueChange();
|
|
2242
2743
|
return;
|
|
2243
2744
|
}
|
|
2244
2745
|
this.syncGhostStyles();
|
|
2245
2746
|
const initialVal = this.input.value || "";
|
|
2246
2747
|
if (initialVal) {
|
|
2247
|
-
this.
|
|
2748
|
+
const transformed = this.applyTransformInput(initialVal, "programmatic", "");
|
|
2749
|
+
this.applyMask(transformed, transformed.length);
|
|
2248
2750
|
} else {
|
|
2249
2751
|
const minPos = this.engine.getPrefixLength();
|
|
2250
2752
|
if (minPos > 0) {
|
|
2251
2753
|
this.applyMask("", minPos);
|
|
2252
2754
|
} else {
|
|
2253
|
-
if (!
|
|
2755
|
+
if (!isSensitive) {
|
|
2254
2756
|
this.history.push("", 0);
|
|
2255
2757
|
const fullTemplate = this.engine.getFullMaskTemplate();
|
|
2256
2758
|
this.lastInternalRemainingMask = fullTemplate;
|
|
@@ -2270,9 +2772,9 @@ var __WulfIIFE = (() => {
|
|
|
2270
2772
|
* Gère de manière sûre la réentrance pour permettre d'appeler setMask() directement dans le callback.
|
|
2271
2773
|
*/
|
|
2272
2774
|
checkValueChange(forceNotify = false) {
|
|
2273
|
-
const
|
|
2775
|
+
const initialSensitive = this.isSensitiveField();
|
|
2274
2776
|
const currentVal = this.input.value;
|
|
2275
|
-
const currentComparison =
|
|
2777
|
+
const currentComparison = initialSensitive ? this.computePasswordDigest(currentVal) : currentVal;
|
|
2276
2778
|
if (currentComparison === this.lastValue && !forceNotify && !this.hasPendingNotification) {
|
|
2277
2779
|
return;
|
|
2278
2780
|
}
|
|
@@ -2283,15 +2785,16 @@ var __WulfIIFE = (() => {
|
|
|
2283
2785
|
this.isNotifying = true;
|
|
2284
2786
|
try {
|
|
2285
2787
|
let iterations = 0;
|
|
2286
|
-
const
|
|
2287
|
-
while (((
|
|
2788
|
+
const MAX_NOTIFICATION_ITERATIONS4 = 10;
|
|
2789
|
+
while (((this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS4) {
|
|
2288
2790
|
iterations++;
|
|
2289
2791
|
this.hasPendingNotification = false;
|
|
2290
2792
|
forceNotify = false;
|
|
2793
|
+
const sensitiveNow = this.isSensitiveField();
|
|
2291
2794
|
const valToNotify = this.input.value;
|
|
2292
|
-
this.lastValue =
|
|
2795
|
+
this.lastValue = sensitiveNow ? this.computePasswordDigest(valToNotify) : valToNotify;
|
|
2293
2796
|
const raw = this.options.disabled ? valToNotify : this.getRawValue();
|
|
2294
|
-
const totalSlots = this.options.disabled ? 0 : this.engine.
|
|
2797
|
+
const totalSlots = this.options.disabled ? 0 : this.engine.getActiveEditableCount();
|
|
2295
2798
|
const isComplete = this.isComplete();
|
|
2296
2799
|
const detail = {
|
|
2297
2800
|
value: valToNotify,
|
|
@@ -2300,23 +2803,24 @@ var __WulfIIFE = (() => {
|
|
|
2300
2803
|
totalSlots,
|
|
2301
2804
|
filledSlots: this.options.disabled ? valToNotify.length : raw.length
|
|
2302
2805
|
};
|
|
2806
|
+
const allowBubble = !sensitiveNow;
|
|
2303
2807
|
const onInputCb = this.options.onInput || this.options.oninput;
|
|
2304
2808
|
if (onInputCb) {
|
|
2305
2809
|
onInputCb(valToNotify, detail);
|
|
2306
2810
|
}
|
|
2307
|
-
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles:
|
|
2811
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: allowBubble, detail }));
|
|
2308
2812
|
this.dispatchNativeInput();
|
|
2309
2813
|
const onChangeCb = this.options.onChange || this.options.onchange;
|
|
2310
2814
|
if (onChangeCb) {
|
|
2311
2815
|
onChangeCb(detail);
|
|
2312
2816
|
}
|
|
2313
|
-
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles:
|
|
2817
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
2314
2818
|
const onCompleteCb = this.options.onComplete || this.options.oncomplete;
|
|
2315
2819
|
if (isComplete) {
|
|
2316
2820
|
if (onCompleteCb) {
|
|
2317
2821
|
onCompleteCb(detail);
|
|
2318
2822
|
}
|
|
2319
|
-
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles:
|
|
2823
|
+
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles: allowBubble, detail }));
|
|
2320
2824
|
}
|
|
2321
2825
|
}
|
|
2322
2826
|
} finally {
|
|
@@ -2349,6 +2853,47 @@ var __WulfIIFE = (() => {
|
|
|
2349
2853
|
max: options.max ?? Infinity
|
|
2350
2854
|
};
|
|
2351
2855
|
}
|
|
2856
|
+
/**
|
|
2857
|
+
* Normalise un texte collé uniquement lorsque le séparateur décimal vs milliers
|
|
2858
|
+
* est mathématiquement non ambigu :
|
|
2859
|
+
* - coexistence de ',' et '.' (le séparateur le plus à droite, s'il est unique, est la décimale),
|
|
2860
|
+
* - répétition (>= 2) d'un unique séparateur (il s'agit alors de séparateurs de milliers).
|
|
2861
|
+
* Un séparateur unique isolé (ex: "1,234") reste inchangé pour respecter la locale configurée.
|
|
2862
|
+
*/
|
|
2863
|
+
normalizePastedValue(pasted) {
|
|
2864
|
+
const str = sanitizePastedText(pasted, 512);
|
|
2865
|
+
if (!str) return "";
|
|
2866
|
+
let commaCount = 0;
|
|
2867
|
+
let dotCount = 0;
|
|
2868
|
+
let lastCommaIdx = -1;
|
|
2869
|
+
let lastDotIdx = -1;
|
|
2870
|
+
for (let i = 0; i < str.length; i++) {
|
|
2871
|
+
const ch = str[i];
|
|
2872
|
+
if (ch === ",") {
|
|
2873
|
+
commaCount++;
|
|
2874
|
+
lastCommaIdx = i;
|
|
2875
|
+
} else if (ch === ".") {
|
|
2876
|
+
dotCount++;
|
|
2877
|
+
lastDotIdx = i;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
if (commaCount > 0 && dotCount > 0) {
|
|
2881
|
+
const decChar = lastCommaIdx > lastDotIdx ? "," : ".";
|
|
2882
|
+
const decCount = decChar === "," ? commaCount : dotCount;
|
|
2883
|
+
if (decCount !== 1) {
|
|
2884
|
+
return str;
|
|
2885
|
+
}
|
|
2886
|
+
const thousandChar = decChar === "," ? "." : ",";
|
|
2887
|
+
return str.split(thousandChar).join("").replace(decChar, this.options.decimalSeparator);
|
|
2888
|
+
}
|
|
2889
|
+
if (commaCount >= 2 && dotCount === 0) {
|
|
2890
|
+
return str.split(",").join("");
|
|
2891
|
+
}
|
|
2892
|
+
if (dotCount >= 2 && commaCount === 0) {
|
|
2893
|
+
return str.split(".").join("");
|
|
2894
|
+
}
|
|
2895
|
+
return str;
|
|
2896
|
+
}
|
|
2352
2897
|
/**
|
|
2353
2898
|
* Analyse et nettoie une saisie utilisateur pour extraire ses composantes numériques.
|
|
2354
2899
|
*/
|
|
@@ -2539,12 +3084,15 @@ var __WulfIIFE = (() => {
|
|
|
2539
3084
|
};
|
|
2540
3085
|
|
|
2541
3086
|
// src/mask/InputAmountMask.ts
|
|
3087
|
+
var MAX_NOTIFICATION_ITERATIONS = 10;
|
|
2542
3088
|
var InputAmountMask = class extends BaseInputMask {
|
|
2543
3089
|
engine;
|
|
2544
3090
|
history;
|
|
2545
3091
|
isUndoingRedoing = false;
|
|
2546
3092
|
isApplying = false;
|
|
2547
3093
|
isComposing = false;
|
|
3094
|
+
isNotifying = false;
|
|
3095
|
+
hasPendingNotification = false;
|
|
2548
3096
|
lastValue = "";
|
|
2549
3097
|
wasInputModeInferred = false;
|
|
2550
3098
|
cutTimerId = null;
|
|
@@ -2604,7 +3152,7 @@ var __WulfIIFE = (() => {
|
|
|
2604
3152
|
}
|
|
2605
3153
|
onNativeValueSet(strVal) {
|
|
2606
3154
|
if (this.options.disabled || this.isComposing) {
|
|
2607
|
-
this.lastValue = strVal;
|
|
3155
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(strVal) : strVal;
|
|
2608
3156
|
return;
|
|
2609
3157
|
}
|
|
2610
3158
|
this.applyAmount(strVal, strVal.length);
|
|
@@ -2619,6 +3167,7 @@ var __WulfIIFE = (() => {
|
|
|
2619
3167
|
bindEvents() {
|
|
2620
3168
|
this.handleInput = this.handleInput.bind(this);
|
|
2621
3169
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
3170
|
+
this.handlePaste = this.handlePaste.bind(this);
|
|
2622
3171
|
this.handleBlur = this.handleBlur.bind(this);
|
|
2623
3172
|
this.handleFocus = this.handleFocus.bind(this);
|
|
2624
3173
|
this.handleClick = this.handleClick.bind(this);
|
|
@@ -2638,6 +3187,7 @@ var __WulfIIFE = (() => {
|
|
|
2638
3187
|
const { signal } = this.abortController;
|
|
2639
3188
|
this.input.addEventListener("input", this.handleInput, { signal });
|
|
2640
3189
|
this.input.addEventListener("keydown", this.handleKeyDown, { signal });
|
|
3190
|
+
this.input.addEventListener("paste", this.handlePaste, { signal });
|
|
2641
3191
|
this.input.addEventListener("blur", this.handleBlur, { signal });
|
|
2642
3192
|
this.input.addEventListener("focus", this.handleFocus, { signal });
|
|
2643
3193
|
this.input.addEventListener("click", this.handleClick, { signal });
|
|
@@ -2672,12 +3222,13 @@ var __WulfIIFE = (() => {
|
|
|
2672
3222
|
applyAmount(val, cursor) {
|
|
2673
3223
|
if (this.isApplying || this.options.disabled) return;
|
|
2674
3224
|
this.isApplying = true;
|
|
3225
|
+
let result = null;
|
|
2675
3226
|
try {
|
|
2676
|
-
|
|
3227
|
+
result = this.engine.format(val, cursor);
|
|
2677
3228
|
this.setNativeValue(result.formatted);
|
|
2678
3229
|
this.input.setSelectionRange(result.cursor, result.cursor);
|
|
2679
|
-
const
|
|
2680
|
-
if (
|
|
3230
|
+
const isSensitive = this.isSensitiveField();
|
|
3231
|
+
if (isSensitive) {
|
|
2681
3232
|
this.options.copyRaw = false;
|
|
2682
3233
|
this.history.clear();
|
|
2683
3234
|
this.clearGhost();
|
|
@@ -2687,17 +3238,19 @@ var __WulfIIFE = (() => {
|
|
|
2687
3238
|
}
|
|
2688
3239
|
this.updateGhost(result);
|
|
2689
3240
|
}
|
|
2690
|
-
const nextComparison = isPwd ? this.computePasswordDigest(result.formatted) : result.formatted;
|
|
2691
|
-
if (this.lastValue !== nextComparison) {
|
|
2692
|
-
this.lastValue = nextComparison;
|
|
2693
|
-
this.notifyChange(result);
|
|
2694
|
-
}
|
|
2695
3241
|
} finally {
|
|
2696
3242
|
this.isApplying = false;
|
|
2697
3243
|
}
|
|
3244
|
+
if (result) {
|
|
3245
|
+
this.checkValueChange(result);
|
|
3246
|
+
}
|
|
2698
3247
|
}
|
|
2699
3248
|
updateGhost(result) {
|
|
2700
3249
|
if (!this.ghost) return;
|
|
3250
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
3251
|
+
this.clearGhost();
|
|
3252
|
+
return;
|
|
3253
|
+
}
|
|
2701
3254
|
if (!result.formatted) {
|
|
2702
3255
|
if (this.shouldHideGhostForPlaceholder(true)) {
|
|
2703
3256
|
this.clearGhost();
|
|
@@ -2721,6 +3274,18 @@ var __WulfIIFE = (() => {
|
|
|
2721
3274
|
const cur = this.input.selectionStart ?? rawVal.length;
|
|
2722
3275
|
this.applyAmount(rawVal, cur);
|
|
2723
3276
|
}
|
|
3277
|
+
handlePaste(e) {
|
|
3278
|
+
if (this.options.disabled) return;
|
|
3279
|
+
e.preventDefault();
|
|
3280
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
3281
|
+
const prepared = this.preparePastedText(this.getClipboardPlainText(e), 512);
|
|
3282
|
+
if (!prepared) return;
|
|
3283
|
+
const normalized = this.engine.normalizePastedValue(prepared);
|
|
3284
|
+
const start = this.input.selectionStart ?? this.input.value.length;
|
|
3285
|
+
const end = this.input.selectionEnd ?? start;
|
|
3286
|
+
const combined = this.input.value.slice(0, start) + normalized + this.input.value.slice(end);
|
|
3287
|
+
this.applyAmount(combined, start + normalized.length);
|
|
3288
|
+
}
|
|
2724
3289
|
handleKeyDown(e) {
|
|
2725
3290
|
if (this.options.disabled || isImeComposing(e)) return;
|
|
2726
3291
|
if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z")) {
|
|
@@ -2785,7 +3350,9 @@ var __WulfIIFE = (() => {
|
|
|
2785
3350
|
}
|
|
2786
3351
|
}
|
|
2787
3352
|
enforceCursorBounds() {
|
|
2788
|
-
if (this.isDestroyed || !this.isFocused ||
|
|
3353
|
+
if (this.isDestroyed || !this.isFocused || getDeepActiveElement(this.input.ownerDocument) !== this.input || !this.input.value || this.options.disabled) {
|
|
3354
|
+
return;
|
|
3355
|
+
}
|
|
2789
3356
|
const start = this.input.selectionStart ?? 0;
|
|
2790
3357
|
const end = this.input.selectionEnd ?? 0;
|
|
2791
3358
|
if (start !== end) return;
|
|
@@ -2816,7 +3383,7 @@ var __WulfIIFE = (() => {
|
|
|
2816
3383
|
}
|
|
2817
3384
|
handleBlur() {
|
|
2818
3385
|
this.wrapper.classList.remove("is-focused");
|
|
2819
|
-
if (this.
|
|
3386
|
+
if (this.isSensitiveField()) {
|
|
2820
3387
|
this.history.clear();
|
|
2821
3388
|
this.lastValue = "";
|
|
2822
3389
|
this.lastTrackedValue = "";
|
|
@@ -2835,7 +3402,7 @@ var __WulfIIFE = (() => {
|
|
|
2835
3402
|
if (this.options.onChange) {
|
|
2836
3403
|
this.options.onChange(detail);
|
|
2837
3404
|
}
|
|
2838
|
-
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles:
|
|
3405
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: !this.isSensitiveField(), detail }));
|
|
2839
3406
|
}
|
|
2840
3407
|
handleAttributeMutation(attrName) {
|
|
2841
3408
|
super.handleAttributeMutation(attrName);
|
|
@@ -2845,6 +3412,34 @@ var __WulfIIFE = (() => {
|
|
|
2845
3412
|
this.updateGhost(this.engine.format(this.input.value));
|
|
2846
3413
|
}
|
|
2847
3414
|
}
|
|
3415
|
+
checkValueChange(initialResult) {
|
|
3416
|
+
const initialSensitive = this.isSensitiveField();
|
|
3417
|
+
const initialComparison = initialSensitive ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
3418
|
+
if (initialComparison === this.lastValue && !this.hasPendingNotification) {
|
|
3419
|
+
return;
|
|
3420
|
+
}
|
|
3421
|
+
if (this.isNotifying) {
|
|
3422
|
+
this.hasPendingNotification = true;
|
|
3423
|
+
return;
|
|
3424
|
+
}
|
|
3425
|
+
this.isNotifying = true;
|
|
3426
|
+
try {
|
|
3427
|
+
let iterations = 0;
|
|
3428
|
+
let nextResult = initialResult;
|
|
3429
|
+
while (((this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification) && iterations < MAX_NOTIFICATION_ITERATIONS) {
|
|
3430
|
+
iterations++;
|
|
3431
|
+
this.hasPendingNotification = false;
|
|
3432
|
+
const sensitiveNow = this.isSensitiveField();
|
|
3433
|
+
const currentVal = this.input.value;
|
|
3434
|
+
this.lastValue = sensitiveNow ? this.computePasswordDigest(currentVal) : currentVal;
|
|
3435
|
+
const res = nextResult ?? this.engine.format(currentVal);
|
|
3436
|
+
nextResult = void 0;
|
|
3437
|
+
this.notifyChange(res);
|
|
3438
|
+
}
|
|
3439
|
+
} finally {
|
|
3440
|
+
this.isNotifying = false;
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
2848
3443
|
notifyChange(result) {
|
|
2849
3444
|
const detail = {
|
|
2850
3445
|
value: result.formatted,
|
|
@@ -2855,7 +3450,7 @@ var __WulfIIFE = (() => {
|
|
|
2855
3450
|
if (this.options.onInput) {
|
|
2856
3451
|
this.options.onInput(detail);
|
|
2857
3452
|
}
|
|
2858
|
-
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles:
|
|
3453
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: !this.isSensitiveField(), detail }));
|
|
2859
3454
|
this.dispatchNativeInput();
|
|
2860
3455
|
}
|
|
2861
3456
|
undo() {
|
|
@@ -2898,20 +3493,62 @@ var __WulfIIFE = (() => {
|
|
|
2898
3493
|
isValid() {
|
|
2899
3494
|
return this.getDetail().isValid;
|
|
2900
3495
|
}
|
|
2901
|
-
|
|
2902
|
-
const
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
} else {
|
|
2907
|
-
this.applyAmount(str, str.length);
|
|
3496
|
+
getSpecificAuditWarnings() {
|
|
3497
|
+
const warnings = [];
|
|
3498
|
+
const currencyOrUnit = (this.options.currency || this.options.unit || "").trim();
|
|
3499
|
+
if (!currencyOrUnit || this.options.disabled) {
|
|
3500
|
+
return warnings;
|
|
2908
3501
|
}
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
if (
|
|
2913
|
-
|
|
2914
|
-
|
|
3502
|
+
const describedbyWarnings = [];
|
|
3503
|
+
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings, true);
|
|
3504
|
+
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
3505
|
+
if (hasValidDescribedby || hasAriaPlaceholder) {
|
|
3506
|
+
return warnings;
|
|
3507
|
+
}
|
|
3508
|
+
const doc = this.input.ownerDocument || document;
|
|
3509
|
+
const root = typeof this.input.getRootNode === "function" ? this.input.getRootNode() : doc;
|
|
3510
|
+
const labelRoot = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : doc;
|
|
3511
|
+
let labelTexts = this.input.getAttribute("aria-label") || "";
|
|
3512
|
+
const labelledBy = this.input.getAttribute("aria-labelledby")?.trim();
|
|
3513
|
+
if (labelledBy) {
|
|
3514
|
+
for (const id of labelledBy.split(/\s+/).filter(Boolean)) {
|
|
3515
|
+
const target = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id);
|
|
3516
|
+
if (target?.textContent) labelTexts += " " + target.textContent;
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
const wrapping = this.input.closest("label");
|
|
3520
|
+
if (wrapping?.textContent) labelTexts += " " + wrapping.textContent;
|
|
3521
|
+
if (this.input.id) {
|
|
3522
|
+
try {
|
|
3523
|
+
const explicit = labelRoot.querySelector(`label[for="${safeCssEscape(this.input.id)}"]`);
|
|
3524
|
+
if (explicit?.textContent) labelTexts += " " + explicit.textContent;
|
|
3525
|
+
} catch {
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
const norm = labelTexts.toLowerCase();
|
|
3529
|
+
const token = currencyOrUnit.toLowerCase();
|
|
3530
|
+
const hasCurrencyAlias = norm.includes(token) || token === "\u20AC" && (norm.includes("euro") || norm.includes("eur")) || token === "$" && (norm.includes("dollar") || norm.includes("usd")) || token === "\xA3" && (norm.includes("livre") || norm.includes("pound") || norm.includes("gbp"));
|
|
3531
|
+
if (!hasCurrencyAlias) {
|
|
3532
|
+
warnings.push(
|
|
3533
|
+
`Devise/unit\xE9 "${currencyOrUnit}" non expos\xE9e aux technologies d'assistance quand le champ est vide (le fant\xF4me est aria-hidden="true") : mentionnez-la dans le <label>, aria-label ou aria-describedby (WCAG 3.3.2).`
|
|
3534
|
+
);
|
|
3535
|
+
}
|
|
3536
|
+
return warnings;
|
|
3537
|
+
}
|
|
3538
|
+
setValue(val) {
|
|
3539
|
+
const str = val !== null && val !== void 0 ? String(val) : "";
|
|
3540
|
+
if (this.options.disabled) {
|
|
3541
|
+
this.setNativeValue(str);
|
|
3542
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(str) : str;
|
|
3543
|
+
} else {
|
|
3544
|
+
this.applyAmount(str, str.length);
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
destroy() {
|
|
3548
|
+
if (this.isDestroyed) return;
|
|
3549
|
+
if (this.cutTimerId !== null) {
|
|
3550
|
+
clearTimeout(this.cutTimerId);
|
|
3551
|
+
this.cutTimerId = null;
|
|
2915
3552
|
}
|
|
2916
3553
|
if (this.resetTimerId !== null) {
|
|
2917
3554
|
clearTimeout(this.resetTimerId);
|
|
@@ -2971,7 +3608,8 @@ var __WulfIIFE = (() => {
|
|
|
2971
3608
|
"it"
|
|
2972
3609
|
];
|
|
2973
3610
|
constructor(options = {}) {
|
|
2974
|
-
|
|
3611
|
+
const customDomains = Array.isArray(options.domains) ? options.domains.slice(0, 500).map((d) => String(d ?? "").trim().slice(0, 253)).filter(Boolean) : [];
|
|
3612
|
+
this.domains = customDomains.length > 0 ? customDomains : _EmailEngine.DEFAULT_DOMAINS;
|
|
2975
3613
|
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];
|
|
2976
3614
|
this.suggestOnAt = options.suggestOnAt ?? true;
|
|
2977
3615
|
this.setDefaultDomain(options.defaultDomain ?? null);
|
|
@@ -2984,7 +3622,7 @@ var __WulfIIFE = (() => {
|
|
|
2984
3622
|
if (domain === true) {
|
|
2985
3623
|
this.defaultDomain = this.domains.length > 0 ? this.domains[0] : null;
|
|
2986
3624
|
} else if (typeof domain === "string" && domain.trim().length > 0) {
|
|
2987
|
-
this.defaultDomain = domain.trim().replace(/^@/, "");
|
|
3625
|
+
this.defaultDomain = domain.trim().replace(/^@/, "").slice(0, 253) || null;
|
|
2988
3626
|
} else {
|
|
2989
3627
|
this.defaultDomain = null;
|
|
2990
3628
|
}
|
|
@@ -2996,7 +3634,7 @@ var __WulfIIFE = (() => {
|
|
|
2996
3634
|
if (tld === true) {
|
|
2997
3635
|
this.defaultTld = this.tlds.length > 0 ? this.tlds[0] : null;
|
|
2998
3636
|
} else if (typeof tld === "string" && tld.trim().length > 0) {
|
|
2999
|
-
this.defaultTld = tld.trim().replace(/^\./, "");
|
|
3637
|
+
this.defaultTld = tld.trim().replace(/^\./, "").slice(0, 32) || null;
|
|
3000
3638
|
} else {
|
|
3001
3639
|
this.defaultTld = null;
|
|
3002
3640
|
}
|
|
@@ -3155,11 +3793,16 @@ var __WulfIIFE = (() => {
|
|
|
3155
3793
|
};
|
|
3156
3794
|
|
|
3157
3795
|
// src/mask/InputEmailMask.ts
|
|
3796
|
+
var MAX_NOTIFICATION_ITERATIONS2 = 10;
|
|
3158
3797
|
var InputEmailMask = class extends BaseInputMask {
|
|
3159
3798
|
engine;
|
|
3160
3799
|
currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3161
3800
|
currentSuggestionIndex = 0;
|
|
3801
|
+
hadInitialAriaAutocomplete = false;
|
|
3162
3802
|
wasAriaAutocompleteSet = false;
|
|
3803
|
+
isSuggestionDismissed = false;
|
|
3804
|
+
isNotifying = false;
|
|
3805
|
+
hasPendingNotification = false;
|
|
3163
3806
|
wasAutocorrectSet = false;
|
|
3164
3807
|
wasAutocapitalizeSet = false;
|
|
3165
3808
|
wasSpellcheckSet = false;
|
|
@@ -3212,18 +3855,42 @@ var __WulfIIFE = (() => {
|
|
|
3212
3855
|
this.input.setAttribute("spellcheck", "false");
|
|
3213
3856
|
this.wasSpellcheckSet = true;
|
|
3214
3857
|
}
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
this.wasAriaAutocompleteSet = true;
|
|
3218
|
-
}
|
|
3858
|
+
this.hadInitialAriaAutocomplete = this.input.hasAttribute("aria-autocomplete");
|
|
3859
|
+
this.syncAriaAutocomplete();
|
|
3219
3860
|
this.engine = new EmailEngine(this.options);
|
|
3220
|
-
this.lastNotifiedValue = this.
|
|
3861
|
+
this.lastNotifiedValue = this.isSensitiveField() ? "" : this.input.value;
|
|
3221
3862
|
this.bindEvents();
|
|
3222
|
-
if (!this.options.disabled && !this.
|
|
3863
|
+
if (!this.options.disabled && !this.isSensitiveField()) {
|
|
3223
3864
|
this.updateSuggestion();
|
|
3224
3865
|
}
|
|
3225
3866
|
this.runAuditWarning(this.options.audit);
|
|
3226
3867
|
}
|
|
3868
|
+
syncAriaAutocomplete() {
|
|
3869
|
+
const canSuggest = Boolean(
|
|
3870
|
+
this.options.setAriaAutocomplete && !this.options.disabled && !this.isSensitiveField() && !this.isDestroyed
|
|
3871
|
+
);
|
|
3872
|
+
if (!this.hadInitialAriaAutocomplete) {
|
|
3873
|
+
if (canSuggest) {
|
|
3874
|
+
if (!this.input.hasAttribute("aria-autocomplete")) {
|
|
3875
|
+
this.input.setAttribute("aria-autocomplete", "inline");
|
|
3876
|
+
this.wasAriaAutocompleteSet = true;
|
|
3877
|
+
}
|
|
3878
|
+
} else if (this.wasAriaAutocompleteSet) {
|
|
3879
|
+
if (this.input.getAttribute("aria-autocomplete") === "inline") {
|
|
3880
|
+
this.input.removeAttribute("aria-autocomplete");
|
|
3881
|
+
}
|
|
3882
|
+
this.wasAriaAutocompleteSet = false;
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
const doc = this.input.ownerDocument || (typeof document !== "undefined" ? document : null);
|
|
3886
|
+
const hasAriaNotify = Boolean(doc && typeof doc.ariaNotify === "function");
|
|
3887
|
+
if (canSuggest && !hasAriaNotify) {
|
|
3888
|
+
this.ensureSrStatusEl();
|
|
3889
|
+
} else if (!canSuggest && this.srStatusEl) {
|
|
3890
|
+
this.srStatusEl.remove();
|
|
3891
|
+
this.srStatusEl = null;
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3227
3894
|
onPasswordModeDetected() {
|
|
3228
3895
|
if (this.srAnnounceTimerId !== null) {
|
|
3229
3896
|
clearTimeout(this.srAnnounceTimerId);
|
|
@@ -3233,25 +3900,28 @@ var __WulfIIFE = (() => {
|
|
|
3233
3900
|
this.lastTrackedValue = "";
|
|
3234
3901
|
this.lastAnnouncedSuggestion = "";
|
|
3235
3902
|
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3236
|
-
|
|
3237
|
-
this.srStatusEl.textContent = "";
|
|
3238
|
-
}
|
|
3903
|
+
this.syncAriaAutocomplete();
|
|
3239
3904
|
this.clearGhost();
|
|
3240
3905
|
}
|
|
3241
3906
|
onNativeValueSet(_strVal) {
|
|
3242
|
-
if (this.options.disabled || this.isComposing || this.
|
|
3907
|
+
if (this.options.disabled || this.isComposing || this.isSensitiveField()) return;
|
|
3908
|
+
this.isSuggestionDismissed = false;
|
|
3243
3909
|
this.updateSuggestion();
|
|
3244
3910
|
}
|
|
3245
3911
|
onDisabledChange(disabled) {
|
|
3246
|
-
|
|
3912
|
+
this.syncAriaAutocomplete();
|
|
3913
|
+
if (disabled || this.isSensitiveField()) {
|
|
3914
|
+
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3247
3915
|
this.clearGhost();
|
|
3248
3916
|
} else {
|
|
3917
|
+
this.isSuggestionDismissed = false;
|
|
3249
3918
|
this.updateSuggestion();
|
|
3250
3919
|
}
|
|
3251
3920
|
}
|
|
3252
3921
|
bindEvents() {
|
|
3253
3922
|
this.handleInput = this.handleInput.bind(this);
|
|
3254
3923
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
3924
|
+
this.handlePaste = this.handlePaste.bind(this);
|
|
3255
3925
|
this.handleBlur = this.handleBlur.bind(this);
|
|
3256
3926
|
this.handleFocus = this.handleFocus.bind(this);
|
|
3257
3927
|
this.onCutHandler = () => {
|
|
@@ -3260,13 +3930,14 @@ var __WulfIIFE = (() => {
|
|
|
3260
3930
|
}
|
|
3261
3931
|
this.cutTimerId = window.setTimeout(() => {
|
|
3262
3932
|
this.cutTimerId = null;
|
|
3263
|
-
if (this.isDestroyed || this.options.disabled || this.
|
|
3933
|
+
if (this.isDestroyed || this.options.disabled || this.isSensitiveField()) return;
|
|
3264
3934
|
this.updateSuggestion();
|
|
3265
3935
|
}, 0);
|
|
3266
3936
|
};
|
|
3267
3937
|
const { signal } = this.abortController;
|
|
3268
3938
|
this.input.addEventListener("input", this.handleInput, { signal });
|
|
3269
3939
|
this.input.addEventListener("keydown", this.handleKeyDown, { signal });
|
|
3940
|
+
this.input.addEventListener("paste", this.handlePaste, { signal });
|
|
3270
3941
|
this.input.addEventListener("blur", this.handleBlur, { signal });
|
|
3271
3942
|
this.input.addEventListener("focus", this.handleFocus, { signal });
|
|
3272
3943
|
this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
|
|
@@ -3276,7 +3947,7 @@ var __WulfIIFE = (() => {
|
|
|
3276
3947
|
}, { signal });
|
|
3277
3948
|
this.input.addEventListener("compositionend", () => {
|
|
3278
3949
|
this.isComposing = false;
|
|
3279
|
-
if (!this.isDestroyed && !this.options.disabled && !this.
|
|
3950
|
+
if (!this.isDestroyed && !this.options.disabled && !this.isSensitiveField()) {
|
|
3280
3951
|
this.handleInput();
|
|
3281
3952
|
}
|
|
3282
3953
|
}, { signal });
|
|
@@ -3287,7 +3958,7 @@ var __WulfIIFE = (() => {
|
|
|
3287
3958
|
}
|
|
3288
3959
|
this.resetTimerId = window.setTimeout(() => {
|
|
3289
3960
|
this.resetTimerId = null;
|
|
3290
|
-
if (this.isDestroyed || this.options.disabled || this.
|
|
3961
|
+
if (this.isDestroyed || this.options.disabled || this.isSensitiveField()) return;
|
|
3291
3962
|
this.updateSuggestion();
|
|
3292
3963
|
}, 0);
|
|
3293
3964
|
};
|
|
@@ -3313,7 +3984,7 @@ var __WulfIIFE = (() => {
|
|
|
3313
3984
|
clearTimeout(this.srAnnounceTimerId);
|
|
3314
3985
|
this.srAnnounceTimerId = null;
|
|
3315
3986
|
}
|
|
3316
|
-
if (!this.options.setAriaAutocomplete || !this.isFocused || this.isDestroyed || this.
|
|
3987
|
+
if (!this.options.setAriaAutocomplete || !this.isFocused || this.isDestroyed || this.isSensitiveField()) {
|
|
3317
3988
|
return;
|
|
3318
3989
|
}
|
|
3319
3990
|
const suggestion = this.currentSuggestion;
|
|
@@ -3330,7 +4001,7 @@ var __WulfIIFE = (() => {
|
|
|
3330
4001
|
}
|
|
3331
4002
|
const run = () => {
|
|
3332
4003
|
this.srAnnounceTimerId = null;
|
|
3333
|
-
if (this.isDestroyed || !this.isFocused || this.
|
|
4004
|
+
if (this.isDestroyed || !this.isFocused || this.isSensitiveField()) return;
|
|
3334
4005
|
this.lastAnnouncedSuggestion = textToAnnounce;
|
|
3335
4006
|
const doc = this.input.ownerDocument || (typeof document !== "undefined" ? document : null);
|
|
3336
4007
|
const docWithAriaNotify = doc;
|
|
@@ -3353,13 +4024,13 @@ var __WulfIIFE = (() => {
|
|
|
3353
4024
|
}
|
|
3354
4025
|
}
|
|
3355
4026
|
updateSuggestion(announceOptions) {
|
|
3356
|
-
if (this.options.disabled || this.
|
|
4027
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
3357
4028
|
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3358
4029
|
this.clearGhost();
|
|
3359
4030
|
return;
|
|
3360
4031
|
}
|
|
3361
4032
|
const val = this.input.value;
|
|
3362
|
-
this.currentSuggestion = this.engine.getSuggestion(val, this.currentSuggestionIndex);
|
|
4033
|
+
this.currentSuggestion = this.isSuggestionDismissed ? { full: val, remaining: "", matchedDomain: null } : this.engine.getSuggestion(val, this.currentSuggestionIndex);
|
|
3363
4034
|
if (!this.ghost) return;
|
|
3364
4035
|
if (this.shouldHideGhostForPlaceholder(val.length === 0)) {
|
|
3365
4036
|
this.clearGhost();
|
|
@@ -3379,19 +4050,39 @@ var __WulfIIFE = (() => {
|
|
|
3379
4050
|
if (announceOptions?.announce) {
|
|
3380
4051
|
this.scheduleSuggestionAnnouncement(Boolean(announceOptions.immediate));
|
|
3381
4052
|
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
4053
|
+
this.notifyValueChange();
|
|
4054
|
+
}
|
|
4055
|
+
notifyValueChange() {
|
|
4056
|
+
if (this.isNotifying) {
|
|
4057
|
+
this.hasPendingNotification = true;
|
|
4058
|
+
return;
|
|
3385
4059
|
}
|
|
3386
|
-
this.
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
4060
|
+
this.isNotifying = true;
|
|
4061
|
+
try {
|
|
4062
|
+
let iterations = 0;
|
|
4063
|
+
do {
|
|
4064
|
+
iterations++;
|
|
4065
|
+
this.hasPendingNotification = false;
|
|
4066
|
+
const sensitiveNow = this.isSensitiveField();
|
|
4067
|
+
const allowBubble = !sensitiveNow;
|
|
4068
|
+
const valNow = this.input.value;
|
|
4069
|
+
const detail = this.getDetail();
|
|
4070
|
+
if (this.options.onInput) {
|
|
4071
|
+
this.options.onInput(detail);
|
|
4072
|
+
}
|
|
4073
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: allowBubble, detail }));
|
|
4074
|
+
if (valNow !== this.lastNotifiedValue) {
|
|
4075
|
+
this.lastNotifiedValue = sensitiveNow ? "" : valNow;
|
|
4076
|
+
this.dispatchNativeInput();
|
|
4077
|
+
}
|
|
4078
|
+
} while (this.hasPendingNotification && iterations < MAX_NOTIFICATION_ITERATIONS2);
|
|
4079
|
+
} finally {
|
|
4080
|
+
this.isNotifying = false;
|
|
3390
4081
|
}
|
|
3391
4082
|
}
|
|
3392
4083
|
handleInput(e) {
|
|
3393
4084
|
if (this.isDispatchingNativeInput) return;
|
|
3394
|
-
if (this.options.disabled || this.
|
|
4085
|
+
if (this.options.disabled || this.isSensitiveField()) return;
|
|
3395
4086
|
if (this.isComposing || e && "isComposing" in e && e.isComposing) return;
|
|
3396
4087
|
if (this.options.autoLowercase) {
|
|
3397
4088
|
const start = this.input.selectionStart ?? 0;
|
|
@@ -3402,16 +4093,60 @@ var __WulfIIFE = (() => {
|
|
|
3402
4093
|
this.input.setSelectionRange(start, end);
|
|
3403
4094
|
}
|
|
3404
4095
|
}
|
|
4096
|
+
this.isSuggestionDismissed = false;
|
|
3405
4097
|
this.currentSuggestionIndex = 0;
|
|
3406
4098
|
this.updateSuggestion({ announce: true, immediate: false });
|
|
3407
4099
|
}
|
|
4100
|
+
handlePaste(e) {
|
|
4101
|
+
if (this.options.disabled || this.isSensitiveField()) return;
|
|
4102
|
+
const raw = this.getClipboardPlainText(e);
|
|
4103
|
+
const prepared = this.preparePastedText(raw, 512);
|
|
4104
|
+
if (prepared === raw) {
|
|
4105
|
+
return;
|
|
4106
|
+
}
|
|
4107
|
+
e.preventDefault();
|
|
4108
|
+
const start = this.input.selectionStart ?? this.input.value.length;
|
|
4109
|
+
const end = this.input.selectionEnd ?? start;
|
|
4110
|
+
const before = this.input.value.slice(0, start);
|
|
4111
|
+
const after = this.input.value.slice(end);
|
|
4112
|
+
const expected = before + prepared + after;
|
|
4113
|
+
const finalExpected = this.options.autoLowercase ? expected.toLowerCase() : expected;
|
|
4114
|
+
if (typeof document !== "undefined" && getDeepActiveElement(this.input.ownerDocument) === this.input && typeof document.execCommand === "function") {
|
|
4115
|
+
try {
|
|
4116
|
+
const execOk = document.execCommand("insertText", false, prepared);
|
|
4117
|
+
if (execOk && this.input.value === finalExpected) {
|
|
4118
|
+
return;
|
|
4119
|
+
}
|
|
4120
|
+
} catch {
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
this.setNativeValue(expected);
|
|
4124
|
+
const nextCursor = start + prepared.length;
|
|
4125
|
+
this.input.setSelectionRange(nextCursor, nextCursor);
|
|
4126
|
+
this.handleInput();
|
|
4127
|
+
}
|
|
3408
4128
|
handleKeyDown(e) {
|
|
3409
|
-
if (this.options.disabled || this.
|
|
4129
|
+
if (this.options.disabled || this.isSensitiveField() || isImeComposing(e)) return;
|
|
3410
4130
|
if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return;
|
|
3411
4131
|
const hasSuggestion = Boolean(this.currentSuggestion.remaining) && !this.currentSuggestion.isHintOnly;
|
|
3412
4132
|
const cursor = this.input.selectionStart ?? 0;
|
|
3413
4133
|
const isAtEnd = cursor === this.input.value.length;
|
|
3414
4134
|
const isNotEmpty = this.input.value.length > 0;
|
|
4135
|
+
if (e.key === "Escape" && hasSuggestion) {
|
|
4136
|
+
e.preventDefault();
|
|
4137
|
+
this.isSuggestionDismissed = true;
|
|
4138
|
+
this.currentSuggestion = { full: this.input.value, remaining: "", matchedDomain: null };
|
|
4139
|
+
if (this.srAnnounceTimerId !== null) {
|
|
4140
|
+
clearTimeout(this.srAnnounceTimerId);
|
|
4141
|
+
this.srAnnounceTimerId = null;
|
|
4142
|
+
}
|
|
4143
|
+
this.lastAnnouncedSuggestion = "";
|
|
4144
|
+
if (this.srStatusEl) {
|
|
4145
|
+
this.srStatusEl.textContent = "";
|
|
4146
|
+
}
|
|
4147
|
+
this.clearGhost();
|
|
4148
|
+
return;
|
|
4149
|
+
}
|
|
3415
4150
|
if (this.options.cycleSuggestions && hasSuggestion && isNotEmpty && isAtEnd) {
|
|
3416
4151
|
if (e.key === "ArrowDown") {
|
|
3417
4152
|
e.preventDefault();
|
|
@@ -3419,161 +4154,2072 @@ var __WulfIIFE = (() => {
|
|
|
3419
4154
|
this.updateSuggestion({ announce: true, immediate: true });
|
|
3420
4155
|
return;
|
|
3421
4156
|
}
|
|
3422
|
-
if (e.key === "ArrowUp") {
|
|
3423
|
-
e.preventDefault();
|
|
3424
|
-
this.currentSuggestionIndex--;
|
|
3425
|
-
this.updateSuggestion({ announce: true, immediate: true });
|
|
4157
|
+
if (e.key === "ArrowUp") {
|
|
4158
|
+
e.preventDefault();
|
|
4159
|
+
this.currentSuggestionIndex--;
|
|
4160
|
+
this.updateSuggestion({ announce: true, immediate: true });
|
|
4161
|
+
return;
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4164
|
+
if (e.key === "Tab" && hasSuggestion && isNotEmpty && this.options.completeOnTab) {
|
|
4165
|
+
e.preventDefault();
|
|
4166
|
+
this.acceptSuggestion();
|
|
4167
|
+
return;
|
|
4168
|
+
}
|
|
4169
|
+
if (e.key === "Enter" && hasSuggestion && isNotEmpty && this.options.completeOnEnter) {
|
|
4170
|
+
e.preventDefault();
|
|
4171
|
+
this.acceptSuggestion();
|
|
4172
|
+
return;
|
|
4173
|
+
}
|
|
4174
|
+
if (e.key === "ArrowRight" && hasSuggestion && isNotEmpty && isAtEnd && this.options.completeOnArrowRight) {
|
|
4175
|
+
e.preventDefault();
|
|
4176
|
+
this.acceptSuggestion();
|
|
4177
|
+
return;
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
4180
|
+
/**
|
|
4181
|
+
* Valide et applique la suggestion courante dans le champ natif.
|
|
4182
|
+
*/
|
|
4183
|
+
acceptSuggestion() {
|
|
4184
|
+
if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.isSensitiveField() || this.input.value.length === 0) {
|
|
4185
|
+
return false;
|
|
4186
|
+
}
|
|
4187
|
+
const completed = this.currentSuggestion.full;
|
|
4188
|
+
this.setNativeValue(completed);
|
|
4189
|
+
this.input.setSelectionRange(completed.length, completed.length);
|
|
4190
|
+
this.currentSuggestionIndex = 0;
|
|
4191
|
+
this.updateSuggestion();
|
|
4192
|
+
const detail = this.getDetail();
|
|
4193
|
+
if (this.options.onChange) {
|
|
4194
|
+
this.options.onChange(detail);
|
|
4195
|
+
}
|
|
4196
|
+
const allowBubble = !this.isSensitiveField();
|
|
4197
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
4198
|
+
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles: allowBubble, detail }));
|
|
4199
|
+
return true;
|
|
4200
|
+
}
|
|
4201
|
+
/**
|
|
4202
|
+
* Modifie dynamiquement le domaine suggéré par défaut.
|
|
4203
|
+
*/
|
|
4204
|
+
setDefaultDomain(domain) {
|
|
4205
|
+
this.engine.setDefaultDomain(domain);
|
|
4206
|
+
this.updateSuggestion();
|
|
4207
|
+
}
|
|
4208
|
+
/**
|
|
4209
|
+
* Modifie dynamiquement l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
|
|
4210
|
+
*/
|
|
4211
|
+
setDefaultTld(tld) {
|
|
4212
|
+
this.engine.setDefaultTld(tld);
|
|
4213
|
+
this.updateSuggestion();
|
|
4214
|
+
}
|
|
4215
|
+
/**
|
|
4216
|
+
* Modifie dynamiquement la liste des extensions (TLD) connues.
|
|
4217
|
+
*/
|
|
4218
|
+
setTlds(tlds) {
|
|
4219
|
+
this.engine.setTlds(tlds);
|
|
4220
|
+
this.currentSuggestionIndex = 0;
|
|
4221
|
+
this.updateSuggestion();
|
|
4222
|
+
}
|
|
4223
|
+
handleFocus() {
|
|
4224
|
+
this.wrapper.classList.add("is-focused");
|
|
4225
|
+
this.isSuggestionDismissed = false;
|
|
4226
|
+
this.syncGhostStyles();
|
|
4227
|
+
this.updateSuggestion();
|
|
4228
|
+
}
|
|
4229
|
+
handleBlur() {
|
|
4230
|
+
this.wrapper.classList.remove("is-focused");
|
|
4231
|
+
if (this.srAnnounceTimerId !== null) {
|
|
4232
|
+
clearTimeout(this.srAnnounceTimerId);
|
|
4233
|
+
this.srAnnounceTimerId = null;
|
|
4234
|
+
}
|
|
4235
|
+
this.lastAnnouncedSuggestion = "";
|
|
4236
|
+
if (this.srStatusEl) {
|
|
4237
|
+
this.srStatusEl.textContent = "";
|
|
4238
|
+
}
|
|
4239
|
+
if (this.isSensitiveField()) {
|
|
4240
|
+
this.lastNotifiedValue = "";
|
|
4241
|
+
this.lastTrackedValue = "";
|
|
4242
|
+
this.clearGhost();
|
|
4243
|
+
return;
|
|
4244
|
+
}
|
|
4245
|
+
this.updateSuggestion();
|
|
4246
|
+
const detail = this.getDetail();
|
|
4247
|
+
if (this.options.onChange) {
|
|
4248
|
+
this.options.onChange(detail);
|
|
4249
|
+
}
|
|
4250
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: !this.isSensitiveField(), detail }));
|
|
4251
|
+
}
|
|
4252
|
+
handleAttributeMutation(attrName) {
|
|
4253
|
+
super.handleAttributeMutation(attrName);
|
|
4254
|
+
if (attrName === "data-mask-cycle-suggestions") {
|
|
4255
|
+
this.options.cycleSuggestions = this.getAttr("data-mask-cycle-suggestions") === "true";
|
|
4256
|
+
} else if (attrName === "data-mask-auto-lowercase") {
|
|
4257
|
+
this.options.autoLowercase = this.getAttr("data-mask-auto-lowercase") === "true";
|
|
4258
|
+
} else if (attrName === "data-mask-default-tld") {
|
|
4259
|
+
const val = this.getAttr("data-mask-default-tld");
|
|
4260
|
+
this.setDefaultTld(val === null || val === "false" || val === "none" ? null : val === "true" ? true : val);
|
|
4261
|
+
} else if (attrName === "data-mask-tlds") {
|
|
4262
|
+
const val = this.getAttr("data-mask-tlds");
|
|
4263
|
+
this.setTlds(val ? val.split(",").map((s) => s.trim()).filter(Boolean) : null);
|
|
4264
|
+
} else if (attrName === "placeholder") {
|
|
4265
|
+
this.updateSuggestion();
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
getDetail() {
|
|
4269
|
+
return {
|
|
4270
|
+
value: this.input.value,
|
|
4271
|
+
suggestedValue: this.currentSuggestion.isHintOnly ? "" : this.currentSuggestion.full,
|
|
4272
|
+
domain: this.currentSuggestion.matchedDomain
|
|
4273
|
+
};
|
|
4274
|
+
}
|
|
4275
|
+
setValue(val) {
|
|
4276
|
+
const str = val !== null && val !== void 0 ? String(val) : "";
|
|
4277
|
+
this.isSuggestionDismissed = false;
|
|
4278
|
+
this.setNativeValue(str);
|
|
4279
|
+
this.updateSuggestion();
|
|
4280
|
+
}
|
|
4281
|
+
destroy() {
|
|
4282
|
+
if (this.isDestroyed) return;
|
|
4283
|
+
if (this.cutTimerId !== null) {
|
|
4284
|
+
clearTimeout(this.cutTimerId);
|
|
4285
|
+
this.cutTimerId = null;
|
|
4286
|
+
}
|
|
4287
|
+
if (this.resetTimerId !== null) {
|
|
4288
|
+
clearTimeout(this.resetTimerId);
|
|
4289
|
+
this.resetTimerId = null;
|
|
4290
|
+
}
|
|
4291
|
+
if (this.srAnnounceTimerId !== null) {
|
|
4292
|
+
clearTimeout(this.srAnnounceTimerId);
|
|
4293
|
+
this.srAnnounceTimerId = null;
|
|
4294
|
+
}
|
|
4295
|
+
if (this.srStatusEl) {
|
|
4296
|
+
this.srStatusEl.remove();
|
|
4297
|
+
this.srStatusEl = null;
|
|
4298
|
+
}
|
|
4299
|
+
this.lastNotifiedValue = "";
|
|
4300
|
+
this.lastAnnouncedSuggestion = "";
|
|
4301
|
+
if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "email") {
|
|
4302
|
+
this.input.removeAttribute("inputmode");
|
|
4303
|
+
}
|
|
4304
|
+
if (this.wasAriaAutocompleteSet && this.input.getAttribute("aria-autocomplete") === "inline") {
|
|
4305
|
+
this.input.removeAttribute("aria-autocomplete");
|
|
4306
|
+
}
|
|
4307
|
+
if (this.wasAutocorrectSet && this.input.getAttribute("autocorrect") === "off") {
|
|
4308
|
+
this.input.removeAttribute("autocorrect");
|
|
4309
|
+
}
|
|
4310
|
+
if (this.wasAutocapitalizeSet && this.input.getAttribute("autocapitalize") === "none") {
|
|
4311
|
+
this.input.removeAttribute("autocapitalize");
|
|
4312
|
+
}
|
|
4313
|
+
if (this.wasSpellcheckSet && this.input.getAttribute("spellcheck") === "false") {
|
|
4314
|
+
this.input.removeAttribute("spellcheck");
|
|
4315
|
+
}
|
|
4316
|
+
super.destroy();
|
|
4317
|
+
}
|
|
4318
|
+
};
|
|
4319
|
+
|
|
4320
|
+
// src/mask/DateUTCEngine.ts
|
|
4321
|
+
var DATE_UTC_PRESETS = {
|
|
4322
|
+
iso: { format: "YYYY-MM-DD HH:mm:ss" },
|
|
4323
|
+
"iso-t": { format: "YYYY-MM-DD\\THH:mm:ss" },
|
|
4324
|
+
fr: {
|
|
4325
|
+
format: "DD/MM/YYYY HH:mm",
|
|
4326
|
+
placeholderTokens: { DD: "jj", MM: "mm", YYYY: "aaaa", HH: "hh", mm: "mm" }
|
|
4327
|
+
},
|
|
4328
|
+
"fr-sec": {
|
|
4329
|
+
format: "DD/MM/YYYY HH:mm:ss",
|
|
4330
|
+
placeholderTokens: { DD: "jj", MM: "mm", YYYY: "aaaa", HH: "hh", mm: "mm", ss: "ss" }
|
|
4331
|
+
},
|
|
4332
|
+
us: { format: "MM/DD/YYYY HH:mm" },
|
|
4333
|
+
"us-12h": { format: "MM/DD/YYYY hh:mm A" },
|
|
4334
|
+
uk: { format: "DD/MM/YYYY HH:mm" },
|
|
4335
|
+
no: { format: "DD/MM-YYYY HH:mm" },
|
|
4336
|
+
cz: { format: "DD. MM. YYYY HH:mm" },
|
|
4337
|
+
de: { format: "DD.MM.YYYY HH:mm" },
|
|
4338
|
+
jp: { format: "YYYY/MM/DD HH:mm" }
|
|
4339
|
+
};
|
|
4340
|
+
var DEFAULT_PLACEHOLDERS = {
|
|
4341
|
+
YYYY: "YYYY",
|
|
4342
|
+
MM: "MM",
|
|
4343
|
+
DD: "DD",
|
|
4344
|
+
HH: "HH",
|
|
4345
|
+
hh: "hh",
|
|
4346
|
+
mm: "mm",
|
|
4347
|
+
ss: "ss",
|
|
4348
|
+
A: "AM"
|
|
4349
|
+
};
|
|
4350
|
+
var TOKEN_DEFS = [
|
|
4351
|
+
{ token: "YYYY", length: 4 },
|
|
4352
|
+
{ token: "MM", length: 2 },
|
|
4353
|
+
{ token: "DD", length: 2 },
|
|
4354
|
+
{ token: "HH", length: 2 },
|
|
4355
|
+
{ token: "hh", length: 2 },
|
|
4356
|
+
{ token: "mm", length: 2 },
|
|
4357
|
+
{ token: "ss", length: 2 },
|
|
4358
|
+
{ token: "A", length: 2 }
|
|
4359
|
+
];
|
|
4360
|
+
var MAX_FORMAT_LENGTH = 128;
|
|
4361
|
+
var MAX_INPUT_LENGTH = 512;
|
|
4362
|
+
var DATE_SEPARATORS = /* @__PURE__ */ new Set(["/", "-", ".", ":", " ", "T", "t"]);
|
|
4363
|
+
var TIME_TOKEN_KINDS = /* @__PURE__ */ new Set(["HH", "hh", "mm", "ss", "A"]);
|
|
4364
|
+
function isAsciiDigit(ch) {
|
|
4365
|
+
return ch >= "0" && ch <= "9";
|
|
4366
|
+
}
|
|
4367
|
+
function parseAsciiInt(str) {
|
|
4368
|
+
let val = 0;
|
|
4369
|
+
for (let i = 0; i < str.length; i++) {
|
|
4370
|
+
const code = str.charCodeAt(i);
|
|
4371
|
+
if (code < 48 || code > 57) return NaN;
|
|
4372
|
+
val = val * 10 + (code - 48);
|
|
4373
|
+
}
|
|
4374
|
+
return str.length > 0 ? val : NaN;
|
|
4375
|
+
}
|
|
4376
|
+
function normalizeSegmentPlaceholder(raw, length, fallback) {
|
|
4377
|
+
const graphemes = Array.from(raw || fallback);
|
|
4378
|
+
const fb = Array.from(fallback);
|
|
4379
|
+
while (graphemes.length < length) {
|
|
4380
|
+
graphemes.push(fb[graphemes.length] || fb[fb.length - 1] || "_");
|
|
4381
|
+
}
|
|
4382
|
+
return graphemes.slice(0, length).join("");
|
|
4383
|
+
}
|
|
4384
|
+
var DateUTCEngine = class _DateUTCEngine {
|
|
4385
|
+
formatSpec = "YYYY-MM-DD HH:mm";
|
|
4386
|
+
customPlaceholders = {};
|
|
4387
|
+
slots = [];
|
|
4388
|
+
segments = [];
|
|
4389
|
+
fullTemplate = "";
|
|
4390
|
+
prefixSlotsCount = 0;
|
|
4391
|
+
prefixString = "";
|
|
4392
|
+
editableCount = 0;
|
|
4393
|
+
hasMeridiemFlag = false;
|
|
4394
|
+
utcIndicator = " UTC";
|
|
4395
|
+
includeMilliseconds = false;
|
|
4396
|
+
convertPastedOffset = true;
|
|
4397
|
+
defaultTimeOnDateOnly = false;
|
|
4398
|
+
minTs = null;
|
|
4399
|
+
maxTs = null;
|
|
4400
|
+
constructor(options = {}) {
|
|
4401
|
+
this.updateOptions(options);
|
|
4402
|
+
}
|
|
4403
|
+
/**
|
|
4404
|
+
* Formate statiquement une date (Date, timestamp ms, ISO ou chaîne) selon les options données.
|
|
4405
|
+
*/
|
|
4406
|
+
static format(value, options = {}) {
|
|
4407
|
+
const engine = new _DateUTCEngine(options);
|
|
4408
|
+
return engine.formatFromValue(value);
|
|
4409
|
+
}
|
|
4410
|
+
updateOptions(options = {}) {
|
|
4411
|
+
if (options.utcIndicator !== void 0) {
|
|
4412
|
+
this.utcIndicator = options.utcIndicator === false ? false : String(options.utcIndicator).slice(0, 32);
|
|
4413
|
+
}
|
|
4414
|
+
if (options.includeMilliseconds !== void 0) {
|
|
4415
|
+
this.includeMilliseconds = Boolean(options.includeMilliseconds);
|
|
4416
|
+
}
|
|
4417
|
+
if (options.convertPastedOffset !== void 0) {
|
|
4418
|
+
this.convertPastedOffset = options.convertPastedOffset !== false;
|
|
4419
|
+
}
|
|
4420
|
+
if (options.defaultTimeOnDateOnly !== void 0) {
|
|
4421
|
+
this.defaultTimeOnDateOnly = options.defaultTimeOnDateOnly;
|
|
4422
|
+
}
|
|
4423
|
+
if (options.min !== void 0) {
|
|
4424
|
+
this.minTs = this.normalizeBoundary(options.min);
|
|
4425
|
+
}
|
|
4426
|
+
if (options.max !== void 0) {
|
|
4427
|
+
this.maxTs = this.normalizeBoundary(options.max);
|
|
4428
|
+
}
|
|
4429
|
+
if (options.placeholderTokens !== void 0) {
|
|
4430
|
+
this.customPlaceholders = options.placeholderTokens || {};
|
|
4431
|
+
}
|
|
4432
|
+
if (options.format !== void 0 || this.slots.length === 0) {
|
|
4433
|
+
this.compile(options.format ?? this.formatSpec, options.placeholderTokens);
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
setFormat(format, placeholderTokens) {
|
|
4437
|
+
if (placeholderTokens !== void 0) {
|
|
4438
|
+
this.customPlaceholders = placeholderTokens;
|
|
4439
|
+
}
|
|
4440
|
+
this.compile(format, this.customPlaceholders);
|
|
4441
|
+
}
|
|
4442
|
+
setUtcIndicator(indicator) {
|
|
4443
|
+
this.utcIndicator = indicator === false ? false : String(indicator).slice(0, 32);
|
|
4444
|
+
}
|
|
4445
|
+
getUtcIndicator() {
|
|
4446
|
+
return this.utcIndicator;
|
|
4447
|
+
}
|
|
4448
|
+
getFormat() {
|
|
4449
|
+
return this.formatSpec;
|
|
4450
|
+
}
|
|
4451
|
+
getFullTemplate() {
|
|
4452
|
+
return this.fullTemplate;
|
|
4453
|
+
}
|
|
4454
|
+
getGhostRemaining(formatted) {
|
|
4455
|
+
const suffix = this.utcIndicator ? this.utcIndicator : "";
|
|
4456
|
+
if (formatted.length >= this.fullTemplate.length) {
|
|
4457
|
+
return suffix;
|
|
4458
|
+
}
|
|
4459
|
+
return this.fullTemplate.slice(formatted.length) + suffix;
|
|
4460
|
+
}
|
|
4461
|
+
getPrefix() {
|
|
4462
|
+
return this.prefixString;
|
|
4463
|
+
}
|
|
4464
|
+
getPrefixLength() {
|
|
4465
|
+
return this.prefixSlotsCount;
|
|
4466
|
+
}
|
|
4467
|
+
getEditableCount() {
|
|
4468
|
+
return this.editableCount;
|
|
4469
|
+
}
|
|
4470
|
+
hasMeridiem() {
|
|
4471
|
+
return this.hasMeridiemFlag;
|
|
4472
|
+
}
|
|
4473
|
+
isNumericOnly() {
|
|
4474
|
+
return !this.hasMeridiemFlag;
|
|
4475
|
+
}
|
|
4476
|
+
getSegments() {
|
|
4477
|
+
return this.segments;
|
|
4478
|
+
}
|
|
4479
|
+
getSlots() {
|
|
4480
|
+
return this.slots;
|
|
4481
|
+
}
|
|
4482
|
+
isSeparatorAt(idx) {
|
|
4483
|
+
return idx >= 0 && idx < this.slots.length && this.slots[idx].isStatic;
|
|
4484
|
+
}
|
|
4485
|
+
getNextEditablePosition(fromIdx) {
|
|
4486
|
+
const start = Math.max(0, fromIdx);
|
|
4487
|
+
for (let i = start; i < this.slots.length; i++) {
|
|
4488
|
+
if (!this.slots[i].isStatic) return i;
|
|
4489
|
+
}
|
|
4490
|
+
return this.slots.length;
|
|
4491
|
+
}
|
|
4492
|
+
compile(format, overridePlaceholders) {
|
|
4493
|
+
const rawSpec = String(format || "YYYY-MM-DD HH:mm").trim().slice(0, MAX_FORMAT_LENGTH) || "YYYY-MM-DD HH:mm";
|
|
4494
|
+
this.formatSpec = rawSpec;
|
|
4495
|
+
const preset = Object.hasOwn(DATE_UTC_PRESETS, rawSpec) ? DATE_UTC_PRESETS[rawSpec] : null;
|
|
4496
|
+
const pattern = preset ? preset.format : rawSpec;
|
|
4497
|
+
const mergedPlaceholders = /* @__PURE__ */ Object.create(null);
|
|
4498
|
+
if (preset?.placeholderTokens) {
|
|
4499
|
+
for (const [k, v] of Object.entries(preset.placeholderTokens)) {
|
|
4500
|
+
if (Object.hasOwn(DEFAULT_PLACEHOLDERS, k) && typeof v === "string") {
|
|
4501
|
+
mergedPlaceholders[k] = v;
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
}
|
|
4505
|
+
const sourceOverrides = overridePlaceholders !== void 0 ? overridePlaceholders : this.customPlaceholders;
|
|
4506
|
+
if (sourceOverrides && typeof sourceOverrides === "object") {
|
|
4507
|
+
for (const [k, v] of Object.entries(sourceOverrides)) {
|
|
4508
|
+
if (Object.hasOwn(DEFAULT_PLACEHOLDERS, k) && typeof v === "string") {
|
|
4509
|
+
mergedPlaceholders[k] = v;
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
this.slots = [];
|
|
4514
|
+
this.segments = [];
|
|
4515
|
+
this.hasMeridiemFlag = false;
|
|
4516
|
+
let template = "";
|
|
4517
|
+
let isPrefixMode = true;
|
|
4518
|
+
let i = 0;
|
|
4519
|
+
while (i < pattern.length) {
|
|
4520
|
+
const ch = pattern[i];
|
|
4521
|
+
if (ch === "\\" && i + 1 < pattern.length) {
|
|
4522
|
+
const lit = pattern[i + 1];
|
|
4523
|
+
this.slots.push({
|
|
4524
|
+
char: lit,
|
|
4525
|
+
isStatic: true,
|
|
4526
|
+
isPrefix: isPrefixMode,
|
|
4527
|
+
segmentIndex: -1,
|
|
4528
|
+
charIndexInSegment: -1,
|
|
4529
|
+
placeholder: lit
|
|
4530
|
+
});
|
|
4531
|
+
template += lit;
|
|
4532
|
+
i += 2;
|
|
4533
|
+
continue;
|
|
4534
|
+
}
|
|
4535
|
+
let matchedToken = null;
|
|
4536
|
+
for (const def of TOKEN_DEFS) {
|
|
4537
|
+
if (pattern.startsWith(def.token, i)) {
|
|
4538
|
+
matchedToken = def;
|
|
4539
|
+
break;
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4542
|
+
if (matchedToken) {
|
|
4543
|
+
isPrefixMode = false;
|
|
4544
|
+
const { token, length } = matchedToken;
|
|
4545
|
+
if (token === "A") {
|
|
4546
|
+
this.hasMeridiemFlag = true;
|
|
4547
|
+
}
|
|
4548
|
+
const phRaw = mergedPlaceholders[token] ?? DEFAULT_PLACEHOLDERS[token];
|
|
4549
|
+
const ph = normalizeSegmentPlaceholder(phRaw, length, DEFAULT_PLACEHOLDERS[token]);
|
|
4550
|
+
const phChars = Array.from(ph);
|
|
4551
|
+
const segIdx = this.segments.length;
|
|
4552
|
+
const start = this.slots.length;
|
|
4553
|
+
for (let k = 0; k < length; k++) {
|
|
4554
|
+
this.slots.push({
|
|
4555
|
+
char: token === "A" ? "A" : "9",
|
|
4556
|
+
isStatic: false,
|
|
4557
|
+
isPrefix: false,
|
|
4558
|
+
segmentIndex: segIdx,
|
|
4559
|
+
charIndexInSegment: k,
|
|
4560
|
+
tokenKind: token,
|
|
4561
|
+
placeholder: phChars[k] || "_"
|
|
4562
|
+
});
|
|
4563
|
+
}
|
|
4564
|
+
this.segments.push({
|
|
4565
|
+
kind: token,
|
|
4566
|
+
start,
|
|
4567
|
+
end: start + length,
|
|
4568
|
+
length,
|
|
4569
|
+
placeholder: ph,
|
|
4570
|
+
followingSeparator: ""
|
|
4571
|
+
});
|
|
4572
|
+
template += ph;
|
|
4573
|
+
i += token.length;
|
|
4574
|
+
} else {
|
|
4575
|
+
this.slots.push({
|
|
4576
|
+
char: ch,
|
|
4577
|
+
isStatic: true,
|
|
4578
|
+
isPrefix: isPrefixMode,
|
|
4579
|
+
segmentIndex: -1,
|
|
4580
|
+
charIndexInSegment: -1,
|
|
4581
|
+
placeholder: ch
|
|
4582
|
+
});
|
|
4583
|
+
template += ch;
|
|
4584
|
+
i++;
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
this.fullTemplate = template;
|
|
4588
|
+
this.editableCount = this.slots.filter((s) => !s.isStatic).length;
|
|
4589
|
+
this.prefixSlotsCount = 0;
|
|
4590
|
+
this.prefixString = "";
|
|
4591
|
+
for (const slot of this.slots) {
|
|
4592
|
+
if (slot.isPrefix) {
|
|
4593
|
+
this.prefixSlotsCount++;
|
|
4594
|
+
this.prefixString += slot.char;
|
|
4595
|
+
} else {
|
|
4596
|
+
break;
|
|
4597
|
+
}
|
|
4598
|
+
}
|
|
4599
|
+
for (let s = 0; s < this.segments.length; s++) {
|
|
4600
|
+
const seg = this.segments[s];
|
|
4601
|
+
let sep = "";
|
|
4602
|
+
for (let pos = seg.end; pos < this.slots.length && this.slots[pos].isStatic; pos++) {
|
|
4603
|
+
sep += this.slots[pos].char;
|
|
4604
|
+
}
|
|
4605
|
+
seg.followingSeparator = sep;
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
/**
|
|
4609
|
+
* Extrait linéairement les caractères bruts valides alignés sur les slots.
|
|
4610
|
+
*/
|
|
4611
|
+
extractRaw(input, expandSingleMeridiem = false) {
|
|
4612
|
+
const str = String(input ?? "").slice(0, MAX_INPUT_LENGTH);
|
|
4613
|
+
if (!str || this.slots.length === 0) return "";
|
|
4614
|
+
let raw = "";
|
|
4615
|
+
let inputIdx = 0;
|
|
4616
|
+
let slotIdx = 0;
|
|
4617
|
+
if (this.prefixSlotsCount > 0) {
|
|
4618
|
+
while (inputIdx < str.length && (str[inputIdx] === " " || str[inputIdx] === " ")) {
|
|
4619
|
+
inputIdx++;
|
|
4620
|
+
}
|
|
4621
|
+
let pIdx = 0;
|
|
4622
|
+
while (inputIdx < str.length && pIdx < this.prefixSlotsCount) {
|
|
4623
|
+
const pChar = this.slots[pIdx].char;
|
|
4624
|
+
const inChar = str[inputIdx];
|
|
4625
|
+
if (inChar.toUpperCase() === pChar.toUpperCase()) {
|
|
4626
|
+
inputIdx++;
|
|
4627
|
+
pIdx++;
|
|
4628
|
+
} else if (pChar === " " && inChar !== " ") {
|
|
4629
|
+
pIdx++;
|
|
4630
|
+
} else {
|
|
4631
|
+
break;
|
|
4632
|
+
}
|
|
4633
|
+
}
|
|
4634
|
+
slotIdx = this.prefixSlotsCount;
|
|
4635
|
+
}
|
|
4636
|
+
while (inputIdx < str.length && slotIdx < this.slots.length) {
|
|
4637
|
+
const slot = this.slots[slotIdx];
|
|
4638
|
+
const ch = str[inputIdx];
|
|
4639
|
+
if (slot.isStatic) {
|
|
4640
|
+
if (ch.toUpperCase() === slot.char.toUpperCase()) {
|
|
4641
|
+
inputIdx++;
|
|
4642
|
+
slotIdx++;
|
|
4643
|
+
} else {
|
|
4644
|
+
slotIdx++;
|
|
4645
|
+
}
|
|
4646
|
+
continue;
|
|
4647
|
+
}
|
|
4648
|
+
if (slot.tokenKind === "A") {
|
|
4649
|
+
const upper = ch.toUpperCase();
|
|
4650
|
+
if (slot.charIndexInSegment === 0) {
|
|
4651
|
+
if (upper === "A" || upper === "P") {
|
|
4652
|
+
raw += upper;
|
|
4653
|
+
inputIdx++;
|
|
4654
|
+
slotIdx++;
|
|
4655
|
+
const nextCh = inputIdx < str.length ? str[inputIdx].toUpperCase() : "";
|
|
4656
|
+
if (nextCh === "M") {
|
|
4657
|
+
raw += "M";
|
|
4658
|
+
inputIdx++;
|
|
4659
|
+
slotIdx++;
|
|
4660
|
+
} else if (expandSingleMeridiem) {
|
|
4661
|
+
raw += "M";
|
|
4662
|
+
slotIdx++;
|
|
4663
|
+
}
|
|
4664
|
+
} else {
|
|
4665
|
+
inputIdx++;
|
|
4666
|
+
}
|
|
4667
|
+
} else {
|
|
4668
|
+
if (upper === "M") {
|
|
4669
|
+
raw += "M";
|
|
4670
|
+
inputIdx++;
|
|
4671
|
+
slotIdx++;
|
|
4672
|
+
} else if (expandSingleMeridiem) {
|
|
4673
|
+
raw += "M";
|
|
4674
|
+
slotIdx++;
|
|
4675
|
+
} else {
|
|
4676
|
+
inputIdx++;
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
continue;
|
|
4680
|
+
}
|
|
4681
|
+
if (isAsciiDigit(ch)) {
|
|
4682
|
+
raw += ch;
|
|
4683
|
+
inputIdx++;
|
|
4684
|
+
slotIdx++;
|
|
4685
|
+
} else {
|
|
4686
|
+
inputIdx++;
|
|
4687
|
+
}
|
|
4688
|
+
}
|
|
4689
|
+
return raw;
|
|
4690
|
+
}
|
|
4691
|
+
/**
|
|
4692
|
+
* Formate une saisie (brute ou partiellement formatée) selon le gabarit configuré.
|
|
4693
|
+
*/
|
|
4694
|
+
format(input, expandSingleMeridiem = false) {
|
|
4695
|
+
if (this.slots.length === 0) return String(input ?? "").slice(0, MAX_INPUT_LENGTH);
|
|
4696
|
+
const cleanRaw = this.extractRaw(input, expandSingleMeridiem);
|
|
4697
|
+
if (cleanRaw.length === 0) {
|
|
4698
|
+
return this.prefixString;
|
|
4699
|
+
}
|
|
4700
|
+
let formatted = "";
|
|
4701
|
+
let rawIdx = 0;
|
|
4702
|
+
for (let i = 0; i < this.slots.length; i++) {
|
|
4703
|
+
const slot = this.slots[i];
|
|
4704
|
+
if (slot.isStatic) {
|
|
4705
|
+
const hasRemainingRaw = rawIdx < cleanRaw.length;
|
|
4706
|
+
const isPrefix = rawIdx === 0 && slot.isPrefix;
|
|
4707
|
+
const isCompletedSegmentTrailingSep = rawIdx > 0 && rawIdx === cleanRaw.length;
|
|
4708
|
+
if (hasRemainingRaw || isPrefix || isCompletedSegmentTrailingSep) {
|
|
4709
|
+
formatted += slot.char;
|
|
4710
|
+
} else {
|
|
4711
|
+
break;
|
|
4712
|
+
}
|
|
4713
|
+
} else if (rawIdx < cleanRaw.length) {
|
|
4714
|
+
formatted += cleanRaw[rawIdx];
|
|
4715
|
+
rawIdx++;
|
|
4716
|
+
} else {
|
|
4717
|
+
break;
|
|
4718
|
+
}
|
|
4719
|
+
}
|
|
4720
|
+
return formatted;
|
|
4721
|
+
}
|
|
4722
|
+
/**
|
|
4723
|
+
* Analyse complète de la saisie courante : formatage, complétude, validité calendaire UTC, Date & ISO.
|
|
4724
|
+
*/
|
|
4725
|
+
analyze(input, expandSingleMeridiem = false) {
|
|
4726
|
+
const cleanRaw = this.extractRaw(input, expandSingleMeridiem);
|
|
4727
|
+
const formatted = this.formatFromCleanRaw(cleanRaw);
|
|
4728
|
+
const totalSlots = this.editableCount;
|
|
4729
|
+
const filledSlots = cleanRaw.length;
|
|
4730
|
+
const isComplete = totalSlots > 0 && filledSlots >= totalSlots;
|
|
4731
|
+
const extracted = this.extractSegmentValues(cleanRaw);
|
|
4732
|
+
const parts = extracted.parts;
|
|
4733
|
+
let date = null;
|
|
4734
|
+
let isoString = null;
|
|
4735
|
+
let timestamp = null;
|
|
4736
|
+
let isValid = false;
|
|
4737
|
+
if (isComplete && extracted.allSegmentsPresent) {
|
|
4738
|
+
const resolvedHour = this.resolveHour24(extracted);
|
|
4739
|
+
if (resolvedHour !== null) {
|
|
4740
|
+
const candidate = {
|
|
4741
|
+
year: parts.year,
|
|
4742
|
+
month: parts.month,
|
|
4743
|
+
day: parts.day,
|
|
4744
|
+
hour: resolvedHour,
|
|
4745
|
+
minute: parts.minute ?? 0,
|
|
4746
|
+
second: parts.second ?? 0
|
|
4747
|
+
};
|
|
4748
|
+
const strictDate = this.buildStrictUTCDate(candidate);
|
|
4749
|
+
if (strictDate) {
|
|
4750
|
+
const ts = strictDate.getTime();
|
|
4751
|
+
const inMin = this.minTs === null || ts >= this.minTs;
|
|
4752
|
+
const inMax = this.maxTs === null || ts <= this.maxTs;
|
|
4753
|
+
if (inMin && inMax) {
|
|
4754
|
+
date = strictDate;
|
|
4755
|
+
timestamp = ts;
|
|
4756
|
+
isoString = this.formatDateToISO(strictDate);
|
|
4757
|
+
isValid = true;
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
return {
|
|
4763
|
+
formatted,
|
|
4764
|
+
rawValue: isoString || "",
|
|
4765
|
+
isoString,
|
|
4766
|
+
date,
|
|
4767
|
+
timestamp,
|
|
4768
|
+
parts,
|
|
4769
|
+
isComplete,
|
|
4770
|
+
isValid,
|
|
4771
|
+
totalSlots,
|
|
4772
|
+
filledSlots
|
|
4773
|
+
};
|
|
4774
|
+
}
|
|
4775
|
+
/**
|
|
4776
|
+
* Calcule la nouvelle position du curseur en préservant le nombre de caractères bruts avant lui.
|
|
4777
|
+
*/
|
|
4778
|
+
mapCursorPosition(inputValue, inputCursor, formatted) {
|
|
4779
|
+
const minPos = this.prefixSlotsCount;
|
|
4780
|
+
const safeInput = String(inputValue ?? "");
|
|
4781
|
+
const safeFormatted = String(formatted ?? "");
|
|
4782
|
+
if (inputCursor <= 0 || !safeFormatted) return minPos;
|
|
4783
|
+
const rawBeforeCursor = this.extractRaw(safeInput.slice(0, inputCursor), false);
|
|
4784
|
+
const targetRawCount = rawBeforeCursor.length;
|
|
4785
|
+
if (targetRawCount === 0) {
|
|
4786
|
+
return Math.max(minPos, Math.min(this.getNextEditablePosition(0), safeFormatted.length));
|
|
4787
|
+
}
|
|
4788
|
+
let currentRawCount = 0;
|
|
4789
|
+
let targetPos = safeFormatted.length;
|
|
4790
|
+
for (let i = 0; i < safeFormatted.length && i < this.slots.length; i++) {
|
|
4791
|
+
if (!this.slots[i].isStatic) {
|
|
4792
|
+
currentRawCount++;
|
|
4793
|
+
if (currentRawCount === targetRawCount) {
|
|
4794
|
+
targetPos = i + 1;
|
|
4795
|
+
break;
|
|
4796
|
+
}
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
while (targetPos < safeFormatted.length && this.slots[targetPos] && this.slots[targetPos].isStatic) {
|
|
4800
|
+
targetPos++;
|
|
4801
|
+
}
|
|
4802
|
+
return Math.max(minPos, Math.min(targetPos, safeFormatted.length));
|
|
4803
|
+
}
|
|
4804
|
+
/**
|
|
4805
|
+
* Gère la frappe d'un séparateur au clavier segment par segment (ex: '5' + '/' -> '05/', '5' + '.' -> '05. ').
|
|
4806
|
+
* Résout atomiquement les séparateurs composites ('DD. MM. YYYY HH:mm') sans jamais dédoubler l'espace.
|
|
4807
|
+
*/
|
|
4808
|
+
tryHandleSeparatorKey(currentValue, cursor, key) {
|
|
4809
|
+
const none = { handled: false, formatted: currentValue, cursor };
|
|
4810
|
+
if (!key || key.length !== 1) return none;
|
|
4811
|
+
if (cursor < this.slots.length && this.slots[cursor].isStatic && this.separatorMatchesKey(this.slots[cursor].char, key)) {
|
|
4812
|
+
const nextEditable = this.getNextEditablePosition(cursor + 1);
|
|
4813
|
+
const formatted = this.format(currentValue);
|
|
4814
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4815
|
+
}
|
|
4816
|
+
if (cursor > this.prefixSlotsCount && cursor - 1 < this.slots.length && this.slots[cursor - 1].isStatic) {
|
|
4817
|
+
let k = cursor - 1;
|
|
4818
|
+
while (k >= this.prefixSlotsCount && this.slots[k].isStatic) {
|
|
4819
|
+
if (this.separatorMatchesKey(this.slots[k].char, key)) {
|
|
4820
|
+
const nextEditable = this.getNextEditablePosition(k + 1);
|
|
4821
|
+
const formatted = this.format(currentValue);
|
|
4822
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4823
|
+
}
|
|
4824
|
+
k--;
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
let segIdx = -1;
|
|
4828
|
+
for (let i = 0; i < this.segments.length; i++) {
|
|
4829
|
+
const seg2 = this.segments[i];
|
|
4830
|
+
if (cursor >= seg2.start && cursor <= seg2.end) {
|
|
4831
|
+
segIdx = i;
|
|
4832
|
+
break;
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
if (segIdx === -1) return none;
|
|
4836
|
+
const seg = this.segments[segIdx];
|
|
4837
|
+
if (!seg.followingSeparator) return none;
|
|
4838
|
+
if (!this.followingSeparatorMatchesKey(seg.followingSeparator, key)) {
|
|
4839
|
+
return none;
|
|
4840
|
+
}
|
|
4841
|
+
const rawInSeg = currentValue.slice(seg.start, Math.min(cursor, seg.end)).replace(/\D/g, "");
|
|
4842
|
+
if (seg.kind !== "YYYY" && seg.kind !== "A" && rawInSeg.length > 0 && rawInSeg.length < seg.length) {
|
|
4843
|
+
const paddedSeg = "0".repeat(seg.length - rawInSeg.length) + rawInSeg;
|
|
4844
|
+
const tail = currentValue.slice(Math.min(currentValue.length, seg.end));
|
|
4845
|
+
const candidate = currentValue.slice(0, seg.start) + paddedSeg + seg.followingSeparator + tail;
|
|
4846
|
+
const formatted = this.format(candidate);
|
|
4847
|
+
const nextEditable = this.getNextEditablePosition(seg.end);
|
|
4848
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4849
|
+
}
|
|
4850
|
+
if (cursor === seg.end) {
|
|
4851
|
+
const formatted = this.format(currentValue);
|
|
4852
|
+
const nextEditable = this.getNextEditablePosition(seg.end);
|
|
4853
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4854
|
+
}
|
|
4855
|
+
return none;
|
|
4856
|
+
}
|
|
4857
|
+
/**
|
|
4858
|
+
* Formate un Date, timestamp numérique, ISO string ou valeur partielle vers le gabarit configuré.
|
|
4859
|
+
* Immunisé contre Invalid Date et NaN.
|
|
4860
|
+
*/
|
|
4861
|
+
formatFromValue(value) {
|
|
4862
|
+
if (value === null || value === void 0) return this.prefixString;
|
|
4863
|
+
if (value instanceof Date) {
|
|
4864
|
+
if (Number.isNaN(value.getTime())) return this.prefixString;
|
|
4865
|
+
return this.formatPartsToTemplate(this.dateToUTCParts(value));
|
|
4866
|
+
}
|
|
4867
|
+
if (typeof value === "number") {
|
|
4868
|
+
if (!Number.isFinite(value)) return this.prefixString;
|
|
4869
|
+
const d = new Date(value);
|
|
4870
|
+
if (Number.isNaN(d.getTime())) return this.prefixString;
|
|
4871
|
+
return this.formatPartsToTemplate(this.dateToUTCParts(d));
|
|
4872
|
+
}
|
|
4873
|
+
const str = String(value).slice(0, MAX_INPUT_LENGTH).trim();
|
|
4874
|
+
if (!str) return this.prefixString;
|
|
4875
|
+
const pasted = this.parsePasted(str);
|
|
4876
|
+
if (pasted.matched) {
|
|
4877
|
+
return pasted.formatted;
|
|
4878
|
+
}
|
|
4879
|
+
if (pasted.rejected) {
|
|
4880
|
+
return this.prefixString;
|
|
4881
|
+
}
|
|
4882
|
+
return this.format(str, true);
|
|
4883
|
+
}
|
|
4884
|
+
/**
|
|
4885
|
+
* Formate une chaîne issue d'une affectation native (input.value = '...') sans altérer la frappe
|
|
4886
|
+
* en cours par le parseur segmenté (seul un ISO 8601 complet avec horaire est reconnu).
|
|
4887
|
+
*/
|
|
4888
|
+
formatFromNativeValue(strVal) {
|
|
4889
|
+
const str = String(strVal ?? "").slice(0, MAX_INPUT_LENGTH);
|
|
4890
|
+
if (!str) return this.prefixString;
|
|
4891
|
+
const trimmed = str.trim();
|
|
4892
|
+
if (trimmed.length >= 16) {
|
|
4893
|
+
const iso = this.parseISO8601Linear(trimmed);
|
|
4894
|
+
if (iso && !iso.dateOnly) {
|
|
4895
|
+
const res = this.parsePasted(trimmed);
|
|
4896
|
+
if (res.matched) return res.formatted;
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
return this.format(str, false);
|
|
4900
|
+
}
|
|
4901
|
+
/**
|
|
4902
|
+
* Parse universellement une chaîne collée en O(N) :
|
|
4903
|
+
* 1) ISO 8601 (YYYY-MM-DD[T| ]HH:mm[:ss][.sss][Z|±HH:MM], date seule)
|
|
4904
|
+
* 2) Format configuré de l'instance avec tolérance des segments courts (ex: 2/3/2026 9:5)
|
|
4905
|
+
*/
|
|
4906
|
+
parsePasted(rawText) {
|
|
4907
|
+
const fail = { matched: false, formatted: "", cursor: 0 };
|
|
4908
|
+
const rejected = { matched: false, rejected: true, formatted: "", cursor: 0 };
|
|
4909
|
+
const text = String(rawText ?? "").slice(0, MAX_INPUT_LENGTH).trim();
|
|
4910
|
+
if (!text || this.segments.length === 0) return fail;
|
|
4911
|
+
const looksLikeIso = text.length >= 10 && isAsciiDigit(text[0]) && isAsciiDigit(text[1]) && isAsciiDigit(text[2]) && isAsciiDigit(text[3]) && text[4] === "-" && isAsciiDigit(text[5]) && isAsciiDigit(text[6]) && text[7] === "-" && isAsciiDigit(text[8]) && isAsciiDigit(text[9]);
|
|
4912
|
+
const iso = this.parseISO8601Linear(text);
|
|
4913
|
+
if (iso) {
|
|
4914
|
+
if (iso.dateOnly) {
|
|
4915
|
+
return this.formatDateOnlyMatch(
|
|
4916
|
+
{ year: iso.year, month: iso.month, day: iso.day },
|
|
4917
|
+
rejected
|
|
4918
|
+
);
|
|
4919
|
+
}
|
|
4920
|
+
if (iso.offsetMinutes !== null && iso.offsetMinutes !== 0 && !this.convertPastedOffset) {
|
|
4921
|
+
return rejected;
|
|
4922
|
+
}
|
|
4923
|
+
const baseDate = this.buildStrictUTCDate({
|
|
4924
|
+
year: iso.year,
|
|
4925
|
+
month: iso.month,
|
|
4926
|
+
day: iso.day,
|
|
4927
|
+
hour: iso.hour,
|
|
4928
|
+
minute: iso.minute,
|
|
4929
|
+
second: iso.second
|
|
4930
|
+
});
|
|
4931
|
+
if (!baseDate) return rejected;
|
|
4932
|
+
let targetDate = baseDate;
|
|
4933
|
+
let offsetConverted;
|
|
4934
|
+
if (iso.offsetMinutes !== null && iso.offsetMinutes !== 0) {
|
|
4935
|
+
const utcMs = baseDate.getTime() - iso.offsetMinutes * 6e4;
|
|
4936
|
+
targetDate = new Date(utcMs);
|
|
4937
|
+
if (Number.isNaN(targetDate.getTime())) return rejected;
|
|
4938
|
+
offsetConverted = {
|
|
4939
|
+
original: text,
|
|
4940
|
+
offsetMinutes: iso.offsetMinutes,
|
|
4941
|
+
utcIso: this.formatDateToISO(targetDate)
|
|
4942
|
+
};
|
|
4943
|
+
}
|
|
4944
|
+
const formatted = this.formatPartsToTemplate(this.dateToUTCParts(targetDate));
|
|
4945
|
+
return {
|
|
4946
|
+
matched: true,
|
|
4947
|
+
formatted,
|
|
4948
|
+
cursor: formatted.length,
|
|
4949
|
+
offsetConverted
|
|
4950
|
+
};
|
|
4951
|
+
}
|
|
4952
|
+
if (looksLikeIso && text.length > 10 && (text[10] === "T" || text[10] === "t" || this.segments[0]?.kind !== "YYYY")) {
|
|
4953
|
+
return rejected;
|
|
4954
|
+
}
|
|
4955
|
+
return this.parseConfiguredFormatLinear(text);
|
|
4956
|
+
}
|
|
4957
|
+
/**
|
|
4958
|
+
* Formate une date UTC valide dans la locale demandée via Intl.DateTimeFormat (aperçu miroir).
|
|
4959
|
+
*/
|
|
4960
|
+
formatLocal(date, locale, intlOptions) {
|
|
4961
|
+
if (!date || Number.isNaN(date.getTime())) return null;
|
|
4962
|
+
try {
|
|
4963
|
+
const opts = intlOptions || {
|
|
4964
|
+
dateStyle: "short",
|
|
4965
|
+
timeStyle: "medium"
|
|
4966
|
+
};
|
|
4967
|
+
return new Intl.DateTimeFormat(locale, opts).format(date);
|
|
4968
|
+
} catch {
|
|
4969
|
+
return null;
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
// ==========================================================================
|
|
4973
|
+
// Helpers internes purs
|
|
4974
|
+
// ==========================================================================
|
|
4975
|
+
normalizeBoundary(val) {
|
|
4976
|
+
if (val === null || val === void 0) return null;
|
|
4977
|
+
if (val instanceof Date) {
|
|
4978
|
+
const t = val.getTime();
|
|
4979
|
+
return Number.isNaN(t) ? null : t;
|
|
4980
|
+
}
|
|
4981
|
+
if (typeof val === "number") {
|
|
4982
|
+
return Number.isFinite(val) ? val : null;
|
|
4983
|
+
}
|
|
4984
|
+
const str = String(val).slice(0, MAX_INPUT_LENGTH).trim();
|
|
4985
|
+
if (!str) return null;
|
|
4986
|
+
const iso = this.parseISO8601Linear(str);
|
|
4987
|
+
if (iso) {
|
|
4988
|
+
const d = this.buildStrictUTCDate({
|
|
4989
|
+
year: iso.year,
|
|
4990
|
+
month: iso.month,
|
|
4991
|
+
day: iso.day,
|
|
4992
|
+
hour: iso.hour,
|
|
4993
|
+
minute: iso.minute,
|
|
4994
|
+
second: iso.second
|
|
4995
|
+
});
|
|
4996
|
+
if (!d) return null;
|
|
4997
|
+
const offsetMs = iso.offsetMinutes ? iso.offsetMinutes * 6e4 : 0;
|
|
4998
|
+
return d.getTime() - offsetMs;
|
|
4999
|
+
}
|
|
5000
|
+
const res = this.analyze(str, true);
|
|
5001
|
+
return res.timestamp;
|
|
5002
|
+
}
|
|
5003
|
+
separatorMatchesKey(sepChar, key) {
|
|
5004
|
+
if (sepChar === key) return true;
|
|
5005
|
+
if ((sepChar === "T" || sepChar === "t") && (key === "T" || key === "t" || key === " ")) {
|
|
5006
|
+
return true;
|
|
5007
|
+
}
|
|
5008
|
+
return false;
|
|
5009
|
+
}
|
|
5010
|
+
followingSeparatorMatchesKey(followingSep, key) {
|
|
5011
|
+
let hasNonSpace = false;
|
|
5012
|
+
for (let i = 0; i < followingSep.length; i++) {
|
|
5013
|
+
if (followingSep[i] !== " ") {
|
|
5014
|
+
hasNonSpace = true;
|
|
5015
|
+
break;
|
|
5016
|
+
}
|
|
5017
|
+
}
|
|
5018
|
+
for (let i = 0; i < followingSep.length; i++) {
|
|
5019
|
+
const ch = followingSep[i];
|
|
5020
|
+
if (hasNonSpace && ch === " ") {
|
|
5021
|
+
continue;
|
|
5022
|
+
}
|
|
5023
|
+
if (this.separatorMatchesKey(ch, key)) return true;
|
|
5024
|
+
}
|
|
5025
|
+
return false;
|
|
5026
|
+
}
|
|
5027
|
+
formatFromCleanRaw(cleanRaw) {
|
|
5028
|
+
if (this.slots.length === 0) return "";
|
|
5029
|
+
if (cleanRaw.length === 0) return this.prefixString;
|
|
5030
|
+
let formatted = "";
|
|
5031
|
+
let rawIdx = 0;
|
|
5032
|
+
for (let i = 0; i < this.slots.length; i++) {
|
|
5033
|
+
const slot = this.slots[i];
|
|
5034
|
+
if (slot.isStatic) {
|
|
5035
|
+
const hasRemainingRaw = rawIdx < cleanRaw.length;
|
|
5036
|
+
const isPrefix = rawIdx === 0 && slot.isPrefix;
|
|
5037
|
+
const isCompletedSegmentTrailingSep = rawIdx > 0 && rawIdx === cleanRaw.length;
|
|
5038
|
+
if (hasRemainingRaw || isPrefix || isCompletedSegmentTrailingSep) {
|
|
5039
|
+
formatted += slot.char;
|
|
5040
|
+
} else {
|
|
5041
|
+
break;
|
|
5042
|
+
}
|
|
5043
|
+
} else if (rawIdx < cleanRaw.length) {
|
|
5044
|
+
formatted += cleanRaw[rawIdx];
|
|
5045
|
+
rawIdx++;
|
|
5046
|
+
} else {
|
|
5047
|
+
break;
|
|
5048
|
+
}
|
|
5049
|
+
}
|
|
5050
|
+
return formatted;
|
|
5051
|
+
}
|
|
5052
|
+
extractSegmentValues(cleanRaw) {
|
|
5053
|
+
const parts = {};
|
|
5054
|
+
let hour12;
|
|
5055
|
+
let meridiem;
|
|
5056
|
+
let rawOffset = 0;
|
|
5057
|
+
let allPresent = true;
|
|
5058
|
+
for (const seg of this.segments) {
|
|
5059
|
+
if (rawOffset + seg.length > cleanRaw.length) {
|
|
5060
|
+
allPresent = false;
|
|
5061
|
+
break;
|
|
5062
|
+
}
|
|
5063
|
+
const chunk = cleanRaw.slice(rawOffset, rawOffset + seg.length);
|
|
5064
|
+
rawOffset += seg.length;
|
|
5065
|
+
switch (seg.kind) {
|
|
5066
|
+
case "YYYY":
|
|
5067
|
+
parts.year = parseAsciiInt(chunk);
|
|
5068
|
+
break;
|
|
5069
|
+
case "MM":
|
|
5070
|
+
parts.month = parseAsciiInt(chunk);
|
|
5071
|
+
break;
|
|
5072
|
+
case "DD":
|
|
5073
|
+
parts.day = parseAsciiInt(chunk);
|
|
5074
|
+
break;
|
|
5075
|
+
case "HH":
|
|
5076
|
+
parts.hour = parseAsciiInt(chunk);
|
|
5077
|
+
break;
|
|
5078
|
+
case "hh":
|
|
5079
|
+
hour12 = parseAsciiInt(chunk);
|
|
5080
|
+
break;
|
|
5081
|
+
case "mm":
|
|
5082
|
+
parts.minute = parseAsciiInt(chunk);
|
|
5083
|
+
break;
|
|
5084
|
+
case "ss":
|
|
5085
|
+
parts.second = parseAsciiInt(chunk);
|
|
5086
|
+
break;
|
|
5087
|
+
case "A":
|
|
5088
|
+
if (chunk === "AM" || chunk === "PM") {
|
|
5089
|
+
meridiem = chunk;
|
|
5090
|
+
} else {
|
|
5091
|
+
allPresent = false;
|
|
5092
|
+
}
|
|
5093
|
+
break;
|
|
5094
|
+
}
|
|
5095
|
+
}
|
|
5096
|
+
if (parts.year === void 0 || parts.month === void 0 || parts.day === void 0) {
|
|
5097
|
+
allPresent = false;
|
|
5098
|
+
}
|
|
5099
|
+
if (parts.hour === void 0 && hour12 === void 0) {
|
|
5100
|
+
allPresent = false;
|
|
5101
|
+
}
|
|
5102
|
+
if (allPresent && hour12 !== void 0) {
|
|
5103
|
+
const resolved = this.resolveHour24({ parts, hour12, meridiem });
|
|
5104
|
+
if (resolved !== null) {
|
|
5105
|
+
parts.hour = resolved;
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
return { parts, hour12, meridiem, allSegmentsPresent: allPresent };
|
|
5109
|
+
}
|
|
5110
|
+
resolveHour24(extracted) {
|
|
5111
|
+
if (extracted.hour12 !== void 0) {
|
|
5112
|
+
const h12 = extracted.hour12;
|
|
5113
|
+
if (h12 < 1 || h12 > 12 || !extracted.meridiem) return null;
|
|
5114
|
+
if (extracted.meridiem === "AM") {
|
|
5115
|
+
return h12 === 12 ? 0 : h12;
|
|
5116
|
+
}
|
|
5117
|
+
return h12 === 12 ? 12 : h12 + 12;
|
|
5118
|
+
}
|
|
5119
|
+
if (extracted.parts.hour !== void 0) {
|
|
5120
|
+
return extracted.parts.hour >= 0 && extracted.parts.hour <= 23 ? extracted.parts.hour : null;
|
|
5121
|
+
}
|
|
5122
|
+
return null;
|
|
5123
|
+
}
|
|
5124
|
+
/**
|
|
5125
|
+
* Validation calendaire stricte sans rollover ni piège Date.UTC(0..99).
|
|
5126
|
+
*/
|
|
5127
|
+
buildStrictUTCDate(parts) {
|
|
5128
|
+
const { year, month, day, hour, minute, second } = parts;
|
|
5129
|
+
if (!Number.isInteger(year) || year < 1 || year > 9999 || !Number.isInteger(month) || month < 1 || month > 12 || !Number.isInteger(day) || day < 1 || day > 31 || !Number.isInteger(hour) || hour < 0 || hour > 23 || !Number.isInteger(minute) || minute < 0 || minute > 59 || !Number.isInteger(second) || second < 0 || second > 59) {
|
|
5130
|
+
return null;
|
|
5131
|
+
}
|
|
5132
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
5133
|
+
d.setUTCFullYear(year, month - 1, day);
|
|
5134
|
+
d.setUTCHours(hour, minute, second, 0);
|
|
5135
|
+
if (d.getUTCFullYear() !== year || d.getUTCMonth() !== month - 1 || d.getUTCDate() !== day || d.getUTCHours() !== hour || d.getUTCMinutes() !== minute || d.getUTCSeconds() !== second) {
|
|
5136
|
+
return null;
|
|
5137
|
+
}
|
|
5138
|
+
return d;
|
|
5139
|
+
}
|
|
5140
|
+
dateToUTCParts(d) {
|
|
5141
|
+
return {
|
|
5142
|
+
year: d.getUTCFullYear(),
|
|
5143
|
+
month: d.getUTCMonth() + 1,
|
|
5144
|
+
day: d.getUTCDate(),
|
|
5145
|
+
hour: d.getUTCHours(),
|
|
5146
|
+
minute: d.getUTCMinutes(),
|
|
5147
|
+
second: d.getUTCSeconds()
|
|
5148
|
+
};
|
|
5149
|
+
}
|
|
5150
|
+
formatDateToISO(d) {
|
|
5151
|
+
const y = String(d.getUTCFullYear()).padStart(4, "0");
|
|
5152
|
+
const m = String(d.getUTCMonth() + 1).padStart(2, "0");
|
|
5153
|
+
const day = String(d.getUTCDate()).padStart(2, "0");
|
|
5154
|
+
const h = String(d.getUTCHours()).padStart(2, "0");
|
|
5155
|
+
const min = String(d.getUTCMinutes()).padStart(2, "0");
|
|
5156
|
+
const s = String(d.getUTCSeconds()).padStart(2, "0");
|
|
5157
|
+
if (this.includeMilliseconds) {
|
|
5158
|
+
const ms = String(d.getUTCMilliseconds()).padStart(3, "0");
|
|
5159
|
+
return `${y}-${m}-${day}T${h}:${min}:${s}.${ms}Z`;
|
|
5160
|
+
}
|
|
5161
|
+
return `${y}-${m}-${day}T${h}:${min}:${s}Z`;
|
|
5162
|
+
}
|
|
5163
|
+
formatPartsToTemplate(parts) {
|
|
5164
|
+
let raw = "";
|
|
5165
|
+
for (const seg of this.segments) {
|
|
5166
|
+
switch (seg.kind) {
|
|
5167
|
+
case "YYYY":
|
|
5168
|
+
raw += String(parts.year).padStart(4, "0").slice(-4);
|
|
5169
|
+
break;
|
|
5170
|
+
case "MM":
|
|
5171
|
+
raw += String(parts.month).padStart(2, "0");
|
|
5172
|
+
break;
|
|
5173
|
+
case "DD":
|
|
5174
|
+
raw += String(parts.day).padStart(2, "0");
|
|
5175
|
+
break;
|
|
5176
|
+
case "HH":
|
|
5177
|
+
raw += String(parts.hour).padStart(2, "0");
|
|
5178
|
+
break;
|
|
5179
|
+
case "hh": {
|
|
5180
|
+
const h12 = parts.hour % 12 === 0 ? 12 : parts.hour % 12;
|
|
5181
|
+
raw += String(h12).padStart(2, "0");
|
|
5182
|
+
break;
|
|
5183
|
+
}
|
|
5184
|
+
case "mm":
|
|
5185
|
+
raw += String(parts.minute).padStart(2, "0");
|
|
5186
|
+
break;
|
|
5187
|
+
case "ss":
|
|
5188
|
+
raw += String(parts.second).padStart(2, "0");
|
|
5189
|
+
break;
|
|
5190
|
+
case "A":
|
|
5191
|
+
raw += parts.hour >= 12 ? "PM" : "AM";
|
|
5192
|
+
break;
|
|
5193
|
+
}
|
|
5194
|
+
}
|
|
5195
|
+
return this.formatFromCleanRaw(raw);
|
|
5196
|
+
}
|
|
5197
|
+
formatDateOnlyMatch(dateParts, fail) {
|
|
5198
|
+
const check = this.buildStrictUTCDate({
|
|
5199
|
+
year: dateParts.year,
|
|
5200
|
+
month: dateParts.month,
|
|
5201
|
+
day: dateParts.day,
|
|
5202
|
+
hour: 0,
|
|
5203
|
+
minute: 0,
|
|
5204
|
+
second: 0
|
|
5205
|
+
});
|
|
5206
|
+
if (!check) return fail;
|
|
5207
|
+
if (typeof this.defaultTimeOnDateOnly === "string" && this.defaultTimeOnDateOnly.trim()) {
|
|
5208
|
+
const parsedTime = this.parseDefaultTime(this.defaultTimeOnDateOnly.trim());
|
|
5209
|
+
if (parsedTime) {
|
|
5210
|
+
const formatted2 = this.formatPartsToTemplate({
|
|
5211
|
+
...dateParts,
|
|
5212
|
+
hour: parsedTime.hour,
|
|
5213
|
+
minute: parsedTime.minute,
|
|
5214
|
+
second: parsedTime.second
|
|
5215
|
+
});
|
|
5216
|
+
return { matched: true, formatted: formatted2, cursor: formatted2.length };
|
|
5217
|
+
}
|
|
5218
|
+
}
|
|
5219
|
+
let rawDate = "";
|
|
5220
|
+
for (const seg of this.segments) {
|
|
5221
|
+
if (TIME_TOKEN_KINDS.has(seg.kind)) break;
|
|
5222
|
+
if (seg.kind === "YYYY") rawDate += String(dateParts.year).padStart(4, "0");
|
|
5223
|
+
else if (seg.kind === "MM") rawDate += String(dateParts.month).padStart(2, "0");
|
|
5224
|
+
else if (seg.kind === "DD") rawDate += String(dateParts.day).padStart(2, "0");
|
|
5225
|
+
}
|
|
5226
|
+
if (!rawDate) return fail;
|
|
5227
|
+
const formatted = this.formatFromCleanRaw(rawDate);
|
|
5228
|
+
return { matched: true, formatted, cursor: formatted.length };
|
|
5229
|
+
}
|
|
5230
|
+
parseDefaultTime(timeStr) {
|
|
5231
|
+
const parts = timeStr.split(":");
|
|
5232
|
+
if (parts.length < 2 || parts.length > 3) return null;
|
|
5233
|
+
const hour = parseAsciiInt(parts[0]);
|
|
5234
|
+
const minute = parseAsciiInt(parts[1]);
|
|
5235
|
+
const second = parts.length === 3 ? parseAsciiInt(parts[2]) : 0;
|
|
5236
|
+
if (Number.isNaN(hour) || hour < 0 || hour > 23 || Number.isNaN(minute) || minute < 0 || minute > 59 || Number.isNaN(second) || second < 0 || second > 59) {
|
|
5237
|
+
return null;
|
|
5238
|
+
}
|
|
5239
|
+
return { hour, minute, second };
|
|
5240
|
+
}
|
|
5241
|
+
/**
|
|
5242
|
+
* Parseur ISO 8601 strict en complexité linéaire O(N) sans regex à backtracking.
|
|
5243
|
+
*/
|
|
5244
|
+
parseISO8601Linear(str) {
|
|
5245
|
+
if (str.length < 10) return null;
|
|
5246
|
+
for (const idx of [0, 1, 2, 3, 5, 6, 8, 9]) {
|
|
5247
|
+
if (!isAsciiDigit(str[idx])) return null;
|
|
5248
|
+
}
|
|
5249
|
+
if (str[4] !== "-" || str[7] !== "-") return null;
|
|
5250
|
+
const year = parseAsciiInt(str.slice(0, 4));
|
|
5251
|
+
const month = parseAsciiInt(str.slice(5, 7));
|
|
5252
|
+
const day = parseAsciiInt(str.slice(8, 10));
|
|
5253
|
+
if (str.length === 10) {
|
|
5254
|
+
return { year, month, day, hour: 0, minute: 0, second: 0, dateOnly: true, offsetMinutes: null };
|
|
5255
|
+
}
|
|
5256
|
+
let pos = 10;
|
|
5257
|
+
if (str[pos] !== "T" && str[pos] !== "t" && str[pos] !== " ") return null;
|
|
5258
|
+
pos++;
|
|
5259
|
+
if (pos + 5 > str.length) return null;
|
|
5260
|
+
if (!isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1]) || str[pos + 2] !== ":" || !isAsciiDigit(str[pos + 3]) || !isAsciiDigit(str[pos + 4])) {
|
|
5261
|
+
return null;
|
|
5262
|
+
}
|
|
5263
|
+
const hour = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5264
|
+
const minute = parseAsciiInt(str.slice(pos + 3, pos + 5));
|
|
5265
|
+
pos += 5;
|
|
5266
|
+
let second = 0;
|
|
5267
|
+
if (pos < str.length && str[pos] === ":") {
|
|
5268
|
+
pos++;
|
|
5269
|
+
if (pos + 2 > str.length || !isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1])) return null;
|
|
5270
|
+
second = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5271
|
+
pos += 2;
|
|
5272
|
+
}
|
|
5273
|
+
if (pos < str.length && str[pos] === ".") {
|
|
5274
|
+
pos++;
|
|
5275
|
+
const fracStart = pos;
|
|
5276
|
+
while (pos < str.length && isAsciiDigit(str[pos])) {
|
|
5277
|
+
pos++;
|
|
5278
|
+
}
|
|
5279
|
+
if (pos === fracStart) return null;
|
|
5280
|
+
}
|
|
5281
|
+
let offsetMinutes = null;
|
|
5282
|
+
if (pos < str.length) {
|
|
5283
|
+
while (pos < str.length && str[pos] === " ") pos++;
|
|
5284
|
+
if (pos < str.length) {
|
|
5285
|
+
const tzChar = str[pos];
|
|
5286
|
+
if (tzChar === "Z" || tzChar === "z") {
|
|
5287
|
+
offsetMinutes = 0;
|
|
5288
|
+
pos++;
|
|
5289
|
+
} else if (tzChar === "+" || tzChar === "-") {
|
|
5290
|
+
const sign = tzChar === "-" ? -1 : 1;
|
|
5291
|
+
pos++;
|
|
5292
|
+
if (pos + 2 > str.length || !isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1])) return null;
|
|
5293
|
+
const offH = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5294
|
+
pos += 2;
|
|
5295
|
+
let offM = 0;
|
|
5296
|
+
if (pos < str.length) {
|
|
5297
|
+
if (str[pos] === ":") pos++;
|
|
5298
|
+
if (pos + 2 > str.length || !isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1])) return null;
|
|
5299
|
+
offM = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5300
|
+
pos += 2;
|
|
5301
|
+
}
|
|
5302
|
+
if (offH > 14 || offM > 59 || offH === 14 && offM !== 0) {
|
|
5303
|
+
return null;
|
|
5304
|
+
}
|
|
5305
|
+
offsetMinutes = sign * (offH * 60 + offM);
|
|
5306
|
+
} else if (str.slice(pos).toUpperCase() === "UTC") {
|
|
5307
|
+
offsetMinutes = 0;
|
|
5308
|
+
pos = str.length;
|
|
5309
|
+
} else {
|
|
5310
|
+
return null;
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
}
|
|
5314
|
+
if (pos !== str.length) return null;
|
|
5315
|
+
return { year, month, day, hour, minute, second, dateOnly: false, offsetMinutes };
|
|
5316
|
+
}
|
|
5317
|
+
/**
|
|
5318
|
+
* Parseur segmenté O(N) aligné sur le gabarit configuré de l'instance.
|
|
5319
|
+
* Tolère les segments courts (ex: 2/3/2026 9:5 ou 2. 3. 2026 9:5 ou 2/3-2026 9:5 pm)
|
|
5320
|
+
* sans deviner sur les dates ambiguës (03/04/2026 suit strictement l'ordre configuré).
|
|
5321
|
+
*/
|
|
5322
|
+
parseConfiguredFormatLinear(text) {
|
|
5323
|
+
const fail = { matched: false, formatted: "", cursor: 0 };
|
|
5324
|
+
let cleaned = text;
|
|
5325
|
+
if (cleaned.toUpperCase().endsWith(" UTC")) {
|
|
5326
|
+
cleaned = cleaned.slice(0, -4).trim();
|
|
5327
|
+
} else if (cleaned.length > 2 && (cleaned.endsWith("Z") || cleaned.endsWith("z")) && isAsciiDigit(cleaned[cleaned.length - 2])) {
|
|
5328
|
+
cleaned = cleaned.slice(0, -1).trim();
|
|
5329
|
+
}
|
|
5330
|
+
if (this.prefixString && cleaned.toLowerCase().startsWith(this.prefixString.trim().toLowerCase())) {
|
|
5331
|
+
cleaned = cleaned.slice(this.prefixString.trim().length).trim();
|
|
5332
|
+
}
|
|
5333
|
+
const tokens = [];
|
|
5334
|
+
let start = -1;
|
|
5335
|
+
for (let i = 0; i < cleaned.length; i++) {
|
|
5336
|
+
const ch = cleaned[i];
|
|
5337
|
+
if (DATE_SEPARATORS.has(ch)) {
|
|
5338
|
+
if (start !== -1) {
|
|
5339
|
+
tokens.push(cleaned.slice(start, i));
|
|
5340
|
+
start = -1;
|
|
5341
|
+
}
|
|
5342
|
+
} else {
|
|
5343
|
+
if (start === -1) start = i;
|
|
5344
|
+
}
|
|
5345
|
+
}
|
|
5346
|
+
if (start !== -1) {
|
|
5347
|
+
tokens.push(cleaned.slice(start));
|
|
5348
|
+
}
|
|
5349
|
+
if (tokens.length === 0 || tokens.length > this.segments.length) return fail;
|
|
5350
|
+
let dateSegCount = 0;
|
|
5351
|
+
for (const seg of this.segments) {
|
|
5352
|
+
if (TIME_TOKEN_KINDS.has(seg.kind)) break;
|
|
5353
|
+
dateSegCount++;
|
|
5354
|
+
}
|
|
5355
|
+
const rawParts = [];
|
|
5356
|
+
let yearVal;
|
|
5357
|
+
let monthVal;
|
|
5358
|
+
let dayVal;
|
|
5359
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
5360
|
+
const tok = tokens[i];
|
|
5361
|
+
const seg = this.segments[i];
|
|
5362
|
+
if (seg.kind === "A") {
|
|
5363
|
+
const up = tok.toUpperCase();
|
|
5364
|
+
if (up === "AM" || up === "A") rawParts.push("AM");
|
|
5365
|
+
else if (up === "PM" || up === "P") rawParts.push("PM");
|
|
5366
|
+
else return fail;
|
|
5367
|
+
continue;
|
|
5368
|
+
}
|
|
5369
|
+
for (let k = 0; k < tok.length; k++) {
|
|
5370
|
+
if (!isAsciiDigit(tok[k])) return fail;
|
|
5371
|
+
}
|
|
5372
|
+
if (seg.kind === "YYYY") {
|
|
5373
|
+
if (tok.length !== 4) return fail;
|
|
5374
|
+
yearVal = parseAsciiInt(tok);
|
|
5375
|
+
rawParts.push(tok);
|
|
5376
|
+
} else {
|
|
5377
|
+
if (tok.length < 1 || tok.length > 2) return fail;
|
|
5378
|
+
const padded = tok.length === 1 ? "0" + tok : tok;
|
|
5379
|
+
const val = parseAsciiInt(padded);
|
|
5380
|
+
if (seg.kind === "MM") monthVal = val;
|
|
5381
|
+
if (seg.kind === "DD") dayVal = val;
|
|
5382
|
+
rawParts.push(padded);
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
if (tokens.length === dateSegCount && yearVal !== void 0 && monthVal !== void 0 && dayVal !== void 0) {
|
|
5386
|
+
return this.formatDateOnlyMatch({ year: yearVal, month: monthVal, day: dayVal }, fail);
|
|
5387
|
+
}
|
|
5388
|
+
const minRequired = this.segments.length;
|
|
5389
|
+
if (tokens.length < minRequired) {
|
|
5390
|
+
const hasMinDateAndHourMin = dateSegCount > 0 && tokens.length >= dateSegCount + 2 && this.segments[dateSegCount + 1]?.kind === "mm";
|
|
5391
|
+
if (!hasMinDateAndHourMin) return fail;
|
|
5392
|
+
}
|
|
5393
|
+
const formatted = this.formatFromCleanRaw(rawParts.join(""));
|
|
5394
|
+
return {
|
|
5395
|
+
matched: true,
|
|
5396
|
+
formatted,
|
|
5397
|
+
cursor: formatted.length
|
|
5398
|
+
};
|
|
5399
|
+
}
|
|
5400
|
+
};
|
|
5401
|
+
|
|
5402
|
+
// src/mask/InputDateUTCMask.ts
|
|
5403
|
+
var MAX_NOTIFICATION_ITERATIONS3 = 10;
|
|
5404
|
+
var InputDateUTCMask = class extends BaseInputMask {
|
|
5405
|
+
engine;
|
|
5406
|
+
history;
|
|
5407
|
+
isComposing = false;
|
|
5408
|
+
isUndoingRedoing = false;
|
|
5409
|
+
isMouseDown = false;
|
|
5410
|
+
isApplying = false;
|
|
5411
|
+
isNotifying = false;
|
|
5412
|
+
hasPendingNotification = false;
|
|
5413
|
+
lastValue = "";
|
|
5414
|
+
lastValueLength = 0;
|
|
5415
|
+
lastInputType = "";
|
|
5416
|
+
inferredInputModeValue = null;
|
|
5417
|
+
wasAutocorrectSet = false;
|
|
5418
|
+
wasAutocapitalizeSet = false;
|
|
5419
|
+
wasSpellcheckSet = false;
|
|
5420
|
+
cutTimerId = null;
|
|
5421
|
+
pasteTimerId = null;
|
|
5422
|
+
resetTimerId = null;
|
|
5423
|
+
constructor(targetOrWrapper, inputOrOptions, options) {
|
|
5424
|
+
const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
|
|
5425
|
+
const wrap = args.wrapper;
|
|
5426
|
+
const inp = args.input;
|
|
5427
|
+
const opts = args.options;
|
|
5428
|
+
const attrFormat = wrap?.getAttribute("data-mask-format") || inp?.getAttribute("data-mask-format") || void 0;
|
|
5429
|
+
const attrUtcIndicator = wrap?.getAttribute("data-mask-utc-indicator") ?? inp?.getAttribute("data-mask-utc-indicator");
|
|
5430
|
+
const attrInfer = wrap?.getAttribute("data-mask-infer-inputmode") ?? inp?.getAttribute("data-mask-infer-inputmode");
|
|
5431
|
+
const resolvedUtcIndicator = opts.utcIndicator !== void 0 ? opts.utcIndicator : attrUtcIndicator !== null ? attrUtcIndicator === "false" || attrUtcIndicator === "none" ? false : attrUtcIndicator : " UTC";
|
|
5432
|
+
const resolvedOptions = {
|
|
5433
|
+
...opts,
|
|
5434
|
+
format: opts.format ?? attrFormat ?? "YYYY-MM-DD HH:mm",
|
|
5435
|
+
utcIndicator: resolvedUtcIndicator,
|
|
5436
|
+
includeMilliseconds: opts.includeMilliseconds ?? false,
|
|
5437
|
+
convertPastedOffset: opts.convertPastedOffset ?? true,
|
|
5438
|
+
defaultTimeOnDateOnly: opts.defaultTimeOnDateOnly ?? false,
|
|
5439
|
+
inferInputMode: opts.inferInputMode ?? (attrInfer !== null ? attrInfer !== "false" : true),
|
|
5440
|
+
onInput: opts.onInput || opts.oninput,
|
|
5441
|
+
onChange: opts.onChange || opts.onchange,
|
|
5442
|
+
onComplete: opts.onComplete || opts.oncomplete
|
|
5443
|
+
};
|
|
5444
|
+
super(wrap, inp, resolvedOptions);
|
|
5445
|
+
this.history = new MaskHistory();
|
|
5446
|
+
this.engine = new DateUTCEngine(this.options);
|
|
5447
|
+
if (!this.input.hasAttribute("autocorrect")) {
|
|
5448
|
+
this.input.setAttribute("autocorrect", "off");
|
|
5449
|
+
this.wasAutocorrectSet = true;
|
|
5450
|
+
}
|
|
5451
|
+
if (!this.input.hasAttribute("autocapitalize")) {
|
|
5452
|
+
this.input.setAttribute("autocapitalize", "none");
|
|
5453
|
+
this.wasAutocapitalizeSet = true;
|
|
5454
|
+
}
|
|
5455
|
+
if (!this.input.hasAttribute("spellcheck")) {
|
|
5456
|
+
this.input.setAttribute("spellcheck", "false");
|
|
5457
|
+
this.wasSpellcheckSet = true;
|
|
5458
|
+
}
|
|
5459
|
+
this.syncInferredInputMode();
|
|
5460
|
+
this.bindEvents();
|
|
5461
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
5462
|
+
this.syncInitialValue();
|
|
5463
|
+
this.runAuditWarning(this.options.audit);
|
|
5464
|
+
}
|
|
5465
|
+
/**
|
|
5466
|
+
* Formate statiquement une date (Date, timestamp ms, ISO ou chaîne) sans DOM.
|
|
5467
|
+
*/
|
|
5468
|
+
static format(value, options = {}) {
|
|
5469
|
+
return DateUTCEngine.format(value, options);
|
|
5470
|
+
}
|
|
5471
|
+
getSpecificAuditWarnings() {
|
|
5472
|
+
const warnings = [];
|
|
5473
|
+
const describedbyWarnings = [];
|
|
5474
|
+
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings, true);
|
|
5475
|
+
const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
|
|
5476
|
+
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
5477
|
+
if (!hasValidDescribedby && !hasAriaPlaceholder && !this.options.disabled) {
|
|
5478
|
+
if (hasPlaceholder) {
|
|
5479
|
+
warnings.push(
|
|
5480
|
+
`Indication du format UTC fragile : placeholder seul dispara\xEEt \xE0 la saisie et l'indicateur UTC fant\xF4me est aria-hidden="true" ; d\xE9finissez aria-describedby ou aria-placeholder (WCAG 3.3.2).`
|
|
5481
|
+
);
|
|
5482
|
+
} else {
|
|
5483
|
+
warnings.push(
|
|
5484
|
+
"Indication du format UTC attendu manquante : d\xE9finissez aria-describedby ou aria-placeholder pour informer les technologies d'assistance du format et du r\xE9f\xE9rentiel UTC (WCAG 3.3.2)."
|
|
5485
|
+
);
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5488
|
+
return warnings;
|
|
5489
|
+
}
|
|
5490
|
+
extractRawSnippet(snippet) {
|
|
5491
|
+
if (!snippet) return "";
|
|
5492
|
+
if (snippet === this.input.value && this.isValid()) {
|
|
5493
|
+
return this.getRawValue();
|
|
5494
|
+
}
|
|
5495
|
+
return this.engine.extractRaw(snippet, false);
|
|
5496
|
+
}
|
|
5497
|
+
onPasswordModeDetected() {
|
|
5498
|
+
this.history.clear();
|
|
5499
|
+
this.lastValue = "";
|
|
5500
|
+
this.lastValueLength = 0;
|
|
5501
|
+
this.lastTrackedValue = "";
|
|
5502
|
+
this.clearGhost();
|
|
5503
|
+
}
|
|
5504
|
+
onNativeValueSet(strVal) {
|
|
5505
|
+
if (this.options.disabled) {
|
|
5506
|
+
this.checkValueChange(false);
|
|
5507
|
+
} else {
|
|
5508
|
+
const formatted = this.engine.formatFromNativeValue(strVal);
|
|
5509
|
+
this.applyFormatted(formatted, formatted.length, false);
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
onDisabledChange(disabled) {
|
|
5513
|
+
if (disabled) {
|
|
5514
|
+
this.wrapper.classList.remove("is-complete", "has-selection");
|
|
5515
|
+
this.clearGhost();
|
|
5516
|
+
this.checkValueChange(false);
|
|
5517
|
+
} else {
|
|
5518
|
+
const formatted = this.engine.formatFromValue(this.input.value);
|
|
5519
|
+
this.applyFormatted(formatted, this.input.selectionStart ?? formatted.length, false);
|
|
5520
|
+
}
|
|
5521
|
+
this.syncInferredInputMode();
|
|
5522
|
+
}
|
|
5523
|
+
handleAttributeMutation(attrName) {
|
|
5524
|
+
super.handleAttributeMutation(attrName);
|
|
5525
|
+
if (attrName === "data-mask-format") {
|
|
5526
|
+
const newFormat = this.getAttr("data-mask-format");
|
|
5527
|
+
if (newFormat && newFormat !== this.engine.getFormat()) {
|
|
5528
|
+
this.setFormat(newFormat);
|
|
5529
|
+
}
|
|
5530
|
+
} else if (attrName === "data-mask-utc-indicator") {
|
|
5531
|
+
const attrInd = this.getAttr("data-mask-utc-indicator");
|
|
5532
|
+
const indicator = attrInd === null || attrInd === "false" || attrInd === "none" ? false : attrInd;
|
|
5533
|
+
this.setUtcIndicator(indicator);
|
|
5534
|
+
} else if (attrName === "placeholder") {
|
|
5535
|
+
this.updateGhost(this.input.value);
|
|
5536
|
+
}
|
|
5537
|
+
}
|
|
5538
|
+
bindEvents() {
|
|
5539
|
+
this.onBeforeInput = this.onBeforeInput.bind(this);
|
|
5540
|
+
this.handleInput = this.handleInput.bind(this);
|
|
5541
|
+
this.onKeyDown = this.onKeyDown.bind(this);
|
|
5542
|
+
this.onPaste = this.onPaste.bind(this);
|
|
5543
|
+
this.onFocus = this.onFocus.bind(this);
|
|
5544
|
+
this.onBlur = this.onBlur.bind(this);
|
|
5545
|
+
this.onClick = this.onClick.bind(this);
|
|
5546
|
+
this.onKeyUp = this.onKeyUp.bind(this);
|
|
5547
|
+
this.onSelect = this.onSelect.bind(this);
|
|
5548
|
+
this.onMouseDown = this.onMouseDown.bind(this);
|
|
5549
|
+
this.onMouseUp = this.onMouseUp.bind(this);
|
|
5550
|
+
this.onCompositionStart = this.onCompositionStart.bind(this);
|
|
5551
|
+
this.onCompositionEnd = this.onCompositionEnd.bind(this);
|
|
5552
|
+
this.onCutHandler = () => {
|
|
5553
|
+
if (this.cutTimerId !== null) clearTimeout(this.cutTimerId);
|
|
5554
|
+
this.cutTimerId = window.setTimeout(() => {
|
|
5555
|
+
this.cutTimerId = null;
|
|
5556
|
+
if (this.isDestroyed) return;
|
|
5557
|
+
if (this.options.disabled) {
|
|
5558
|
+
this.checkValueChange(false);
|
|
5559
|
+
} else {
|
|
5560
|
+
const cur = this.input.selectionStart ?? this.input.value.length;
|
|
5561
|
+
this.applyFormatted(this.input.value, cur, false);
|
|
5562
|
+
}
|
|
5563
|
+
}, 0);
|
|
5564
|
+
};
|
|
5565
|
+
const onChangeNative = () => {
|
|
5566
|
+
if (this.isDestroyed) return;
|
|
5567
|
+
this.checkValueChange(true, true);
|
|
5568
|
+
};
|
|
5569
|
+
const { signal } = this.abortController;
|
|
5570
|
+
this.input.addEventListener("beforeinput", this.onBeforeInput, { signal });
|
|
5571
|
+
this.input.addEventListener("input", this.handleInput, { signal });
|
|
5572
|
+
this.input.addEventListener("keydown", this.onKeyDown, { signal });
|
|
5573
|
+
this.input.addEventListener("paste", this.onPaste, { signal });
|
|
5574
|
+
this.input.addEventListener("focus", this.onFocus, { signal });
|
|
5575
|
+
this.input.addEventListener("blur", this.onBlur, { signal });
|
|
5576
|
+
this.input.addEventListener("click", this.onClick, { signal });
|
|
5577
|
+
this.input.addEventListener("keyup", this.onKeyUp, { signal });
|
|
5578
|
+
this.input.addEventListener("select", this.onSelect, { signal });
|
|
5579
|
+
this.input.addEventListener("mousedown", this.onMouseDown, { signal });
|
|
5580
|
+
window.addEventListener("mouseup", this.onMouseUp, { signal });
|
|
5581
|
+
this.input.addEventListener("compositionstart", this.onCompositionStart, { signal });
|
|
5582
|
+
this.input.addEventListener("compositionend", this.onCompositionEnd, { signal });
|
|
5583
|
+
this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
|
|
5584
|
+
this.input.addEventListener("cut", this.onCutHandler, { signal });
|
|
5585
|
+
this.input.addEventListener("change", onChangeNative, { signal });
|
|
5586
|
+
if (this.input.form) {
|
|
5587
|
+
this.onFormResetHandler = () => {
|
|
5588
|
+
if (this.resetTimerId !== null) clearTimeout(this.resetTimerId);
|
|
5589
|
+
this.resetTimerId = window.setTimeout(() => {
|
|
5590
|
+
this.resetTimerId = null;
|
|
5591
|
+
if (this.isDestroyed) return;
|
|
5592
|
+
if (this.options.disabled) {
|
|
5593
|
+
this.checkValueChange(false);
|
|
5594
|
+
} else {
|
|
5595
|
+
this.syncInitialValue();
|
|
5596
|
+
}
|
|
5597
|
+
}, 0);
|
|
5598
|
+
};
|
|
5599
|
+
this.input.form.addEventListener("reset", this.onFormResetHandler, { signal });
|
|
5600
|
+
}
|
|
5601
|
+
}
|
|
5602
|
+
syncInferredInputMode() {
|
|
5603
|
+
if (this.options.inferInputMode === false) return;
|
|
5604
|
+
if (this.options.disabled) {
|
|
5605
|
+
if (this.inferredInputModeValue && this.input.getAttribute("inputmode") === this.inferredInputModeValue) {
|
|
5606
|
+
this.input.removeAttribute("inputmode");
|
|
5607
|
+
}
|
|
5608
|
+
this.inferredInputModeValue = null;
|
|
5609
|
+
return;
|
|
5610
|
+
}
|
|
5611
|
+
const desired = this.engine.isNumericOnly() ? "numeric" : "text";
|
|
5612
|
+
const currentAttr = this.input.getAttribute("inputmode");
|
|
5613
|
+
if (!currentAttr || this.inferredInputModeValue === currentAttr) {
|
|
5614
|
+
this.input.inputMode = desired;
|
|
5615
|
+
this.inferredInputModeValue = desired;
|
|
5616
|
+
}
|
|
5617
|
+
}
|
|
5618
|
+
// ==========================================================================
|
|
5619
|
+
// API Publique
|
|
5620
|
+
// ==========================================================================
|
|
5621
|
+
getDetail() {
|
|
5622
|
+
const result = this.engine.analyze(this.input.value, false);
|
|
5623
|
+
return {
|
|
5624
|
+
...result,
|
|
5625
|
+
value: this.options.disabled ? this.input.value : result.formatted
|
|
5626
|
+
};
|
|
5627
|
+
}
|
|
5628
|
+
getRawValue() {
|
|
5629
|
+
if (this.options.disabled) return this.input.value;
|
|
5630
|
+
return this.getDetail().rawValue;
|
|
5631
|
+
}
|
|
5632
|
+
getISOString() {
|
|
5633
|
+
return this.getDetail().isoString;
|
|
5634
|
+
}
|
|
5635
|
+
getDate() {
|
|
5636
|
+
return this.getDetail().date;
|
|
5637
|
+
}
|
|
5638
|
+
getTimestamp() {
|
|
5639
|
+
return this.getDetail().timestamp;
|
|
5640
|
+
}
|
|
5641
|
+
getParts() {
|
|
5642
|
+
return this.getDetail().parts;
|
|
5643
|
+
}
|
|
5644
|
+
/**
|
|
5645
|
+
* Progressive Enhancement Baseline : retourne un Temporal.Instant natif si supporté par le navigateur,
|
|
5646
|
+
* sinon null (zéro polyfill externe).
|
|
5647
|
+
*/
|
|
5648
|
+
getTemporalInstant() {
|
|
5649
|
+
const ts = this.getTimestamp();
|
|
5650
|
+
if (ts === null) return null;
|
|
5651
|
+
const globalTemporal = globalThis.Temporal;
|
|
5652
|
+
if (globalTemporal?.Instant && typeof globalTemporal.Instant.fromEpochMilliseconds === "function") {
|
|
5653
|
+
try {
|
|
5654
|
+
return globalTemporal.Instant.fromEpochMilliseconds(ts);
|
|
5655
|
+
} catch {
|
|
5656
|
+
return null;
|
|
5657
|
+
}
|
|
5658
|
+
}
|
|
5659
|
+
return null;
|
|
5660
|
+
}
|
|
5661
|
+
isComplete() {
|
|
5662
|
+
if (this.options.disabled) return true;
|
|
5663
|
+
return this.getDetail().isComplete;
|
|
5664
|
+
}
|
|
5665
|
+
isValid() {
|
|
5666
|
+
if (this.options.disabled) return true;
|
|
5667
|
+
return this.getDetail().isValid;
|
|
5668
|
+
}
|
|
5669
|
+
setValue(val) {
|
|
5670
|
+
if (this.options.disabled) {
|
|
5671
|
+
const str = val instanceof Date ? Number.isNaN(val.getTime()) ? "" : this.engine.formatDateToISO(val) : val !== null && val !== void 0 ? String(val) : "";
|
|
5672
|
+
this.setNativeValue(str);
|
|
5673
|
+
this.checkValueChange(false);
|
|
5674
|
+
return;
|
|
5675
|
+
}
|
|
5676
|
+
const formatted = this.engine.formatFromValue(val);
|
|
5677
|
+
this.applyFormatted(formatted, formatted.length, true);
|
|
5678
|
+
}
|
|
5679
|
+
/**
|
|
5680
|
+
* Remplit l'instant UTC courant.
|
|
5681
|
+
*/
|
|
5682
|
+
setNow() {
|
|
5683
|
+
this.setValue(/* @__PURE__ */ new Date());
|
|
5684
|
+
}
|
|
5685
|
+
/**
|
|
5686
|
+
* Convertit la date UTC saisie vers la locale demandée via Intl.DateTimeFormat (aperçu sans widget).
|
|
5687
|
+
*/
|
|
5688
|
+
formatLocal(locale, intlOptions) {
|
|
5689
|
+
return this.engine.formatLocal(this.getDate(), locale, intlOptions);
|
|
5690
|
+
}
|
|
5691
|
+
/**
|
|
5692
|
+
* Change dynamiquement le format (preset ou chaîne de tokens) et reconvertit la date courante si elle est valide.
|
|
5693
|
+
*/
|
|
5694
|
+
setFormat(format, placeholderTokens) {
|
|
5695
|
+
const currentDate = this.getDate();
|
|
5696
|
+
this.options.format = format;
|
|
5697
|
+
if (placeholderTokens !== void 0) {
|
|
5698
|
+
this.options.placeholderTokens = placeholderTokens;
|
|
5699
|
+
}
|
|
5700
|
+
this.engine.setFormat(format, placeholderTokens);
|
|
5701
|
+
this.syncInferredInputMode();
|
|
5702
|
+
if (this.options.disabled) {
|
|
5703
|
+
this.clearGhost();
|
|
5704
|
+
return;
|
|
5705
|
+
}
|
|
5706
|
+
if (currentDate) {
|
|
5707
|
+
const formatted = this.engine.formatFromValue(currentDate);
|
|
5708
|
+
this.applyFormatted(formatted, formatted.length, true);
|
|
5709
|
+
} else {
|
|
5710
|
+
const formatted = this.engine.format(this.input.value, false);
|
|
5711
|
+
this.applyFormatted(formatted, Math.min(this.input.selectionStart ?? formatted.length, formatted.length), false);
|
|
5712
|
+
}
|
|
5713
|
+
}
|
|
5714
|
+
setUtcIndicator(indicator) {
|
|
5715
|
+
this.options.utcIndicator = indicator;
|
|
5716
|
+
this.engine.setUtcIndicator(indicator);
|
|
5717
|
+
this.updateGhost(this.input.value);
|
|
5718
|
+
}
|
|
5719
|
+
undo() {
|
|
5720
|
+
if (this.options.disabled) return;
|
|
5721
|
+
const state = this.history.undo();
|
|
5722
|
+
if (state) {
|
|
5723
|
+
this.isUndoingRedoing = true;
|
|
5724
|
+
try {
|
|
5725
|
+
this.applyFormatted(this.engine.format(state.raw, false), state.cursor, true);
|
|
5726
|
+
} finally {
|
|
5727
|
+
this.isUndoingRedoing = false;
|
|
5728
|
+
}
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
redo() {
|
|
5732
|
+
if (this.options.disabled) return;
|
|
5733
|
+
const state = this.history.redo();
|
|
5734
|
+
if (state) {
|
|
5735
|
+
this.isUndoingRedoing = true;
|
|
5736
|
+
try {
|
|
5737
|
+
this.applyFormatted(this.engine.format(state.raw, false), state.cursor, true);
|
|
5738
|
+
} finally {
|
|
5739
|
+
this.isUndoingRedoing = false;
|
|
5740
|
+
}
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5743
|
+
destroy() {
|
|
5744
|
+
if (this.isDestroyed) return;
|
|
5745
|
+
if (this.cutTimerId !== null) {
|
|
5746
|
+
clearTimeout(this.cutTimerId);
|
|
5747
|
+
this.cutTimerId = null;
|
|
5748
|
+
}
|
|
5749
|
+
if (this.pasteTimerId !== null) {
|
|
5750
|
+
clearTimeout(this.pasteTimerId);
|
|
5751
|
+
this.pasteTimerId = null;
|
|
5752
|
+
}
|
|
5753
|
+
if (this.resetTimerId !== null) {
|
|
5754
|
+
clearTimeout(this.resetTimerId);
|
|
5755
|
+
this.resetTimerId = null;
|
|
5756
|
+
}
|
|
5757
|
+
if (this.inferredInputModeValue && this.input.getAttribute("inputmode") === this.inferredInputModeValue) {
|
|
5758
|
+
this.input.removeAttribute("inputmode");
|
|
5759
|
+
}
|
|
5760
|
+
if (this.wasAutocorrectSet) this.input.removeAttribute("autocorrect");
|
|
5761
|
+
if (this.wasAutocapitalizeSet) this.input.removeAttribute("autocapitalize");
|
|
5762
|
+
if (this.wasSpellcheckSet) this.input.removeAttribute("spellcheck");
|
|
5763
|
+
this.history.clear();
|
|
5764
|
+
this.lastValue = "";
|
|
5765
|
+
this.lastValueLength = 0;
|
|
5766
|
+
super.destroy();
|
|
5767
|
+
}
|
|
5768
|
+
// ==========================================================================
|
|
5769
|
+
// Événements DOM & Clavier
|
|
5770
|
+
// ==========================================================================
|
|
5771
|
+
checkSelection() {
|
|
5772
|
+
if (this.options.disabled) return;
|
|
5773
|
+
const start = this.input.selectionStart ?? 0;
|
|
5774
|
+
const end = this.input.selectionEnd ?? start;
|
|
5775
|
+
this.wrapper.classList.toggle("has-selection", start !== end);
|
|
5776
|
+
}
|
|
5777
|
+
onBeforeInput(e) {
|
|
5778
|
+
this.lastInputType = e.inputType || "";
|
|
5779
|
+
if (this.options.disabled || this.isComposing) return;
|
|
5780
|
+
if (e.inputType === "insertFromPaste" || e.inputType === "insertReplacementText") return;
|
|
5781
|
+
if (e.inputType && e.inputType.startsWith("insert")) {
|
|
5782
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5783
|
+
if (totalSlots > 0) {
|
|
5784
|
+
const currentRaw = this.engine.extractRaw(this.input.value, false);
|
|
5785
|
+
const start = this.input.selectionStart ?? 0;
|
|
5786
|
+
const end = this.input.selectionEnd ?? start;
|
|
5787
|
+
let available = Math.max(0, totalSlots - currentRaw.length);
|
|
5788
|
+
if (end > start) {
|
|
5789
|
+
const selectedRaw = this.engine.extractRaw(this.input.value.slice(start, end), false);
|
|
5790
|
+
available = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
5791
|
+
}
|
|
5792
|
+
if (available <= 0) {
|
|
5793
|
+
e.preventDefault();
|
|
5794
|
+
}
|
|
5795
|
+
}
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
handleInput(e) {
|
|
5799
|
+
if (this.isDispatchingNativeInput || this.isComposing) return;
|
|
5800
|
+
if (this.options.disabled) {
|
|
5801
|
+
this.checkValueChange(false);
|
|
5802
|
+
return;
|
|
5803
|
+
}
|
|
5804
|
+
const inputType = e?.inputType || this.lastInputType || "";
|
|
5805
|
+
this.lastInputType = "";
|
|
5806
|
+
const val = this.input.value;
|
|
5807
|
+
const cursor = this.input.selectionStart ?? val.length;
|
|
5808
|
+
const prevState = this.history.getCurrent();
|
|
5809
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5810
|
+
const isShorter = inputType.startsWith("delete") || !this.isSensitiveField() && val.length < this.lastValueLength;
|
|
5811
|
+
const newRawNoExpand = this.engine.extractRaw(val, false);
|
|
5812
|
+
if (totalSlots > 0 && prevState && prevState.raw.length >= totalSlots && newRawNoExpand.length > totalSlots) {
|
|
5813
|
+
const prevFormatted = this.engine.format(prevState.raw, false);
|
|
5814
|
+
this.applyFormatted(prevFormatted, prevState.cursor, true);
|
|
5815
|
+
return;
|
|
5816
|
+
}
|
|
5817
|
+
let candidate = val;
|
|
5818
|
+
let expandMeridiem = !isShorter;
|
|
5819
|
+
if (isShorter && this.engine.hasMeridiem()) {
|
|
5820
|
+
for (const seg of this.engine.getSegments()) {
|
|
5821
|
+
if (seg.kind === "A" && val.length >= seg.start + 1 && val.length < seg.end) {
|
|
5822
|
+
candidate = val.slice(0, seg.start) + val.slice(seg.start + 1);
|
|
5823
|
+
expandMeridiem = false;
|
|
5824
|
+
break;
|
|
5825
|
+
}
|
|
5826
|
+
}
|
|
5827
|
+
}
|
|
5828
|
+
this.applyFormatted(candidate, cursor, false, expandMeridiem);
|
|
5829
|
+
this.checkSelection();
|
|
5830
|
+
}
|
|
5831
|
+
onKeyDown(e) {
|
|
5832
|
+
if (this.options.disabled || isImeComposing(e)) return;
|
|
5833
|
+
const cursor = this.input.selectionStart ?? 0;
|
|
5834
|
+
const selectionEnd = this.input.selectionEnd ?? cursor;
|
|
5835
|
+
const minPos = this.engine.getPrefixLength();
|
|
5836
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z") && !e.shiftKey) {
|
|
5837
|
+
e.preventDefault();
|
|
5838
|
+
this.undo();
|
|
5839
|
+
return;
|
|
5840
|
+
}
|
|
5841
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "y" || e.key === "Y") || (e.ctrlKey || e.metaKey) && e.shiftKey && (e.key === "z" || e.key === "Z")) {
|
|
5842
|
+
e.preventDefault();
|
|
5843
|
+
this.redo();
|
|
5844
|
+
return;
|
|
5845
|
+
}
|
|
5846
|
+
this.history.updateCurrentCursor(cursor);
|
|
5847
|
+
const isPrintable = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
5848
|
+
const hasSelection = selectionEnd > cursor;
|
|
5849
|
+
if (isPrintable && !hasSelection) {
|
|
5850
|
+
const sepResult = this.engine.tryHandleSeparatorKey(this.input.value, cursor, e.key);
|
|
5851
|
+
if (sepResult.handled) {
|
|
5852
|
+
e.preventDefault();
|
|
5853
|
+
this.applyFormatted(sepResult.formatted, sepResult.cursor, true);
|
|
5854
|
+
return;
|
|
5855
|
+
}
|
|
5856
|
+
if (this.engine.hasMeridiem()) {
|
|
5857
|
+
for (const seg of this.engine.getSegments()) {
|
|
5858
|
+
if (seg.kind === "A" && cursor >= seg.start && cursor <= seg.end) {
|
|
5859
|
+
const up = e.key.toUpperCase();
|
|
5860
|
+
if (up === "A" || up === "P") {
|
|
5861
|
+
e.preventDefault();
|
|
5862
|
+
const meridiem = up === "A" ? "AM" : "PM";
|
|
5863
|
+
const val = this.input.value;
|
|
5864
|
+
const updated = val.slice(0, seg.start) + meridiem + val.slice(Math.min(val.length, seg.end));
|
|
5865
|
+
this.applyFormatted(updated, seg.end, true);
|
|
5866
|
+
return;
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
5869
|
+
}
|
|
5870
|
+
}
|
|
5871
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5872
|
+
if (totalSlots > 0 && this.engine.extractRaw(this.input.value, false).length >= totalSlots) {
|
|
5873
|
+
e.preventDefault();
|
|
5874
|
+
return;
|
|
5875
|
+
}
|
|
5876
|
+
}
|
|
5877
|
+
if (hasSelection) {
|
|
5878
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
5879
|
+
e.preventDefault();
|
|
5880
|
+
const val = this.input.value;
|
|
5881
|
+
const updated = val.slice(0, cursor) + val.slice(selectionEnd);
|
|
5882
|
+
this.applyFormatted(updated, Math.max(minPos, cursor), false);
|
|
5883
|
+
return;
|
|
5884
|
+
}
|
|
5885
|
+
return;
|
|
5886
|
+
}
|
|
5887
|
+
if (e.key === "ArrowLeft" && !e.shiftKey && cursor <= minPos) {
|
|
5888
|
+
e.preventDefault();
|
|
5889
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5890
|
+
return;
|
|
5891
|
+
}
|
|
5892
|
+
if (e.key === "Home" && minPos > 0 && !e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
5893
|
+
e.preventDefault();
|
|
5894
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5897
|
+
if (e.key === "Backspace" && cursor <= minPos) {
|
|
5898
|
+
e.preventDefault();
|
|
5899
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5900
|
+
return;
|
|
5901
|
+
}
|
|
5902
|
+
if (e.key === "Delete" && cursor < minPos) {
|
|
5903
|
+
e.preventDefault();
|
|
5904
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5905
|
+
return;
|
|
5906
|
+
}
|
|
5907
|
+
if (e.key === "Backspace" && this.engine.hasMeridiem()) {
|
|
5908
|
+
for (const seg of this.engine.getSegments()) {
|
|
5909
|
+
if (seg.kind === "A" && cursor > seg.start && cursor <= seg.end) {
|
|
5910
|
+
e.preventDefault();
|
|
5911
|
+
const val = this.input.value;
|
|
5912
|
+
const updated = val.slice(0, seg.start) + val.slice(Math.min(val.length, seg.end));
|
|
5913
|
+
this.applyFormatted(updated, seg.start, true);
|
|
5914
|
+
return;
|
|
5915
|
+
}
|
|
5916
|
+
}
|
|
5917
|
+
}
|
|
5918
|
+
if (e.key === "Backspace" && (e.ctrlKey || e.altKey || e.metaKey)) {
|
|
5919
|
+
e.preventDefault();
|
|
5920
|
+
if (cursor <= minPos) {
|
|
5921
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5922
|
+
return;
|
|
5923
|
+
}
|
|
5924
|
+
let i = cursor - 1;
|
|
5925
|
+
while (i >= minPos && this.engine.isSeparatorAt(i)) i--;
|
|
5926
|
+
while (i >= minPos && !this.engine.isSeparatorAt(i)) i--;
|
|
5927
|
+
const startPos = Math.max(minPos, i + 1);
|
|
5928
|
+
const val = this.input.value;
|
|
5929
|
+
this.applyFormatted(val.slice(0, startPos) + val.slice(cursor), startPos, true);
|
|
5930
|
+
return;
|
|
5931
|
+
}
|
|
5932
|
+
if (e.key === "Delete" && (e.ctrlKey || e.altKey || e.metaKey)) {
|
|
5933
|
+
e.preventDefault();
|
|
5934
|
+
const val = this.input.value;
|
|
5935
|
+
if (cursor >= val.length) return;
|
|
5936
|
+
let i = cursor;
|
|
5937
|
+
while (i < val.length && this.engine.isSeparatorAt(i)) i++;
|
|
5938
|
+
while (i < val.length && !this.engine.isSeparatorAt(i)) i++;
|
|
5939
|
+
while (i < val.length && this.engine.isSeparatorAt(i)) i++;
|
|
5940
|
+
this.applyFormatted(val.slice(0, cursor) + val.slice(i), cursor, true);
|
|
5941
|
+
return;
|
|
5942
|
+
}
|
|
5943
|
+
if (e.key === "Backspace" && cursor > minPos && this.engine.isSeparatorAt(cursor - 1)) {
|
|
5944
|
+
e.preventDefault();
|
|
5945
|
+
let targetPos = cursor - 1;
|
|
5946
|
+
while (targetPos > minPos && this.engine.isSeparatorAt(targetPos - 1)) {
|
|
5947
|
+
targetPos--;
|
|
5948
|
+
}
|
|
5949
|
+
if (targetPos > minPos) {
|
|
5950
|
+
const val = this.input.value;
|
|
5951
|
+
this.applyFormatted(val.slice(0, targetPos - 1) + val.slice(cursor), targetPos - 1, false);
|
|
5952
|
+
} else {
|
|
5953
|
+
this.applyFormatted("", minPos, true);
|
|
5954
|
+
}
|
|
5955
|
+
return;
|
|
5956
|
+
}
|
|
5957
|
+
if (e.key === "Delete" && cursor < this.input.value.length && this.engine.isSeparatorAt(cursor)) {
|
|
5958
|
+
e.preventDefault();
|
|
5959
|
+
let targetPos = cursor;
|
|
5960
|
+
while (targetPos < this.input.value.length && this.engine.isSeparatorAt(targetPos)) {
|
|
5961
|
+
targetPos++;
|
|
5962
|
+
}
|
|
5963
|
+
if (targetPos < this.input.value.length) {
|
|
5964
|
+
const val = this.input.value;
|
|
5965
|
+
this.applyFormatted(val.slice(0, targetPos) + val.slice(targetPos + 1), cursor, true);
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
}
|
|
5969
|
+
onPaste(e) {
|
|
5970
|
+
if (this.options.disabled) {
|
|
5971
|
+
if (this.pasteTimerId !== null) clearTimeout(this.pasteTimerId);
|
|
5972
|
+
this.pasteTimerId = window.setTimeout(() => {
|
|
5973
|
+
this.pasteTimerId = null;
|
|
5974
|
+
if (!this.isDestroyed) this.checkValueChange(false);
|
|
5975
|
+
}, 0);
|
|
5976
|
+
return;
|
|
5977
|
+
}
|
|
5978
|
+
e.preventDefault();
|
|
5979
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
5980
|
+
const pastedText = this.preparePastedText(this.getClipboardPlainText(e), 512);
|
|
5981
|
+
if (!pastedText) return;
|
|
5982
|
+
const minPos = this.engine.getPrefixLength();
|
|
5983
|
+
const selStart = this.input.selectionStart ?? 0;
|
|
5984
|
+
const selEnd = this.input.selectionEnd ?? selStart;
|
|
5985
|
+
const currentVal = this.input.value;
|
|
5986
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5987
|
+
const currentRaw = this.engine.extractRaw(currentVal, false);
|
|
5988
|
+
const isGlobalOrEmpty = currentRaw.length === 0 || selStart <= minPos && selEnd >= currentVal.length || selStart === selEnd;
|
|
5989
|
+
if (isGlobalOrEmpty) {
|
|
5990
|
+
const parsed = this.engine.parsePasted(pastedText);
|
|
5991
|
+
if (parsed.matched) {
|
|
5992
|
+
this.applyFormatted(parsed.formatted, parsed.cursor, true);
|
|
5993
|
+
if (parsed.offsetConverted && this.options.onOffsetConverted) {
|
|
5994
|
+
try {
|
|
5995
|
+
this.options.onOffsetConverted(parsed.offsetConverted);
|
|
5996
|
+
} catch {
|
|
5997
|
+
}
|
|
5998
|
+
}
|
|
5999
|
+
this.checkSelection();
|
|
6000
|
+
return;
|
|
6001
|
+
}
|
|
6002
|
+
if (parsed.rejected) {
|
|
3426
6003
|
return;
|
|
3427
6004
|
}
|
|
3428
6005
|
}
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
this.
|
|
3432
|
-
|
|
6006
|
+
let available = Math.max(0, totalSlots - currentRaw.length);
|
|
6007
|
+
if (selEnd > selStart) {
|
|
6008
|
+
const selectedRaw = this.engine.extractRaw(currentVal.slice(selStart, selEnd), false);
|
|
6009
|
+
available = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
3433
6010
|
}
|
|
3434
|
-
if (
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
6011
|
+
if (available <= 0) return;
|
|
6012
|
+
const effectiveStart = Math.max(minPos, selStart);
|
|
6013
|
+
const effectiveEnd = Math.max(minPos, selEnd);
|
|
6014
|
+
const combined = currentVal.slice(0, effectiveStart) + pastedText + currentVal.slice(effectiveEnd);
|
|
6015
|
+
this.applyFormatted(combined, effectiveStart + pastedText.length, false, true);
|
|
6016
|
+
this.checkSelection();
|
|
6017
|
+
}
|
|
6018
|
+
onFocus() {
|
|
6019
|
+
this.syncGhostStyles();
|
|
6020
|
+
this.wrapper.classList.add("is-focused");
|
|
6021
|
+
if (!this.options.disabled && !this.isMouseDown) {
|
|
6022
|
+
this.enforceMinCursor();
|
|
3438
6023
|
}
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
6024
|
+
this.updateGhost(this.input.value);
|
|
6025
|
+
this.checkSelection();
|
|
6026
|
+
}
|
|
6027
|
+
onBlur() {
|
|
6028
|
+
this.wrapper.classList.remove("is-focused", "has-selection");
|
|
6029
|
+
if (this.isSensitiveField()) {
|
|
6030
|
+
this.onPasswordModeDetected();
|
|
3442
6031
|
return;
|
|
3443
6032
|
}
|
|
6033
|
+
this.updateGhost(this.input.value);
|
|
6034
|
+
this.checkValueChange(false, true);
|
|
3444
6035
|
}
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
acceptSuggestion() {
|
|
3449
|
-
if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.input.value.length === 0) return false;
|
|
3450
|
-
const completed = this.currentSuggestion.full;
|
|
3451
|
-
this.setNativeValue(completed);
|
|
3452
|
-
this.input.setSelectionRange(completed.length, completed.length);
|
|
3453
|
-
this.currentSuggestionIndex = 0;
|
|
3454
|
-
this.updateSuggestion();
|
|
3455
|
-
const detail = this.getDetail();
|
|
3456
|
-
if (this.options.onChange) {
|
|
3457
|
-
this.options.onChange(detail);
|
|
6036
|
+
onClick() {
|
|
6037
|
+
if (!this.options.disabled) {
|
|
6038
|
+
this.enforceMinCursor();
|
|
3458
6039
|
}
|
|
3459
|
-
this.input.
|
|
3460
|
-
this.
|
|
3461
|
-
return true;
|
|
6040
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
6041
|
+
this.checkSelection();
|
|
3462
6042
|
}
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
6043
|
+
onKeyUp(e) {
|
|
6044
|
+
if (!this.options.disabled) {
|
|
6045
|
+
if ((e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Home") && !e.shiftKey) {
|
|
6046
|
+
this.enforceMinCursor();
|
|
6047
|
+
}
|
|
6048
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
6049
|
+
}
|
|
6050
|
+
this.checkSelection();
|
|
3469
6051
|
}
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
setDefaultTld(tld) {
|
|
3474
|
-
this.engine.setDefaultTld(tld);
|
|
3475
|
-
this.updateSuggestion();
|
|
6052
|
+
onSelect() {
|
|
6053
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
6054
|
+
this.checkSelection();
|
|
3476
6055
|
}
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
*/
|
|
3480
|
-
setTlds(tlds) {
|
|
3481
|
-
this.engine.setTlds(tlds);
|
|
3482
|
-
this.currentSuggestionIndex = 0;
|
|
3483
|
-
this.updateSuggestion();
|
|
6056
|
+
onMouseDown() {
|
|
6057
|
+
this.isMouseDown = true;
|
|
3484
6058
|
}
|
|
3485
|
-
|
|
3486
|
-
this.
|
|
3487
|
-
this.
|
|
3488
|
-
this.updateSuggestion();
|
|
6059
|
+
onMouseUp() {
|
|
6060
|
+
this.isMouseDown = false;
|
|
6061
|
+
this.checkSelection();
|
|
3489
6062
|
}
|
|
3490
|
-
|
|
3491
|
-
this.
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
this.
|
|
3497
|
-
|
|
3498
|
-
|
|
6063
|
+
onCompositionStart() {
|
|
6064
|
+
this.isComposing = true;
|
|
6065
|
+
}
|
|
6066
|
+
onCompositionEnd() {
|
|
6067
|
+
this.isComposing = false;
|
|
6068
|
+
if (this.options.disabled) return;
|
|
6069
|
+
const cur = this.input.selectionStart ?? this.input.value.length;
|
|
6070
|
+
this.applyFormatted(this.input.value, cur, false, true);
|
|
6071
|
+
this.checkSelection();
|
|
6072
|
+
}
|
|
6073
|
+
enforceMinCursor() {
|
|
6074
|
+
const minPos = this.engine.getPrefixLength();
|
|
6075
|
+
if (minPos <= 0) return;
|
|
6076
|
+
const start = this.input.selectionStart ?? 0;
|
|
6077
|
+
const end = this.input.selectionEnd ?? start;
|
|
6078
|
+
if (start !== end) return;
|
|
6079
|
+
if (start < minPos) {
|
|
6080
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
3499
6081
|
}
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
6082
|
+
}
|
|
6083
|
+
// ==========================================================================
|
|
6084
|
+
// Synchronisation & Notifications
|
|
6085
|
+
// ==========================================================================
|
|
6086
|
+
updateGhost(formatted) {
|
|
6087
|
+
if (!this.ghost) return;
|
|
6088
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
3503
6089
|
this.clearGhost();
|
|
3504
6090
|
return;
|
|
3505
6091
|
}
|
|
3506
|
-
this.
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
6092
|
+
const isCleanEmpty = !formatted || formatted === this.engine.getPrefix();
|
|
6093
|
+
if (this.shouldHideGhostForPlaceholder(isCleanEmpty)) {
|
|
6094
|
+
this.clearGhost();
|
|
6095
|
+
return;
|
|
3510
6096
|
}
|
|
3511
|
-
this.
|
|
6097
|
+
const remaining = this.engine.getGhostRemaining(formatted);
|
|
6098
|
+
const doc = this.input.ownerDocument || document;
|
|
6099
|
+
const spanTyped = doc.createElement("span");
|
|
6100
|
+
spanTyped.className = "mask-ghost-typed";
|
|
6101
|
+
spanTyped.textContent = formatted;
|
|
6102
|
+
const spanRemaining = doc.createElement("span");
|
|
6103
|
+
spanRemaining.className = "mask-ghost-remaining";
|
|
6104
|
+
spanRemaining.textContent = remaining;
|
|
6105
|
+
this.setGhostContent(spanTyped, spanRemaining);
|
|
6106
|
+
this.ghost.scrollLeft = this.input.scrollLeft;
|
|
3512
6107
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
6108
|
+
applyFormatted(rawOrPartial, cursorPosition, forceExactCursor = false, expandSingleMeridiem = false) {
|
|
6109
|
+
if (this.options.disabled || this.isApplying) return;
|
|
6110
|
+
this.isApplying = true;
|
|
6111
|
+
try {
|
|
6112
|
+
const formatted = this.engine.format(rawOrPartial, expandSingleMeridiem);
|
|
6113
|
+
const isSensitive = this.isSensitiveField();
|
|
6114
|
+
this.setNativeValue(formatted);
|
|
6115
|
+
if (isSensitive) {
|
|
6116
|
+
this.clearGhost();
|
|
6117
|
+
} else {
|
|
6118
|
+
this.updateGhost(formatted);
|
|
6119
|
+
}
|
|
6120
|
+
const minPos = this.engine.getPrefixLength();
|
|
6121
|
+
let safeCursor;
|
|
6122
|
+
if (forceExactCursor || this.isUndoingRedoing) {
|
|
6123
|
+
safeCursor = Math.max(minPos, Math.min(cursorPosition, formatted.length));
|
|
6124
|
+
} else {
|
|
6125
|
+
safeCursor = Math.max(minPos, this.engine.mapCursorPosition(rawOrPartial, cursorPosition, formatted));
|
|
6126
|
+
}
|
|
6127
|
+
this.input.setSelectionRange(safeCursor, safeCursor);
|
|
6128
|
+
const analysis = this.engine.analyze(formatted, false);
|
|
6129
|
+
this.wrapper.classList.toggle("is-complete", analysis.isComplete);
|
|
6130
|
+
if (isSensitive) {
|
|
6131
|
+
this.options.copyRaw = false;
|
|
6132
|
+
this.lastValueLength = 0;
|
|
6133
|
+
this.history.clear();
|
|
6134
|
+
} else {
|
|
6135
|
+
this.lastValueLength = formatted.length;
|
|
6136
|
+
if (!this.isUndoingRedoing) {
|
|
6137
|
+
this.history.push(this.engine.extractRaw(formatted, false), safeCursor);
|
|
6138
|
+
}
|
|
6139
|
+
}
|
|
6140
|
+
} finally {
|
|
6141
|
+
this.isApplying = false;
|
|
3527
6142
|
}
|
|
6143
|
+
this.checkValueChange(false);
|
|
3528
6144
|
}
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
const str = val !== null && val !== void 0 ? String(val) : "";
|
|
3538
|
-
this.setNativeValue(str);
|
|
3539
|
-
this.updateSuggestion();
|
|
3540
|
-
}
|
|
3541
|
-
destroy() {
|
|
3542
|
-
if (this.isDestroyed) return;
|
|
3543
|
-
if (this.cutTimerId !== null) {
|
|
3544
|
-
clearTimeout(this.cutTimerId);
|
|
3545
|
-
this.cutTimerId = null;
|
|
3546
|
-
}
|
|
3547
|
-
if (this.resetTimerId !== null) {
|
|
3548
|
-
clearTimeout(this.resetTimerId);
|
|
3549
|
-
this.resetTimerId = null;
|
|
3550
|
-
}
|
|
3551
|
-
if (this.srAnnounceTimerId !== null) {
|
|
3552
|
-
clearTimeout(this.srAnnounceTimerId);
|
|
3553
|
-
this.srAnnounceTimerId = null;
|
|
3554
|
-
}
|
|
3555
|
-
if (this.srStatusEl) {
|
|
3556
|
-
this.srStatusEl.remove();
|
|
3557
|
-
this.srStatusEl = null;
|
|
3558
|
-
}
|
|
3559
|
-
this.lastNotifiedValue = "";
|
|
3560
|
-
this.lastAnnouncedSuggestion = "";
|
|
3561
|
-
if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "email") {
|
|
3562
|
-
this.input.removeAttribute("inputmode");
|
|
6145
|
+
syncInitialValue() {
|
|
6146
|
+
const isSensitive = this.isSensitiveField();
|
|
6147
|
+
if (this.options.disabled) {
|
|
6148
|
+
this.clearGhost();
|
|
6149
|
+
this.lastValue = isSensitive ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
6150
|
+
this.lastValueLength = isSensitive ? 0 : this.input.value.length;
|
|
6151
|
+
this.checkValueChange(false);
|
|
6152
|
+
return;
|
|
3563
6153
|
}
|
|
3564
|
-
|
|
3565
|
-
|
|
6154
|
+
this.syncGhostStyles();
|
|
6155
|
+
const initialVal = this.input.value || "";
|
|
6156
|
+
if (initialVal) {
|
|
6157
|
+
const formatted = this.engine.formatFromValue(initialVal);
|
|
6158
|
+
this.applyFormatted(formatted, formatted.length, true);
|
|
6159
|
+
} else {
|
|
6160
|
+
const minPos = this.engine.getPrefixLength();
|
|
6161
|
+
if (minPos > 0) {
|
|
6162
|
+
this.applyFormatted("", minPos, true);
|
|
6163
|
+
} else {
|
|
6164
|
+
if (!isSensitive) {
|
|
6165
|
+
this.history.push("", 0);
|
|
6166
|
+
this.updateGhost("");
|
|
6167
|
+
} else {
|
|
6168
|
+
this.clearGhost();
|
|
6169
|
+
}
|
|
6170
|
+
this.checkValueChange(false);
|
|
6171
|
+
}
|
|
3566
6172
|
}
|
|
3567
|
-
|
|
3568
|
-
|
|
6173
|
+
}
|
|
6174
|
+
checkValueChange(forceNotify = false, emitChangeEvent = false) {
|
|
6175
|
+
const initialSensitive = this.isSensitiveField();
|
|
6176
|
+
const currentVal = this.input.value;
|
|
6177
|
+
const currentComparison = initialSensitive ? this.computePasswordDigest(currentVal) : currentVal;
|
|
6178
|
+
if (currentComparison === this.lastValue && !forceNotify && !this.hasPendingNotification) {
|
|
6179
|
+
if (emitChangeEvent) {
|
|
6180
|
+
const allowBubble = !initialSensitive;
|
|
6181
|
+
const detail = this.getDetail();
|
|
6182
|
+
const onChangeCb = this.options.onChange || this.options.onchange;
|
|
6183
|
+
if (onChangeCb) onChangeCb(detail);
|
|
6184
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
6185
|
+
}
|
|
6186
|
+
return;
|
|
3569
6187
|
}
|
|
3570
|
-
if (this.
|
|
3571
|
-
this.
|
|
6188
|
+
if (this.isNotifying) {
|
|
6189
|
+
this.hasPendingNotification = true;
|
|
6190
|
+
return;
|
|
3572
6191
|
}
|
|
3573
|
-
|
|
3574
|
-
|
|
6192
|
+
this.isNotifying = true;
|
|
6193
|
+
try {
|
|
6194
|
+
let iterations = 0;
|
|
6195
|
+
while (((this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS3) {
|
|
6196
|
+
iterations++;
|
|
6197
|
+
this.hasPendingNotification = false;
|
|
6198
|
+
forceNotify = false;
|
|
6199
|
+
const sensitiveNow = this.isSensitiveField();
|
|
6200
|
+
const allowBubble = !sensitiveNow;
|
|
6201
|
+
const valToNotify = this.input.value;
|
|
6202
|
+
this.lastValue = sensitiveNow ? this.computePasswordDigest(valToNotify) : valToNotify;
|
|
6203
|
+
this.lastValueLength = sensitiveNow ? 0 : valToNotify.length;
|
|
6204
|
+
const detail = this.getDetail();
|
|
6205
|
+
const onInputCb = this.options.onInput || this.options.oninput;
|
|
6206
|
+
if (onInputCb) onInputCb(detail);
|
|
6207
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: allowBubble, detail }));
|
|
6208
|
+
this.dispatchNativeInput();
|
|
6209
|
+
if (emitChangeEvent) {
|
|
6210
|
+
const onChangeCb = this.options.onChange || this.options.onchange;
|
|
6211
|
+
if (onChangeCb) onChangeCb(detail);
|
|
6212
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
6213
|
+
}
|
|
6214
|
+
if (detail.isComplete) {
|
|
6215
|
+
const onCompleteCb = this.options.onComplete || this.options.oncomplete;
|
|
6216
|
+
if (onCompleteCb) onCompleteCb(detail);
|
|
6217
|
+
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles: allowBubble, detail }));
|
|
6218
|
+
}
|
|
6219
|
+
}
|
|
6220
|
+
} finally {
|
|
6221
|
+
this.isNotifying = false;
|
|
3575
6222
|
}
|
|
3576
|
-
super.destroy();
|
|
3577
6223
|
}
|
|
3578
6224
|
};
|
|
3579
6225
|
|
|
@@ -3587,7 +6233,12 @@ var __WulfIIFE = (() => {
|
|
|
3587
6233
|
AmountEngine,
|
|
3588
6234
|
InputAmountMask,
|
|
3589
6235
|
EmailEngine,
|
|
3590
|
-
InputEmailMask
|
|
6236
|
+
InputEmailMask,
|
|
6237
|
+
DateUTCEngine,
|
|
6238
|
+
DATE_UTC_PRESETS,
|
|
6239
|
+
InputDateUTCMask,
|
|
6240
|
+
sanitizePastedText,
|
|
6241
|
+
stripBidiAndInvisibles
|
|
3591
6242
|
};
|
|
3592
6243
|
var wulfNamespace = getSafeWulfNamespace();
|
|
3593
6244
|
if (wulfNamespace) {
|
|
@@ -4518,8 +7169,8 @@ var __WulfIIFE = (() => {
|
|
|
4518
7169
|
if (el) {
|
|
4519
7170
|
const vpRect = this.viewport.getBoundingClientRect();
|
|
4520
7171
|
const elRect = el.getBoundingClientRect();
|
|
4521
|
-
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
4522
|
-
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
7172
|
+
targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
|
|
7173
|
+
targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
|
|
4523
7174
|
}
|
|
4524
7175
|
break;
|
|
4525
7176
|
}
|
|
@@ -4527,8 +7178,8 @@ var __WulfIIFE = (() => {
|
|
|
4527
7178
|
} else if (target instanceof HTMLElement) {
|
|
4528
7179
|
const vpRect = this.viewport.getBoundingClientRect();
|
|
4529
7180
|
const elRect = target.getBoundingClientRect();
|
|
4530
|
-
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
4531
|
-
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
7181
|
+
targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
|
|
7182
|
+
targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
|
|
4532
7183
|
} else if (typeof target === "object" && target !== null) {
|
|
4533
7184
|
targetTop = target.top;
|
|
4534
7185
|
targetLeft = target.left;
|
|
@@ -5772,6 +8423,9 @@ var __WulfIIFE = (() => {
|
|
|
5772
8423
|
this.isPausedByFocus = false;
|
|
5773
8424
|
} else if (source === "hover") {
|
|
5774
8425
|
this.isPausedByHover = false;
|
|
8426
|
+
if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
|
|
8427
|
+
this.isPausedByFocus = true;
|
|
8428
|
+
}
|
|
5775
8429
|
} else {
|
|
5776
8430
|
this.isPausedByHover = false;
|
|
5777
8431
|
this.isPausedByFocus = false;
|