@agencecinq/utils 3.0.0 → 4.0.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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +6 -0
- package/dist/events.d.ts +3 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/focus-trap.d.ts.map +1 -1
- package/dist/index.js +43 -40
- package/package.json +1 -1
- package/src/events.ts +3 -0
- package/src/focus-trap.ts +1 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @agencecinq/utils@
|
|
3
|
+
> @agencecinq/utils@4.0.0 build /Users/19h47/Sites/agencecinq-shopify/packages/utils
|
|
4
4
|
> vite build
|
|
5
5
|
|
|
6
6
|
[36mvite v7.3.1 [32mbuilding client environment for production...[36m[39m
|
|
7
|
-
[2K[1Gtransforming (1) [2msrc/index.ts[22m[2K[
|
|
7
|
+
[2K[1Gtransforming (1) [2msrc/index.ts[22m[2K[1G[32m✓[39m 7 modules transformed.
|
|
8
8
|
[2K[1Grendering chunks (1)...[2K[1G[32m
|
|
9
9
|
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
10
|
-
[2K[1Gcomputing gzip size (0)...[2K[1Gcomputing gzip size (1)...[2K[1G[2mdist/[22m[36mindex.js [39m[1m[2m3.
|
|
11
|
-
[32m[36m[vite:dts][32m Declaration files built in
|
|
10
|
+
[2K[1Gcomputing gzip size (0)...[2K[1Gcomputing gzip size (1)...[2K[1G[2mdist/[22m[36mindex.js [39m[1m[2m3.37 kB[22m[1m[22m[2m │ gzip: 1.55 kB[22m
|
|
11
|
+
[32m[36m[vite:dts][32m Declaration files built in 1450ms.
|
|
12
12
|
[39m
|
|
13
|
-
[32m✓ built in
|
|
13
|
+
[32m✓ built in 1.62s[39m
|
package/CHANGELOG.md
CHANGED
package/dist/events.d.ts
CHANGED
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;CASlB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
|
package/dist/focus-trap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-trap.d.ts","sourceRoot":"","sources":["../src/focus-trap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"focus-trap.d.ts","sourceRoot":"","sources":["../src/focus-trap.ts"],"names":[],"mappings":"AAUA,iBAAS,oBAAoB,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,EAAE,CAkBnE;AAED,iBAAS,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,cAAc,GAAE,WAAuB,GAAG,IAAI,CAoC3F;AAED,iBAAS,eAAe,CAAC,cAAc,GAAE,WAAW,GAAG,IAAW,GAAG,IAAI,CAQxE;AAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _ = {
|
|
2
2
|
DRAWER_CLOSE: "drawer-close",
|
|
3
3
|
DRAWER_OPEN: "drawer-open",
|
|
4
4
|
DRAWER_TOGGLE: "drawer-toggle",
|
|
5
|
+
MODAL_CLOSE: "modal-close",
|
|
6
|
+
MODAL_OPEN: "modal-open",
|
|
7
|
+
MODAL_TOGGLE: "modal-toggle",
|
|
5
8
|
CART_UPDATE: "cart-update",
|
|
6
9
|
VARIANT_CHANGE: "variant-change"
|
|
7
10
|
}, f = (e, t) => {
|
|
8
|
-
let
|
|
11
|
+
let o = null, r = null;
|
|
9
12
|
const s = () => {
|
|
10
|
-
r && e(...r),
|
|
13
|
+
r && e(...r), o = null;
|
|
11
14
|
};
|
|
12
15
|
return (...c) => {
|
|
13
|
-
r = c,
|
|
16
|
+
r = c, o || (o = setTimeout(s, t));
|
|
14
17
|
};
|
|
15
|
-
}, l = document.documentElement, { body:
|
|
18
|
+
}, l = document.documentElement, { body: i } = document, W = l.hasAttribute("data-debug"), n = {
|
|
16
19
|
y: 0,
|
|
17
20
|
x: 0
|
|
18
21
|
}, a = {
|
|
@@ -32,21 +35,21 @@ const k = {
|
|
|
32
35
|
"2xl": window.matchMedia("(min-width: 1440px)"),
|
|
33
36
|
"3xl": window.matchMedia("(min-width: 1920px)")
|
|
34
37
|
}, C = !0, u = (e, t) => {
|
|
35
|
-
typeof e < "u" && (
|
|
38
|
+
typeof e < "u" && (n.x = e), typeof t < "u" && (n.y = t), window.scrollTo(n.x, n.y);
|
|
36
39
|
};
|
|
37
|
-
function
|
|
38
|
-
const e = l.scrollLeft, t = l.scrollTop,
|
|
39
|
-
|
|
40
|
+
function M() {
|
|
41
|
+
const e = l.scrollLeft, t = l.scrollTop, o = i.scrollLeft, r = i.scrollTop;
|
|
42
|
+
n.x = window.scrollX || e || o, n.y = window.scrollY || t || r || 0, l.style.setProperty("overflow", "hidden"), l.style.setProperty("height", "100%"), l.style.setProperty("scroll-padding-top", "0px"), u(n.x, n.y);
|
|
40
43
|
}
|
|
41
|
-
function
|
|
42
|
-
let t = !0,
|
|
43
|
-
typeof e == "number" ?
|
|
44
|
+
function N(e = 0) {
|
|
45
|
+
let t = !0, o = n.y;
|
|
46
|
+
typeof e == "number" ? o = e : typeof e == "boolean" && e === !1 && (t = !1), l.style.removeProperty("overflow"), l.style.removeProperty("height"), l.style.removeProperty("scroll-padding-top"), t && u(n.x, o);
|
|
44
47
|
}
|
|
45
|
-
const
|
|
46
|
-
function
|
|
48
|
+
const d = {};
|
|
49
|
+
function m(e) {
|
|
47
50
|
return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
|
|
48
51
|
}
|
|
49
|
-
function
|
|
52
|
+
function y(e) {
|
|
50
53
|
if (!e) return [];
|
|
51
54
|
const t = [
|
|
52
55
|
"summary",
|
|
@@ -60,50 +63,50 @@ function m(e) {
|
|
|
60
63
|
"iframe",
|
|
61
64
|
"[contenteditable]"
|
|
62
65
|
].join(",");
|
|
63
|
-
return Array.from(e.querySelectorAll(t)).filter((
|
|
66
|
+
return Array.from(e.querySelectorAll(t)).filter((o) => m(o) && o.getAttribute("tabindex") !== "-1");
|
|
64
67
|
}
|
|
65
68
|
function G(e, t = e) {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
const r =
|
|
69
|
-
E(),
|
|
69
|
+
const o = y(e);
|
|
70
|
+
if (o.length === 0) return;
|
|
71
|
+
const r = o[0], s = o[o.length - 1];
|
|
72
|
+
E(), d.keydown = (c) => {
|
|
70
73
|
c.key === "Tab" && (c.shiftKey ? (document.activeElement === r || document.activeElement === e) && (c.preventDefault(), s.focus()) : document.activeElement === s && (c.preventDefault(), r.focus()));
|
|
71
|
-
}, document.addEventListener("keydown",
|
|
74
|
+
}, document.addEventListener("keydown", d.keydown), t.focus(), t instanceof HTMLInputElement && ["search", "text", "email", "url"].includes(t.type) && t.value && t.setSelectionRange(0, t.value.length);
|
|
72
75
|
}
|
|
73
76
|
function E(e = null) {
|
|
74
|
-
|
|
77
|
+
d.keydown && document.removeEventListener("keydown", d.keydown), e && e.focus();
|
|
75
78
|
}
|
|
76
|
-
const p = 8, w = 9, h = 13,
|
|
79
|
+
const p = 8, w = 9, h = 13, A = 16, b = 27, g = 32, x = 33, R = 34, v = 35, L = 36, P = 37, O = 38, S = 39, T = 40, D = 46, H = {
|
|
77
80
|
BACKSPACE: p,
|
|
78
81
|
TAB: w,
|
|
79
82
|
ENTER: h,
|
|
80
|
-
SHIFT:
|
|
81
|
-
ESCAPE:
|
|
82
|
-
SPACE:
|
|
83
|
-
PAGE_UP:
|
|
83
|
+
SHIFT: A,
|
|
84
|
+
ESCAPE: b,
|
|
85
|
+
SPACE: g,
|
|
86
|
+
PAGE_UP: x,
|
|
84
87
|
PAGE_DOWN: R,
|
|
85
88
|
END: v,
|
|
86
|
-
HOME:
|
|
87
|
-
ARROW_LEFT:
|
|
88
|
-
ARROW_UP:
|
|
89
|
-
ARROW_RIGHT:
|
|
90
|
-
ARROW_DOWN:
|
|
91
|
-
DELETE:
|
|
89
|
+
HOME: L,
|
|
90
|
+
ARROW_LEFT: P,
|
|
91
|
+
ARROW_UP: O,
|
|
92
|
+
ARROW_RIGHT: S,
|
|
93
|
+
ARROW_DOWN: T,
|
|
94
|
+
DELETE: D
|
|
92
95
|
};
|
|
93
96
|
export {
|
|
94
|
-
|
|
97
|
+
_ as EVENTS,
|
|
95
98
|
G as addTrapFocus,
|
|
96
|
-
|
|
99
|
+
i as body,
|
|
97
100
|
k as breakpoints,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
M as disableScroll,
|
|
102
|
+
N as enableScroll,
|
|
103
|
+
y as getFocusableElements,
|
|
101
104
|
l as html,
|
|
102
105
|
W as isDebug,
|
|
103
|
-
|
|
106
|
+
H as keycode,
|
|
104
107
|
a as mouse,
|
|
105
108
|
C as production,
|
|
106
109
|
E as removeTrapFocus,
|
|
107
|
-
|
|
110
|
+
n as scroll,
|
|
108
111
|
f as throttle
|
|
109
112
|
};
|
package/package.json
CHANGED
package/src/events.ts
CHANGED
|
@@ -2,6 +2,9 @@ export const EVENTS = {
|
|
|
2
2
|
DRAWER_CLOSE: 'drawer-close',
|
|
3
3
|
DRAWER_OPEN: 'drawer-open',
|
|
4
4
|
DRAWER_TOGGLE: 'drawer-toggle',
|
|
5
|
+
MODAL_CLOSE: 'modal-close',
|
|
6
|
+
MODAL_OPEN: 'modal-open',
|
|
7
|
+
MODAL_TOGGLE: 'modal-toggle',
|
|
5
8
|
CART_UPDATE: 'cart-update',
|
|
6
9
|
VARIANT_CHANGE: 'variant-change',
|
|
7
10
|
};
|
package/src/focus-trap.ts
CHANGED
|
@@ -4,9 +4,6 @@ const trapFocusHandlers: {
|
|
|
4
4
|
keydown?: (event: KeyboardEvent) => void;
|
|
5
5
|
} = {};
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Filtre les éléments réellement visibles et focalisables
|
|
9
|
-
*/
|
|
10
7
|
function isVisible(el: HTMLElement): boolean {
|
|
11
8
|
return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
|
|
12
9
|
}
|
|
@@ -38,20 +35,17 @@ function addTrapFocus(container: HTMLElement, elementToFocus: HTMLElement = cont
|
|
|
38
35
|
const first = elements[0];
|
|
39
36
|
const last = elements[elements.length - 1];
|
|
40
37
|
|
|
41
|
-
// Nettoyage avant d'ajouter (pour éviter les doublons)
|
|
42
38
|
removeTrapFocus();
|
|
43
39
|
|
|
44
40
|
trapFocusHandlers.keydown = (event: KeyboardEvent): void => {
|
|
45
41
|
if (event.key !== 'Tab') return;
|
|
46
42
|
|
|
47
43
|
if (event.shiftKey) {
|
|
48
|
-
// Tab arrière
|
|
49
44
|
if (document.activeElement === first || document.activeElement === container) {
|
|
50
45
|
event.preventDefault();
|
|
51
46
|
last.focus();
|
|
52
47
|
}
|
|
53
48
|
} else {
|
|
54
|
-
// Tab avant
|
|
55
49
|
if (document.activeElement === last) {
|
|
56
50
|
event.preventDefault();
|
|
57
51
|
first.focus();
|
|
@@ -61,10 +55,8 @@ function addTrapFocus(container: HTMLElement, elementToFocus: HTMLElement = cont
|
|
|
61
55
|
|
|
62
56
|
document.addEventListener('keydown', trapFocusHandlers.keydown);
|
|
63
57
|
|
|
64
|
-
// Focus initial
|
|
65
58
|
elementToFocus.focus();
|
|
66
59
|
|
|
67
|
-
// Support spécifique pour les inputs texte (sélection du contenu)
|
|
68
60
|
if (
|
|
69
61
|
elementToFocus instanceof HTMLInputElement &&
|
|
70
62
|
['search', 'text', 'email', 'url'].includes(elementToFocus.type) &&
|
|
@@ -84,4 +76,4 @@ function removeTrapFocus(elementToFocus: HTMLElement | null = null): void {
|
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
|
|
87
|
-
export { addTrapFocus, removeTrapFocus, getFocusableElements };
|
|
79
|
+
export { addTrapFocus, removeTrapFocus, getFocusableElements };
|