@cronocode/react-box 3.0.14 → 3.0.15

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 +1 @@
1
- "use strict";const c=require("react/jsx-runtime"),v=require("react-dom"),d=require("../box.cjs"),s=require("react"),C=require("../core.cjs"),l=2;function R(f,w){const{onPositionChange:a}=f,i=s.useRef(null),[t,p]=s.useState(),b=C.usePortalContainer(),h=s.useCallback((r,e)=>{const o=m=>{m.target.contains(r)&&e(r)},n=new AbortController;return document.addEventListener("scroll",o,n),()=>n.abort()},[t]),x=s.useCallback((r,e)=>{const o=n=>{e(r)};return window.addEventListener("resize",o,{capture:!0}),()=>{window.removeEventListener("resize",o,{capture:!0})}},[t]),u=s.useCallback(r=>{const e=r.getBoundingClientRect(),o=Math.round((e.top+window.scrollY)*l)/l,n=Math.round((e.left+window.scrollX)*l)/l;((t==null?void 0:t.top)!==o||(t==null?void 0:t.left)!==n)&&(a==null||a({top:o,left:n}),p({top:o,left:n,width:e.width>0?e.width:void 0}))},[t]);return s.useLayoutEffect(()=>{if(i.current){u(i.current);const r=h(i.current,u),e=x(i.current,u);return()=>{r(),e()}}},[t]),c.jsxs(c.Fragment,{children:[c.jsx(d,{ref:i}),t&&v.createPortal(c.jsx(d,{ref:w,position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${t.left}px,${t.top}px)`,width:t.width},children:c.jsx(d,{position:"absolute",width:"fit",...f})}),b)]})}const j=s.forwardRef(R);module.exports=j;
1
+ "use strict";const i=require("react/jsx-runtime"),C=require("react-dom"),d=require("../box.cjs"),s=require("react"),R=require("../core.cjs"),l=2;function m(f,w){const{onPositionChange:a}=f,c=s.useRef(null),[t,b]=s.useState(),h=R.usePortalContainer(),x=s.useCallback((r,e)=>{const n=p=>{p.target.contains(r)&&e(r)},o=new AbortController;return document.addEventListener("scroll",n,{signal:o.signal,capture:!0}),()=>o.abort()},[t]),g=s.useCallback((r,e)=>{const n=p=>{e(r)},o=new AbortController;return window.addEventListener("resize",n,{signal:o.signal,capture:!0}),()=>o.abort()},[t]),u=s.useCallback(r=>{const e=r.getBoundingClientRect(),n=Math.round((e.top+window.scrollY)*l)/l,o=Math.round((e.left+window.scrollX)*l)/l;((t==null?void 0:t.top)!==n||(t==null?void 0:t.left)!==o)&&(a==null||a({top:n,left:o}),b({top:n,left:o,width:e.width>0?e.width:void 0}))},[t]);return s.useLayoutEffect(()=>{if(c.current){u(c.current);const r=x(c.current,u),e=g(c.current,u);return()=>{r(),e()}}},[t]),i.jsxs(i.Fragment,{children:[i.jsx(d,{ref:c}),t&&C.createPortal(i.jsx(d,{ref:w,position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${t.left}px,${t.top}px)`,width:t.width},children:i.jsx(d,{position:"absolute",width:"fit",...f})}),h)]})}const j=s.forwardRef(m);module.exports=j;
@@ -1,63 +1,61 @@
1
1
  import { jsxs as x, Fragment as C, jsx as a } from "react/jsx-runtime";
2
- import { createPortal as R } from "react-dom";
2
+ import { createPortal as v } from "react-dom";
3
3
  import u from "../box.mjs";
4
- import { forwardRef as g, useRef as z, useState as E, useCallback as d, useLayoutEffect as L } from "react";
5
- import { f as D } from "../core.mjs";
4
+ import { forwardRef as R, useRef as z, useState as A, useCallback as f, useLayoutEffect as D } from "react";
5
+ import { f as E } from "../core.mjs";
6
6
  const i = 2;
