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.esm.js
CHANGED
|
@@ -9,8 +9,11 @@ var mask_exports = {};
|
|
|
9
9
|
__export(mask_exports, {
|
|
10
10
|
AmountEngine: () => AmountEngine,
|
|
11
11
|
BaseInputMask: () => BaseInputMask,
|
|
12
|
+
DATE_UTC_PRESETS: () => DATE_UTC_PRESETS,
|
|
13
|
+
DateUTCEngine: () => DateUTCEngine,
|
|
12
14
|
EmailEngine: () => EmailEngine,
|
|
13
15
|
InputAmountMask: () => InputAmountMask,
|
|
16
|
+
InputDateUTCMask: () => InputDateUTCMask,
|
|
14
17
|
InputEmailMask: () => InputEmailMask,
|
|
15
18
|
InputMask: () => InputMask,
|
|
16
19
|
Mask: () => Mask,
|
|
@@ -18,7 +21,8 @@ __export(mask_exports, {
|
|
|
18
21
|
MaskHistory: () => MaskHistory,
|
|
19
22
|
MaskKeyboard: () => MaskKeyboard,
|
|
20
23
|
default: () => mask_default,
|
|
21
|
-
|
|
24
|
+
sanitizePastedText: () => sanitizePastedText,
|
|
25
|
+
stripBidiAndInvisibles: () => stripBidiAndInvisibles
|
|
22
26
|
});
|
|
23
27
|
|
|
24
28
|
// src/common/dom.ts
|
|
@@ -149,27 +153,52 @@ var AuditableComponent = class {
|
|
|
149
153
|
return warnings;
|
|
150
154
|
}
|
|
151
155
|
/**
|
|
152
|
-
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
|
|
153
|
-
* pointe vers des éléments réellement présents dans le document.
|
|
156
|
+
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
|
|
157
|
+
* pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
|
|
154
158
|
*/
|
|
155
|
-
checkAriaIdReferences(element, attrName, warnings) {
|
|
159
|
+
checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
|
|
156
160
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
157
161
|
if (!rawValue) return false;
|
|
158
162
|
const doc = element.ownerDocument || document;
|
|
159
163
|
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
160
164
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
161
|
-
const
|
|
162
|
-
(id) =>
|
|
165
|
+
const targets = ids.map(
|
|
166
|
+
(id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
|
|
163
167
|
);
|
|
164
|
-
|
|
168
|
+
const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
|
|
169
|
+
if (!allFound) {
|
|
165
170
|
warnings.push(
|
|
166
171
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
167
172
|
);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (requireNonEmptyText) {
|
|
176
|
+
const hasNonEmptyText = targets.some((el) => {
|
|
177
|
+
if (!el) return false;
|
|
178
|
+
const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
|
|
179
|
+
return text.length > 0;
|
|
180
|
+
});
|
|
181
|
+
if (!hasNonEmptyText) {
|
|
182
|
+
warnings.push(
|
|
183
|
+
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
|
|
184
|
+
);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
168
187
|
}
|
|
169
|
-
return
|
|
188
|
+
return true;
|
|
170
189
|
}
|
|
171
190
|
};
|
|
172
191
|
|
|
192
|
+
// src/mask/paste.ts
|
|
193
|
+
var MAX_PASTE_LENGTH = 4096;
|
|
194
|
+
function stripBidiAndInvisibles(raw, maxLength = MAX_PASTE_LENGTH) {
|
|
195
|
+
const safeLimit = Math.max(0, maxLength);
|
|
196
|
+
return String(raw ?? "").slice(0, safeLimit).replace(/[\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
|
|
197
|
+
}
|
|
198
|
+
function sanitizePastedText(raw, maxLength = MAX_PASTE_LENGTH) {
|
|
199
|
+
return stripBidiAndInvisibles(raw, maxLength).replace(/[\u00A0\u202F\u2007]/g, " ").replace(/[\u2013\u2014\u2212]/g, "-").trim();
|
|
200
|
+
}
|
|
201
|
+
|
|
173
202
|
// src/mask/BaseInputMask.ts
|
|
174
203
|
var VALID_ALIGNS = /* @__PURE__ */ new Set(["left", "right", "center"]);
|
|
175
204
|
function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
@@ -207,6 +236,7 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
207
236
|
};
|
|
208
237
|
onFormResetHandler;
|
|
209
238
|
mutationObserver = null;
|
|
239
|
+
resizeObserver = null;
|
|
210
240
|
focusSelectTimerId = null;
|
|
211
241
|
abortController = new AbortController();
|
|
212
242
|
constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
@@ -222,7 +252,7 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
222
252
|
if (!effectiveWrapper && shouldCreateWrapper) {
|
|
223
253
|
const doc = this.input.ownerDocument || document;
|
|
224
254
|
const span = doc.createElement("span");
|
|
225
|
-
span.className = "wulf-mask-wrapper";
|
|
255
|
+
span.className = "wulf-mask-wrapper wulf-mask-wrapper--auto";
|
|
226
256
|
if (this.input.parentNode) {
|
|
227
257
|
this.input.parentNode.insertBefore(span, this.input);
|
|
228
258
|
}
|
|
@@ -252,21 +282,24 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
252
282
|
const dataDisabled = this.hasAttr("data-disabled");
|
|
253
283
|
const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
|
|
254
284
|
const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
|
|
285
|
+
const dataSensitive = this.getAttr("data-mask-sensitive") === "true";
|
|
255
286
|
const rawDataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
|
|
256
287
|
const dataAlign = rawDataAlign && VALID_ALIGNS.has(rawDataAlign) ? rawDataAlign : null;
|
|
257
288
|
this.hadInitialDataAlign = this.wrapper.hasAttribute("data-align");
|
|
258
289
|
const dataAudit = this.getAttr("data-mask-audit");
|
|
259
|
-
const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
|
|
290
|
+
const { disabled: optDisabled, align: optAlign, sensitive: optSensitive, ...otherOptions } = options;
|
|
260
291
|
const validOptAlign = optAlign && VALID_ALIGNS.has(optAlign) ? optAlign : void 0;
|
|
261
292
|
const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
|
|
262
293
|
const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
|
|
263
|
-
const
|
|
294
|
+
const resolvedSensitive = Boolean(optSensitive ?? dataSensitive);
|
|
295
|
+
const isSensitive = this.isPasswordInput() || resolvedSensitive;
|
|
264
296
|
this.options = {
|
|
265
297
|
...otherOptions,
|
|
266
298
|
createWrapper: shouldCreateWrapper,
|
|
267
299
|
showMaskOnFocus: options.showMaskOnFocus ?? dataFocusOnly ?? false,
|
|
268
300
|
selectAllOnFocus: options.selectAllOnFocus ?? dataSelectAll ?? false,
|
|
269
|
-
copyRaw:
|
|
301
|
+
copyRaw: isSensitive ? false : options.copyRaw ?? dataCopyRaw ?? false,
|
|
302
|
+
sensitive: resolvedSensitive,
|
|
270
303
|
disabled: resolvedDisabled,
|
|
271
304
|
align: validOptAlign ?? (dataAlign || void 0),
|
|
272
305
|
emitNativeInput: options.emitNativeInput ?? true,
|
|
@@ -321,7 +354,7 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
321
354
|
this.input.addEventListener("blur", this.onBaseBlur, { signal });
|
|
322
355
|
}
|
|
323
356
|
onBaseCopy = (e) => {
|
|
324
|
-
if (!this.options.copyRaw || this.options.disabled || this.
|
|
357
|
+
if (!this.options.copyRaw || this.options.disabled || this.isSensitiveField()) return;
|
|
325
358
|
const start = this.input.selectionStart ?? 0;
|
|
326
359
|
const end = this.input.selectionEnd ?? start;
|
|
327
360
|
let textToCopy = "";
|
|
@@ -341,6 +374,30 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
341
374
|
extractRawSnippet(snippet) {
|
|
342
375
|
return snippet;
|
|
343
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Extrait de manière compatible le texte brut du presse-papier lors d'un événement paste.
|
|
379
|
+
*/
|
|
380
|
+
getClipboardPlainText(e) {
|
|
381
|
+
if (!e.clipboardData) return "";
|
|
382
|
+
return e.clipboardData.getData("text") || e.clipboardData.getData("text/plain") || "";
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Applique l'hygiène Unicode O(N) puis le hook optionnel transformPaste de façon sécurisée et bornée.
|
|
386
|
+
*/
|
|
387
|
+
preparePastedText(rawClipboard, maxLength = MAX_PASTE_LENGTH) {
|
|
388
|
+
const sanitized = sanitizePastedText(rawClipboard, maxLength);
|
|
389
|
+
if (typeof this.options.transformPaste !== "function") {
|
|
390
|
+
return sanitized;
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
const transformed = this.options.transformPaste(sanitized);
|
|
394
|
+
if (typeof transformed === "string") {
|
|
395
|
+
return sanitizePastedText(transformed, maxLength);
|
|
396
|
+
}
|
|
397
|
+
} catch {
|
|
398
|
+
}
|
|
399
|
+
return sanitized;
|
|
400
|
+
}
|
|
344
401
|
onBaseFocus = () => {
|
|
345
402
|
this.isFocused = true;
|
|
346
403
|
if (this.options.selectAllOnFocus && this.input.value.length > 0) {
|
|
@@ -349,7 +406,7 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
349
406
|
}
|
|
350
407
|
this.focusSelectTimerId = window.setTimeout(() => {
|
|
351
408
|
this.focusSelectTimerId = null;
|
|
352
|
-
if (!this.isDestroyed &&
|
|
409
|
+
if (!this.isDestroyed && getDeepActiveElement(this.input.ownerDocument) === this.input) {
|
|
353
410
|
this.input.select();
|
|
354
411
|
}
|
|
355
412
|
}, 0);
|
|
@@ -357,7 +414,7 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
357
414
|
};
|
|
358
415
|
onBaseBlur = () => {
|
|
359
416
|
this.isFocused = false;
|
|
360
|
-
if (this.
|
|
417
|
+
if (this.isSensitiveField()) {
|
|
361
418
|
this.lastTrackedValue = "";
|
|
362
419
|
this.clearGhost();
|
|
363
420
|
this.wrapper.removeAttribute("data-mask");
|
|
@@ -384,11 +441,14 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
384
441
|
"data-mask-strict",
|
|
385
442
|
"data-mask-select-on-focus",
|
|
386
443
|
"data-mask-copy-raw",
|
|
444
|
+
"data-mask-sensitive",
|
|
387
445
|
"data-mask-pad-decimals",
|
|
388
446
|
"data-mask-auto-lowercase",
|
|
389
447
|
"data-mask-cycle-suggestions",
|
|
390
448
|
"data-mask-default-tld",
|
|
391
449
|
"data-mask-tlds",
|
|
450
|
+
"data-mask-format",
|
|
451
|
+
"data-mask-utc-indicator",
|
|
392
452
|
"data-disabled",
|
|
393
453
|
"data-mask-align",
|
|
394
454
|
"data-align",
|
|
@@ -407,6 +467,12 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
407
467
|
isPasswordInput() {
|
|
408
468
|
return (this.input.type || "").toLowerCase() === "password";
|
|
409
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* Indique si le champ relève du sanctuaire confidentiel (type="password" ou option sensitive: true).
|
|
472
|
+
*/
|
|
473
|
+
isSensitiveField() {
|
|
474
|
+
return this.isPasswordInput() || Boolean(this.options.sensitive);
|
|
475
|
+
}
|
|
410
476
|
/**
|
|
411
477
|
* Calcule une empreinte non réversible pour détecter les changements sans conserver de secret en RAM.
|
|
412
478
|
*/
|
|
@@ -461,9 +527,19 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
461
527
|
} else if (attrName === "data-mask-select-on-focus") {
|
|
462
528
|
this.options.selectAllOnFocus = this.getAttr("data-mask-select-on-focus") === "true";
|
|
463
529
|
} else if (attrName === "data-mask-copy-raw") {
|
|
464
|
-
this.options.copyRaw = this.
|
|
530
|
+
this.options.copyRaw = this.isSensitiveField() ? false : this.getAttr("data-mask-copy-raw") === "true";
|
|
531
|
+
} else if (attrName === "data-mask-sensitive") {
|
|
532
|
+
const nextSensitive = this.getAttr("data-mask-sensitive") === "true";
|
|
533
|
+
this.options.sensitive = nextSensitive;
|
|
534
|
+
if (this.isSensitiveField()) {
|
|
535
|
+
this.options.copyRaw = false;
|
|
536
|
+
this.lastTrackedValue = "";
|
|
537
|
+
this.clearGhost();
|
|
538
|
+
this.wrapper.removeAttribute("data-mask");
|
|
539
|
+
this.onPasswordModeDetected();
|
|
540
|
+
}
|
|
465
541
|
} else if (attrName === "type") {
|
|
466
|
-
if (this.
|
|
542
|
+
if (this.isSensitiveField()) {
|
|
467
543
|
this.options.copyRaw = false;
|
|
468
544
|
this.lastTrackedValue = "";
|
|
469
545
|
this.clearGhost();
|
|
@@ -514,6 +590,24 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
514
590
|
this.ghost.style.pointerEvents = "none";
|
|
515
591
|
}
|
|
516
592
|
this.syncGhostStyles();
|
|
593
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
594
|
+
this.resizeObserver?.disconnect();
|
|
595
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
596
|
+
if (!this.isDestroyed) {
|
|
597
|
+
this.syncGhostStyles();
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
this.resizeObserver.observe(this.input);
|
|
601
|
+
}
|
|
602
|
+
const docWithFonts = doc;
|
|
603
|
+
if (docWithFonts.fonts?.ready && typeof docWithFonts.fonts.ready.then === "function") {
|
|
604
|
+
docWithFonts.fonts.ready.then(() => {
|
|
605
|
+
if (!this.isDestroyed) {
|
|
606
|
+
this.syncGhostStyles();
|
|
607
|
+
}
|
|
608
|
+
}).catch(() => {
|
|
609
|
+
});
|
|
610
|
+
}
|
|
517
611
|
}
|
|
518
612
|
/**
|
|
519
613
|
* Met à jour atomiquement le contenu du conteneur fantôme et synchronise .has-visible-ghost.
|
|
@@ -550,6 +644,10 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
550
644
|
this.ghost.style.fontWeight = style.fontWeight;
|
|
551
645
|
this.ghost.style.fontStyle = style.fontStyle;
|
|
552
646
|
this.ghost.style.letterSpacing = style.letterSpacing;
|
|
647
|
+
this.ghost.style.wordSpacing = style.wordSpacing;
|
|
648
|
+
this.ghost.style.textIndent = style.textIndent;
|
|
649
|
+
this.ghost.style.fontKerning = style.fontKerning;
|
|
650
|
+
this.ghost.style.fontVariantNumeric = style.fontVariantNumeric;
|
|
553
651
|
this.ghost.style.lineHeight = style.lineHeight;
|
|
554
652
|
this.ghost.style.paddingTop = style.paddingTop;
|
|
555
653
|
this.ghost.style.paddingBottom = style.paddingBottom;
|
|
@@ -601,11 +699,12 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
601
699
|
if (this.options.emitNativeInput === false) return;
|
|
602
700
|
this.isDispatchingNativeInput = true;
|
|
603
701
|
try {
|
|
702
|
+
const isSensitive = this.isSensitiveField();
|
|
604
703
|
const tracker = this.input._valueTracker;
|
|
605
|
-
if (!
|
|
704
|
+
if (!isSensitive && tracker && typeof tracker.setValue === "function") {
|
|
606
705
|
tracker.setValue(this.lastTrackedValue);
|
|
607
706
|
}
|
|
608
|
-
this.lastTrackedValue =
|
|
707
|
+
this.lastTrackedValue = isSensitive ? "" : this.input.value;
|
|
609
708
|
this.input.dispatchEvent(new Event("input", { bubbles: true, cancelable: false }));
|
|
610
709
|
} finally {
|
|
611
710
|
this.isDispatchingNativeInput = false;
|
|
@@ -723,6 +822,37 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
723
822
|
getRawValue() {
|
|
724
823
|
return this.input.value;
|
|
725
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* Vérifie qu'un élément <label> possède un nom accessible non vide,
|
|
827
|
+
* en ignorant le texte éventuel des contrôles enfants (<input>, <select>, <textarea>, <button>).
|
|
828
|
+
*/
|
|
829
|
+
hasAccessibleLabelText(labelEl) {
|
|
830
|
+
if (!labelEl) return false;
|
|
831
|
+
const ariaLabel = labelEl.getAttribute("aria-label")?.trim();
|
|
832
|
+
if (ariaLabel) return true;
|
|
833
|
+
const collectText = (node) => {
|
|
834
|
+
if (node.nodeType === 3) {
|
|
835
|
+
return node.textContent || "";
|
|
836
|
+
}
|
|
837
|
+
if (node.nodeType === 1) {
|
|
838
|
+
const el = node;
|
|
839
|
+
const tag = el.tagName;
|
|
840
|
+
if (tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA" || tag === "BUTTON") {
|
|
841
|
+
return "";
|
|
842
|
+
}
|
|
843
|
+
if (el.getAttribute("aria-hidden") === "true") {
|
|
844
|
+
return "";
|
|
845
|
+
}
|
|
846
|
+
let acc = "";
|
|
847
|
+
for (let i = 0; i < el.childNodes.length; i++) {
|
|
848
|
+
acc += collectText(el.childNodes[i]);
|
|
849
|
+
}
|
|
850
|
+
return acc;
|
|
851
|
+
}
|
|
852
|
+
return "";
|
|
853
|
+
};
|
|
854
|
+
return collectText(labelEl).trim().length > 0;
|
|
855
|
+
}
|
|
726
856
|
/**
|
|
727
857
|
* Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
|
|
728
858
|
* et retourne la liste des contraintes manquantes.
|
|
@@ -733,23 +863,39 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
733
863
|
const root = typeof this.input.getRootNode === "function" ? this.input.getRootNode() : doc;
|
|
734
864
|
const labelRoot = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : doc;
|
|
735
865
|
const ariaLabel = this.input.getAttribute("aria-label")?.trim();
|
|
736
|
-
const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
|
|
737
|
-
const
|
|
738
|
-
const
|
|
866
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings, true);
|
|
867
|
+
const wrappingLabel = this.input.closest("label");
|
|
868
|
+
const hasWrappingLabel = this.hasAccessibleLabelText(wrappingLabel);
|
|
869
|
+
const hasNativeLabels = Boolean(
|
|
870
|
+
this.input.labels && Array.from(this.input.labels).some((lbl) => this.hasAccessibleLabelText(lbl))
|
|
871
|
+
);
|
|
739
872
|
let hasExplicitLabelFor = false;
|
|
740
873
|
if (this.input.id) {
|
|
741
874
|
try {
|
|
742
|
-
|
|
875
|
+
const explicitLabel = labelRoot.querySelector(`label[for="${safeCssEscape(this.input.id)}"]`);
|
|
876
|
+
hasExplicitLabelFor = this.hasAccessibleLabelText(explicitLabel);
|
|
743
877
|
} catch {
|
|
744
878
|
hasExplicitLabelFor = false;
|
|
745
879
|
}
|
|
746
880
|
}
|
|
747
881
|
if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
|
|
748
882
|
warnings.push(
|
|
749
|
-
`\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
|
|
883
|
+
`\xC9tiquetage accessible manquant : associez un <label for="id"> non vide (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
|
|
750
884
|
);
|
|
751
885
|
}
|
|
752
|
-
this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
|
|
886
|
+
this.checkAriaIdReferences(this.input, "aria-describedby", warnings, true);
|
|
887
|
+
if (this.input.hasAttribute("aria-errormessage")) {
|
|
888
|
+
this.checkAriaIdReferences(this.input, "aria-errormessage", warnings, true);
|
|
889
|
+
}
|
|
890
|
+
const rawTabIndex = this.input.getAttribute("tabindex");
|
|
891
|
+
if (rawTabIndex !== null) {
|
|
892
|
+
const parsedTabIndex = Number.parseInt(rawTabIndex, 10);
|
|
893
|
+
if (Number.isFinite(parsedTabIndex) && parsedTabIndex > 0) {
|
|
894
|
+
warnings.push(
|
|
895
|
+
`Attribut tabindex="${rawTabIndex}" positif d\xE9tect\xE9 : \xE9vitez les tabindex > 0 qui perturbent l'ordre de tabulation naturel (WCAG 2.4.3).`
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
753
899
|
const extraWarnings = this.getSpecificAuditWarnings();
|
|
754
900
|
warnings.push(...extraWarnings);
|
|
755
901
|
return warnings;
|
|
@@ -788,6 +934,10 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
788
934
|
this.mutationObserver.disconnect();
|
|
789
935
|
this.mutationObserver = null;
|
|
790
936
|
}
|
|
937
|
+
if (this.resizeObserver) {
|
|
938
|
+
this.resizeObserver.disconnect();
|
|
939
|
+
this.resizeObserver = null;
|
|
940
|
+
}
|
|
791
941
|
this.abortController.abort();
|
|
792
942
|
this.lastTrackedValue = "";
|
|
793
943
|
this.unhookValueProperty();
|
|
@@ -828,6 +978,7 @@ var BaseInputMask = class extends AuditableComponent {
|
|
|
828
978
|
};
|
|
829
979
|
|
|
830
980
|
// src/mask/MaskEngine.ts
|
|
981
|
+
var SEGMENT_SEPARATORS = /* @__PURE__ */ new Set(["/", "-", ".", ":"]);
|
|
831
982
|
var DEFAULT_TOKENS = {
|
|
832
983
|
"9": { pattern: /[0-9]/ },
|
|
833
984
|
"a": { pattern: /[a-zA-Z]/ },
|
|
@@ -838,6 +989,8 @@ var DEFAULT_TOKENS = {
|
|
|
838
989
|
var MaskEngine = class _MaskEngine {
|
|
839
990
|
pattern;
|
|
840
991
|
patterns = [];
|
|
992
|
+
patternResolver = null;
|
|
993
|
+
lastResolvedKey = "";
|
|
841
994
|
subEngines = [];
|
|
842
995
|
activeEngine = null;
|
|
843
996
|
placeholderChar;
|
|
@@ -874,7 +1027,7 @@ var MaskEngine = class _MaskEngine {
|
|
|
874
1027
|
* Fonction statique utilitaire permettant un formatage direct sans instanciation manuelle.
|
|
875
1028
|
*
|
|
876
1029
|
* @param value Valeur à formater (brute ou partiellement formatée)
|
|
877
|
-
* @param pattern Masque à appliquer (ex: "99 99 99 99 99"
|
|
1030
|
+
* @param pattern Masque à appliquer (ex: "99 99 99 99 99", tableau de masques ou résolveur dynamique)
|
|
878
1031
|
* @param options Options facultatives (placeholderChar, tokens, strict, autoLowercase)
|
|
879
1032
|
* @returns La valeur formatée selon le masque
|
|
880
1033
|
*/
|
|
@@ -884,17 +1037,69 @@ var MaskEngine = class _MaskEngine {
|
|
|
884
1037
|
return engine.format(value ?? "");
|
|
885
1038
|
}
|
|
886
1039
|
/**
|
|
887
|
-
*
|
|
1040
|
+
* Indique si le gabarit repose sur une fonction résolveuse dynamique.
|
|
1041
|
+
*/
|
|
1042
|
+
isDynamicPattern() {
|
|
1043
|
+
return this.patternResolver !== null;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Résout et compile si besoin le gabarit dynamique pour la valeur fournie (avec mémoïsation).
|
|
1047
|
+
*/
|
|
1048
|
+
resolveForValue(input) {
|
|
1049
|
+
if (!this.patternResolver) return false;
|
|
1050
|
+
let resolved;
|
|
1051
|
+
try {
|
|
1052
|
+
resolved = this.patternResolver(String(input ?? "").slice(0, 4096));
|
|
1053
|
+
} catch {
|
|
1054
|
+
return false;
|
|
1055
|
+
}
|
|
1056
|
+
let normalized;
|
|
1057
|
+
let key;
|
|
1058
|
+
if (Array.isArray(resolved)) {
|
|
1059
|
+
normalized = resolved.slice(0, 32).map((p) => String(p ?? "").slice(0, 512));
|
|
1060
|
+
key = "A:" + normalized.join("\0");
|
|
1061
|
+
} else if (typeof resolved === "string") {
|
|
1062
|
+
normalized = resolved.slice(0, 512);
|
|
1063
|
+
key = "S:" + normalized;
|
|
1064
|
+
} else {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
if (key === this.lastResolvedKey) {
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
this.lastResolvedKey = key;
|
|
1071
|
+
this.compileStatic(normalized);
|
|
1072
|
+
return true;
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Analyse le ou les gabarits (statiques ou résolus dynamiquement) et compile la liste des slots.
|
|
888
1076
|
*/
|
|
889
1077
|
compile(newPattern) {
|
|
1078
|
+
if (typeof newPattern === "function") {
|
|
1079
|
+
this.patternResolver = newPattern;
|
|
1080
|
+
this.lastResolvedKey = "";
|
|
1081
|
+
this.resolveForValue("");
|
|
1082
|
+
return this.slots;
|
|
1083
|
+
}
|
|
890
1084
|
if (newPattern !== void 0) {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1085
|
+
this.patternResolver = null;
|
|
1086
|
+
this.lastResolvedKey = "";
|
|
1087
|
+
return this.compileStatic(newPattern);
|
|
1088
|
+
}
|
|
1089
|
+
if (this.patternResolver) {
|
|
1090
|
+
this.lastResolvedKey = "";
|
|
1091
|
+
this.resolveForValue("");
|
|
1092
|
+
return this.slots;
|
|
1093
|
+
}
|
|
1094
|
+
return this.compileStatic(this.patterns.length > 0 ? this.patterns : this.pattern);
|
|
1095
|
+
}
|
|
1096
|
+
compileStatic(newPattern) {
|
|
1097
|
+
if (Array.isArray(newPattern)) {
|
|
1098
|
+
this.patterns = newPattern.slice(0, 32).map((p) => String(p ?? "").slice(0, 512));
|
|
1099
|
+
this.pattern = this.patterns[0] || "";
|
|
1100
|
+
} else {
|
|
1101
|
+
this.patterns = [];
|
|
1102
|
+
this.pattern = String(newPattern ?? "").slice(0, 512);
|
|
898
1103
|
}
|
|
899
1104
|
if (this.patterns.length > 0) {
|
|
900
1105
|
this.subEngines = this.patterns.map((p) => new _MaskEngine(p, {
|
|
@@ -926,14 +1131,15 @@ var MaskEngine = class _MaskEngine {
|
|
|
926
1131
|
const token = !isEscaped && Object.hasOwn(this.tokens, char) ? this.tokens[char] : void 0;
|
|
927
1132
|
if (token) {
|
|
928
1133
|
isPrefixMode = false;
|
|
1134
|
+
const slotPlaceholder = token.placeholder ? Array.from(String(token.placeholder))[0] || this.placeholderChar : this.placeholderChar;
|
|
929
1135
|
this.slots.push({
|
|
930
1136
|
char,
|
|
931
1137
|
isStatic: false,
|
|
932
1138
|
isPrefix: false,
|
|
933
1139
|
token,
|
|
934
|
-
placeholder:
|
|
1140
|
+
placeholder: slotPlaceholder
|
|
935
1141
|
});
|
|
936
|
-
templateBuilder +=
|
|
1142
|
+
templateBuilder += slotPlaceholder;
|
|
937
1143
|
} else {
|
|
938
1144
|
this.slots.push({
|
|
939
1145
|
char,
|
|
@@ -1001,13 +1207,29 @@ var MaskEngine = class _MaskEngine {
|
|
|
1001
1207
|
return this.activeEngine ? this.activeEngine.getFullMaskTemplate() : this.fullMaskTemplate;
|
|
1002
1208
|
}
|
|
1003
1209
|
/**
|
|
1004
|
-
* Nombre total de positions éditables
|
|
1210
|
+
* Nombre total de positions éditables du sous-moteur actif (pour isComplete et detail.totalSlots).
|
|
1005
1211
|
*/
|
|
1006
|
-
|
|
1212
|
+
getActiveEditableCount() {
|
|
1213
|
+
if (this.subEngines.length > 0) {
|
|
1214
|
+
const target = this.activeEngine ?? this.subEngines[0];
|
|
1215
|
+
return target.getActiveEditableCount();
|
|
1216
|
+
}
|
|
1217
|
+
return this.activeEngine ? this.activeEngine.getActiveEditableCount() : this.slots.filter((s) => !s.isStatic).length;
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Capacité maximale de positions éditables parmi les gabarits configurés (pour le blocage de frappe / collage).
|
|
1221
|
+
*/
|
|
1222
|
+
getMaxEditableCount() {
|
|
1007
1223
|
if (this.subEngines.length > 0) {
|
|
1008
|
-
return Math.max(...this.subEngines.map((e) => e.
|
|
1224
|
+
return Math.max(...this.subEngines.map((e) => e.getMaxEditableCount()));
|
|
1009
1225
|
}
|
|
1010
|
-
return this.
|
|
1226
|
+
return this.getActiveEditableCount();
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Capacité maximale totale de positions éditables dans le masque (alias rétrocompatible de getMaxEditableCount).
|
|
1230
|
+
*/
|
|
1231
|
+
getEditableCount() {
|
|
1232
|
+
return this.getMaxEditableCount();
|
|
1011
1233
|
}
|
|
1012
1234
|
/**
|
|
1013
1235
|
* Indique si tous les emplacements éditables du masque acceptent exclusivement des chiffres numériques.
|
|
@@ -1045,15 +1267,199 @@ var MaskEngine = class _MaskEngine {
|
|
|
1045
1267
|
isStrict() {
|
|
1046
1268
|
return this.strict;
|
|
1047
1269
|
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Normalise une chaîne issue du presse-papier en alignant et complétant à gauche par '0'
|
|
1272
|
+
* les segments numériques courts lorsque la structure correspond sans ambiguïté au gabarit.
|
|
1273
|
+
* N'altère jamais extractRaw() ni la saisie clavier.
|
|
1274
|
+
*/
|
|
1275
|
+
normalizePastedValue(pasted) {
|
|
1276
|
+
const rawPasted = String(pasted ?? "");
|
|
1277
|
+
if (!rawPasted) return rawPasted;
|
|
1278
|
+
this.resolveForValue(rawPasted);
|
|
1279
|
+
if (this.subEngines.length > 0) {
|
|
1280
|
+
const lowerPasted = rawPasted.toLowerCase();
|
|
1281
|
+
const withMatchingPrefix = this.subEngines.filter((e) => {
|
|
1282
|
+
const p = e.getPrefix();
|
|
1283
|
+
return p.length > 0 && lowerPasted.startsWith(p.trim().toLowerCase());
|
|
1284
|
+
});
|
|
1285
|
+
const candidates = withMatchingPrefix.length > 0 ? withMatchingPrefix : this.subEngines;
|
|
1286
|
+
let firstMatch = null;
|
|
1287
|
+
for (const eng of candidates) {
|
|
1288
|
+
const res = eng.tryNormalizeSegments(rawPasted);
|
|
1289
|
+
if (res.matched) {
|
|
1290
|
+
if (res.exactSegmentCount) {
|
|
1291
|
+
return res.normalized;
|
|
1292
|
+
}
|
|
1293
|
+
if (firstMatch === null) {
|
|
1294
|
+
firstMatch = res.normalized;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return firstMatch !== null ? firstMatch : rawPasted;
|
|
1299
|
+
}
|
|
1300
|
+
return this.tryNormalizeSegments(rawPasted).normalized;
|
|
1301
|
+
}
|
|
1302
|
+
tryNormalizeSegments(pasted) {
|
|
1303
|
+
const fail = { matched: false, normalized: pasted, exactSegmentCount: false };
|
|
1304
|
+
if (!this.strict || this.slots.length === 0 || !pasted) {
|
|
1305
|
+
return fail;
|
|
1306
|
+
}
|
|
1307
|
+
let rest = pasted;
|
|
1308
|
+
if (this.prefixSlotsCount > 0) {
|
|
1309
|
+
let inputIdx = 0;
|
|
1310
|
+
while (inputIdx < pasted.length && (pasted[inputIdx] === " " || pasted[inputIdx] === " ")) {
|
|
1311
|
+
inputIdx++;
|
|
1312
|
+
}
|
|
1313
|
+
let pIdx = 0;
|
|
1314
|
+
while (inputIdx < pasted.length && pIdx < this.prefixSlotsCount) {
|
|
1315
|
+
const pChar = this.slots[pIdx].char;
|
|
1316
|
+
const inChar = pasted[inputIdx];
|
|
1317
|
+
if (inChar.toUpperCase() === pChar.toUpperCase()) {
|
|
1318
|
+
inputIdx++;
|
|
1319
|
+
pIdx++;
|
|
1320
|
+
} else if (pChar === " " && inChar !== " ") {
|
|
1321
|
+
pIdx++;
|
|
1322
|
+
} else {
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
if (pIdx === this.prefixSlotsCount) {
|
|
1327
|
+
rest = pasted.slice(inputIdx);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
if (!rest) {
|
|
1331
|
+
return fail;
|
|
1332
|
+
}
|
|
1333
|
+
const segments = [];
|
|
1334
|
+
const separators = [];
|
|
1335
|
+
let currentSeg = [];
|
|
1336
|
+
let currentSep = "";
|
|
1337
|
+
let hasTrailingStatic = false;
|
|
1338
|
+
for (let i = this.prefixSlotsCount; i < this.slots.length; i++) {
|
|
1339
|
+
const slot = this.slots[i];
|
|
1340
|
+
if (slot.isStatic) {
|
|
1341
|
+
if (currentSeg.length > 0) {
|
|
1342
|
+
segments.push(currentSeg);
|
|
1343
|
+
currentSeg = [];
|
|
1344
|
+
currentSep = slot.char;
|
|
1345
|
+
} else {
|
|
1346
|
+
currentSep += slot.char;
|
|
1347
|
+
}
|
|
1348
|
+
} else {
|
|
1349
|
+
if (currentSep.length > 0) {
|
|
1350
|
+
separators.push(currentSep);
|
|
1351
|
+
currentSep = "";
|
|
1352
|
+
}
|
|
1353
|
+
currentSeg.push(slot);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
if (currentSeg.length > 0) {
|
|
1357
|
+
segments.push(currentSeg);
|
|
1358
|
+
} else if (currentSep.length > 0) {
|
|
1359
|
+
hasTrailingStatic = true;
|
|
1360
|
+
}
|
|
1361
|
+
if (hasTrailingStatic || segments.length < 2 || separators.length !== segments.length - 1) {
|
|
1362
|
+
return fail;
|
|
1363
|
+
}
|
|
1364
|
+
const coreSeps = [];
|
|
1365
|
+
for (const sep of separators) {
|
|
1366
|
+
const core = sep.trim();
|
|
1367
|
+
if (core.length !== 1 || !SEGMENT_SEPARATORS.has(core)) {
|
|
1368
|
+
return fail;
|
|
1369
|
+
}
|
|
1370
|
+
coreSeps.push(core);
|
|
1371
|
+
}
|
|
1372
|
+
const parts = [];
|
|
1373
|
+
const foundSeps = [];
|
|
1374
|
+
let blockStart = 0;
|
|
1375
|
+
for (let i = 0; i < rest.length; i++) {
|
|
1376
|
+
const ch = rest[i];
|
|
1377
|
+
if (SEGMENT_SEPARATORS.has(ch)) {
|
|
1378
|
+
parts.push(rest.slice(blockStart, i).trim());
|
|
1379
|
+
foundSeps.push(ch);
|
|
1380
|
+
blockStart = i + 1;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
parts.push(rest.slice(blockStart).trim());
|
|
1384
|
+
if (foundSeps.length === 0 || foundSeps.length > coreSeps.length) {
|
|
1385
|
+
return fail;
|
|
1386
|
+
}
|
|
1387
|
+
if (parts.length !== foundSeps.length + 1 || parts.length > segments.length || parts.some((p) => p.length === 0)) {
|
|
1388
|
+
return fail;
|
|
1389
|
+
}
|
|
1390
|
+
const matchesMaskOrder = foundSeps.every((sep, idx) => sep === coreSeps[idx]);
|
|
1391
|
+
const isHomogeneous = foundSeps.every((sep) => sep === foundSeps[0]);
|
|
1392
|
+
if (!matchesMaskOrder && !isHomogeneous) {
|
|
1393
|
+
return fail;
|
|
1394
|
+
}
|
|
1395
|
+
const exactSegmentCount = parts.length === segments.length;
|
|
1396
|
+
const paddedParts = [];
|
|
1397
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1398
|
+
const part = parts[i];
|
|
1399
|
+
const segSlots = segments[i];
|
|
1400
|
+
if (part.length > segSlots.length) {
|
|
1401
|
+
return fail;
|
|
1402
|
+
}
|
|
1403
|
+
const isNumericSeg = segSlots.every(
|
|
1404
|
+
(s) => Boolean(s.token && s.token.pattern.test("0") && !s.token.pattern.test("a") && !s.token.pattern.test("Z"))
|
|
1405
|
+
);
|
|
1406
|
+
if (isNumericSeg) {
|
|
1407
|
+
const isClosedBySep = i < parts.length - 1;
|
|
1408
|
+
const isTerminalTwoDigitEligible = i === parts.length - 1 && exactSegmentCount && segments.length <= 3 && segSlots.length === 2;
|
|
1409
|
+
const shouldPad = part.length < segSlots.length && (isClosedBySep || isTerminalTwoDigitEligible);
|
|
1410
|
+
const offset = shouldPad ? segSlots.length - part.length : 0;
|
|
1411
|
+
for (let k = 0; k < part.length; k++) {
|
|
1412
|
+
const ch = part[k];
|
|
1413
|
+
if (ch < "0" || ch > "9" || !segSlots[offset + k].token.pattern.test(ch)) {
|
|
1414
|
+
return fail;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
paddedParts.push(shouldPad ? "0".repeat(segSlots.length - part.length) + part : part);
|
|
1418
|
+
} else {
|
|
1419
|
+
if (part.length !== segSlots.length) {
|
|
1420
|
+
return fail;
|
|
1421
|
+
}
|
|
1422
|
+
for (let k = 0; k < part.length; k++) {
|
|
1423
|
+
if (!segSlots[k].token || !segSlots[k].token.pattern.test(part[k])) {
|
|
1424
|
+
return fail;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
paddedParts.push(part);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
let normalized = this.prefixSlotsCount > 0 ? this.prefixString : "";
|
|
1431
|
+
for (let i = 0; i < paddedParts.length; i++) {
|
|
1432
|
+
if (i > 0) {
|
|
1433
|
+
normalized += separators[i - 1];
|
|
1434
|
+
}
|
|
1435
|
+
normalized += paddedParts[i];
|
|
1436
|
+
}
|
|
1437
|
+
return {
|
|
1438
|
+
matched: true,
|
|
1439
|
+
normalized,
|
|
1440
|
+
exactSegmentCount
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Filtre et extrait les caractères éditables sans déclencher de ré-évaluation dynamique du gabarit.
|
|
1445
|
+
* Utile pour mesurer une sélection partielle ou mapper le curseur sans effet de bord.
|
|
1446
|
+
*/
|
|
1447
|
+
extractRawForCurrentPattern(input) {
|
|
1448
|
+
return this.extractRawInternal(input);
|
|
1449
|
+
}
|
|
1048
1450
|
/**
|
|
1049
1451
|
* Filtre et extrait uniquement les caractères éditables valides d'une chaîne.
|
|
1050
1452
|
* Gère intelligemment la présence ou l'absence des séparateurs statiques et du préfixe.
|
|
1051
1453
|
*/
|
|
1052
1454
|
extractRaw(input) {
|
|
1455
|
+
this.resolveForValue(input);
|
|
1456
|
+
return this.extractRawInternal(input);
|
|
1457
|
+
}
|
|
1458
|
+
extractRawInternal(input) {
|
|
1053
1459
|
if (this.subEngines.length > 0) {
|
|
1054
1460
|
const engine = this.selectEngine(input);
|
|
1055
1461
|
if (engine !== this) {
|
|
1056
|
-
return engine.
|
|
1462
|
+
return engine.extractRawInternal(input);
|
|
1057
1463
|
}
|
|
1058
1464
|
}
|
|
1059
1465
|
const maxInputLen = Math.max(4096, this.slots.length * 4);
|
|
@@ -1120,6 +1526,7 @@ var MaskEngine = class _MaskEngine {
|
|
|
1120
1526
|
* Si aucune donnée éditable n'est présente, retourne le préfixe statique fixe s'il existe.
|
|
1121
1527
|
*/
|
|
1122
1528
|
format(rawValue) {
|
|
1529
|
+
this.resolveForValue(rawValue);
|
|
1123
1530
|
if (this.subEngines.length > 0) {
|
|
1124
1531
|
const engine = this.selectEngine(rawValue);
|
|
1125
1532
|
if (engine !== this) {
|
|
@@ -1129,7 +1536,7 @@ var MaskEngine = class _MaskEngine {
|
|
|
1129
1536
|
const maxInputLen = Math.max(4096, this.slots.length * 4);
|
|
1130
1537
|
const rawStr = String(rawValue ?? "").slice(0, maxInputLen);
|
|
1131
1538
|
if (!this.slots.length) return rawStr;
|
|
1132
|
-
const cleanRaw = this.
|
|
1539
|
+
const cleanRaw = this.extractRawInternal(rawStr);
|
|
1133
1540
|
if (cleanRaw.length === 0) {
|
|
1134
1541
|
return this.prefixString;
|
|
1135
1542
|
}
|
|
@@ -1191,7 +1598,7 @@ var MaskEngine = class _MaskEngine {
|
|
|
1191
1598
|
const safeInput = String(inputValue ?? "");
|
|
1192
1599
|
const safeFormatted = String(formatted ?? "");
|
|
1193
1600
|
if (inputCursor <= 0 || !safeFormatted) return minPos;
|
|
1194
|
-
const rawBeforeCursor = this.
|
|
1601
|
+
const rawBeforeCursor = this.extractRawInternal(safeInput.slice(0, inputCursor));
|
|
1195
1602
|
const targetRawCount = rawBeforeCursor.length;
|
|
1196
1603
|
if (targetRawCount === 0) {
|
|
1197
1604
|
return Math.max(minPos, Math.min(this.getNextEditablePosition(0), safeFormatted.length));
|
|
@@ -1374,10 +1781,25 @@ var MaskKeyboard = class {
|
|
|
1374
1781
|
if (isPrintableChar && !hasSelection) {
|
|
1375
1782
|
const slots = engine.getSlots();
|
|
1376
1783
|
const isAlreadyOnSep = cursor < slots.length && slots[cursor].isStatic && slots[cursor].char === e.key;
|
|
1377
|
-
|
|
1784
|
+
let justAfterSepIdx = -1;
|
|
1785
|
+
if (cursor > 0 && cursor - 1 < slots.length) {
|
|
1786
|
+
if (slots[cursor - 1].isStatic && slots[cursor - 1].char === e.key) {
|
|
1787
|
+
justAfterSepIdx = cursor - 1;
|
|
1788
|
+
} else {
|
|
1789
|
+
let k = cursor - 1;
|
|
1790
|
+
while (k >= minPos && slots[k].isStatic) {
|
|
1791
|
+
if (slots[k].char === e.key) {
|
|
1792
|
+
justAfterSepIdx = k;
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
k--;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
const isJustAfterSep = justAfterSepIdx !== -1;
|
|
1378
1800
|
if (isAlreadyOnSep || isJustAfterSep) {
|
|
1379
1801
|
e.preventDefault();
|
|
1380
|
-
const baseIdx = isAlreadyOnSep ? cursor :
|
|
1802
|
+
const baseIdx = isAlreadyOnSep ? cursor : justAfterSepIdx;
|
|
1381
1803
|
const nextEditable = engine.getNextEditablePosition(baseIdx + 1);
|
|
1382
1804
|
this.delegate.applyMask(input.value, nextEditable, true);
|
|
1383
1805
|
return;
|
|
@@ -1400,7 +1822,7 @@ var MaskKeyboard = class {
|
|
|
1400
1822
|
segStart++;
|
|
1401
1823
|
const segLength = nextSepIdx - segStart;
|
|
1402
1824
|
const currentSegVal = input.value.slice(segStart, cursor);
|
|
1403
|
-
const isNumericSegment = slots.slice(segStart, nextSepIdx).every((s) =>
|
|
1825
|
+
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")));
|
|
1404
1826
|
if (isNumericSegment && segLength > currentSegVal.length && currentSegVal.length > 0) {
|
|
1405
1827
|
const missingCount = segLength - currentSegVal.length;
|
|
1406
1828
|
const paddedSeg = "0".repeat(missingCount) + currentSegVal;
|
|
@@ -1416,19 +1838,27 @@ var MaskKeyboard = class {
|
|
|
1416
1838
|
}
|
|
1417
1839
|
}
|
|
1418
1840
|
if (isPrintableChar && engine.isStrict()) {
|
|
1419
|
-
const
|
|
1841
|
+
const isDynamic = engine.isDynamicPattern();
|
|
1842
|
+
const currentRaw = engine.extractRaw(input.value);
|
|
1843
|
+
const selectedRaw = selectionEnd > cursor ? engine.extractRawForCurrentPattern(input.value.slice(cursor, selectionEnd)) : "";
|
|
1844
|
+
if (isDynamic) {
|
|
1845
|
+
const candidate = input.value.slice(0, cursor) + e.key + input.value.slice(selectionEnd);
|
|
1846
|
+
engine.resolveForValue(candidate);
|
|
1847
|
+
}
|
|
1848
|
+
const totalSlots = engine.getMaxEditableCount();
|
|
1420
1849
|
if (totalSlots > 0) {
|
|
1421
|
-
const
|
|
1422
|
-
let availableCapacity = totalSlots - currentRaw.length;
|
|
1423
|
-
if (selectionEnd > cursor) {
|
|
1424
|
-
const selectedRaw = engine.extractRaw(input.value.slice(cursor, selectionEnd));
|
|
1425
|
-
availableCapacity = totalSlots - (currentRaw.length - selectedRaw.length);
|
|
1426
|
-
}
|
|
1850
|
+
const availableCapacity = totalSlots - (currentRaw.length - selectedRaw.length);
|
|
1427
1851
|
if (availableCapacity <= 0) {
|
|
1852
|
+
if (isDynamic) {
|
|
1853
|
+
engine.resolveForValue(input.value);
|
|
1854
|
+
}
|
|
1428
1855
|
e.preventDefault();
|
|
1429
1856
|
return;
|
|
1430
1857
|
}
|
|
1431
1858
|
}
|
|
1859
|
+
if (isDynamic) {
|
|
1860
|
+
engine.resolveForValue(input.value);
|
|
1861
|
+
}
|
|
1432
1862
|
}
|
|
1433
1863
|
if (selectionEnd > cursor) {
|
|
1434
1864
|
if (e.key === "Backspace" || e.key === "Delete") {
|
|
@@ -1567,6 +1997,7 @@ var InputMask = class extends BaseInputMask {
|
|
|
1567
1997
|
cutTimerId = null;
|
|
1568
1998
|
pasteTimerId = null;
|
|
1569
1999
|
resetTimerId = null;
|
|
2000
|
+
lastInputType = "";
|
|
1570
2001
|
constructor(targetOrWrapper, inputOrOptions, options) {
|
|
1571
2002
|
const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
|
|
1572
2003
|
const wrap = args.wrapper;
|
|
@@ -1617,20 +2048,26 @@ var InputMask = class extends BaseInputMask {
|
|
|
1617
2048
|
enforceMinCursor: () => this.enforceMinCursor()
|
|
1618
2049
|
});
|
|
1619
2050
|
this.bindEvents();
|
|
1620
|
-
this.lastValue = this.
|
|
2051
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
1621
2052
|
this.syncInitialValue();
|
|
1622
2053
|
this.runAuditWarning(this.options.audit);
|
|
1623
2054
|
}
|
|
1624
2055
|
getSpecificAuditWarnings() {
|
|
1625
2056
|
const warnings = [];
|
|
1626
2057
|
const describedbyWarnings = [];
|
|
1627
|
-
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings);
|
|
2058
|
+
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings, true);
|
|
1628
2059
|
const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
|
|
1629
2060
|
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
1630
|
-
if (!hasValidDescribedby && !
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
2061
|
+
if (!hasValidDescribedby && !hasAriaPlaceholder && !this.options.disabled) {
|
|
2062
|
+
if (hasPlaceholder) {
|
|
2063
|
+
warnings.push(
|
|
2064
|
+
"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)."
|
|
2065
|
+
);
|
|
2066
|
+
} else {
|
|
2067
|
+
warnings.push(
|
|
2068
|
+
"Indication du format attendu manquante : d\xE9finissez aria-describedby ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
1634
2071
|
}
|
|
1635
2072
|
return warnings;
|
|
1636
2073
|
}
|
|
@@ -1649,7 +2086,7 @@ var InputMask = class extends BaseInputMask {
|
|
|
1649
2086
|
* Formate statiquement une valeur selon un masque donné sans nécessiter d'élément DOM.
|
|
1650
2087
|
*
|
|
1651
2088
|
* @param value Valeur à formater (ex: "0123456789")
|
|
1652
|
-
* @param mask Gabarit de masque (ex: "99 99 99 99 99")
|
|
2089
|
+
* @param mask Gabarit de masque (ex: "99 99 99 99 99", tableau ou résolveur dynamique)
|
|
1653
2090
|
* @param options Options facultatives du masque (tokens, placeholderChar, strict, etc.)
|
|
1654
2091
|
* @returns Valeur formatée (ex: "01 23 45 67 89")
|
|
1655
2092
|
*/
|
|
@@ -1660,7 +2097,8 @@ var InputMask = class extends BaseInputMask {
|
|
|
1660
2097
|
if (this.options.disabled) {
|
|
1661
2098
|
this.checkValueChange();
|
|
1662
2099
|
} else {
|
|
1663
|
-
this.
|
|
2100
|
+
const transformed = this.applyTransformInput(strVal, "programmatic", "");
|
|
2101
|
+
this.applyMask(transformed, transformed.length);
|
|
1664
2102
|
}
|
|
1665
2103
|
}
|
|
1666
2104
|
onDisabledChange(disabled) {
|
|
@@ -1837,10 +2275,13 @@ var InputMask = class extends BaseInputMask {
|
|
|
1837
2275
|
super.handleAttributeMutation(attrName);
|
|
1838
2276
|
if (attrName === "data-mask") {
|
|
1839
2277
|
const rawAttr = this.getAttr("data-mask");
|
|
2278
|
+
if (rawAttr === null && (this.isSensitiveField() || typeof this.options.mask === "function")) {
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
1840
2281
|
if (rawAttr === this.lastInternalRemainingMask) {
|
|
1841
2282
|
return;
|
|
1842
2283
|
}
|
|
1843
|
-
const currentMaskStr = Array.isArray(this.options.mask) ? this.options.mask.join("|") : this.options.mask || "";
|
|
2284
|
+
const currentMaskStr = typeof this.options.mask === "function" ? "" : Array.isArray(this.options.mask) ? this.options.mask.join("|") : this.options.mask || "";
|
|
1844
2285
|
if (rawAttr === currentMaskStr) {
|
|
1845
2286
|
return;
|
|
1846
2287
|
}
|
|
@@ -1862,6 +2303,19 @@ var InputMask = class extends BaseInputMask {
|
|
|
1862
2303
|
this.updateGhost(this.input.value);
|
|
1863
2304
|
}
|
|
1864
2305
|
}
|
|
2306
|
+
applyTransformInput(value, source, inputType) {
|
|
2307
|
+
if (typeof this.options.transformInput !== "function") {
|
|
2308
|
+
return value;
|
|
2309
|
+
}
|
|
2310
|
+
try {
|
|
2311
|
+
const res = this.options.transformInput(value, { source, inputType });
|
|
2312
|
+
if (typeof res === "string") {
|
|
2313
|
+
return source === "paste" ? sanitizePastedText(res, 4096) : stripBidiAndInvisibles(res, 4096);
|
|
2314
|
+
}
|
|
2315
|
+
} catch {
|
|
2316
|
+
}
|
|
2317
|
+
return value;
|
|
2318
|
+
}
|
|
1865
2319
|
/**
|
|
1866
2320
|
* Affecte une nouvelle valeur manuellement (formatée ou brute).
|
|
1867
2321
|
*/
|
|
@@ -1872,7 +2326,8 @@ var InputMask = class extends BaseInputMask {
|
|
|
1872
2326
|
this.checkValueChange();
|
|
1873
2327
|
return;
|
|
1874
2328
|
}
|
|
1875
|
-
this.
|
|
2329
|
+
const transformed = this.applyTransformInput(safeVal, "programmatic", "");
|
|
2330
|
+
this.applyMask(transformed, transformed.length);
|
|
1876
2331
|
}
|
|
1877
2332
|
/**
|
|
1878
2333
|
* Retourne la valeur brute sans séparateurs.
|
|
@@ -1881,12 +2336,14 @@ var InputMask = class extends BaseInputMask {
|
|
|
1881
2336
|
return this.engine.extractRaw(this.input.value);
|
|
1882
2337
|
}
|
|
1883
2338
|
/**
|
|
1884
|
-
* Indique si tous les emplacements éditables sont renseignés.
|
|
2339
|
+
* Indique si tous les emplacements éditables du gabarit actif sont renseignés.
|
|
1885
2340
|
*/
|
|
1886
2341
|
isComplete() {
|
|
1887
2342
|
if (this.options.disabled) return true;
|
|
1888
2343
|
const raw = this.getRawValue();
|
|
1889
|
-
|
|
2344
|
+
const activeSlots = this.engine.getActiveEditableCount();
|
|
2345
|
+
if (activeSlots === 0) return true;
|
|
2346
|
+
return raw.length >= activeSlots;
|
|
1890
2347
|
}
|
|
1891
2348
|
/**
|
|
1892
2349
|
* Callback d'écoute directe ou getter/setter pour onInput.
|
|
@@ -1932,32 +2389,45 @@ var InputMask = class extends BaseInputMask {
|
|
|
1932
2389
|
this.wrapper.classList.toggle("has-selection", hasSelection);
|
|
1933
2390
|
}
|
|
1934
2391
|
onBeforeInput(e) {
|
|
2392
|
+
this.lastInputType = e.inputType || "";
|
|
1935
2393
|
if (this.options.disabled) return;
|
|
1936
2394
|
if (this.isComposing) return;
|
|
1937
2395
|
if (!this.engine.isStrict()) return;
|
|
1938
2396
|
if (e.inputType === "insertFromPaste" || e.inputType === "insertReplacementText") return;
|
|
1939
2397
|
if (e.inputType && e.inputType.startsWith("insert")) {
|
|
1940
|
-
const
|
|
2398
|
+
const currentVal = this.input.value;
|
|
2399
|
+
const isDynamic = this.engine.isDynamicPattern();
|
|
2400
|
+
const currentRaw = this.engine.extractRaw(currentVal);
|
|
2401
|
+
const start = this.input.selectionStart ?? 0;
|
|
2402
|
+
const end = this.input.selectionEnd ?? start;
|
|
2403
|
+
const selectedRaw = end > start ? this.engine.extractRawForCurrentPattern(currentVal.slice(start, end)) : "";
|
|
2404
|
+
if (isDynamic) {
|
|
2405
|
+
const candidate = currentVal.slice(0, start) + (e.data ?? "") + currentVal.slice(end);
|
|
2406
|
+
this.engine.resolveForValue(candidate);
|
|
2407
|
+
}
|
|
2408
|
+
const totalSlots = this.engine.getMaxEditableCount();
|
|
1941
2409
|
if (totalSlots > 0) {
|
|
1942
|
-
const
|
|
1943
|
-
const start = this.input.selectionStart ?? 0;
|
|
1944
|
-
const end = this.input.selectionEnd ?? start;
|
|
1945
|
-
let availableCapacity = Math.max(0, totalSlots - currentRaw.length);
|
|
1946
|
-
if (end > start) {
|
|
1947
|
-
const selectedRaw = this.engine.extractRaw(this.input.value.slice(start, end));
|
|
1948
|
-
availableCapacity = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
1949
|
-
}
|
|
2410
|
+
const availableCapacity = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
1950
2411
|
if (availableCapacity <= 0) {
|
|
2412
|
+
if (isDynamic) {
|
|
2413
|
+
this.engine.resolveForValue(currentVal);
|
|
2414
|
+
}
|
|
1951
2415
|
e.preventDefault();
|
|
2416
|
+
return;
|
|
1952
2417
|
}
|
|
1953
2418
|
}
|
|
2419
|
+
if (isDynamic) {
|
|
2420
|
+
this.engine.resolveForValue(currentVal);
|
|
2421
|
+
}
|
|
1954
2422
|
}
|
|
1955
2423
|
}
|
|
1956
2424
|
handleInput(e) {
|
|
1957
2425
|
if (this.isDispatchingNativeInput) return;
|
|
1958
2426
|
if (this.isComposing) return;
|
|
2427
|
+
const inputType = e?.inputType || this.lastInputType || "";
|
|
2428
|
+
this.lastInputType = "";
|
|
1959
2429
|
const hasOnInput = Boolean(this.options.onInput || this.options.oninput);
|
|
1960
|
-
const currentComparison = this.
|
|
2430
|
+
const currentComparison = this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
1961
2431
|
if (hasOnInput && currentComparison !== this.lastValue) {
|
|
1962
2432
|
this.checkValueChange();
|
|
1963
2433
|
}
|
|
@@ -1965,17 +2435,20 @@ var InputMask = class extends BaseInputMask {
|
|
|
1965
2435
|
this.checkValueChange();
|
|
1966
2436
|
return;
|
|
1967
2437
|
}
|
|
2438
|
+
const rawInputVal = this.input.value;
|
|
2439
|
+
const oldCursor = this.input.selectionStart ?? rawInputVal.length;
|
|
2440
|
+
const transformedVal = this.applyTransformInput(rawInputVal, "input", inputType);
|
|
2441
|
+
const effectiveCursor = transformedVal !== rawInputVal ? oldCursor >= rawInputVal.length ? transformedVal.length : Math.min(oldCursor, transformedVal.length) : oldCursor;
|
|
1968
2442
|
const prevState = this.history.getCurrent();
|
|
1969
|
-
const
|
|
2443
|
+
const newRaw = this.engine.extractRaw(transformedVal);
|
|
2444
|
+
const totalSlots = this.engine.getMaxEditableCount();
|
|
1970
2445
|
if (totalSlots > 0 && this.engine.isStrict() && prevState && prevState.raw.length >= totalSlots) {
|
|
1971
|
-
const newRaw = this.engine.extractRaw(this.input.value);
|
|
1972
2446
|
if (newRaw.length > totalSlots) {
|
|
1973
2447
|
this.applyMask(prevState.raw, prevState.cursor);
|
|
1974
2448
|
return;
|
|
1975
2449
|
}
|
|
1976
2450
|
}
|
|
1977
|
-
|
|
1978
|
-
this.applyMask(this.input.value, oldCursor);
|
|
2451
|
+
this.applyMask(transformedVal, effectiveCursor);
|
|
1979
2452
|
this.checkSelection();
|
|
1980
2453
|
}
|
|
1981
2454
|
onKeyDown(e) {
|
|
@@ -2000,15 +2473,15 @@ var InputMask = class extends BaseInputMask {
|
|
|
2000
2473
|
}
|
|
2001
2474
|
e.preventDefault();
|
|
2002
2475
|
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
2003
|
-
const
|
|
2004
|
-
const pastedText =
|
|
2476
|
+
const preparedText = this.preparePastedText(this.getClipboardPlainText(e), 4096);
|
|
2477
|
+
const pastedText = this.applyTransformInput(preparedText, "paste", "insertFromPaste");
|
|
2005
2478
|
if (!pastedText) return;
|
|
2006
2479
|
const minPos = this.engine.getPrefixLength();
|
|
2007
2480
|
const selStart = this.input.selectionStart ?? 0;
|
|
2008
2481
|
const selEnd = this.input.selectionEnd ?? selStart;
|
|
2009
2482
|
const currentVal = this.input.value;
|
|
2010
|
-
const totalSlots = this.engine.getEditableCount();
|
|
2011
2483
|
const currentRaw = this.getRawValue();
|
|
2484
|
+
const totalSlots = this.engine.getMaxEditableCount();
|
|
2012
2485
|
const prefix = this.engine.getPrefix();
|
|
2013
2486
|
const cleanPrefix = prefix.replace(/[\s.-]+/g, "").toUpperCase();
|
|
2014
2487
|
const cleanPasted = pastedText.replace(/[\s.-]+/g, "").toUpperCase();
|
|
@@ -2023,17 +2496,38 @@ var InputMask = class extends BaseInputMask {
|
|
|
2023
2496
|
}
|
|
2024
2497
|
let availableCapacity = Math.max(0, totalSlots - currentRaw.length);
|
|
2025
2498
|
if (effectiveStart !== effectiveEnd) {
|
|
2026
|
-
const selectedRaw = this.engine.
|
|
2499
|
+
const selectedRaw = this.engine.extractRawForCurrentPattern(currentVal.slice(effectiveStart, effectiveEnd));
|
|
2027
2500
|
availableCapacity = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
2028
2501
|
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2502
|
+
const normalizedPasted = this.engine.normalizePastedValue(pastedText);
|
|
2503
|
+
const activeSlots = this.engine.getActiveEditableCount();
|
|
2504
|
+
const isCurrentComplete = activeSlots > 0 && currentRaw.length >= activeSlots;
|
|
2505
|
+
if (this.engine.isStrict() && (availableCapacity <= 0 || selStart === selEnd && isCurrentComplete)) {
|
|
2506
|
+
const pastedRawLen = this.engine.extractRaw(normalizedPasted).length;
|
|
2507
|
+
const targetMaxSlots = this.engine.getMaxEditableCount();
|
|
2508
|
+
if (selStart === selEnd && targetMaxSlots > 0 && pastedRawLen === targetMaxSlots && (availableCapacity <= 0 || pastedRawLen > availableCapacity)) {
|
|
2509
|
+
effectiveStart = 0;
|
|
2510
|
+
effectiveEnd = currentVal.length;
|
|
2511
|
+
} else if (availableCapacity <= 0) {
|
|
2512
|
+
this.engine.resolveForValue(currentVal);
|
|
2513
|
+
return;
|
|
2514
|
+
} else {
|
|
2515
|
+
this.engine.resolveForValue(currentVal);
|
|
2516
|
+
}
|
|
2031
2517
|
}
|
|
2032
2518
|
let combined;
|
|
2033
2519
|
let newCursorPos;
|
|
2034
2520
|
if (effectiveStart === 0 && effectiveEnd === currentVal.length) {
|
|
2035
|
-
combined =
|
|
2036
|
-
newCursorPos =
|
|
2521
|
+
combined = normalizedPasted;
|
|
2522
|
+
newCursorPos = normalizedPasted.length;
|
|
2523
|
+
} else if (currentRaw.length === 0 && effectiveStart === minPos && effectiveEnd === currentVal.length) {
|
|
2524
|
+
if (minPos > 0 && normalizedPasted.toUpperCase().startsWith(prefix.toUpperCase())) {
|
|
2525
|
+
combined = normalizedPasted;
|
|
2526
|
+
newCursorPos = normalizedPasted.length;
|
|
2527
|
+
} else {
|
|
2528
|
+
combined = currentVal.slice(0, effectiveStart) + normalizedPasted;
|
|
2529
|
+
newCursorPos = combined.length;
|
|
2530
|
+
}
|
|
2037
2531
|
} else {
|
|
2038
2532
|
combined = currentVal.slice(0, effectiveStart) + pastedText + currentVal.slice(effectiveEnd);
|
|
2039
2533
|
newCursorPos = effectiveStart + pastedText.length;
|
|
@@ -2052,7 +2546,7 @@ var InputMask = class extends BaseInputMask {
|
|
|
2052
2546
|
}
|
|
2053
2547
|
onBlur() {
|
|
2054
2548
|
this.wrapper.classList.remove("is-focused", "has-selection");
|
|
2055
|
-
if (this.
|
|
2549
|
+
if (this.isSensitiveField()) {
|
|
2056
2550
|
this.history.clear();
|
|
2057
2551
|
this.lastValue = "";
|
|
2058
2552
|
this.lastInternalRemainingMask = "";
|
|
@@ -2113,7 +2607,7 @@ var InputMask = class extends BaseInputMask {
|
|
|
2113
2607
|
// ==========================================================================
|
|
2114
2608
|
updateGhost(formatted) {
|
|
2115
2609
|
if (!this.ghost) return;
|
|
2116
|
-
if (this.options.disabled || this.
|
|
2610
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
2117
2611
|
this.clearGhost();
|
|
2118
2612
|
return;
|
|
2119
2613
|
}
|
|
@@ -2141,10 +2635,13 @@ var InputMask = class extends BaseInputMask {
|
|
|
2141
2635
|
let isCompleted = false;
|
|
2142
2636
|
try {
|
|
2143
2637
|
formatted = this.engine.format(rawOrPartial);
|
|
2638
|
+
if (this.engine.isDynamicPattern()) {
|
|
2639
|
+
this.syncInferredInputMode();
|
|
2640
|
+
}
|
|
2144
2641
|
const remainingMask = this.engine.getRemainingMask(formatted);
|
|
2145
|
-
const
|
|
2146
|
-
this.
|
|
2147
|
-
if (
|
|
2642
|
+
const isSensitive = this.isSensitiveField();
|
|
2643
|
+
this.setNativeValue(formatted);
|
|
2644
|
+
if (isSensitive) {
|
|
2148
2645
|
this.lastInternalRemainingMask = "";
|
|
2149
2646
|
this.wrapper.removeAttribute("data-mask");
|
|
2150
2647
|
this.clearGhost();
|
|
@@ -2164,7 +2661,7 @@ var InputMask = class extends BaseInputMask {
|
|
|
2164
2661
|
this.input.setSelectionRange(safeCursor, safeCursor);
|
|
2165
2662
|
isCompleted = this.isComplete();
|
|
2166
2663
|
this.wrapper.classList.toggle("is-complete", isCompleted);
|
|
2167
|
-
if (
|
|
2664
|
+
if (isSensitive) {
|
|
2168
2665
|
this.options.copyRaw = false;
|
|
2169
2666
|
this.history.clear();
|
|
2170
2667
|
} else if (!this.isUndoingRedoing) {
|
|
@@ -2176,24 +2673,25 @@ var InputMask = class extends BaseInputMask {
|
|
|
2176
2673
|
this.checkValueChange();
|
|
2177
2674
|
}
|
|
2178
2675
|
syncInitialValue() {
|
|
2179
|
-
const
|
|
2676
|
+
const isSensitive = this.isSensitiveField();
|
|
2180
2677
|
if (this.options.disabled) {
|
|
2181
2678
|
this.wrapper.removeAttribute("data-mask");
|
|
2182
2679
|
this.clearGhost();
|
|
2183
|
-
this.lastValue =
|
|
2680
|
+
this.lastValue = isSensitive ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
2184
2681
|
this.checkValueChange();
|
|
2185
2682
|
return;
|
|
2186
2683
|
}
|
|
2187
2684
|
this.syncGhostStyles();
|
|
2188
2685
|
const initialVal = this.input.value || "";
|
|
2189
2686
|
if (initialVal) {
|
|
2190
|
-
this.
|
|
2687
|
+
const transformed = this.applyTransformInput(initialVal, "programmatic", "");
|
|
2688
|
+
this.applyMask(transformed, transformed.length);
|
|
2191
2689
|
} else {
|
|
2192
2690
|
const minPos = this.engine.getPrefixLength();
|
|
2193
2691
|
if (minPos > 0) {
|
|
2194
2692
|
this.applyMask("", minPos);
|
|
2195
2693
|
} else {
|
|
2196
|
-
if (!
|
|
2694
|
+
if (!isSensitive) {
|
|
2197
2695
|
this.history.push("", 0);
|
|
2198
2696
|
const fullTemplate = this.engine.getFullMaskTemplate();
|
|
2199
2697
|
this.lastInternalRemainingMask = fullTemplate;
|
|
@@ -2213,9 +2711,9 @@ var InputMask = class extends BaseInputMask {
|
|
|
2213
2711
|
* Gère de manière sûre la réentrance pour permettre d'appeler setMask() directement dans le callback.
|
|
2214
2712
|
*/
|
|
2215
2713
|
checkValueChange(forceNotify = false) {
|
|
2216
|
-
const
|
|
2714
|
+
const initialSensitive = this.isSensitiveField();
|
|
2217
2715
|
const currentVal = this.input.value;
|
|
2218
|
-
const currentComparison =
|
|
2716
|
+
const currentComparison = initialSensitive ? this.computePasswordDigest(currentVal) : currentVal;
|
|
2219
2717
|
if (currentComparison === this.lastValue && !forceNotify && !this.hasPendingNotification) {
|
|
2220
2718
|
return;
|
|
2221
2719
|
}
|
|
@@ -2226,15 +2724,16 @@ var InputMask = class extends BaseInputMask {
|
|
|
2226
2724
|
this.isNotifying = true;
|
|
2227
2725
|
try {
|
|
2228
2726
|
let iterations = 0;
|
|
2229
|
-
const
|
|
2230
|
-
while (((
|
|
2727
|
+
const MAX_NOTIFICATION_ITERATIONS4 = 10;
|
|
2728
|
+
while (((this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS4) {
|
|
2231
2729
|
iterations++;
|
|
2232
2730
|
this.hasPendingNotification = false;
|
|
2233
2731
|
forceNotify = false;
|
|
2732
|
+
const sensitiveNow = this.isSensitiveField();
|
|
2234
2733
|
const valToNotify = this.input.value;
|
|
2235
|
-
this.lastValue =
|
|
2734
|
+
this.lastValue = sensitiveNow ? this.computePasswordDigest(valToNotify) : valToNotify;
|
|
2236
2735
|
const raw = this.options.disabled ? valToNotify : this.getRawValue();
|
|
2237
|
-
const totalSlots = this.options.disabled ? 0 : this.engine.
|
|
2736
|
+
const totalSlots = this.options.disabled ? 0 : this.engine.getActiveEditableCount();
|
|
2238
2737
|
const isComplete = this.isComplete();
|
|
2239
2738
|
const detail = {
|
|
2240
2739
|
value: valToNotify,
|
|
@@ -2243,23 +2742,24 @@ var InputMask = class extends BaseInputMask {
|
|
|
2243
2742
|
totalSlots,
|
|
2244
2743
|
filledSlots: this.options.disabled ? valToNotify.length : raw.length
|
|
2245
2744
|
};
|
|
2745
|
+
const allowBubble = !sensitiveNow;
|
|
2246
2746
|
const onInputCb = this.options.onInput || this.options.oninput;
|
|
2247
2747
|
if (onInputCb) {
|
|
2248
2748
|
onInputCb(valToNotify, detail);
|
|
2249
2749
|
}
|
|
2250
|
-
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles:
|
|
2750
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: allowBubble, detail }));
|
|
2251
2751
|
this.dispatchNativeInput();
|
|
2252
2752
|
const onChangeCb = this.options.onChange || this.options.onchange;
|
|
2253
2753
|
if (onChangeCb) {
|
|
2254
2754
|
onChangeCb(detail);
|
|
2255
2755
|
}
|
|
2256
|
-
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles:
|
|
2756
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
2257
2757
|
const onCompleteCb = this.options.onComplete || this.options.oncomplete;
|
|
2258
2758
|
if (isComplete) {
|
|
2259
2759
|
if (onCompleteCb) {
|
|
2260
2760
|
onCompleteCb(detail);
|
|
2261
2761
|
}
|
|
2262
|
-
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles:
|
|
2762
|
+
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles: allowBubble, detail }));
|
|
2263
2763
|
}
|
|
2264
2764
|
}
|
|
2265
2765
|
} finally {
|
|
@@ -2292,6 +2792,47 @@ var AmountEngine = class _AmountEngine {
|
|
|
2292
2792
|
max: options.max ?? Infinity
|
|
2293
2793
|
};
|
|
2294
2794
|
}
|
|
2795
|
+
/**
|
|
2796
|
+
* Normalise un texte collé uniquement lorsque le séparateur décimal vs milliers
|
|
2797
|
+
* est mathématiquement non ambigu :
|
|
2798
|
+
* - coexistence de ',' et '.' (le séparateur le plus à droite, s'il est unique, est la décimale),
|
|
2799
|
+
* - répétition (>= 2) d'un unique séparateur (il s'agit alors de séparateurs de milliers).
|
|
2800
|
+
* Un séparateur unique isolé (ex: "1,234") reste inchangé pour respecter la locale configurée.
|
|
2801
|
+
*/
|
|
2802
|
+
normalizePastedValue(pasted) {
|
|
2803
|
+
const str = sanitizePastedText(pasted, 512);
|
|
2804
|
+
if (!str) return "";
|
|
2805
|
+
let commaCount = 0;
|
|
2806
|
+
let dotCount = 0;
|
|
2807
|
+
let lastCommaIdx = -1;
|
|
2808
|
+
let lastDotIdx = -1;
|
|
2809
|
+
for (let i = 0; i < str.length; i++) {
|
|
2810
|
+
const ch = str[i];
|
|
2811
|
+
if (ch === ",") {
|
|
2812
|
+
commaCount++;
|
|
2813
|
+
lastCommaIdx = i;
|
|
2814
|
+
} else if (ch === ".") {
|
|
2815
|
+
dotCount++;
|
|
2816
|
+
lastDotIdx = i;
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
if (commaCount > 0 && dotCount > 0) {
|
|
2820
|
+
const decChar = lastCommaIdx > lastDotIdx ? "," : ".";
|
|
2821
|
+
const decCount = decChar === "," ? commaCount : dotCount;
|
|
2822
|
+
if (decCount !== 1) {
|
|
2823
|
+
return str;
|
|
2824
|
+
}
|
|
2825
|
+
const thousandChar = decChar === "," ? "." : ",";
|
|
2826
|
+
return str.split(thousandChar).join("").replace(decChar, this.options.decimalSeparator);
|
|
2827
|
+
}
|
|
2828
|
+
if (commaCount >= 2 && dotCount === 0) {
|
|
2829
|
+
return str.split(",").join("");
|
|
2830
|
+
}
|
|
2831
|
+
if (dotCount >= 2 && commaCount === 0) {
|
|
2832
|
+
return str.split(".").join("");
|
|
2833
|
+
}
|
|
2834
|
+
return str;
|
|
2835
|
+
}
|
|
2295
2836
|
/**
|
|
2296
2837
|
* Analyse et nettoie une saisie utilisateur pour extraire ses composantes numériques.
|
|
2297
2838
|
*/
|
|
@@ -2482,12 +3023,15 @@ var AmountEngine = class _AmountEngine {
|
|
|
2482
3023
|
};
|
|
2483
3024
|
|
|
2484
3025
|
// src/mask/InputAmountMask.ts
|
|
3026
|
+
var MAX_NOTIFICATION_ITERATIONS = 10;
|
|
2485
3027
|
var InputAmountMask = class extends BaseInputMask {
|
|
2486
3028
|
engine;
|
|
2487
3029
|
history;
|
|
2488
3030
|
isUndoingRedoing = false;
|
|
2489
3031
|
isApplying = false;
|
|
2490
3032
|
isComposing = false;
|
|
3033
|
+
isNotifying = false;
|
|
3034
|
+
hasPendingNotification = false;
|
|
2491
3035
|
lastValue = "";
|
|
2492
3036
|
wasInputModeInferred = false;
|
|
2493
3037
|
cutTimerId = null;
|
|
@@ -2547,7 +3091,7 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2547
3091
|
}
|
|
2548
3092
|
onNativeValueSet(strVal) {
|
|
2549
3093
|
if (this.options.disabled || this.isComposing) {
|
|
2550
|
-
this.lastValue = strVal;
|
|
3094
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(strVal) : strVal;
|
|
2551
3095
|
return;
|
|
2552
3096
|
}
|
|
2553
3097
|
this.applyAmount(strVal, strVal.length);
|
|
@@ -2562,6 +3106,7 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2562
3106
|
bindEvents() {
|
|
2563
3107
|
this.handleInput = this.handleInput.bind(this);
|
|
2564
3108
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
3109
|
+
this.handlePaste = this.handlePaste.bind(this);
|
|
2565
3110
|
this.handleBlur = this.handleBlur.bind(this);
|
|
2566
3111
|
this.handleFocus = this.handleFocus.bind(this);
|
|
2567
3112
|
this.handleClick = this.handleClick.bind(this);
|
|
@@ -2581,6 +3126,7 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2581
3126
|
const { signal } = this.abortController;
|
|
2582
3127
|
this.input.addEventListener("input", this.handleInput, { signal });
|
|
2583
3128
|
this.input.addEventListener("keydown", this.handleKeyDown, { signal });
|
|
3129
|
+
this.input.addEventListener("paste", this.handlePaste, { signal });
|
|
2584
3130
|
this.input.addEventListener("blur", this.handleBlur, { signal });
|
|
2585
3131
|
this.input.addEventListener("focus", this.handleFocus, { signal });
|
|
2586
3132
|
this.input.addEventListener("click", this.handleClick, { signal });
|
|
@@ -2615,12 +3161,13 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2615
3161
|
applyAmount(val, cursor) {
|
|
2616
3162
|
if (this.isApplying || this.options.disabled) return;
|
|
2617
3163
|
this.isApplying = true;
|
|
3164
|
+
let result = null;
|
|
2618
3165
|
try {
|
|
2619
|
-
|
|
3166
|
+
result = this.engine.format(val, cursor);
|
|
2620
3167
|
this.setNativeValue(result.formatted);
|
|
2621
3168
|
this.input.setSelectionRange(result.cursor, result.cursor);
|
|
2622
|
-
const
|
|
2623
|
-
if (
|
|
3169
|
+
const isSensitive = this.isSensitiveField();
|
|
3170
|
+
if (isSensitive) {
|
|
2624
3171
|
this.options.copyRaw = false;
|
|
2625
3172
|
this.history.clear();
|
|
2626
3173
|
this.clearGhost();
|
|
@@ -2630,17 +3177,19 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2630
3177
|
}
|
|
2631
3178
|
this.updateGhost(result);
|
|
2632
3179
|
}
|
|
2633
|
-
const nextComparison = isPwd ? this.computePasswordDigest(result.formatted) : result.formatted;
|
|
2634
|
-
if (this.lastValue !== nextComparison) {
|
|
2635
|
-
this.lastValue = nextComparison;
|
|
2636
|
-
this.notifyChange(result);
|
|
2637
|
-
}
|
|
2638
3180
|
} finally {
|
|
2639
3181
|
this.isApplying = false;
|
|
2640
3182
|
}
|
|
3183
|
+
if (result) {
|
|
3184
|
+
this.checkValueChange(result);
|
|
3185
|
+
}
|
|
2641
3186
|
}
|
|
2642
3187
|
updateGhost(result) {
|
|
2643
3188
|
if (!this.ghost) return;
|
|
3189
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
3190
|
+
this.clearGhost();
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
2644
3193
|
if (!result.formatted) {
|
|
2645
3194
|
if (this.shouldHideGhostForPlaceholder(true)) {
|
|
2646
3195
|
this.clearGhost();
|
|
@@ -2664,6 +3213,18 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2664
3213
|
const cur = this.input.selectionStart ?? rawVal.length;
|
|
2665
3214
|
this.applyAmount(rawVal, cur);
|
|
2666
3215
|
}
|
|
3216
|
+
handlePaste(e) {
|
|
3217
|
+
if (this.options.disabled) return;
|
|
3218
|
+
e.preventDefault();
|
|
3219
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
3220
|
+
const prepared = this.preparePastedText(this.getClipboardPlainText(e), 512);
|
|
3221
|
+
if (!prepared) return;
|
|
3222
|
+
const normalized = this.engine.normalizePastedValue(prepared);
|
|
3223
|
+
const start = this.input.selectionStart ?? this.input.value.length;
|
|
3224
|
+
const end = this.input.selectionEnd ?? start;
|
|
3225
|
+
const combined = this.input.value.slice(0, start) + normalized + this.input.value.slice(end);
|
|
3226
|
+
this.applyAmount(combined, start + normalized.length);
|
|
3227
|
+
}
|
|
2667
3228
|
handleKeyDown(e) {
|
|
2668
3229
|
if (this.options.disabled || isImeComposing(e)) return;
|
|
2669
3230
|
if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z")) {
|
|
@@ -2728,7 +3289,9 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2728
3289
|
}
|
|
2729
3290
|
}
|
|
2730
3291
|
enforceCursorBounds() {
|
|
2731
|
-
if (this.isDestroyed || !this.isFocused ||
|
|
3292
|
+
if (this.isDestroyed || !this.isFocused || getDeepActiveElement(this.input.ownerDocument) !== this.input || !this.input.value || this.options.disabled) {
|
|
3293
|
+
return;
|
|
3294
|
+
}
|
|
2732
3295
|
const start = this.input.selectionStart ?? 0;
|
|
2733
3296
|
const end = this.input.selectionEnd ?? 0;
|
|
2734
3297
|
if (start !== end) return;
|
|
@@ -2759,7 +3322,7 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2759
3322
|
}
|
|
2760
3323
|
handleBlur() {
|
|
2761
3324
|
this.wrapper.classList.remove("is-focused");
|
|
2762
|
-
if (this.
|
|
3325
|
+
if (this.isSensitiveField()) {
|
|
2763
3326
|
this.history.clear();
|
|
2764
3327
|
this.lastValue = "";
|
|
2765
3328
|
this.lastTrackedValue = "";
|
|
@@ -2778,7 +3341,7 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2778
3341
|
if (this.options.onChange) {
|
|
2779
3342
|
this.options.onChange(detail);
|
|
2780
3343
|
}
|
|
2781
|
-
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles:
|
|
3344
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: !this.isSensitiveField(), detail }));
|
|
2782
3345
|
}
|
|
2783
3346
|
handleAttributeMutation(attrName) {
|
|
2784
3347
|
super.handleAttributeMutation(attrName);
|
|
@@ -2788,6 +3351,34 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2788
3351
|
this.updateGhost(this.engine.format(this.input.value));
|
|
2789
3352
|
}
|
|
2790
3353
|
}
|
|
3354
|
+
checkValueChange(initialResult) {
|
|
3355
|
+
const initialSensitive = this.isSensitiveField();
|
|
3356
|
+
const initialComparison = initialSensitive ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
3357
|
+
if (initialComparison === this.lastValue && !this.hasPendingNotification) {
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3360
|
+
if (this.isNotifying) {
|
|
3361
|
+
this.hasPendingNotification = true;
|
|
3362
|
+
return;
|
|
3363
|
+
}
|
|
3364
|
+
this.isNotifying = true;
|
|
3365
|
+
try {
|
|
3366
|
+
let iterations = 0;
|
|
3367
|
+
let nextResult = initialResult;
|
|
3368
|
+
while (((this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification) && iterations < MAX_NOTIFICATION_ITERATIONS) {
|
|
3369
|
+
iterations++;
|
|
3370
|
+
this.hasPendingNotification = false;
|
|
3371
|
+
const sensitiveNow = this.isSensitiveField();
|
|
3372
|
+
const currentVal = this.input.value;
|
|
3373
|
+
this.lastValue = sensitiveNow ? this.computePasswordDigest(currentVal) : currentVal;
|
|
3374
|
+
const res = nextResult ?? this.engine.format(currentVal);
|
|
3375
|
+
nextResult = void 0;
|
|
3376
|
+
this.notifyChange(res);
|
|
3377
|
+
}
|
|
3378
|
+
} finally {
|
|
3379
|
+
this.isNotifying = false;
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
2791
3382
|
notifyChange(result) {
|
|
2792
3383
|
const detail = {
|
|
2793
3384
|
value: result.formatted,
|
|
@@ -2798,7 +3389,7 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2798
3389
|
if (this.options.onInput) {
|
|
2799
3390
|
this.options.onInput(detail);
|
|
2800
3391
|
}
|
|
2801
|
-
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles:
|
|
3392
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: !this.isSensitiveField(), detail }));
|
|
2802
3393
|
this.dispatchNativeInput();
|
|
2803
3394
|
}
|
|
2804
3395
|
undo() {
|
|
@@ -2841,20 +3432,62 @@ var InputAmountMask = class extends BaseInputMask {
|
|
|
2841
3432
|
isValid() {
|
|
2842
3433
|
return this.getDetail().isValid;
|
|
2843
3434
|
}
|
|
2844
|
-
|
|
2845
|
-
const
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
} else {
|
|
2850
|
-
this.applyAmount(str, str.length);
|
|
3435
|
+
getSpecificAuditWarnings() {
|
|
3436
|
+
const warnings = [];
|
|
3437
|
+
const currencyOrUnit = (this.options.currency || this.options.unit || "").trim();
|
|
3438
|
+
if (!currencyOrUnit || this.options.disabled) {
|
|
3439
|
+
return warnings;
|
|
2851
3440
|
}
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
if (
|
|
2856
|
-
|
|
2857
|
-
|
|
3441
|
+
const describedbyWarnings = [];
|
|
3442
|
+
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings, true);
|
|
3443
|
+
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
3444
|
+
if (hasValidDescribedby || hasAriaPlaceholder) {
|
|
3445
|
+
return warnings;
|
|
3446
|
+
}
|
|
3447
|
+
const doc = this.input.ownerDocument || document;
|
|
3448
|
+
const root = typeof this.input.getRootNode === "function" ? this.input.getRootNode() : doc;
|
|
3449
|
+
const labelRoot = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : doc;
|
|
3450
|
+
let labelTexts = this.input.getAttribute("aria-label") || "";
|
|
3451
|
+
const labelledBy = this.input.getAttribute("aria-labelledby")?.trim();
|
|
3452
|
+
if (labelledBy) {
|
|
3453
|
+
for (const id of labelledBy.split(/\s+/).filter(Boolean)) {
|
|
3454
|
+
const target = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id);
|
|
3455
|
+
if (target?.textContent) labelTexts += " " + target.textContent;
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
const wrapping = this.input.closest("label");
|
|
3459
|
+
if (wrapping?.textContent) labelTexts += " " + wrapping.textContent;
|
|
3460
|
+
if (this.input.id) {
|
|
3461
|
+
try {
|
|
3462
|
+
const explicit = labelRoot.querySelector(`label[for="${safeCssEscape(this.input.id)}"]`);
|
|
3463
|
+
if (explicit?.textContent) labelTexts += " " + explicit.textContent;
|
|
3464
|
+
} catch {
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
const norm = labelTexts.toLowerCase();
|
|
3468
|
+
const token = currencyOrUnit.toLowerCase();
|
|
3469
|
+
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"));
|
|
3470
|
+
if (!hasCurrencyAlias) {
|
|
3471
|
+
warnings.push(
|
|
3472
|
+
`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).`
|
|
3473
|
+
);
|
|
3474
|
+
}
|
|
3475
|
+
return warnings;
|
|
3476
|
+
}
|
|
3477
|
+
setValue(val) {
|
|
3478
|
+
const str = val !== null && val !== void 0 ? String(val) : "";
|
|
3479
|
+
if (this.options.disabled) {
|
|
3480
|
+
this.setNativeValue(str);
|
|
3481
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(str) : str;
|
|
3482
|
+
} else {
|
|
3483
|
+
this.applyAmount(str, str.length);
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
destroy() {
|
|
3487
|
+
if (this.isDestroyed) return;
|
|
3488
|
+
if (this.cutTimerId !== null) {
|
|
3489
|
+
clearTimeout(this.cutTimerId);
|
|
3490
|
+
this.cutTimerId = null;
|
|
2858
3491
|
}
|
|
2859
3492
|
if (this.resetTimerId !== null) {
|
|
2860
3493
|
clearTimeout(this.resetTimerId);
|
|
@@ -2914,7 +3547,8 @@ var EmailEngine = class _EmailEngine {
|
|
|
2914
3547
|
"it"
|
|
2915
3548
|
];
|
|
2916
3549
|
constructor(options = {}) {
|
|
2917
|
-
|
|
3550
|
+
const customDomains = Array.isArray(options.domains) ? options.domains.slice(0, 500).map((d) => String(d ?? "").trim().slice(0, 253)).filter(Boolean) : [];
|
|
3551
|
+
this.domains = customDomains.length > 0 ? customDomains : _EmailEngine.DEFAULT_DOMAINS;
|
|
2918
3552
|
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];
|
|
2919
3553
|
this.suggestOnAt = options.suggestOnAt ?? true;
|
|
2920
3554
|
this.setDefaultDomain(options.defaultDomain ?? null);
|
|
@@ -2927,7 +3561,7 @@ var EmailEngine = class _EmailEngine {
|
|
|
2927
3561
|
if (domain === true) {
|
|
2928
3562
|
this.defaultDomain = this.domains.length > 0 ? this.domains[0] : null;
|
|
2929
3563
|
} else if (typeof domain === "string" && domain.trim().length > 0) {
|
|
2930
|
-
this.defaultDomain = domain.trim().replace(/^@/, "");
|
|
3564
|
+
this.defaultDomain = domain.trim().replace(/^@/, "").slice(0, 253) || null;
|
|
2931
3565
|
} else {
|
|
2932
3566
|
this.defaultDomain = null;
|
|
2933
3567
|
}
|
|
@@ -2939,7 +3573,7 @@ var EmailEngine = class _EmailEngine {
|
|
|
2939
3573
|
if (tld === true) {
|
|
2940
3574
|
this.defaultTld = this.tlds.length > 0 ? this.tlds[0] : null;
|
|
2941
3575
|
} else if (typeof tld === "string" && tld.trim().length > 0) {
|
|
2942
|
-
this.defaultTld = tld.trim().replace(/^\./, "");
|
|
3576
|
+
this.defaultTld = tld.trim().replace(/^\./, "").slice(0, 32) || null;
|
|
2943
3577
|
} else {
|
|
2944
3578
|
this.defaultTld = null;
|
|
2945
3579
|
}
|
|
@@ -3098,11 +3732,16 @@ var EmailEngine = class _EmailEngine {
|
|
|
3098
3732
|
};
|
|
3099
3733
|
|
|
3100
3734
|
// src/mask/InputEmailMask.ts
|
|
3735
|
+
var MAX_NOTIFICATION_ITERATIONS2 = 10;
|
|
3101
3736
|
var InputEmailMask = class extends BaseInputMask {
|
|
3102
3737
|
engine;
|
|
3103
3738
|
currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3104
3739
|
currentSuggestionIndex = 0;
|
|
3740
|
+
hadInitialAriaAutocomplete = false;
|
|
3105
3741
|
wasAriaAutocompleteSet = false;
|
|
3742
|
+
isSuggestionDismissed = false;
|
|
3743
|
+
isNotifying = false;
|
|
3744
|
+
hasPendingNotification = false;
|
|
3106
3745
|
wasAutocorrectSet = false;
|
|
3107
3746
|
wasAutocapitalizeSet = false;
|
|
3108
3747
|
wasSpellcheckSet = false;
|
|
@@ -3155,18 +3794,42 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3155
3794
|
this.input.setAttribute("spellcheck", "false");
|
|
3156
3795
|
this.wasSpellcheckSet = true;
|
|
3157
3796
|
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
this.wasAriaAutocompleteSet = true;
|
|
3161
|
-
}
|
|
3797
|
+
this.hadInitialAriaAutocomplete = this.input.hasAttribute("aria-autocomplete");
|
|
3798
|
+
this.syncAriaAutocomplete();
|
|
3162
3799
|
this.engine = new EmailEngine(this.options);
|
|
3163
|
-
this.lastNotifiedValue = this.
|
|
3800
|
+
this.lastNotifiedValue = this.isSensitiveField() ? "" : this.input.value;
|
|
3164
3801
|
this.bindEvents();
|
|
3165
|
-
if (!this.options.disabled && !this.
|
|
3802
|
+
if (!this.options.disabled && !this.isSensitiveField()) {
|
|
3166
3803
|
this.updateSuggestion();
|
|
3167
3804
|
}
|
|
3168
3805
|
this.runAuditWarning(this.options.audit);
|
|
3169
3806
|
}
|
|
3807
|
+
syncAriaAutocomplete() {
|
|
3808
|
+
const canSuggest = Boolean(
|
|
3809
|
+
this.options.setAriaAutocomplete && !this.options.disabled && !this.isSensitiveField() && !this.isDestroyed
|
|
3810
|
+
);
|
|
3811
|
+
if (!this.hadInitialAriaAutocomplete) {
|
|
3812
|
+
if (canSuggest) {
|
|
3813
|
+
if (!this.input.hasAttribute("aria-autocomplete")) {
|
|
3814
|
+
this.input.setAttribute("aria-autocomplete", "inline");
|
|
3815
|
+
this.wasAriaAutocompleteSet = true;
|
|
3816
|
+
}
|
|
3817
|
+
} else if (this.wasAriaAutocompleteSet) {
|
|
3818
|
+
if (this.input.getAttribute("aria-autocomplete") === "inline") {
|
|
3819
|
+
this.input.removeAttribute("aria-autocomplete");
|
|
3820
|
+
}
|
|
3821
|
+
this.wasAriaAutocompleteSet = false;
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
const doc = this.input.ownerDocument || (typeof document !== "undefined" ? document : null);
|
|
3825
|
+
const hasAriaNotify = Boolean(doc && typeof doc.ariaNotify === "function");
|
|
3826
|
+
if (canSuggest && !hasAriaNotify) {
|
|
3827
|
+
this.ensureSrStatusEl();
|
|
3828
|
+
} else if (!canSuggest && this.srStatusEl) {
|
|
3829
|
+
this.srStatusEl.remove();
|
|
3830
|
+
this.srStatusEl = null;
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3170
3833
|
onPasswordModeDetected() {
|
|
3171
3834
|
if (this.srAnnounceTimerId !== null) {
|
|
3172
3835
|
clearTimeout(this.srAnnounceTimerId);
|
|
@@ -3176,25 +3839,28 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3176
3839
|
this.lastTrackedValue = "";
|
|
3177
3840
|
this.lastAnnouncedSuggestion = "";
|
|
3178
3841
|
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3179
|
-
|
|
3180
|
-
this.srStatusEl.textContent = "";
|
|
3181
|
-
}
|
|
3842
|
+
this.syncAriaAutocomplete();
|
|
3182
3843
|
this.clearGhost();
|
|
3183
3844
|
}
|
|
3184
3845
|
onNativeValueSet(_strVal) {
|
|
3185
|
-
if (this.options.disabled || this.isComposing || this.
|
|
3846
|
+
if (this.options.disabled || this.isComposing || this.isSensitiveField()) return;
|
|
3847
|
+
this.isSuggestionDismissed = false;
|
|
3186
3848
|
this.updateSuggestion();
|
|
3187
3849
|
}
|
|
3188
3850
|
onDisabledChange(disabled) {
|
|
3189
|
-
|
|
3851
|
+
this.syncAriaAutocomplete();
|
|
3852
|
+
if (disabled || this.isSensitiveField()) {
|
|
3853
|
+
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3190
3854
|
this.clearGhost();
|
|
3191
3855
|
} else {
|
|
3856
|
+
this.isSuggestionDismissed = false;
|
|
3192
3857
|
this.updateSuggestion();
|
|
3193
3858
|
}
|
|
3194
3859
|
}
|
|
3195
3860
|
bindEvents() {
|
|
3196
3861
|
this.handleInput = this.handleInput.bind(this);
|
|
3197
3862
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
3863
|
+
this.handlePaste = this.handlePaste.bind(this);
|
|
3198
3864
|
this.handleBlur = this.handleBlur.bind(this);
|
|
3199
3865
|
this.handleFocus = this.handleFocus.bind(this);
|
|
3200
3866
|
this.onCutHandler = () => {
|
|
@@ -3203,13 +3869,14 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3203
3869
|
}
|
|
3204
3870
|
this.cutTimerId = window.setTimeout(() => {
|
|
3205
3871
|
this.cutTimerId = null;
|
|
3206
|
-
if (this.isDestroyed || this.options.disabled || this.
|
|
3872
|
+
if (this.isDestroyed || this.options.disabled || this.isSensitiveField()) return;
|
|
3207
3873
|
this.updateSuggestion();
|
|
3208
3874
|
}, 0);
|
|
3209
3875
|
};
|
|
3210
3876
|
const { signal } = this.abortController;
|
|
3211
3877
|
this.input.addEventListener("input", this.handleInput, { signal });
|
|
3212
3878
|
this.input.addEventListener("keydown", this.handleKeyDown, { signal });
|
|
3879
|
+
this.input.addEventListener("paste", this.handlePaste, { signal });
|
|
3213
3880
|
this.input.addEventListener("blur", this.handleBlur, { signal });
|
|
3214
3881
|
this.input.addEventListener("focus", this.handleFocus, { signal });
|
|
3215
3882
|
this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
|
|
@@ -3219,7 +3886,7 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3219
3886
|
}, { signal });
|
|
3220
3887
|
this.input.addEventListener("compositionend", () => {
|
|
3221
3888
|
this.isComposing = false;
|
|
3222
|
-
if (!this.isDestroyed && !this.options.disabled && !this.
|
|
3889
|
+
if (!this.isDestroyed && !this.options.disabled && !this.isSensitiveField()) {
|
|
3223
3890
|
this.handleInput();
|
|
3224
3891
|
}
|
|
3225
3892
|
}, { signal });
|
|
@@ -3230,7 +3897,7 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3230
3897
|
}
|
|
3231
3898
|
this.resetTimerId = window.setTimeout(() => {
|
|
3232
3899
|
this.resetTimerId = null;
|
|
3233
|
-
if (this.isDestroyed || this.options.disabled || this.
|
|
3900
|
+
if (this.isDestroyed || this.options.disabled || this.isSensitiveField()) return;
|
|
3234
3901
|
this.updateSuggestion();
|
|
3235
3902
|
}, 0);
|
|
3236
3903
|
};
|
|
@@ -3256,7 +3923,7 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3256
3923
|
clearTimeout(this.srAnnounceTimerId);
|
|
3257
3924
|
this.srAnnounceTimerId = null;
|
|
3258
3925
|
}
|
|
3259
|
-
if (!this.options.setAriaAutocomplete || !this.isFocused || this.isDestroyed || this.
|
|
3926
|
+
if (!this.options.setAriaAutocomplete || !this.isFocused || this.isDestroyed || this.isSensitiveField()) {
|
|
3260
3927
|
return;
|
|
3261
3928
|
}
|
|
3262
3929
|
const suggestion = this.currentSuggestion;
|
|
@@ -3273,7 +3940,7 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3273
3940
|
}
|
|
3274
3941
|
const run = () => {
|
|
3275
3942
|
this.srAnnounceTimerId = null;
|
|
3276
|
-
if (this.isDestroyed || !this.isFocused || this.
|
|
3943
|
+
if (this.isDestroyed || !this.isFocused || this.isSensitiveField()) return;
|
|
3277
3944
|
this.lastAnnouncedSuggestion = textToAnnounce;
|
|
3278
3945
|
const doc = this.input.ownerDocument || (typeof document !== "undefined" ? document : null);
|
|
3279
3946
|
const docWithAriaNotify = doc;
|
|
@@ -3296,13 +3963,13 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3296
3963
|
}
|
|
3297
3964
|
}
|
|
3298
3965
|
updateSuggestion(announceOptions) {
|
|
3299
|
-
if (this.options.disabled || this.
|
|
3966
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
3300
3967
|
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
3301
3968
|
this.clearGhost();
|
|
3302
3969
|
return;
|
|
3303
3970
|
}
|
|
3304
3971
|
const val = this.input.value;
|
|
3305
|
-
this.currentSuggestion = this.engine.getSuggestion(val, this.currentSuggestionIndex);
|
|
3972
|
+
this.currentSuggestion = this.isSuggestionDismissed ? { full: val, remaining: "", matchedDomain: null } : this.engine.getSuggestion(val, this.currentSuggestionIndex);
|
|
3306
3973
|
if (!this.ghost) return;
|
|
3307
3974
|
if (this.shouldHideGhostForPlaceholder(val.length === 0)) {
|
|
3308
3975
|
this.clearGhost();
|
|
@@ -3322,19 +3989,39 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3322
3989
|
if (announceOptions?.announce) {
|
|
3323
3990
|
this.scheduleSuggestionAnnouncement(Boolean(announceOptions.immediate));
|
|
3324
3991
|
}
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3992
|
+
this.notifyValueChange();
|
|
3993
|
+
}
|
|
3994
|
+
notifyValueChange() {
|
|
3995
|
+
if (this.isNotifying) {
|
|
3996
|
+
this.hasPendingNotification = true;
|
|
3997
|
+
return;
|
|
3328
3998
|
}
|
|
3329
|
-
this.
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3999
|
+
this.isNotifying = true;
|
|
4000
|
+
try {
|
|
4001
|
+
let iterations = 0;
|
|
4002
|
+
do {
|
|
4003
|
+
iterations++;
|
|
4004
|
+
this.hasPendingNotification = false;
|
|
4005
|
+
const sensitiveNow = this.isSensitiveField();
|
|
4006
|
+
const allowBubble = !sensitiveNow;
|
|
4007
|
+
const valNow = this.input.value;
|
|
4008
|
+
const detail = this.getDetail();
|
|
4009
|
+
if (this.options.onInput) {
|
|
4010
|
+
this.options.onInput(detail);
|
|
4011
|
+
}
|
|
4012
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: allowBubble, detail }));
|
|
4013
|
+
if (valNow !== this.lastNotifiedValue) {
|
|
4014
|
+
this.lastNotifiedValue = sensitiveNow ? "" : valNow;
|
|
4015
|
+
this.dispatchNativeInput();
|
|
4016
|
+
}
|
|
4017
|
+
} while (this.hasPendingNotification && iterations < MAX_NOTIFICATION_ITERATIONS2);
|
|
4018
|
+
} finally {
|
|
4019
|
+
this.isNotifying = false;
|
|
3333
4020
|
}
|
|
3334
4021
|
}
|
|
3335
4022
|
handleInput(e) {
|
|
3336
4023
|
if (this.isDispatchingNativeInput) return;
|
|
3337
|
-
if (this.options.disabled || this.
|
|
4024
|
+
if (this.options.disabled || this.isSensitiveField()) return;
|
|
3338
4025
|
if (this.isComposing || e && "isComposing" in e && e.isComposing) return;
|
|
3339
4026
|
if (this.options.autoLowercase) {
|
|
3340
4027
|
const start = this.input.selectionStart ?? 0;
|
|
@@ -3345,16 +4032,60 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3345
4032
|
this.input.setSelectionRange(start, end);
|
|
3346
4033
|
}
|
|
3347
4034
|
}
|
|
4035
|
+
this.isSuggestionDismissed = false;
|
|
3348
4036
|
this.currentSuggestionIndex = 0;
|
|
3349
4037
|
this.updateSuggestion({ announce: true, immediate: false });
|
|
3350
4038
|
}
|
|
4039
|
+
handlePaste(e) {
|
|
4040
|
+
if (this.options.disabled || this.isSensitiveField()) return;
|
|
4041
|
+
const raw = this.getClipboardPlainText(e);
|
|
4042
|
+
const prepared = this.preparePastedText(raw, 512);
|
|
4043
|
+
if (prepared === raw) {
|
|
4044
|
+
return;
|
|
4045
|
+
}
|
|
4046
|
+
e.preventDefault();
|
|
4047
|
+
const start = this.input.selectionStart ?? this.input.value.length;
|
|
4048
|
+
const end = this.input.selectionEnd ?? start;
|
|
4049
|
+
const before = this.input.value.slice(0, start);
|
|
4050
|
+
const after = this.input.value.slice(end);
|
|
4051
|
+
const expected = before + prepared + after;
|
|
4052
|
+
const finalExpected = this.options.autoLowercase ? expected.toLowerCase() : expected;
|
|
4053
|
+
if (typeof document !== "undefined" && getDeepActiveElement(this.input.ownerDocument) === this.input && typeof document.execCommand === "function") {
|
|
4054
|
+
try {
|
|
4055
|
+
const execOk = document.execCommand("insertText", false, prepared);
|
|
4056
|
+
if (execOk && this.input.value === finalExpected) {
|
|
4057
|
+
return;
|
|
4058
|
+
}
|
|
4059
|
+
} catch {
|
|
4060
|
+
}
|
|
4061
|
+
}
|
|
4062
|
+
this.setNativeValue(expected);
|
|
4063
|
+
const nextCursor = start + prepared.length;
|
|
4064
|
+
this.input.setSelectionRange(nextCursor, nextCursor);
|
|
4065
|
+
this.handleInput();
|
|
4066
|
+
}
|
|
3351
4067
|
handleKeyDown(e) {
|
|
3352
|
-
if (this.options.disabled || this.
|
|
4068
|
+
if (this.options.disabled || this.isSensitiveField() || isImeComposing(e)) return;
|
|
3353
4069
|
if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return;
|
|
3354
4070
|
const hasSuggestion = Boolean(this.currentSuggestion.remaining) && !this.currentSuggestion.isHintOnly;
|
|
3355
4071
|
const cursor = this.input.selectionStart ?? 0;
|
|
3356
4072
|
const isAtEnd = cursor === this.input.value.length;
|
|
3357
4073
|
const isNotEmpty = this.input.value.length > 0;
|
|
4074
|
+
if (e.key === "Escape" && hasSuggestion) {
|
|
4075
|
+
e.preventDefault();
|
|
4076
|
+
this.isSuggestionDismissed = true;
|
|
4077
|
+
this.currentSuggestion = { full: this.input.value, remaining: "", matchedDomain: null };
|
|
4078
|
+
if (this.srAnnounceTimerId !== null) {
|
|
4079
|
+
clearTimeout(this.srAnnounceTimerId);
|
|
4080
|
+
this.srAnnounceTimerId = null;
|
|
4081
|
+
}
|
|
4082
|
+
this.lastAnnouncedSuggestion = "";
|
|
4083
|
+
if (this.srStatusEl) {
|
|
4084
|
+
this.srStatusEl.textContent = "";
|
|
4085
|
+
}
|
|
4086
|
+
this.clearGhost();
|
|
4087
|
+
return;
|
|
4088
|
+
}
|
|
3358
4089
|
if (this.options.cycleSuggestions && hasSuggestion && isNotEmpty && isAtEnd) {
|
|
3359
4090
|
if (e.key === "ArrowDown") {
|
|
3360
4091
|
e.preventDefault();
|
|
@@ -3362,161 +4093,2072 @@ var InputEmailMask = class extends BaseInputMask {
|
|
|
3362
4093
|
this.updateSuggestion({ announce: true, immediate: true });
|
|
3363
4094
|
return;
|
|
3364
4095
|
}
|
|
3365
|
-
if (e.key === "ArrowUp") {
|
|
3366
|
-
e.preventDefault();
|
|
3367
|
-
this.currentSuggestionIndex--;
|
|
3368
|
-
this.updateSuggestion({ announce: true, immediate: true });
|
|
4096
|
+
if (e.key === "ArrowUp") {
|
|
4097
|
+
e.preventDefault();
|
|
4098
|
+
this.currentSuggestionIndex--;
|
|
4099
|
+
this.updateSuggestion({ announce: true, immediate: true });
|
|
4100
|
+
return;
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
if (e.key === "Tab" && hasSuggestion && isNotEmpty && this.options.completeOnTab) {
|
|
4104
|
+
e.preventDefault();
|
|
4105
|
+
this.acceptSuggestion();
|
|
4106
|
+
return;
|
|
4107
|
+
}
|
|
4108
|
+
if (e.key === "Enter" && hasSuggestion && isNotEmpty && this.options.completeOnEnter) {
|
|
4109
|
+
e.preventDefault();
|
|
4110
|
+
this.acceptSuggestion();
|
|
4111
|
+
return;
|
|
4112
|
+
}
|
|
4113
|
+
if (e.key === "ArrowRight" && hasSuggestion && isNotEmpty && isAtEnd && this.options.completeOnArrowRight) {
|
|
4114
|
+
e.preventDefault();
|
|
4115
|
+
this.acceptSuggestion();
|
|
4116
|
+
return;
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
/**
|
|
4120
|
+
* Valide et applique la suggestion courante dans le champ natif.
|
|
4121
|
+
*/
|
|
4122
|
+
acceptSuggestion() {
|
|
4123
|
+
if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.isSensitiveField() || this.input.value.length === 0) {
|
|
4124
|
+
return false;
|
|
4125
|
+
}
|
|
4126
|
+
const completed = this.currentSuggestion.full;
|
|
4127
|
+
this.setNativeValue(completed);
|
|
4128
|
+
this.input.setSelectionRange(completed.length, completed.length);
|
|
4129
|
+
this.currentSuggestionIndex = 0;
|
|
4130
|
+
this.updateSuggestion();
|
|
4131
|
+
const detail = this.getDetail();
|
|
4132
|
+
if (this.options.onChange) {
|
|
4133
|
+
this.options.onChange(detail);
|
|
4134
|
+
}
|
|
4135
|
+
const allowBubble = !this.isSensitiveField();
|
|
4136
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
4137
|
+
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles: allowBubble, detail }));
|
|
4138
|
+
return true;
|
|
4139
|
+
}
|
|
4140
|
+
/**
|
|
4141
|
+
* Modifie dynamiquement le domaine suggéré par défaut.
|
|
4142
|
+
*/
|
|
4143
|
+
setDefaultDomain(domain) {
|
|
4144
|
+
this.engine.setDefaultDomain(domain);
|
|
4145
|
+
this.updateSuggestion();
|
|
4146
|
+
}
|
|
4147
|
+
/**
|
|
4148
|
+
* Modifie dynamiquement l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
|
|
4149
|
+
*/
|
|
4150
|
+
setDefaultTld(tld) {
|
|
4151
|
+
this.engine.setDefaultTld(tld);
|
|
4152
|
+
this.updateSuggestion();
|
|
4153
|
+
}
|
|
4154
|
+
/**
|
|
4155
|
+
* Modifie dynamiquement la liste des extensions (TLD) connues.
|
|
4156
|
+
*/
|
|
4157
|
+
setTlds(tlds) {
|
|
4158
|
+
this.engine.setTlds(tlds);
|
|
4159
|
+
this.currentSuggestionIndex = 0;
|
|
4160
|
+
this.updateSuggestion();
|
|
4161
|
+
}
|
|
4162
|
+
handleFocus() {
|
|
4163
|
+
this.wrapper.classList.add("is-focused");
|
|
4164
|
+
this.isSuggestionDismissed = false;
|
|
4165
|
+
this.syncGhostStyles();
|
|
4166
|
+
this.updateSuggestion();
|
|
4167
|
+
}
|
|
4168
|
+
handleBlur() {
|
|
4169
|
+
this.wrapper.classList.remove("is-focused");
|
|
4170
|
+
if (this.srAnnounceTimerId !== null) {
|
|
4171
|
+
clearTimeout(this.srAnnounceTimerId);
|
|
4172
|
+
this.srAnnounceTimerId = null;
|
|
4173
|
+
}
|
|
4174
|
+
this.lastAnnouncedSuggestion = "";
|
|
4175
|
+
if (this.srStatusEl) {
|
|
4176
|
+
this.srStatusEl.textContent = "";
|
|
4177
|
+
}
|
|
4178
|
+
if (this.isSensitiveField()) {
|
|
4179
|
+
this.lastNotifiedValue = "";
|
|
4180
|
+
this.lastTrackedValue = "";
|
|
4181
|
+
this.clearGhost();
|
|
4182
|
+
return;
|
|
4183
|
+
}
|
|
4184
|
+
this.updateSuggestion();
|
|
4185
|
+
const detail = this.getDetail();
|
|
4186
|
+
if (this.options.onChange) {
|
|
4187
|
+
this.options.onChange(detail);
|
|
4188
|
+
}
|
|
4189
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: !this.isSensitiveField(), detail }));
|
|
4190
|
+
}
|
|
4191
|
+
handleAttributeMutation(attrName) {
|
|
4192
|
+
super.handleAttributeMutation(attrName);
|
|
4193
|
+
if (attrName === "data-mask-cycle-suggestions") {
|
|
4194
|
+
this.options.cycleSuggestions = this.getAttr("data-mask-cycle-suggestions") === "true";
|
|
4195
|
+
} else if (attrName === "data-mask-auto-lowercase") {
|
|
4196
|
+
this.options.autoLowercase = this.getAttr("data-mask-auto-lowercase") === "true";
|
|
4197
|
+
} else if (attrName === "data-mask-default-tld") {
|
|
4198
|
+
const val = this.getAttr("data-mask-default-tld");
|
|
4199
|
+
this.setDefaultTld(val === null || val === "false" || val === "none" ? null : val === "true" ? true : val);
|
|
4200
|
+
} else if (attrName === "data-mask-tlds") {
|
|
4201
|
+
const val = this.getAttr("data-mask-tlds");
|
|
4202
|
+
this.setTlds(val ? val.split(",").map((s) => s.trim()).filter(Boolean) : null);
|
|
4203
|
+
} else if (attrName === "placeholder") {
|
|
4204
|
+
this.updateSuggestion();
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
getDetail() {
|
|
4208
|
+
return {
|
|
4209
|
+
value: this.input.value,
|
|
4210
|
+
suggestedValue: this.currentSuggestion.isHintOnly ? "" : this.currentSuggestion.full,
|
|
4211
|
+
domain: this.currentSuggestion.matchedDomain
|
|
4212
|
+
};
|
|
4213
|
+
}
|
|
4214
|
+
setValue(val) {
|
|
4215
|
+
const str = val !== null && val !== void 0 ? String(val) : "";
|
|
4216
|
+
this.isSuggestionDismissed = false;
|
|
4217
|
+
this.setNativeValue(str);
|
|
4218
|
+
this.updateSuggestion();
|
|
4219
|
+
}
|
|
4220
|
+
destroy() {
|
|
4221
|
+
if (this.isDestroyed) return;
|
|
4222
|
+
if (this.cutTimerId !== null) {
|
|
4223
|
+
clearTimeout(this.cutTimerId);
|
|
4224
|
+
this.cutTimerId = null;
|
|
4225
|
+
}
|
|
4226
|
+
if (this.resetTimerId !== null) {
|
|
4227
|
+
clearTimeout(this.resetTimerId);
|
|
4228
|
+
this.resetTimerId = null;
|
|
4229
|
+
}
|
|
4230
|
+
if (this.srAnnounceTimerId !== null) {
|
|
4231
|
+
clearTimeout(this.srAnnounceTimerId);
|
|
4232
|
+
this.srAnnounceTimerId = null;
|
|
4233
|
+
}
|
|
4234
|
+
if (this.srStatusEl) {
|
|
4235
|
+
this.srStatusEl.remove();
|
|
4236
|
+
this.srStatusEl = null;
|
|
4237
|
+
}
|
|
4238
|
+
this.lastNotifiedValue = "";
|
|
4239
|
+
this.lastAnnouncedSuggestion = "";
|
|
4240
|
+
if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "email") {
|
|
4241
|
+
this.input.removeAttribute("inputmode");
|
|
4242
|
+
}
|
|
4243
|
+
if (this.wasAriaAutocompleteSet && this.input.getAttribute("aria-autocomplete") === "inline") {
|
|
4244
|
+
this.input.removeAttribute("aria-autocomplete");
|
|
4245
|
+
}
|
|
4246
|
+
if (this.wasAutocorrectSet && this.input.getAttribute("autocorrect") === "off") {
|
|
4247
|
+
this.input.removeAttribute("autocorrect");
|
|
4248
|
+
}
|
|
4249
|
+
if (this.wasAutocapitalizeSet && this.input.getAttribute("autocapitalize") === "none") {
|
|
4250
|
+
this.input.removeAttribute("autocapitalize");
|
|
4251
|
+
}
|
|
4252
|
+
if (this.wasSpellcheckSet && this.input.getAttribute("spellcheck") === "false") {
|
|
4253
|
+
this.input.removeAttribute("spellcheck");
|
|
4254
|
+
}
|
|
4255
|
+
super.destroy();
|
|
4256
|
+
}
|
|
4257
|
+
};
|
|
4258
|
+
|
|
4259
|
+
// src/mask/DateUTCEngine.ts
|
|
4260
|
+
var DATE_UTC_PRESETS = {
|
|
4261
|
+
iso: { format: "YYYY-MM-DD HH:mm:ss" },
|
|
4262
|
+
"iso-t": { format: "YYYY-MM-DD\\THH:mm:ss" },
|
|
4263
|
+
fr: {
|
|
4264
|
+
format: "DD/MM/YYYY HH:mm",
|
|
4265
|
+
placeholderTokens: { DD: "jj", MM: "mm", YYYY: "aaaa", HH: "hh", mm: "mm" }
|
|
4266
|
+
},
|
|
4267
|
+
"fr-sec": {
|
|
4268
|
+
format: "DD/MM/YYYY HH:mm:ss",
|
|
4269
|
+
placeholderTokens: { DD: "jj", MM: "mm", YYYY: "aaaa", HH: "hh", mm: "mm", ss: "ss" }
|
|
4270
|
+
},
|
|
4271
|
+
us: { format: "MM/DD/YYYY HH:mm" },
|
|
4272
|
+
"us-12h": { format: "MM/DD/YYYY hh:mm A" },
|
|
4273
|
+
uk: { format: "DD/MM/YYYY HH:mm" },
|
|
4274
|
+
no: { format: "DD/MM-YYYY HH:mm" },
|
|
4275
|
+
cz: { format: "DD. MM. YYYY HH:mm" },
|
|
4276
|
+
de: { format: "DD.MM.YYYY HH:mm" },
|
|
4277
|
+
jp: { format: "YYYY/MM/DD HH:mm" }
|
|
4278
|
+
};
|
|
4279
|
+
var DEFAULT_PLACEHOLDERS = {
|
|
4280
|
+
YYYY: "YYYY",
|
|
4281
|
+
MM: "MM",
|
|
4282
|
+
DD: "DD",
|
|
4283
|
+
HH: "HH",
|
|
4284
|
+
hh: "hh",
|
|
4285
|
+
mm: "mm",
|
|
4286
|
+
ss: "ss",
|
|
4287
|
+
A: "AM"
|
|
4288
|
+
};
|
|
4289
|
+
var TOKEN_DEFS = [
|
|
4290
|
+
{ token: "YYYY", length: 4 },
|
|
4291
|
+
{ token: "MM", length: 2 },
|
|
4292
|
+
{ token: "DD", length: 2 },
|
|
4293
|
+
{ token: "HH", length: 2 },
|
|
4294
|
+
{ token: "hh", length: 2 },
|
|
4295
|
+
{ token: "mm", length: 2 },
|
|
4296
|
+
{ token: "ss", length: 2 },
|
|
4297
|
+
{ token: "A", length: 2 }
|
|
4298
|
+
];
|
|
4299
|
+
var MAX_FORMAT_LENGTH = 128;
|
|
4300
|
+
var MAX_INPUT_LENGTH = 512;
|
|
4301
|
+
var DATE_SEPARATORS = /* @__PURE__ */ new Set(["/", "-", ".", ":", " ", "T", "t"]);
|
|
4302
|
+
var TIME_TOKEN_KINDS = /* @__PURE__ */ new Set(["HH", "hh", "mm", "ss", "A"]);
|
|
4303
|
+
function isAsciiDigit(ch) {
|
|
4304
|
+
return ch >= "0" && ch <= "9";
|
|
4305
|
+
}
|
|
4306
|
+
function parseAsciiInt(str) {
|
|
4307
|
+
let val = 0;
|
|
4308
|
+
for (let i = 0; i < str.length; i++) {
|
|
4309
|
+
const code = str.charCodeAt(i);
|
|
4310
|
+
if (code < 48 || code > 57) return NaN;
|
|
4311
|
+
val = val * 10 + (code - 48);
|
|
4312
|
+
}
|
|
4313
|
+
return str.length > 0 ? val : NaN;
|
|
4314
|
+
}
|
|
4315
|
+
function normalizeSegmentPlaceholder(raw, length, fallback) {
|
|
4316
|
+
const graphemes = Array.from(raw || fallback);
|
|
4317
|
+
const fb = Array.from(fallback);
|
|
4318
|
+
while (graphemes.length < length) {
|
|
4319
|
+
graphemes.push(fb[graphemes.length] || fb[fb.length - 1] || "_");
|
|
4320
|
+
}
|
|
4321
|
+
return graphemes.slice(0, length).join("");
|
|
4322
|
+
}
|
|
4323
|
+
var DateUTCEngine = class _DateUTCEngine {
|
|
4324
|
+
formatSpec = "YYYY-MM-DD HH:mm";
|
|
4325
|
+
customPlaceholders = {};
|
|
4326
|
+
slots = [];
|
|
4327
|
+
segments = [];
|
|
4328
|
+
fullTemplate = "";
|
|
4329
|
+
prefixSlotsCount = 0;
|
|
4330
|
+
prefixString = "";
|
|
4331
|
+
editableCount = 0;
|
|
4332
|
+
hasMeridiemFlag = false;
|
|
4333
|
+
utcIndicator = " UTC";
|
|
4334
|
+
includeMilliseconds = false;
|
|
4335
|
+
convertPastedOffset = true;
|
|
4336
|
+
defaultTimeOnDateOnly = false;
|
|
4337
|
+
minTs = null;
|
|
4338
|
+
maxTs = null;
|
|
4339
|
+
constructor(options = {}) {
|
|
4340
|
+
this.updateOptions(options);
|
|
4341
|
+
}
|
|
4342
|
+
/**
|
|
4343
|
+
* Formate statiquement une date (Date, timestamp ms, ISO ou chaîne) selon les options données.
|
|
4344
|
+
*/
|
|
4345
|
+
static format(value, options = {}) {
|
|
4346
|
+
const engine = new _DateUTCEngine(options);
|
|
4347
|
+
return engine.formatFromValue(value);
|
|
4348
|
+
}
|
|
4349
|
+
updateOptions(options = {}) {
|
|
4350
|
+
if (options.utcIndicator !== void 0) {
|
|
4351
|
+
this.utcIndicator = options.utcIndicator === false ? false : String(options.utcIndicator).slice(0, 32);
|
|
4352
|
+
}
|
|
4353
|
+
if (options.includeMilliseconds !== void 0) {
|
|
4354
|
+
this.includeMilliseconds = Boolean(options.includeMilliseconds);
|
|
4355
|
+
}
|
|
4356
|
+
if (options.convertPastedOffset !== void 0) {
|
|
4357
|
+
this.convertPastedOffset = options.convertPastedOffset !== false;
|
|
4358
|
+
}
|
|
4359
|
+
if (options.defaultTimeOnDateOnly !== void 0) {
|
|
4360
|
+
this.defaultTimeOnDateOnly = options.defaultTimeOnDateOnly;
|
|
4361
|
+
}
|
|
4362
|
+
if (options.min !== void 0) {
|
|
4363
|
+
this.minTs = this.normalizeBoundary(options.min);
|
|
4364
|
+
}
|
|
4365
|
+
if (options.max !== void 0) {
|
|
4366
|
+
this.maxTs = this.normalizeBoundary(options.max);
|
|
4367
|
+
}
|
|
4368
|
+
if (options.placeholderTokens !== void 0) {
|
|
4369
|
+
this.customPlaceholders = options.placeholderTokens || {};
|
|
4370
|
+
}
|
|
4371
|
+
if (options.format !== void 0 || this.slots.length === 0) {
|
|
4372
|
+
this.compile(options.format ?? this.formatSpec, options.placeholderTokens);
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
setFormat(format, placeholderTokens) {
|
|
4376
|
+
if (placeholderTokens !== void 0) {
|
|
4377
|
+
this.customPlaceholders = placeholderTokens;
|
|
4378
|
+
}
|
|
4379
|
+
this.compile(format, this.customPlaceholders);
|
|
4380
|
+
}
|
|
4381
|
+
setUtcIndicator(indicator) {
|
|
4382
|
+
this.utcIndicator = indicator === false ? false : String(indicator).slice(0, 32);
|
|
4383
|
+
}
|
|
4384
|
+
getUtcIndicator() {
|
|
4385
|
+
return this.utcIndicator;
|
|
4386
|
+
}
|
|
4387
|
+
getFormat() {
|
|
4388
|
+
return this.formatSpec;
|
|
4389
|
+
}
|
|
4390
|
+
getFullTemplate() {
|
|
4391
|
+
return this.fullTemplate;
|
|
4392
|
+
}
|
|
4393
|
+
getGhostRemaining(formatted) {
|
|
4394
|
+
const suffix = this.utcIndicator ? this.utcIndicator : "";
|
|
4395
|
+
if (formatted.length >= this.fullTemplate.length) {
|
|
4396
|
+
return suffix;
|
|
4397
|
+
}
|
|
4398
|
+
return this.fullTemplate.slice(formatted.length) + suffix;
|
|
4399
|
+
}
|
|
4400
|
+
getPrefix() {
|
|
4401
|
+
return this.prefixString;
|
|
4402
|
+
}
|
|
4403
|
+
getPrefixLength() {
|
|
4404
|
+
return this.prefixSlotsCount;
|
|
4405
|
+
}
|
|
4406
|
+
getEditableCount() {
|
|
4407
|
+
return this.editableCount;
|
|
4408
|
+
}
|
|
4409
|
+
hasMeridiem() {
|
|
4410
|
+
return this.hasMeridiemFlag;
|
|
4411
|
+
}
|
|
4412
|
+
isNumericOnly() {
|
|
4413
|
+
return !this.hasMeridiemFlag;
|
|
4414
|
+
}
|
|
4415
|
+
getSegments() {
|
|
4416
|
+
return this.segments;
|
|
4417
|
+
}
|
|
4418
|
+
getSlots() {
|
|
4419
|
+
return this.slots;
|
|
4420
|
+
}
|
|
4421
|
+
isSeparatorAt(idx) {
|
|
4422
|
+
return idx >= 0 && idx < this.slots.length && this.slots[idx].isStatic;
|
|
4423
|
+
}
|
|
4424
|
+
getNextEditablePosition(fromIdx) {
|
|
4425
|
+
const start = Math.max(0, fromIdx);
|
|
4426
|
+
for (let i = start; i < this.slots.length; i++) {
|
|
4427
|
+
if (!this.slots[i].isStatic) return i;
|
|
4428
|
+
}
|
|
4429
|
+
return this.slots.length;
|
|
4430
|
+
}
|
|
4431
|
+
compile(format, overridePlaceholders) {
|
|
4432
|
+
const rawSpec = String(format || "YYYY-MM-DD HH:mm").trim().slice(0, MAX_FORMAT_LENGTH) || "YYYY-MM-DD HH:mm";
|
|
4433
|
+
this.formatSpec = rawSpec;
|
|
4434
|
+
const preset = Object.hasOwn(DATE_UTC_PRESETS, rawSpec) ? DATE_UTC_PRESETS[rawSpec] : null;
|
|
4435
|
+
const pattern = preset ? preset.format : rawSpec;
|
|
4436
|
+
const mergedPlaceholders = /* @__PURE__ */ Object.create(null);
|
|
4437
|
+
if (preset?.placeholderTokens) {
|
|
4438
|
+
for (const [k, v] of Object.entries(preset.placeholderTokens)) {
|
|
4439
|
+
if (Object.hasOwn(DEFAULT_PLACEHOLDERS, k) && typeof v === "string") {
|
|
4440
|
+
mergedPlaceholders[k] = v;
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
const sourceOverrides = overridePlaceholders !== void 0 ? overridePlaceholders : this.customPlaceholders;
|
|
4445
|
+
if (sourceOverrides && typeof sourceOverrides === "object") {
|
|
4446
|
+
for (const [k, v] of Object.entries(sourceOverrides)) {
|
|
4447
|
+
if (Object.hasOwn(DEFAULT_PLACEHOLDERS, k) && typeof v === "string") {
|
|
4448
|
+
mergedPlaceholders[k] = v;
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
this.slots = [];
|
|
4453
|
+
this.segments = [];
|
|
4454
|
+
this.hasMeridiemFlag = false;
|
|
4455
|
+
let template = "";
|
|
4456
|
+
let isPrefixMode = true;
|
|
4457
|
+
let i = 0;
|
|
4458
|
+
while (i < pattern.length) {
|
|
4459
|
+
const ch = pattern[i];
|
|
4460
|
+
if (ch === "\\" && i + 1 < pattern.length) {
|
|
4461
|
+
const lit = pattern[i + 1];
|
|
4462
|
+
this.slots.push({
|
|
4463
|
+
char: lit,
|
|
4464
|
+
isStatic: true,
|
|
4465
|
+
isPrefix: isPrefixMode,
|
|
4466
|
+
segmentIndex: -1,
|
|
4467
|
+
charIndexInSegment: -1,
|
|
4468
|
+
placeholder: lit
|
|
4469
|
+
});
|
|
4470
|
+
template += lit;
|
|
4471
|
+
i += 2;
|
|
4472
|
+
continue;
|
|
4473
|
+
}
|
|
4474
|
+
let matchedToken = null;
|
|
4475
|
+
for (const def of TOKEN_DEFS) {
|
|
4476
|
+
if (pattern.startsWith(def.token, i)) {
|
|
4477
|
+
matchedToken = def;
|
|
4478
|
+
break;
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
4481
|
+
if (matchedToken) {
|
|
4482
|
+
isPrefixMode = false;
|
|
4483
|
+
const { token, length } = matchedToken;
|
|
4484
|
+
if (token === "A") {
|
|
4485
|
+
this.hasMeridiemFlag = true;
|
|
4486
|
+
}
|
|
4487
|
+
const phRaw = mergedPlaceholders[token] ?? DEFAULT_PLACEHOLDERS[token];
|
|
4488
|
+
const ph = normalizeSegmentPlaceholder(phRaw, length, DEFAULT_PLACEHOLDERS[token]);
|
|
4489
|
+
const phChars = Array.from(ph);
|
|
4490
|
+
const segIdx = this.segments.length;
|
|
4491
|
+
const start = this.slots.length;
|
|
4492
|
+
for (let k = 0; k < length; k++) {
|
|
4493
|
+
this.slots.push({
|
|
4494
|
+
char: token === "A" ? "A" : "9",
|
|
4495
|
+
isStatic: false,
|
|
4496
|
+
isPrefix: false,
|
|
4497
|
+
segmentIndex: segIdx,
|
|
4498
|
+
charIndexInSegment: k,
|
|
4499
|
+
tokenKind: token,
|
|
4500
|
+
placeholder: phChars[k] || "_"
|
|
4501
|
+
});
|
|
4502
|
+
}
|
|
4503
|
+
this.segments.push({
|
|
4504
|
+
kind: token,
|
|
4505
|
+
start,
|
|
4506
|
+
end: start + length,
|
|
4507
|
+
length,
|
|
4508
|
+
placeholder: ph,
|
|
4509
|
+
followingSeparator: ""
|
|
4510
|
+
});
|
|
4511
|
+
template += ph;
|
|
4512
|
+
i += token.length;
|
|
4513
|
+
} else {
|
|
4514
|
+
this.slots.push({
|
|
4515
|
+
char: ch,
|
|
4516
|
+
isStatic: true,
|
|
4517
|
+
isPrefix: isPrefixMode,
|
|
4518
|
+
segmentIndex: -1,
|
|
4519
|
+
charIndexInSegment: -1,
|
|
4520
|
+
placeholder: ch
|
|
4521
|
+
});
|
|
4522
|
+
template += ch;
|
|
4523
|
+
i++;
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
this.fullTemplate = template;
|
|
4527
|
+
this.editableCount = this.slots.filter((s) => !s.isStatic).length;
|
|
4528
|
+
this.prefixSlotsCount = 0;
|
|
4529
|
+
this.prefixString = "";
|
|
4530
|
+
for (const slot of this.slots) {
|
|
4531
|
+
if (slot.isPrefix) {
|
|
4532
|
+
this.prefixSlotsCount++;
|
|
4533
|
+
this.prefixString += slot.char;
|
|
4534
|
+
} else {
|
|
4535
|
+
break;
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
for (let s = 0; s < this.segments.length; s++) {
|
|
4539
|
+
const seg = this.segments[s];
|
|
4540
|
+
let sep = "";
|
|
4541
|
+
for (let pos = seg.end; pos < this.slots.length && this.slots[pos].isStatic; pos++) {
|
|
4542
|
+
sep += this.slots[pos].char;
|
|
4543
|
+
}
|
|
4544
|
+
seg.followingSeparator = sep;
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
/**
|
|
4548
|
+
* Extrait linéairement les caractères bruts valides alignés sur les slots.
|
|
4549
|
+
*/
|
|
4550
|
+
extractRaw(input, expandSingleMeridiem = false) {
|
|
4551
|
+
const str = String(input ?? "").slice(0, MAX_INPUT_LENGTH);
|
|
4552
|
+
if (!str || this.slots.length === 0) return "";
|
|
4553
|
+
let raw = "";
|
|
4554
|
+
let inputIdx = 0;
|
|
4555
|
+
let slotIdx = 0;
|
|
4556
|
+
if (this.prefixSlotsCount > 0) {
|
|
4557
|
+
while (inputIdx < str.length && (str[inputIdx] === " " || str[inputIdx] === " ")) {
|
|
4558
|
+
inputIdx++;
|
|
4559
|
+
}
|
|
4560
|
+
let pIdx = 0;
|
|
4561
|
+
while (inputIdx < str.length && pIdx < this.prefixSlotsCount) {
|
|
4562
|
+
const pChar = this.slots[pIdx].char;
|
|
4563
|
+
const inChar = str[inputIdx];
|
|
4564
|
+
if (inChar.toUpperCase() === pChar.toUpperCase()) {
|
|
4565
|
+
inputIdx++;
|
|
4566
|
+
pIdx++;
|
|
4567
|
+
} else if (pChar === " " && inChar !== " ") {
|
|
4568
|
+
pIdx++;
|
|
4569
|
+
} else {
|
|
4570
|
+
break;
|
|
4571
|
+
}
|
|
4572
|
+
}
|
|
4573
|
+
slotIdx = this.prefixSlotsCount;
|
|
4574
|
+
}
|
|
4575
|
+
while (inputIdx < str.length && slotIdx < this.slots.length) {
|
|
4576
|
+
const slot = this.slots[slotIdx];
|
|
4577
|
+
const ch = str[inputIdx];
|
|
4578
|
+
if (slot.isStatic) {
|
|
4579
|
+
if (ch.toUpperCase() === slot.char.toUpperCase()) {
|
|
4580
|
+
inputIdx++;
|
|
4581
|
+
slotIdx++;
|
|
4582
|
+
} else {
|
|
4583
|
+
slotIdx++;
|
|
4584
|
+
}
|
|
4585
|
+
continue;
|
|
4586
|
+
}
|
|
4587
|
+
if (slot.tokenKind === "A") {
|
|
4588
|
+
const upper = ch.toUpperCase();
|
|
4589
|
+
if (slot.charIndexInSegment === 0) {
|
|
4590
|
+
if (upper === "A" || upper === "P") {
|
|
4591
|
+
raw += upper;
|
|
4592
|
+
inputIdx++;
|
|
4593
|
+
slotIdx++;
|
|
4594
|
+
const nextCh = inputIdx < str.length ? str[inputIdx].toUpperCase() : "";
|
|
4595
|
+
if (nextCh === "M") {
|
|
4596
|
+
raw += "M";
|
|
4597
|
+
inputIdx++;
|
|
4598
|
+
slotIdx++;
|
|
4599
|
+
} else if (expandSingleMeridiem) {
|
|
4600
|
+
raw += "M";
|
|
4601
|
+
slotIdx++;
|
|
4602
|
+
}
|
|
4603
|
+
} else {
|
|
4604
|
+
inputIdx++;
|
|
4605
|
+
}
|
|
4606
|
+
} else {
|
|
4607
|
+
if (upper === "M") {
|
|
4608
|
+
raw += "M";
|
|
4609
|
+
inputIdx++;
|
|
4610
|
+
slotIdx++;
|
|
4611
|
+
} else if (expandSingleMeridiem) {
|
|
4612
|
+
raw += "M";
|
|
4613
|
+
slotIdx++;
|
|
4614
|
+
} else {
|
|
4615
|
+
inputIdx++;
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
continue;
|
|
4619
|
+
}
|
|
4620
|
+
if (isAsciiDigit(ch)) {
|
|
4621
|
+
raw += ch;
|
|
4622
|
+
inputIdx++;
|
|
4623
|
+
slotIdx++;
|
|
4624
|
+
} else {
|
|
4625
|
+
inputIdx++;
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4628
|
+
return raw;
|
|
4629
|
+
}
|
|
4630
|
+
/**
|
|
4631
|
+
* Formate une saisie (brute ou partiellement formatée) selon le gabarit configuré.
|
|
4632
|
+
*/
|
|
4633
|
+
format(input, expandSingleMeridiem = false) {
|
|
4634
|
+
if (this.slots.length === 0) return String(input ?? "").slice(0, MAX_INPUT_LENGTH);
|
|
4635
|
+
const cleanRaw = this.extractRaw(input, expandSingleMeridiem);
|
|
4636
|
+
if (cleanRaw.length === 0) {
|
|
4637
|
+
return this.prefixString;
|
|
4638
|
+
}
|
|
4639
|
+
let formatted = "";
|
|
4640
|
+
let rawIdx = 0;
|
|
4641
|
+
for (let i = 0; i < this.slots.length; i++) {
|
|
4642
|
+
const slot = this.slots[i];
|
|
4643
|
+
if (slot.isStatic) {
|
|
4644
|
+
const hasRemainingRaw = rawIdx < cleanRaw.length;
|
|
4645
|
+
const isPrefix = rawIdx === 0 && slot.isPrefix;
|
|
4646
|
+
const isCompletedSegmentTrailingSep = rawIdx > 0 && rawIdx === cleanRaw.length;
|
|
4647
|
+
if (hasRemainingRaw || isPrefix || isCompletedSegmentTrailingSep) {
|
|
4648
|
+
formatted += slot.char;
|
|
4649
|
+
} else {
|
|
4650
|
+
break;
|
|
4651
|
+
}
|
|
4652
|
+
} else if (rawIdx < cleanRaw.length) {
|
|
4653
|
+
formatted += cleanRaw[rawIdx];
|
|
4654
|
+
rawIdx++;
|
|
4655
|
+
} else {
|
|
4656
|
+
break;
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4659
|
+
return formatted;
|
|
4660
|
+
}
|
|
4661
|
+
/**
|
|
4662
|
+
* Analyse complète de la saisie courante : formatage, complétude, validité calendaire UTC, Date & ISO.
|
|
4663
|
+
*/
|
|
4664
|
+
analyze(input, expandSingleMeridiem = false) {
|
|
4665
|
+
const cleanRaw = this.extractRaw(input, expandSingleMeridiem);
|
|
4666
|
+
const formatted = this.formatFromCleanRaw(cleanRaw);
|
|
4667
|
+
const totalSlots = this.editableCount;
|
|
4668
|
+
const filledSlots = cleanRaw.length;
|
|
4669
|
+
const isComplete = totalSlots > 0 && filledSlots >= totalSlots;
|
|
4670
|
+
const extracted = this.extractSegmentValues(cleanRaw);
|
|
4671
|
+
const parts = extracted.parts;
|
|
4672
|
+
let date = null;
|
|
4673
|
+
let isoString = null;
|
|
4674
|
+
let timestamp = null;
|
|
4675
|
+
let isValid = false;
|
|
4676
|
+
if (isComplete && extracted.allSegmentsPresent) {
|
|
4677
|
+
const resolvedHour = this.resolveHour24(extracted);
|
|
4678
|
+
if (resolvedHour !== null) {
|
|
4679
|
+
const candidate = {
|
|
4680
|
+
year: parts.year,
|
|
4681
|
+
month: parts.month,
|
|
4682
|
+
day: parts.day,
|
|
4683
|
+
hour: resolvedHour,
|
|
4684
|
+
minute: parts.minute ?? 0,
|
|
4685
|
+
second: parts.second ?? 0
|
|
4686
|
+
};
|
|
4687
|
+
const strictDate = this.buildStrictUTCDate(candidate);
|
|
4688
|
+
if (strictDate) {
|
|
4689
|
+
const ts = strictDate.getTime();
|
|
4690
|
+
const inMin = this.minTs === null || ts >= this.minTs;
|
|
4691
|
+
const inMax = this.maxTs === null || ts <= this.maxTs;
|
|
4692
|
+
if (inMin && inMax) {
|
|
4693
|
+
date = strictDate;
|
|
4694
|
+
timestamp = ts;
|
|
4695
|
+
isoString = this.formatDateToISO(strictDate);
|
|
4696
|
+
isValid = true;
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
}
|
|
4701
|
+
return {
|
|
4702
|
+
formatted,
|
|
4703
|
+
rawValue: isoString || "",
|
|
4704
|
+
isoString,
|
|
4705
|
+
date,
|
|
4706
|
+
timestamp,
|
|
4707
|
+
parts,
|
|
4708
|
+
isComplete,
|
|
4709
|
+
isValid,
|
|
4710
|
+
totalSlots,
|
|
4711
|
+
filledSlots
|
|
4712
|
+
};
|
|
4713
|
+
}
|
|
4714
|
+
/**
|
|
4715
|
+
* Calcule la nouvelle position du curseur en préservant le nombre de caractères bruts avant lui.
|
|
4716
|
+
*/
|
|
4717
|
+
mapCursorPosition(inputValue, inputCursor, formatted) {
|
|
4718
|
+
const minPos = this.prefixSlotsCount;
|
|
4719
|
+
const safeInput = String(inputValue ?? "");
|
|
4720
|
+
const safeFormatted = String(formatted ?? "");
|
|
4721
|
+
if (inputCursor <= 0 || !safeFormatted) return minPos;
|
|
4722
|
+
const rawBeforeCursor = this.extractRaw(safeInput.slice(0, inputCursor), false);
|
|
4723
|
+
const targetRawCount = rawBeforeCursor.length;
|
|
4724
|
+
if (targetRawCount === 0) {
|
|
4725
|
+
return Math.max(minPos, Math.min(this.getNextEditablePosition(0), safeFormatted.length));
|
|
4726
|
+
}
|
|
4727
|
+
let currentRawCount = 0;
|
|
4728
|
+
let targetPos = safeFormatted.length;
|
|
4729
|
+
for (let i = 0; i < safeFormatted.length && i < this.slots.length; i++) {
|
|
4730
|
+
if (!this.slots[i].isStatic) {
|
|
4731
|
+
currentRawCount++;
|
|
4732
|
+
if (currentRawCount === targetRawCount) {
|
|
4733
|
+
targetPos = i + 1;
|
|
4734
|
+
break;
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
while (targetPos < safeFormatted.length && this.slots[targetPos] && this.slots[targetPos].isStatic) {
|
|
4739
|
+
targetPos++;
|
|
4740
|
+
}
|
|
4741
|
+
return Math.max(minPos, Math.min(targetPos, safeFormatted.length));
|
|
4742
|
+
}
|
|
4743
|
+
/**
|
|
4744
|
+
* Gère la frappe d'un séparateur au clavier segment par segment (ex: '5' + '/' -> '05/', '5' + '.' -> '05. ').
|
|
4745
|
+
* Résout atomiquement les séparateurs composites ('DD. MM. YYYY HH:mm') sans jamais dédoubler l'espace.
|
|
4746
|
+
*/
|
|
4747
|
+
tryHandleSeparatorKey(currentValue, cursor, key) {
|
|
4748
|
+
const none = { handled: false, formatted: currentValue, cursor };
|
|
4749
|
+
if (!key || key.length !== 1) return none;
|
|
4750
|
+
if (cursor < this.slots.length && this.slots[cursor].isStatic && this.separatorMatchesKey(this.slots[cursor].char, key)) {
|
|
4751
|
+
const nextEditable = this.getNextEditablePosition(cursor + 1);
|
|
4752
|
+
const formatted = this.format(currentValue);
|
|
4753
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4754
|
+
}
|
|
4755
|
+
if (cursor > this.prefixSlotsCount && cursor - 1 < this.slots.length && this.slots[cursor - 1].isStatic) {
|
|
4756
|
+
let k = cursor - 1;
|
|
4757
|
+
while (k >= this.prefixSlotsCount && this.slots[k].isStatic) {
|
|
4758
|
+
if (this.separatorMatchesKey(this.slots[k].char, key)) {
|
|
4759
|
+
const nextEditable = this.getNextEditablePosition(k + 1);
|
|
4760
|
+
const formatted = this.format(currentValue);
|
|
4761
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4762
|
+
}
|
|
4763
|
+
k--;
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
let segIdx = -1;
|
|
4767
|
+
for (let i = 0; i < this.segments.length; i++) {
|
|
4768
|
+
const seg2 = this.segments[i];
|
|
4769
|
+
if (cursor >= seg2.start && cursor <= seg2.end) {
|
|
4770
|
+
segIdx = i;
|
|
4771
|
+
break;
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
if (segIdx === -1) return none;
|
|
4775
|
+
const seg = this.segments[segIdx];
|
|
4776
|
+
if (!seg.followingSeparator) return none;
|
|
4777
|
+
if (!this.followingSeparatorMatchesKey(seg.followingSeparator, key)) {
|
|
4778
|
+
return none;
|
|
4779
|
+
}
|
|
4780
|
+
const rawInSeg = currentValue.slice(seg.start, Math.min(cursor, seg.end)).replace(/\D/g, "");
|
|
4781
|
+
if (seg.kind !== "YYYY" && seg.kind !== "A" && rawInSeg.length > 0 && rawInSeg.length < seg.length) {
|
|
4782
|
+
const paddedSeg = "0".repeat(seg.length - rawInSeg.length) + rawInSeg;
|
|
4783
|
+
const tail = currentValue.slice(Math.min(currentValue.length, seg.end));
|
|
4784
|
+
const candidate = currentValue.slice(0, seg.start) + paddedSeg + seg.followingSeparator + tail;
|
|
4785
|
+
const formatted = this.format(candidate);
|
|
4786
|
+
const nextEditable = this.getNextEditablePosition(seg.end);
|
|
4787
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4788
|
+
}
|
|
4789
|
+
if (cursor === seg.end) {
|
|
4790
|
+
const formatted = this.format(currentValue);
|
|
4791
|
+
const nextEditable = this.getNextEditablePosition(seg.end);
|
|
4792
|
+
return { handled: true, formatted, cursor: Math.min(nextEditable, formatted.length) };
|
|
4793
|
+
}
|
|
4794
|
+
return none;
|
|
4795
|
+
}
|
|
4796
|
+
/**
|
|
4797
|
+
* Formate un Date, timestamp numérique, ISO string ou valeur partielle vers le gabarit configuré.
|
|
4798
|
+
* Immunisé contre Invalid Date et NaN.
|
|
4799
|
+
*/
|
|
4800
|
+
formatFromValue(value) {
|
|
4801
|
+
if (value === null || value === void 0) return this.prefixString;
|
|
4802
|
+
if (value instanceof Date) {
|
|
4803
|
+
if (Number.isNaN(value.getTime())) return this.prefixString;
|
|
4804
|
+
return this.formatPartsToTemplate(this.dateToUTCParts(value));
|
|
4805
|
+
}
|
|
4806
|
+
if (typeof value === "number") {
|
|
4807
|
+
if (!Number.isFinite(value)) return this.prefixString;
|
|
4808
|
+
const d = new Date(value);
|
|
4809
|
+
if (Number.isNaN(d.getTime())) return this.prefixString;
|
|
4810
|
+
return this.formatPartsToTemplate(this.dateToUTCParts(d));
|
|
4811
|
+
}
|
|
4812
|
+
const str = String(value).slice(0, MAX_INPUT_LENGTH).trim();
|
|
4813
|
+
if (!str) return this.prefixString;
|
|
4814
|
+
const pasted = this.parsePasted(str);
|
|
4815
|
+
if (pasted.matched) {
|
|
4816
|
+
return pasted.formatted;
|
|
4817
|
+
}
|
|
4818
|
+
if (pasted.rejected) {
|
|
4819
|
+
return this.prefixString;
|
|
4820
|
+
}
|
|
4821
|
+
return this.format(str, true);
|
|
4822
|
+
}
|
|
4823
|
+
/**
|
|
4824
|
+
* Formate une chaîne issue d'une affectation native (input.value = '...') sans altérer la frappe
|
|
4825
|
+
* en cours par le parseur segmenté (seul un ISO 8601 complet avec horaire est reconnu).
|
|
4826
|
+
*/
|
|
4827
|
+
formatFromNativeValue(strVal) {
|
|
4828
|
+
const str = String(strVal ?? "").slice(0, MAX_INPUT_LENGTH);
|
|
4829
|
+
if (!str) return this.prefixString;
|
|
4830
|
+
const trimmed = str.trim();
|
|
4831
|
+
if (trimmed.length >= 16) {
|
|
4832
|
+
const iso = this.parseISO8601Linear(trimmed);
|
|
4833
|
+
if (iso && !iso.dateOnly) {
|
|
4834
|
+
const res = this.parsePasted(trimmed);
|
|
4835
|
+
if (res.matched) return res.formatted;
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4838
|
+
return this.format(str, false);
|
|
4839
|
+
}
|
|
4840
|
+
/**
|
|
4841
|
+
* Parse universellement une chaîne collée en O(N) :
|
|
4842
|
+
* 1) ISO 8601 (YYYY-MM-DD[T| ]HH:mm[:ss][.sss][Z|±HH:MM], date seule)
|
|
4843
|
+
* 2) Format configuré de l'instance avec tolérance des segments courts (ex: 2/3/2026 9:5)
|
|
4844
|
+
*/
|
|
4845
|
+
parsePasted(rawText) {
|
|
4846
|
+
const fail = { matched: false, formatted: "", cursor: 0 };
|
|
4847
|
+
const rejected = { matched: false, rejected: true, formatted: "", cursor: 0 };
|
|
4848
|
+
const text = String(rawText ?? "").slice(0, MAX_INPUT_LENGTH).trim();
|
|
4849
|
+
if (!text || this.segments.length === 0) return fail;
|
|
4850
|
+
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]);
|
|
4851
|
+
const iso = this.parseISO8601Linear(text);
|
|
4852
|
+
if (iso) {
|
|
4853
|
+
if (iso.dateOnly) {
|
|
4854
|
+
return this.formatDateOnlyMatch(
|
|
4855
|
+
{ year: iso.year, month: iso.month, day: iso.day },
|
|
4856
|
+
rejected
|
|
4857
|
+
);
|
|
4858
|
+
}
|
|
4859
|
+
if (iso.offsetMinutes !== null && iso.offsetMinutes !== 0 && !this.convertPastedOffset) {
|
|
4860
|
+
return rejected;
|
|
4861
|
+
}
|
|
4862
|
+
const baseDate = this.buildStrictUTCDate({
|
|
4863
|
+
year: iso.year,
|
|
4864
|
+
month: iso.month,
|
|
4865
|
+
day: iso.day,
|
|
4866
|
+
hour: iso.hour,
|
|
4867
|
+
minute: iso.minute,
|
|
4868
|
+
second: iso.second
|
|
4869
|
+
});
|
|
4870
|
+
if (!baseDate) return rejected;
|
|
4871
|
+
let targetDate = baseDate;
|
|
4872
|
+
let offsetConverted;
|
|
4873
|
+
if (iso.offsetMinutes !== null && iso.offsetMinutes !== 0) {
|
|
4874
|
+
const utcMs = baseDate.getTime() - iso.offsetMinutes * 6e4;
|
|
4875
|
+
targetDate = new Date(utcMs);
|
|
4876
|
+
if (Number.isNaN(targetDate.getTime())) return rejected;
|
|
4877
|
+
offsetConverted = {
|
|
4878
|
+
original: text,
|
|
4879
|
+
offsetMinutes: iso.offsetMinutes,
|
|
4880
|
+
utcIso: this.formatDateToISO(targetDate)
|
|
4881
|
+
};
|
|
4882
|
+
}
|
|
4883
|
+
const formatted = this.formatPartsToTemplate(this.dateToUTCParts(targetDate));
|
|
4884
|
+
return {
|
|
4885
|
+
matched: true,
|
|
4886
|
+
formatted,
|
|
4887
|
+
cursor: formatted.length,
|
|
4888
|
+
offsetConverted
|
|
4889
|
+
};
|
|
4890
|
+
}
|
|
4891
|
+
if (looksLikeIso && text.length > 10 && (text[10] === "T" || text[10] === "t" || this.segments[0]?.kind !== "YYYY")) {
|
|
4892
|
+
return rejected;
|
|
4893
|
+
}
|
|
4894
|
+
return this.parseConfiguredFormatLinear(text);
|
|
4895
|
+
}
|
|
4896
|
+
/**
|
|
4897
|
+
* Formate une date UTC valide dans la locale demandée via Intl.DateTimeFormat (aperçu miroir).
|
|
4898
|
+
*/
|
|
4899
|
+
formatLocal(date, locale, intlOptions) {
|
|
4900
|
+
if (!date || Number.isNaN(date.getTime())) return null;
|
|
4901
|
+
try {
|
|
4902
|
+
const opts = intlOptions || {
|
|
4903
|
+
dateStyle: "short",
|
|
4904
|
+
timeStyle: "medium"
|
|
4905
|
+
};
|
|
4906
|
+
return new Intl.DateTimeFormat(locale, opts).format(date);
|
|
4907
|
+
} catch {
|
|
4908
|
+
return null;
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
// ==========================================================================
|
|
4912
|
+
// Helpers internes purs
|
|
4913
|
+
// ==========================================================================
|
|
4914
|
+
normalizeBoundary(val) {
|
|
4915
|
+
if (val === null || val === void 0) return null;
|
|
4916
|
+
if (val instanceof Date) {
|
|
4917
|
+
const t = val.getTime();
|
|
4918
|
+
return Number.isNaN(t) ? null : t;
|
|
4919
|
+
}
|
|
4920
|
+
if (typeof val === "number") {
|
|
4921
|
+
return Number.isFinite(val) ? val : null;
|
|
4922
|
+
}
|
|
4923
|
+
const str = String(val).slice(0, MAX_INPUT_LENGTH).trim();
|
|
4924
|
+
if (!str) return null;
|
|
4925
|
+
const iso = this.parseISO8601Linear(str);
|
|
4926
|
+
if (iso) {
|
|
4927
|
+
const d = this.buildStrictUTCDate({
|
|
4928
|
+
year: iso.year,
|
|
4929
|
+
month: iso.month,
|
|
4930
|
+
day: iso.day,
|
|
4931
|
+
hour: iso.hour,
|
|
4932
|
+
minute: iso.minute,
|
|
4933
|
+
second: iso.second
|
|
4934
|
+
});
|
|
4935
|
+
if (!d) return null;
|
|
4936
|
+
const offsetMs = iso.offsetMinutes ? iso.offsetMinutes * 6e4 : 0;
|
|
4937
|
+
return d.getTime() - offsetMs;
|
|
4938
|
+
}
|
|
4939
|
+
const res = this.analyze(str, true);
|
|
4940
|
+
return res.timestamp;
|
|
4941
|
+
}
|
|
4942
|
+
separatorMatchesKey(sepChar, key) {
|
|
4943
|
+
if (sepChar === key) return true;
|
|
4944
|
+
if ((sepChar === "T" || sepChar === "t") && (key === "T" || key === "t" || key === " ")) {
|
|
4945
|
+
return true;
|
|
4946
|
+
}
|
|
4947
|
+
return false;
|
|
4948
|
+
}
|
|
4949
|
+
followingSeparatorMatchesKey(followingSep, key) {
|
|
4950
|
+
let hasNonSpace = false;
|
|
4951
|
+
for (let i = 0; i < followingSep.length; i++) {
|
|
4952
|
+
if (followingSep[i] !== " ") {
|
|
4953
|
+
hasNonSpace = true;
|
|
4954
|
+
break;
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
for (let i = 0; i < followingSep.length; i++) {
|
|
4958
|
+
const ch = followingSep[i];
|
|
4959
|
+
if (hasNonSpace && ch === " ") {
|
|
4960
|
+
continue;
|
|
4961
|
+
}
|
|
4962
|
+
if (this.separatorMatchesKey(ch, key)) return true;
|
|
4963
|
+
}
|
|
4964
|
+
return false;
|
|
4965
|
+
}
|
|
4966
|
+
formatFromCleanRaw(cleanRaw) {
|
|
4967
|
+
if (this.slots.length === 0) return "";
|
|
4968
|
+
if (cleanRaw.length === 0) return this.prefixString;
|
|
4969
|
+
let formatted = "";
|
|
4970
|
+
let rawIdx = 0;
|
|
4971
|
+
for (let i = 0; i < this.slots.length; i++) {
|
|
4972
|
+
const slot = this.slots[i];
|
|
4973
|
+
if (slot.isStatic) {
|
|
4974
|
+
const hasRemainingRaw = rawIdx < cleanRaw.length;
|
|
4975
|
+
const isPrefix = rawIdx === 0 && slot.isPrefix;
|
|
4976
|
+
const isCompletedSegmentTrailingSep = rawIdx > 0 && rawIdx === cleanRaw.length;
|
|
4977
|
+
if (hasRemainingRaw || isPrefix || isCompletedSegmentTrailingSep) {
|
|
4978
|
+
formatted += slot.char;
|
|
4979
|
+
} else {
|
|
4980
|
+
break;
|
|
4981
|
+
}
|
|
4982
|
+
} else if (rawIdx < cleanRaw.length) {
|
|
4983
|
+
formatted += cleanRaw[rawIdx];
|
|
4984
|
+
rawIdx++;
|
|
4985
|
+
} else {
|
|
4986
|
+
break;
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
return formatted;
|
|
4990
|
+
}
|
|
4991
|
+
extractSegmentValues(cleanRaw) {
|
|
4992
|
+
const parts = {};
|
|
4993
|
+
let hour12;
|
|
4994
|
+
let meridiem;
|
|
4995
|
+
let rawOffset = 0;
|
|
4996
|
+
let allPresent = true;
|
|
4997
|
+
for (const seg of this.segments) {
|
|
4998
|
+
if (rawOffset + seg.length > cleanRaw.length) {
|
|
4999
|
+
allPresent = false;
|
|
5000
|
+
break;
|
|
5001
|
+
}
|
|
5002
|
+
const chunk = cleanRaw.slice(rawOffset, rawOffset + seg.length);
|
|
5003
|
+
rawOffset += seg.length;
|
|
5004
|
+
switch (seg.kind) {
|
|
5005
|
+
case "YYYY":
|
|
5006
|
+
parts.year = parseAsciiInt(chunk);
|
|
5007
|
+
break;
|
|
5008
|
+
case "MM":
|
|
5009
|
+
parts.month = parseAsciiInt(chunk);
|
|
5010
|
+
break;
|
|
5011
|
+
case "DD":
|
|
5012
|
+
parts.day = parseAsciiInt(chunk);
|
|
5013
|
+
break;
|
|
5014
|
+
case "HH":
|
|
5015
|
+
parts.hour = parseAsciiInt(chunk);
|
|
5016
|
+
break;
|
|
5017
|
+
case "hh":
|
|
5018
|
+
hour12 = parseAsciiInt(chunk);
|
|
5019
|
+
break;
|
|
5020
|
+
case "mm":
|
|
5021
|
+
parts.minute = parseAsciiInt(chunk);
|
|
5022
|
+
break;
|
|
5023
|
+
case "ss":
|
|
5024
|
+
parts.second = parseAsciiInt(chunk);
|
|
5025
|
+
break;
|
|
5026
|
+
case "A":
|
|
5027
|
+
if (chunk === "AM" || chunk === "PM") {
|
|
5028
|
+
meridiem = chunk;
|
|
5029
|
+
} else {
|
|
5030
|
+
allPresent = false;
|
|
5031
|
+
}
|
|
5032
|
+
break;
|
|
5033
|
+
}
|
|
5034
|
+
}
|
|
5035
|
+
if (parts.year === void 0 || parts.month === void 0 || parts.day === void 0) {
|
|
5036
|
+
allPresent = false;
|
|
5037
|
+
}
|
|
5038
|
+
if (parts.hour === void 0 && hour12 === void 0) {
|
|
5039
|
+
allPresent = false;
|
|
5040
|
+
}
|
|
5041
|
+
if (allPresent && hour12 !== void 0) {
|
|
5042
|
+
const resolved = this.resolveHour24({ parts, hour12, meridiem });
|
|
5043
|
+
if (resolved !== null) {
|
|
5044
|
+
parts.hour = resolved;
|
|
5045
|
+
}
|
|
5046
|
+
}
|
|
5047
|
+
return { parts, hour12, meridiem, allSegmentsPresent: allPresent };
|
|
5048
|
+
}
|
|
5049
|
+
resolveHour24(extracted) {
|
|
5050
|
+
if (extracted.hour12 !== void 0) {
|
|
5051
|
+
const h12 = extracted.hour12;
|
|
5052
|
+
if (h12 < 1 || h12 > 12 || !extracted.meridiem) return null;
|
|
5053
|
+
if (extracted.meridiem === "AM") {
|
|
5054
|
+
return h12 === 12 ? 0 : h12;
|
|
5055
|
+
}
|
|
5056
|
+
return h12 === 12 ? 12 : h12 + 12;
|
|
5057
|
+
}
|
|
5058
|
+
if (extracted.parts.hour !== void 0) {
|
|
5059
|
+
return extracted.parts.hour >= 0 && extracted.parts.hour <= 23 ? extracted.parts.hour : null;
|
|
5060
|
+
}
|
|
5061
|
+
return null;
|
|
5062
|
+
}
|
|
5063
|
+
/**
|
|
5064
|
+
* Validation calendaire stricte sans rollover ni piège Date.UTC(0..99).
|
|
5065
|
+
*/
|
|
5066
|
+
buildStrictUTCDate(parts) {
|
|
5067
|
+
const { year, month, day, hour, minute, second } = parts;
|
|
5068
|
+
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) {
|
|
5069
|
+
return null;
|
|
5070
|
+
}
|
|
5071
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
5072
|
+
d.setUTCFullYear(year, month - 1, day);
|
|
5073
|
+
d.setUTCHours(hour, minute, second, 0);
|
|
5074
|
+
if (d.getUTCFullYear() !== year || d.getUTCMonth() !== month - 1 || d.getUTCDate() !== day || d.getUTCHours() !== hour || d.getUTCMinutes() !== minute || d.getUTCSeconds() !== second) {
|
|
5075
|
+
return null;
|
|
5076
|
+
}
|
|
5077
|
+
return d;
|
|
5078
|
+
}
|
|
5079
|
+
dateToUTCParts(d) {
|
|
5080
|
+
return {
|
|
5081
|
+
year: d.getUTCFullYear(),
|
|
5082
|
+
month: d.getUTCMonth() + 1,
|
|
5083
|
+
day: d.getUTCDate(),
|
|
5084
|
+
hour: d.getUTCHours(),
|
|
5085
|
+
minute: d.getUTCMinutes(),
|
|
5086
|
+
second: d.getUTCSeconds()
|
|
5087
|
+
};
|
|
5088
|
+
}
|
|
5089
|
+
formatDateToISO(d) {
|
|
5090
|
+
const y = String(d.getUTCFullYear()).padStart(4, "0");
|
|
5091
|
+
const m = String(d.getUTCMonth() + 1).padStart(2, "0");
|
|
5092
|
+
const day = String(d.getUTCDate()).padStart(2, "0");
|
|
5093
|
+
const h = String(d.getUTCHours()).padStart(2, "0");
|
|
5094
|
+
const min = String(d.getUTCMinutes()).padStart(2, "0");
|
|
5095
|
+
const s = String(d.getUTCSeconds()).padStart(2, "0");
|
|
5096
|
+
if (this.includeMilliseconds) {
|
|
5097
|
+
const ms = String(d.getUTCMilliseconds()).padStart(3, "0");
|
|
5098
|
+
return `${y}-${m}-${day}T${h}:${min}:${s}.${ms}Z`;
|
|
5099
|
+
}
|
|
5100
|
+
return `${y}-${m}-${day}T${h}:${min}:${s}Z`;
|
|
5101
|
+
}
|
|
5102
|
+
formatPartsToTemplate(parts) {
|
|
5103
|
+
let raw = "";
|
|
5104
|
+
for (const seg of this.segments) {
|
|
5105
|
+
switch (seg.kind) {
|
|
5106
|
+
case "YYYY":
|
|
5107
|
+
raw += String(parts.year).padStart(4, "0").slice(-4);
|
|
5108
|
+
break;
|
|
5109
|
+
case "MM":
|
|
5110
|
+
raw += String(parts.month).padStart(2, "0");
|
|
5111
|
+
break;
|
|
5112
|
+
case "DD":
|
|
5113
|
+
raw += String(parts.day).padStart(2, "0");
|
|
5114
|
+
break;
|
|
5115
|
+
case "HH":
|
|
5116
|
+
raw += String(parts.hour).padStart(2, "0");
|
|
5117
|
+
break;
|
|
5118
|
+
case "hh": {
|
|
5119
|
+
const h12 = parts.hour % 12 === 0 ? 12 : parts.hour % 12;
|
|
5120
|
+
raw += String(h12).padStart(2, "0");
|
|
5121
|
+
break;
|
|
5122
|
+
}
|
|
5123
|
+
case "mm":
|
|
5124
|
+
raw += String(parts.minute).padStart(2, "0");
|
|
5125
|
+
break;
|
|
5126
|
+
case "ss":
|
|
5127
|
+
raw += String(parts.second).padStart(2, "0");
|
|
5128
|
+
break;
|
|
5129
|
+
case "A":
|
|
5130
|
+
raw += parts.hour >= 12 ? "PM" : "AM";
|
|
5131
|
+
break;
|
|
5132
|
+
}
|
|
5133
|
+
}
|
|
5134
|
+
return this.formatFromCleanRaw(raw);
|
|
5135
|
+
}
|
|
5136
|
+
formatDateOnlyMatch(dateParts, fail) {
|
|
5137
|
+
const check = this.buildStrictUTCDate({
|
|
5138
|
+
year: dateParts.year,
|
|
5139
|
+
month: dateParts.month,
|
|
5140
|
+
day: dateParts.day,
|
|
5141
|
+
hour: 0,
|
|
5142
|
+
minute: 0,
|
|
5143
|
+
second: 0
|
|
5144
|
+
});
|
|
5145
|
+
if (!check) return fail;
|
|
5146
|
+
if (typeof this.defaultTimeOnDateOnly === "string" && this.defaultTimeOnDateOnly.trim()) {
|
|
5147
|
+
const parsedTime = this.parseDefaultTime(this.defaultTimeOnDateOnly.trim());
|
|
5148
|
+
if (parsedTime) {
|
|
5149
|
+
const formatted2 = this.formatPartsToTemplate({
|
|
5150
|
+
...dateParts,
|
|
5151
|
+
hour: parsedTime.hour,
|
|
5152
|
+
minute: parsedTime.minute,
|
|
5153
|
+
second: parsedTime.second
|
|
5154
|
+
});
|
|
5155
|
+
return { matched: true, formatted: formatted2, cursor: formatted2.length };
|
|
5156
|
+
}
|
|
5157
|
+
}
|
|
5158
|
+
let rawDate = "";
|
|
5159
|
+
for (const seg of this.segments) {
|
|
5160
|
+
if (TIME_TOKEN_KINDS.has(seg.kind)) break;
|
|
5161
|
+
if (seg.kind === "YYYY") rawDate += String(dateParts.year).padStart(4, "0");
|
|
5162
|
+
else if (seg.kind === "MM") rawDate += String(dateParts.month).padStart(2, "0");
|
|
5163
|
+
else if (seg.kind === "DD") rawDate += String(dateParts.day).padStart(2, "0");
|
|
5164
|
+
}
|
|
5165
|
+
if (!rawDate) return fail;
|
|
5166
|
+
const formatted = this.formatFromCleanRaw(rawDate);
|
|
5167
|
+
return { matched: true, formatted, cursor: formatted.length };
|
|
5168
|
+
}
|
|
5169
|
+
parseDefaultTime(timeStr) {
|
|
5170
|
+
const parts = timeStr.split(":");
|
|
5171
|
+
if (parts.length < 2 || parts.length > 3) return null;
|
|
5172
|
+
const hour = parseAsciiInt(parts[0]);
|
|
5173
|
+
const minute = parseAsciiInt(parts[1]);
|
|
5174
|
+
const second = parts.length === 3 ? parseAsciiInt(parts[2]) : 0;
|
|
5175
|
+
if (Number.isNaN(hour) || hour < 0 || hour > 23 || Number.isNaN(minute) || minute < 0 || minute > 59 || Number.isNaN(second) || second < 0 || second > 59) {
|
|
5176
|
+
return null;
|
|
5177
|
+
}
|
|
5178
|
+
return { hour, minute, second };
|
|
5179
|
+
}
|
|
5180
|
+
/**
|
|
5181
|
+
* Parseur ISO 8601 strict en complexité linéaire O(N) sans regex à backtracking.
|
|
5182
|
+
*/
|
|
5183
|
+
parseISO8601Linear(str) {
|
|
5184
|
+
if (str.length < 10) return null;
|
|
5185
|
+
for (const idx of [0, 1, 2, 3, 5, 6, 8, 9]) {
|
|
5186
|
+
if (!isAsciiDigit(str[idx])) return null;
|
|
5187
|
+
}
|
|
5188
|
+
if (str[4] !== "-" || str[7] !== "-") return null;
|
|
5189
|
+
const year = parseAsciiInt(str.slice(0, 4));
|
|
5190
|
+
const month = parseAsciiInt(str.slice(5, 7));
|
|
5191
|
+
const day = parseAsciiInt(str.slice(8, 10));
|
|
5192
|
+
if (str.length === 10) {
|
|
5193
|
+
return { year, month, day, hour: 0, minute: 0, second: 0, dateOnly: true, offsetMinutes: null };
|
|
5194
|
+
}
|
|
5195
|
+
let pos = 10;
|
|
5196
|
+
if (str[pos] !== "T" && str[pos] !== "t" && str[pos] !== " ") return null;
|
|
5197
|
+
pos++;
|
|
5198
|
+
if (pos + 5 > str.length) return null;
|
|
5199
|
+
if (!isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1]) || str[pos + 2] !== ":" || !isAsciiDigit(str[pos + 3]) || !isAsciiDigit(str[pos + 4])) {
|
|
5200
|
+
return null;
|
|
5201
|
+
}
|
|
5202
|
+
const hour = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5203
|
+
const minute = parseAsciiInt(str.slice(pos + 3, pos + 5));
|
|
5204
|
+
pos += 5;
|
|
5205
|
+
let second = 0;
|
|
5206
|
+
if (pos < str.length && str[pos] === ":") {
|
|
5207
|
+
pos++;
|
|
5208
|
+
if (pos + 2 > str.length || !isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1])) return null;
|
|
5209
|
+
second = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5210
|
+
pos += 2;
|
|
5211
|
+
}
|
|
5212
|
+
if (pos < str.length && str[pos] === ".") {
|
|
5213
|
+
pos++;
|
|
5214
|
+
const fracStart = pos;
|
|
5215
|
+
while (pos < str.length && isAsciiDigit(str[pos])) {
|
|
5216
|
+
pos++;
|
|
5217
|
+
}
|
|
5218
|
+
if (pos === fracStart) return null;
|
|
5219
|
+
}
|
|
5220
|
+
let offsetMinutes = null;
|
|
5221
|
+
if (pos < str.length) {
|
|
5222
|
+
while (pos < str.length && str[pos] === " ") pos++;
|
|
5223
|
+
if (pos < str.length) {
|
|
5224
|
+
const tzChar = str[pos];
|
|
5225
|
+
if (tzChar === "Z" || tzChar === "z") {
|
|
5226
|
+
offsetMinutes = 0;
|
|
5227
|
+
pos++;
|
|
5228
|
+
} else if (tzChar === "+" || tzChar === "-") {
|
|
5229
|
+
const sign = tzChar === "-" ? -1 : 1;
|
|
5230
|
+
pos++;
|
|
5231
|
+
if (pos + 2 > str.length || !isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1])) return null;
|
|
5232
|
+
const offH = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5233
|
+
pos += 2;
|
|
5234
|
+
let offM = 0;
|
|
5235
|
+
if (pos < str.length) {
|
|
5236
|
+
if (str[pos] === ":") pos++;
|
|
5237
|
+
if (pos + 2 > str.length || !isAsciiDigit(str[pos]) || !isAsciiDigit(str[pos + 1])) return null;
|
|
5238
|
+
offM = parseAsciiInt(str.slice(pos, pos + 2));
|
|
5239
|
+
pos += 2;
|
|
5240
|
+
}
|
|
5241
|
+
if (offH > 14 || offM > 59 || offH === 14 && offM !== 0) {
|
|
5242
|
+
return null;
|
|
5243
|
+
}
|
|
5244
|
+
offsetMinutes = sign * (offH * 60 + offM);
|
|
5245
|
+
} else if (str.slice(pos).toUpperCase() === "UTC") {
|
|
5246
|
+
offsetMinutes = 0;
|
|
5247
|
+
pos = str.length;
|
|
5248
|
+
} else {
|
|
5249
|
+
return null;
|
|
5250
|
+
}
|
|
5251
|
+
}
|
|
5252
|
+
}
|
|
5253
|
+
if (pos !== str.length) return null;
|
|
5254
|
+
return { year, month, day, hour, minute, second, dateOnly: false, offsetMinutes };
|
|
5255
|
+
}
|
|
5256
|
+
/**
|
|
5257
|
+
* Parseur segmenté O(N) aligné sur le gabarit configuré de l'instance.
|
|
5258
|
+
* Tolère les segments courts (ex: 2/3/2026 9:5 ou 2. 3. 2026 9:5 ou 2/3-2026 9:5 pm)
|
|
5259
|
+
* sans deviner sur les dates ambiguës (03/04/2026 suit strictement l'ordre configuré).
|
|
5260
|
+
*/
|
|
5261
|
+
parseConfiguredFormatLinear(text) {
|
|
5262
|
+
const fail = { matched: false, formatted: "", cursor: 0 };
|
|
5263
|
+
let cleaned = text;
|
|
5264
|
+
if (cleaned.toUpperCase().endsWith(" UTC")) {
|
|
5265
|
+
cleaned = cleaned.slice(0, -4).trim();
|
|
5266
|
+
} else if (cleaned.length > 2 && (cleaned.endsWith("Z") || cleaned.endsWith("z")) && isAsciiDigit(cleaned[cleaned.length - 2])) {
|
|
5267
|
+
cleaned = cleaned.slice(0, -1).trim();
|
|
5268
|
+
}
|
|
5269
|
+
if (this.prefixString && cleaned.toLowerCase().startsWith(this.prefixString.trim().toLowerCase())) {
|
|
5270
|
+
cleaned = cleaned.slice(this.prefixString.trim().length).trim();
|
|
5271
|
+
}
|
|
5272
|
+
const tokens = [];
|
|
5273
|
+
let start = -1;
|
|
5274
|
+
for (let i = 0; i < cleaned.length; i++) {
|
|
5275
|
+
const ch = cleaned[i];
|
|
5276
|
+
if (DATE_SEPARATORS.has(ch)) {
|
|
5277
|
+
if (start !== -1) {
|
|
5278
|
+
tokens.push(cleaned.slice(start, i));
|
|
5279
|
+
start = -1;
|
|
5280
|
+
}
|
|
5281
|
+
} else {
|
|
5282
|
+
if (start === -1) start = i;
|
|
5283
|
+
}
|
|
5284
|
+
}
|
|
5285
|
+
if (start !== -1) {
|
|
5286
|
+
tokens.push(cleaned.slice(start));
|
|
5287
|
+
}
|
|
5288
|
+
if (tokens.length === 0 || tokens.length > this.segments.length) return fail;
|
|
5289
|
+
let dateSegCount = 0;
|
|
5290
|
+
for (const seg of this.segments) {
|
|
5291
|
+
if (TIME_TOKEN_KINDS.has(seg.kind)) break;
|
|
5292
|
+
dateSegCount++;
|
|
5293
|
+
}
|
|
5294
|
+
const rawParts = [];
|
|
5295
|
+
let yearVal;
|
|
5296
|
+
let monthVal;
|
|
5297
|
+
let dayVal;
|
|
5298
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
5299
|
+
const tok = tokens[i];
|
|
5300
|
+
const seg = this.segments[i];
|
|
5301
|
+
if (seg.kind === "A") {
|
|
5302
|
+
const up = tok.toUpperCase();
|
|
5303
|
+
if (up === "AM" || up === "A") rawParts.push("AM");
|
|
5304
|
+
else if (up === "PM" || up === "P") rawParts.push("PM");
|
|
5305
|
+
else return fail;
|
|
5306
|
+
continue;
|
|
5307
|
+
}
|
|
5308
|
+
for (let k = 0; k < tok.length; k++) {
|
|
5309
|
+
if (!isAsciiDigit(tok[k])) return fail;
|
|
5310
|
+
}
|
|
5311
|
+
if (seg.kind === "YYYY") {
|
|
5312
|
+
if (tok.length !== 4) return fail;
|
|
5313
|
+
yearVal = parseAsciiInt(tok);
|
|
5314
|
+
rawParts.push(tok);
|
|
5315
|
+
} else {
|
|
5316
|
+
if (tok.length < 1 || tok.length > 2) return fail;
|
|
5317
|
+
const padded = tok.length === 1 ? "0" + tok : tok;
|
|
5318
|
+
const val = parseAsciiInt(padded);
|
|
5319
|
+
if (seg.kind === "MM") monthVal = val;
|
|
5320
|
+
if (seg.kind === "DD") dayVal = val;
|
|
5321
|
+
rawParts.push(padded);
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
if (tokens.length === dateSegCount && yearVal !== void 0 && monthVal !== void 0 && dayVal !== void 0) {
|
|
5325
|
+
return this.formatDateOnlyMatch({ year: yearVal, month: monthVal, day: dayVal }, fail);
|
|
5326
|
+
}
|
|
5327
|
+
const minRequired = this.segments.length;
|
|
5328
|
+
if (tokens.length < minRequired) {
|
|
5329
|
+
const hasMinDateAndHourMin = dateSegCount > 0 && tokens.length >= dateSegCount + 2 && this.segments[dateSegCount + 1]?.kind === "mm";
|
|
5330
|
+
if (!hasMinDateAndHourMin) return fail;
|
|
5331
|
+
}
|
|
5332
|
+
const formatted = this.formatFromCleanRaw(rawParts.join(""));
|
|
5333
|
+
return {
|
|
5334
|
+
matched: true,
|
|
5335
|
+
formatted,
|
|
5336
|
+
cursor: formatted.length
|
|
5337
|
+
};
|
|
5338
|
+
}
|
|
5339
|
+
};
|
|
5340
|
+
|
|
5341
|
+
// src/mask/InputDateUTCMask.ts
|
|
5342
|
+
var MAX_NOTIFICATION_ITERATIONS3 = 10;
|
|
5343
|
+
var InputDateUTCMask = class extends BaseInputMask {
|
|
5344
|
+
engine;
|
|
5345
|
+
history;
|
|
5346
|
+
isComposing = false;
|
|
5347
|
+
isUndoingRedoing = false;
|
|
5348
|
+
isMouseDown = false;
|
|
5349
|
+
isApplying = false;
|
|
5350
|
+
isNotifying = false;
|
|
5351
|
+
hasPendingNotification = false;
|
|
5352
|
+
lastValue = "";
|
|
5353
|
+
lastValueLength = 0;
|
|
5354
|
+
lastInputType = "";
|
|
5355
|
+
inferredInputModeValue = null;
|
|
5356
|
+
wasAutocorrectSet = false;
|
|
5357
|
+
wasAutocapitalizeSet = false;
|
|
5358
|
+
wasSpellcheckSet = false;
|
|
5359
|
+
cutTimerId = null;
|
|
5360
|
+
pasteTimerId = null;
|
|
5361
|
+
resetTimerId = null;
|
|
5362
|
+
constructor(targetOrWrapper, inputOrOptions, options) {
|
|
5363
|
+
const args = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, options);
|
|
5364
|
+
const wrap = args.wrapper;
|
|
5365
|
+
const inp = args.input;
|
|
5366
|
+
const opts = args.options;
|
|
5367
|
+
const attrFormat = wrap?.getAttribute("data-mask-format") || inp?.getAttribute("data-mask-format") || void 0;
|
|
5368
|
+
const attrUtcIndicator = wrap?.getAttribute("data-mask-utc-indicator") ?? inp?.getAttribute("data-mask-utc-indicator");
|
|
5369
|
+
const attrInfer = wrap?.getAttribute("data-mask-infer-inputmode") ?? inp?.getAttribute("data-mask-infer-inputmode");
|
|
5370
|
+
const resolvedUtcIndicator = opts.utcIndicator !== void 0 ? opts.utcIndicator : attrUtcIndicator !== null ? attrUtcIndicator === "false" || attrUtcIndicator === "none" ? false : attrUtcIndicator : " UTC";
|
|
5371
|
+
const resolvedOptions = {
|
|
5372
|
+
...opts,
|
|
5373
|
+
format: opts.format ?? attrFormat ?? "YYYY-MM-DD HH:mm",
|
|
5374
|
+
utcIndicator: resolvedUtcIndicator,
|
|
5375
|
+
includeMilliseconds: opts.includeMilliseconds ?? false,
|
|
5376
|
+
convertPastedOffset: opts.convertPastedOffset ?? true,
|
|
5377
|
+
defaultTimeOnDateOnly: opts.defaultTimeOnDateOnly ?? false,
|
|
5378
|
+
inferInputMode: opts.inferInputMode ?? (attrInfer !== null ? attrInfer !== "false" : true),
|
|
5379
|
+
onInput: opts.onInput || opts.oninput,
|
|
5380
|
+
onChange: opts.onChange || opts.onchange,
|
|
5381
|
+
onComplete: opts.onComplete || opts.oncomplete
|
|
5382
|
+
};
|
|
5383
|
+
super(wrap, inp, resolvedOptions);
|
|
5384
|
+
this.history = new MaskHistory();
|
|
5385
|
+
this.engine = new DateUTCEngine(this.options);
|
|
5386
|
+
if (!this.input.hasAttribute("autocorrect")) {
|
|
5387
|
+
this.input.setAttribute("autocorrect", "off");
|
|
5388
|
+
this.wasAutocorrectSet = true;
|
|
5389
|
+
}
|
|
5390
|
+
if (!this.input.hasAttribute("autocapitalize")) {
|
|
5391
|
+
this.input.setAttribute("autocapitalize", "none");
|
|
5392
|
+
this.wasAutocapitalizeSet = true;
|
|
5393
|
+
}
|
|
5394
|
+
if (!this.input.hasAttribute("spellcheck")) {
|
|
5395
|
+
this.input.setAttribute("spellcheck", "false");
|
|
5396
|
+
this.wasSpellcheckSet = true;
|
|
5397
|
+
}
|
|
5398
|
+
this.syncInferredInputMode();
|
|
5399
|
+
this.bindEvents();
|
|
5400
|
+
this.lastValue = this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
5401
|
+
this.syncInitialValue();
|
|
5402
|
+
this.runAuditWarning(this.options.audit);
|
|
5403
|
+
}
|
|
5404
|
+
/**
|
|
5405
|
+
* Formate statiquement une date (Date, timestamp ms, ISO ou chaîne) sans DOM.
|
|
5406
|
+
*/
|
|
5407
|
+
static format(value, options = {}) {
|
|
5408
|
+
return DateUTCEngine.format(value, options);
|
|
5409
|
+
}
|
|
5410
|
+
getSpecificAuditWarnings() {
|
|
5411
|
+
const warnings = [];
|
|
5412
|
+
const describedbyWarnings = [];
|
|
5413
|
+
const hasValidDescribedby = this.checkAriaIdReferences(this.input, "aria-describedby", describedbyWarnings, true);
|
|
5414
|
+
const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
|
|
5415
|
+
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
5416
|
+
if (!hasValidDescribedby && !hasAriaPlaceholder && !this.options.disabled) {
|
|
5417
|
+
if (hasPlaceholder) {
|
|
5418
|
+
warnings.push(
|
|
5419
|
+
`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).`
|
|
5420
|
+
);
|
|
5421
|
+
} else {
|
|
5422
|
+
warnings.push(
|
|
5423
|
+
"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)."
|
|
5424
|
+
);
|
|
5425
|
+
}
|
|
5426
|
+
}
|
|
5427
|
+
return warnings;
|
|
5428
|
+
}
|
|
5429
|
+
extractRawSnippet(snippet) {
|
|
5430
|
+
if (!snippet) return "";
|
|
5431
|
+
if (snippet === this.input.value && this.isValid()) {
|
|
5432
|
+
return this.getRawValue();
|
|
5433
|
+
}
|
|
5434
|
+
return this.engine.extractRaw(snippet, false);
|
|
5435
|
+
}
|
|
5436
|
+
onPasswordModeDetected() {
|
|
5437
|
+
this.history.clear();
|
|
5438
|
+
this.lastValue = "";
|
|
5439
|
+
this.lastValueLength = 0;
|
|
5440
|
+
this.lastTrackedValue = "";
|
|
5441
|
+
this.clearGhost();
|
|
5442
|
+
}
|
|
5443
|
+
onNativeValueSet(strVal) {
|
|
5444
|
+
if (this.options.disabled) {
|
|
5445
|
+
this.checkValueChange(false);
|
|
5446
|
+
} else {
|
|
5447
|
+
const formatted = this.engine.formatFromNativeValue(strVal);
|
|
5448
|
+
this.applyFormatted(formatted, formatted.length, false);
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
onDisabledChange(disabled) {
|
|
5452
|
+
if (disabled) {
|
|
5453
|
+
this.wrapper.classList.remove("is-complete", "has-selection");
|
|
5454
|
+
this.clearGhost();
|
|
5455
|
+
this.checkValueChange(false);
|
|
5456
|
+
} else {
|
|
5457
|
+
const formatted = this.engine.formatFromValue(this.input.value);
|
|
5458
|
+
this.applyFormatted(formatted, this.input.selectionStart ?? formatted.length, false);
|
|
5459
|
+
}
|
|
5460
|
+
this.syncInferredInputMode();
|
|
5461
|
+
}
|
|
5462
|
+
handleAttributeMutation(attrName) {
|
|
5463
|
+
super.handleAttributeMutation(attrName);
|
|
5464
|
+
if (attrName === "data-mask-format") {
|
|
5465
|
+
const newFormat = this.getAttr("data-mask-format");
|
|
5466
|
+
if (newFormat && newFormat !== this.engine.getFormat()) {
|
|
5467
|
+
this.setFormat(newFormat);
|
|
5468
|
+
}
|
|
5469
|
+
} else if (attrName === "data-mask-utc-indicator") {
|
|
5470
|
+
const attrInd = this.getAttr("data-mask-utc-indicator");
|
|
5471
|
+
const indicator = attrInd === null || attrInd === "false" || attrInd === "none" ? false : attrInd;
|
|
5472
|
+
this.setUtcIndicator(indicator);
|
|
5473
|
+
} else if (attrName === "placeholder") {
|
|
5474
|
+
this.updateGhost(this.input.value);
|
|
5475
|
+
}
|
|
5476
|
+
}
|
|
5477
|
+
bindEvents() {
|
|
5478
|
+
this.onBeforeInput = this.onBeforeInput.bind(this);
|
|
5479
|
+
this.handleInput = this.handleInput.bind(this);
|
|
5480
|
+
this.onKeyDown = this.onKeyDown.bind(this);
|
|
5481
|
+
this.onPaste = this.onPaste.bind(this);
|
|
5482
|
+
this.onFocus = this.onFocus.bind(this);
|
|
5483
|
+
this.onBlur = this.onBlur.bind(this);
|
|
5484
|
+
this.onClick = this.onClick.bind(this);
|
|
5485
|
+
this.onKeyUp = this.onKeyUp.bind(this);
|
|
5486
|
+
this.onSelect = this.onSelect.bind(this);
|
|
5487
|
+
this.onMouseDown = this.onMouseDown.bind(this);
|
|
5488
|
+
this.onMouseUp = this.onMouseUp.bind(this);
|
|
5489
|
+
this.onCompositionStart = this.onCompositionStart.bind(this);
|
|
5490
|
+
this.onCompositionEnd = this.onCompositionEnd.bind(this);
|
|
5491
|
+
this.onCutHandler = () => {
|
|
5492
|
+
if (this.cutTimerId !== null) clearTimeout(this.cutTimerId);
|
|
5493
|
+
this.cutTimerId = window.setTimeout(() => {
|
|
5494
|
+
this.cutTimerId = null;
|
|
5495
|
+
if (this.isDestroyed) return;
|
|
5496
|
+
if (this.options.disabled) {
|
|
5497
|
+
this.checkValueChange(false);
|
|
5498
|
+
} else {
|
|
5499
|
+
const cur = this.input.selectionStart ?? this.input.value.length;
|
|
5500
|
+
this.applyFormatted(this.input.value, cur, false);
|
|
5501
|
+
}
|
|
5502
|
+
}, 0);
|
|
5503
|
+
};
|
|
5504
|
+
const onChangeNative = () => {
|
|
5505
|
+
if (this.isDestroyed) return;
|
|
5506
|
+
this.checkValueChange(true, true);
|
|
5507
|
+
};
|
|
5508
|
+
const { signal } = this.abortController;
|
|
5509
|
+
this.input.addEventListener("beforeinput", this.onBeforeInput, { signal });
|
|
5510
|
+
this.input.addEventListener("input", this.handleInput, { signal });
|
|
5511
|
+
this.input.addEventListener("keydown", this.onKeyDown, { signal });
|
|
5512
|
+
this.input.addEventListener("paste", this.onPaste, { signal });
|
|
5513
|
+
this.input.addEventListener("focus", this.onFocus, { signal });
|
|
5514
|
+
this.input.addEventListener("blur", this.onBlur, { signal });
|
|
5515
|
+
this.input.addEventListener("click", this.onClick, { signal });
|
|
5516
|
+
this.input.addEventListener("keyup", this.onKeyUp, { signal });
|
|
5517
|
+
this.input.addEventListener("select", this.onSelect, { signal });
|
|
5518
|
+
this.input.addEventListener("mousedown", this.onMouseDown, { signal });
|
|
5519
|
+
window.addEventListener("mouseup", this.onMouseUp, { signal });
|
|
5520
|
+
this.input.addEventListener("compositionstart", this.onCompositionStart, { signal });
|
|
5521
|
+
this.input.addEventListener("compositionend", this.onCompositionEnd, { signal });
|
|
5522
|
+
this.input.addEventListener("scroll", this.onScroll, { passive: true, signal });
|
|
5523
|
+
this.input.addEventListener("cut", this.onCutHandler, { signal });
|
|
5524
|
+
this.input.addEventListener("change", onChangeNative, { signal });
|
|
5525
|
+
if (this.input.form) {
|
|
5526
|
+
this.onFormResetHandler = () => {
|
|
5527
|
+
if (this.resetTimerId !== null) clearTimeout(this.resetTimerId);
|
|
5528
|
+
this.resetTimerId = window.setTimeout(() => {
|
|
5529
|
+
this.resetTimerId = null;
|
|
5530
|
+
if (this.isDestroyed) return;
|
|
5531
|
+
if (this.options.disabled) {
|
|
5532
|
+
this.checkValueChange(false);
|
|
5533
|
+
} else {
|
|
5534
|
+
this.syncInitialValue();
|
|
5535
|
+
}
|
|
5536
|
+
}, 0);
|
|
5537
|
+
};
|
|
5538
|
+
this.input.form.addEventListener("reset", this.onFormResetHandler, { signal });
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
syncInferredInputMode() {
|
|
5542
|
+
if (this.options.inferInputMode === false) return;
|
|
5543
|
+
if (this.options.disabled) {
|
|
5544
|
+
if (this.inferredInputModeValue && this.input.getAttribute("inputmode") === this.inferredInputModeValue) {
|
|
5545
|
+
this.input.removeAttribute("inputmode");
|
|
5546
|
+
}
|
|
5547
|
+
this.inferredInputModeValue = null;
|
|
5548
|
+
return;
|
|
5549
|
+
}
|
|
5550
|
+
const desired = this.engine.isNumericOnly() ? "numeric" : "text";
|
|
5551
|
+
const currentAttr = this.input.getAttribute("inputmode");
|
|
5552
|
+
if (!currentAttr || this.inferredInputModeValue === currentAttr) {
|
|
5553
|
+
this.input.inputMode = desired;
|
|
5554
|
+
this.inferredInputModeValue = desired;
|
|
5555
|
+
}
|
|
5556
|
+
}
|
|
5557
|
+
// ==========================================================================
|
|
5558
|
+
// API Publique
|
|
5559
|
+
// ==========================================================================
|
|
5560
|
+
getDetail() {
|
|
5561
|
+
const result = this.engine.analyze(this.input.value, false);
|
|
5562
|
+
return {
|
|
5563
|
+
...result,
|
|
5564
|
+
value: this.options.disabled ? this.input.value : result.formatted
|
|
5565
|
+
};
|
|
5566
|
+
}
|
|
5567
|
+
getRawValue() {
|
|
5568
|
+
if (this.options.disabled) return this.input.value;
|
|
5569
|
+
return this.getDetail().rawValue;
|
|
5570
|
+
}
|
|
5571
|
+
getISOString() {
|
|
5572
|
+
return this.getDetail().isoString;
|
|
5573
|
+
}
|
|
5574
|
+
getDate() {
|
|
5575
|
+
return this.getDetail().date;
|
|
5576
|
+
}
|
|
5577
|
+
getTimestamp() {
|
|
5578
|
+
return this.getDetail().timestamp;
|
|
5579
|
+
}
|
|
5580
|
+
getParts() {
|
|
5581
|
+
return this.getDetail().parts;
|
|
5582
|
+
}
|
|
5583
|
+
/**
|
|
5584
|
+
* Progressive Enhancement Baseline : retourne un Temporal.Instant natif si supporté par le navigateur,
|
|
5585
|
+
* sinon null (zéro polyfill externe).
|
|
5586
|
+
*/
|
|
5587
|
+
getTemporalInstant() {
|
|
5588
|
+
const ts = this.getTimestamp();
|
|
5589
|
+
if (ts === null) return null;
|
|
5590
|
+
const globalTemporal = globalThis.Temporal;
|
|
5591
|
+
if (globalTemporal?.Instant && typeof globalTemporal.Instant.fromEpochMilliseconds === "function") {
|
|
5592
|
+
try {
|
|
5593
|
+
return globalTemporal.Instant.fromEpochMilliseconds(ts);
|
|
5594
|
+
} catch {
|
|
5595
|
+
return null;
|
|
5596
|
+
}
|
|
5597
|
+
}
|
|
5598
|
+
return null;
|
|
5599
|
+
}
|
|
5600
|
+
isComplete() {
|
|
5601
|
+
if (this.options.disabled) return true;
|
|
5602
|
+
return this.getDetail().isComplete;
|
|
5603
|
+
}
|
|
5604
|
+
isValid() {
|
|
5605
|
+
if (this.options.disabled) return true;
|
|
5606
|
+
return this.getDetail().isValid;
|
|
5607
|
+
}
|
|
5608
|
+
setValue(val) {
|
|
5609
|
+
if (this.options.disabled) {
|
|
5610
|
+
const str = val instanceof Date ? Number.isNaN(val.getTime()) ? "" : this.engine.formatDateToISO(val) : val !== null && val !== void 0 ? String(val) : "";
|
|
5611
|
+
this.setNativeValue(str);
|
|
5612
|
+
this.checkValueChange(false);
|
|
5613
|
+
return;
|
|
5614
|
+
}
|
|
5615
|
+
const formatted = this.engine.formatFromValue(val);
|
|
5616
|
+
this.applyFormatted(formatted, formatted.length, true);
|
|
5617
|
+
}
|
|
5618
|
+
/**
|
|
5619
|
+
* Remplit l'instant UTC courant.
|
|
5620
|
+
*/
|
|
5621
|
+
setNow() {
|
|
5622
|
+
this.setValue(/* @__PURE__ */ new Date());
|
|
5623
|
+
}
|
|
5624
|
+
/**
|
|
5625
|
+
* Convertit la date UTC saisie vers la locale demandée via Intl.DateTimeFormat (aperçu sans widget).
|
|
5626
|
+
*/
|
|
5627
|
+
formatLocal(locale, intlOptions) {
|
|
5628
|
+
return this.engine.formatLocal(this.getDate(), locale, intlOptions);
|
|
5629
|
+
}
|
|
5630
|
+
/**
|
|
5631
|
+
* Change dynamiquement le format (preset ou chaîne de tokens) et reconvertit la date courante si elle est valide.
|
|
5632
|
+
*/
|
|
5633
|
+
setFormat(format, placeholderTokens) {
|
|
5634
|
+
const currentDate = this.getDate();
|
|
5635
|
+
this.options.format = format;
|
|
5636
|
+
if (placeholderTokens !== void 0) {
|
|
5637
|
+
this.options.placeholderTokens = placeholderTokens;
|
|
5638
|
+
}
|
|
5639
|
+
this.engine.setFormat(format, placeholderTokens);
|
|
5640
|
+
this.syncInferredInputMode();
|
|
5641
|
+
if (this.options.disabled) {
|
|
5642
|
+
this.clearGhost();
|
|
5643
|
+
return;
|
|
5644
|
+
}
|
|
5645
|
+
if (currentDate) {
|
|
5646
|
+
const formatted = this.engine.formatFromValue(currentDate);
|
|
5647
|
+
this.applyFormatted(formatted, formatted.length, true);
|
|
5648
|
+
} else {
|
|
5649
|
+
const formatted = this.engine.format(this.input.value, false);
|
|
5650
|
+
this.applyFormatted(formatted, Math.min(this.input.selectionStart ?? formatted.length, formatted.length), false);
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
setUtcIndicator(indicator) {
|
|
5654
|
+
this.options.utcIndicator = indicator;
|
|
5655
|
+
this.engine.setUtcIndicator(indicator);
|
|
5656
|
+
this.updateGhost(this.input.value);
|
|
5657
|
+
}
|
|
5658
|
+
undo() {
|
|
5659
|
+
if (this.options.disabled) return;
|
|
5660
|
+
const state = this.history.undo();
|
|
5661
|
+
if (state) {
|
|
5662
|
+
this.isUndoingRedoing = true;
|
|
5663
|
+
try {
|
|
5664
|
+
this.applyFormatted(this.engine.format(state.raw, false), state.cursor, true);
|
|
5665
|
+
} finally {
|
|
5666
|
+
this.isUndoingRedoing = false;
|
|
5667
|
+
}
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
redo() {
|
|
5671
|
+
if (this.options.disabled) return;
|
|
5672
|
+
const state = this.history.redo();
|
|
5673
|
+
if (state) {
|
|
5674
|
+
this.isUndoingRedoing = true;
|
|
5675
|
+
try {
|
|
5676
|
+
this.applyFormatted(this.engine.format(state.raw, false), state.cursor, true);
|
|
5677
|
+
} finally {
|
|
5678
|
+
this.isUndoingRedoing = false;
|
|
5679
|
+
}
|
|
5680
|
+
}
|
|
5681
|
+
}
|
|
5682
|
+
destroy() {
|
|
5683
|
+
if (this.isDestroyed) return;
|
|
5684
|
+
if (this.cutTimerId !== null) {
|
|
5685
|
+
clearTimeout(this.cutTimerId);
|
|
5686
|
+
this.cutTimerId = null;
|
|
5687
|
+
}
|
|
5688
|
+
if (this.pasteTimerId !== null) {
|
|
5689
|
+
clearTimeout(this.pasteTimerId);
|
|
5690
|
+
this.pasteTimerId = null;
|
|
5691
|
+
}
|
|
5692
|
+
if (this.resetTimerId !== null) {
|
|
5693
|
+
clearTimeout(this.resetTimerId);
|
|
5694
|
+
this.resetTimerId = null;
|
|
5695
|
+
}
|
|
5696
|
+
if (this.inferredInputModeValue && this.input.getAttribute("inputmode") === this.inferredInputModeValue) {
|
|
5697
|
+
this.input.removeAttribute("inputmode");
|
|
5698
|
+
}
|
|
5699
|
+
if (this.wasAutocorrectSet) this.input.removeAttribute("autocorrect");
|
|
5700
|
+
if (this.wasAutocapitalizeSet) this.input.removeAttribute("autocapitalize");
|
|
5701
|
+
if (this.wasSpellcheckSet) this.input.removeAttribute("spellcheck");
|
|
5702
|
+
this.history.clear();
|
|
5703
|
+
this.lastValue = "";
|
|
5704
|
+
this.lastValueLength = 0;
|
|
5705
|
+
super.destroy();
|
|
5706
|
+
}
|
|
5707
|
+
// ==========================================================================
|
|
5708
|
+
// Événements DOM & Clavier
|
|
5709
|
+
// ==========================================================================
|
|
5710
|
+
checkSelection() {
|
|
5711
|
+
if (this.options.disabled) return;
|
|
5712
|
+
const start = this.input.selectionStart ?? 0;
|
|
5713
|
+
const end = this.input.selectionEnd ?? start;
|
|
5714
|
+
this.wrapper.classList.toggle("has-selection", start !== end);
|
|
5715
|
+
}
|
|
5716
|
+
onBeforeInput(e) {
|
|
5717
|
+
this.lastInputType = e.inputType || "";
|
|
5718
|
+
if (this.options.disabled || this.isComposing) return;
|
|
5719
|
+
if (e.inputType === "insertFromPaste" || e.inputType === "insertReplacementText") return;
|
|
5720
|
+
if (e.inputType && e.inputType.startsWith("insert")) {
|
|
5721
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5722
|
+
if (totalSlots > 0) {
|
|
5723
|
+
const currentRaw = this.engine.extractRaw(this.input.value, false);
|
|
5724
|
+
const start = this.input.selectionStart ?? 0;
|
|
5725
|
+
const end = this.input.selectionEnd ?? start;
|
|
5726
|
+
let available = Math.max(0, totalSlots - currentRaw.length);
|
|
5727
|
+
if (end > start) {
|
|
5728
|
+
const selectedRaw = this.engine.extractRaw(this.input.value.slice(start, end), false);
|
|
5729
|
+
available = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
5730
|
+
}
|
|
5731
|
+
if (available <= 0) {
|
|
5732
|
+
e.preventDefault();
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
handleInput(e) {
|
|
5738
|
+
if (this.isDispatchingNativeInput || this.isComposing) return;
|
|
5739
|
+
if (this.options.disabled) {
|
|
5740
|
+
this.checkValueChange(false);
|
|
5741
|
+
return;
|
|
5742
|
+
}
|
|
5743
|
+
const inputType = e?.inputType || this.lastInputType || "";
|
|
5744
|
+
this.lastInputType = "";
|
|
5745
|
+
const val = this.input.value;
|
|
5746
|
+
const cursor = this.input.selectionStart ?? val.length;
|
|
5747
|
+
const prevState = this.history.getCurrent();
|
|
5748
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5749
|
+
const isShorter = inputType.startsWith("delete") || !this.isSensitiveField() && val.length < this.lastValueLength;
|
|
5750
|
+
const newRawNoExpand = this.engine.extractRaw(val, false);
|
|
5751
|
+
if (totalSlots > 0 && prevState && prevState.raw.length >= totalSlots && newRawNoExpand.length > totalSlots) {
|
|
5752
|
+
const prevFormatted = this.engine.format(prevState.raw, false);
|
|
5753
|
+
this.applyFormatted(prevFormatted, prevState.cursor, true);
|
|
5754
|
+
return;
|
|
5755
|
+
}
|
|
5756
|
+
let candidate = val;
|
|
5757
|
+
let expandMeridiem = !isShorter;
|
|
5758
|
+
if (isShorter && this.engine.hasMeridiem()) {
|
|
5759
|
+
for (const seg of this.engine.getSegments()) {
|
|
5760
|
+
if (seg.kind === "A" && val.length >= seg.start + 1 && val.length < seg.end) {
|
|
5761
|
+
candidate = val.slice(0, seg.start) + val.slice(seg.start + 1);
|
|
5762
|
+
expandMeridiem = false;
|
|
5763
|
+
break;
|
|
5764
|
+
}
|
|
5765
|
+
}
|
|
5766
|
+
}
|
|
5767
|
+
this.applyFormatted(candidate, cursor, false, expandMeridiem);
|
|
5768
|
+
this.checkSelection();
|
|
5769
|
+
}
|
|
5770
|
+
onKeyDown(e) {
|
|
5771
|
+
if (this.options.disabled || isImeComposing(e)) return;
|
|
5772
|
+
const cursor = this.input.selectionStart ?? 0;
|
|
5773
|
+
const selectionEnd = this.input.selectionEnd ?? cursor;
|
|
5774
|
+
const minPos = this.engine.getPrefixLength();
|
|
5775
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z") && !e.shiftKey) {
|
|
5776
|
+
e.preventDefault();
|
|
5777
|
+
this.undo();
|
|
5778
|
+
return;
|
|
5779
|
+
}
|
|
5780
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "y" || e.key === "Y") || (e.ctrlKey || e.metaKey) && e.shiftKey && (e.key === "z" || e.key === "Z")) {
|
|
5781
|
+
e.preventDefault();
|
|
5782
|
+
this.redo();
|
|
5783
|
+
return;
|
|
5784
|
+
}
|
|
5785
|
+
this.history.updateCurrentCursor(cursor);
|
|
5786
|
+
const isPrintable = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
5787
|
+
const hasSelection = selectionEnd > cursor;
|
|
5788
|
+
if (isPrintable && !hasSelection) {
|
|
5789
|
+
const sepResult = this.engine.tryHandleSeparatorKey(this.input.value, cursor, e.key);
|
|
5790
|
+
if (sepResult.handled) {
|
|
5791
|
+
e.preventDefault();
|
|
5792
|
+
this.applyFormatted(sepResult.formatted, sepResult.cursor, true);
|
|
5793
|
+
return;
|
|
5794
|
+
}
|
|
5795
|
+
if (this.engine.hasMeridiem()) {
|
|
5796
|
+
for (const seg of this.engine.getSegments()) {
|
|
5797
|
+
if (seg.kind === "A" && cursor >= seg.start && cursor <= seg.end) {
|
|
5798
|
+
const up = e.key.toUpperCase();
|
|
5799
|
+
if (up === "A" || up === "P") {
|
|
5800
|
+
e.preventDefault();
|
|
5801
|
+
const meridiem = up === "A" ? "AM" : "PM";
|
|
5802
|
+
const val = this.input.value;
|
|
5803
|
+
const updated = val.slice(0, seg.start) + meridiem + val.slice(Math.min(val.length, seg.end));
|
|
5804
|
+
this.applyFormatted(updated, seg.end, true);
|
|
5805
|
+
return;
|
|
5806
|
+
}
|
|
5807
|
+
}
|
|
5808
|
+
}
|
|
5809
|
+
}
|
|
5810
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5811
|
+
if (totalSlots > 0 && this.engine.extractRaw(this.input.value, false).length >= totalSlots) {
|
|
5812
|
+
e.preventDefault();
|
|
5813
|
+
return;
|
|
5814
|
+
}
|
|
5815
|
+
}
|
|
5816
|
+
if (hasSelection) {
|
|
5817
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
5818
|
+
e.preventDefault();
|
|
5819
|
+
const val = this.input.value;
|
|
5820
|
+
const updated = val.slice(0, cursor) + val.slice(selectionEnd);
|
|
5821
|
+
this.applyFormatted(updated, Math.max(minPos, cursor), false);
|
|
5822
|
+
return;
|
|
5823
|
+
}
|
|
5824
|
+
return;
|
|
5825
|
+
}
|
|
5826
|
+
if (e.key === "ArrowLeft" && !e.shiftKey && cursor <= minPos) {
|
|
5827
|
+
e.preventDefault();
|
|
5828
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5829
|
+
return;
|
|
5830
|
+
}
|
|
5831
|
+
if (e.key === "Home" && minPos > 0 && !e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
5832
|
+
e.preventDefault();
|
|
5833
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5834
|
+
return;
|
|
5835
|
+
}
|
|
5836
|
+
if (e.key === "Backspace" && cursor <= minPos) {
|
|
5837
|
+
e.preventDefault();
|
|
5838
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5839
|
+
return;
|
|
5840
|
+
}
|
|
5841
|
+
if (e.key === "Delete" && cursor < minPos) {
|
|
5842
|
+
e.preventDefault();
|
|
5843
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5844
|
+
return;
|
|
5845
|
+
}
|
|
5846
|
+
if (e.key === "Backspace" && this.engine.hasMeridiem()) {
|
|
5847
|
+
for (const seg of this.engine.getSegments()) {
|
|
5848
|
+
if (seg.kind === "A" && cursor > seg.start && cursor <= seg.end) {
|
|
5849
|
+
e.preventDefault();
|
|
5850
|
+
const val = this.input.value;
|
|
5851
|
+
const updated = val.slice(0, seg.start) + val.slice(Math.min(val.length, seg.end));
|
|
5852
|
+
this.applyFormatted(updated, seg.start, true);
|
|
5853
|
+
return;
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
}
|
|
5857
|
+
if (e.key === "Backspace" && (e.ctrlKey || e.altKey || e.metaKey)) {
|
|
5858
|
+
e.preventDefault();
|
|
5859
|
+
if (cursor <= minPos) {
|
|
5860
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
5861
|
+
return;
|
|
5862
|
+
}
|
|
5863
|
+
let i = cursor - 1;
|
|
5864
|
+
while (i >= minPos && this.engine.isSeparatorAt(i)) i--;
|
|
5865
|
+
while (i >= minPos && !this.engine.isSeparatorAt(i)) i--;
|
|
5866
|
+
const startPos = Math.max(minPos, i + 1);
|
|
5867
|
+
const val = this.input.value;
|
|
5868
|
+
this.applyFormatted(val.slice(0, startPos) + val.slice(cursor), startPos, true);
|
|
5869
|
+
return;
|
|
5870
|
+
}
|
|
5871
|
+
if (e.key === "Delete" && (e.ctrlKey || e.altKey || e.metaKey)) {
|
|
5872
|
+
e.preventDefault();
|
|
5873
|
+
const val = this.input.value;
|
|
5874
|
+
if (cursor >= val.length) return;
|
|
5875
|
+
let i = cursor;
|
|
5876
|
+
while (i < val.length && this.engine.isSeparatorAt(i)) i++;
|
|
5877
|
+
while (i < val.length && !this.engine.isSeparatorAt(i)) i++;
|
|
5878
|
+
while (i < val.length && this.engine.isSeparatorAt(i)) i++;
|
|
5879
|
+
this.applyFormatted(val.slice(0, cursor) + val.slice(i), cursor, true);
|
|
5880
|
+
return;
|
|
5881
|
+
}
|
|
5882
|
+
if (e.key === "Backspace" && cursor > minPos && this.engine.isSeparatorAt(cursor - 1)) {
|
|
5883
|
+
e.preventDefault();
|
|
5884
|
+
let targetPos = cursor - 1;
|
|
5885
|
+
while (targetPos > minPos && this.engine.isSeparatorAt(targetPos - 1)) {
|
|
5886
|
+
targetPos--;
|
|
5887
|
+
}
|
|
5888
|
+
if (targetPos > minPos) {
|
|
5889
|
+
const val = this.input.value;
|
|
5890
|
+
this.applyFormatted(val.slice(0, targetPos - 1) + val.slice(cursor), targetPos - 1, false);
|
|
5891
|
+
} else {
|
|
5892
|
+
this.applyFormatted("", minPos, true);
|
|
5893
|
+
}
|
|
5894
|
+
return;
|
|
5895
|
+
}
|
|
5896
|
+
if (e.key === "Delete" && cursor < this.input.value.length && this.engine.isSeparatorAt(cursor)) {
|
|
5897
|
+
e.preventDefault();
|
|
5898
|
+
let targetPos = cursor;
|
|
5899
|
+
while (targetPos < this.input.value.length && this.engine.isSeparatorAt(targetPos)) {
|
|
5900
|
+
targetPos++;
|
|
5901
|
+
}
|
|
5902
|
+
if (targetPos < this.input.value.length) {
|
|
5903
|
+
const val = this.input.value;
|
|
5904
|
+
this.applyFormatted(val.slice(0, targetPos) + val.slice(targetPos + 1), cursor, true);
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
}
|
|
5908
|
+
onPaste(e) {
|
|
5909
|
+
if (this.options.disabled) {
|
|
5910
|
+
if (this.pasteTimerId !== null) clearTimeout(this.pasteTimerId);
|
|
5911
|
+
this.pasteTimerId = window.setTimeout(() => {
|
|
5912
|
+
this.pasteTimerId = null;
|
|
5913
|
+
if (!this.isDestroyed) this.checkValueChange(false);
|
|
5914
|
+
}, 0);
|
|
5915
|
+
return;
|
|
5916
|
+
}
|
|
5917
|
+
e.preventDefault();
|
|
5918
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
5919
|
+
const pastedText = this.preparePastedText(this.getClipboardPlainText(e), 512);
|
|
5920
|
+
if (!pastedText) return;
|
|
5921
|
+
const minPos = this.engine.getPrefixLength();
|
|
5922
|
+
const selStart = this.input.selectionStart ?? 0;
|
|
5923
|
+
const selEnd = this.input.selectionEnd ?? selStart;
|
|
5924
|
+
const currentVal = this.input.value;
|
|
5925
|
+
const totalSlots = this.engine.getEditableCount();
|
|
5926
|
+
const currentRaw = this.engine.extractRaw(currentVal, false);
|
|
5927
|
+
const isGlobalOrEmpty = currentRaw.length === 0 || selStart <= minPos && selEnd >= currentVal.length || selStart === selEnd;
|
|
5928
|
+
if (isGlobalOrEmpty) {
|
|
5929
|
+
const parsed = this.engine.parsePasted(pastedText);
|
|
5930
|
+
if (parsed.matched) {
|
|
5931
|
+
this.applyFormatted(parsed.formatted, parsed.cursor, true);
|
|
5932
|
+
if (parsed.offsetConverted && this.options.onOffsetConverted) {
|
|
5933
|
+
try {
|
|
5934
|
+
this.options.onOffsetConverted(parsed.offsetConverted);
|
|
5935
|
+
} catch {
|
|
5936
|
+
}
|
|
5937
|
+
}
|
|
5938
|
+
this.checkSelection();
|
|
5939
|
+
return;
|
|
5940
|
+
}
|
|
5941
|
+
if (parsed.rejected) {
|
|
3369
5942
|
return;
|
|
3370
5943
|
}
|
|
3371
5944
|
}
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
this.
|
|
3375
|
-
|
|
5945
|
+
let available = Math.max(0, totalSlots - currentRaw.length);
|
|
5946
|
+
if (selEnd > selStart) {
|
|
5947
|
+
const selectedRaw = this.engine.extractRaw(currentVal.slice(selStart, selEnd), false);
|
|
5948
|
+
available = Math.max(0, totalSlots - (currentRaw.length - selectedRaw.length));
|
|
3376
5949
|
}
|
|
3377
|
-
if (
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
5950
|
+
if (available <= 0) return;
|
|
5951
|
+
const effectiveStart = Math.max(minPos, selStart);
|
|
5952
|
+
const effectiveEnd = Math.max(minPos, selEnd);
|
|
5953
|
+
const combined = currentVal.slice(0, effectiveStart) + pastedText + currentVal.slice(effectiveEnd);
|
|
5954
|
+
this.applyFormatted(combined, effectiveStart + pastedText.length, false, true);
|
|
5955
|
+
this.checkSelection();
|
|
5956
|
+
}
|
|
5957
|
+
onFocus() {
|
|
5958
|
+
this.syncGhostStyles();
|
|
5959
|
+
this.wrapper.classList.add("is-focused");
|
|
5960
|
+
if (!this.options.disabled && !this.isMouseDown) {
|
|
5961
|
+
this.enforceMinCursor();
|
|
3381
5962
|
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
5963
|
+
this.updateGhost(this.input.value);
|
|
5964
|
+
this.checkSelection();
|
|
5965
|
+
}
|
|
5966
|
+
onBlur() {
|
|
5967
|
+
this.wrapper.classList.remove("is-focused", "has-selection");
|
|
5968
|
+
if (this.isSensitiveField()) {
|
|
5969
|
+
this.onPasswordModeDetected();
|
|
3385
5970
|
return;
|
|
3386
5971
|
}
|
|
5972
|
+
this.updateGhost(this.input.value);
|
|
5973
|
+
this.checkValueChange(false, true);
|
|
3387
5974
|
}
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
acceptSuggestion() {
|
|
3392
|
-
if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.input.value.length === 0) return false;
|
|
3393
|
-
const completed = this.currentSuggestion.full;
|
|
3394
|
-
this.setNativeValue(completed);
|
|
3395
|
-
this.input.setSelectionRange(completed.length, completed.length);
|
|
3396
|
-
this.currentSuggestionIndex = 0;
|
|
3397
|
-
this.updateSuggestion();
|
|
3398
|
-
const detail = this.getDetail();
|
|
3399
|
-
if (this.options.onChange) {
|
|
3400
|
-
this.options.onChange(detail);
|
|
5975
|
+
onClick() {
|
|
5976
|
+
if (!this.options.disabled) {
|
|
5977
|
+
this.enforceMinCursor();
|
|
3401
5978
|
}
|
|
3402
|
-
this.input.
|
|
3403
|
-
this.
|
|
3404
|
-
return true;
|
|
5979
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
5980
|
+
this.checkSelection();
|
|
3405
5981
|
}
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
5982
|
+
onKeyUp(e) {
|
|
5983
|
+
if (!this.options.disabled) {
|
|
5984
|
+
if ((e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Home") && !e.shiftKey) {
|
|
5985
|
+
this.enforceMinCursor();
|
|
5986
|
+
}
|
|
5987
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
5988
|
+
}
|
|
5989
|
+
this.checkSelection();
|
|
3412
5990
|
}
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
setDefaultTld(tld) {
|
|
3417
|
-
this.engine.setDefaultTld(tld);
|
|
3418
|
-
this.updateSuggestion();
|
|
5991
|
+
onSelect() {
|
|
5992
|
+
this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
|
|
5993
|
+
this.checkSelection();
|
|
3419
5994
|
}
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
*/
|
|
3423
|
-
setTlds(tlds) {
|
|
3424
|
-
this.engine.setTlds(tlds);
|
|
3425
|
-
this.currentSuggestionIndex = 0;
|
|
3426
|
-
this.updateSuggestion();
|
|
5995
|
+
onMouseDown() {
|
|
5996
|
+
this.isMouseDown = true;
|
|
3427
5997
|
}
|
|
3428
|
-
|
|
3429
|
-
this.
|
|
3430
|
-
this.
|
|
3431
|
-
this.updateSuggestion();
|
|
5998
|
+
onMouseUp() {
|
|
5999
|
+
this.isMouseDown = false;
|
|
6000
|
+
this.checkSelection();
|
|
3432
6001
|
}
|
|
3433
|
-
|
|
3434
|
-
this.
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
this.
|
|
3440
|
-
|
|
3441
|
-
|
|
6002
|
+
onCompositionStart() {
|
|
6003
|
+
this.isComposing = true;
|
|
6004
|
+
}
|
|
6005
|
+
onCompositionEnd() {
|
|
6006
|
+
this.isComposing = false;
|
|
6007
|
+
if (this.options.disabled) return;
|
|
6008
|
+
const cur = this.input.selectionStart ?? this.input.value.length;
|
|
6009
|
+
this.applyFormatted(this.input.value, cur, false, true);
|
|
6010
|
+
this.checkSelection();
|
|
6011
|
+
}
|
|
6012
|
+
enforceMinCursor() {
|
|
6013
|
+
const minPos = this.engine.getPrefixLength();
|
|
6014
|
+
if (minPos <= 0) return;
|
|
6015
|
+
const start = this.input.selectionStart ?? 0;
|
|
6016
|
+
const end = this.input.selectionEnd ?? start;
|
|
6017
|
+
if (start !== end) return;
|
|
6018
|
+
if (start < minPos) {
|
|
6019
|
+
this.input.setSelectionRange(minPos, minPos);
|
|
3442
6020
|
}
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
6021
|
+
}
|
|
6022
|
+
// ==========================================================================
|
|
6023
|
+
// Synchronisation & Notifications
|
|
6024
|
+
// ==========================================================================
|
|
6025
|
+
updateGhost(formatted) {
|
|
6026
|
+
if (!this.ghost) return;
|
|
6027
|
+
if (this.options.disabled || this.isSensitiveField()) {
|
|
3446
6028
|
this.clearGhost();
|
|
3447
6029
|
return;
|
|
3448
6030
|
}
|
|
3449
|
-
this.
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
6031
|
+
const isCleanEmpty = !formatted || formatted === this.engine.getPrefix();
|
|
6032
|
+
if (this.shouldHideGhostForPlaceholder(isCleanEmpty)) {
|
|
6033
|
+
this.clearGhost();
|
|
6034
|
+
return;
|
|
3453
6035
|
}
|
|
3454
|
-
this.
|
|
6036
|
+
const remaining = this.engine.getGhostRemaining(formatted);
|
|
6037
|
+
const doc = this.input.ownerDocument || document;
|
|
6038
|
+
const spanTyped = doc.createElement("span");
|
|
6039
|
+
spanTyped.className = "mask-ghost-typed";
|
|
6040
|
+
spanTyped.textContent = formatted;
|
|
6041
|
+
const spanRemaining = doc.createElement("span");
|
|
6042
|
+
spanRemaining.className = "mask-ghost-remaining";
|
|
6043
|
+
spanRemaining.textContent = remaining;
|
|
6044
|
+
this.setGhostContent(spanTyped, spanRemaining);
|
|
6045
|
+
this.ghost.scrollLeft = this.input.scrollLeft;
|
|
3455
6046
|
}
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
6047
|
+
applyFormatted(rawOrPartial, cursorPosition, forceExactCursor = false, expandSingleMeridiem = false) {
|
|
6048
|
+
if (this.options.disabled || this.isApplying) return;
|
|
6049
|
+
this.isApplying = true;
|
|
6050
|
+
try {
|
|
6051
|
+
const formatted = this.engine.format(rawOrPartial, expandSingleMeridiem);
|
|
6052
|
+
const isSensitive = this.isSensitiveField();
|
|
6053
|
+
this.setNativeValue(formatted);
|
|
6054
|
+
if (isSensitive) {
|
|
6055
|
+
this.clearGhost();
|
|
6056
|
+
} else {
|
|
6057
|
+
this.updateGhost(formatted);
|
|
6058
|
+
}
|
|
6059
|
+
const minPos = this.engine.getPrefixLength();
|
|
6060
|
+
let safeCursor;
|
|
6061
|
+
if (forceExactCursor || this.isUndoingRedoing) {
|
|
6062
|
+
safeCursor = Math.max(minPos, Math.min(cursorPosition, formatted.length));
|
|
6063
|
+
} else {
|
|
6064
|
+
safeCursor = Math.max(minPos, this.engine.mapCursorPosition(rawOrPartial, cursorPosition, formatted));
|
|
6065
|
+
}
|
|
6066
|
+
this.input.setSelectionRange(safeCursor, safeCursor);
|
|
6067
|
+
const analysis = this.engine.analyze(formatted, false);
|
|
6068
|
+
this.wrapper.classList.toggle("is-complete", analysis.isComplete);
|
|
6069
|
+
if (isSensitive) {
|
|
6070
|
+
this.options.copyRaw = false;
|
|
6071
|
+
this.lastValueLength = 0;
|
|
6072
|
+
this.history.clear();
|
|
6073
|
+
} else {
|
|
6074
|
+
this.lastValueLength = formatted.length;
|
|
6075
|
+
if (!this.isUndoingRedoing) {
|
|
6076
|
+
this.history.push(this.engine.extractRaw(formatted, false), safeCursor);
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
} finally {
|
|
6080
|
+
this.isApplying = false;
|
|
3470
6081
|
}
|
|
6082
|
+
this.checkValueChange(false);
|
|
3471
6083
|
}
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
const str = val !== null && val !== void 0 ? String(val) : "";
|
|
3481
|
-
this.setNativeValue(str);
|
|
3482
|
-
this.updateSuggestion();
|
|
3483
|
-
}
|
|
3484
|
-
destroy() {
|
|
3485
|
-
if (this.isDestroyed) return;
|
|
3486
|
-
if (this.cutTimerId !== null) {
|
|
3487
|
-
clearTimeout(this.cutTimerId);
|
|
3488
|
-
this.cutTimerId = null;
|
|
3489
|
-
}
|
|
3490
|
-
if (this.resetTimerId !== null) {
|
|
3491
|
-
clearTimeout(this.resetTimerId);
|
|
3492
|
-
this.resetTimerId = null;
|
|
3493
|
-
}
|
|
3494
|
-
if (this.srAnnounceTimerId !== null) {
|
|
3495
|
-
clearTimeout(this.srAnnounceTimerId);
|
|
3496
|
-
this.srAnnounceTimerId = null;
|
|
3497
|
-
}
|
|
3498
|
-
if (this.srStatusEl) {
|
|
3499
|
-
this.srStatusEl.remove();
|
|
3500
|
-
this.srStatusEl = null;
|
|
3501
|
-
}
|
|
3502
|
-
this.lastNotifiedValue = "";
|
|
3503
|
-
this.lastAnnouncedSuggestion = "";
|
|
3504
|
-
if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "email") {
|
|
3505
|
-
this.input.removeAttribute("inputmode");
|
|
6084
|
+
syncInitialValue() {
|
|
6085
|
+
const isSensitive = this.isSensitiveField();
|
|
6086
|
+
if (this.options.disabled) {
|
|
6087
|
+
this.clearGhost();
|
|
6088
|
+
this.lastValue = isSensitive ? this.computePasswordDigest(this.input.value) : this.input.value;
|
|
6089
|
+
this.lastValueLength = isSensitive ? 0 : this.input.value.length;
|
|
6090
|
+
this.checkValueChange(false);
|
|
6091
|
+
return;
|
|
3506
6092
|
}
|
|
3507
|
-
|
|
3508
|
-
|
|
6093
|
+
this.syncGhostStyles();
|
|
6094
|
+
const initialVal = this.input.value || "";
|
|
6095
|
+
if (initialVal) {
|
|
6096
|
+
const formatted = this.engine.formatFromValue(initialVal);
|
|
6097
|
+
this.applyFormatted(formatted, formatted.length, true);
|
|
6098
|
+
} else {
|
|
6099
|
+
const minPos = this.engine.getPrefixLength();
|
|
6100
|
+
if (minPos > 0) {
|
|
6101
|
+
this.applyFormatted("", minPos, true);
|
|
6102
|
+
} else {
|
|
6103
|
+
if (!isSensitive) {
|
|
6104
|
+
this.history.push("", 0);
|
|
6105
|
+
this.updateGhost("");
|
|
6106
|
+
} else {
|
|
6107
|
+
this.clearGhost();
|
|
6108
|
+
}
|
|
6109
|
+
this.checkValueChange(false);
|
|
6110
|
+
}
|
|
3509
6111
|
}
|
|
3510
|
-
|
|
3511
|
-
|
|
6112
|
+
}
|
|
6113
|
+
checkValueChange(forceNotify = false, emitChangeEvent = false) {
|
|
6114
|
+
const initialSensitive = this.isSensitiveField();
|
|
6115
|
+
const currentVal = this.input.value;
|
|
6116
|
+
const currentComparison = initialSensitive ? this.computePasswordDigest(currentVal) : currentVal;
|
|
6117
|
+
if (currentComparison === this.lastValue && !forceNotify && !this.hasPendingNotification) {
|
|
6118
|
+
if (emitChangeEvent) {
|
|
6119
|
+
const allowBubble = !initialSensitive;
|
|
6120
|
+
const detail = this.getDetail();
|
|
6121
|
+
const onChangeCb = this.options.onChange || this.options.onchange;
|
|
6122
|
+
if (onChangeCb) onChangeCb(detail);
|
|
6123
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
6124
|
+
}
|
|
6125
|
+
return;
|
|
3512
6126
|
}
|
|
3513
|
-
if (this.
|
|
3514
|
-
this.
|
|
6127
|
+
if (this.isNotifying) {
|
|
6128
|
+
this.hasPendingNotification = true;
|
|
6129
|
+
return;
|
|
3515
6130
|
}
|
|
3516
|
-
|
|
3517
|
-
|
|
6131
|
+
this.isNotifying = true;
|
|
6132
|
+
try {
|
|
6133
|
+
let iterations = 0;
|
|
6134
|
+
while (((this.isSensitiveField() ? this.computePasswordDigest(this.input.value) : this.input.value) !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS3) {
|
|
6135
|
+
iterations++;
|
|
6136
|
+
this.hasPendingNotification = false;
|
|
6137
|
+
forceNotify = false;
|
|
6138
|
+
const sensitiveNow = this.isSensitiveField();
|
|
6139
|
+
const allowBubble = !sensitiveNow;
|
|
6140
|
+
const valToNotify = this.input.value;
|
|
6141
|
+
this.lastValue = sensitiveNow ? this.computePasswordDigest(valToNotify) : valToNotify;
|
|
6142
|
+
this.lastValueLength = sensitiveNow ? 0 : valToNotify.length;
|
|
6143
|
+
const detail = this.getDetail();
|
|
6144
|
+
const onInputCb = this.options.onInput || this.options.oninput;
|
|
6145
|
+
if (onInputCb) onInputCb(detail);
|
|
6146
|
+
this.input.dispatchEvent(new CustomEvent("mask:input", { bubbles: allowBubble, detail }));
|
|
6147
|
+
this.dispatchNativeInput();
|
|
6148
|
+
if (emitChangeEvent) {
|
|
6149
|
+
const onChangeCb = this.options.onChange || this.options.onchange;
|
|
6150
|
+
if (onChangeCb) onChangeCb(detail);
|
|
6151
|
+
this.input.dispatchEvent(new CustomEvent("mask:change", { bubbles: allowBubble, detail }));
|
|
6152
|
+
}
|
|
6153
|
+
if (detail.isComplete) {
|
|
6154
|
+
const onCompleteCb = this.options.onComplete || this.options.oncomplete;
|
|
6155
|
+
if (onCompleteCb) onCompleteCb(detail);
|
|
6156
|
+
this.input.dispatchEvent(new CustomEvent("mask:complete", { bubbles: allowBubble, detail }));
|
|
6157
|
+
}
|
|
6158
|
+
}
|
|
6159
|
+
} finally {
|
|
6160
|
+
this.isNotifying = false;
|
|
3518
6161
|
}
|
|
3519
|
-
super.destroy();
|
|
3520
6162
|
}
|
|
3521
6163
|
};
|
|
3522
6164
|
|
|
@@ -3530,7 +6172,12 @@ var Mask = {
|
|
|
3530
6172
|
AmountEngine,
|
|
3531
6173
|
InputAmountMask,
|
|
3532
6174
|
EmailEngine,
|
|
3533
|
-
InputEmailMask
|
|
6175
|
+
InputEmailMask,
|
|
6176
|
+
DateUTCEngine,
|
|
6177
|
+
DATE_UTC_PRESETS,
|
|
6178
|
+
InputDateUTCMask,
|
|
6179
|
+
sanitizePastedText,
|
|
6180
|
+
stripBidiAndInvisibles
|
|
3534
6181
|
};
|
|
3535
6182
|
var wulfNamespace = getSafeWulfNamespace();
|
|
3536
6183
|
if (wulfNamespace) {
|
|
@@ -4461,8 +7108,8 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
4461
7108
|
if (el) {
|
|
4462
7109
|
const vpRect = this.viewport.getBoundingClientRect();
|
|
4463
7110
|
const elRect = el.getBoundingClientRect();
|
|
4464
|
-
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
4465
|
-
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
7111
|
+
targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
|
|
7112
|
+
targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
|
|
4466
7113
|
}
|
|
4467
7114
|
break;
|
|
4468
7115
|
}
|
|
@@ -4470,8 +7117,8 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
4470
7117
|
} else if (target instanceof HTMLElement) {
|
|
4471
7118
|
const vpRect = this.viewport.getBoundingClientRect();
|
|
4472
7119
|
const elRect = target.getBoundingClientRect();
|
|
4473
|
-
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
4474
|
-
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
7120
|
+
targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
|
|
7121
|
+
targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
|
|
4475
7122
|
} else if (typeof target === "object" && target !== null) {
|
|
4476
7123
|
targetTop = target.top;
|
|
4477
7124
|
targetLeft = target.left;
|
|
@@ -5715,6 +8362,9 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
5715
8362
|
this.isPausedByFocus = false;
|
|
5716
8363
|
} else if (source === "hover") {
|
|
5717
8364
|
this.isPausedByHover = false;
|
|
8365
|
+
if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
|
|
8366
|
+
this.isPausedByFocus = true;
|
|
8367
|
+
}
|
|
5718
8368
|
} else {
|
|
5719
8369
|
this.isPausedByHover = false;
|
|
5720
8370
|
this.isPausedByFocus = false;
|
|
@@ -7427,9 +10077,12 @@ export {
|
|
|
7427
10077
|
AmountEngine,
|
|
7428
10078
|
AuditableComponent,
|
|
7429
10079
|
BaseInputMask,
|
|
10080
|
+
DATE_UTC_PRESETS,
|
|
10081
|
+
DateUTCEngine,
|
|
7430
10082
|
EmailEngine,
|
|
7431
10083
|
focus_trap_exports as FocusTrap,
|
|
7432
10084
|
InputAmountMask,
|
|
10085
|
+
InputDateUTCMask,
|
|
7433
10086
|
InputEmailMask,
|
|
7434
10087
|
InputMask,
|
|
7435
10088
|
LayoutEngine,
|
|
@@ -7458,9 +10111,10 @@ export {
|
|
|
7458
10111
|
isImeComposing,
|
|
7459
10112
|
parseCssDurationMs,
|
|
7460
10113
|
prefersReducedMotion,
|
|
7461
|
-
resolveMaskConstructorArgs,
|
|
7462
10114
|
safeCssEscape,
|
|
7463
10115
|
safeMove,
|
|
10116
|
+
sanitizePastedText,
|
|
10117
|
+
stripBidiAndInvisibles,
|
|
7464
10118
|
waitForAnimations
|
|
7465
10119
|
};
|
|
7466
10120
|
//# sourceMappingURL=index.esm.js.map
|