@telefonica/mistica 15.15.0 → 15.16.1

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,105 +1,105 @@
1
1
  "use client";
2
- import { jsxs as p, Fragment as O, jsx as a } from "react/jsx-runtime";
2
+ import { jsxs as p, Fragment as H, jsx as a } from "react/jsx-runtime";
3
3
  import * as v from "react";
4
- import P from "classnames";
5
- import { debounce as _ } from "./utils/helpers.js";
6
- import { isRunningAcceptanceTest as j } from "./utils/platform.js";
7
- import { useBoundingRect as W, useScreenSize as G, useTheme as M, useElementDimensions as E, useWindowSize as X, useIsomorphicLayoutEffect as q } from "./hooks.js";
8
- import { getScrollableParentElement as J, addPassiveEventListener as b, removePassiveEventListener as S, hasScroll as K, getScrollDistanceToBottom as Q } from "./utils/dom.js";
9
- import { Portal as U } from "./portal.js";
4
+ import z from "classnames";
5
+ import { debounce as O } from "./utils/helpers.js";
6
+ import { isRunningAcceptanceTest as P } from "./utils/platform.js";
7
+ import { useBoundingRect as _, useScreenSize as j, useTheme as M, useElementDimensions as y, useWindowSize as W, useIsomorphicLayoutEffect as G } from "./hooks.js";
8
+ import { getScrollableParentElement as X, addPassiveEventListener as E, removePassiveEventListener as b, hasScroll as q, getScrollDistanceToBottom as J } from "./utils/dom.js";
9
+ import { Portal as K } from "./portal.js";
10
10
  import { vars as T } from "./skins/skin-contract.css-mistica.js";
