wulf.js 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -11
- package/changelog.md +50 -0
- package/dist/anchor.esm.js +9 -0
- package/dist/anchor.esm.js.map +7 -0
- package/dist/anchor.global.js +695 -0
- package/dist/anchor.global.js.map +7 -0
- package/dist/anchor.global.min.js +6 -0
- package/dist/anchor.global.min.js.map +7 -0
- package/dist/autosize.css +1 -0
- package/dist/autosize.css.map +7 -0
- package/dist/autosize.esm.js +10 -0
- package/dist/autosize.esm.js.map +7 -0
- package/dist/autosize.global.js +657 -0
- package/dist/autosize.global.js.map +7 -0
- package/dist/autosize.global.min.js +6 -0
- package/dist/autosize.global.min.js.map +7 -0
- package/dist/autosize.layered.css +1 -0
- package/dist/autosize.layered.css.map +7 -0
- package/dist/chunks/chunk-22AIMRD5.js +119 -0
- package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
- package/dist/chunks/chunk-5N2IRGDM.js +766 -0
- package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
- package/dist/chunks/chunk-72FVCNNZ.js +863 -0
- package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
- package/dist/chunks/chunk-AXZYYW7H.js +865 -0
- package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
- package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
- package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
- package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
- package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
- package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
- package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
- package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
- package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
- package/dist/chunks/chunk-QV46A7FV.js +197 -0
- package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
- package/dist/chunks/chunk-SXLUXN6W.js +612 -0
- package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
- package/dist/chunks/chunk-T2H4EJCW.js +621 -0
- package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
- package/dist/chunks/chunk-TILLYEF2.js +6044 -0
- package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
- package/dist/chunks/chunk-VJO22BAT.js +72 -0
- package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
- package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
- package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
- package/dist/focus-trap.esm.js +6 -594
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +176 -61
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +79 -10448
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +3660 -202
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +6 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +16 -6094
- package/dist/mask.esm.js.map +4 -4
- package/dist/mask.global.js +44 -55
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +3 -3
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +15 -1158
- package/dist/masonry.esm.js.map +4 -4
- package/dist/masonry.global.js +84 -94
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +14 -1252
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +64 -58
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +3 -3
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -1
- package/dist/scroll.layered.css.map +2 -2
- package/dist/shortcut.esm.js +6 -901
- package/dist/shortcut.esm.js.map +4 -4
- package/dist/shortcut.global.js +43 -36
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +6 -3
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/size-report.json +319 -0
- package/dist/sortable.css +1 -0
- package/dist/sortable.css.map +7 -0
- package/dist/sortable.esm.js +22 -0
- package/dist/sortable.esm.js.map +7 -0
- package/dist/sortable.global.js +1477 -0
- package/dist/sortable.global.js.map +7 -0
- package/dist/sortable.global.min.js +6 -0
- package/dist/sortable.global.min.js.map +7 -0
- package/dist/sortable.layered.css +1 -0
- package/dist/sortable.layered.css.map +7 -0
- package/dist/sri-manifest.json +64 -0
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +19 -1208
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +314 -111
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +3 -3
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -1
- package/dist/toast.layered.css.map +2 -2
- package/dist/types/anchor/Anchor.d.ts +41 -0
- package/dist/types/anchor/index.d.ts +3 -0
- package/dist/types/anchor/types.d.ts +115 -0
- package/dist/types/autosize/Autosize.d.ts +71 -0
- package/dist/types/autosize/index.d.ts +3 -0
- package/dist/types/autosize/types.d.ts +66 -0
- package/dist/types/common/AuditableComponent.d.ts +1 -1
- package/dist/types/common/registry.d.ts +40 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +3 -1
- package/dist/types/index.d.ts +13 -1
- package/dist/types/scroll/types.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +2 -0
- package/dist/types/shortcut/types.d.ts +5 -0
- package/dist/types/sortable/Sortable.d.ts +75 -0
- package/dist/types/sortable/i18n/en.d.ts +2 -0
- package/dist/types/sortable/i18n/fr.d.ts +2 -0
- package/dist/types/sortable/i18n/index.d.ts +9 -0
- package/dist/types/sortable/i18n/types.d.ts +15 -0
- package/dist/types/sortable/index.d.ts +4 -0
- package/dist/types/sortable/types.d.ts +112 -0
- package/dist/types/toast/Toast.d.ts +6 -1
- package/dist/types/toast/ToastInstance.d.ts +7 -0
- package/dist/types/toast/ToastManager.d.ts +2 -2
- package/dist/types/toast/types.d.ts +27 -1
- package/dist/types/undo/UndoManager.d.ts +112 -0
- package/dist/types/undo/i18n/en.d.ts +2 -0
- package/dist/types/undo/i18n/fr.d.ts +2 -0
- package/dist/types/undo/i18n/index.d.ts +9 -0
- package/dist/types/undo/i18n/types.d.ts +6 -0
- package/dist/types/undo/index.d.ts +5 -0
- package/dist/types/undo/types.d.ts +106 -0
- package/dist/undo.esm.js +23 -0
- package/dist/undo.esm.js.map +7 -0
- package/dist/undo.global.js +1029 -0
- package/dist/undo.global.js.map +7 -0
- package/dist/undo.global.min.js +6 -0
- package/dist/undo.global.min.js.map +7 -0
- package/package.json +54 -5
package/dist/scroll.esm.js
CHANGED
|
@@ -1,1261 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof window === "undefined") return null;
|
|
4
|
-
const win = window;
|
|
5
|
-
const existing = win.Wulf;
|
|
6
|
-
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
7
|
-
const fresh = {};
|
|
8
|
-
win.Wulf = fresh;
|
|
9
|
-
return fresh;
|
|
10
|
-
}
|
|
11
|
-
return existing;
|
|
12
|
-
}
|
|
13
|
-
function safeMove(parent, node, referenceNode = null) {
|
|
14
|
-
const moveBefore = parent.moveBefore;
|
|
15
|
-
if (typeof moveBefore === "function" && node.isConnected && parent.isConnected && typeof parent.getRootNode === "function" && typeof node.getRootNode === "function" && parent.getRootNode() === node.getRootNode()) {
|
|
16
|
-
try {
|
|
17
|
-
moveBefore.call(parent, node, referenceNode);
|
|
18
|
-
return;
|
|
19
|
-
} catch {
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
parent.insertBefore(node, referenceNode);
|
|
23
|
-
}
|
|
24
|
-
function prefersReducedMotion() {
|
|
25
|
-
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// src/common/AuditableComponent.ts
|
|
29
|
-
var AuditableComponent = class {
|
|
30
|
-
/**
|
|
31
|
-
* Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
|
|
32
|
-
*/
|
|
33
|
-
getAuditDisableHint() {
|
|
34
|
-
return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
|
|
38
|
-
* si l'audit est activé et que des contraintes manquent.
|
|
39
|
-
*/
|
|
40
|
-
runAuditWarning(enabled = true) {
|
|
41
|
-
if (!enabled) return [];
|
|
42
|
-
const warnings = this.audit();
|
|
43
|
-
if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
|
|
44
|
-
console.warn(
|
|
45
|
-
`[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
|
|
46
|
-
` + warnings.map((w) => ` - ${w}`).join("\n") + `
|
|
47
|
-
(${this.getAuditDisableHint()})`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return warnings;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
|
|
54
|
-
* pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
|
|
55
|
-
*/
|
|
56
|
-
checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
|
|
57
|
-
const rawValue = element.getAttribute(attrName)?.trim();
|
|
58
|
-
if (!rawValue) return false;
|
|
59
|
-
const doc = element.ownerDocument || document;
|
|
60
|
-
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
61
|
-
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
62
|
-
const targets = ids.map(
|
|
63
|
-
(id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
|
|
64
|
-
);
|
|
65
|
-
const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
|
|
66
|
-
if (!allFound) {
|
|
67
|
-
warnings.push(
|
|
68
|
-
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
69
|
-
);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
if (requireNonEmptyText) {
|
|
73
|
-
const hasNonEmptyText = targets.some((el) => {
|
|
74
|
-
if (!el) return false;
|
|
75
|
-
const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
|
|
76
|
-
return text.length > 0;
|
|
77
|
-
});
|
|
78
|
-
if (!hasNonEmptyText) {
|
|
79
|
-
warnings.push(
|
|
80
|
-
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
|
|
81
|
-
);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// src/common/LocalizedComponent.ts
|
|
90
|
-
var LocalizedComponent = class extends AuditableComponent {
|
|
91
|
-
static _i18n;
|
|
92
|
-
/**
|
|
93
|
-
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
94
|
-
*/
|
|
95
|
-
static setLocale(locale) {
|
|
96
|
-
if (this._i18n) {
|
|
97
|
-
this._i18n.setLocale(locale);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Retourne la langue globale active du composant.
|
|
102
|
-
*/
|
|
103
|
-
static getLocale() {
|
|
104
|
-
return this._i18n ? this._i18n.getLocale() : "";
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Enregistre un dictionnaire de traduction pour une langue donnée.
|
|
108
|
-
*/
|
|
109
|
-
static registerLocale(locale, translations) {
|
|
110
|
-
if (this._i18n) {
|
|
111
|
-
this._i18n.registerLocale(locale, translations);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Surcharge les libellés globalement pour ce composant.
|
|
116
|
-
*/
|
|
117
|
-
static setI18n(overrides) {
|
|
118
|
-
if (this._i18n) {
|
|
119
|
-
this._i18n.setI18n(overrides);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Retourne l'ensemble des libellés actifs résolus du composant.
|
|
124
|
-
*/
|
|
125
|
-
static getI18n() {
|
|
126
|
-
return this._i18n ? this._i18n.getAll() : {};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Réinitialise les réglages de langue et surcharges globales.
|
|
130
|
-
*/
|
|
131
|
-
static resetI18n() {
|
|
132
|
-
if (this._i18n) {
|
|
133
|
-
this._i18n.reset();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Résout une clé au niveau statique de la classe.
|
|
138
|
-
*/
|
|
139
|
-
static t(key, instanceOverride) {
|
|
140
|
-
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Surcharges de localisation spécifiques à cette instance.
|
|
144
|
-
*/
|
|
145
|
-
i18nOverrides;
|
|
146
|
-
constructor(i18nOverrides) {
|
|
147
|
-
super();
|
|
148
|
-
this.i18nOverrides = i18nOverrides;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Traduit une clé en tenant compte automatiquement des surcharges de l'instance courante.
|
|
152
|
-
*/
|
|
153
|
-
t(key) {
|
|
154
|
-
const ctor = this.constructor;
|
|
155
|
-
return ctor._i18n ? ctor._i18n.t(key, this.i18nOverrides) : String(key);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// src/common/i18n.ts
|
|
160
|
-
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
161
|
-
function isSafeKey(key) {
|
|
162
|
-
return Boolean(key) && !FORBIDDEN_KEYS.has(key);
|
|
163
|
-
}
|
|
164
|
-
function normalizeLocaleCode(locale) {
|
|
165
|
-
const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
|
|
166
|
-
return isSafeKey(norm) ? norm : "";
|
|
167
|
-
}
|
|
168
|
-
function getPrimaryLanguage(normalizedLocale) {
|
|
169
|
-
const dashIndex = normalizedLocale.indexOf("-");
|
|
170
|
-
const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
171
|
-
return primary && isSafeKey(primary) ? primary : null;
|
|
172
|
-
}
|
|
173
|
-
function assignDefined(target, source) {
|
|
174
|
-
if (!source || typeof source !== "object") return target;
|
|
175
|
-
for (const key of Object.keys(source)) {
|
|
176
|
-
if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
|
|
177
|
-
target[key] = source[key];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return target;
|
|
181
|
-
}
|
|
182
|
-
function createI18nManager(defaultLocale, locales) {
|
|
183
|
-
const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
|
|
184
|
-
const initialLocales = /* @__PURE__ */ Object.create(null);
|
|
185
|
-
for (const [loc, dict] of Object.entries(locales)) {
|
|
186
|
-
const norm = normalizeLocaleCode(loc);
|
|
187
|
-
if (norm) {
|
|
188
|
-
initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
let currentLocale = fallbackLocale;
|
|
192
|
-
let activeLocales = /* @__PURE__ */ Object.create(null);
|
|
193
|
-
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
194
|
-
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
195
|
-
}
|
|
196
|
-
let globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
197
|
-
function resolveActiveDictionaries() {
|
|
198
|
-
const dicts = [];
|
|
199
|
-
if (isSafeKey(currentLocale)) {
|
|
200
|
-
const exact = activeLocales[currentLocale];
|
|
201
|
-
if (exact) dicts.push(exact);
|
|
202
|
-
}
|
|
203
|
-
const primary = getPrimaryLanguage(currentLocale);
|
|
204
|
-
if (primary && activeLocales[primary]) {
|
|
205
|
-
dicts.push(activeLocales[primary]);
|
|
206
|
-
}
|
|
207
|
-
return dicts;
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
setLocale(locale) {
|
|
211
|
-
if (locale && typeof locale === "string" && locale.trim()) {
|
|
212
|
-
const norm = normalizeLocaleCode(locale);
|
|
213
|
-
if (norm) {
|
|
214
|
-
currentLocale = norm;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
getLocale() {
|
|
219
|
-
return currentLocale;
|
|
220
|
-
},
|
|
221
|
-
registerLocale(locale, translations) {
|
|
222
|
-
if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
|
|
223
|
-
const norm = normalizeLocaleCode(locale);
|
|
224
|
-
if (!norm) return;
|
|
225
|
-
const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
|
|
226
|
-
activeLocales[norm] = assignDefined(base, translations);
|
|
227
|
-
},
|
|
228
|
-
setI18n(overrides) {
|
|
229
|
-
if (!overrides || typeof overrides !== "object") return;
|
|
230
|
-
const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
|
|
231
|
-
globalOverrides = assignDefined(base, overrides);
|
|
232
|
-
},
|
|
233
|
-
t(key, instanceOverride) {
|
|
234
|
-
if (!isSafeKey(String(key))) {
|
|
235
|
-
return "";
|
|
236
|
-
}
|
|
237
|
-
if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
|
|
238
|
-
return String(instanceOverride[key]);
|
|
239
|
-
}
|
|
240
|
-
if (globalOverrides[key] !== void 0) {
|
|
241
|
-
return String(globalOverrides[key]);
|
|
242
|
-
}
|
|
243
|
-
for (const dict of resolveActiveDictionaries()) {
|
|
244
|
-
if (dict[key] !== void 0) {
|
|
245
|
-
return String(dict[key]);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
const fallbackDict = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
249
|
-
if (fallbackDict && fallbackDict[key] !== void 0) {
|
|
250
|
-
return String(fallbackDict[key]);
|
|
251
|
-
}
|
|
252
|
-
return String(key);
|
|
253
|
-
},
|
|
254
|
-
getAll(instanceOverride) {
|
|
255
|
-
const result = {};
|
|
256
|
-
const fallback = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
257
|
-
assignDefined(result, fallback);
|
|
258
|
-
const activeDicts = resolveActiveDictionaries().reverse();
|
|
259
|
-
for (const dict of activeDicts) {
|
|
260
|
-
assignDefined(result, dict);
|
|
261
|
-
}
|
|
262
|
-
assignDefined(result, globalOverrides);
|
|
263
|
-
assignDefined(result, instanceOverride);
|
|
264
|
-
return result;
|
|
265
|
-
},
|
|
266
|
-
reset() {
|
|
267
|
-
currentLocale = fallbackLocale;
|
|
268
|
-
globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
269
|
-
activeLocales = /* @__PURE__ */ Object.create(null);
|
|
270
|
-
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
271
|
-
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// src/scroll/i18n/fr.ts
|
|
278
|
-
var scrollFr = {
|
|
279
|
-
viewport: "Zone de contenu d\xE9filable",
|
|
280
|
-
verticalThumb: "D\xE9filement vertical",
|
|
281
|
-
horizontalThumb: "D\xE9filement horizontal"
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
// src/scroll/i18n/en.ts
|
|
285
|
-
var scrollEn = {
|
|
286
|
-
viewport: "Scrollable content area",
|
|
287
|
-
verticalThumb: "Vertical scroll",
|
|
288
|
-
horizontalThumb: "Horizontal scroll"
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// src/scroll/i18n/index.ts
|
|
292
|
-
var scrollI18n = createI18nManager("fr", {
|
|
293
|
-
fr: scrollFr,
|
|
294
|
-
en: scrollEn
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
// src/scroll/ScrollBlock.ts
|
|
298
|
-
var idCounter = 0;
|
|
299
|
-
var ScrollBlock = class extends LocalizedComponent {
|
|
300
|
-
static _i18n = scrollI18n;
|
|
301
|
-
static i18n = scrollI18n;
|
|
302
|
-
root;
|
|
303
|
-
viewport;
|
|
304
|
-
options;
|
|
305
|
-
createdViewport = false;
|
|
306
|
-
isDestroyed = false;
|
|
307
|
-
wasIdGenerated = false;
|
|
308
|
-
wasRoleInferred = false;
|
|
309
|
-
wasAriaLabelInferred = false;
|
|
310
|
-
hasExplicitAriaLabel = false;
|
|
311
|
-
hasRootAriaLabel = false;
|
|
312
|
-
propagatedRootLabel = null;
|
|
313
|
-
lastInferredAriaLabel = "";
|
|
314
|
-
trackY;
|
|
315
|
-
thumbY;
|
|
316
|
-
trackX;
|
|
317
|
-
thumbX;
|
|
318
|
-
resizeObserver;
|
|
319
|
-
mutationObserver;
|
|
320
|
-
observedChildren = /* @__PURE__ */ new Set();
|
|
321
|
-
hideTimer;
|
|
322
|
-
scrollEndFallbackTimer;
|
|
323
|
-
rafId = null;
|
|
324
|
-
resizeRafId = null;
|
|
325
|
-
abortController = new AbortController();
|
|
326
|
-
dragAbortController;
|
|
327
|
-
activeScrollToController;
|
|
328
|
-
supportsScrollEnd = typeof window !== "undefined" && "onscrollend" in window;
|
|
329
|
-
// Cache de métriques géométriques mis à jour dans update() pour éviter tout forced reflow en cours de scroll
|
|
330
|
-
cachedMaxTop = 0;
|
|
331
|
-
cachedMaxLeft = 0;
|
|
332
|
-
cachedTrackHeight = 0;
|
|
333
|
-
cachedThumbHeight = 0;
|
|
334
|
-
cachedTrackWidth = 0;
|
|
335
|
-
cachedThumbWidth = 0;
|
|
336
|
-
isDragging = false;
|
|
337
|
-
dragAxis;
|
|
338
|
-
dragPointerId;
|
|
339
|
-
dragStartPos = 0;
|
|
340
|
-
dragStartScroll = 0;
|
|
341
|
-
atBottom = false;
|
|
342
|
-
atTop = true;
|
|
343
|
-
atRight = false;
|
|
344
|
-
atLeft = true;
|
|
345
|
-
// Références d'écouteurs d'événements pour les callbacks et le drag
|
|
346
|
-
boundOnScroll;
|
|
347
|
-
boundOnScrollEnd;
|
|
348
|
-
boundOnMouseEnter;
|
|
349
|
-
boundOnMouseLeave;
|
|
350
|
-
boundOnFocusIn;
|
|
351
|
-
boundOnFocusOut;
|
|
352
|
-
boundPointerMove;
|
|
353
|
-
boundPointerUp;
|
|
354
|
-
constructor(element, options) {
|
|
355
|
-
super(options?.i18n);
|
|
356
|
-
let resolvedElement = null;
|
|
357
|
-
if (typeof element === "string") {
|
|
358
|
-
try {
|
|
359
|
-
resolvedElement = document.querySelector(element);
|
|
360
|
-
} catch {
|
|
361
|
-
resolvedElement = null;
|
|
362
|
-
}
|
|
363
|
-
} else {
|
|
364
|
-
resolvedElement = element;
|
|
365
|
-
}
|
|
366
|
-
if (!resolvedElement || !(resolvedElement instanceof HTMLElement)) {
|
|
367
|
-
throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
|
|
368
|
-
}
|
|
369
|
-
this.root = resolvedElement;
|
|
370
|
-
this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
|
|
371
|
-
const rawDelay = options?.autoHideDelay;
|
|
372
|
-
const safeAutoHideDelay = typeof rawDelay === "number" && Number.isFinite(rawDelay) && rawDelay >= 0 ? Math.min(rawDelay, 2147483647) : 1e3;
|
|
373
|
-
const rawMinThumb = options?.minThumbSize;
|
|
374
|
-
const safeMinThumbSize = typeof rawMinThumb === "number" && Number.isFinite(rawMinThumb) && rawMinThumb > 0 ? rawMinThumb : 24;
|
|
375
|
-
const rawEdge = options?.edgeThreshold;
|
|
376
|
-
const safeEdgeThreshold = typeof rawEdge === "number" && Number.isFinite(rawEdge) && rawEdge >= 0 ? rawEdge : 10;
|
|
377
|
-
this.options = {
|
|
378
|
-
axis: options?.axis || "y",
|
|
379
|
-
mode: options?.mode || "custom",
|
|
380
|
-
autoHide: options?.autoHide ?? true,
|
|
381
|
-
autoHideDelay: safeAutoHideDelay,
|
|
382
|
-
alwaysVisible: options?.alwaysVisible ?? false,
|
|
383
|
-
ariaLabel: options?.ariaLabel || this.t("viewport"),
|
|
384
|
-
i18n: options?.i18n || {},
|
|
385
|
-
minThumbSize: safeMinThumbSize,
|
|
386
|
-
edgeThreshold: safeEdgeThreshold,
|
|
387
|
-
onScroll: options?.onScroll || (() => {
|
|
388
|
-
}),
|
|
389
|
-
onScrollEnd: options?.onScrollEnd || (() => {
|
|
390
|
-
}),
|
|
391
|
-
onTotalScroll: options?.onTotalScroll || (() => {
|
|
392
|
-
}),
|
|
393
|
-
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
394
|
-
}),
|
|
395
|
-
audit: options?.audit ?? true
|
|
396
|
-
};
|
|
397
|
-
this.boundOnScroll = this.handleScroll.bind(this);
|
|
398
|
-
this.boundOnScrollEnd = this.handleScrollEnd.bind(this);
|
|
399
|
-
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
400
|
-
this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
|
|
401
|
-
this.boundOnFocusIn = this.handleFocusIn.bind(this);
|
|
402
|
-
this.boundOnFocusOut = this.handleFocusOut.bind(this);
|
|
403
|
-
this.boundPointerMove = this.handlePointerMove.bind(this);
|
|
404
|
-
this.boundPointerUp = this.handlePointerUp.bind(this);
|
|
405
|
-
this.viewport = this.setupViewport();
|
|
406
|
-
this.setupAccessibility();
|
|
407
|
-
this.setupScrollbars();
|
|
408
|
-
this.setupEventListeners();
|
|
409
|
-
this.setupObserver();
|
|
410
|
-
this.update();
|
|
411
|
-
this.runAuditWarning(this.options.audit);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Prépare le viewport défilant sans altérer les éléments enfants.
|
|
415
|
-
*/
|
|
416
|
-
setupViewport() {
|
|
417
|
-
this.root.classList.add("wulf-scrollblock");
|
|
418
|
-
if (this.options.mode === "native") {
|
|
419
|
-
this.root.classList.add("wulf-scrollblock--native");
|
|
420
|
-
}
|
|
421
|
-
if (this.options.alwaysVisible) {
|
|
422
|
-
this.root.classList.add("is-always-visible");
|
|
423
|
-
}
|
|
424
|
-
if (this.options.axis === "both") {
|
|
425
|
-
this.root.classList.add("has-both-axes");
|
|
426
|
-
}
|
|
427
|
-
const existingViewport = this.root.querySelector(":scope > .wulf-scrollblock-viewport");
|
|
428
|
-
if (existingViewport) {
|
|
429
|
-
return existingViewport;
|
|
430
|
-
}
|
|
431
|
-
const existingChildren = Array.from(this.root.childNodes);
|
|
432
|
-
const viewport = document.createElement("div");
|
|
433
|
-
viewport.className = "wulf-scrollblock-viewport";
|
|
434
|
-
this.root.appendChild(viewport);
|
|
435
|
-
for (const child of existingChildren) {
|
|
436
|
-
safeMove(viewport, child, null);
|
|
437
|
-
}
|
|
438
|
-
this.createdViewport = true;
|
|
439
|
-
return viewport;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Configure les attributs WAI-ARIA pour une accessibilité maximale.
|
|
443
|
-
*/
|
|
444
|
-
setupAccessibility() {
|
|
445
|
-
if (!this.viewport.id) {
|
|
446
|
-
idCounter += 1;
|
|
447
|
-
this.viewport.id = `wulf-scrollblock-vp-${idCounter}`;
|
|
448
|
-
this.wasIdGenerated = true;
|
|
449
|
-
}
|
|
450
|
-
if (!this.viewport.hasAttribute("role")) {
|
|
451
|
-
this.viewport.setAttribute("role", "region");
|
|
452
|
-
this.wasRoleInferred = true;
|
|
453
|
-
}
|
|
454
|
-
const rootLabelledBy = this.root.getAttribute("aria-labelledby")?.trim();
|
|
455
|
-
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
456
|
-
if (rootLabelledBy) {
|
|
457
|
-
this.hasRootAriaLabel = true;
|
|
458
|
-
if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-labelledby") && !this.viewport.hasAttribute("aria-label")) {
|
|
459
|
-
this.viewport.setAttribute("aria-labelledby", rootLabelledBy);
|
|
460
|
-
this.propagatedRootLabel = "aria-labelledby";
|
|
461
|
-
}
|
|
462
|
-
} else if (rootAriaLabel) {
|
|
463
|
-
this.hasRootAriaLabel = true;
|
|
464
|
-
if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
|
|
465
|
-
this.viewport.setAttribute("aria-label", rootAriaLabel);
|
|
466
|
-
this.propagatedRootLabel = "aria-label";
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
if (this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label")) {
|
|
470
|
-
this.viewport.setAttribute("aria-label", this.options.ariaLabel);
|
|
471
|
-
this.lastInferredAriaLabel = this.options.ariaLabel;
|
|
472
|
-
this.wasAriaLabelInferred = true;
|
|
473
|
-
} else if (!this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
|
|
474
|
-
const label = this.t("viewport");
|
|
475
|
-
this.viewport.setAttribute("aria-label", label);
|
|
476
|
-
this.lastInferredAriaLabel = label;
|
|
477
|
-
this.wasAriaLabelInferred = true;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Synchronise dynamiquement les libellés ARIA si la langue globale change après montage.
|
|
482
|
-
*/
|
|
483
|
-
syncAccessibilityLabels() {
|
|
484
|
-
if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
|
|
485
|
-
const currentAttr = this.viewport.getAttribute("aria-label");
|
|
486
|
-
if (currentAttr === this.lastInferredAriaLabel) {
|
|
487
|
-
const nextLabel = this.t("viewport");
|
|
488
|
-
this.viewport.setAttribute("aria-label", nextLabel);
|
|
489
|
-
this.lastInferredAriaLabel = nextLabel;
|
|
490
|
-
this.options.ariaLabel = nextLabel;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
if (this.thumbY) {
|
|
494
|
-
this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
|
|
495
|
-
}
|
|
496
|
-
if (this.thumbX) {
|
|
497
|
-
this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Crée les rails et curseurs selon l'axe sélectionné.
|
|
502
|
-
*/
|
|
503
|
-
setupScrollbars() {
|
|
504
|
-
if (this.options.mode === "native") {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
if (this.options.axis === "y" || this.options.axis === "both") {
|
|
508
|
-
this.trackY = document.createElement("div");
|
|
509
|
-
this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
|
|
510
|
-
this.thumbY = document.createElement("div");
|
|
511
|
-
this.thumbY.className = "wulf-scrollblock-thumb";
|
|
512
|
-
this.thumbY.setAttribute("role", "scrollbar");
|
|
513
|
-
this.thumbY.setAttribute("aria-orientation", "vertical");
|
|
514
|
-
this.thumbY.setAttribute("aria-controls", this.viewport.id);
|
|
515
|
-
this.thumbY.setAttribute("aria-valuenow", "0");
|
|
516
|
-
this.thumbY.setAttribute("aria-valuemin", "0");
|
|
517
|
-
this.thumbY.setAttribute("aria-valuemax", "100");
|
|
518
|
-
this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
|
|
519
|
-
this.trackY.appendChild(this.thumbY);
|
|
520
|
-
this.root.appendChild(this.trackY);
|
|
521
|
-
this.attachTrackListeners(this.trackY, this.thumbY, "y");
|
|
522
|
-
}
|
|
523
|
-
if (this.options.axis === "x" || this.options.axis === "both") {
|
|
524
|
-
this.trackX = document.createElement("div");
|
|
525
|
-
this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
|
|
526
|
-
this.thumbX = document.createElement("div");
|
|
527
|
-
this.thumbX.className = "wulf-scrollblock-thumb";
|
|
528
|
-
this.thumbX.setAttribute("role", "scrollbar");
|
|
529
|
-
this.thumbX.setAttribute("aria-orientation", "horizontal");
|
|
530
|
-
this.thumbX.setAttribute("aria-controls", this.viewport.id);
|
|
531
|
-
this.thumbX.setAttribute("aria-valuenow", "0");
|
|
532
|
-
this.thumbX.setAttribute("aria-valuemin", "0");
|
|
533
|
-
this.thumbX.setAttribute("aria-valuemax", "100");
|
|
534
|
-
this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
|
|
535
|
-
this.trackX.appendChild(this.thumbX);
|
|
536
|
-
this.root.appendChild(this.trackX);
|
|
537
|
-
this.attachTrackListeners(this.trackX, this.thumbX, "x");
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
isRtl() {
|
|
541
|
-
return typeof window !== "undefined" && window.getComputedStyle(this.viewport).direction === "rtl";
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Attache les écouteurs souris/pointeur et clavier WAI-ARIA sur un rail et son curseur.
|
|
545
|
-
*/
|
|
546
|
-
attachTrackListeners(track, thumb, axis) {
|
|
547
|
-
const { signal } = this.abortController;
|
|
548
|
-
thumb.addEventListener("pointerdown", (e) => {
|
|
549
|
-
if (e.button !== 0) return;
|
|
550
|
-
e.preventDefault();
|
|
551
|
-
e.stopPropagation();
|
|
552
|
-
this.dragAbortController?.abort();
|
|
553
|
-
this.dragAbortController = new AbortController();
|
|
554
|
-
const dragSignal = this.dragAbortController.signal;
|
|
555
|
-
this.isDragging = true;
|
|
556
|
-
this.dragAxis = axis;
|
|
557
|
-
this.dragPointerId = e.pointerId;
|
|
558
|
-
this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
|
|
559
|
-
this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
560
|
-
try {
|
|
561
|
-
thumb.setPointerCapture(e.pointerId);
|
|
562
|
-
} catch {
|
|
563
|
-
}
|
|
564
|
-
thumb.classList.add("is-active");
|
|
565
|
-
this.root.classList.add("is-dragging");
|
|
566
|
-
window.addEventListener("pointermove", this.boundPointerMove, { signal: dragSignal });
|
|
567
|
-
window.addEventListener("pointerup", this.boundPointerUp, { signal: dragSignal });
|
|
568
|
-
window.addEventListener("pointercancel", this.boundPointerUp, { signal: dragSignal });
|
|
569
|
-
thumb.addEventListener("lostpointercapture", this.boundPointerUp, { signal: dragSignal });
|
|
570
|
-
}, { signal });
|
|
571
|
-
thumb.addEventListener("keydown", (e) => {
|
|
572
|
-
if (e.ctrlKey || e.altKey || e.metaKey) return;
|
|
573
|
-
const step = 40;
|
|
574
|
-
const page = axis === "y" ? Math.max(step, Math.round(this.viewport.clientHeight * 0.9)) : Math.max(step, Math.round(this.viewport.clientWidth * 0.9));
|
|
575
|
-
const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
576
|
-
if (maxScroll <= 0) return;
|
|
577
|
-
const rtl = axis === "x" && this.isRtl();
|
|
578
|
-
const current = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
579
|
-
let target = null;
|
|
580
|
-
if (axis === "y") {
|
|
581
|
-
switch (e.key) {
|
|
582
|
-
case "ArrowDown":
|
|
583
|
-
target = current + step;
|
|
584
|
-
break;
|
|
585
|
-
case "ArrowUp":
|
|
586
|
-
target = current - step;
|
|
587
|
-
break;
|
|
588
|
-
case "PageDown":
|
|
589
|
-
target = current + page;
|
|
590
|
-
break;
|
|
591
|
-
case "PageUp":
|
|
592
|
-
target = current - page;
|
|
593
|
-
break;
|
|
594
|
-
case " ":
|
|
595
|
-
target = current + (e.shiftKey ? -page : page);
|
|
596
|
-
break;
|
|
597
|
-
case "Home":
|
|
598
|
-
target = 0;
|
|
599
|
-
break;
|
|
600
|
-
case "End":
|
|
601
|
-
target = maxScroll;
|
|
602
|
-
break;
|
|
603
|
-
}
|
|
604
|
-
} else {
|
|
605
|
-
switch (e.key) {
|
|
606
|
-
case "ArrowRight":
|
|
607
|
-
target = current + step;
|
|
608
|
-
break;
|
|
609
|
-
case "ArrowLeft":
|
|
610
|
-
target = current - step;
|
|
611
|
-
break;
|
|
612
|
-
case "PageDown":
|
|
613
|
-
target = current + (rtl ? -page : page);
|
|
614
|
-
break;
|
|
615
|
-
case "PageUp":
|
|
616
|
-
target = current + (rtl ? page : -page);
|
|
617
|
-
break;
|
|
618
|
-
case " ":
|
|
619
|
-
target = current + (e.shiftKey ? rtl ? page : -page : rtl ? -page : page);
|
|
620
|
-
break;
|
|
621
|
-
case "Home":
|
|
622
|
-
target = 0;
|
|
623
|
-
break;
|
|
624
|
-
case "End":
|
|
625
|
-
target = rtl ? -maxScroll : maxScroll;
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if (target === null) return;
|
|
630
|
-
e.preventDefault();
|
|
631
|
-
e.stopPropagation();
|
|
632
|
-
void this.scrollTo(axis === "y" ? { top: target } : { left: target }, { smooth: false });
|
|
633
|
-
this.syncThumbs();
|
|
634
|
-
}, { signal });
|
|
635
|
-
track.addEventListener("pointerdown", (e) => {
|
|
636
|
-
if (e.button !== 0 || e.target === thumb) return;
|
|
637
|
-
e.preventDefault();
|
|
638
|
-
const rtl = axis === "x" && this.isRtl();
|
|
639
|
-
const rect = track.getBoundingClientRect();
|
|
640
|
-
const clickPos = axis === "y" ? e.clientY - rect.top : rtl ? rect.right - e.clientX : e.clientX - rect.left;
|
|
641
|
-
const trackSize = axis === "y" ? rect.height : rect.width;
|
|
642
|
-
if (trackSize <= 0) return;
|
|
643
|
-
const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
644
|
-
const ratio = Math.max(0, Math.min(1, clickPos / trackSize));
|
|
645
|
-
const targetScroll = rtl ? -(ratio * maxScroll) : ratio * maxScroll;
|
|
646
|
-
void this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
647
|
-
}, { signal });
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Écouteurs globaux sur le viewport et les interactions.
|
|
651
|
-
*/
|
|
652
|
-
setupEventListeners() {
|
|
653
|
-
const { signal } = this.abortController;
|
|
654
|
-
this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true, signal });
|
|
655
|
-
if (this.supportsScrollEnd) {
|
|
656
|
-
this.viewport.addEventListener("scrollend", this.boundOnScrollEnd, { passive: true, signal });
|
|
657
|
-
}
|
|
658
|
-
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
659
|
-
this.root.addEventListener("mouseenter", this.boundOnMouseEnter, { signal });
|
|
660
|
-
this.root.addEventListener("mouseleave", this.boundOnMouseLeave, { signal });
|
|
661
|
-
this.root.addEventListener("focusin", this.boundOnFocusIn, { signal });
|
|
662
|
-
this.root.addEventListener("focusout", this.boundOnFocusOut, { signal });
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Initialise le ResizeObserver réactif.
|
|
667
|
-
*/
|
|
668
|
-
setupObserver() {
|
|
669
|
-
const scheduleUpdate = () => {
|
|
670
|
-
if (this.isDestroyed || this.resizeRafId !== null) return;
|
|
671
|
-
this.resizeRafId = window.requestAnimationFrame(() => {
|
|
672
|
-
this.resizeRafId = null;
|
|
673
|
-
if (!this.isDestroyed) {
|
|
674
|
-
this.update();
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
};
|
|
678
|
-
if (typeof ResizeObserver !== "undefined") {
|
|
679
|
-
this.resizeObserver = new ResizeObserver(scheduleUpdate);
|
|
680
|
-
this.resizeObserver.observe(this.root);
|
|
681
|
-
this.resizeObserver.observe(this.viewport);
|
|
682
|
-
for (const child of Array.from(this.viewport.children)) {
|
|
683
|
-
this.resizeObserver.observe(child);
|
|
684
|
-
this.observedChildren.add(child);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
if (typeof MutationObserver !== "undefined") {
|
|
688
|
-
this.mutationObserver = new MutationObserver(scheduleUpdate);
|
|
689
|
-
this.mutationObserver.observe(this.viewport, { childList: true });
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* Déplacement lors du glissement du curseur.
|
|
694
|
-
*/
|
|
695
|
-
handlePointerMove(e) {
|
|
696
|
-
if (!this.isDragging || !this.dragAxis) return;
|
|
697
|
-
if (this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) return;
|
|
698
|
-
const isY = this.dragAxis === "y";
|
|
699
|
-
const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
|
|
700
|
-
const trackSize = isY ? this.cachedTrackHeight : this.cachedTrackWidth;
|
|
701
|
-
const thumbSize = isY ? this.cachedThumbHeight : this.cachedThumbWidth;
|
|
702
|
-
const maxScroll = isY ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
703
|
-
const maxThumbTravel = trackSize - thumbSize;
|
|
704
|
-
if (maxThumbTravel <= 0 || maxScroll <= 0) return;
|
|
705
|
-
const ratio = maxScroll / maxThumbTravel;
|
|
706
|
-
const nextScroll = this.dragStartScroll + delta * ratio;
|
|
707
|
-
if (isY) {
|
|
708
|
-
this.viewport.scrollTop = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
709
|
-
} else if (this.isRtl()) {
|
|
710
|
-
this.viewport.scrollLeft = Math.max(-maxScroll, Math.min(0, nextScroll));
|
|
711
|
-
} else {
|
|
712
|
-
this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Relâchement de la capture du pointeur.
|
|
717
|
-
*/
|
|
718
|
-
handlePointerUp(e) {
|
|
719
|
-
if (!this.isDragging) return;
|
|
720
|
-
if (e && e.type !== "lostpointercapture" && this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
if (this.dragPointerId !== void 0) {
|
|
724
|
-
const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
|
|
725
|
-
try {
|
|
726
|
-
if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
|
|
727
|
-
activeThumb.releasePointerCapture(this.dragPointerId);
|
|
728
|
-
}
|
|
729
|
-
} catch {
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
this.dragAbortController?.abort();
|
|
733
|
-
this.dragAbortController = void 0;
|
|
734
|
-
this.isDragging = false;
|
|
735
|
-
this.dragAxis = void 0;
|
|
736
|
-
this.dragPointerId = void 0;
|
|
737
|
-
this.thumbY?.classList.remove("is-active");
|
|
738
|
-
this.thumbX?.classList.remove("is-active");
|
|
739
|
-
this.root.classList.remove("is-dragging");
|
|
740
|
-
this.scheduleAutoHide();
|
|
741
|
-
}
|
|
742
|
-
getScrollInfo() {
|
|
743
|
-
const { scrollTop, scrollLeft } = this.viewport;
|
|
744
|
-
const maxTop = this.cachedMaxTop;
|
|
745
|
-
const maxLeft = this.cachedMaxLeft;
|
|
746
|
-
const rtl = this.isRtl();
|
|
747
|
-
const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
|
|
748
|
-
const progressY = maxTop > 0 ? Math.max(0, Math.min(1, scrollTop / maxTop)) : 0;
|
|
749
|
-
const progressX = maxLeft > 0 ? Math.max(0, Math.min(1, logicalLeft / maxLeft)) : 0;
|
|
750
|
-
return {
|
|
751
|
-
top: scrollTop,
|
|
752
|
-
left: scrollLeft,
|
|
753
|
-
maxTop,
|
|
754
|
-
maxLeft,
|
|
755
|
-
progressY: Math.round(progressY * 100),
|
|
756
|
-
progressX: Math.round(progressX * 100)
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* Gestionnaire d'événement de défilement natif.
|
|
761
|
-
*/
|
|
762
|
-
handleScroll() {
|
|
763
|
-
this.scheduleSyncThumbs();
|
|
764
|
-
const info = this.getScrollInfo();
|
|
765
|
-
const { top: scrollTop, left: scrollLeft, maxTop, maxLeft } = info;
|
|
766
|
-
try {
|
|
767
|
-
this.options.onScroll(info);
|
|
768
|
-
} catch (err) {
|
|
769
|
-
console.error("[Wulf.Scroll] Erreur dans onScroll:", err);
|
|
770
|
-
}
|
|
771
|
-
const threshold = this.options.edgeThreshold;
|
|
772
|
-
if (maxTop > 0) {
|
|
773
|
-
const nowBottom = scrollTop >= maxTop - threshold;
|
|
774
|
-
const nowTop = scrollTop <= threshold;
|
|
775
|
-
if (nowBottom && !this.atBottom) {
|
|
776
|
-
try {
|
|
777
|
-
this.options.onTotalScroll("bottom");
|
|
778
|
-
} catch (err) {
|
|
779
|
-
console.error("[Wulf.Scroll] Erreur dans onTotalScroll:", err);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (nowTop && !this.atTop) {
|
|
783
|
-
try {
|
|
784
|
-
this.options.onTotalScrollBack("top");
|
|
785
|
-
} catch (err) {
|
|
786
|
-
console.error("[Wulf.Scroll] Erreur dans onTotalScrollBack:", err);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
this.atBottom = nowBottom;
|
|
790
|
-
this.atTop = nowTop;
|
|
791
|
-
}
|
|
792
|
-
if (maxLeft > 0) {
|
|
793
|
-
const rtl = this.isRtl();
|
|
794
|
-
const nowRight = rtl ? scrollLeft >= -threshold : scrollLeft >= maxLeft - threshold;
|
|
795
|
-
const nowLeft = rtl ? scrollLeft <= -maxLeft + threshold : scrollLeft <= threshold;
|
|
796
|
-
if (nowRight && !this.atRight) {
|
|
797
|
-
try {
|
|
798
|
-
this.options.onTotalScroll("right");
|
|
799
|
-
} catch (err) {
|
|
800
|
-
console.error("[Wulf.Scroll] Erreur dans onTotalScroll:", err);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
if (nowLeft && !this.atLeft) {
|
|
804
|
-
try {
|
|
805
|
-
this.options.onTotalScrollBack("left");
|
|
806
|
-
} catch (err) {
|
|
807
|
-
console.error("[Wulf.Scroll] Erreur dans onTotalScrollBack:", err);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
this.atRight = nowRight;
|
|
811
|
-
this.atLeft = nowLeft;
|
|
812
|
-
}
|
|
813
|
-
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
814
|
-
this.clearAutoHideTimer();
|
|
815
|
-
this.root.classList.add("is-scrolling");
|
|
816
|
-
if (!this.supportsScrollEnd) {
|
|
817
|
-
this.scheduleAutoHide();
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
if (!this.supportsScrollEnd) {
|
|
821
|
-
if (this.scrollEndFallbackTimer !== void 0) {
|
|
822
|
-
window.clearTimeout(this.scrollEndFallbackTimer);
|
|
823
|
-
}
|
|
824
|
-
this.scrollEndFallbackTimer = window.setTimeout(() => {
|
|
825
|
-
this.scrollEndFallbackTimer = void 0;
|
|
826
|
-
this.handleScrollEnd();
|
|
827
|
-
}, 150);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Gestionnaire de fin de défilement (`scrollend` natif ou repli temporisé).
|
|
832
|
-
*/
|
|
833
|
-
handleScrollEnd() {
|
|
834
|
-
try {
|
|
835
|
-
this.options.onScrollEnd(this.getScrollInfo());
|
|
836
|
-
} catch (err) {
|
|
837
|
-
console.error("[Wulf.Scroll] Erreur dans onScrollEnd:", err);
|
|
838
|
-
}
|
|
839
|
-
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
840
|
-
this.scheduleAutoHide();
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Planifie une synchronisation des curseurs calée sur la prochaine trame d'affichage.
|
|
845
|
-
*/
|
|
846
|
-
scheduleSyncThumbs() {
|
|
847
|
-
if (this.options.mode === "native" || this.isDestroyed) return;
|
|
848
|
-
if (this.rafId !== null) return;
|
|
849
|
-
this.rafId = window.requestAnimationFrame(() => {
|
|
850
|
-
this.rafId = null;
|
|
851
|
-
if (!this.isDestroyed) {
|
|
852
|
-
this.syncThumbs();
|
|
853
|
-
}
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* Synchronise la position physique (via variables CSS) et ARIA des curseurs à partir des métriques en cache.
|
|
858
|
-
*/
|
|
859
|
-
syncThumbs() {
|
|
860
|
-
if (this.options.mode === "native" || this.isDestroyed) return;
|
|
861
|
-
const { scrollTop, scrollLeft } = this.viewport;
|
|
862
|
-
if (this.thumbY && this.trackY) {
|
|
863
|
-
const maxScrollY = this.cachedMaxTop;
|
|
864
|
-
const maxTravelY = this.cachedTrackHeight - this.cachedThumbHeight;
|
|
865
|
-
if (maxScrollY > 0) {
|
|
866
|
-
const ratioY = Math.max(0, Math.min(1, scrollTop / maxScrollY));
|
|
867
|
-
this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
|
|
868
|
-
if (maxTravelY > 0) {
|
|
869
|
-
const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
|
|
870
|
-
this.thumbY.style.setProperty("--scrollblock-thumb-y", `${posY}px`);
|
|
871
|
-
}
|
|
872
|
-
} else {
|
|
873
|
-
this.thumbY.setAttribute("aria-valuenow", "0");
|
|
874
|
-
this.thumbY.style.setProperty("--scrollblock-thumb-y", "0px");
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
if (this.thumbX && this.trackX) {
|
|
878
|
-
const maxScrollX = this.cachedMaxLeft;
|
|
879
|
-
const maxTravelX = this.cachedTrackWidth - this.cachedThumbWidth;
|
|
880
|
-
if (maxScrollX > 0) {
|
|
881
|
-
const rtl = this.isRtl();
|
|
882
|
-
const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
|
|
883
|
-
const ratioX = Math.max(0, Math.min(1, logicalLeft / maxScrollX));
|
|
884
|
-
this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
|
|
885
|
-
if (maxTravelX > 0) {
|
|
886
|
-
const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
|
|
887
|
-
const signedPosX = rtl ? -posX : posX;
|
|
888
|
-
this.thumbX.style.setProperty("--scrollblock-thumb-x", `${signedPosX}px`);
|
|
889
|
-
}
|
|
890
|
-
} else {
|
|
891
|
-
this.thumbX.setAttribute("aria-valuenow", "0");
|
|
892
|
-
this.thumbX.style.setProperty("--scrollblock-thumb-x", "0px");
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
handleMouseEnter() {
|
|
897
|
-
this.root.classList.add("is-visible");
|
|
898
|
-
this.clearAutoHideTimer();
|
|
899
|
-
}
|
|
900
|
-
handleMouseLeave() {
|
|
901
|
-
this.scheduleAutoHide();
|
|
902
|
-
}
|
|
903
|
-
handleFocusIn() {
|
|
904
|
-
this.root.classList.add("is-visible");
|
|
905
|
-
this.clearAutoHideTimer();
|
|
906
|
-
}
|
|
907
|
-
handleFocusOut() {
|
|
908
|
-
this.scheduleAutoHide();
|
|
909
|
-
}
|
|
910
|
-
clearAutoHideTimer() {
|
|
911
|
-
if (this.hideTimer) {
|
|
912
|
-
window.clearTimeout(this.hideTimer);
|
|
913
|
-
this.hideTimer = void 0;
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
scheduleAutoHide() {
|
|
917
|
-
if (this.options.alwaysVisible || !this.options.autoHide || this.isDragging) return;
|
|
918
|
-
this.clearAutoHideTimer();
|
|
919
|
-
this.hideTimer = window.setTimeout(() => {
|
|
920
|
-
this.root.classList.remove("is-scrolling");
|
|
921
|
-
this.root.classList.remove("is-visible");
|
|
922
|
-
}, this.options.autoHideDelay);
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Recalcule les dimensions et la visibilité des barres.
|
|
926
|
-
*/
|
|
927
|
-
update() {
|
|
928
|
-
if (this.isDestroyed) return;
|
|
929
|
-
this.syncAccessibilityLabels();
|
|
930
|
-
if (this.resizeObserver) {
|
|
931
|
-
const currentChildren = new Set(Array.from(this.viewport.children));
|
|
932
|
-
for (const prev of this.observedChildren) {
|
|
933
|
-
if (!currentChildren.has(prev)) {
|
|
934
|
-
this.resizeObserver.unobserve(prev);
|
|
935
|
-
this.observedChildren.delete(prev);
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
for (const child of currentChildren) {
|
|
939
|
-
if (!this.observedChildren.has(child)) {
|
|
940
|
-
this.resizeObserver.observe(child);
|
|
941
|
-
this.observedChildren.add(child);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
|
|
946
|
-
const trackHeight = this.trackY ? this.trackY.clientHeight : 0;
|
|
947
|
-
const trackWidth = this.trackX ? this.trackX.clientWidth : 0;
|
|
948
|
-
const cssMinY = this.thumbY && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbY).minBlockSize) || 0 : 0;
|
|
949
|
-
const cssMinX = this.thumbX && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbX).minInlineSize) || 0 : 0;
|
|
950
|
-
this.cachedMaxTop = Math.max(0, scrollHeight - clientHeight);
|
|
951
|
-
this.cachedMaxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
952
|
-
this.cachedTrackHeight = trackHeight;
|
|
953
|
-
this.cachedTrackWidth = trackWidth;
|
|
954
|
-
const canScrollY = scrollHeight > clientHeight;
|
|
955
|
-
const canScrollX = scrollWidth > clientWidth;
|
|
956
|
-
let calculatedHeight = this.cachedThumbHeight;
|
|
957
|
-
if (this.trackY && this.thumbY && canScrollY && scrollHeight > 0) {
|
|
958
|
-
const effectiveMinY = Math.max(this.options.minThumbSize, cssMinY);
|
|
959
|
-
calculatedHeight = Math.max(
|
|
960
|
-
effectiveMinY,
|
|
961
|
-
trackHeight * (clientHeight / scrollHeight)
|
|
962
|
-
);
|
|
963
|
-
this.cachedThumbHeight = calculatedHeight;
|
|
964
|
-
}
|
|
965
|
-
let calculatedWidth = this.cachedThumbWidth;
|
|
966
|
-
if (this.trackX && this.thumbX && canScrollX && scrollWidth > 0) {
|
|
967
|
-
const effectiveMinX = Math.max(this.options.minThumbSize, cssMinX);
|
|
968
|
-
calculatedWidth = Math.max(
|
|
969
|
-
effectiveMinX,
|
|
970
|
-
trackWidth * (clientWidth / scrollWidth)
|
|
971
|
-
);
|
|
972
|
-
this.cachedThumbWidth = calculatedWidth;
|
|
973
|
-
}
|
|
974
|
-
this.root.classList.toggle("has-scroll-y", canScrollY);
|
|
975
|
-
this.root.classList.toggle("has-scroll-x", canScrollX);
|
|
976
|
-
if (canScrollY || canScrollX) {
|
|
977
|
-
this.viewport.setAttribute("tabindex", "0");
|
|
978
|
-
} else {
|
|
979
|
-
this.viewport.removeAttribute("tabindex");
|
|
980
|
-
}
|
|
981
|
-
if (this.trackY && this.thumbY) {
|
|
982
|
-
this.trackY.hidden = !canScrollY;
|
|
983
|
-
if (canScrollY) {
|
|
984
|
-
this.thumbY.setAttribute("tabindex", "0");
|
|
985
|
-
this.thumbY.style.height = `${calculatedHeight}px`;
|
|
986
|
-
} else {
|
|
987
|
-
this.thumbY.removeAttribute("tabindex");
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
if (this.trackX && this.thumbX) {
|
|
991
|
-
this.trackX.hidden = !canScrollX;
|
|
992
|
-
if (canScrollX) {
|
|
993
|
-
this.thumbX.setAttribute("tabindex", "0");
|
|
994
|
-
this.thumbX.style.width = `${calculatedWidth}px`;
|
|
995
|
-
} else {
|
|
996
|
-
this.thumbX.removeAttribute("tabindex");
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
this.syncThumbs();
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Défilement programmatique direct ou lissé.
|
|
1003
|
-
* Retourne une Promesse résolue lorsque le défilement atteint sa cible.
|
|
1004
|
-
*/
|
|
1005
|
-
scrollTo(target, options) {
|
|
1006
|
-
if (this.isDestroyed) return Promise.resolve();
|
|
1007
|
-
const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
|
|
1008
|
-
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion();
|
|
1009
|
-
const behavior = shouldSmooth ? "smooth" : "auto";
|
|
1010
|
-
const rtl = this.isRtl();
|
|
1011
|
-
const { scrollHeight, clientHeight, scrollWidth, clientWidth, scrollTop, scrollLeft } = this.viewport;
|
|
1012
|
-
const maxTop = Math.max(0, scrollHeight - clientHeight);
|
|
1013
|
-
const maxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
1014
|
-
this.cachedMaxTop = maxTop;
|
|
1015
|
-
this.cachedMaxLeft = maxLeft;
|
|
1016
|
-
let targetTop;
|
|
1017
|
-
let targetLeft;
|
|
1018
|
-
if (typeof target === "number") {
|
|
1019
|
-
targetTop = target;
|
|
1020
|
-
} else if (typeof target === "string") {
|
|
1021
|
-
switch (target) {
|
|
1022
|
-
case "top":
|
|
1023
|
-
targetTop = 0;
|
|
1024
|
-
break;
|
|
1025
|
-
case "bottom":
|
|
1026
|
-
targetTop = maxTop;
|
|
1027
|
-
break;
|
|
1028
|
-
case "left":
|
|
1029
|
-
targetLeft = rtl ? -maxLeft : 0;
|
|
1030
|
-
break;
|
|
1031
|
-
case "right":
|
|
1032
|
-
targetLeft = rtl ? 0 : maxLeft;
|
|
1033
|
-
break;
|
|
1034
|
-
default: {
|
|
1035
|
-
if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
|
|
1036
|
-
const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
|
|
1037
|
-
if (this.options.axis === "x") {
|
|
1038
|
-
targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
|
|
1039
|
-
} else if (this.options.axis === "both") {
|
|
1040
|
-
targetTop = maxTop * pct;
|
|
1041
|
-
targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
|
|
1042
|
-
} else {
|
|
1043
|
-
targetTop = maxTop * pct;
|
|
1044
|
-
}
|
|
1045
|
-
break;
|
|
1046
|
-
}
|
|
1047
|
-
let el = null;
|
|
1048
|
-
try {
|
|
1049
|
-
el = this.viewport.querySelector(target);
|
|
1050
|
-
} catch {
|
|
1051
|
-
el = null;
|
|
1052
|
-
}
|
|
1053
|
-
if (el) {
|
|
1054
|
-
const vpRect = this.viewport.getBoundingClientRect();
|
|
1055
|
-
const elRect = el.getBoundingClientRect();
|
|
1056
|
-
targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
|
|
1057
|
-
targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
|
|
1058
|
-
}
|
|
1059
|
-
break;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
} else if (target instanceof HTMLElement) {
|
|
1063
|
-
if (target.isConnected && this.viewport.contains(target)) {
|
|
1064
|
-
const vpRect = this.viewport.getBoundingClientRect();
|
|
1065
|
-
const elRect = target.getBoundingClientRect();
|
|
1066
|
-
targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
|
|
1067
|
-
targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
|
|
1068
|
-
}
|
|
1069
|
-
} else if (typeof target === "object" && target !== null) {
|
|
1070
|
-
targetTop = target.top;
|
|
1071
|
-
targetLeft = target.left;
|
|
1072
|
-
}
|
|
1073
|
-
const clampedTop = targetTop !== void 0 && Number.isFinite(targetTop) ? Math.max(0, Math.min(maxTop, targetTop)) : void 0;
|
|
1074
|
-
const minLeftBound = rtl ? -maxLeft : 0;
|
|
1075
|
-
const maxLeftBound = rtl ? 0 : maxLeft;
|
|
1076
|
-
const clampedLeft = targetLeft !== void 0 && Number.isFinite(targetLeft) ? Math.max(minLeftBound, Math.min(maxLeftBound, targetLeft)) : void 0;
|
|
1077
|
-
const destTop = clampedTop ?? scrollTop;
|
|
1078
|
-
const destLeft = clampedLeft ?? scrollLeft;
|
|
1079
|
-
if (Math.abs(destTop - scrollTop) <= 1 && Math.abs(destLeft - scrollLeft) <= 1) {
|
|
1080
|
-
return Promise.resolve();
|
|
1081
|
-
}
|
|
1082
|
-
this.activeScrollToController?.abort();
|
|
1083
|
-
const waitController = new AbortController();
|
|
1084
|
-
this.activeScrollToController = waitController;
|
|
1085
|
-
const nativeResult = this.viewport.scrollTo({
|
|
1086
|
-
top: clampedTop,
|
|
1087
|
-
left: clampedLeft,
|
|
1088
|
-
behavior
|
|
1089
|
-
});
|
|
1090
|
-
if (nativeResult instanceof Promise) {
|
|
1091
|
-
return nativeResult.then(() => {
|
|
1092
|
-
if (this.activeScrollToController === waitController) {
|
|
1093
|
-
this.activeScrollToController = void 0;
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
if (behavior !== "smooth") {
|
|
1098
|
-
if (this.activeScrollToController === waitController) {
|
|
1099
|
-
this.activeScrollToController = void 0;
|
|
1100
|
-
}
|
|
1101
|
-
return Promise.resolve();
|
|
1102
|
-
}
|
|
1103
|
-
return new Promise((resolve) => {
|
|
1104
|
-
let settled = false;
|
|
1105
|
-
let idleTimerId;
|
|
1106
|
-
let maxTimerId;
|
|
1107
|
-
const finish = () => {
|
|
1108
|
-
if (settled) return;
|
|
1109
|
-
settled = true;
|
|
1110
|
-
if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
|
|
1111
|
-
if (maxTimerId !== void 0) window.clearTimeout(maxTimerId);
|
|
1112
|
-
if (this.activeScrollToController === waitController) {
|
|
1113
|
-
this.activeScrollToController = void 0;
|
|
1114
|
-
}
|
|
1115
|
-
waitController.abort();
|
|
1116
|
-
resolve();
|
|
1117
|
-
};
|
|
1118
|
-
waitController.signal.addEventListener("abort", finish, { once: true });
|
|
1119
|
-
this.abortController.signal.addEventListener("abort", finish, { once: true, signal: waitController.signal });
|
|
1120
|
-
if (this.supportsScrollEnd) {
|
|
1121
|
-
this.viewport.addEventListener("scrollend", finish, { once: true, signal: waitController.signal });
|
|
1122
|
-
} else {
|
|
1123
|
-
const bumpIdle = () => {
|
|
1124
|
-
if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
|
|
1125
|
-
idleTimerId = window.setTimeout(finish, 150);
|
|
1126
|
-
};
|
|
1127
|
-
this.viewport.addEventListener("scroll", bumpIdle, { passive: true, signal: waitController.signal });
|
|
1128
|
-
bumpIdle();
|
|
1129
|
-
}
|
|
1130
|
-
maxTimerId = window.setTimeout(finish, 2500);
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
|
|
1135
|
-
* et retourne la liste des contraintes manquantes.
|
|
1136
|
-
*/
|
|
1137
|
-
audit() {
|
|
1138
|
-
const warnings = [];
|
|
1139
|
-
const hasViewportLabelledby = this.checkAriaIdReferences(this.viewport, "aria-labelledby", warnings, true);
|
|
1140
|
-
const hasRootLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings, true);
|
|
1141
|
-
const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
|
|
1142
|
-
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
1143
|
-
const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
|
|
1144
|
-
if (!this.hasExplicitAriaLabel && !this.hasRootAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
1145
|
-
warnings.push(
|
|
1146
|
-
"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)."
|
|
1147
|
-
);
|
|
1148
|
-
}
|
|
1149
|
-
if (this.options.mode !== "native" && this.options.minThumbSize < 24) {
|
|
1150
|
-
warnings.push(
|
|
1151
|
-
`Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
|
|
1152
|
-
);
|
|
1153
|
-
}
|
|
1154
|
-
if (this.root.tabIndex > 0 || this.viewport.tabIndex > 0) {
|
|
1155
|
-
warnings.push(
|
|
1156
|
-
'Attribut tabindex > 0 d\xE9tect\xE9 sur la zone d\xE9filable : utilisez uniquement tabindex="0" ou "-1" (WCAG 2.4.3).'
|
|
1157
|
-
);
|
|
1158
|
-
}
|
|
1159
|
-
if (this.root.getAttribute("role") === "region" && this.viewport.getAttribute("role") === "region") {
|
|
1160
|
-
warnings.push(
|
|
1161
|
-
'Landmark role="region" redondant : \xE9vitez de d\xE9clarer role="region" \xE0 la fois sur le conteneur racine et sur le viewport interne.'
|
|
1162
|
-
);
|
|
1163
|
-
}
|
|
1164
|
-
return warnings;
|
|
1165
|
-
}
|
|
1166
|
-
getAuditPrefix() {
|
|
1167
|
-
return "Wulf.Scroll";
|
|
1168
|
-
}
|
|
1169
|
-
getAuditTargetLabel() {
|
|
1170
|
-
return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-scrollblock>`;
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Détruit le composant et libère toutes les ressources.
|
|
1174
|
-
*/
|
|
1175
|
-
destroy() {
|
|
1176
|
-
if (this.isDestroyed) return;
|
|
1177
|
-
if (this.isDragging) {
|
|
1178
|
-
this.handlePointerUp();
|
|
1179
|
-
}
|
|
1180
|
-
this.isDestroyed = true;
|
|
1181
|
-
this.clearAutoHideTimer();
|
|
1182
|
-
if (this.scrollEndFallbackTimer !== void 0) {
|
|
1183
|
-
window.clearTimeout(this.scrollEndFallbackTimer);
|
|
1184
|
-
this.scrollEndFallbackTimer = void 0;
|
|
1185
|
-
}
|
|
1186
|
-
if (this.rafId !== null) {
|
|
1187
|
-
window.cancelAnimationFrame(this.rafId);
|
|
1188
|
-
this.rafId = null;
|
|
1189
|
-
}
|
|
1190
|
-
if (this.resizeRafId !== null) {
|
|
1191
|
-
window.cancelAnimationFrame(this.resizeRafId);
|
|
1192
|
-
this.resizeRafId = null;
|
|
1193
|
-
}
|
|
1194
|
-
this.activeScrollToController?.abort();
|
|
1195
|
-
this.activeScrollToController = void 0;
|
|
1196
|
-
this.dragAbortController?.abort();
|
|
1197
|
-
this.dragAbortController = void 0;
|
|
1198
|
-
this.abortController.abort();
|
|
1199
|
-
if (this.resizeObserver) {
|
|
1200
|
-
this.resizeObserver.disconnect();
|
|
1201
|
-
}
|
|
1202
|
-
if (this.mutationObserver) {
|
|
1203
|
-
this.mutationObserver.disconnect();
|
|
1204
|
-
this.mutationObserver = void 0;
|
|
1205
|
-
}
|
|
1206
|
-
this.observedChildren.clear();
|
|
1207
|
-
this.trackY?.remove();
|
|
1208
|
-
this.trackX?.remove();
|
|
1209
|
-
this.root.classList.remove(
|
|
1210
|
-
"wulf-scrollblock",
|
|
1211
|
-
"wulf-scrollblock--native",
|
|
1212
|
-
"has-scroll-y",
|
|
1213
|
-
"has-scroll-x",
|
|
1214
|
-
"has-both-axes",
|
|
1215
|
-
"is-visible",
|
|
1216
|
-
"is-scrolling",
|
|
1217
|
-
"is-dragging",
|
|
1218
|
-
"is-always-visible"
|
|
1219
|
-
);
|
|
1220
|
-
if (this.createdViewport && this.viewport.parentElement === this.root) {
|
|
1221
|
-
while (this.viewport.firstChild) {
|
|
1222
|
-
safeMove(this.root, this.viewport.firstChild, this.viewport);
|
|
1223
|
-
}
|
|
1224
|
-
this.viewport.remove();
|
|
1225
|
-
} else {
|
|
1226
|
-
this.viewport.removeAttribute("tabindex");
|
|
1227
|
-
if (this.wasIdGenerated) {
|
|
1228
|
-
this.viewport.removeAttribute("id");
|
|
1229
|
-
}
|
|
1230
|
-
if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
|
|
1231
|
-
this.viewport.removeAttribute("role");
|
|
1232
|
-
}
|
|
1233
|
-
if (this.propagatedRootLabel) {
|
|
1234
|
-
this.viewport.removeAttribute(this.propagatedRootLabel);
|
|
1235
|
-
}
|
|
1236
|
-
if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
1237
|
-
this.viewport.removeAttribute("aria-label");
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
// src/scroll/index.ts
|
|
1244
|
-
var Scroll = {
|
|
1
|
+
import {
|
|
2
|
+
Scroll,
|
|
1245
3
|
ScrollBlock,
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
4
|
+
scrollEn,
|
|
5
|
+
scrollFr,
|
|
6
|
+
scrollI18n,
|
|
7
|
+
scroll_default
|
|
8
|
+
} from "./chunks/chunk-NLUQZEL4.js";
|
|
9
|
+
import {
|
|
10
|
+
LocalizedComponent,
|
|
11
|
+
createI18nManager
|
|
12
|
+
} from "./chunks/chunk-QV46A7FV.js";
|
|
13
|
+
import "./chunks/chunk-22AIMRD5.js";
|
|
14
|
+
import "./chunks/chunk-VJO22BAT.js";
|
|
1253
15
|
export {
|
|
1254
16
|
LocalizedComponent,
|
|
1255
17
|
Scroll,
|
|
1256
18
|
ScrollBlock,
|
|
1257
19
|
createI18nManager,
|
|
1258
|
-
|
|
20
|
+
scroll_default as default,
|
|
1259
21
|
scrollEn,
|
|
1260
22
|
scrollFr,
|
|
1261
23
|
scrollI18n
|