@agencecinq/utils 4.0.1 → 5.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@4.0.1 build /Users/19h47/Sites/agencecinq-ui/packages/utils
3
+ > @agencecinq/utils@5.0.0 build /Users/19h47/Sites/agencecinq-ui/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 (5) src/scroll.ts✓ 7 modules transformed.
7
+ transforming (1) src/index.ts✓ 8 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.41 kB │ gzip: 1.57 kB
11
- [vite:dts] Declaration files built in 1952ms.
10
+ computing gzip size (0)...computing gzip size (1)...dist/index.js 3.66 kB │ gzip: 1.66 kB
11
+ [vite:dts] Declaration files built in 1427ms.
12
12
  
13
- ✓ built in 2.35s
13
+ ✓ built in 1.61s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @agencecinq/utils
2
2
 
3
+ ## 5.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 3594668: Spinbutton package
8
+
9
+ ## 4.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Add `CART_BEFORE_ADD` event constant for batching extra items into a single `/cart/add.js` request. Listeners receive a mutable `items` array in `event.detail` and can push their own additions (e.g. free samples) before the AddToCart caller fires the request.
14
+
3
15
  ## 4.0.1
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Clamps a number between a minimum and a maximum value.
3
+ *
4
+ * @example
5
+ * clamp(10, 1, 5); // 5
6
+ * clamp(-1, 0, 10); // 0
7
+ * clamp(7, 3, 9); // 7
8
+ */
9
+ export declare const clamp: (value: number, min: number, max: number) => number;
10
+ //# sourceMappingURL=clamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clamp.d.ts","sourceRoot":"","sources":["../src/clamp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAC3B,CAAC"}
package/dist/events.d.ts CHANGED
@@ -5,6 +5,11 @@ export declare const EVENTS: {
5
5
  MODAL_CLOSE: string;
6
6
  MODAL_OPEN: string;
7
7
  MODAL_TOGGLE: string;
8
+ SPINBUTTON_CHANGE: string;
9
+ TAB_BEFORE_ACTIVATE: string;
10
+ TAB_ACTIVATE: string;
11
+ TAB_DELETE: string;
12
+ CART_BEFORE_ADD: string;
8
13
  CART_BEFORE_UPDATE: string;
9
14
  CART_UPDATE: string;
10
15
  VARIANT_CHANGE: string;
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;CAUlB,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;;;;;;;;;;;;;;;CAelB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export * from './throttle';
4
4
  export * from './environment';
5
5
  export * from './focus-trap';
6
6
  export * from './keycode';
7
+ export * from './clamp';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,56 +1,61 @@
1
- const D = {
1
+ const S = {
2
2
  DRAWER_CLOSE: "drawer-close",
3
3
  DRAWER_OPEN: "drawer-open",
4
4
  DRAWER_TOGGLE: "drawer-toggle",
5
5
  MODAL_CLOSE: "modal-close",
6
6
  MODAL_OPEN: "modal-open",
7
7
  MODAL_TOGGLE: "modal-toggle",
8
+ SPINBUTTON_CHANGE: "spinbutton-change",
9
+ TAB_BEFORE_ACTIVATE: "tab-before-activate",
10
+ TAB_ACTIVATE: "tab-activate",
11
+ TAB_DELETE: "tab-delete",
12
+ CART_BEFORE_ADD: "cart-before-add",
8
13
  CART_BEFORE_UPDATE: "cart-before-update",
9
14
  CART_UPDATE: "cart-update",
10
15
  VARIANT_CHANGE: "variant-change"
11
16
  }, f = (e, t) => {
12
- let o = null, r = null;
17
+ let o = null, c = null;
13
18
  const s = () => {
14
- r && e(...r), o = null;
19
+ c && e(...c), o = null;
15
20
  };
16
- return (...c) => {
17
- r = c, o || (o = setTimeout(s, t));
21
+ return (...r) => {
22
+ c = r, o || (o = setTimeout(s, t));
18
23
  };
19
- }, l = document.documentElement, { body: i } = document, C = l.hasAttribute("data-debug"), n = {
24
+ }, l = document.documentElement, { body: d } = document, C = l.hasAttribute("data-debug"), n = {
20
25
  y: 0,
21
26
  x: 0
22
- }, a = {
27
+ }, i = {
23
28
  x: 0,
24
29
  y: 0
25
30
  };
26
31
  window.addEventListener(
27
32
  "pointermove",
28
33
  f(({ x: e, y: t }) => {
29
- a.x = e, a.y = t;
34
+ i.x = e, i.y = t;
30
35
  }, 100),
31
36
  { passive: !0 }
32
37
  );
33
- const W = {
38
+ const N = {
34
39
  lg: window.matchMedia("(width >= 64rem)"),
35
40
  xl: window.matchMedia("(min-width: 1280px)"),
36
41
  "2xl": window.matchMedia("(min-width: 1440px)"),
37
42
  "3xl": window.matchMedia("(min-width: 1920px)")
38
- }, k = !0, u = (e, t) => {
43
+ }, M = !0, u = (e, t) => {
39
44
  typeof e < "u" && (n.x = e), typeof t < "u" && (n.y = t), window.scrollTo(n.x, n.y);
40
45
  };
41
- function M() {
42
- const e = l.scrollLeft, t = l.scrollTop, o = i.scrollLeft, r = i.scrollTop;
43
- 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);
46
+ function W() {
47
+ const e = l.scrollLeft, t = l.scrollTop, o = d.scrollLeft, c = d.scrollTop;
48
+ n.x = window.scrollX || e || o, n.y = window.scrollY || t || c || 0, l.style.setProperty("overflow", "hidden"), l.style.setProperty("height", "100%"), l.style.setProperty("scroll-padding-top", "0px"), u(n.x, n.y);
44
49
  }
45
- function N(e = 0) {
50
+ function k(e = 0) {
46
51
  let t = !0, o = n.y;
47
52
  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);
48
53
  }
49
- const d = {};
50
- function m(e) {
54
+ const a = {};
55
+ function E(e) {
51
56
  return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
52
57
  }
53
- function y(e) {
58
+ function m(e) {
54
59
  if (!e) return [];
55
60
  const t = [
56
61
  "summary",
@@ -64,50 +69,51 @@ function y(e) {
64
69
  "iframe",
65
70
  "[contenteditable]"
66
71
  ].join(",");
67
- return Array.from(e.querySelectorAll(t)).filter((o) => m(o) && o.getAttribute("tabindex") !== "-1");
72
+ return Array.from(e.querySelectorAll(t)).filter((o) => E(o) && o.getAttribute("tabindex") !== "-1");
68
73
  }
69
- function G(e, t = e) {
70
- const o = y(e);
74
+ function B(e, t = e) {
75
+ const o = m(e);
71
76
  if (o.length === 0) return;
72
- const r = o[0], s = o[o.length - 1];
73
- E(), d.keydown = (c) => {
74
- c.key === "Tab" && (c.shiftKey ? (document.activeElement === r || document.activeElement === e) && (c.preventDefault(), s.focus()) : document.activeElement === s && (c.preventDefault(), r.focus()));
75
- }, 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);
77
+ const c = o[0], s = o[o.length - 1];
78
+ y(), a.keydown = (r) => {
79
+ r.key === "Tab" && (r.shiftKey ? (document.activeElement === c || document.activeElement === e) && (r.preventDefault(), s.focus()) : document.activeElement === s && (r.preventDefault(), c.focus()));
80
+ }, document.addEventListener("keydown", a.keydown), t.focus(), t instanceof HTMLInputElement && ["search", "text", "email", "url"].includes(t.type) && t.value && t.setSelectionRange(0, t.value.length);
76
81
  }
77
- function E(e = null) {
78
- d.keydown && document.removeEventListener("keydown", d.keydown), e && e.focus();
82
+ function y(e = null) {
83
+ a.keydown && document.removeEventListener("keydown", a.keydown), e && e.focus();
79
84
  }
80
- const p = 8, w = 9, A = 13, h = 16, b = 27, g = 32, R = 33, x = 34, P = 35, T = 36, v = 37, L = 38, O = 39, S = 40, _ = 46, H = {
81
- BACKSPACE: p,
82
- TAB: w,
83
- ENTER: A,
84
- SHIFT: h,
85
- ESCAPE: b,
86
- SPACE: g,
85
+ const A = 8, p = 9, b = 13, w = 16, h = 27, T = 32, R = 33, g = 34, _ = 35, x = 36, O = 37, v = 38, P = 39, D = 40, L = 46, G = {
86
+ BACKSPACE: A,
87
+ TAB: p,
88
+ ENTER: b,
89
+ SHIFT: w,
90
+ ESCAPE: h,
91
+ SPACE: T,
87
92
  PAGE_UP: R,
88
- PAGE_DOWN: x,
89
- END: P,
90
- HOME: T,
91
- ARROW_LEFT: v,
92
- ARROW_UP: L,
93
- ARROW_RIGHT: O,
94
- ARROW_DOWN: S,
95
- DELETE: _
96
- };
93
+ PAGE_DOWN: g,
94
+ END: _,
95
+ HOME: x,
96
+ ARROW_LEFT: O,
97
+ ARROW_UP: v,
98
+ ARROW_RIGHT: P,
99
+ ARROW_DOWN: D,
100
+ DELETE: L
101
+ }, H = (e, t, o) => Math.min(Math.max(e, t), o);
97
102
  export {
98
- D as EVENTS,
99
- G as addTrapFocus,
100
- i as body,
101
- W as breakpoints,
102
- M as disableScroll,
103
- N as enableScroll,
104
- y as getFocusableElements,
103
+ S as EVENTS,
104
+ B as addTrapFocus,
105
+ d as body,
106
+ N as breakpoints,
107
+ H as clamp,
108
+ W as disableScroll,
109
+ k as enableScroll,
110
+ m as getFocusableElements,
105
111
  l as html,
106
112
  C as isDebug,
107
- H as keycode,
108
- a as mouse,
109
- k as production,
110
- E as removeTrapFocus,
113
+ G as keycode,
114
+ i as mouse,
115
+ M as production,
116
+ y as removeTrapFocus,
111
117
  n as scroll,
112
118
  f as throttle
113
119
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agencecinq/utils",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/src/clamp.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Clamps a number between a minimum and a maximum value.
3
+ *
4
+ * @example
5
+ * clamp(10, 1, 5); // 5
6
+ * clamp(-1, 0, 10); // 0
7
+ * clamp(7, 3, 9); // 7
8
+ */
9
+ export const clamp = (value: number, min: number, max: number): number =>
10
+ Math.min(Math.max(value, min), max);
package/src/events.ts CHANGED
@@ -5,6 +5,11 @@ export const EVENTS = {
5
5
  MODAL_CLOSE: 'modal-close',
6
6
  MODAL_OPEN: 'modal-open',
7
7
  MODAL_TOGGLE: 'modal-toggle',
8
+ SPINBUTTON_CHANGE: 'spinbutton-change',
9
+ TAB_BEFORE_ACTIVATE: 'tab-before-activate',
10
+ TAB_ACTIVATE: 'tab-activate',
11
+ TAB_DELETE: 'tab-delete',
12
+ CART_BEFORE_ADD: 'cart-before-add',
8
13
  CART_BEFORE_UPDATE: 'cart-before-update',
9
14
  CART_UPDATE: 'cart-update',
10
15
  VARIANT_CHANGE: 'variant-change',
package/src/index.ts CHANGED
@@ -3,4 +3,5 @@ export * from './scroll';
3
3
  export * from './throttle';
4
4
  export * from './environment';
5
5
  export * from './focus-trap';
6
- export * from './keycode';
6
+ export * from './keycode';
7
+ export * from './clamp';