11
- import { container as V, footer as Y, withoutFooter as Z, elevated as C, fixedFooter as ee, portal as te, fixedBackgroundLayer as oe, absoluteBackgroundLayer as $, vars as re } from "./fixed-footer-layout.css-mistica.js";
12
- import { applyCssVars as se, safeAreaInsetBottom as g } from "./utils/css.js";
13
- import { useFixedToTopHeight as ae } from "./fixed-to-top.js";
14
- import { useOverScrollColor as ie } from "./overscroll-color-context.js";
15
- const ne = (e)=>e === document.documentElement ? window : e, ce = (e)=>{
11
+ import { container as Q, footer as U, withoutFooter as V, elevated as Y, fixedFooter as Z, portal as C, fixedBackgroundLayer as ee, absoluteBackgroundLayer as S, vars as te } from "./fixed-footer-layout.css-mistica.js";
12
+ import { applyCssVars as oe, safeAreaInsetBottom as re } from "./utils/css.js";
13
+ import { useFixedToTopHeight as se } from "./fixed-to-top.js";
14
+ import { useOverScrollColor as ae } from "./overscroll-color-context.js";
15
+ const ie = (e)=>e === document.documentElement ? window : e, ne = (e)=>{
16
16
  const l = setTimeout(e, 0);
17
17
  return {
18
18
  cancel: ()=>clearTimeout(l)
19
19
  };
20
- }, le = 200, me = (param)=>{
20
+ }, ce = 200, le = (param)=>{
21
21
  let { isFooterVisible: e = !0, footer: l, footerHeight: k = "auto", footerBgColor: i = T.colors.background, containerBgColor: F = T.colors.background, children: L, onChangeFooterHeight: n } = param;
22
- const [w, h] = v.useState(!1), m = v.useRef(null), { height: d } = W(m) || {
22
+ const [$, g] = v.useState(!1), d = v.useRef(null), { height: m } = _(d) || {
23
23
  height: 0
24
- }, { isTabletOrSmaller: u } = G(), { platformOverrides: x } = M(), { height: r, ref: D } = E(), { visualHeight: I } = X(), s = ae(), t = I - s - r > le, { topColor: N = i } = ie(), { height: y, ref: R } = E();
25
- q(()=>{
24
+ }, { isTabletOrSmaller: u } = j(), { platformOverrides: h } = M(), { height: r, ref: w } = y({
25
+ includeMargins: !0
26
+ }), { visualHeight: D } = W(), s = se(), t = D - s - r > ce, { topColor: I = i } = ae(), { height: x, ref: N } = y();
27
+ G(()=>{
26
28
  n == null || n(r);
27
29
  }, [
28
30
  n,
29
31
  r
30
- ]);
31
- const A = `calc(${g} + ${r}px)`;
32
- v.useEffect(()=>{
33
- if (!u || j(x) || !t) {
34
- h(!1);
32
+ ]), v.useEffect(()=>{
33
+ if (!u || P(h) || !t) {
34
+ g(!1);
35
35
  return;
36
36
  }
37
- const f = J(m.current), B = ()=>K(f) && Q(f) > s + 1, o = _(()=>{
38
- h(B());
37
+ const f = X(d.current), A = ()=>q(f) && J(f) > s + 1, o = O(()=>{
38
+ g(A());
39
39
  }, 50, {
40
40
  leading: !0,
41
41
  maxWait: 100
42
- }), z = ce(o), c = ne(f);
43
- return b(c, "resize", o), b(c, "scroll", o), ()=>{
44
- o.cancel(), S(c, "scroll", o), S(c, "resize", o), z.cancel();
42
+ }), B = ne(o), c = ie(f);
43
+ return E(c, "resize", o), E(c, "scroll", o), ()=>{
44
+ o.cancel(), b(c, "scroll", o), b(c, "resize", o), B.cancel();
45
45
  };
46
46
  }, [
47
- x,
47
+ h,
48
48
  u,
49
49
  t,
50
50
  // `topDistance` and `contentHeight` dependencies are needed to recalculate the elevation state
51
51
  s,
52
- d
52
+ m
53
53
  ]);
54
- const H = ()=>/* @__PURE__ */ p(U, {
55
- className: te,
54
+ const R = ()=>/* @__PURE__ */ p(K, {
55
+ className: C,
56
56
  children: [
57
57
  /* @__PURE__ */ a("div", {
58
- className: oe,
58
+ className: ee,
59
59
  style: {
60
- background: `linear-gradient(180deg, ${N} 50%, ${i} 50% 100%)`
60
+ background: `linear-gradient(180deg, ${I} 50%, ${i} 50% 100%)`
61
61
  }
62
62
  }),
63
63
  /* @__PURE__ */ a("div", {
64
- ref: R,
65
- className: $,
64
+ ref: N,
65
+ className: S,
66
66
  style: {
67
67
  background: F,
68
68
  // this color could be a gradient
69
69
  top: s - 1,
70
70
  // -1 because the navigationbar could have a 1px transparent background
71
- bottom: t ? A : "unset",
72
- height: t ? "unset" : d
71
+ bottom: t ? r : "unset",
72
+ height: t ? "unset" : m
73
73
  }
74
74
  }),
75
75
  /* @__PURE__ */ a("div", {
76
- className: $,
76
+ className: S,
77
77
  style: {
78
78
  background: i,
79
- top: y + s - 1,
80
- height: `calc(${d}px - ${y}px)`
79
+ top: x + s - 1,
80
+ height: `calc(${m}px - ${x}px)`
81
81
  }
82
82
  })
83
83
  ]
84
84
  });
85
- return /* @__PURE__ */ p(O, {
85
+ return /* @__PURE__ */ p(H, {
86
86
  children: [
87
87
  /* @__PURE__ */ p("div", {
88
- ref: m,
89
- className: V,
90
- style: se({
91
- [re.footerHeight]: t ? `calc(${g} + ${r}px)` : "0px"
88
+ ref: d,
89
+ className: Q,
90
+ style: oe({
91
+ [te.footerHeight]: t ? `${r}px` : "0px"
92
92
  }),
93
93
  children: [
94
- H(),
94
+ R(),
95
95
  L
96
96
  ]
97
97
  }),
98
98
  /* @__PURE__ */ a("div", {
99
- className: P(Y, {
100
- [Z]: !e,
101
- [C]: w,
102
- [ee]: t
99
+ className: z(U, {
100
+ [V]: !e,
101
+ [Y]: $,
102
+ [Z]: t
103
103
  }),
104
104
  style: {
105
105
  background: u ? i : void 0
@@ -107,16 +107,16 @@ const ne = (e)=>e === document.documentElement ? window : e, ce = (e)=>{
107
107
  "data-testid": `fixed-footer${e ? "-visible" : "-hidden"}`,
108
108
  "data-position-fixed": "bottom",
109
109
  children: e && /* @__PURE__ */ a("aside", {
110
- ref: D,
110
+ ref: w,
111
111
  "data-component-name": "FixedFooter",
112
112
  style: {
113
113
  height: k,
114
- marginBottom: g
114
+ marginBottom: re
115
115
  },
116
116
  children: l
117
117
  })
118
118
  })
119
119
  ]
120
120
  });
121
- }, $e = me;
122
- export { $e as default };
121
+ }, Se = le;
122
+ export { Se as default };
package/dist-es/hooks.js CHANGED
@@ -1,162 +1,168 @@
1
- import * as r from "react";
2
- import b from "./theme-context.js";
3
- import y from "./screen-size-context.js";
4
- import W from "./aria-id-getter-context.js";
5
- import { listenResize as x } from "./utils/dom.js";
6
- import { isClientSide as h } from "./utils/environment.js";
7
- import { isEqual as E } from "./utils/helpers.js";
8
- const H = ()=>{
9
- const t = r.useContext(b);
1
+ import * as n from "react";
2
+ import I from "./theme-context.js";
3
+ import E from "./screen-size-context.js";
4
+ import H from "./aria-id-getter-context.js";
5
+ import { listenResize as T } from "./utils/dom.js";
6
+ import { isClientSide as l } from "./utils/environment.js";
7
+ import { isEqual as R } from "./utils/helpers.js";
8
+ const C = ()=>{
9
+ const t = n.useContext(I);
10
10
  if (!t) throw Error("To use @telefonica/mistica components you must instantiate <ThemeContextProvider> as their parent.");
11
11
  return t;
12
12
  };
13
- let a = "", m = 0, w = 0;
14
- const L = (t)=>{
15
- r.useEffect(()=>{
13
+ let f = "", S = 0, g = 0;
14
+ const M = (t)=>{
15
+ n.useEffect(()=>{
16
16
  if (t) {
17
- const n = document.scrollingElement || document.documentElement, e = ()=>{
17
+ const r = document.scrollingElement || document.documentElement, e = ()=>{
18
18
  var i;
19
19
  var _ref, _ref1;
20
- if (w++, !(w > 1) && (m = (_ref = n == null ? void 0 : n.scrollTop) !== null && _ref !== void 0 ? _ref : 0, a = (_ref1 = (i = document.body) == null ? void 0 : i.style.cssText) !== null && _ref1 !== void 0 ? _ref1 : "", document.body)) {
20
+ if (g++, !(g > 1) && (S = (_ref = r == null ? void 0 : r.scrollTop) !== null && _ref !== void 0 ? _ref : 0, f = (_ref1 = (i = document.body) == null ? void 0 : i.style.cssText) !== null && _ref1 !== void 0 ? _ref1 : "", document.body)) {
21
21
  var _ref2;
22
- const o = window.innerWidth > ((_ref2 = n == null ? void 0 : n.clientWidth) !== null && _ref2 !== void 0 ? _ref2 : window.innerWidth) ? "scroll" : "hidden";
23
- document.body.style.cssText = a + (a.endsWith(";") ? "" : ";") + [
22
+ const o = window.innerWidth > ((_ref2 = r == null ? void 0 : r.clientWidth) !== null && _ref2 !== void 0 ? _ref2 : window.innerWidth) ? "scroll" : "hidden";
23
+ document.body.style.cssText = f + (f.endsWith(";") ? "" : ";") + [
24
24
  "overflow: hidden;",
25
25
  `overflow-y: ${o};`,
26
26
  "position: fixed;",
27
- `top: ${-m}px;`,
27
+ `top: ${-S}px;`,
28
28
  "left: 0px;",
29
29
  "right: 0px;",
30
30
  "bottom: 0px;",
31
31
  "overscroll-behavior-y: contain;"
32
32
  ].join("");
33
33
  }
34
- }, s = ()=>{
35
- w--, !(w > 0) && (document.body && (document.body.style.cssText = a), n && (n.scrollTop = m));
34
+ }, c = ()=>{
35
+ g--, !(g > 0) && (document.body && (document.body.style.cssText = f), r && (r.scrollTop = S));
36
36
  };
37
- return e(), s;
37
+ return e(), c;
38
38
  }
39
39
  return ()=>{};
40
40
  }, [
41
41
  t
42
42
  ]);
43
- }, M = ()=>r.useContext(y), q = ()=>{
44
- const [t, n] = r.useState(0), [e, s] = r.useState(0), [i, c] = r.useState(null), o = r.useCallback((d)=>{
45
- if (!d) {
46
- n(0), s(0);
43
+ }, k = ()=>n.useContext(E), F = function() {
44
+ let { includeMargins: t = !1 } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
45
+ const [r, e] = n.useState(0), [c, i] = n.useState(0), [s, o] = n.useState(null), d = n.useCallback((a)=>{
46
+ if (!a) {
47
+ e(0), i(0);
47
48
  return;
48
49
  }
49
- const { width: f, height: l } = d[0].contentRect;
50
- n(f), s(l);
51
- }, []), u = r.useCallback((d)=>{
52
- c(d);
50
+ const { width: w, height: m } = a[0].contentRect;
51
+ if (t) {
52
+ const h = window.getComputedStyle(a[0].target), v = parseInt(h.marginTop, 10), b = parseInt(h.marginBottom, 10), W = parseInt(h.marginLeft, 10), x = parseInt(h.marginRight, 10);
53
+ e(w + W + x), i(m + v + b);
54
+ } else e(w), i(m);
55
+ }, [
56
+ t
57
+ ]), u = n.useCallback((a)=>{
58
+ o(a);
53
59
  }, []);
54
- return r.useEffect(()=>{
55
- if (!i) {
56
- n(0), s(0);
60
+ return n.useEffect(()=>{
61
+ if (!s) {
62
+ e(0), i(0);
57
63
  return;
58
64
  }
59
- return x(i, o);
65
+ return T(s, d);
60
66
  }, [
61
- i,
62
- o
67
+ s,
68
+ d
63
69
  ]), {
64
- width: t,
65
- height: e,
70
+ width: r,
71
+ height: c,
66
72
  ref: u
67
73
  };
68
- }, D = (t)=>{
69
- const { useId: n } = H();
70
- if (n) {
71
- const e = n();
74
+ }, $ = (t)=>{
75
+ const { useId: r } = C();
76
+ if (r) {
77
+ const e = r();
72
78
  return t || e;
73
79
  } else {
74
- const e = r.useContext(W);
75
- return r.useRef(t || e()).current;
80
+ const e = n.useContext(H);
81
+ return n.useRef(t || e()).current;
76
82
  }
77
- }, v = ()=>{
78
- var l;
79
- const [t, n] = r.useState(h() ? window.innerHeight : 1200), [e, s] = r.useState(h() ? window.innerWidth : 800), [i, c] = r.useState(h() ? window.screen.availHeight : 1200), [o, u] = r.useState(h() ? window.screen.availWidth : 800), [d, f] = r.useState(h() ? ((l = window.visualViewport) == null ? void 0 : l.height) || window.screen.availHeight : 1200);
80
- return r.useEffect(()=>{
81
- const g = ()=>{
82
- var S;
83
- n(window.innerHeight), s(window.innerWidth), c(window.screen.availHeight), u(window.screen.availWidth), f(((S = window.visualViewport) == null ? void 0 : S.height) || window.screen.availHeight);
83
+ }, y = ()=>{
84
+ var w;
85
+ const [t, r] = n.useState(l() ? window.innerHeight : 1200), [e, c] = n.useState(l() ? window.innerWidth : 800), [i, s] = n.useState(l() ? window.screen.availHeight : 1200), [o, d] = n.useState(l() ? window.screen.availWidth : 800), [u, a] = n.useState(l() ? ((w = window.visualViewport) == null ? void 0 : w.height) || window.screen.availHeight : 1200);
86
+ return n.useEffect(()=>{
87
+ const m = ()=>{
88
+ var h;
89
+ r(window.innerHeight), c(window.innerWidth), s(window.screen.availHeight), d(window.screen.availWidth), a(((h = window.visualViewport) == null ? void 0 : h.height) || window.screen.availHeight);
84
90
  };
85
- return window.addEventListener("resize", g), ()=>{
86
- window.removeEventListener("resize", g);
91
+ return window.addEventListener("resize", m), ()=>{
92
+ window.removeEventListener("resize", m);
87
93
  };
88
- }, []), r.useMemo(()=>({
94
+ }, []), n.useMemo(()=>({
89
95
  height: t,
90
96
  width: e,
91
97
  screenHeight: i,
92
98
  screenWidth: o,
93
- visualHeight: d
99
+ visualHeight: u
94
100
  }), [
95
101
  t,
96
102
  e,
97
103
  i,
98
104
  o,
99
- d
105
+ u
100
106
  ]);
101
- }, k = ()=>{
102
- const { height: t } = v();
107
+ }, j = ()=>{
108
+ const { height: t } = y();
103
109
  return t;
104
- }, F = ()=>{
105
- const { width: t } = v();
110
+ }, G = ()=>{
111
+ const { width: t } = y();
106
112
  return t;
107
- }, $ = h() ? r.useLayoutEffect : r.useEffect, I = (t, n, e)=>{
108
- const [s, i] = r.useState(n);
109
- return r.useEffect(()=>{
113
+ }, O = l() ? n.useLayoutEffect : n.useEffect, B = (t, r, e)=>{
114
+ const [c, i] = n.useState(r);
115
+ return n.useEffect(()=>{
110
116
  if (!t.current) return;
111
117
  if (typeof window.IntersectionObserver > "u") return ()=>{};
112
- const c = new IntersectionObserver((o)=>{
118
+ const s = new IntersectionObserver((o)=>{
113
119
  i(o[0].isIntersecting);
114
120
  }, {
115
121
  root: e == null ? void 0 : e.root,
116
122
  rootMargin: e == null ? void 0 : e.rootMargin,
117
123
  threshold: e == null ? void 0 : e.threshold
118
124
  });
119
- return c.observe(t.current), ()=>{
120
- c.disconnect();
125
+ return s.observe(t.current), ()=>{
126
+ s.disconnect();
121
127
  };
122
128
  }, [
123
129
  t,
124
130
  e == null ? void 0 : e.root,
125
131
  e == null ? void 0 : e.rootMargin,
126
132
  e == null ? void 0 : e.threshold
127
- ]), s;
128
- }, T = (t)=>{
129
- const { top: n, right: e, bottom: s, left: i, width: c, height: o, x: u, y: d } = t.getBoundingClientRect();
133
+ ]), c;
134
+ }, z = (t)=>{
135
+ const { top: r, right: e, bottom: c, left: i, width: s, height: o, x: d, y: u } = t.getBoundingClientRect();
130
136
  return {
131
- top: n,
137
+ top: r,
132
138
  right: e,
133
- bottom: s,
139
+ bottom: c,
134
140
  left: i,
135
- width: c,
141
+ width: s,
136
142
  height: o,
137
- x: u,
138
- y: d
143
+ x: d,
144
+ y: u
139
145
  };
140
- }, j = function(t) {
141
- let n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0, e = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
142
- const [s, i] = r.useState(), c = I(t, !1);
143
- return r.useEffect(()=>{
146
+ }, P = function(t) {
147
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0, e = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
148
+ const [c, i] = n.useState(), s = B(t, !1);
149
+ return n.useEffect(()=>{
144
150
  let o;
145
- const u = ()=>{
146
- if (t.current && (c || e)) {
147
- const d = T(t.current);
148
- E(s, d) || i(d), n && (o = requestAnimationFrame(u));
151
+ const d = ()=>{
152
+ if (t.current && (s || e)) {
153
+ const u = z(t.current);
154
+ R(c, u) || i(u), r && (o = requestAnimationFrame(d));
149
155
  } else i(void 0);
150
156
  };
151
- return o = requestAnimationFrame(u), ()=>{
157
+ return o = requestAnimationFrame(d), ()=>{
152
158
  cancelAnimationFrame(o);
153
159
  };
154
160
  }, [
155
161
  t,
156
- s,
157
162
  c,
158
- n,
163
+ s,
164
+ r,
159
165
  e
160
- ]), s;
166
+ ]), c;
161
167
  };
162
- export { D as useAriaId, j as useBoundingRect, L as useDisableBodyScroll, q as useElementDimensions, I as useIsInViewport, $ as useIsomorphicLayoutEffect, M as useScreenSize, H as useTheme, k as useWindowHeight, v as useWindowSize, F as useWindowWidth };
168
+ export { $ as useAriaId, P as useBoundingRect, M as useDisableBodyScroll, F as useElementDimensions, B as useIsInViewport, O as useIsomorphicLayoutEffect, k as useScreenSize, C as useTheme, j as useWindowHeight, y as useWindowSize, G as useWindowWidth };
@@ -1,2 +1,2 @@
1
- const o = "15.15.0";
1
+ const o = "15.16.1";
2
2
  export { o as PACKAGE_VERSION };