wulf.js 2.0.1 → 2.1.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 +240 -4
- package/changelog.md +37 -0
- package/dist/focus-trap.esm.js +110 -37
- package/dist/focus-trap.esm.js.map +2 -2
- package/dist/focus-trap.global.js +110 -37
- 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 +3370 -337
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +3370 -337
- 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 +175 -69
- package/dist/masonry.esm.js.map +2 -2
- package/dist/masonry.global.js +175 -69
- package/dist/masonry.global.js.map +2 -2
- package/dist/masonry.global.min.js +3 -3
- package/dist/masonry.global.min.js.map +3 -3
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +132 -40
- package/dist/scroll.esm.js.map +2 -2
- package/dist/scroll.global.js +132 -40
- 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/scroll.layered.css +1 -1
- package/dist/scroll.layered.css.map +2 -2
- package/dist/shortcut.esm.js +182 -22
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +182 -22
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +4 -1
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +116 -19
- package/dist/toast.esm.js.map +2 -2
- package/dist/toast.global.js +116 -19
- package/dist/toast.global.js.map +2 -2
- package/dist/toast.global.min.js +3 -3
- 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/common/dom.d.ts +5 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +5 -2
- 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 +15 -0
- package/dist/types/mask/types.d.ts +27 -2
- package/dist/types/masonry/Masonry.d.ts +2 -0
- package/dist/types/scroll/ScrollBlock.d.ts +2 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +14 -3
- package/dist/types/toast/ToastManager.d.ts +2 -0
- package/package.json +1 -1
package/dist/toast.esm.js
CHANGED
|
@@ -10,6 +10,23 @@ function getSafeWulfNamespace() {
|
|
|
10
10
|
}
|
|
11
11
|
return existing;
|
|
12
12
|
}
|
|
13
|
+
function stripBidiAndInvisibles(raw, maxLength = 4096) {
|
|
14
|
+
const safeLimit = Math.max(0, maxLength);
|
|
15
|
+
return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
|
|
16
|
+
}
|
|
17
|
+
function getDeepActiveElement(root) {
|
|
18
|
+
if (typeof document === "undefined") return null;
|
|
19
|
+
let active = (root ?? document).activeElement;
|
|
20
|
+
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
21
|
+
active = active.shadowRoot.activeElement;
|
|
22
|
+
}
|
|
23
|
+
return active && typeof active.focus === "function" ? active : null;
|
|
24
|
+
}
|
|
25
|
+
function isImeComposing(event) {
|
|
26
|
+
return Boolean(
|
|
27
|
+
event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
|
|
28
|
+
);
|
|
29
|
+
}
|
|
13
30
|
function prefersReducedMotion() {
|
|
14
31
|
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
15
32
|
}
|
|
@@ -188,24 +205,39 @@ var AuditableComponent = class {
|
|
|
188
205
|
return warnings;
|
|
189
206
|
}
|
|
190
207
|
/**
|
|
191
|
-
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
|
|
192
|
-
* pointe vers des éléments réellement présents dans le document.
|
|
208
|
+
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
|
|
209
|
+
* pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
|
|
193
210
|
*/
|
|
194
|
-
checkAriaIdReferences(element, attrName, warnings) {
|
|
211
|
+
checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
|
|
195
212
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
196
213
|
if (!rawValue) return false;
|
|
197
214
|
const doc = element.ownerDocument || document;
|
|
198
215
|
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
199
216
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
200
|
-
const
|
|
201
|
-
(id) =>
|
|
217
|
+
const targets = ids.map(
|
|
218
|
+
(id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
|
|
202
219
|
);
|
|
203
|
-
|
|
220
|
+
const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
|
|
221
|
+
if (!allFound) {
|
|
204
222
|
warnings.push(
|
|
205
223
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
206
224
|
);
|
|
225
|
+
return false;
|
|
207
226
|
}
|
|
208
|
-
|
|
227
|
+
if (requireNonEmptyText) {
|
|
228
|
+
const hasNonEmptyText = targets.some((el) => {
|
|
229
|
+
if (!el) return false;
|
|
230
|
+
const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
|
|
231
|
+
return text.length > 0;
|
|
232
|
+
});
|
|
233
|
+
if (!hasNonEmptyText) {
|
|
234
|
+
warnings.push(
|
|
235
|
+
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
|
|
236
|
+
);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
209
241
|
}
|
|
210
242
|
};
|
|
211
243
|
|
|
@@ -300,17 +332,18 @@ var toastI18n = createI18nManager("fr", {
|
|
|
300
332
|
// src/toast/ToastInstance.ts
|
|
301
333
|
var nextToastId = 1;
|
|
302
334
|
var DEFAULT_TOAST_DURATION = 5e3;
|
|
335
|
+
var SAFE_COLOR_FALLBACK_RE = /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lch|lab)\([^;{}<>\\]+\)|[a-z]{3,20})$/i;
|
|
303
336
|
function isSafeCssValue(val) {
|
|
304
337
|
if (!val || typeof val !== "string" || val.length > 128) return false;
|
|
305
338
|
const trimmed = val.trim();
|
|
306
339
|
if (!trimmed) return false;
|
|
307
|
-
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
|
|
340
|
+
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env|var)\s*\(/i.test(trimmed)) {
|
|
308
341
|
return false;
|
|
309
342
|
}
|
|
310
343
|
if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
|
|
311
344
|
return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
|
|
312
345
|
}
|
|
313
|
-
return
|
|
346
|
+
return SAFE_COLOR_FALLBACK_RE.test(trimmed);
|
|
314
347
|
}
|
|
315
348
|
function sanitizeIconClasses(icon) {
|
|
316
349
|
return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
|
|
@@ -339,7 +372,7 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
339
372
|
this.id = `wulf-toast-${nextToastId++}`;
|
|
340
373
|
this.options = Object.freeze({ ...options });
|
|
341
374
|
this.onDismissCallback = onDismiss;
|
|
342
|
-
this.previousActiveElement =
|
|
375
|
+
this.previousActiveElement = getDeepActiveElement();
|
|
343
376
|
const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
|
|
344
377
|
if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
|
|
345
378
|
this.remainingTime = Math.min(duration, 2147483647);
|
|
@@ -426,7 +459,30 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
426
459
|
}
|
|
427
460
|
}
|
|
428
461
|
const content = document.createElement("div");
|
|
429
|
-
|
|
462
|
+
const isInteractiveContent = Boolean(this.options.onClick || this.options.closeOnClick);
|
|
463
|
+
content.className = isInteractiveContent ? "wulf-toast-content wulf-toast-content--interactive" : "wulf-toast-content";
|
|
464
|
+
if (isInteractiveContent) {
|
|
465
|
+
content.setAttribute("role", "button");
|
|
466
|
+
content.setAttribute("tabindex", "0");
|
|
467
|
+
content.addEventListener("keydown", (e) => {
|
|
468
|
+
if (isImeComposing(e)) return;
|
|
469
|
+
if (e.key === "Enter") {
|
|
470
|
+
e.preventDefault();
|
|
471
|
+
e.stopPropagation();
|
|
472
|
+
content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
473
|
+
} else if (e.key === " ") {
|
|
474
|
+
e.preventDefault();
|
|
475
|
+
e.stopPropagation();
|
|
476
|
+
}
|
|
477
|
+
}, { signal: this.eventsAbortController.signal });
|
|
478
|
+
content.addEventListener("keyup", (e) => {
|
|
479
|
+
if (e.key === " ") {
|
|
480
|
+
e.preventDefault();
|
|
481
|
+
e.stopPropagation();
|
|
482
|
+
content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
483
|
+
}
|
|
484
|
+
}, { signal: this.eventsAbortController.signal });
|
|
485
|
+
}
|
|
430
486
|
if (this.options.title && this.options.title.trim() !== "") {
|
|
431
487
|
const titleEl = document.createElement("div");
|
|
432
488
|
titleEl.className = "wulf-toast-title";
|
|
@@ -470,7 +526,7 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
470
526
|
* Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
|
|
471
527
|
*/
|
|
472
528
|
appendTextWithLineBreaks(container, text) {
|
|
473
|
-
const safeText = String(text ?? "")
|
|
529
|
+
const safeText = stripBidiAndInvisibles(String(text ?? ""), 4096);
|
|
474
530
|
const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
|
|
475
531
|
lines.forEach((line, index) => {
|
|
476
532
|
if (index > 0) {
|
|
@@ -486,7 +542,11 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
486
542
|
const { signal } = this.eventsAbortController;
|
|
487
543
|
this.element.addEventListener("click", (e) => {
|
|
488
544
|
if (this.options.onClick) {
|
|
489
|
-
|
|
545
|
+
try {
|
|
546
|
+
this.options.onClick(this, e);
|
|
547
|
+
} catch (err) {
|
|
548
|
+
console.error("[Wulf.Toast] Erreur dans le callback onClick:", err);
|
|
549
|
+
}
|
|
490
550
|
}
|
|
491
551
|
if (this.options.closeOnClick) {
|
|
492
552
|
this.close("toast-click");
|
|
@@ -509,6 +569,7 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
509
569
|
}, { signal });
|
|
510
570
|
this.element.addEventListener("keydown", (e) => {
|
|
511
571
|
if (e.key === "Escape" && (this.options.closable ?? true)) {
|
|
572
|
+
if (isImeComposing(e)) return;
|
|
512
573
|
e.stopPropagation();
|
|
513
574
|
this.close("close-button");
|
|
514
575
|
}
|
|
@@ -543,7 +604,8 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
543
604
|
this.timerStartTime = performance.now();
|
|
544
605
|
this.timerId = window.setTimeout(() => {
|
|
545
606
|
this.timerId = null;
|
|
546
|
-
|
|
607
|
+
const active = getDeepActiveElement();
|
|
608
|
+
if (active && this.element.contains(active)) {
|
|
547
609
|
this.isPendingFocusDismiss = true;
|
|
548
610
|
return;
|
|
549
611
|
}
|
|
@@ -583,6 +645,10 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
583
645
|
this.isPausedByFocus = false;
|
|
584
646
|
} else if (source === "hover") {
|
|
585
647
|
this.isPausedByHover = false;
|
|
648
|
+
const active = getDeepActiveElement();
|
|
649
|
+
if (active && this.element.contains(active)) {
|
|
650
|
+
this.isPausedByFocus = true;
|
|
651
|
+
}
|
|
586
652
|
} else {
|
|
587
653
|
this.isPausedByHover = false;
|
|
588
654
|
this.isPausedByFocus = false;
|
|
@@ -606,7 +672,11 @@ var ToastInstance = class extends AuditableComponent {
|
|
|
606
672
|
this.element.parentNode.removeChild(this.element);
|
|
607
673
|
}
|
|
608
674
|
if (this.options.onClose) {
|
|
609
|
-
|
|
675
|
+
try {
|
|
676
|
+
this.options.onClose(this, reason);
|
|
677
|
+
} catch (err) {
|
|
678
|
+
console.error("[Wulf.Toast] Erreur dans le callback onClose:", err);
|
|
679
|
+
}
|
|
610
680
|
}
|
|
611
681
|
}
|
|
612
682
|
/**
|
|
@@ -666,6 +736,7 @@ var FOCUSABLE_IN_TOAST = 'button:not([disabled]), [href], [tabindex]:not([tabind
|
|
|
666
736
|
var ToastManager = class _ToastManager {
|
|
667
737
|
static instance = null;
|
|
668
738
|
containers = /* @__PURE__ */ new Map();
|
|
739
|
+
containerBaseLabels = /* @__PURE__ */ new WeakMap();
|
|
669
740
|
activeToasts = /* @__PURE__ */ new Map();
|
|
670
741
|
announcerEl = null;
|
|
671
742
|
politeRegion = null;
|
|
@@ -787,7 +858,7 @@ var ToastManager = class _ToastManager {
|
|
|
787
858
|
* Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
|
|
788
859
|
*/
|
|
789
860
|
announce(toast) {
|
|
790
|
-
const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => val.trim());
|
|
861
|
+
const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => stripBidiAndInvisibles(val, 512).trim()).filter(Boolean);
|
|
791
862
|
if (parts.length === 0) return;
|
|
792
863
|
const rawText = parts.join(". ");
|
|
793
864
|
const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
|
|
@@ -899,7 +970,8 @@ var ToastManager = class _ToastManager {
|
|
|
899
970
|
* Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
|
|
900
971
|
*/
|
|
901
972
|
handleFocusHandoff(toast, list) {
|
|
902
|
-
|
|
973
|
+
const active = getDeepActiveElement();
|
|
974
|
+
if (!active || !toast.element.contains(active)) {
|
|
903
975
|
return;
|
|
904
976
|
}
|
|
905
977
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
@@ -912,7 +984,15 @@ var ToastManager = class _ToastManager {
|
|
|
912
984
|
}
|
|
913
985
|
}
|
|
914
986
|
const prev = toast.getPreviousActiveElement();
|
|
915
|
-
if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
|
|
987
|
+
if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.hidden && !prev.closest("[hidden]") && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true" && (prev.tabIndex >= 0 || prev.getAttribute("tabindex") !== null)) {
|
|
988
|
+
const prevWithCheck = prev;
|
|
989
|
+
if (typeof prevWithCheck.checkVisibility === "function" && !prevWithCheck.checkVisibility({
|
|
990
|
+
checkOpacity: false,
|
|
991
|
+
checkVisibilityCSS: true,
|
|
992
|
+
visibilityProperty: true
|
|
993
|
+
})) {
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
916
996
|
try {
|
|
917
997
|
prev.focus();
|
|
918
998
|
} catch {
|
|
@@ -940,6 +1020,7 @@ var ToastManager = class _ToastManager {
|
|
|
940
1020
|
this.disposeContainer(container);
|
|
941
1021
|
this.containers.delete(position);
|
|
942
1022
|
this.activeToasts.delete(position);
|
|
1023
|
+
this.syncContainerRegionLabels();
|
|
943
1024
|
}
|
|
944
1025
|
}
|
|
945
1026
|
} else if (toast.element.parentNode) {
|
|
@@ -978,6 +1059,7 @@ var ToastManager = class _ToastManager {
|
|
|
978
1059
|
this.disposeContainer(container);
|
|
979
1060
|
this.containers.delete(position);
|
|
980
1061
|
this.activeToasts.delete(position);
|
|
1062
|
+
this.syncContainerRegionLabels();
|
|
981
1063
|
}
|
|
982
1064
|
}
|
|
983
1065
|
} else {
|
|
@@ -1010,6 +1092,7 @@ var ToastManager = class _ToastManager {
|
|
|
1010
1092
|
this.activeToasts.delete(pos);
|
|
1011
1093
|
}
|
|
1012
1094
|
}
|
|
1095
|
+
this.syncContainerRegionLabels();
|
|
1013
1096
|
}
|
|
1014
1097
|
});
|
|
1015
1098
|
}
|
|
@@ -1021,6 +1104,10 @@ var ToastManager = class _ToastManager {
|
|
|
1021
1104
|
window.clearTimeout(timerId);
|
|
1022
1105
|
}
|
|
1023
1106
|
this.announceTimers = [];
|
|
1107
|
+
this.politeAnnounceTimerId = null;
|
|
1108
|
+
this.assertiveAnnounceTimerId = null;
|
|
1109
|
+
this.politeClearTimerId = null;
|
|
1110
|
+
this.assertiveClearTimerId = null;
|
|
1024
1111
|
for (const list of Array.from(this.activeToasts.values())) {
|
|
1025
1112
|
for (const toast of [...list]) {
|
|
1026
1113
|
toast.destroyImmediate("programmatic");
|
|
@@ -1041,6 +1128,13 @@ var ToastManager = class _ToastManager {
|
|
|
1041
1128
|
}
|
|
1042
1129
|
_ToastManager.instance = null;
|
|
1043
1130
|
}
|
|
1131
|
+
syncContainerRegionLabels() {
|
|
1132
|
+
const useSuffix = this.containers.size > 1;
|
|
1133
|
+
for (const [pos, container] of this.containers.entries()) {
|
|
1134
|
+
const baseLabel = this.containerBaseLabels.get(container) || toastI18n.t("notificationsRegion");
|
|
1135
|
+
container.setAttribute("aria-label", useSuffix ? `${baseLabel} (${pos})` : baseLabel);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1044
1138
|
/**
|
|
1045
1139
|
* Récupère ou crée le conteneur DOM pour une position d'affichage.
|
|
1046
1140
|
*/
|
|
@@ -1050,12 +1144,15 @@ var ToastManager = class _ToastManager {
|
|
|
1050
1144
|
container = document.createElement("div");
|
|
1051
1145
|
container.className = `wulf-toast-container wulf-toast-${position}`;
|
|
1052
1146
|
container.setAttribute("role", "region");
|
|
1053
|
-
|
|
1147
|
+
const baseLabel = toastI18n.t("notificationsRegion", toast.options.i18n);
|
|
1148
|
+
this.containerBaseLabels.set(container, baseLabel);
|
|
1149
|
+
container.setAttribute("aria-label", baseLabel);
|
|
1054
1150
|
if (useTopLayer && typeof container.showPopover === "function") {
|
|
1055
1151
|
container.setAttribute("popover", "manual");
|
|
1056
1152
|
}
|
|
1057
1153
|
document.body.appendChild(container);
|
|
1058
1154
|
this.containers.set(position, container);
|
|
1155
|
+
this.syncContainerRegionLabels();
|
|
1059
1156
|
}
|
|
1060
1157
|
return container;
|
|
1061
1158
|
}
|