7
- function H(f, p) {
8
- const { onPositionChange: l } = f, s = z(null), [t, w] = E(), m = D(), h = d(
9
- (o, e) => {
10
- const r = (v) => {
11
- v.target.contains(o) && e(o);
12
- }, n = new AbortController();
13
- return document.addEventListener("scroll", r, n), () => n.abort();
7
+ function H(d, w) {
8
+ const { onPositionChange: l } = d, s = z(null), [t, m] = A(), b = E(), h = f(
9
+ (e, o) => {
10
+ const n = (p) => {
11
+ p.target.contains(e) && o(e);
12
+ }, r = new AbortController();
13
+ return document.addEventListener("scroll", n, { signal: r.signal, capture: !0 }), () => r.abort();
14
14
  },
15
15
  [t]
16
- ), b = d(
17
- (o, e) => {
18
- const r = (n) => {
19
- e(o);
20
- };
21
- return window.addEventListener("resize", r, { capture: !0 }), () => {
22
- window.removeEventListener("resize", r, { capture: !0 });
23
- };
16
+ ), g = f(
17
+ (e, o) => {
18
+ const n = (p) => {
19
+ o(e);
20
+ }, r = new AbortController();
21
+ return window.addEventListener("resize", n, { signal: r.signal, capture: !0 }), () => r.abort();
24
22
  },
25
23
  [t]
26
- ), c = d(
27
- (o) => {
28
- const e = o.getBoundingClientRect(), r = Math.round((e.top + window.scrollY) * i) / i, n = Math.round((e.left + window.scrollX) * i) / i;
29
- ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== n) && (l == null || l({ top: r, left: n }), w({ top: r, left: n, width: e.width > 0 ? e.width : void 0 }));
24
+ ), c = f(
25
+ (e) => {
26
+ const o = e.getBoundingClientRect(), n = Math.round((o.top + window.scrollY) * i) / i, r = Math.round((o.left + window.scrollX) * i) / i;
27
+ ((t == null ? void 0 : t.top) !== n || (t == null ? void 0 : t.left) !== r) && (l == null || l({ top: n, left: r }), m({ top: n, left: r, width: o.width > 0 ? o.width : void 0 }));
30
28
  },
31
29
  [t]
32
30
  );
33
- return L(() => {
31
+ return D(() => {
34
32
  if (s.current) {
35
33
  c(s.current);
36
- const o = h(s.current, c), e = b(s.current, c);
34
+ const e = h(s.current, c), o = g(s.current, c);
37
35
  return () => {
38
- o(), e();
36
+ e(), o();
39
37
  };
40
38
  }
41
39
  }, [t]), /* @__PURE__ */ x(C, { children: [
42
40
  /* @__PURE__ */ a(u, { ref: s }),
43
- t && R(
41
+ t && v(
44
42
  /* @__PURE__ */ a(
45
43
  u,
46
44
  {
47
- ref: p,
45
+ ref: w,
48
46
  position: "absolute",
49
47
  top: 0,
50
48
  left: 0,
51
49
  transition: "none",
52
50
  style: { transform: `translate(${t.left}px,${t.top}px)`, width: t.width },
53
- children: /* @__PURE__ */ a(u, { position: "absolute", width: "fit", ...f })
51
+ children: /* @__PURE__ */ a(u, { position: "absolute", width: "fit", ...d })
54
52
  }
55
53
  ),
56
- m
54
+ b
57
55
  )
58
56
  ] });
59
57
  }
60
- const M = g(H);
58
+ const M = R(H);
61
59
  export {
62
60
  M as default
63
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "3.0.14",
3
+ "version": "3.0.15",
4
4
  "type": "module",
5
5
  "main": "./box.cjs",
6
6
  "module": "./box.mjs",