@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.
@@ -1,13 +1,13 @@
1
1
 
2
2
  
3
- > @agencecinq/utils@3.0.0 build /Users/19h47/Sites/agencecinq-shopify/packages/utils
3
+ > @agencecinq/utils@4.0.0 build /Users/19h47/Sites/agencecinq-shopify/packages/utils
4
4
  > vite build
5
5
 
6
6
  vite v7.3.1 building client environment for production...
7
- transforming (1) src/index.tstransforming (2) src/events.ts✓ 7 modules transformed.
7
+ transforming (1) src/index.ts✓ 7 modules transformed.
8
8
  rendering chunks (1)...
9
9
  [vite:dts] Start generate declaration files...
10
- computing gzip size (0)...computing gzip size (1)...dist/index.js 3.28 kB │ gzip: 1.52 kB
11
- [vite:dts] Declaration files built in 5543ms.
10
+ computing gzip size (0)...computing gzip size (1)...dist/index.js 3.37 kB │ gzip: 1.55 kB
11
+ [vite:dts] Declaration files built in 1450ms.
12
12
  
13
- ✓ built in 5.99s
13
+ ✓ built in 1.62s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @agencecinq/utils
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Create a new package in @agencecinq/shopify
8
+
3
9
  ## 3.0.0
4
10
 
5
11
  ### Major Changes
package/dist/events.d.ts CHANGED
@@ -2,6 +2,9 @@ export declare const EVENTS: {
2
2
  DRAWER_CLOSE: string;
3
3
  DRAWER_OPEN: string;
4
4
  DRAWER_TOGGLE: string;
5
+ MODAL_CLOSE: string;
6
+ MODAL_OPEN: string;
7
+ MODAL_TOGGLE: string;
5
8
  CART_UPDATE: string;
6
9
  VARIANT_CHANGE: string;
7
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;CAMlB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"focus-trap.d.ts","sourceRoot":"","sources":["../src/focus-trap.ts"],"names":[],"mappings":"AAaA,iBAAS,oBAAoB,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,EAAE,CAkBnE;AAED,iBAAS,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,cAAc,GAAE,WAAuB,GAAG,IAAI,CAyC3F;AAED,iBAAS,eAAe,CAAC,cAAc,GAAE,WAAW,GAAG,IAAW,GAAG,IAAI,CAQxE;AAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC"}
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 O = {
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 n = null, r = null;
11
+ let o = null, r = null;
9
12
  const s = () => {
10
- r && e(...r), n = null;
13
+ r && e(...r), o = null;
11
14
  };
12
15
  return (...c) => {
13
- r = c, n || (n = setTimeout(s, t));
16
+ r = c, o || (o = setTimeout(s, t));
14
17
  };
15
- }, l = document.documentElement, { body: d } = document, W = l.hasAttribute("data-debug"), o = {
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" && (o.x = e), typeof t < "u" && (o.y = t), window.scrollTo(o.x, o.y);
38
+ typeof e < "u" && (n.x = e), typeof t < "u" && (n.y = t), window.scrollTo(n.x, n.y);
36
39
  };
37
- function N() {
38
- const e = l.scrollLeft, t = l.scrollTop, n = d.scrollLeft, r = d.scrollTop;
39
- o.x = window.scrollX || e || n, o.y = window.scrollY || t || r || 0, l.style.setProperty("overflow", "hidden"), l.style.setProperty("height", "100%"), l.style.setProperty("scroll-padding-top", "0px"), u(o.x, o.y);
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 H(e = 0) {
42
- let t = !0, n = o.y;
43
- typeof e == "number" ? n = e : typeof e == "boolean" && e === !1 && (t = !1), l.style.removeProperty("overflow"), l.style.removeProperty("height"), l.style.removeProperty("scroll-padding-top"), t && u(o.x, n);
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 i = {};
46
- function y(e) {
48
+ const d = {};
49
+ function m(e) {
47
50
  return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
48
51
  }
49
- function m(e) {
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((n) => y(n) && n.getAttribute("tabindex") !== "-1");
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 n = m(e);
67
- if (n.length === 0) return;
68
- const r = n[0], s = n[n.length - 1];
69
- E(), i.keydown = (c) => {
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", i.keydown), t.focus(), t instanceof HTMLInputElement && ["search", "text", "email", "url"].includes(t.type) && t.value && t.setSelectionRange(0, t.value.length);
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
- i.keydown && document.removeEventListener("keydown", i.keydown), e && e.focus();
77
+ d.keydown && document.removeEventListener("keydown", d.keydown), e && e.focus();
75
78
  }
76
- const p = 8, w = 9, h = 13, b = 16, A = 27, x = 32, g = 33, R = 34, v = 35, P = 36, S = 37, T = 38, L = 39, D = 40, _ = 46, M = {
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: b,
81
- ESCAPE: A,
82
- SPACE: x,
83
- PAGE_UP: g,
83
+ SHIFT: A,
84
+ ESCAPE: b,
85
+ SPACE: g,
86
+ PAGE_UP: x,
84
87
  PAGE_DOWN: R,
85
88
  END: v,
86
- HOME: P,
87
- ARROW_LEFT: S,
88
- ARROW_UP: T,
89
- ARROW_RIGHT: L,
90
- ARROW_DOWN: D,
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
- O as EVENTS,
97
+ _ as EVENTS,
95
98
  G as addTrapFocus,
96
- d as body,
99
+ i as body,
97
100
  k as breakpoints,
98
- N as disableScroll,
99
- H as enableScroll,
100
- m as getFocusableElements,
101
+ M as disableScroll,
102
+ N as enableScroll,
103
+ y as getFocusableElements,
101
104
  l as html,
102
105
  W as isDebug,
103
- M as keycode,
106
+ H as keycode,
104
107
  a as mouse,
105
108
  C as production,
106
109
  E as removeTrapFocus,
107
- o as scroll,
110
+ n as scroll,
108
111
  f as throttle
109
112
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agencecinq/utils",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
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 };