wulf.js 1.8.4 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -21
- package/changelog.md +76 -0
- package/dist/focus-trap.cjs.js +430 -0
- package/dist/focus-trap.cjs.js.map +7 -0
- package/dist/focus-trap.esm.js +407 -0
- package/dist/focus-trap.esm.js.map +7 -0
- package/dist/focus-trap.global.js +433 -0
- package/dist/focus-trap.global.js.map +7 -0
- package/dist/focus-trap.global.min.js +6 -0
- package/dist/focus-trap.global.min.js.map +7 -0
- package/dist/index.cjs.js +1177 -59
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.esm.js +1177 -59
- package/dist/index.esm.js.map +3 -3
- package/dist/index.global.js +1177 -59
- package/dist/index.global.js.map +3 -3
- package/dist/index.global.min.js +4 -1
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.cjs.js +337 -33
- package/dist/mask.cjs.js.map +3 -3
- package/dist/mask.css +1 -1
- package/dist/mask.css.map +2 -2
- package/dist/mask.esm.js +337 -33
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +337 -33
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +4 -1
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.cjs.js +296 -10
- package/dist/masonry.cjs.js.map +3 -3
- package/dist/masonry.esm.js +296 -10
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +296 -10
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -1
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.cjs.js +332 -9
- package/dist/scroll.cjs.js.map +3 -3
- package/dist/scroll.esm.js +332 -9
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +332 -9
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +4 -1
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/toast.cjs.js +289 -7
- package/dist/toast.cjs.js.map +3 -3
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +289 -7
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +289 -7
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +4 -1
- package/dist/toast.global.min.js.map +4 -4
- package/dist/types/common/AuditableComponent.d.ts +45 -0
- package/dist/types/common/LocalizedComponent.d.ts +54 -0
- package/dist/types/common/i18n.d.ts +39 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +64 -0
- package/dist/types/focus-trap/index.d.ts +3 -0
- package/dist/types/focus-trap/types.d.ts +45 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mask/BaseInputMask.d.ts +15 -1
- package/dist/types/mask/EmailEngine.d.ts +24 -2
- package/dist/types/mask/InputEmailMask.d.ts +8 -0
- package/dist/types/mask/InputMask.d.ts +9 -0
- package/dist/types/mask/types.d.ts +5 -2
- package/dist/types/masonry/Masonry.d.ts +18 -1
- package/dist/types/masonry/i18n/en.d.ts +2 -0
- package/dist/types/masonry/i18n/fr.d.ts +2 -0
- package/dist/types/masonry/i18n/index.d.ts +9 -0
- package/dist/types/masonry/i18n/types.d.ts +7 -0
- package/dist/types/masonry/index.d.ts +1 -0
- package/dist/types/masonry/types.d.ts +15 -5
- package/dist/types/scroll/ScrollBlock.d.ts +21 -1
- package/dist/types/scroll/i18n/en.d.ts +2 -0
- package/dist/types/scroll/i18n/fr.d.ts +2 -0
- package/dist/types/scroll/i18n/index.d.ts +9 -0
- package/dist/types/scroll/i18n/types.d.ts +11 -0
- package/dist/types/scroll/index.d.ts +2 -0
- package/dist/types/scroll/types.d.ts +9 -3
- package/dist/types/toast/Toast.d.ts +8 -1
- package/dist/types/toast/ToastInstance.d.ts +9 -1
- package/dist/types/toast/i18n/en.d.ts +2 -0
- package/dist/types/toast/i18n/fr.d.ts +2 -0
- package/dist/types/toast/i18n/index.d.ts +9 -0
- package/dist/types/toast/i18n/types.d.ts +7 -0
- package/dist/types/toast/index.d.ts +1 -0
- package/dist/types/toast/types.d.ts +12 -3
- package/package.json +9 -3
package/dist/index.global.js
CHANGED
|
@@ -22,11 +22,14 @@ var Wulf = (() => {
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
AmountEngine: () => AmountEngine,
|
|
25
|
+
AuditableComponent: () => AuditableComponent,
|
|
25
26
|
BaseInputMask: () => BaseInputMask,
|
|
26
27
|
EmailEngine: () => EmailEngine,
|
|
28
|
+
FocusTrap: () => focus_trap_exports,
|
|
27
29
|
InputAmountMask: () => InputAmountMask,
|
|
28
30
|
InputEmailMask: () => InputEmailMask,
|
|
29
31
|
InputMask: () => InputMask,
|
|
32
|
+
LocalizedComponent: () => LocalizedComponent,
|
|
30
33
|
Mask: () => mask_exports,
|
|
31
34
|
MaskEngine: () => MaskEngine,
|
|
32
35
|
MaskHistory: () => MaskHistory,
|
|
@@ -34,6 +37,8 @@ var Wulf = (() => {
|
|
|
34
37
|
Masonry: () => masonry_exports,
|
|
35
38
|
Scroll: () => scroll_exports,
|
|
36
39
|
Toast: () => toast_exports,
|
|
40
|
+
WulfFocusTrap: () => FocusTrap,
|
|
41
|
+
createI18nManager: () => createI18nManager,
|
|
37
42
|
default: () => mask_default,
|
|
38
43
|
resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
|
|
39
44
|
});
|
|
@@ -55,6 +60,49 @@ var Wulf = (() => {
|
|
|
55
60
|
resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
|
|
56
61
|
});
|
|
57
62
|
|
|
63
|
+
// src/common/AuditableComponent.ts
|
|
64
|
+
var AuditableComponent = class {
|
|
65
|
+
/**
|
|
66
|
+
* Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
|
|
67
|
+
*/
|
|
68
|
+
getAuditDisableHint() {
|
|
69
|
+
return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
|
|
73
|
+
* si l'audit est activé et que des contraintes manquent.
|
|
74
|
+
*/
|
|
75
|
+
runAuditWarning(enabled = true) {
|
|
76
|
+
if (!enabled) return [];
|
|
77
|
+
const warnings = this.audit();
|
|
78
|
+
if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
|
|
79
|
+
console.warn(
|
|
80
|
+
`[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
|
|
81
|
+
` + warnings.map((w) => ` - ${w}`).join("\n") + `
|
|
82
|
+
(${this.getAuditDisableHint()})`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return warnings;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
|
|
89
|
+
* pointe vers des éléments réellement présents dans le document.
|
|
90
|
+
*/
|
|
91
|
+
checkAriaIdReferences(element, attrName, warnings) {
|
|
92
|
+
const rawValue = element.getAttribute(attrName)?.trim();
|
|
93
|
+
if (!rawValue) return false;
|
|
94
|
+
const doc = element.ownerDocument || document;
|
|
95
|
+
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
96
|
+
const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
|
|
97
|
+
if (!isValid) {
|
|
98
|
+
warnings.push(
|
|
99
|
+
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return isValid;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
58
106
|
// src/mask/BaseInputMask.ts
|
|
59
107
|
function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
60
108
|
const isSecondArgInput = Boolean(
|
|
@@ -73,8 +121,9 @@ var Wulf = (() => {
|
|
|
73
121
|
options: inputOrOptions && typeof inputOrOptions === "object" && !("tagName" in inputOrOptions) ? inputOrOptions : {}
|
|
74
122
|
};
|
|
75
123
|
}
|
|
76
|
-
var BaseInputMask = class {
|
|
124
|
+
var BaseInputMask = class extends AuditableComponent {
|
|
77
125
|
constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
|
|
126
|
+
super();
|
|
78
127
|
this.ghost = null;
|
|
79
128
|
this.isWrapperCreated = false;
|
|
80
129
|
this.isDestroyed = false;
|
|
@@ -85,6 +134,7 @@ var Wulf = (() => {
|
|
|
85
134
|
this.onCutHandler = () => {
|
|
86
135
|
};
|
|
87
136
|
this.mutationObserver = null;
|
|
137
|
+
this.focusSelectTimerId = null;
|
|
88
138
|
this.onBaseCopy = (e) => {
|
|
89
139
|
if (!this.options.copyRaw || this.options.disabled || this.input.type === "password") return;
|
|
90
140
|
const start = this.input.selectionStart ?? 0;
|
|
@@ -103,7 +153,11 @@ var Wulf = (() => {
|
|
|
103
153
|
this.onBaseFocus = () => {
|
|
104
154
|
this.isFocused = true;
|
|
105
155
|
if (this.options.selectAllOnFocus && this.input.value.length > 0) {
|
|
106
|
-
|
|
156
|
+
if (this.focusSelectTimerId !== null) {
|
|
157
|
+
clearTimeout(this.focusSelectTimerId);
|
|
158
|
+
}
|
|
159
|
+
this.focusSelectTimerId = window.setTimeout(() => {
|
|
160
|
+
this.focusSelectTimerId = null;
|
|
107
161
|
if (!this.isDestroyed && document.activeElement === this.input) {
|
|
108
162
|
this.input.select();
|
|
109
163
|
}
|
|
@@ -122,7 +176,7 @@ var Wulf = (() => {
|
|
|
122
176
|
}
|
|
123
177
|
};
|
|
124
178
|
const { wrapper: providedWrapper, input, options } = resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions);
|
|
125
|
-
if (!input ||
|
|
179
|
+
if (!input || typeof input !== "object" || input.nodeType !== 1 || input.tagName !== "INPUT") {
|
|
126
180
|
throw new Error(`[${new.target.name || "InputMask"}] input (HTMLInputElement) est requis.`);
|
|
127
181
|
}
|
|
128
182
|
this.input = input;
|
|
@@ -157,8 +211,10 @@ var Wulf = (() => {
|
|
|
157
211
|
const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
|
|
158
212
|
const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
|
|
159
213
|
const dataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
|
|
214
|
+
const dataAudit = this.getAttr("data-mask-audit");
|
|
160
215
|
const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
|
|
161
216
|
const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
|
|
217
|
+
const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
|
|
162
218
|
const isPassword = this.input.type === "password";
|
|
163
219
|
this.options = {
|
|
164
220
|
...otherOptions,
|
|
@@ -168,7 +224,8 @@ var Wulf = (() => {
|
|
|
168
224
|
copyRaw: isPassword ? false : options.copyRaw ?? dataCopyRaw ?? false,
|
|
169
225
|
disabled: resolvedDisabled,
|
|
170
226
|
align: optAlign ?? (dataAlign || void 0),
|
|
171
|
-
emitNativeInput: options.emitNativeInput ?? true
|
|
227
|
+
emitNativeInput: options.emitNativeInput ?? true,
|
|
228
|
+
audit: resolvedAudit
|
|
172
229
|
};
|
|
173
230
|
if (this.options.showMaskOnFocus) {
|
|
174
231
|
this.wrapper.classList.add("mask-focus-only");
|
|
@@ -247,6 +304,8 @@ var Wulf = (() => {
|
|
|
247
304
|
"data-mask-pad-decimals",
|
|
248
305
|
"data-mask-auto-lowercase",
|
|
249
306
|
"data-mask-cycle-suggestions",
|
|
307
|
+
"data-mask-default-tld",
|
|
308
|
+
"data-mask-tlds",
|
|
250
309
|
"data-disabled",
|
|
251
310
|
"data-mask-align",
|
|
252
311
|
"data-align",
|
|
@@ -511,12 +570,58 @@ var Wulf = (() => {
|
|
|
511
570
|
getRawValue() {
|
|
512
571
|
return this.input.value;
|
|
513
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
|
|
575
|
+
* et retourne la liste des contraintes manquantes.
|
|
576
|
+
*/
|
|
577
|
+
audit() {
|
|
578
|
+
const warnings = [];
|
|
579
|
+
const doc = this.input.ownerDocument || document;
|
|
580
|
+
const ariaLabel = this.input.getAttribute("aria-label")?.trim();
|
|
581
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
|
|
582
|
+
const hasWrappingLabel = Boolean(this.input.closest("label"));
|
|
583
|
+
const hasNativeLabels = Boolean(this.input.labels && this.input.labels.length > 0);
|
|
584
|
+
let hasExplicitLabelFor = false;
|
|
585
|
+
if (this.input.id && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
586
|
+
hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${CSS.escape(this.input.id)}"]`));
|
|
587
|
+
} else if (this.input.id) {
|
|
588
|
+
hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${this.input.id}"]`));
|
|
589
|
+
}
|
|
590
|
+
if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
|
|
591
|
+
warnings.push(
|
|
592
|
+
`\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
|
|
596
|
+
const extraWarnings = this.getSpecificAuditWarnings();
|
|
597
|
+
warnings.push(...extraWarnings);
|
|
598
|
+
return warnings;
|
|
599
|
+
}
|
|
600
|
+
getAuditPrefix() {
|
|
601
|
+
return `Wulf.Mask.${this.constructor.name || "InputMask"}`;
|
|
602
|
+
}
|
|
603
|
+
getAuditTargetLabel() {
|
|
604
|
+
return this.input.id ? `#${this.input.id}` : this.input.name ? `input[name="${this.input.name}"]` : "<input>";
|
|
605
|
+
}
|
|
606
|
+
getAuditDisableHint() {
|
|
607
|
+
return 'Passez { audit: false } ou data-mask-audit="false" pour d\xE9sactiver cet avertissement';
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Crochet permettant aux classes filles d'ajouter des vérifications d'audit spécifiques.
|
|
611
|
+
*/
|
|
612
|
+
getSpecificAuditWarnings() {
|
|
613
|
+
return [];
|
|
614
|
+
}
|
|
514
615
|
/**
|
|
515
616
|
* Supprime les éléments fantômes, restaure les propriétés et nettoie les attributs.
|
|
516
617
|
*/
|
|
517
618
|
destroy() {
|
|
518
619
|
if (this.isDestroyed) return;
|
|
519
620
|
this.isDestroyed = true;
|
|
621
|
+
if (this.focusSelectTimerId !== null) {
|
|
622
|
+
clearTimeout(this.focusSelectTimerId);
|
|
623
|
+
this.focusSelectTimerId = null;
|
|
624
|
+
}
|
|
520
625
|
if (this.mutationObserver) {
|
|
521
626
|
this.mutationObserver.disconnect();
|
|
522
627
|
this.mutationObserver = null;
|
|
@@ -1278,6 +1383,9 @@ var Wulf = (() => {
|
|
|
1278
1383
|
this.onChangeNativeHandler = () => {
|
|
1279
1384
|
};
|
|
1280
1385
|
this.wasInputModeInferred = false;
|
|
1386
|
+
this.cutTimerId = null;
|
|
1387
|
+
this.pasteTimerId = null;
|
|
1388
|
+
this.resetTimerId = null;
|
|
1281
1389
|
this.history = new MaskHistory();
|
|
1282
1390
|
this.engine = new MaskEngine(this.options.mask || "", {
|
|
1283
1391
|
placeholderChar: this.options.placeholderChar,
|
|
@@ -1285,12 +1393,7 @@ var Wulf = (() => {
|
|
|
1285
1393
|
strict: this.options.strict,
|
|
1286
1394
|
autoLowercase: this.options.autoLowercase
|
|
1287
1395
|
});
|
|
1288
|
-
|
|
1289
|
-
if (this.engine.isNumericOnly()) {
|
|
1290
|
-
this.input.inputMode = "numeric";
|
|
1291
|
-
this.wasInputModeInferred = true;
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1396
|
+
this.syncInferredInputMode();
|
|
1294
1397
|
this.keyboard = new MaskKeyboard({
|
|
1295
1398
|
getInput: () => this.input,
|
|
1296
1399
|
getEngine: () => this.engine,
|
|
@@ -1303,6 +1406,19 @@ var Wulf = (() => {
|
|
|
1303
1406
|
this.bindEvents();
|
|
1304
1407
|
this.lastValue = this.input.value;
|
|
1305
1408
|
this.syncInitialValue();
|
|
1409
|
+
this.runAuditWarning(this.options.audit);
|
|
1410
|
+
}
|
|
1411
|
+
getSpecificAuditWarnings() {
|
|
1412
|
+
const warnings = [];
|
|
1413
|
+
const hasDescribedby = Boolean(this.input.getAttribute("aria-describedby")?.trim());
|
|
1414
|
+
const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
|
|
1415
|
+
const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
|
|
1416
|
+
if (!hasDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
|
|
1417
|
+
warnings.push(
|
|
1418
|
+
"Indication du format attendu manquante : d\xE9finissez aria-describedby, placeholder ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
return warnings;
|
|
1306
1422
|
}
|
|
1307
1423
|
extractRawSnippet(snippet) {
|
|
1308
1424
|
return this.engine.extractRaw(snippet);
|
|
@@ -1354,7 +1470,9 @@ var Wulf = (() => {
|
|
|
1354
1470
|
this.onScroll = this.onScroll.bind(this);
|
|
1355
1471
|
this.onBeforeInput = this.onBeforeInput.bind(this);
|
|
1356
1472
|
this.onCutHandler = () => {
|
|
1357
|
-
|
|
1473
|
+
if (this.cutTimerId !== null) clearTimeout(this.cutTimerId);
|
|
1474
|
+
this.cutTimerId = window.setTimeout(() => {
|
|
1475
|
+
this.cutTimerId = null;
|
|
1358
1476
|
if (this.isDestroyed) return;
|
|
1359
1477
|
if (this.options.disabled) {
|
|
1360
1478
|
this.checkValueChange();
|
|
@@ -1386,7 +1504,9 @@ var Wulf = (() => {
|
|
|
1386
1504
|
this.input.addEventListener("change", this.onChangeNativeHandler);
|
|
1387
1505
|
if (this.input.form) {
|
|
1388
1506
|
this.onFormResetHandler = () => {
|
|
1389
|
-
|
|
1507
|
+
if (this.resetTimerId !== null) clearTimeout(this.resetTimerId);
|
|
1508
|
+
this.resetTimerId = window.setTimeout(() => {
|
|
1509
|
+
this.resetTimerId = null;
|
|
1390
1510
|
if (this.isDestroyed) return;
|
|
1391
1511
|
if (this.options.disabled) {
|
|
1392
1512
|
this.checkValueChange();
|
|
@@ -1398,11 +1518,40 @@ var Wulf = (() => {
|
|
|
1398
1518
|
this.input.form.addEventListener("reset", this.onFormResetHandler);
|
|
1399
1519
|
}
|
|
1400
1520
|
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Synchronise dynamiquement l'attribut inputmode="numeric" selon le motif actif
|
|
1523
|
+
* sans jamais écraser un inputmode défini explicitement par l'hôte.
|
|
1524
|
+
*/
|
|
1525
|
+
syncInferredInputMode() {
|
|
1526
|
+
if (!this.options.inferInputMode) return;
|
|
1527
|
+
const isNum = !this.options.disabled && this.engine.isNumericOnly();
|
|
1528
|
+
if (isNum) {
|
|
1529
|
+
if (!this.input.hasAttribute("inputmode")) {
|
|
1530
|
+
this.input.inputMode = "numeric";
|
|
1531
|
+
this.wasInputModeInferred = true;
|
|
1532
|
+
}
|
|
1533
|
+
} else if (this.wasInputModeInferred && this.input.getAttribute("inputmode") === "numeric") {
|
|
1534
|
+
this.input.removeAttribute("inputmode");
|
|
1535
|
+
this.wasInputModeInferred = false;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1401
1538
|
/**
|
|
1402
1539
|
* Supprime tous les écouteurs et nettoie les attributs associés.
|
|
1403
1540
|
*/
|
|
1404
1541
|
destroy() {
|
|
1405
1542
|
if (this.isDestroyed) return;
|
|
1543
|
+
if (this.cutTimerId !== null) {
|
|
1544
|
+
clearTimeout(this.cutTimerId);
|
|
1545
|
+
this.cutTimerId = null;
|
|
1546
|
+
}
|
|
1547
|
+
if (this.pasteTimerId !== null) {
|
|
1548
|
+
clearTimeout(this.pasteTimerId);
|
|
1549
|
+
this.pasteTimerId = null;
|
|
1550
|
+
}
|
|
1551
|
+
if (this.resetTimerId !== null) {
|
|
1552
|
+
clearTimeout(this.resetTimerId);
|
|
1553
|
+
this.resetTimerId = null;
|
|
1554
|
+
}
|
|
1406
1555
|
this.input.removeEventListener("beforeinput", this.onBeforeInput);
|
|
1407
1556
|
this.input.removeEventListener("input", this.handleInput);
|
|
1408
1557
|
this.input.removeEventListener("keydown", this.onKeyDown);
|
|
@@ -1464,6 +1613,7 @@ var Wulf = (() => {
|
|
|
1464
1613
|
this.history.clear();
|
|
1465
1614
|
}
|
|
1466
1615
|
this.setDisabled(true);
|
|
1616
|
+
this.syncInferredInputMode();
|
|
1467
1617
|
return;
|
|
1468
1618
|
}
|
|
1469
1619
|
this.options.mask = newPattern;
|
|
@@ -1474,6 +1624,7 @@ var Wulf = (() => {
|
|
|
1474
1624
|
this.history.clear();
|
|
1475
1625
|
}
|
|
1476
1626
|
this.setDisabled(false);
|
|
1627
|
+
this.syncInferredInputMode();
|
|
1477
1628
|
}
|
|
1478
1629
|
handleAttributeMutation(attrName) {
|
|
1479
1630
|
super.handleAttributeMutation(attrName);
|
|
@@ -1631,7 +1782,9 @@ var Wulf = (() => {
|
|
|
1631
1782
|
}
|
|
1632
1783
|
onPaste(e) {
|
|
1633
1784
|
if (this.options.disabled) {
|
|
1634
|
-
|
|
1785
|
+
if (this.pasteTimerId !== null) clearTimeout(this.pasteTimerId);
|
|
1786
|
+
this.pasteTimerId = window.setTimeout(() => {
|
|
1787
|
+
this.pasteTimerId = null;
|
|
1635
1788
|
if (!this.isDestroyed) this.checkValueChange();
|
|
1636
1789
|
}, 0);
|
|
1637
1790
|
return;
|
|
@@ -2115,6 +2268,7 @@ var Wulf = (() => {
|
|
|
2115
2268
|
isValid: true
|
|
2116
2269
|
});
|
|
2117
2270
|
}
|
|
2271
|
+
this.runAuditWarning(this.options.audit);
|
|
2118
2272
|
}
|
|
2119
2273
|
extractRawSnippet(snippet) {
|
|
2120
2274
|
const p = this.engine.parse(snippet);
|
|
@@ -2440,9 +2594,12 @@ var Wulf = (() => {
|
|
|
2440
2594
|
var _EmailEngine = class _EmailEngine {
|
|
2441
2595
|
constructor(options = {}) {
|
|
2442
2596
|
this.defaultDomain = null;
|
|
2597
|
+
this.defaultTld = "__";
|
|
2443
2598
|
this.domains = options.domains && options.domains.length > 0 ? options.domains : _EmailEngine.DEFAULT_DOMAINS;
|
|
2599
|
+
this.tlds = options.tlds && options.tlds.length > 0 ? options.tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
|
|
2444
2600
|
this.suggestOnAt = options.suggestOnAt ?? true;
|
|
2445
2601
|
this.setDefaultDomain(options.defaultDomain ?? null);
|
|
2602
|
+
this.setDefaultTld(options.defaultTld !== void 0 ? options.defaultTld : "__");
|
|
2446
2603
|
}
|
|
2447
2604
|
/**
|
|
2448
2605
|
* Définit ou modifie le domaine suggéré par défaut.
|
|
@@ -2456,6 +2613,35 @@ var Wulf = (() => {
|
|
|
2456
2613
|
this.defaultDomain = null;
|
|
2457
2614
|
}
|
|
2458
2615
|
}
|
|
2616
|
+
/**
|
|
2617
|
+
* Définit ou modifie l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
|
|
2618
|
+
*/
|
|
2619
|
+
setDefaultTld(tld) {
|
|
2620
|
+
if (tld === true) {
|
|
2621
|
+
this.defaultTld = this.tlds.length > 0 ? this.tlds[0] : null;
|
|
2622
|
+
} else if (typeof tld === "string" && tld.trim().length > 0) {
|
|
2623
|
+
this.defaultTld = tld.trim().replace(/^\./, "");
|
|
2624
|
+
} else {
|
|
2625
|
+
this.defaultTld = null;
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
* Définit ou modifie la liste des extensions (TLD) proposées par ordre de priorité.
|
|
2630
|
+
*/
|
|
2631
|
+
setTlds(tlds) {
|
|
2632
|
+
this.tlds = tlds && tlds.length > 0 ? tlds.map((t) => t.trim().replace(/^\./, "")).filter(Boolean) : [..._EmailEngine.DEFAULT_TLDS];
|
|
2633
|
+
}
|
|
2634
|
+
/**
|
|
2635
|
+
* Retourne l'ensemble des extensions (TLD) correspondant au fragment saisi après le dernier point,
|
|
2636
|
+
* dans l'ordre exact fourni par l'utilisateur.
|
|
2637
|
+
*/
|
|
2638
|
+
getMatchingTlds(tldInput) {
|
|
2639
|
+
const query = (tldInput ?? "").toLowerCase();
|
|
2640
|
+
if (query.length === 0) {
|
|
2641
|
+
return [...this.tlds];
|
|
2642
|
+
}
|
|
2643
|
+
return this.tlds.filter((t) => t.toLowerCase().startsWith(query) && t.toLowerCase() !== query);
|
|
2644
|
+
}
|
|
2459
2645
|
/**
|
|
2460
2646
|
* Retourne l'ensemble des domaines correspondant à la saisie courante.
|
|
2461
2647
|
*/
|
|
@@ -2476,10 +2662,10 @@ var Wulf = (() => {
|
|
|
2476
2662
|
return this.domains.filter((d) => d.toLowerCase().startsWith(query) && d.toLowerCase() !== query);
|
|
2477
2663
|
}
|
|
2478
2664
|
/**
|
|
2479
|
-
* Analyse la saisie courante et calcule la suggestion de domaine adaptée.
|
|
2665
|
+
* Analyse la saisie courante et calcule la suggestion de domaine ou d'extension (TLD) adaptée.
|
|
2480
2666
|
*
|
|
2481
2667
|
* @param input Saisie utilisateur
|
|
2482
|
-
* @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines correspondent (permet le cyclage)
|
|
2668
|
+
* @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines/TLD correspondent (permet le cyclage)
|
|
2483
2669
|
*/
|
|
2484
2670
|
getSuggestion(input, matchIndex = 0) {
|
|
2485
2671
|
const val = input ?? "";
|
|
@@ -2488,30 +2674,104 @@ var Wulf = (() => {
|
|
|
2488
2674
|
return {
|
|
2489
2675
|
full: val ? `${val}@${this.defaultDomain}` : `@${this.defaultDomain}`,
|
|
2490
2676
|
remaining: `@${this.defaultDomain}`,
|
|
2491
|
-
matchedDomain: this.defaultDomain
|
|
2677
|
+
matchedDomain: this.defaultDomain,
|
|
2678
|
+
isHintOnly: false
|
|
2492
2679
|
};
|
|
2493
2680
|
}
|
|
2494
|
-
return { full: val, remaining: "", matchedDomain: null };
|
|
2681
|
+
return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2495
2682
|
}
|
|
2496
2683
|
const atIndex = val.indexOf("@");
|
|
2497
2684
|
const localPart = val.substring(0, atIndex);
|
|
2498
2685
|
const domainPart = val.substring(atIndex + 1);
|
|
2499
2686
|
if (val.indexOf("@", atIndex + 1) !== -1) {
|
|
2500
|
-
return { full: val, remaining: "", matchedDomain: null };
|
|
2687
|
+
return { full: val, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2501
2688
|
}
|
|
2502
2689
|
const matches = this.getMatchingDomains(input);
|
|
2503
|
-
if (matches.length
|
|
2504
|
-
|
|
2690
|
+
if (matches.length > 0) {
|
|
2691
|
+
const safeIndex = (matchIndex % matches.length + matches.length) % matches.length;
|
|
2692
|
+
const matched = matches[safeIndex];
|
|
2693
|
+
const query = domainPart.toLowerCase();
|
|
2694
|
+
const remaining = matched.substring(query.length);
|
|
2695
|
+
return {
|
|
2696
|
+
full: `${localPart}@${matched}`,
|
|
2697
|
+
remaining,
|
|
2698
|
+
matchedDomain: matched,
|
|
2699
|
+
isHintOnly: false
|
|
2700
|
+
};
|
|
2505
2701
|
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
const
|
|
2510
|
-
|
|
2511
|
-
full:
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2702
|
+
if (domainPart.length === 0 || domainPart.startsWith(".")) {
|
|
2703
|
+
return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2704
|
+
}
|
|
2705
|
+
const lowerDomain = domainPart.toLowerCase();
|
|
2706
|
+
if (this.domains.some((d) => d.toLowerCase() === lowerDomain)) {
|
|
2707
|
+
return { full: input, remaining: "", matchedDomain: domainPart, isHintOnly: false };
|
|
2708
|
+
}
|
|
2709
|
+
const lastDotIndex = domainPart.lastIndexOf(".");
|
|
2710
|
+
if (lastDotIndex === -1) {
|
|
2711
|
+
if (!this.defaultTld) {
|
|
2712
|
+
return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2713
|
+
}
|
|
2714
|
+
const isHint = this.defaultTld.includes("_");
|
|
2715
|
+
const remaining = `.${this.defaultTld}`;
|
|
2716
|
+
const fullDomain = `${domainPart}.${this.defaultTld}`;
|
|
2717
|
+
return {
|
|
2718
|
+
full: isHint ? input : `${localPart}@${fullDomain}`,
|
|
2719
|
+
remaining,
|
|
2720
|
+
matchedDomain: isHint ? null : fullDomain,
|
|
2721
|
+
isHintOnly: isHint
|
|
2722
|
+
};
|
|
2723
|
+
}
|
|
2724
|
+
const hostPart = domainPart.substring(0, lastDotIndex);
|
|
2725
|
+
const tldPart = domainPart.substring(lastDotIndex + 1);
|
|
2726
|
+
if (!hostPart || hostPart.endsWith(".")) {
|
|
2727
|
+
return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2728
|
+
}
|
|
2729
|
+
if (tldPart.length === 0) {
|
|
2730
|
+
if (this.defaultTld && !this.defaultTld.includes("_")) {
|
|
2731
|
+
const fullDomain = `${hostPart}.${this.defaultTld}`;
|
|
2732
|
+
return {
|
|
2733
|
+
full: `${localPart}@${fullDomain}`,
|
|
2734
|
+
remaining: this.defaultTld,
|
|
2735
|
+
matchedDomain: fullDomain,
|
|
2736
|
+
isHintOnly: false
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
if (this.defaultTld && this.defaultTld.includes("_")) {
|
|
2740
|
+
return {
|
|
2741
|
+
full: input,
|
|
2742
|
+
remaining: this.defaultTld,
|
|
2743
|
+
matchedDomain: null,
|
|
2744
|
+
isHintOnly: true
|
|
2745
|
+
};
|
|
2746
|
+
}
|
|
2747
|
+
return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2748
|
+
}
|
|
2749
|
+
const lowerTld = tldPart.toLowerCase();
|
|
2750
|
+
const matchingTlds = this.getMatchingTlds(tldPart);
|
|
2751
|
+
if (matchingTlds.length > 0) {
|
|
2752
|
+
const safeTldIndex = (matchIndex % matchingTlds.length + matchingTlds.length) % matchingTlds.length;
|
|
2753
|
+
const matchedTld = matchingTlds[safeTldIndex];
|
|
2754
|
+
const remaining = matchedTld.substring(lowerTld.length);
|
|
2755
|
+
const fullDomain = `${hostPart}.${matchedTld}`;
|
|
2756
|
+
return {
|
|
2757
|
+
full: `${localPart}@${fullDomain}`,
|
|
2758
|
+
remaining,
|
|
2759
|
+
matchedDomain: fullDomain,
|
|
2760
|
+
isHintOnly: false
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
if (this.defaultTld && this.defaultTld.includes("_") && tldPart.length < this.defaultTld.length) {
|
|
2764
|
+
const remaining = this.defaultTld.substring(tldPart.length);
|
|
2765
|
+
if (remaining.includes("_")) {
|
|
2766
|
+
return {
|
|
2767
|
+
full: input,
|
|
2768
|
+
remaining,
|
|
2769
|
+
matchedDomain: null,
|
|
2770
|
+
isHintOnly: true
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
return { full: input, remaining: "", matchedDomain: null, isHintOnly: false };
|
|
2515
2775
|
}
|
|
2516
2776
|
};
|
|
2517
2777
|
_EmailEngine.DEFAULT_DOMAINS = [
|
|
@@ -2526,6 +2786,27 @@ var Wulf = (() => {
|
|
|
2526
2786
|
"laposte.net",
|
|
2527
2787
|
"proton.me"
|
|
2528
2788
|
];
|
|
2789
|
+
_EmailEngine.DEFAULT_TLDS = [
|
|
2790
|
+
"com",
|
|
2791
|
+
"fr",
|
|
2792
|
+
"net",
|
|
2793
|
+
"org",
|
|
2794
|
+
"eu",
|
|
2795
|
+
"io",
|
|
2796
|
+
"co",
|
|
2797
|
+
"info",
|
|
2798
|
+
"biz",
|
|
2799
|
+
"me",
|
|
2800
|
+
"tv",
|
|
2801
|
+
"fi",
|
|
2802
|
+
"be",
|
|
2803
|
+
"ch",
|
|
2804
|
+
"ca",
|
|
2805
|
+
"uk",
|
|
2806
|
+
"de",
|
|
2807
|
+
"es",
|
|
2808
|
+
"it"
|
|
2809
|
+
];
|
|
2529
2810
|
var EmailEngine = _EmailEngine;
|
|
2530
2811
|
|
|
2531
2812
|
// src/mask/InputEmailMask.ts
|
|
@@ -2539,6 +2820,10 @@ var Wulf = (() => {
|
|
|
2539
2820
|
const dataAutoLower = wrap?.getAttribute("data-mask-auto-lowercase") === "true" || inp?.getAttribute("data-mask-auto-lowercase") === "true";
|
|
2540
2821
|
const dataAriaAuto = wrap?.getAttribute("data-mask-aria-autocomplete") ?? inp?.getAttribute("data-mask-aria-autocomplete");
|
|
2541
2822
|
const setAriaAutocomplete = opts.setAriaAutocomplete ?? (dataAriaAuto !== null ? dataAriaAuto !== "false" : true);
|
|
2823
|
+
const dataTlds = wrap?.getAttribute("data-mask-tlds") ?? inp?.getAttribute("data-mask-tlds");
|
|
2824
|
+
const parsedTlds = opts.tlds ?? (dataTlds ? dataTlds.split(",").map((s) => s.trim()).filter(Boolean) : void 0);
|
|
2825
|
+
const dataDefaultTld = wrap?.getAttribute("data-mask-default-tld") ?? inp?.getAttribute("data-mask-default-tld");
|
|
2826
|
+
const resolvedDefaultTld = opts.defaultTld !== void 0 ? opts.defaultTld : dataDefaultTld !== null ? dataDefaultTld === "false" || dataDefaultTld === "none" ? null : dataDefaultTld === "true" ? true : dataDefaultTld : void 0;
|
|
2542
2827
|
const resolvedOptions = {
|
|
2543
2828
|
completeOnTab: true,
|
|
2544
2829
|
completeOnArrowRight: true,
|
|
@@ -2546,7 +2831,9 @@ var Wulf = (() => {
|
|
|
2546
2831
|
cycleSuggestions: opts.cycleSuggestions ?? dataCycle ?? false,
|
|
2547
2832
|
autoLowercase: opts.autoLowercase ?? dataAutoLower ?? false,
|
|
2548
2833
|
setAriaAutocomplete,
|
|
2549
|
-
...opts
|
|
2834
|
+
...opts,
|
|
2835
|
+
...parsedTlds !== void 0 ? { tlds: parsedTlds } : {},
|
|
2836
|
+
...resolvedDefaultTld !== void 0 ? { defaultTld: resolvedDefaultTld } : {}
|
|
2550
2837
|
};
|
|
2551
2838
|
super(wrap, inp, resolvedOptions);
|
|
2552
2839
|
this.currentSuggestion = { full: "", remaining: "", matchedDomain: null };
|
|
@@ -2564,6 +2851,7 @@ var Wulf = (() => {
|
|
|
2564
2851
|
if (!this.options.disabled) {
|
|
2565
2852
|
this.updateSuggestion();
|
|
2566
2853
|
}
|
|
2854
|
+
this.runAuditWarning(this.options.audit);
|
|
2567
2855
|
}
|
|
2568
2856
|
onNativeValueSet(_strVal) {
|
|
2569
2857
|
if (this.options.disabled) return;
|
|
@@ -2659,7 +2947,7 @@ var Wulf = (() => {
|
|
|
2659
2947
|
}
|
|
2660
2948
|
handleKeyDown(e) {
|
|
2661
2949
|
if (this.options.disabled) return;
|
|
2662
|
-
const hasSuggestion = Boolean(this.currentSuggestion.remaining);
|
|
2950
|
+
const hasSuggestion = Boolean(this.currentSuggestion.remaining) && !this.currentSuggestion.isHintOnly;
|
|
2663
2951
|
const cursor = this.input.selectionStart ?? 0;
|
|
2664
2952
|
const isAtEnd = cursor === this.input.value.length;
|
|
2665
2953
|
const isNotEmpty = this.input.value.length > 0;
|
|
@@ -2697,7 +2985,7 @@ var Wulf = (() => {
|
|
|
2697
2985
|
* Valide et applique la suggestion courante dans le champ natif.
|
|
2698
2986
|
*/
|
|
2699
2987
|
acceptSuggestion() {
|
|
2700
|
-
if (!this.currentSuggestion.remaining || this.options.disabled || this.input.value.length === 0) return false;
|
|
2988
|
+
if (!this.currentSuggestion.remaining || this.currentSuggestion.isHintOnly || this.options.disabled || this.input.value.length === 0) return false;
|
|
2701
2989
|
const completed = this.currentSuggestion.full;
|
|
2702
2990
|
this.setNativeValue(completed);
|
|
2703
2991
|
this.input.setSelectionRange(completed.length, completed.length);
|
|
@@ -2718,6 +3006,21 @@ var Wulf = (() => {
|
|
|
2718
3006
|
this.engine.setDefaultDomain(domain);
|
|
2719
3007
|
this.updateSuggestion();
|
|
2720
3008
|
}
|
|
3009
|
+
/**
|
|
3010
|
+
* Modifie dynamiquement l'extension (TLD) ou gabarit suggéré par défaut sur un domaine inconnu.
|
|
3011
|
+
*/
|
|
3012
|
+
setDefaultTld(tld) {
|
|
3013
|
+
this.engine.setDefaultTld(tld);
|
|
3014
|
+
this.updateSuggestion();
|
|
3015
|
+
}
|
|
3016
|
+
/**
|
|
3017
|
+
* Modifie dynamiquement la liste des extensions (TLD) connues.
|
|
3018
|
+
*/
|
|
3019
|
+
setTlds(tlds) {
|
|
3020
|
+
this.engine.setTlds(tlds);
|
|
3021
|
+
this.currentSuggestionIndex = 0;
|
|
3022
|
+
this.updateSuggestion();
|
|
3023
|
+
}
|
|
2721
3024
|
handleFocus() {
|
|
2722
3025
|
this.wrapper.classList.add("is-focused");
|
|
2723
3026
|
this.syncGhostStyles();
|
|
@@ -2738,6 +3041,12 @@ var Wulf = (() => {
|
|
|
2738
3041
|
this.options.cycleSuggestions = this.getAttr("data-mask-cycle-suggestions") === "true";
|
|
2739
3042
|
} else if (attrName === "data-mask-auto-lowercase") {
|
|
2740
3043
|
this.options.autoLowercase = this.getAttr("data-mask-auto-lowercase") === "true";
|
|
3044
|
+
} else if (attrName === "data-mask-default-tld") {
|
|
3045
|
+
const val = this.getAttr("data-mask-default-tld");
|
|
3046
|
+
this.setDefaultTld(val === null || val === "false" || val === "none" ? null : val === "true" ? true : val);
|
|
3047
|
+
} else if (attrName === "data-mask-tlds") {
|
|
3048
|
+
const val = this.getAttr("data-mask-tlds");
|
|
3049
|
+
this.setTlds(val ? val.split(",").map((s) => s.trim()).filter(Boolean) : null);
|
|
2741
3050
|
} else if (attrName === "placeholder") {
|
|
2742
3051
|
this.updateSuggestion();
|
|
2743
3052
|
}
|
|
@@ -2745,7 +3054,7 @@ var Wulf = (() => {
|
|
|
2745
3054
|
getDetail() {
|
|
2746
3055
|
return {
|
|
2747
3056
|
value: this.input.value,
|
|
2748
|
-
suggestedValue: this.currentSuggestion.full,
|
|
3057
|
+
suggestedValue: this.currentSuggestion.isHintOnly ? "" : this.currentSuggestion.full,
|
|
2749
3058
|
domain: this.currentSuggestion.matchedDomain
|
|
2750
3059
|
};
|
|
2751
3060
|
}
|
|
@@ -2803,16 +3112,207 @@ var Wulf = (() => {
|
|
|
2803
3112
|
// src/scroll/index.ts
|
|
2804
3113
|
var scroll_exports = {};
|
|
2805
3114
|
__export(scroll_exports, {
|
|
3115
|
+
LocalizedComponent: () => LocalizedComponent,
|
|
2806
3116
|
Scroll: () => Scroll,
|
|
2807
3117
|
ScrollBlock: () => ScrollBlock,
|
|
2808
|
-
|
|
3118
|
+
createI18nManager: () => createI18nManager,
|
|
3119
|
+
default: () => scroll_default,
|
|
3120
|
+
scrollEn: () => scrollEn,
|
|
3121
|
+
scrollFr: () => scrollFr,
|
|
3122
|
+
scrollI18n: () => scrollI18n
|
|
3123
|
+
});
|
|
3124
|
+
|
|
3125
|
+
// src/common/LocalizedComponent.ts
|
|
3126
|
+
var LocalizedComponent = class extends AuditableComponent {
|
|
3127
|
+
/**
|
|
3128
|
+
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
3129
|
+
*/
|
|
3130
|
+
static setLocale(locale) {
|
|
3131
|
+
if (this._i18n) {
|
|
3132
|
+
this._i18n.setLocale(locale);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
/**
|
|
3136
|
+
* Retourne la langue globale active du composant.
|
|
3137
|
+
*/
|
|
3138
|
+
static getLocale() {
|
|
3139
|
+
return this._i18n ? this._i18n.getLocale() : "";
|
|
3140
|
+
}
|
|
3141
|
+
/**
|
|
3142
|
+
* Enregistre un dictionnaire de traduction pour une langue donnée.
|
|
3143
|
+
*/
|
|
3144
|
+
static registerLocale(locale, translations) {
|
|
3145
|
+
if (this._i18n) {
|
|
3146
|
+
this._i18n.registerLocale(locale, translations);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
/**
|
|
3150
|
+
* Surcharge les libellés globalement pour ce composant.
|
|
3151
|
+
*/
|
|
3152
|
+
static setI18n(overrides) {
|
|
3153
|
+
if (this._i18n) {
|
|
3154
|
+
this._i18n.setI18n(overrides);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
/**
|
|
3158
|
+
* Retourne l'ensemble des libellés actifs résolus du composant.
|
|
3159
|
+
*/
|
|
3160
|
+
static getI18n() {
|
|
3161
|
+
return this._i18n ? this._i18n.getAll() : {};
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* Réinitialise les réglages de langue et surcharges globales.
|
|
3165
|
+
*/
|
|
3166
|
+
static resetI18n() {
|
|
3167
|
+
if (this._i18n) {
|
|
3168
|
+
this._i18n.reset();
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Résout une clé au niveau statique de la classe.
|
|
3173
|
+
*/
|
|
3174
|
+
static t(key, instanceOverride) {
|
|
3175
|
+
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
3176
|
+
}
|
|
3177
|
+
constructor(i18nOverrides) {
|
|
3178
|
+
super();
|
|
3179
|
+
this.i18nOverrides = i18nOverrides;
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* Traduit une clé en tenant compte automatiquement des surcharges de l'instance courante.
|
|
3183
|
+
*/
|
|
3184
|
+
t(key) {
|
|
3185
|
+
const ctor = this.constructor;
|
|
3186
|
+
return ctor._i18n ? ctor._i18n.t(key, this.i18nOverrides) : String(key);
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
|
|
3190
|
+
// src/common/i18n.ts
|
|
3191
|
+
function normalizeLocaleCode(locale) {
|
|
3192
|
+
return locale.trim().toLowerCase().replace(/_/g, "-");
|
|
3193
|
+
}
|
|
3194
|
+
function getPrimaryLanguage(normalizedLocale) {
|
|
3195
|
+
const dashIndex = normalizedLocale.indexOf("-");
|
|
3196
|
+
return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
3197
|
+
}
|
|
3198
|
+
function assignDefined(target, source) {
|
|
3199
|
+
if (!source) return target;
|
|
3200
|
+
for (const key of Object.keys(source)) {
|
|
3201
|
+
if (source[key] !== void 0) {
|
|
3202
|
+
target[key] = source[key];
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
return target;
|
|
3206
|
+
}
|
|
3207
|
+
function createI18nManager(defaultLocale, locales) {
|
|
3208
|
+
const fallbackLocale = normalizeLocaleCode(defaultLocale);
|
|
3209
|
+
const initialLocales = {};
|
|
3210
|
+
for (const [loc, dict] of Object.entries(locales)) {
|
|
3211
|
+
initialLocales[normalizeLocaleCode(loc)] = { ...dict };
|
|
3212
|
+
}
|
|
3213
|
+
let currentLocale = fallbackLocale;
|
|
3214
|
+
let activeLocales = { ...initialLocales };
|
|
3215
|
+
let globalOverrides = {};
|
|
3216
|
+
function resolveActiveDictionaries() {
|
|
3217
|
+
const dicts = [];
|
|
3218
|
+
const exact = activeLocales[currentLocale];
|
|
3219
|
+
if (exact) dicts.push(exact);
|
|
3220
|
+
const primary = getPrimaryLanguage(currentLocale);
|
|
3221
|
+
if (primary && activeLocales[primary]) {
|
|
3222
|
+
dicts.push(activeLocales[primary]);
|
|
3223
|
+
}
|
|
3224
|
+
return dicts;
|
|
3225
|
+
}
|
|
3226
|
+
return {
|
|
3227
|
+
setLocale(locale) {
|
|
3228
|
+
if (locale && locale.trim()) {
|
|
3229
|
+
currentLocale = normalizeLocaleCode(locale);
|
|
3230
|
+
}
|
|
3231
|
+
},
|
|
3232
|
+
getLocale() {
|
|
3233
|
+
return currentLocale;
|
|
3234
|
+
},
|
|
3235
|
+
registerLocale(locale, translations) {
|
|
3236
|
+
if (!locale || !locale.trim() || !translations) return;
|
|
3237
|
+
const norm = normalizeLocaleCode(locale);
|
|
3238
|
+
activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
|
|
3239
|
+
},
|
|
3240
|
+
setI18n(overrides) {
|
|
3241
|
+
if (!overrides) return;
|
|
3242
|
+
globalOverrides = assignDefined({ ...globalOverrides }, overrides);
|
|
3243
|
+
},
|
|
3244
|
+
t(key, instanceOverride) {
|
|
3245
|
+
if (instanceOverride && instanceOverride[key] !== void 0) {
|
|
3246
|
+
return String(instanceOverride[key]);
|
|
3247
|
+
}
|
|
3248
|
+
if (globalOverrides[key] !== void 0) {
|
|
3249
|
+
return String(globalOverrides[key]);
|
|
3250
|
+
}
|
|
3251
|
+
for (const dict of resolveActiveDictionaries()) {
|
|
3252
|
+
if (dict[key] !== void 0) {
|
|
3253
|
+
return String(dict[key]);
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
const fallbackDict = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
3257
|
+
if (fallbackDict && fallbackDict[key] !== void 0) {
|
|
3258
|
+
return String(fallbackDict[key]);
|
|
3259
|
+
}
|
|
3260
|
+
return String(key);
|
|
3261
|
+
},
|
|
3262
|
+
getAll(instanceOverride) {
|
|
3263
|
+
const result = {};
|
|
3264
|
+
const fallback = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
3265
|
+
assignDefined(result, fallback);
|
|
3266
|
+
const activeDicts = resolveActiveDictionaries().reverse();
|
|
3267
|
+
for (const dict of activeDicts) {
|
|
3268
|
+
assignDefined(result, dict);
|
|
3269
|
+
}
|
|
3270
|
+
assignDefined(result, globalOverrides);
|
|
3271
|
+
assignDefined(result, instanceOverride);
|
|
3272
|
+
return result;
|
|
3273
|
+
},
|
|
3274
|
+
reset() {
|
|
3275
|
+
currentLocale = fallbackLocale;
|
|
3276
|
+
globalOverrides = {};
|
|
3277
|
+
activeLocales = {};
|
|
3278
|
+
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
3279
|
+
activeLocales[loc] = { ...dict };
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
// src/scroll/i18n/fr.ts
|
|
3286
|
+
var scrollFr = {
|
|
3287
|
+
viewport: "Zone de contenu d\xE9filable",
|
|
3288
|
+
verticalThumb: "D\xE9filement vertical",
|
|
3289
|
+
horizontalThumb: "D\xE9filement horizontal"
|
|
3290
|
+
};
|
|
3291
|
+
|
|
3292
|
+
// src/scroll/i18n/en.ts
|
|
3293
|
+
var scrollEn = {
|
|
3294
|
+
viewport: "Scrollable content area",
|
|
3295
|
+
verticalThumb: "Vertical scroll",
|
|
3296
|
+
horizontalThumb: "Horizontal scroll"
|
|
3297
|
+
};
|
|
3298
|
+
|
|
3299
|
+
// src/scroll/i18n/index.ts
|
|
3300
|
+
var scrollI18n = createI18nManager("fr", {
|
|
3301
|
+
fr: scrollFr,
|
|
3302
|
+
en: scrollEn
|
|
2809
3303
|
});
|
|
2810
3304
|
|
|
2811
3305
|
// src/scroll/ScrollBlock.ts
|
|
2812
3306
|
var idCounter = 0;
|
|
2813
|
-
var ScrollBlock = class {
|
|
3307
|
+
var ScrollBlock = class extends LocalizedComponent {
|
|
2814
3308
|
constructor(element, options) {
|
|
3309
|
+
super(options?.i18n);
|
|
2815
3310
|
this.createdViewport = false;
|
|
3311
|
+
this.wasIdGenerated = false;
|
|
3312
|
+
this.wasRoleInferred = false;
|
|
3313
|
+
this.wasAriaLabelInferred = false;
|
|
3314
|
+
this.hasExplicitAriaLabel = false;
|
|
3315
|
+
this.lastInferredAriaLabel = "";
|
|
2816
3316
|
this.isDragging = false;
|
|
2817
3317
|
this.dragStartPos = 0;
|
|
2818
3318
|
this.dragStartScroll = 0;
|
|
@@ -2825,12 +3325,14 @@ var Wulf = (() => {
|
|
|
2825
3325
|
throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
|
|
2826
3326
|
}
|
|
2827
3327
|
this.root = resolvedElement;
|
|
3328
|
+
this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
|
|
2828
3329
|
this.options = {
|
|
2829
3330
|
axis: options?.axis || "y",
|
|
2830
3331
|
autoHide: options?.autoHide ?? true,
|
|
2831
3332
|
autoHideDelay: options?.autoHideDelay ?? 1e3,
|
|
2832
3333
|
alwaysVisible: options?.alwaysVisible ?? false,
|
|
2833
|
-
ariaLabel: options?.ariaLabel || "
|
|
3334
|
+
ariaLabel: options?.ariaLabel || this.t("viewport"),
|
|
3335
|
+
i18n: options?.i18n || {},
|
|
2834
3336
|
minThumbSize: options?.minThumbSize ?? 24,
|
|
2835
3337
|
edgeThreshold: options?.edgeThreshold ?? 10,
|
|
2836
3338
|
onScroll: options?.onScroll || (() => {
|
|
@@ -2838,7 +3340,8 @@ var Wulf = (() => {
|
|
|
2838
3340
|
onTotalScroll: options?.onTotalScroll || (() => {
|
|
2839
3341
|
}),
|
|
2840
3342
|
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
2841
|
-
})
|
|
3343
|
+
}),
|
|
3344
|
+
audit: options?.audit ?? true
|
|
2842
3345
|
};
|
|
2843
3346
|
this.boundOnScroll = this.handleScroll.bind(this);
|
|
2844
3347
|
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
@@ -2853,6 +3356,7 @@ var Wulf = (() => {
|
|
|
2853
3356
|
this.setupEventListeners();
|
|
2854
3357
|
this.setupObserver();
|
|
2855
3358
|
this.update();
|
|
3359
|
+
this.runAuditWarning(this.options.audit);
|
|
2856
3360
|
}
|
|
2857
3361
|
/**
|
|
2858
3362
|
* Prépare le viewport défilant sans altérer les éléments enfants.
|
|
@@ -2885,9 +3389,38 @@ var Wulf = (() => {
|
|
|
2885
3389
|
if (!this.viewport.id) {
|
|
2886
3390
|
idCounter += 1;
|
|
2887
3391
|
this.viewport.id = `wulf-scrollblock-vp-${idCounter}`;
|
|
3392
|
+
this.wasIdGenerated = true;
|
|
3393
|
+
}
|
|
3394
|
+
if (!this.viewport.hasAttribute("role")) {
|
|
3395
|
+
this.viewport.setAttribute("role", "region");
|
|
3396
|
+
this.wasRoleInferred = true;
|
|
3397
|
+
}
|
|
3398
|
+
if (!this.viewport.hasAttribute("aria-label")) {
|
|
3399
|
+
const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("viewport");
|
|
3400
|
+
this.viewport.setAttribute("aria-label", label);
|
|
3401
|
+
this.lastInferredAriaLabel = label;
|
|
3402
|
+
this.wasAriaLabelInferred = true;
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
/**
|
|
3406
|
+
* Synchronise dynamiquement les libellés ARIA si la langue globale change après montage.
|
|
3407
|
+
*/
|
|
3408
|
+
syncAccessibilityLabels() {
|
|
3409
|
+
if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
|
|
3410
|
+
const currentAttr = this.viewport.getAttribute("aria-label");
|
|
3411
|
+
if (currentAttr === this.lastInferredAriaLabel) {
|
|
3412
|
+
const nextLabel = this.t("viewport");
|
|
3413
|
+
this.viewport.setAttribute("aria-label", nextLabel);
|
|
3414
|
+
this.lastInferredAriaLabel = nextLabel;
|
|
3415
|
+
this.options.ariaLabel = nextLabel;
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
if (this.thumbY) {
|
|
3419
|
+
this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
|
|
3420
|
+
}
|
|
3421
|
+
if (this.thumbX) {
|
|
3422
|
+
this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
|
|
2888
3423
|
}
|
|
2889
|
-
this.viewport.setAttribute("role", "region");
|
|
2890
|
-
this.viewport.setAttribute("aria-label", this.options.ariaLabel);
|
|
2891
3424
|
}
|
|
2892
3425
|
/**
|
|
2893
3426
|
* Crée les rails et curseurs selon l'axe sélectionné.
|
|
@@ -2905,7 +3438,7 @@ var Wulf = (() => {
|
|
|
2905
3438
|
this.thumbY.setAttribute("aria-valuenow", "0");
|
|
2906
3439
|
this.thumbY.setAttribute("aria-valuemin", "0");
|
|
2907
3440
|
this.thumbY.setAttribute("aria-valuemax", "100");
|
|
2908
|
-
this.thumbY.setAttribute("aria-label", "
|
|
3441
|
+
this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
|
|
2909
3442
|
this.trackY.appendChild(this.thumbY);
|
|
2910
3443
|
this.root.appendChild(this.trackY);
|
|
2911
3444
|
this.attachTrackListeners(this.trackY, this.thumbY, "y");
|
|
@@ -2922,7 +3455,7 @@ var Wulf = (() => {
|
|
|
2922
3455
|
this.thumbX.setAttribute("aria-valuenow", "0");
|
|
2923
3456
|
this.thumbX.setAttribute("aria-valuemin", "0");
|
|
2924
3457
|
this.thumbX.setAttribute("aria-valuemax", "100");
|
|
2925
|
-
this.thumbX.setAttribute("aria-label", "
|
|
3458
|
+
this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
|
|
2926
3459
|
this.trackX.appendChild(this.thumbX);
|
|
2927
3460
|
this.root.appendChild(this.trackX);
|
|
2928
3461
|
this.attachTrackListeners(this.trackX, this.thumbX, "x");
|
|
@@ -3144,6 +3677,7 @@ var Wulf = (() => {
|
|
|
3144
3677
|
* Recalcule les dimensions et la visibilité des barres.
|
|
3145
3678
|
*/
|
|
3146
3679
|
update() {
|
|
3680
|
+
this.syncAccessibilityLabels();
|
|
3147
3681
|
const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
|
|
3148
3682
|
const canScrollY = scrollHeight > clientHeight;
|
|
3149
3683
|
const canScrollX = scrollWidth > clientWidth;
|
|
@@ -3205,6 +3739,18 @@ var Wulf = (() => {
|
|
|
3205
3739
|
targetLeft = maxLeft;
|
|
3206
3740
|
break;
|
|
3207
3741
|
default: {
|
|
3742
|
+
if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
|
|
3743
|
+
const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
|
|
3744
|
+
if (this.options.axis === "x") {
|
|
3745
|
+
targetLeft = maxLeft * pct;
|
|
3746
|
+
} else if (this.options.axis === "both") {
|
|
3747
|
+
targetTop = maxTop * pct;
|
|
3748
|
+
targetLeft = maxLeft * pct;
|
|
3749
|
+
} else {
|
|
3750
|
+
targetTop = maxTop * pct;
|
|
3751
|
+
}
|
|
3752
|
+
break;
|
|
3753
|
+
}
|
|
3208
3754
|
let el = null;
|
|
3209
3755
|
try {
|
|
3210
3756
|
el = this.viewport.querySelector(target);
|
|
@@ -3231,6 +3777,35 @@ var Wulf = (() => {
|
|
|
3231
3777
|
behavior
|
|
3232
3778
|
});
|
|
3233
3779
|
}
|
|
3780
|
+
/**
|
|
3781
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
|
|
3782
|
+
* et retourne la liste des contraintes manquantes.
|
|
3783
|
+
*/
|
|
3784
|
+
audit() {
|
|
3785
|
+
const warnings = [];
|
|
3786
|
+
const hasViewportLabelledby = this.checkAriaIdReferences(this.viewport, "aria-labelledby", warnings);
|
|
3787
|
+
const hasRootLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
|
|
3788
|
+
const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
|
|
3789
|
+
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
3790
|
+
const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
|
|
3791
|
+
if (!this.hasExplicitAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
3792
|
+
warnings.push(
|
|
3793
|
+
"Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour d\xE9crire la zone d\xE9filable (WCAG 4.1.2)."
|
|
3794
|
+
);
|
|
3795
|
+
}
|
|
3796
|
+
if (this.options.minThumbSize < 24) {
|
|
3797
|
+
warnings.push(
|
|
3798
|
+
`Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
|
|
3799
|
+
);
|
|
3800
|
+
}
|
|
3801
|
+
return warnings;
|
|
3802
|
+
}
|
|
3803
|
+
getAuditPrefix() {
|
|
3804
|
+
return "Wulf.Scroll";
|
|
3805
|
+
}
|
|
3806
|
+
getAuditTargetLabel() {
|
|
3807
|
+
return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-scrollblock>`;
|
|
3808
|
+
}
|
|
3234
3809
|
/**
|
|
3235
3810
|
* Détruit le composant et libère toutes les ressources.
|
|
3236
3811
|
*/
|
|
@@ -3264,13 +3839,27 @@ var Wulf = (() => {
|
|
|
3264
3839
|
this.root.insertBefore(this.viewport.firstChild, this.viewport);
|
|
3265
3840
|
}
|
|
3266
3841
|
this.viewport.remove();
|
|
3842
|
+
} else {
|
|
3843
|
+
this.viewport.removeAttribute("tabindex");
|
|
3844
|
+
if (this.wasIdGenerated) {
|
|
3845
|
+
this.viewport.removeAttribute("id");
|
|
3846
|
+
}
|
|
3847
|
+
if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
|
|
3848
|
+
this.viewport.removeAttribute("role");
|
|
3849
|
+
}
|
|
3850
|
+
if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
3851
|
+
this.viewport.removeAttribute("aria-label");
|
|
3852
|
+
}
|
|
3267
3853
|
}
|
|
3268
3854
|
}
|
|
3269
3855
|
};
|
|
3856
|
+
ScrollBlock._i18n = scrollI18n;
|
|
3857
|
+
ScrollBlock.i18n = scrollI18n;
|
|
3270
3858
|
|
|
3271
3859
|
// src/scroll/index.ts
|
|
3272
3860
|
var Scroll = {
|
|
3273
|
-
ScrollBlock
|
|
3861
|
+
ScrollBlock,
|
|
3862
|
+
i18n: scrollI18n
|
|
3274
3863
|
};
|
|
3275
3864
|
var scroll_default = ScrollBlock;
|
|
3276
3865
|
if (typeof window !== "undefined") {
|
|
@@ -3284,8 +3873,13 @@ var Wulf = (() => {
|
|
|
3284
3873
|
var masonry_exports = {};
|
|
3285
3874
|
__export(masonry_exports, {
|
|
3286
3875
|
LayoutEngine: () => LayoutEngine,
|
|
3876
|
+
LocalizedComponent: () => LocalizedComponent,
|
|
3287
3877
|
Masonry: () => Masonry,
|
|
3288
|
-
|
|
3878
|
+
createI18nManager: () => createI18nManager,
|
|
3879
|
+
default: () => masonry_default,
|
|
3880
|
+
masonryEn: () => masonryEn,
|
|
3881
|
+
masonryFr: () => masonryFr,
|
|
3882
|
+
masonryI18n: () => masonryI18n
|
|
3289
3883
|
});
|
|
3290
3884
|
|
|
3291
3885
|
// src/masonry/LayoutEngine.ts
|
|
@@ -3475,9 +4069,26 @@ var Wulf = (() => {
|
|
|
3475
4069
|
}
|
|
3476
4070
|
};
|
|
3477
4071
|
|
|
4072
|
+
// src/masonry/i18n/fr.ts
|
|
4073
|
+
var masonryFr = {
|
|
4074
|
+
gallery: "Galerie en grille asym\xE9trique"
|
|
4075
|
+
};
|
|
4076
|
+
|
|
4077
|
+
// src/masonry/i18n/en.ts
|
|
4078
|
+
var masonryEn = {
|
|
4079
|
+
gallery: "Masonry grid gallery"
|
|
4080
|
+
};
|
|
4081
|
+
|
|
4082
|
+
// src/masonry/i18n/index.ts
|
|
4083
|
+
var masonryI18n = createI18nManager("fr", {
|
|
4084
|
+
fr: masonryFr,
|
|
4085
|
+
en: masonryEn
|
|
4086
|
+
});
|
|
4087
|
+
|
|
3478
4088
|
// src/masonry/Masonry.ts
|
|
3479
|
-
var Masonry = class {
|
|
4089
|
+
var Masonry = class extends LocalizedComponent {
|
|
3480
4090
|
constructor(target, options = {}) {
|
|
4091
|
+
super(options.i18n);
|
|
3481
4092
|
this.isNativeCSSGrid = false;
|
|
3482
4093
|
this._items = [];
|
|
3483
4094
|
this.resizeObserver = null;
|
|
@@ -3486,6 +4097,8 @@ var Wulf = (() => {
|
|
|
3486
4097
|
this.isDestroyed = false;
|
|
3487
4098
|
this.wasRoleInferred = false;
|
|
3488
4099
|
this.wasAriaLabelInferred = false;
|
|
4100
|
+
this.hasExplicitAriaLabel = false;
|
|
4101
|
+
this.lastInferredAriaLabel = "";
|
|
3489
4102
|
this.removeTimers = /* @__PURE__ */ new Set();
|
|
3490
4103
|
this.pendingImageListeners = [];
|
|
3491
4104
|
if (typeof target === "string") {
|
|
@@ -3503,11 +4116,12 @@ var Wulf = (() => {
|
|
|
3503
4116
|
height: this.root.style.height,
|
|
3504
4117
|
width: this.root.style.width
|
|
3505
4118
|
};
|
|
4119
|
+
this.hasExplicitAriaLabel = Boolean(options.ariaLabel || options.i18n?.gallery);
|
|
3506
4120
|
this.options = {
|
|
3507
4121
|
itemSelector: options.itemSelector || "> *",
|
|
3508
4122
|
columnWidth: options.columnWidth ?? 0,
|
|
3509
4123
|
gutter: options.gutter ?? 0,
|
|
3510
|
-
percentPosition: options.percentPosition
|
|
4124
|
+
percentPosition: Boolean(options.percentPosition),
|
|
3511
4125
|
fitWidth: Boolean(options.fitWidth),
|
|
3512
4126
|
horizontalOrder: Boolean(options.horizontalOrder),
|
|
3513
4127
|
transitionDuration: options.transitionDuration !== void 0 ? options.transitionDuration : 300,
|
|
@@ -3516,11 +4130,13 @@ var Wulf = (() => {
|
|
|
3516
4130
|
autoImages: options.autoImages !== false,
|
|
3517
4131
|
useNativeCSSGrid: options.useNativeCSSGrid !== false,
|
|
3518
4132
|
ariaRole: options.ariaRole || "region",
|
|
3519
|
-
ariaLabel: options.ariaLabel || "
|
|
4133
|
+
ariaLabel: options.ariaLabel || this.t("gallery"),
|
|
4134
|
+
i18n: options.i18n || {},
|
|
3520
4135
|
onLayout: options.onLayout || (() => {
|
|
3521
4136
|
}),
|
|
3522
4137
|
onItemPlaced: options.onItemPlaced || (() => {
|
|
3523
|
-
})
|
|
4138
|
+
}),
|
|
4139
|
+
audit: options.audit ?? true
|
|
3524
4140
|
};
|
|
3525
4141
|
const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("grid-template-rows", "masonry");
|
|
3526
4142
|
if (this.options.useNativeCSSGrid && supportsNativeCSS) {
|
|
@@ -3535,6 +4151,7 @@ var Wulf = (() => {
|
|
|
3535
4151
|
this.initObservers();
|
|
3536
4152
|
this.initImages();
|
|
3537
4153
|
this.layout();
|
|
4154
|
+
this.runAuditWarning(this.options.audit);
|
|
3538
4155
|
}
|
|
3539
4156
|
get items() {
|
|
3540
4157
|
return [...this._items];
|
|
@@ -3547,11 +4164,27 @@ var Wulf = (() => {
|
|
|
3547
4164
|
this.root.setAttribute("role", this.options.ariaRole);
|
|
3548
4165
|
this.wasRoleInferred = true;
|
|
3549
4166
|
}
|
|
3550
|
-
|
|
3551
|
-
|
|
4167
|
+
const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("gallery");
|
|
4168
|
+
if (label && !this.root.hasAttribute("aria-label")) {
|
|
4169
|
+
this.root.setAttribute("aria-label", label);
|
|
4170
|
+
this.lastInferredAriaLabel = label;
|
|
3552
4171
|
this.wasAriaLabelInferred = true;
|
|
3553
4172
|
}
|
|
3554
4173
|
}
|
|
4174
|
+
/**
|
|
4175
|
+
* Synchronise dynamiquement le libellé ARIA si la langue globale change après montage.
|
|
4176
|
+
*/
|
|
4177
|
+
syncAccessibilityLabels() {
|
|
4178
|
+
if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
|
|
4179
|
+
const currentAttr = this.root.getAttribute("aria-label");
|
|
4180
|
+
if (currentAttr === this.lastInferredAriaLabel) {
|
|
4181
|
+
const nextLabel = this.t("gallery");
|
|
4182
|
+
this.root.setAttribute("aria-label", nextLabel);
|
|
4183
|
+
this.lastInferredAriaLabel = nextLabel;
|
|
4184
|
+
this.options.ariaLabel = nextLabel;
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
3555
4188
|
/**
|
|
3556
4189
|
* Configure les variables CSS de transition sur le conteneur.
|
|
3557
4190
|
*/
|
|
@@ -3658,6 +4291,7 @@ var Wulf = (() => {
|
|
|
3658
4291
|
*/
|
|
3659
4292
|
layout() {
|
|
3660
4293
|
if (this.isDestroyed) return;
|
|
4294
|
+
this.syncAccessibilityLabels();
|
|
3661
4295
|
if (this.isNativeCSSGrid) {
|
|
3662
4296
|
this.options.onLayout([]);
|
|
3663
4297
|
return;
|
|
@@ -3672,10 +4306,16 @@ var Wulf = (() => {
|
|
|
3672
4306
|
this.root.classList.remove("wulf-masonry--fit-width");
|
|
3673
4307
|
}
|
|
3674
4308
|
const stagger = this.options.stagger;
|
|
4309
|
+
const usePercent = this.options.percentPosition && result.containerWidth > 0;
|
|
3675
4310
|
for (let i = 0; i < result.positions.length; i++) {
|
|
3676
4311
|
const pos = result.positions[i];
|
|
3677
4312
|
const item = pos.element;
|
|
3678
|
-
|
|
4313
|
+
if (usePercent) {
|
|
4314
|
+
const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
|
|
4315
|
+
item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
|
|
4316
|
+
} else {
|
|
4317
|
+
item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
|
|
4318
|
+
}
|
|
3679
4319
|
item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
|
|
3680
4320
|
item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
|
|
3681
4321
|
if (stagger > 0) {
|
|
@@ -3764,6 +4404,35 @@ var Wulf = (() => {
|
|
|
3764
4404
|
}, dur);
|
|
3765
4405
|
this.removeTimers.add(timerId);
|
|
3766
4406
|
}
|
|
4407
|
+
/**
|
|
4408
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la grille Masonry
|
|
4409
|
+
* et retourne la liste des contraintes manquantes.
|
|
4410
|
+
*/
|
|
4411
|
+
audit() {
|
|
4412
|
+
const warnings = [];
|
|
4413
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
|
|
4414
|
+
const hasCustomRootAriaLabel = !this.wasAriaLabelInferred && Boolean(this.root.getAttribute("aria-label")?.trim());
|
|
4415
|
+
if (!this.hasExplicitAriaLabel && !hasCustomRootAriaLabel && !hasValidLabelledby) {
|
|
4416
|
+
warnings.push(
|
|
4417
|
+
"Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour qualifier la grille (WCAG 4.1.2)."
|
|
4418
|
+
);
|
|
4419
|
+
}
|
|
4420
|
+
const imagesWithoutAlt = Array.from(this.root.querySelectorAll("img")).filter(
|
|
4421
|
+
(img) => !img.hasAttribute("alt") && img.getAttribute("aria-hidden") !== "true"
|
|
4422
|
+
);
|
|
4423
|
+
if (imagesWithoutAlt.length > 0) {
|
|
4424
|
+
warnings.push(
|
|
4425
|
+
`${imagesWithoutAlt.length} image(s) <img> d\xE9pourvue(s) d'attribut alt : renseignez alt="description" (ou alt="" si d\xE9corative) (WCAG 1.1.1).`
|
|
4426
|
+
);
|
|
4427
|
+
}
|
|
4428
|
+
return warnings;
|
|
4429
|
+
}
|
|
4430
|
+
getAuditPrefix() {
|
|
4431
|
+
return "Wulf.Masonry";
|
|
4432
|
+
}
|
|
4433
|
+
getAuditTargetLabel() {
|
|
4434
|
+
return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-masonry>`;
|
|
4435
|
+
}
|
|
3767
4436
|
/**
|
|
3768
4437
|
* Libère les ressources, déconnecte les observateurs et nettoie les styles injectés.
|
|
3769
4438
|
*/
|
|
@@ -3795,7 +4464,7 @@ var Wulf = (() => {
|
|
|
3795
4464
|
if (this.wasRoleInferred && this.root.getAttribute("role") === this.options.ariaRole) {
|
|
3796
4465
|
this.root.removeAttribute("role");
|
|
3797
4466
|
}
|
|
3798
|
-
if (this.wasAriaLabelInferred && this.root.getAttribute("aria-label") === this.
|
|
4467
|
+
if (this.wasAriaLabelInferred && this.root.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
3799
4468
|
this.root.removeAttribute("aria-label");
|
|
3800
4469
|
}
|
|
3801
4470
|
this.root.style.removeProperty("--wulf-masonry-duration");
|
|
@@ -3819,6 +4488,8 @@ var Wulf = (() => {
|
|
|
3819
4488
|
this._items = [];
|
|
3820
4489
|
}
|
|
3821
4490
|
};
|
|
4491
|
+
Masonry._i18n = masonryI18n;
|
|
4492
|
+
Masonry.i18n = masonryI18n;
|
|
3822
4493
|
|
|
3823
4494
|
// src/masonry/index.ts
|
|
3824
4495
|
var masonry_default = Masonry;
|
|
@@ -3828,23 +4499,46 @@ var Wulf = (() => {
|
|
|
3828
4499
|
win.Wulf = wulfNamespace;
|
|
3829
4500
|
wulfNamespace.Masonry = Object.assign(Masonry, {
|
|
3830
4501
|
Masonry,
|
|
3831
|
-
LayoutEngine
|
|
4502
|
+
LayoutEngine,
|
|
4503
|
+
i18n: masonryI18n
|
|
3832
4504
|
});
|
|
3833
4505
|
}
|
|
3834
4506
|
|
|
3835
4507
|
// src/toast/index.ts
|
|
3836
4508
|
var toast_exports = {};
|
|
3837
4509
|
__export(toast_exports, {
|
|
4510
|
+
LocalizedComponent: () => LocalizedComponent,
|
|
3838
4511
|
Toast: () => Toast,
|
|
3839
4512
|
ToastInstance: () => ToastInstance,
|
|
3840
4513
|
ToastManager: () => ToastManager,
|
|
3841
|
-
|
|
4514
|
+
createI18nManager: () => createI18nManager,
|
|
4515
|
+
default: () => toast_default,
|
|
4516
|
+
toastEn: () => toastEn,
|
|
4517
|
+
toastFr: () => toastFr,
|
|
4518
|
+
toastI18n: () => toastI18n
|
|
4519
|
+
});
|
|
4520
|
+
|
|
4521
|
+
// src/toast/i18n/fr.ts
|
|
4522
|
+
var toastFr = {
|
|
4523
|
+
closeButton: "Fermer la notification"
|
|
4524
|
+
};
|
|
4525
|
+
|
|
4526
|
+
// src/toast/i18n/en.ts
|
|
4527
|
+
var toastEn = {
|
|
4528
|
+
closeButton: "Close notification"
|
|
4529
|
+
};
|
|
4530
|
+
|
|
4531
|
+
// src/toast/i18n/index.ts
|
|
4532
|
+
var toastI18n = createI18nManager("fr", {
|
|
4533
|
+
fr: toastFr,
|
|
4534
|
+
en: toastEn
|
|
3842
4535
|
});
|
|
3843
4536
|
|
|
3844
4537
|
// src/toast/ToastInstance.ts
|
|
3845
4538
|
var nextToastId = 1;
|
|
3846
|
-
var ToastInstance = class {
|
|
4539
|
+
var ToastInstance = class extends AuditableComponent {
|
|
3847
4540
|
constructor(options, onDismiss) {
|
|
4541
|
+
super();
|
|
3848
4542
|
this._isClosed = false;
|
|
3849
4543
|
this.timerId = null;
|
|
3850
4544
|
this.remainingTime = 0;
|
|
@@ -3861,10 +4555,45 @@ var Wulf = (() => {
|
|
|
3861
4555
|
}
|
|
3862
4556
|
this.element = this.createDOM();
|
|
3863
4557
|
this.bindEvents();
|
|
4558
|
+
this.runAuditWarning(options.audit !== false);
|
|
3864
4559
|
}
|
|
3865
4560
|
get isClosed() {
|
|
3866
4561
|
return this._isClosed;
|
|
3867
4562
|
}
|
|
4563
|
+
/**
|
|
4564
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
|
|
4565
|
+
* et retourne la liste des contraintes manquantes.
|
|
4566
|
+
*/
|
|
4567
|
+
audit() {
|
|
4568
|
+
const warnings = [];
|
|
4569
|
+
const hasTitle = Boolean(this.options.title && this.options.title.trim().length > 0);
|
|
4570
|
+
const hasMessage = Boolean(this.options.message && this.options.message.trim().length > 0);
|
|
4571
|
+
if (!hasTitle && !hasMessage) {
|
|
4572
|
+
warnings.push(
|
|
4573
|
+
"Contenu textuel vide : d\xE9finissez au moins un title ou un message pour que le lecteur d'\xE9cran puisse annoncer la notification (WCAG 4.1.3)."
|
|
4574
|
+
);
|
|
4575
|
+
}
|
|
4576
|
+
const duration = this.options.duration === void 0 ? 4e3 : this.options.duration;
|
|
4577
|
+
if (typeof duration === "number" && duration > 0 && duration < 5e3) {
|
|
4578
|
+
warnings.push(
|
|
4579
|
+
`Dur\xE9e d'affichage trop courte (duration: ${duration}ms) : pr\xE9voyez au moins 5000ms ou duration: false pour laisser le temps de lecture aux utilisateurs (WCAG 2.2.1).`
|
|
4580
|
+
);
|
|
4581
|
+
}
|
|
4582
|
+
const closable = this.options.closable ?? true;
|
|
4583
|
+
const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
|
|
4584
|
+
if (isPersistent && !closable && !this.options.closeOnClick) {
|
|
4585
|
+
warnings.push(
|
|
4586
|
+
"Notification persistante impossible \xE0 fermer : activez closable: true ou closeOnClick: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4589
|
+
return warnings;
|
|
4590
|
+
}
|
|
4591
|
+
getAuditPrefix() {
|
|
4592
|
+
return "Wulf.Toast";
|
|
4593
|
+
}
|
|
4594
|
+
getAuditTargetLabel() {
|
|
4595
|
+
return `#${this.id}`;
|
|
4596
|
+
}
|
|
3868
4597
|
/**
|
|
3869
4598
|
* Construction du DOM de manière 100% sécurisée sans aucun `innerHTML`.
|
|
3870
4599
|
*/
|
|
@@ -3912,12 +4641,12 @@ var Wulf = (() => {
|
|
|
3912
4641
|
content.appendChild(messageEl);
|
|
3913
4642
|
}
|
|
3914
4643
|
el.appendChild(content);
|
|
3915
|
-
const closable = this.options.closable
|
|
4644
|
+
const closable = this.options.closable ?? true;
|
|
3916
4645
|
if (closable) {
|
|
3917
4646
|
const closeBtn = document.createElement("button");
|
|
3918
4647
|
closeBtn.type = "button";
|
|
3919
4648
|
closeBtn.className = "wulf-toast-close";
|
|
3920
|
-
closeBtn.setAttribute("aria-label", "
|
|
4649
|
+
closeBtn.setAttribute("aria-label", toastI18n.t("closeButton", this.options.i18n));
|
|
3921
4650
|
closeBtn.setAttribute("tabindex", "0");
|
|
3922
4651
|
const closeIcon = document.createElement("span");
|
|
3923
4652
|
closeIcon.className = "wulf-toast-close-icon";
|
|
@@ -3953,6 +4682,9 @@ var Wulf = (() => {
|
|
|
3953
4682
|
if (this.options.onClick) {
|
|
3954
4683
|
this.options.onClick(this, e);
|
|
3955
4684
|
}
|
|
4685
|
+
if (this.options.closeOnClick) {
|
|
4686
|
+
this.close("toast-click");
|
|
4687
|
+
}
|
|
3956
4688
|
});
|
|
3957
4689
|
this.element.addEventListener("mouseenter", () => this.pauseTimer());
|
|
3958
4690
|
this.element.addEventListener("mouseleave", () => this.resumeTimer());
|
|
@@ -4042,9 +4774,14 @@ var Wulf = (() => {
|
|
|
4042
4774
|
window.setTimeout(handleAnimationEnd, 90);
|
|
4043
4775
|
} else {
|
|
4044
4776
|
let transitioned = false;
|
|
4777
|
+
let fallbackTimerId = null;
|
|
4045
4778
|
const onEnd = () => {
|
|
4046
4779
|
if (!transitioned) {
|
|
4047
4780
|
transitioned = true;
|
|
4781
|
+
if (fallbackTimerId !== null) {
|
|
4782
|
+
window.clearTimeout(fallbackTimerId);
|
|
4783
|
+
fallbackTimerId = null;
|
|
4784
|
+
}
|
|
4048
4785
|
this.element.removeEventListener("animationend", onEnd);
|
|
4049
4786
|
this.element.removeEventListener("transitionend", onEnd);
|
|
4050
4787
|
handleAnimationEnd();
|
|
@@ -4052,7 +4789,7 @@ var Wulf = (() => {
|
|
|
4052
4789
|
};
|
|
4053
4790
|
this.element.addEventListener("animationend", onEnd, { once: true });
|
|
4054
4791
|
this.element.addEventListener("transitionend", onEnd, { once: true });
|
|
4055
|
-
window.setTimeout(onEnd, 300);
|
|
4792
|
+
fallbackTimerId = window.setTimeout(onEnd, 300);
|
|
4056
4793
|
}
|
|
4057
4794
|
});
|
|
4058
4795
|
}
|
|
@@ -4216,7 +4953,16 @@ var Wulf = (() => {
|
|
|
4216
4953
|
var ToastManager = _ToastManager;
|
|
4217
4954
|
|
|
4218
4955
|
// src/toast/Toast.ts
|
|
4219
|
-
var Toast = class {
|
|
4956
|
+
var Toast = class extends LocalizedComponent {
|
|
4957
|
+
audit() {
|
|
4958
|
+
return [];
|
|
4959
|
+
}
|
|
4960
|
+
getAuditPrefix() {
|
|
4961
|
+
return "Wulf.Toast";
|
|
4962
|
+
}
|
|
4963
|
+
getAuditTargetLabel() {
|
|
4964
|
+
return "Toast";
|
|
4965
|
+
}
|
|
4220
4966
|
/**
|
|
4221
4967
|
* Affiche une nouvelle notification Toast avec les options spécifiées.
|
|
4222
4968
|
*/
|
|
@@ -4235,6 +4981,8 @@ var Wulf = (() => {
|
|
|
4235
4981
|
return ToastManager.getInstance().clearAll(position);
|
|
4236
4982
|
}
|
|
4237
4983
|
};
|
|
4984
|
+
Toast._i18n = toastI18n;
|
|
4985
|
+
Toast.i18n = toastI18n;
|
|
4238
4986
|
|
|
4239
4987
|
// src/toast/index.ts
|
|
4240
4988
|
var toast_default = Toast;
|
|
@@ -4242,7 +4990,377 @@ var Wulf = (() => {
|
|
|
4242
4990
|
const win = window;
|
|
4243
4991
|
const wulfNamespace = win.Wulf || {};
|
|
4244
4992
|
win.Wulf = wulfNamespace;
|
|
4245
|
-
wulfNamespace.Toast = Toast
|
|
4993
|
+
wulfNamespace.Toast = Object.assign(Toast, {
|
|
4994
|
+
Toast,
|
|
4995
|
+
i18n: toastI18n
|
|
4996
|
+
});
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
// src/focus-trap/index.ts
|
|
5000
|
+
var focus_trap_exports = {};
|
|
5001
|
+
__export(focus_trap_exports, {
|
|
5002
|
+
FocusTrap: () => FocusTrap,
|
|
5003
|
+
default: () => FocusTrap
|
|
5004
|
+
});
|
|
5005
|
+
|
|
5006
|
+
// src/focus-trap/FocusTrap.ts
|
|
5007
|
+
var FOCUSABLE_SELECTOR = [
|
|
5008
|
+
"a[href]",
|
|
5009
|
+
"area[href]",
|
|
5010
|
+
"input:not([disabled])",
|
|
5011
|
+
"select:not([disabled])",
|
|
5012
|
+
"textarea:not([disabled])",
|
|
5013
|
+
"button:not([disabled])",
|
|
5014
|
+
"iframe",
|
|
5015
|
+
"object",
|
|
5016
|
+
"embed",
|
|
5017
|
+
'[contenteditable="true"]',
|
|
5018
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
5019
|
+
].join(",");
|
|
5020
|
+
var trapStack = [];
|
|
5021
|
+
var FocusTrap = class extends AuditableComponent {
|
|
5022
|
+
constructor(target, options = {}) {
|
|
5023
|
+
super();
|
|
5024
|
+
this.active = false;
|
|
5025
|
+
this.paused = false;
|
|
5026
|
+
this.previousActiveElement = null;
|
|
5027
|
+
this.inertSiblings = [];
|
|
5028
|
+
// Sentinelles anti-fuite de focus
|
|
5029
|
+
this.startSentinel = null;
|
|
5030
|
+
this.endSentinel = null;
|
|
5031
|
+
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
5032
|
+
if (!el || !(el instanceof HTMLElement)) {
|
|
5033
|
+
throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
|
|
5034
|
+
}
|
|
5035
|
+
this.element = el;
|
|
5036
|
+
this.options = {
|
|
5037
|
+
initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
|
|
5038
|
+
returnFocus: options.returnFocus ?? true,
|
|
5039
|
+
fallbackReturnFocus: options.fallbackReturnFocus ?? "",
|
|
5040
|
+
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
5041
|
+
allowOutsideClick: options.allowOutsideClick ?? false,
|
|
5042
|
+
setInert: options.setInert ?? false,
|
|
5043
|
+
onActivate: options.onActivate ?? (() => {
|
|
5044
|
+
}),
|
|
5045
|
+
onDeactivate: options.onDeactivate ?? (() => {
|
|
5046
|
+
}),
|
|
5047
|
+
audit: options.audit ?? true
|
|
5048
|
+
};
|
|
5049
|
+
this.handleKeyDownBound = this.handleKeyDown.bind(this);
|
|
5050
|
+
this.handleClickOutsideBound = this.handleClickOutside.bind(this);
|
|
5051
|
+
this.handleFocusInBound = this.handleFocusIn.bind(this);
|
|
5052
|
+
this.runAuditWarning(this.options.audit);
|
|
5053
|
+
}
|
|
5054
|
+
/**
|
|
5055
|
+
* Vérifie si un élément est réellement focusable, visible et actif dans le DOM.
|
|
5056
|
+
*/
|
|
5057
|
+
isFocusable(el) {
|
|
5058
|
+
if (!el || !el.isConnected) return false;
|
|
5059
|
+
if (el.disabled) return false;
|
|
5060
|
+
if (el.closest("fieldset[disabled]") && !el.closest("legend")) return false;
|
|
5061
|
+
if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
|
|
5062
|
+
if (el.hidden || el.closest("[hidden]")) return false;
|
|
5063
|
+
if (el.style.display === "none" || el.style.visibility === "hidden") return false;
|
|
5064
|
+
const style = window.getComputedStyle(el);
|
|
5065
|
+
if (style.display === "none" || style.visibility === "hidden") return false;
|
|
5066
|
+
if (el.offsetWidth === 0 && el.offsetHeight === 0 && style.position !== "fixed") {
|
|
5067
|
+
return false;
|
|
5068
|
+
}
|
|
5069
|
+
if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
|
|
5070
|
+
const group = Array.from(
|
|
5071
|
+
this.element.querySelectorAll(`input[type="radio"][name="${CSS.escape(el.name)}"]`)
|
|
5072
|
+
);
|
|
5073
|
+
const checked = group.find((r) => r.checked);
|
|
5074
|
+
if (checked) {
|
|
5075
|
+
return el === checked;
|
|
5076
|
+
}
|
|
5077
|
+
return el === group[0];
|
|
5078
|
+
}
|
|
5079
|
+
return true;
|
|
5080
|
+
}
|
|
5081
|
+
/**
|
|
5082
|
+
* Retourne tous les éléments focusables réels ordonnés dans le conteneur.
|
|
5083
|
+
*/
|
|
5084
|
+
getFocusableElements() {
|
|
5085
|
+
const rawElements = Array.from(this.element.querySelectorAll(FOCUSABLE_SELECTOR));
|
|
5086
|
+
return rawElements.filter((el) => this.isFocusable(el));
|
|
5087
|
+
}
|
|
5088
|
+
/**
|
|
5089
|
+
* Active le trap.
|
|
5090
|
+
*/
|
|
5091
|
+
activate() {
|
|
5092
|
+
if (this.active) return this;
|
|
5093
|
+
const currentTop = trapStack[trapStack.length - 1];
|
|
5094
|
+
if (currentTop) {
|
|
5095
|
+
currentTop.pause();
|
|
5096
|
+
}
|
|
5097
|
+
this.active = true;
|
|
5098
|
+
this.paused = false;
|
|
5099
|
+
trapStack.push(this);
|
|
5100
|
+
this.previousActiveElement = document.activeElement;
|
|
5101
|
+
this.setupSentinels();
|
|
5102
|
+
if (this.options.setInert) {
|
|
5103
|
+
this.applyInert();
|
|
5104
|
+
}
|
|
5105
|
+
document.addEventListener("keydown", this.handleKeyDownBound, true);
|
|
5106
|
+
document.addEventListener("focusin", this.handleFocusInBound, true);
|
|
5107
|
+
if (!this.options.allowOutsideClick) {
|
|
5108
|
+
document.addEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
5109
|
+
document.addEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
5110
|
+
}
|
|
5111
|
+
this.applyInitialFocus();
|
|
5112
|
+
this.runAuditWarning(this.options.audit);
|
|
5113
|
+
this.options.onActivate();
|
|
5114
|
+
return this;
|
|
5115
|
+
}
|
|
5116
|
+
/**
|
|
5117
|
+
* Désactive le trap et libère les écouteurs.
|
|
5118
|
+
*/
|
|
5119
|
+
deactivate() {
|
|
5120
|
+
if (!this.active) return this;
|
|
5121
|
+
this.active = false;
|
|
5122
|
+
this.paused = false;
|
|
5123
|
+
const index = trapStack.indexOf(this);
|
|
5124
|
+
if (index !== -1) {
|
|
5125
|
+
trapStack.splice(index, 1);
|
|
5126
|
+
}
|
|
5127
|
+
const nextTop = trapStack[trapStack.length - 1];
|
|
5128
|
+
if (nextTop) {
|
|
5129
|
+
nextTop.unpause();
|
|
5130
|
+
}
|
|
5131
|
+
document.removeEventListener("keydown", this.handleKeyDownBound, true);
|
|
5132
|
+
document.removeEventListener("focusin", this.handleFocusInBound, true);
|
|
5133
|
+
document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
|
|
5134
|
+
document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
|
|
5135
|
+
this.removeSentinels();
|
|
5136
|
+
this.removeInert();
|
|
5137
|
+
if (this.options.returnFocus) {
|
|
5138
|
+
this.restoreFocus();
|
|
5139
|
+
}
|
|
5140
|
+
this.options.onDeactivate();
|
|
5141
|
+
return this;
|
|
5142
|
+
}
|
|
5143
|
+
/**
|
|
5144
|
+
* Met en pause le trap (utilisé quand un trap fils s'ouvre au-dessus).
|
|
5145
|
+
*/
|
|
5146
|
+
pause() {
|
|
5147
|
+
this.paused = true;
|
|
5148
|
+
}
|
|
5149
|
+
/**
|
|
5150
|
+
* Sort de pause.
|
|
5151
|
+
*/
|
|
5152
|
+
unpause() {
|
|
5153
|
+
this.paused = false;
|
|
5154
|
+
}
|
|
5155
|
+
/**
|
|
5156
|
+
* Indique si le trap est actuellement actif et non en pause.
|
|
5157
|
+
*/
|
|
5158
|
+
isActive() {
|
|
5159
|
+
return this.active && !this.paused;
|
|
5160
|
+
}
|
|
5161
|
+
/**
|
|
5162
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA du conteneur FocusTrap
|
|
5163
|
+
* et retourne la liste des contraintes manquantes.
|
|
5164
|
+
*/
|
|
5165
|
+
audit() {
|
|
5166
|
+
const warnings = [];
|
|
5167
|
+
const role = this.element.getAttribute("role");
|
|
5168
|
+
const isNativeDialog = this.element.tagName.toLowerCase() === "dialog";
|
|
5169
|
+
const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
|
|
5170
|
+
if (!isNativeDialog && (!role || !validRoles.includes(role))) {
|
|
5171
|
+
warnings.push(
|
|
5172
|
+
'R\xF4le s\xE9mantique manquant ou inadapt\xE9 : d\xE9finissez role="dialog" (ou "alertdialog", "menu", "listbox") sur le conteneur.'
|
|
5173
|
+
);
|
|
5174
|
+
}
|
|
5175
|
+
if ((isNativeDialog || role === "dialog" || role === "alertdialog") && this.element.getAttribute("aria-modal") !== "true") {
|
|
5176
|
+
warnings.push(
|
|
5177
|
+
'Isolation modale manquante : d\xE9finissez aria-modal="true" sur le conteneur de dialogue (WCAG 4.1.2).'
|
|
5178
|
+
);
|
|
5179
|
+
}
|
|
5180
|
+
const ariaLabel = this.element.getAttribute("aria-label")?.trim();
|
|
5181
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings);
|
|
5182
|
+
if (!ariaLabel && !hasValidLabelledby) {
|
|
5183
|
+
warnings.push(
|
|
5184
|
+
'Nom accessible manquant : d\xE9finissez aria-labelledby="id-titre" ou aria-label="..." sur le conteneur (WCAG 4.1.2).'
|
|
5185
|
+
);
|
|
5186
|
+
}
|
|
5187
|
+
return warnings;
|
|
5188
|
+
}
|
|
5189
|
+
getAuditPrefix() {
|
|
5190
|
+
return "Wulf.FocusTrap";
|
|
5191
|
+
}
|
|
5192
|
+
getAuditTargetLabel() {
|
|
5193
|
+
return this.element.id ? `#${this.element.id}` : `<${this.element.tagName.toLowerCase()}>`;
|
|
5194
|
+
}
|
|
5195
|
+
/**
|
|
5196
|
+
* Détruit l'instance proprement.
|
|
5197
|
+
*/
|
|
5198
|
+
destroy() {
|
|
5199
|
+
this.deactivate();
|
|
5200
|
+
}
|
|
5201
|
+
// --- Implémentation interne ---
|
|
5202
|
+
handleKeyDown(e) {
|
|
5203
|
+
if (!this.isActive()) return;
|
|
5204
|
+
if (e.key === "Escape" && this.options.escapeDeactivates) {
|
|
5205
|
+
e.preventDefault();
|
|
5206
|
+
e.stopPropagation();
|
|
5207
|
+
this.deactivate();
|
|
5208
|
+
return;
|
|
5209
|
+
}
|
|
5210
|
+
if (e.key !== "Tab") return;
|
|
5211
|
+
const focusables = this.getFocusableElements();
|
|
5212
|
+
if (focusables.length === 0) {
|
|
5213
|
+
e.preventDefault();
|
|
5214
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
5215
|
+
this.element.setAttribute("tabindex", "-1");
|
|
5216
|
+
}
|
|
5217
|
+
this.element.focus();
|
|
5218
|
+
return;
|
|
5219
|
+
}
|
|
5220
|
+
const first = focusables[0];
|
|
5221
|
+
const last = focusables[focusables.length - 1];
|
|
5222
|
+
const current = document.activeElement;
|
|
5223
|
+
if (!e.shiftKey && (current === last || !this.element.contains(current))) {
|
|
5224
|
+
e.preventDefault();
|
|
5225
|
+
first.focus();
|
|
5226
|
+
} else if (e.shiftKey && (current === first || !this.element.contains(current))) {
|
|
5227
|
+
e.preventDefault();
|
|
5228
|
+
last.focus();
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5231
|
+
handleFocusIn(e) {
|
|
5232
|
+
if (!this.isActive()) return;
|
|
5233
|
+
const target = e.target;
|
|
5234
|
+
if (!target) return;
|
|
5235
|
+
if (target === this.startSentinel) {
|
|
5236
|
+
const focusables = this.getFocusableElements();
|
|
5237
|
+
if (focusables.length > 0) {
|
|
5238
|
+
focusables[focusables.length - 1].focus();
|
|
5239
|
+
} else {
|
|
5240
|
+
this.element.focus();
|
|
5241
|
+
}
|
|
5242
|
+
return;
|
|
5243
|
+
}
|
|
5244
|
+
if (target === this.endSentinel) {
|
|
5245
|
+
const focusables = this.getFocusableElements();
|
|
5246
|
+
if (focusables.length > 0) {
|
|
5247
|
+
focusables[0].focus();
|
|
5248
|
+
} else {
|
|
5249
|
+
this.element.focus();
|
|
5250
|
+
}
|
|
5251
|
+
return;
|
|
5252
|
+
}
|
|
5253
|
+
if (!this.element.contains(target)) {
|
|
5254
|
+
const focusables = this.getFocusableElements();
|
|
5255
|
+
if (focusables.length > 0) {
|
|
5256
|
+
focusables[0].focus();
|
|
5257
|
+
} else {
|
|
5258
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
5259
|
+
this.element.setAttribute("tabindex", "-1");
|
|
5260
|
+
}
|
|
5261
|
+
this.element.focus();
|
|
5262
|
+
}
|
|
5263
|
+
}
|
|
5264
|
+
}
|
|
5265
|
+
handleClickOutside(e) {
|
|
5266
|
+
if (!this.isActive()) return;
|
|
5267
|
+
const target = e.target;
|
|
5268
|
+
if (target && !this.element.contains(target)) {
|
|
5269
|
+
e.preventDefault();
|
|
5270
|
+
e.stopPropagation();
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
setupSentinels() {
|
|
5274
|
+
if (!this.startSentinel) {
|
|
5275
|
+
this.startSentinel = document.createElement("span");
|
|
5276
|
+
this.startSentinel.setAttribute("tabindex", "0");
|
|
5277
|
+
this.startSentinel.setAttribute("aria-hidden", "true");
|
|
5278
|
+
this.startSentinel.className = "wulf-sentinel-start";
|
|
5279
|
+
this.startSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
|
|
5280
|
+
}
|
|
5281
|
+
if (!this.endSentinel) {
|
|
5282
|
+
this.endSentinel = document.createElement("span");
|
|
5283
|
+
this.endSentinel.setAttribute("tabindex", "0");
|
|
5284
|
+
this.endSentinel.setAttribute("aria-hidden", "true");
|
|
5285
|
+
this.endSentinel.className = "wulf-sentinel-end";
|
|
5286
|
+
this.endSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
|
|
5287
|
+
}
|
|
5288
|
+
if (this.element.parentNode) {
|
|
5289
|
+
this.element.parentNode.insertBefore(this.startSentinel, this.element);
|
|
5290
|
+
this.element.parentNode.insertBefore(this.endSentinel, this.element.nextSibling);
|
|
5291
|
+
}
|
|
5292
|
+
}
|
|
5293
|
+
removeSentinels() {
|
|
5294
|
+
this.startSentinel?.remove();
|
|
5295
|
+
this.endSentinel?.remove();
|
|
5296
|
+
this.startSentinel = null;
|
|
5297
|
+
this.endSentinel = null;
|
|
5298
|
+
}
|
|
5299
|
+
applyInert() {
|
|
5300
|
+
this.inertSiblings = [];
|
|
5301
|
+
let parent = this.element.parentElement;
|
|
5302
|
+
let currentChild = this.element;
|
|
5303
|
+
while (parent && parent !== document.body) {
|
|
5304
|
+
currentChild = parent;
|
|
5305
|
+
parent = parent.parentElement;
|
|
5306
|
+
}
|
|
5307
|
+
if (parent === document.body) {
|
|
5308
|
+
Array.from(document.body.children).forEach((child) => {
|
|
5309
|
+
if (child instanceof HTMLElement && child !== currentChild && child !== this.startSentinel && child !== this.endSentinel && !child.hasAttribute("inert")) {
|
|
5310
|
+
child.setAttribute("inert", "");
|
|
5311
|
+
this.inertSiblings.push(child);
|
|
5312
|
+
}
|
|
5313
|
+
});
|
|
5314
|
+
}
|
|
5315
|
+
}
|
|
5316
|
+
removeInert() {
|
|
5317
|
+
this.inertSiblings.forEach((el) => el.removeAttribute("inert"));
|
|
5318
|
+
this.inertSiblings = [];
|
|
5319
|
+
}
|
|
5320
|
+
applyInitialFocus() {
|
|
5321
|
+
if (this.options.initialFocus === false) return;
|
|
5322
|
+
let targetEl = null;
|
|
5323
|
+
if (typeof this.options.initialFocus === "string") {
|
|
5324
|
+
targetEl = this.element.querySelector(this.options.initialFocus);
|
|
5325
|
+
} else if (this.options.initialFocus instanceof HTMLElement) {
|
|
5326
|
+
targetEl = this.options.initialFocus;
|
|
5327
|
+
}
|
|
5328
|
+
if (targetEl && this.isFocusable(targetEl)) {
|
|
5329
|
+
targetEl.focus();
|
|
5330
|
+
return;
|
|
5331
|
+
}
|
|
5332
|
+
const focusables = this.getFocusableElements();
|
|
5333
|
+
if (focusables.length > 0) {
|
|
5334
|
+
focusables[0].focus();
|
|
5335
|
+
} else {
|
|
5336
|
+
if (this.element.getAttribute("tabindex") === null) {
|
|
5337
|
+
this.element.setAttribute("tabindex", "-1");
|
|
5338
|
+
}
|
|
5339
|
+
this.element.focus();
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5342
|
+
restoreFocus() {
|
|
5343
|
+
if (this.previousActiveElement && this.previousActiveElement.isConnected) {
|
|
5344
|
+
this.previousActiveElement.focus();
|
|
5345
|
+
return;
|
|
5346
|
+
}
|
|
5347
|
+
if (this.options.fallbackReturnFocus) {
|
|
5348
|
+
const fallback = typeof this.options.fallbackReturnFocus === "string" ? document.querySelector(this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
|
|
5349
|
+
if (fallback && fallback.isConnected) {
|
|
5350
|
+
fallback.focus();
|
|
5351
|
+
}
|
|
5352
|
+
}
|
|
5353
|
+
}
|
|
5354
|
+
};
|
|
5355
|
+
|
|
5356
|
+
// src/focus-trap/index.ts
|
|
5357
|
+
if (typeof window !== "undefined") {
|
|
5358
|
+
const win = window;
|
|
5359
|
+
const wulfNamespace = win.Wulf || {};
|
|
5360
|
+
win.Wulf = wulfNamespace;
|
|
5361
|
+
wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
|
|
5362
|
+
FocusTrap
|
|
5363
|
+
});
|
|
4246
5364
|
}
|
|
4247
5365
|
return __toCommonJS(index_exports);
|
|
4248
5366
|
})();
|