wulf.js 1.9.0 → 1.9.2
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 +220 -19
- package/changelog.md +42 -0
- package/dist/focus-trap.esm.js +407 -0
- package/dist/focus-trap.esm.js.map +7 -0
- package/dist/focus-trap.global.js +433 -0
- package/dist/focus-trap.global.js.map +7 -0
- package/dist/focus-trap.global.min.js +6 -0
- package/dist/focus-trap.global.min.js.map +7 -0
- package/dist/index.esm.js +1179 -8
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +1180 -9
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +5 -2
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +106 -2
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +107 -3
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +5 -2
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +78 -3
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +79 -4
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +5 -2
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/scroll.esm.js +78 -3
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +79 -4
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +5 -2
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/shortcut.esm.js +584 -0
- package/dist/shortcut.esm.js.map +7 -0
- package/dist/shortcut.global.js +610 -0
- package/dist/shortcut.global.js.map +7 -0
- package/dist/shortcut.global.min.js +3 -0
- package/dist/shortcut.global.min.js.map +7 -0
- package/dist/toast.esm.js +91 -2
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +92 -3
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +5 -2
- package/dist/toast.global.min.js.map +4 -4
- package/dist/types/common/AuditableComponent.d.ts +45 -0
- package/dist/types/common/LocalizedComponent.d.ts +3 -2
- package/dist/types/focus-trap/FocusTrap.d.ts +64 -0
- package/dist/types/focus-trap/index.d.ts +3 -0
- package/dist/types/focus-trap/types.d.ts +45 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mask/BaseInputMask.d.ts +14 -1
- package/dist/types/mask/InputMask.d.ts +1 -0
- package/dist/types/mask/types.d.ts +5 -2
- package/dist/types/masonry/Masonry.d.ts +7 -0
- package/dist/types/masonry/types.d.ts +7 -2
- package/dist/types/scroll/ScrollBlock.d.ts +7 -0
- package/dist/types/scroll/types.d.ts +3 -2
- package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +91 -0
- package/dist/types/shortcut/index.d.ts +4 -0
- package/dist/types/shortcut/types.d.ts +101 -0
- package/dist/types/toast/Toast.d.ts +3 -0
- package/dist/types/toast/ToastInstance.d.ts +9 -1
- package/dist/types/toast/types.d.ts +3 -2
- package/package.json +23 -10
- package/dist/index.cjs.js +0 -4783
- package/dist/index.cjs.js.map +0 -7
- package/dist/mask.cjs.js +0 -2982
- package/dist/mask.cjs.js.map +0 -7
- package/dist/masonry.cjs.js +0 -783
- package/dist/masonry.cjs.js.map +0 -7
- package/dist/scroll.cjs.js +0 -748
- package/dist/scroll.cjs.js.map +0 -7
- package/dist/toast.cjs.js +0 -626
- package/dist/toast.cjs.js.map +0 -7
package/dist/scroll.cjs.js
DELETED
|
@@ -1,748 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/scroll/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
LocalizedComponent: () => LocalizedComponent,
|
|
24
|
-
Scroll: () => Scroll,
|
|
25
|
-
ScrollBlock: () => ScrollBlock,
|
|
26
|
-
createI18nManager: () => createI18nManager,
|
|
27
|
-
default: () => index_default,
|
|
28
|
-
scrollEn: () => scrollEn,
|
|
29
|
-
scrollFr: () => scrollFr,
|
|
30
|
-
scrollI18n: () => scrollI18n
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(index_exports);
|
|
33
|
-
|
|
34
|
-
// src/common/LocalizedComponent.ts
|
|
35
|
-
var LocalizedComponent = class {
|
|
36
|
-
/**
|
|
37
|
-
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
38
|
-
*/
|
|
39
|
-
static setLocale(locale) {
|
|
40
|
-
if (this._i18n) {
|
|
41
|
-
this._i18n.setLocale(locale);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Retourne la langue globale active du composant.
|
|
46
|
-
*/
|
|
47
|
-
static getLocale() {
|
|
48
|
-
return this._i18n ? this._i18n.getLocale() : "";
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Enregistre un dictionnaire de traduction pour une langue donnée.
|
|
52
|
-
*/
|
|
53
|
-
static registerLocale(locale, translations) {
|
|
54
|
-
if (this._i18n) {
|
|
55
|
-
this._i18n.registerLocale(locale, translations);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Surcharge les libellés globalement pour ce composant.
|
|
60
|
-
*/
|
|
61
|
-
static setI18n(overrides) {
|
|
62
|
-
if (this._i18n) {
|
|
63
|
-
this._i18n.setI18n(overrides);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Retourne l'ensemble des libellés actifs résolus du composant.
|
|
68
|
-
*/
|
|
69
|
-
static getI18n() {
|
|
70
|
-
return this._i18n ? this._i18n.getAll() : {};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Réinitialise les réglages de langue et surcharges globales.
|
|
74
|
-
*/
|
|
75
|
-
static resetI18n() {
|
|
76
|
-
if (this._i18n) {
|
|
77
|
-
this._i18n.reset();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Résout une clé au niveau statique de la classe.
|
|
82
|
-
*/
|
|
83
|
-
static t(key, instanceOverride) {
|
|
84
|
-
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
85
|
-
}
|
|
86
|
-
constructor(i18nOverrides) {
|
|
87
|
-
this.i18nOverrides = i18nOverrides;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Traduit une clé en tenant compte automatiquement des surcharges de l'instance courante.
|
|
91
|
-
*/
|
|
92
|
-
t(key) {
|
|
93
|
-
const ctor = this.constructor;
|
|
94
|
-
return ctor._i18n ? ctor._i18n.t(key, this.i18nOverrides) : String(key);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/common/i18n.ts
|
|
99
|
-
function normalizeLocaleCode(locale) {
|
|
100
|
-
return locale.trim().toLowerCase().replace(/_/g, "-");
|
|
101
|
-
}
|
|
102
|
-
function getPrimaryLanguage(normalizedLocale) {
|
|
103
|
-
const dashIndex = normalizedLocale.indexOf("-");
|
|
104
|
-
return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
105
|
-
}
|
|
106
|
-
function assignDefined(target, source) {
|
|
107
|
-
if (!source) return target;
|
|
108
|
-
for (const key of Object.keys(source)) {
|
|
109
|
-
if (source[key] !== void 0) {
|
|
110
|
-
target[key] = source[key];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return target;
|
|
114
|
-
}
|
|
115
|
-
function createI18nManager(defaultLocale, locales) {
|
|
116
|
-
const fallbackLocale = normalizeLocaleCode(defaultLocale);
|
|
117
|
-
const initialLocales = {};
|
|
118
|
-
for (const [loc, dict] of Object.entries(locales)) {
|
|
119
|
-
initialLocales[normalizeLocaleCode(loc)] = { ...dict };
|
|
120
|
-
}
|
|
121
|
-
let currentLocale = fallbackLocale;
|
|
122
|
-
let activeLocales = { ...initialLocales };
|
|
123
|
-
let globalOverrides = {};
|
|
124
|
-
function resolveActiveDictionaries() {
|
|
125
|
-
const dicts = [];
|
|
126
|
-
const exact = activeLocales[currentLocale];
|
|
127
|
-
if (exact) dicts.push(exact);
|
|
128
|
-
const primary = getPrimaryLanguage(currentLocale);
|
|
129
|
-
if (primary && activeLocales[primary]) {
|
|
130
|
-
dicts.push(activeLocales[primary]);
|
|
131
|
-
}
|
|
132
|
-
return dicts;
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
setLocale(locale) {
|
|
136
|
-
if (locale && locale.trim()) {
|
|
137
|
-
currentLocale = normalizeLocaleCode(locale);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
getLocale() {
|
|
141
|
-
return currentLocale;
|
|
142
|
-
},
|
|
143
|
-
registerLocale(locale, translations) {
|
|
144
|
-
if (!locale || !locale.trim() || !translations) return;
|
|
145
|
-
const norm = normalizeLocaleCode(locale);
|
|
146
|
-
activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
|
|
147
|
-
},
|
|
148
|
-
setI18n(overrides) {
|
|
149
|
-
if (!overrides) return;
|
|
150
|
-
globalOverrides = assignDefined({ ...globalOverrides }, overrides);
|
|
151
|
-
},
|
|
152
|
-
t(key, instanceOverride) {
|
|
153
|
-
if (instanceOverride && instanceOverride[key] !== void 0) {
|
|
154
|
-
return String(instanceOverride[key]);
|
|
155
|
-
}
|
|
156
|
-
if (globalOverrides[key] !== void 0) {
|
|
157
|
-
return String(globalOverrides[key]);
|
|
158
|
-
}
|
|
159
|
-
for (const dict of resolveActiveDictionaries()) {
|
|
160
|
-
if (dict[key] !== void 0) {
|
|
161
|
-
return String(dict[key]);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const fallbackDict = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
165
|
-
if (fallbackDict && fallbackDict[key] !== void 0) {
|
|
166
|
-
return String(fallbackDict[key]);
|
|
167
|
-
}
|
|
168
|
-
return String(key);
|
|
169
|
-
},
|
|
170
|
-
getAll(instanceOverride) {
|
|
171
|
-
const result = {};
|
|
172
|
-
const fallback = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
|
|
173
|
-
assignDefined(result, fallback);
|
|
174
|
-
const activeDicts = resolveActiveDictionaries().reverse();
|
|
175
|
-
for (const dict of activeDicts) {
|
|
176
|
-
assignDefined(result, dict);
|
|
177
|
-
}
|
|
178
|
-
assignDefined(result, globalOverrides);
|
|
179
|
-
assignDefined(result, instanceOverride);
|
|
180
|
-
return result;
|
|
181
|
-
},
|
|
182
|
-
reset() {
|
|
183
|
-
currentLocale = fallbackLocale;
|
|
184
|
-
globalOverrides = {};
|
|
185
|
-
activeLocales = {};
|
|
186
|
-
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
187
|
-
activeLocales[loc] = { ...dict };
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// src/scroll/i18n/fr.ts
|
|
194
|
-
var scrollFr = {
|
|
195
|
-
viewport: "Zone de contenu d\xE9filable",
|
|
196
|
-
verticalThumb: "D\xE9filement vertical",
|
|
197
|
-
horizontalThumb: "D\xE9filement horizontal"
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
// src/scroll/i18n/en.ts
|
|
201
|
-
var scrollEn = {
|
|
202
|
-
viewport: "Scrollable content area",
|
|
203
|
-
verticalThumb: "Vertical scroll",
|
|
204
|
-
horizontalThumb: "Horizontal scroll"
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
// src/scroll/i18n/index.ts
|
|
208
|
-
var scrollI18n = createI18nManager("fr", {
|
|
209
|
-
fr: scrollFr,
|
|
210
|
-
en: scrollEn
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// src/scroll/ScrollBlock.ts
|
|
214
|
-
var idCounter = 0;
|
|
215
|
-
var ScrollBlock = class extends LocalizedComponent {
|
|
216
|
-
constructor(element, options) {
|
|
217
|
-
super(options?.i18n);
|
|
218
|
-
this.createdViewport = false;
|
|
219
|
-
this.wasIdGenerated = false;
|
|
220
|
-
this.wasRoleInferred = false;
|
|
221
|
-
this.wasAriaLabelInferred = false;
|
|
222
|
-
this.hasExplicitAriaLabel = false;
|
|
223
|
-
this.lastInferredAriaLabel = "";
|
|
224
|
-
this.isDragging = false;
|
|
225
|
-
this.dragStartPos = 0;
|
|
226
|
-
this.dragStartScroll = 0;
|
|
227
|
-
this.atBottom = false;
|
|
228
|
-
this.atTop = true;
|
|
229
|
-
this.atRight = false;
|
|
230
|
-
this.atLeft = true;
|
|
231
|
-
const resolvedElement = typeof element === "string" ? document.querySelector(element) : element;
|
|
232
|
-
if (!resolvedElement) {
|
|
233
|
-
throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
|
|
234
|
-
}
|
|
235
|
-
this.root = resolvedElement;
|
|
236
|
-
this.hasExplicitAriaLabel = Boolean(options?.ariaLabel);
|
|
237
|
-
this.options = {
|
|
238
|
-
axis: options?.axis || "y",
|
|
239
|
-
autoHide: options?.autoHide ?? true,
|
|
240
|
-
autoHideDelay: options?.autoHideDelay ?? 1e3,
|
|
241
|
-
alwaysVisible: options?.alwaysVisible ?? false,
|
|
242
|
-
ariaLabel: options?.ariaLabel || this.t("viewport"),
|
|
243
|
-
i18n: options?.i18n || {},
|
|
244
|
-
minThumbSize: options?.minThumbSize ?? 24,
|
|
245
|
-
edgeThreshold: options?.edgeThreshold ?? 10,
|
|
246
|
-
onScroll: options?.onScroll || (() => {
|
|
247
|
-
}),
|
|
248
|
-
onTotalScroll: options?.onTotalScroll || (() => {
|
|
249
|
-
}),
|
|
250
|
-
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
251
|
-
})
|
|
252
|
-
};
|
|
253
|
-
this.boundOnScroll = this.handleScroll.bind(this);
|
|
254
|
-
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
255
|
-
this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
|
|
256
|
-
this.boundOnFocusIn = this.handleFocusIn.bind(this);
|
|
257
|
-
this.boundOnFocusOut = this.handleFocusOut.bind(this);
|
|
258
|
-
this.boundPointerMove = this.handlePointerMove.bind(this);
|
|
259
|
-
this.boundPointerUp = this.handlePointerUp.bind(this);
|
|
260
|
-
this.viewport = this.setupViewport();
|
|
261
|
-
this.setupAccessibility();
|
|
262
|
-
this.setupScrollbars();
|
|
263
|
-
this.setupEventListeners();
|
|
264
|
-
this.setupObserver();
|
|
265
|
-
this.update();
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Prépare le viewport défilant sans altérer les éléments enfants.
|
|
269
|
-
*/
|
|
270
|
-
setupViewport() {
|
|
271
|
-
this.root.classList.add("wulf-scrollblock");
|
|
272
|
-
if (this.options.alwaysVisible) {
|
|
273
|
-
this.root.classList.add("is-always-visible");
|
|
274
|
-
}
|
|
275
|
-
if (this.options.axis === "both") {
|
|
276
|
-
this.root.classList.add("has-both-axes");
|
|
277
|
-
}
|
|
278
|
-
const existingViewport = this.root.querySelector(":scope > .wulf-scrollblock-viewport");
|
|
279
|
-
if (existingViewport) {
|
|
280
|
-
return existingViewport;
|
|
281
|
-
}
|
|
282
|
-
const viewport = document.createElement("div");
|
|
283
|
-
viewport.className = "wulf-scrollblock-viewport";
|
|
284
|
-
while (this.root.firstChild) {
|
|
285
|
-
viewport.appendChild(this.root.firstChild);
|
|
286
|
-
}
|
|
287
|
-
this.root.appendChild(viewport);
|
|
288
|
-
this.createdViewport = true;
|
|
289
|
-
return viewport;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Configure les attributs WAI-ARIA pour une accessibilité maximale.
|
|
293
|
-
*/
|
|
294
|
-
setupAccessibility() {
|
|
295
|
-
if (!this.viewport.id) {
|
|
296
|
-
idCounter += 1;
|
|
297
|
-
this.viewport.id = `wulf-scrollblock-vp-${idCounter}`;
|
|
298
|
-
this.wasIdGenerated = true;
|
|
299
|
-
}
|
|
300
|
-
if (!this.viewport.hasAttribute("role")) {
|
|
301
|
-
this.viewport.setAttribute("role", "region");
|
|
302
|
-
this.wasRoleInferred = true;
|
|
303
|
-
}
|
|
304
|
-
if (!this.viewport.hasAttribute("aria-label")) {
|
|
305
|
-
const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("viewport");
|
|
306
|
-
this.viewport.setAttribute("aria-label", label);
|
|
307
|
-
this.lastInferredAriaLabel = label;
|
|
308
|
-
this.wasAriaLabelInferred = true;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Synchronise dynamiquement les libellés ARIA si la langue globale change après montage.
|
|
313
|
-
*/
|
|
314
|
-
syncAccessibilityLabels() {
|
|
315
|
-
if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
|
|
316
|
-
const currentAttr = this.viewport.getAttribute("aria-label");
|
|
317
|
-
if (currentAttr === this.lastInferredAriaLabel) {
|
|
318
|
-
const nextLabel = this.t("viewport");
|
|
319
|
-
this.viewport.setAttribute("aria-label", nextLabel);
|
|
320
|
-
this.lastInferredAriaLabel = nextLabel;
|
|
321
|
-
this.options.ariaLabel = nextLabel;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
if (this.thumbY) {
|
|
325
|
-
this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
|
|
326
|
-
}
|
|
327
|
-
if (this.thumbX) {
|
|
328
|
-
this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Crée les rails et curseurs selon l'axe sélectionné.
|
|
333
|
-
*/
|
|
334
|
-
setupScrollbars() {
|
|
335
|
-
if (this.options.axis === "y" || this.options.axis === "both") {
|
|
336
|
-
this.trackY = document.createElement("div");
|
|
337
|
-
this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
|
|
338
|
-
this.trackY.setAttribute("aria-hidden", "true");
|
|
339
|
-
this.thumbY = document.createElement("div");
|
|
340
|
-
this.thumbY.className = "wulf-scrollblock-thumb";
|
|
341
|
-
this.thumbY.setAttribute("role", "scrollbar");
|
|
342
|
-
this.thumbY.setAttribute("aria-orientation", "vertical");
|
|
343
|
-
this.thumbY.setAttribute("aria-controls", this.viewport.id);
|
|
344
|
-
this.thumbY.setAttribute("aria-valuenow", "0");
|
|
345
|
-
this.thumbY.setAttribute("aria-valuemin", "0");
|
|
346
|
-
this.thumbY.setAttribute("aria-valuemax", "100");
|
|
347
|
-
this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
|
|
348
|
-
this.trackY.appendChild(this.thumbY);
|
|
349
|
-
this.root.appendChild(this.trackY);
|
|
350
|
-
this.attachTrackListeners(this.trackY, this.thumbY, "y");
|
|
351
|
-
}
|
|
352
|
-
if (this.options.axis === "x" || this.options.axis === "both") {
|
|
353
|
-
this.trackX = document.createElement("div");
|
|
354
|
-
this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
|
|
355
|
-
this.trackX.setAttribute("aria-hidden", "true");
|
|
356
|
-
this.thumbX = document.createElement("div");
|
|
357
|
-
this.thumbX.className = "wulf-scrollblock-thumb";
|
|
358
|
-
this.thumbX.setAttribute("role", "scrollbar");
|
|
359
|
-
this.thumbX.setAttribute("aria-orientation", "horizontal");
|
|
360
|
-
this.thumbX.setAttribute("aria-controls", this.viewport.id);
|
|
361
|
-
this.thumbX.setAttribute("aria-valuenow", "0");
|
|
362
|
-
this.thumbX.setAttribute("aria-valuemin", "0");
|
|
363
|
-
this.thumbX.setAttribute("aria-valuemax", "100");
|
|
364
|
-
this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
|
|
365
|
-
this.trackX.appendChild(this.thumbX);
|
|
366
|
-
this.root.appendChild(this.trackX);
|
|
367
|
-
this.attachTrackListeners(this.trackX, this.thumbX, "x");
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Attache les écouteurs sur un rail et son curseur.
|
|
372
|
-
*/
|
|
373
|
-
attachTrackListeners(track, thumb, axis) {
|
|
374
|
-
thumb.addEventListener("pointerdown", (e) => {
|
|
375
|
-
e.preventDefault();
|
|
376
|
-
e.stopPropagation();
|
|
377
|
-
this.isDragging = true;
|
|
378
|
-
this.dragAxis = axis;
|
|
379
|
-
this.dragPointerId = e.pointerId;
|
|
380
|
-
this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
|
|
381
|
-
this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
382
|
-
thumb.setPointerCapture(e.pointerId);
|
|
383
|
-
thumb.classList.add("is-active");
|
|
384
|
-
this.root.classList.add("is-dragging");
|
|
385
|
-
window.addEventListener("pointermove", this.boundPointerMove);
|
|
386
|
-
window.addEventListener("pointerup", this.boundPointerUp);
|
|
387
|
-
window.addEventListener("pointercancel", this.boundPointerUp);
|
|
388
|
-
});
|
|
389
|
-
track.addEventListener("pointerdown", (e) => {
|
|
390
|
-
if (e.target === thumb) return;
|
|
391
|
-
e.preventDefault();
|
|
392
|
-
const rect = track.getBoundingClientRect();
|
|
393
|
-
const clickPos = axis === "y" ? e.clientY - rect.top : e.clientX - rect.left;
|
|
394
|
-
const trackSize = axis === "y" ? rect.height : rect.width;
|
|
395
|
-
const clientSize = axis === "y" ? this.viewport.clientHeight : this.viewport.clientWidth;
|
|
396
|
-
const scrollSize = axis === "y" ? this.viewport.scrollHeight : this.viewport.scrollWidth;
|
|
397
|
-
const ratio = clickPos / trackSize;
|
|
398
|
-
const targetScroll = ratio * (scrollSize - clientSize);
|
|
399
|
-
this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Écouteurs globaux sur le viewport et les interactions.
|
|
404
|
-
*/
|
|
405
|
-
setupEventListeners() {
|
|
406
|
-
this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true });
|
|
407
|
-
if (this.options.autoHide && !this.options.alwaysVisible) {
|
|
408
|
-
this.root.addEventListener("mouseenter", this.boundOnMouseEnter);
|
|
409
|
-
this.root.addEventListener("mouseleave", this.boundOnMouseLeave);
|
|
410
|
-
this.root.addEventListener("focusin", this.boundOnFocusIn);
|
|
411
|
-
this.root.addEventListener("focusout", this.boundOnFocusOut);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Initialise le ResizeObserver réactif.
|
|
416
|
-
*/
|
|
417
|
-
setupObserver() {
|
|
418
|
-
if (typeof ResizeObserver !== "undefined") {
|
|
419
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
420
|
-
window.requestAnimationFrame(() => this.update());
|
|
421
|
-
});
|
|
422
|
-
this.resizeObserver.observe(this.root);
|
|
423
|
-
this.resizeObserver.observe(this.viewport);
|
|
424
|
-
if (this.viewport.firstElementChild) {
|
|
425
|
-
this.resizeObserver.observe(this.viewport.firstElementChild);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Déplacement lors du glissement du curseur.
|
|
431
|
-
*/
|
|
432
|
-
handlePointerMove(e) {
|
|
433
|
-
if (!this.isDragging || !this.dragAxis) return;
|
|
434
|
-
const isY = this.dragAxis === "y";
|
|
435
|
-
const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
|
|
436
|
-
const track = isY ? this.trackY : this.trackX;
|
|
437
|
-
const thumb = isY ? this.thumbY : this.thumbX;
|
|
438
|
-
if (!track || !thumb) return;
|
|
439
|
-
const trackSize = isY ? track.clientHeight : track.clientWidth;
|
|
440
|
-
const thumbSize = isY ? thumb.clientHeight : thumb.clientWidth;
|
|
441
|
-
const clientSize = isY ? this.viewport.clientHeight : this.viewport.clientWidth;
|
|
442
|
-
const scrollSize = isY ? this.viewport.scrollHeight : this.viewport.scrollWidth;
|
|
443
|
-
const maxScroll = scrollSize - clientSize;
|
|
444
|
-
const maxThumbTravel = trackSize - thumbSize;
|
|
445
|
-
if (maxThumbTravel <= 0 || maxScroll <= 0) return;
|
|
446
|
-
const ratio = maxScroll / maxThumbTravel;
|
|
447
|
-
const nextScroll = this.dragStartScroll + delta * ratio;
|
|
448
|
-
if (isY) {
|
|
449
|
-
this.viewport.scrollTop = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
450
|
-
} else {
|
|
451
|
-
this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Relâchement de la capture du pointeur.
|
|
456
|
-
*/
|
|
457
|
-
handlePointerUp(e) {
|
|
458
|
-
if (!this.isDragging) return;
|
|
459
|
-
if (this.dragPointerId !== void 0) {
|
|
460
|
-
const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
|
|
461
|
-
if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
|
|
462
|
-
activeThumb.releasePointerCapture(this.dragPointerId);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
window.removeEventListener("pointermove", this.boundPointerMove);
|
|
466
|
-
window.removeEventListener("pointerup", this.boundPointerUp);
|
|
467
|
-
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
468
|
-
this.isDragging = false;
|
|
469
|
-
this.dragAxis = void 0;
|
|
470
|
-
this.dragPointerId = void 0;
|
|
471
|
-
this.thumbY?.classList.remove("is-active");
|
|
472
|
-
this.thumbX?.classList.remove("is-active");
|
|
473
|
-
this.root.classList.remove("is-dragging");
|
|
474
|
-
this.scheduleAutoHide();
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Gestionnaire d'événement de défilement natif.
|
|
478
|
-
*/
|
|
479
|
-
handleScroll() {
|
|
480
|
-
this.syncThumbs();
|
|
481
|
-
const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = this.viewport;
|
|
482
|
-
const maxTop = Math.max(0, scrollHeight - clientHeight);
|
|
483
|
-
const maxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
484
|
-
const progressY = maxTop > 0 ? scrollTop / maxTop : 0;
|
|
485
|
-
const progressX = maxLeft > 0 ? scrollLeft / maxLeft : 0;
|
|
486
|
-
this.options.onScroll({
|
|
487
|
-
top: scrollTop,
|
|
488
|
-
left: scrollLeft,
|
|
489
|
-
maxTop,
|
|
490
|
-
maxLeft,
|
|
491
|
-
progressY: Math.round(progressY * 100),
|
|
492
|
-
progressX: Math.round(progressX * 100)
|
|
493
|
-
});
|
|
494
|
-
const threshold = this.options.edgeThreshold;
|
|
495
|
-
if (maxTop > 0) {
|
|
496
|
-
const nowBottom = scrollTop >= maxTop - threshold;
|
|
497
|
-
const nowTop = scrollTop <= threshold;
|
|
498
|
-
if (nowBottom && !this.atBottom) {
|
|
499
|
-
this.options.onTotalScroll("bottom");
|
|
500
|
-
}
|
|
501
|
-
if (nowTop && !this.atTop) {
|
|
502
|
-
this.options.onTotalScrollBack("top");
|
|
503
|
-
}
|
|
504
|
-
this.atBottom = nowBottom;
|
|
505
|
-
this.atTop = nowTop;
|
|
506
|
-
}
|
|
507
|
-
if (maxLeft > 0) {
|
|
508
|
-
const nowRight = scrollLeft >= maxLeft - threshold;
|
|
509
|
-
const nowLeft = scrollLeft <= threshold;
|
|
510
|
-
if (nowRight && !this.atRight) {
|
|
511
|
-
this.options.onTotalScroll("right");
|
|
512
|
-
}
|
|
513
|
-
if (nowLeft && !this.atLeft) {
|
|
514
|
-
this.options.onTotalScrollBack("left");
|
|
515
|
-
}
|
|
516
|
-
this.atRight = nowRight;
|
|
517
|
-
this.atLeft = nowLeft;
|
|
518
|
-
}
|
|
519
|
-
if (this.options.autoHide && !this.options.alwaysVisible) {
|
|
520
|
-
this.root.classList.add("is-scrolling");
|
|
521
|
-
this.scheduleAutoHide();
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* Synchronise la position physique et ARIA des curseurs.
|
|
526
|
-
*/
|
|
527
|
-
syncThumbs() {
|
|
528
|
-
const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = this.viewport;
|
|
529
|
-
if (this.thumbY && this.trackY) {
|
|
530
|
-
const maxScrollY = scrollHeight - clientHeight;
|
|
531
|
-
const trackHeight = this.trackY.clientHeight;
|
|
532
|
-
const thumbHeight = this.thumbY.clientHeight;
|
|
533
|
-
const maxTravelY = trackHeight - thumbHeight;
|
|
534
|
-
if (maxScrollY > 0 && maxTravelY > 0) {
|
|
535
|
-
const ratioY = scrollTop / maxScrollY;
|
|
536
|
-
const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
|
|
537
|
-
this.thumbY.style.transform = `translate3d(0, ${posY}px, 0)`;
|
|
538
|
-
this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
if (this.thumbX && this.trackX) {
|
|
542
|
-
const maxScrollX = scrollWidth - clientWidth;
|
|
543
|
-
const trackWidth = this.trackX.clientWidth;
|
|
544
|
-
const thumbWidth = this.thumbX.clientWidth;
|
|
545
|
-
const maxTravelX = trackWidth - thumbWidth;
|
|
546
|
-
if (maxScrollX > 0 && maxTravelX > 0) {
|
|
547
|
-
const ratioX = scrollLeft / maxScrollX;
|
|
548
|
-
const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
|
|
549
|
-
this.thumbX.style.transform = `translate3d(${posX}px, 0, 0)`;
|
|
550
|
-
this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
handleMouseEnter() {
|
|
555
|
-
this.root.classList.add("is-visible");
|
|
556
|
-
this.clearAutoHideTimer();
|
|
557
|
-
}
|
|
558
|
-
handleMouseLeave() {
|
|
559
|
-
this.scheduleAutoHide();
|
|
560
|
-
}
|
|
561
|
-
handleFocusIn() {
|
|
562
|
-
this.root.classList.add("is-visible");
|
|
563
|
-
this.clearAutoHideTimer();
|
|
564
|
-
}
|
|
565
|
-
handleFocusOut() {
|
|
566
|
-
this.scheduleAutoHide();
|
|
567
|
-
}
|
|
568
|
-
clearAutoHideTimer() {
|
|
569
|
-
if (this.hideTimer) {
|
|
570
|
-
window.clearTimeout(this.hideTimer);
|
|
571
|
-
this.hideTimer = void 0;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
scheduleAutoHide() {
|
|
575
|
-
if (this.options.alwaysVisible || !this.options.autoHide || this.isDragging) return;
|
|
576
|
-
this.clearAutoHideTimer();
|
|
577
|
-
this.hideTimer = window.setTimeout(() => {
|
|
578
|
-
this.root.classList.remove("is-scrolling");
|
|
579
|
-
this.root.classList.remove("is-visible");
|
|
580
|
-
}, this.options.autoHideDelay);
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Recalcule les dimensions et la visibilité des barres.
|
|
584
|
-
*/
|
|
585
|
-
update() {
|
|
586
|
-
this.syncAccessibilityLabels();
|
|
587
|
-
const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
|
|
588
|
-
const canScrollY = scrollHeight > clientHeight;
|
|
589
|
-
const canScrollX = scrollWidth > clientWidth;
|
|
590
|
-
this.root.classList.toggle("has-scroll-y", canScrollY);
|
|
591
|
-
this.root.classList.toggle("has-scroll-x", canScrollX);
|
|
592
|
-
if (canScrollY || canScrollX) {
|
|
593
|
-
this.viewport.setAttribute("tabindex", "0");
|
|
594
|
-
} else {
|
|
595
|
-
this.viewport.removeAttribute("tabindex");
|
|
596
|
-
}
|
|
597
|
-
if (this.trackY && this.thumbY) {
|
|
598
|
-
if (canScrollY) {
|
|
599
|
-
const trackHeight = this.trackY.clientHeight;
|
|
600
|
-
const calculatedHeight = Math.max(
|
|
601
|
-
this.options.minThumbSize,
|
|
602
|
-
trackHeight * (clientHeight / scrollHeight)
|
|
603
|
-
);
|
|
604
|
-
this.thumbY.style.height = `${calculatedHeight}px`;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
if (this.trackX && this.thumbX) {
|
|
608
|
-
if (canScrollX) {
|
|
609
|
-
const trackWidth = this.trackX.clientWidth;
|
|
610
|
-
const calculatedWidth = Math.max(
|
|
611
|
-
this.options.minThumbSize,
|
|
612
|
-
trackWidth * (clientWidth / scrollWidth)
|
|
613
|
-
);
|
|
614
|
-
this.thumbX.style.width = `${calculatedWidth}px`;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
this.syncThumbs();
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* Défilement programmatique direct ou lissé.
|
|
621
|
-
*/
|
|
622
|
-
scrollTo(target, options) {
|
|
623
|
-
const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
624
|
-
const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
|
|
625
|
-
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion;
|
|
626
|
-
const behavior = shouldSmooth ? "smooth" : "auto";
|
|
627
|
-
const maxTop = Math.max(0, this.viewport.scrollHeight - this.viewport.clientHeight);
|
|
628
|
-
const maxLeft = Math.max(0, this.viewport.scrollWidth - this.viewport.clientWidth);
|
|
629
|
-
let targetTop;
|
|
630
|
-
let targetLeft;
|
|
631
|
-
if (typeof target === "number") {
|
|
632
|
-
targetTop = target;
|
|
633
|
-
} else if (typeof target === "string") {
|
|
634
|
-
switch (target) {
|
|
635
|
-
case "top":
|
|
636
|
-
targetTop = 0;
|
|
637
|
-
break;
|
|
638
|
-
case "bottom":
|
|
639
|
-
targetTop = maxTop;
|
|
640
|
-
break;
|
|
641
|
-
case "left":
|
|
642
|
-
targetLeft = 0;
|
|
643
|
-
break;
|
|
644
|
-
case "right":
|
|
645
|
-
targetLeft = maxLeft;
|
|
646
|
-
break;
|
|
647
|
-
default: {
|
|
648
|
-
if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
|
|
649
|
-
const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
|
|
650
|
-
if (this.options.axis === "x") {
|
|
651
|
-
targetLeft = maxLeft * pct;
|
|
652
|
-
} else if (this.options.axis === "both") {
|
|
653
|
-
targetTop = maxTop * pct;
|
|
654
|
-
targetLeft = maxLeft * pct;
|
|
655
|
-
} else {
|
|
656
|
-
targetTop = maxTop * pct;
|
|
657
|
-
}
|
|
658
|
-
break;
|
|
659
|
-
}
|
|
660
|
-
let el = null;
|
|
661
|
-
try {
|
|
662
|
-
el = this.viewport.querySelector(target);
|
|
663
|
-
} catch {
|
|
664
|
-
el = null;
|
|
665
|
-
}
|
|
666
|
-
if (el) {
|
|
667
|
-
targetTop = el.offsetTop;
|
|
668
|
-
targetLeft = el.offsetLeft;
|
|
669
|
-
}
|
|
670
|
-
break;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
} else if (target instanceof HTMLElement) {
|
|
674
|
-
targetTop = target.offsetTop;
|
|
675
|
-
targetLeft = target.offsetLeft;
|
|
676
|
-
} else if (typeof target === "object") {
|
|
677
|
-
targetTop = target.top;
|
|
678
|
-
targetLeft = target.left;
|
|
679
|
-
}
|
|
680
|
-
this.viewport.scrollTo({
|
|
681
|
-
top: targetTop !== void 0 ? Math.max(0, Math.min(maxTop, targetTop)) : void 0,
|
|
682
|
-
left: targetLeft !== void 0 ? Math.max(0, Math.min(maxLeft, targetLeft)) : void 0,
|
|
683
|
-
behavior
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Détruit le composant et libère toutes les ressources.
|
|
688
|
-
*/
|
|
689
|
-
destroy() {
|
|
690
|
-
this.clearAutoHideTimer();
|
|
691
|
-
if (this.resizeObserver) {
|
|
692
|
-
this.resizeObserver.disconnect();
|
|
693
|
-
}
|
|
694
|
-
this.viewport.removeEventListener("scroll", this.boundOnScroll);
|
|
695
|
-
this.root.removeEventListener("mouseenter", this.boundOnMouseEnter);
|
|
696
|
-
this.root.removeEventListener("mouseleave", this.boundOnMouseLeave);
|
|
697
|
-
this.root.removeEventListener("focusin", this.boundOnFocusIn);
|
|
698
|
-
this.root.removeEventListener("focusout", this.boundOnFocusOut);
|
|
699
|
-
window.removeEventListener("pointermove", this.boundPointerMove);
|
|
700
|
-
window.removeEventListener("pointerup", this.boundPointerUp);
|
|
701
|
-
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
702
|
-
this.trackY?.remove();
|
|
703
|
-
this.trackX?.remove();
|
|
704
|
-
this.root.classList.remove(
|
|
705
|
-
"wulf-scrollblock",
|
|
706
|
-
"has-scroll-y",
|
|
707
|
-
"has-scroll-x",
|
|
708
|
-
"has-both-axes",
|
|
709
|
-
"is-visible",
|
|
710
|
-
"is-scrolling",
|
|
711
|
-
"is-dragging",
|
|
712
|
-
"is-always-visible"
|
|
713
|
-
);
|
|
714
|
-
if (this.createdViewport && this.viewport.parentElement === this.root) {
|
|
715
|
-
while (this.viewport.firstChild) {
|
|
716
|
-
this.root.insertBefore(this.viewport.firstChild, this.viewport);
|
|
717
|
-
}
|
|
718
|
-
this.viewport.remove();
|
|
719
|
-
} else {
|
|
720
|
-
this.viewport.removeAttribute("tabindex");
|
|
721
|
-
if (this.wasIdGenerated) {
|
|
722
|
-
this.viewport.removeAttribute("id");
|
|
723
|
-
}
|
|
724
|
-
if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
|
|
725
|
-
this.viewport.removeAttribute("role");
|
|
726
|
-
}
|
|
727
|
-
if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
728
|
-
this.viewport.removeAttribute("aria-label");
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
ScrollBlock._i18n = scrollI18n;
|
|
734
|
-
ScrollBlock.i18n = scrollI18n;
|
|
735
|
-
|
|
736
|
-
// src/scroll/index.ts
|
|
737
|
-
var Scroll = {
|
|
738
|
-
ScrollBlock,
|
|
739
|
-
i18n: scrollI18n
|
|
740
|
-
};
|
|
741
|
-
var index_default = ScrollBlock;
|
|
742
|
-
if (typeof window !== "undefined") {
|
|
743
|
-
const win = window;
|
|
744
|
-
const wulfNamespace = win.Wulf || {};
|
|
745
|
-
win.Wulf = wulfNamespace;
|
|
746
|
-
wulfNamespace.Scroll = Scroll;
|
|
747
|
-
}
|
|
748
|
-
//# sourceMappingURL=scroll.cjs.js.map
|