wulf.js 2.1.0 → 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/changelog.md +10 -0
- package/dist/focus-trap.esm.js +88 -30
- package/dist/focus-trap.esm.js.map +2 -2
- package/dist/focus-trap.global.js +88 -30
- 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 +541 -162
- package/dist/index.esm.js.map +2 -2
- package/dist/index.global.js +541 -162
- package/dist/index.global.js.map +2 -2
- package/dist/index.global.min.js +2 -2
- package/dist/index.global.min.js.map +3 -3
- package/dist/mask.esm.js +4 -4
- package/dist/mask.esm.js.map +2 -2
- package/dist/mask.global.js +4 -4
- package/dist/mask.global.js.map +2 -2
- package/dist/mask.global.min.js +2 -2
- package/dist/mask.global.min.js.map +3 -3
- package/dist/masonry.esm.js +153 -62
- package/dist/masonry.esm.js.map +2 -2
- package/dist/masonry.global.js +153 -62
- 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 +108 -31
- package/dist/scroll.esm.js.map +2 -2
- package/dist/scroll.global.js +108 -31
- 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 +92 -13
- package/dist/toast.esm.js.map +2 -2
- package/dist/toast.global.js +92 -13
- 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/dom.d.ts +5 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +5 -2
- package/dist/types/mask/paste.d.ts +2 -5
- 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.global.js
CHANGED
|
@@ -44,6 +44,23 @@ var __WulfIIFE = (() => {
|
|
|
44
44
|
}
|
|
45
45
|
return existing;
|
|
46
46
|
}
|
|
47
|
+
function stripBidiAndInvisibles(raw, maxLength = 4096) {
|
|
48
|
+
const safeLimit = Math.max(0, maxLength);
|
|
49
|
+
return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
|
|
50
|
+
}
|
|
51
|
+
function getDeepActiveElement(root) {
|
|
52
|
+
if (typeof document === "undefined") return null;
|
|
53
|
+
let active = (root ?? document).activeElement;
|
|
54
|
+
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
55
|
+
active = active.shadowRoot.activeElement;
|
|
56
|
+
}
|
|
57
|
+
return active && typeof active.focus === "function" ? active : null;
|
|
58
|
+
}
|
|
59
|
+
function isImeComposing(event) {
|
|
60
|
+
return Boolean(
|
|
61
|
+
event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
|
|
62
|
+
);
|
|
63
|
+
}
|
|
47
64
|
function prefersReducedMotion() {
|
|
48
65
|
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
49
66
|
}
|
|
@@ -349,17 +366,18 @@ var __WulfIIFE = (() => {
|
|
|
349
366
|
// src/toast/ToastInstance.ts
|
|
350
367
|
var nextToastId = 1;
|
|
351
368
|
var DEFAULT_TOAST_DURATION = 5e3;
|
|
369
|
+
var SAFE_COLOR_FALLBACK_RE = /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lch|lab)\([^;{}<>\\]+\)|[a-z]{3,20})$/i;
|
|
352
370
|
function isSafeCssValue(val) {
|
|
353
371
|
if (!val || typeof val !== "string" || val.length > 128) return false;
|
|
354
372
|
const trimmed = val.trim();
|
|
355
373
|
if (!trimmed) return false;
|
|
356
|
-
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
|
|
374
|
+
if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env|var)\s*\(/i.test(trimmed)) {
|
|
357
375
|
return false;
|
|
358
376
|
}
|
|
359
377
|
if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
|
|
360
378
|
return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
|
|
361
379
|
}
|
|
362
|
-
return
|
|
380
|
+
return SAFE_COLOR_FALLBACK_RE.test(trimmed);
|
|
363
381
|
}
|
|
364
382
|
function sanitizeIconClasses(icon) {
|
|
365
383
|
return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
|
|
@@ -388,7 +406,7 @@ var __WulfIIFE = (() => {
|
|
|
388
406
|
this.id = `wulf-toast-${nextToastId++}`;
|
|
389
407
|
this.options = Object.freeze({ ...options });
|
|
390
408
|
this.onDismissCallback = onDismiss;
|
|
391
|
-
this.previousActiveElement =
|
|
409
|
+
this.previousActiveElement = getDeepActiveElement();
|
|
392
410
|
const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
|
|
393
411
|
if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
|
|
394
412
|
this.remainingTime = Math.min(duration, 2147483647);
|
|
@@ -475,7 +493,30 @@ var __WulfIIFE = (() => {
|
|
|
475
493
|
}
|
|
476
494
|
}
|
|
477
495
|
const content = document.createElement("div");
|
|
478
|
-
|
|
496
|
+
const isInteractiveContent = Boolean(this.options.onClick || this.options.closeOnClick);
|
|
497
|
+
content.className = isInteractiveContent ? "wulf-toast-content wulf-toast-content--interactive" : "wulf-toast-content";
|
|
498
|
+
if (isInteractiveContent) {
|
|
499
|
+
content.setAttribute("role", "button");
|
|
500
|
+
content.setAttribute("tabindex", "0");
|
|
501
|
+
content.addEventListener("keydown", (e) => {
|
|
502
|
+
if (isImeComposing(e)) return;
|
|
503
|
+
if (e.key === "Enter") {
|
|
504
|
+
e.preventDefault();
|
|
505
|
+
e.stopPropagation();
|
|
506
|
+
content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
507
|
+
} else if (e.key === " ") {
|
|
508
|
+
e.preventDefault();
|
|
509
|
+
e.stopPropagation();
|
|
510
|
+
}
|
|
511
|
+
}, { signal: this.eventsAbortController.signal });
|
|
512
|
+
content.addEventListener("keyup", (e) => {
|
|
513
|
+
if (e.key === " ") {
|
|
514
|
+
e.preventDefault();
|
|
515
|
+
e.stopPropagation();
|
|
516
|
+
content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
517
|
+
}
|
|
518
|
+
}, { signal: this.eventsAbortController.signal });
|
|
519
|
+
}
|
|
479
520
|
if (this.options.title && this.options.title.trim() !== "") {
|
|
480
521
|
const titleEl = document.createElement("div");
|
|
481
522
|
titleEl.className = "wulf-toast-title";
|
|
@@ -519,7 +560,7 @@ var __WulfIIFE = (() => {
|
|
|
519
560
|
* Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
|
|
520
561
|
*/
|
|
521
562
|
appendTextWithLineBreaks(container, text) {
|
|
522
|
-
const safeText = String(text ?? "")
|
|
563
|
+
const safeText = stripBidiAndInvisibles(String(text ?? ""), 4096);
|
|
523
564
|
const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
|
|
524
565
|
lines.forEach((line, index) => {
|
|
525
566
|
if (index > 0) {
|
|
@@ -535,7 +576,11 @@ var __WulfIIFE = (() => {
|
|
|
535
576
|
const { signal } = this.eventsAbortController;
|
|
536
577
|
this.element.addEventListener("click", (e) => {
|
|
537
578
|
if (this.options.onClick) {
|
|
538
|
-
|
|
579
|
+
try {
|
|
580
|
+
this.options.onClick(this, e);
|
|
581
|
+
} catch (err) {
|
|
582
|
+
console.error("[Wulf.Toast] Erreur dans le callback onClick:", err);
|
|
583
|
+
}
|
|
539
584
|
}
|
|
540
585
|
if (this.options.closeOnClick) {
|
|
541
586
|
this.close("toast-click");
|
|
@@ -558,6 +603,7 @@ var __WulfIIFE = (() => {
|
|
|
558
603
|
}, { signal });
|
|
559
604
|
this.element.addEventListener("keydown", (e) => {
|
|
560
605
|
if (e.key === "Escape" && (this.options.closable ?? true)) {
|
|
606
|
+
if (isImeComposing(e)) return;
|
|
561
607
|
e.stopPropagation();
|
|
562
608
|
this.close("close-button");
|
|
563
609
|
}
|
|
@@ -592,7 +638,8 @@ var __WulfIIFE = (() => {
|
|
|
592
638
|
this.timerStartTime = performance.now();
|
|
593
639
|
this.timerId = window.setTimeout(() => {
|
|
594
640
|
this.timerId = null;
|
|
595
|
-
|
|
641
|
+
const active = getDeepActiveElement();
|
|
642
|
+
if (active && this.element.contains(active)) {
|
|
596
643
|
this.isPendingFocusDismiss = true;
|
|
597
644
|
return;
|
|
598
645
|
}
|
|
@@ -632,7 +679,8 @@ var __WulfIIFE = (() => {
|
|
|
632
679
|
this.isPausedByFocus = false;
|
|
633
680
|
} else if (source === "hover") {
|
|
634
681
|
this.isPausedByHover = false;
|
|
635
|
-
|
|
682
|
+
const active = getDeepActiveElement();
|
|
683
|
+
if (active && this.element.contains(active)) {
|
|
636
684
|
this.isPausedByFocus = true;
|
|
637
685
|
}
|
|
638
686
|
} else {
|
|
@@ -658,7 +706,11 @@ var __WulfIIFE = (() => {
|
|
|
658
706
|
this.element.parentNode.removeChild(this.element);
|
|
659
707
|
}
|
|
660
708
|
if (this.options.onClose) {
|
|
661
|
-
|
|
709
|
+
try {
|
|
710
|
+
this.options.onClose(this, reason);
|
|
711
|
+
} catch (err) {
|
|
712
|
+
console.error("[Wulf.Toast] Erreur dans le callback onClose:", err);
|
|
713
|
+
}
|
|
662
714
|
}
|
|
663
715
|
}
|
|
664
716
|
/**
|
|
@@ -718,6 +770,7 @@ var __WulfIIFE = (() => {
|
|
|
718
770
|
var ToastManager = class _ToastManager {
|
|
719
771
|
static instance = null;
|
|
720
772
|
containers = /* @__PURE__ */ new Map();
|
|
773
|
+
containerBaseLabels = /* @__PURE__ */ new WeakMap();
|
|
721
774
|
activeToasts = /* @__PURE__ */ new Map();
|
|
722
775
|
announcerEl = null;
|
|
723
776
|
politeRegion = null;
|
|
@@ -839,7 +892,7 @@ var __WulfIIFE = (() => {
|
|
|
839
892
|
* Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
|
|
840
893
|
*/
|
|
841
894
|
announce(toast) {
|
|
842
|
-
const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => val.trim());
|
|
895
|
+
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);
|
|
843
896
|
if (parts.length === 0) return;
|
|
844
897
|
const rawText = parts.join(". ");
|
|
845
898
|
const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
|
|
@@ -951,7 +1004,8 @@ var __WulfIIFE = (() => {
|
|
|
951
1004
|
* Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
|
|
952
1005
|
*/
|
|
953
1006
|
handleFocusHandoff(toast, list) {
|
|
954
|
-
|
|
1007
|
+
const active = getDeepActiveElement();
|
|
1008
|
+
if (!active || !toast.element.contains(active)) {
|
|
955
1009
|
return;
|
|
956
1010
|
}
|
|
957
1011
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
@@ -964,7 +1018,15 @@ var __WulfIIFE = (() => {
|
|
|
964
1018
|
}
|
|
965
1019
|
}
|
|
966
1020
|
const prev = toast.getPreviousActiveElement();
|
|
967
|
-
if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
|
|
1021
|
+
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)) {
|
|
1022
|
+
const prevWithCheck = prev;
|
|
1023
|
+
if (typeof prevWithCheck.checkVisibility === "function" && !prevWithCheck.checkVisibility({
|
|
1024
|
+
checkOpacity: false,
|
|
1025
|
+
checkVisibilityCSS: true,
|
|
1026
|
+
visibilityProperty: true
|
|
1027
|
+
})) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
968
1030
|
try {
|
|
969
1031
|
prev.focus();
|
|
970
1032
|
} catch {
|
|
@@ -992,6 +1054,7 @@ var __WulfIIFE = (() => {
|
|
|
992
1054
|
this.disposeContainer(container);
|
|
993
1055
|
this.containers.delete(position);
|
|
994
1056
|
this.activeToasts.delete(position);
|
|
1057
|
+
this.syncContainerRegionLabels();
|
|
995
1058
|
}
|
|
996
1059
|
}
|
|
997
1060
|
} else if (toast.element.parentNode) {
|
|
@@ -1030,6 +1093,7 @@ var __WulfIIFE = (() => {
|
|
|
1030
1093
|
this.disposeContainer(container);
|
|
1031
1094
|
this.containers.delete(position);
|
|
1032
1095
|
this.activeToasts.delete(position);
|
|
1096
|
+
this.syncContainerRegionLabels();
|
|
1033
1097
|
}
|
|
1034
1098
|
}
|
|
1035
1099
|
} else {
|
|
@@ -1062,6 +1126,7 @@ var __WulfIIFE = (() => {
|
|
|
1062
1126
|
this.activeToasts.delete(pos);
|
|
1063
1127
|
}
|
|
1064
1128
|
}
|
|
1129
|
+
this.syncContainerRegionLabels();
|
|
1065
1130
|
}
|
|
1066
1131
|
});
|
|
1067
1132
|
}
|
|
@@ -1073,6 +1138,10 @@ var __WulfIIFE = (() => {
|
|
|
1073
1138
|
window.clearTimeout(timerId);
|
|
1074
1139
|
}
|
|
1075
1140
|
this.announceTimers = [];
|
|
1141
|
+
this.politeAnnounceTimerId = null;
|
|
1142
|
+
this.assertiveAnnounceTimerId = null;
|
|
1143
|
+
this.politeClearTimerId = null;
|
|
1144
|
+
this.assertiveClearTimerId = null;
|
|
1076
1145
|
for (const list of Array.from(this.activeToasts.values())) {
|
|
1077
1146
|
for (const toast of [...list]) {
|
|
1078
1147
|
toast.destroyImmediate("programmatic");
|
|
@@ -1093,6 +1162,13 @@ var __WulfIIFE = (() => {
|
|
|
1093
1162
|
}
|
|
1094
1163
|
_ToastManager.instance = null;
|
|
1095
1164
|
}
|
|
1165
|
+
syncContainerRegionLabels() {
|
|
1166
|
+
const useSuffix = this.containers.size > 1;
|
|
1167
|
+
for (const [pos, container] of this.containers.entries()) {
|
|
1168
|
+
const baseLabel = this.containerBaseLabels.get(container) || toastI18n.t("notificationsRegion");
|
|
1169
|
+
container.setAttribute("aria-label", useSuffix ? `${baseLabel} (${pos})` : baseLabel);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1096
1172
|
/**
|
|
1097
1173
|
* Récupère ou crée le conteneur DOM pour une position d'affichage.
|
|
1098
1174
|
*/
|
|
@@ -1102,12 +1178,15 @@ var __WulfIIFE = (() => {
|
|
|
1102
1178
|
container = document.createElement("div");
|
|
1103
1179
|
container.className = `wulf-toast-container wulf-toast-${position}`;
|
|
1104
1180
|
container.setAttribute("role", "region");
|
|
1105
|
-
|
|
1181
|
+
const baseLabel = toastI18n.t("notificationsRegion", toast.options.i18n);
|
|
1182
|
+
this.containerBaseLabels.set(container, baseLabel);
|
|
1183
|
+
container.setAttribute("aria-label", baseLabel);
|
|
1106
1184
|
if (useTopLayer && typeof container.showPopover === "function") {
|
|
1107
1185
|
container.setAttribute("popover", "manual");
|
|
1108
1186
|
}
|
|
1109
1187
|
document.body.appendChild(container);
|
|
1110
1188
|
this.containers.set(position, container);
|
|
1189
|
+
this.syncContainerRegionLabels();
|
|
1111
1190
|
}
|
|
1112
1191
|
return container;
|
|
1113
1192
|
}
|