@cronocode/react-box 1.4.4 → 1.4.6

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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),v=require("react-dom"),d=require("../box.cjs"),s=require("react"),q=require("../utils/utils.cjs");require("../box.module.css.cjs");require("../theme.cjs");function x(u){const{children:f,onPositionChange:c}=u,o=s.useRef(null),[e,p]=s.useState(),w=q.usePortalContainer(),b=s.useCallback((t,r)=>{const n=a=>{a.target.contains(t)&&r()};return document.addEventListener("scroll",n,{capture:!0}),()=>{document.removeEventListener("scroll",n,{capture:!0})}},[e]),m=s.useCallback((t,r)=>{const n=a=>{r()};return window.addEventListener("resize",n,{capture:!0}),()=>{window.removeEventListener("resize",n,{capture:!0})}},[e]),i=s.useCallback(()=>{if(o.current){const t=o.current.getBoundingClientRect(),r=t.top+window.scrollY,n=t.left+window.scrollX;((e==null?void 0:e.top)!==r||(e==null?void 0:e.left)!==n)&&(c==null||c({top:r,left:n}),p({top:t.top+window.scrollY,left:t.left+window.scrollX}))}},[e]);return s.useLayoutEffect(()=>{if(o.current){i();const t=b(o.current,i),r=m(o.current,i);return()=>{t(),r()}}},[e]),l.jsxs(l.Fragment,{children:[l.jsx(d.default,{ref:o,position:"absolute",top:0,left:0,...u,children:void 0}),e&&v.createPortal(l.jsx(d.default,{position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${e.left}px,${e.top}px)`},children:f}),w)]})}exports.default=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),m=require("react-dom"),d=require("../box.cjs"),s=require("react"),h=require("../utils/utils.cjs");require("../box.module.css.cjs");require("../theme.cjs");function q(u){const{children:f,onPositionChange:c}=u,o=s.useRef(null),[e,p]=s.useState(),w=h.usePortalContainer(),v=s.useCallback((t,r)=>{const n=a=>{a.target.contains(t)&&r()};return document.addEventListener("scroll",n,{capture:!0}),()=>{document.removeEventListener("scroll",n,{capture:!0})}},[e]),b=s.useCallback((t,r)=>{const n=a=>{r()};return window.addEventListener("resize",n,{capture:!0}),()=>{window.removeEventListener("resize",n,{capture:!0})}},[e]),i=s.useCallback(()=>{if(o.current){const t=o.current.getBoundingClientRect(),r=t.top+window.scrollY,n=t.left+window.scrollX;((e==null?void 0:e.top)!==r||(e==null?void 0:e.left)!==n)&&(c==null||c({top:r,left:n}),p({top:t.top+window.scrollY,left:t.left+window.scrollX,width:t.width>0?t.width:void 0}))}},[e]);return s.useLayoutEffect(()=>{if(o.current){i();const t=v(o.current,i),r=b(o.current,i);return()=>{t(),r()}}},[e]),l.jsxs(l.Fragment,{children:[l.jsx(d.default,{ref:o,position:"absolute",top:0,left:0,...u,children:void 0}),e&&m.createPortal(l.jsx(d.default,{position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${e.left}px,${e.top}px)`,width:e.width},children:f}),w)]})}exports.default=q;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { BoxPosition } from '../types';
3
- interface Props extends BoxPosition {
2
+ import { BoxPosition, BoxSize } from '../types';
3
+ interface Props extends BoxPosition, BoxSize {
4
4
  children: React.ReactNode;
5
5
  style?: React.ComponentProps<'div'>['style'];
6
6
  onPositionChange?(position: {
@@ -1,12 +1,12 @@
1
- import { jsxs as x, Fragment as b, jsx as a } from "react/jsx-runtime";
2
- import { createPortal as E } from "react-dom";
3
- import f from "../box.mjs";
4
- import { useRef as L, useState as z, useCallback as c, useLayoutEffect as g } from "react";
5
- import { u as C } from "../utils/utils.mjs";
1
+ import { jsxs as h, Fragment as x, jsx as a } from "react/jsx-runtime";
2
+ import { createPortal as b } from "react-dom";
3
+ import d from "../box.mjs";
4
+ import { useRef as E, useState as L, useCallback as l, useLayoutEffect as z } from "react";
5
+ import { u as g } from "../utils/utils.mjs";
6
6
  import "../box.module.css.mjs";
7
7
  import "../theme.mjs";
8
- function P(i) {
9
- const { children: p, onPositionChange: s } = i, n = L(null), [t, d] = z(), m = C(), w = c(
8
+ function P(c) {
9
+ const { children: f, onPositionChange: s } = c, n = E(null), [t, p] = L(), m = g(), w = l(
10
10
  (e, r) => {
11
11
  const o = (u) => {
12
12
  u.target.contains(e) && r();
@@ -16,7 +16,7 @@ function P(i) {
16
16
  };
17
17
  },
18
18
  [t]
19
- ), v = c(
19
+ ), v = l(
20
20
  (e, r) => {
21
21
  const o = (u) => {
22
22
  r();
@@ -26,32 +26,32 @@ function P(i) {
26
26
  };
27
27
  },
28
28
  [t]
29
- ), l = c(() => {
29
+ ), i = l(() => {
30
30
  if (n.current) {
31
31
  const e = n.current.getBoundingClientRect(), r = e.top + window.scrollY, o = e.left + window.scrollX;
32
- ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== o) && (s == null || s({ top: r, left: o }), d({ top: e.top + window.scrollY, left: e.left + window.scrollX }));
32
+ ((t == null ? void 0 : t.top) !== r || (t == null ? void 0 : t.left) !== o) && (s == null || s({ top: r, left: o }), p({ top: e.top + window.scrollY, left: e.left + window.scrollX, width: e.width > 0 ? e.width : void 0 }));
33
33
  }
34
34
  }, [t]);
35
- return g(() => {
35
+ return z(() => {
36
36
  if (n.current) {
37
- l();
38
- const e = w(n.current, l), r = v(n.current, l);
37
+ i();
38
+ const e = w(n.current, i), r = v(n.current, i);
39
39
  return () => {
40
40
  e(), r();
41
41
  };
42
42
  }
43
- }, [t]), /* @__PURE__ */ x(b, { children: [
44
- /* @__PURE__ */ a(f, { ref: n, position: "absolute", top: 0, left: 0, ...i, children: void 0 }),
45
- t && E(
43
+ }, [t]), /* @__PURE__ */ h(x, { children: [
44
+ /* @__PURE__ */ a(d, { ref: n, position: "absolute", top: 0, left: 0, ...c, children: void 0 }),
45
+ t && b(
46
46
  /* @__PURE__ */ a(
47
- f,
47
+ d,
48
48
  {
49
49
  position: "absolute",
50
50
  top: 0,
51
51
  left: 0,
52
52
  transition: "none",
53
- style: { transform: `translate(${t.left}px,${t.top}px)` },
54
- children: p
53
+ style: { transform: `translate(${t.left}px,${t.top}px)`, width: t.width },
54
+ children: f
55
55
  }
56
56
  ),
57
57
  m
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "main": "./box.cjs",
5
5
  "module": "./box.mjs",
6
6
  "types": "./box.d.ts",
package/plugins.cjs CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(r){const _=Object.entries(r.colors).map(([o,e])=>`--color${o}: ${e};`).join(`
2
- `),n=Object.entries(r.shadows).map(([o,e])=>`--shadow${o}: ${e};`).join(`
3
- `),i=Object.entries(r.backgrounds).map(([o,e])=>`--background${o}: ${e};`).join(`
4
- `),s=`:root {
5
- ${_}
6
- ${n}
7
- ${i}
8
- }`,$=Object.keys(r.colors).map(o=>`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(r){const _=Object.entries(r.colors).map(([o,l])=>`--color${o}: ${l};`).join(`
2
+ `),t=Object.entries(r.shadows).map(([o,l])=>`--shadow${o}: ${l};`).join(`
3
+ `),c=Object.entries(r.backgrounds).map(([o,l])=>`--background${o}: ${l};`).join(`
4
+ `),e=[":root {"];_&&e.push(` ${_}`),t&&e.push(` ${t}`),c&&e.push(` ${c}`),e.push("}");const n=Object.keys(r.colors).map(o=>`
9
5
  .color_${o},
10
6
  .color_h_${o}:hover,
11
7
  ._h:hover>.color_h_${o} {
@@ -124,7 +120,7 @@
124
120
  line {
125
121
  stroke: var(--color${o});
126
122
  }
127
- }`),h=Object.keys(r.shadows).map(o=>`
123
+ }`),i=Object.keys(r.shadows).map(o=>`
128
124
  .shadow_${o},
129
125
  .shadow_h_${o}:hover,
130
126
  ._h:hover>.shadow_h_${o} {
@@ -138,7 +134,7 @@
138
134
 
139
135
  .shadow_a_${o}:active {
140
136
  box-shadow: var(--shadow${o});
141
- }`),b=Object.keys(r.backgrounds).map(o=>`
137
+ }`),h=Object.keys(r.backgrounds).map(o=>`
142
138
  .bg_${o},
143
139
  .bg_h_${o}:hover,
144
140
  ._h:hover>.bg_h_${o} {
@@ -152,12 +148,12 @@
152
148
 
153
149
  .bg_a_${o}:active {
154
150
  background: var(--background${o});
155
- }`),l=Object.keys(r.colors).map(o=>`'${o}'`).join(" | "),t=Object.keys(r.backgrounds).map(o=>`'${o}'`).join(" | "),c=Object.keys(r.shadows).map(o=>`'${o}'`).join(" | "),p=`import '@cronocode/react-box';
151
+ }`),s=Object.keys(r.colors).map(o=>`'${o}'`).join(" | "),$=Object.keys(r.backgrounds).map(o=>`'${o}'`).join(" | "),b=Object.keys(r.shadows).map(o=>`'${o}'`).join(" | "),p=`import {ColorType} from '@cronocode/react-box';
156
152
 
157
153
  declare module '@cronocode/react-box' {
158
- type ColorType = ${l};
159
- type BackgroundType = ${t};
160
- type ShadowType = ${c};
154
+ type ColorType = ${s};
155
+ type BackgroundType = ${$};
156
+ type ShadowType = ${b};
161
157
 
162
158
  namespace Augmented {
163
159
  interface Props {
@@ -196,13 +192,8 @@ declare module '@cronocode/react-box' {
196
192
  }
197
193
  }
198
194
  }
199
- `,d=`import '@cronocode/react-box/components/baseSvg';
200
195
 
201
196
  declare module '@cronocode/react-box/components/baseSvg' {
202
- type ColorType = ${l};
203
- type BackgroundType = ${t};
204
- type ShadowType = ${c};
205
-
206
197
  namespace Augmented {
207
198
  interface Props {
208
199
  fill?: ColorType;
@@ -216,5 +207,6 @@ declare module '@cronocode/react-box/components/baseSvg' {
216
207
  }
217
208
  }
218
209
  }
219
- `;return{themeCss:[s,...$,...h,...b].join(`
220
- `),boxDts:p,baseSvgDts:d}}exports.boxTheme=u;
210
+ `;return{themeCss:[e.join(`
211
+ `),...n,...i,...h].join(`
212
+ `),boxDts:p}}exports.boxTheme=u;
package/plugins.d.ts CHANGED
@@ -6,7 +6,6 @@ interface BoxThemeOptions {
6
6
  interface BoxThemeResources {
7
7
  themeCss: string;
8
8
  boxDts: string;
9
- baseSvgDts: string;
10
9
  }
11
10
  export declare function boxTheme(options: BoxThemeOptions): BoxThemeResources;
12
11
  export {};
package/plugins.mjs CHANGED
@@ -1,12 +1,10 @@
1
- function C(r) {
2
- const c = Object.entries(r.colors).map(([o, e]) => `--color${o}: ${e};`).join(`
3
- `), n = Object.entries(r.shadows).map(([o, e]) => `--shadow${o}: ${e};`).join(`
4
- `), i = Object.entries(r.backgrounds).map(([o, e]) => `--background${o}: ${e};`).join(`
5
- `), $ = `:root {
6
- ${c}
7
- ${n}
8
- ${i}
9
- }`, s = Object.keys(r.colors).map((o) => `
1
+ function d(r) {
2
+ const _ = Object.entries(r.colors).map(([o, l]) => `--color${o}: ${l};`).join(`
3
+ `), t = Object.entries(r.shadows).map(([o, l]) => `--shadow${o}: ${l};`).join(`
4
+ `), c = Object.entries(r.backgrounds).map(([o, l]) => `--background${o}: ${l};`).join(`
5
+ `), e = [":root {"];
6
+ _ && e.push(` ${_}`), t && e.push(` ${t}`), c && e.push(` ${c}`), e.push("}");
7
+ const n = Object.keys(r.colors).map((o) => `
10
8
  .color_${o},
11
9
  .color_h_${o}:hover,
12
10
  ._h:hover>.color_h_${o} {
@@ -125,7 +123,7 @@ function C(r) {
125
123
  line {
126
124
  stroke: var(--color${o});
127
125
  }
128
- }`), h = Object.keys(r.shadows).map((o) => `
126
+ }`), i = Object.keys(r.shadows).map((o) => `
129
127
  .shadow_${o},
130
128
  .shadow_h_${o}:hover,
131
129
  ._h:hover>.shadow_h_${o} {
@@ -139,7 +137,7 @@ function C(r) {
139
137
 
140
138
  .shadow_a_${o}:active {
141
139
  box-shadow: var(--shadow${o});
142
- }`), b = Object.keys(r.backgrounds).map((o) => `
140
+ }`), h = Object.keys(r.backgrounds).map((o) => `
143
141
  .bg_${o},
144
142
  .bg_h_${o}:hover,
145
143
  ._h:hover>.bg_h_${o} {
@@ -153,12 +151,12 @@ function C(r) {
153
151
 
154
152
  .bg_a_${o}:active {
155
153
  background: var(--background${o});
156
- }`), l = Object.keys(r.colors).map((o) => `'${o}'`).join(" | "), t = Object.keys(r.backgrounds).map((o) => `'${o}'`).join(" | "), _ = Object.keys(r.shadows).map((o) => `'${o}'`).join(" | "), p = `import '@cronocode/react-box';
154
+ }`), $ = Object.keys(r.colors).map((o) => `'${o}'`).join(" | "), s = Object.keys(r.backgrounds).map((o) => `'${o}'`).join(" | "), b = Object.keys(r.shadows).map((o) => `'${o}'`).join(" | "), p = `import {ColorType} from '@cronocode/react-box';
157
155
 
158
156
  declare module '@cronocode/react-box' {
159
- type ColorType = ${l};
160
- type BackgroundType = ${t};
161
- type ShadowType = ${_};
157
+ type ColorType = ${$};
158
+ type BackgroundType = ${s};
159
+ type ShadowType = ${b};
162
160
 
163
161
  namespace Augmented {
164
162
  interface Props {
@@ -197,13 +195,8 @@ declare module '@cronocode/react-box' {
197
195
  }
198
196
  }
199
197
  }
200
- `, d = `import '@cronocode/react-box/components/baseSvg';
201
198
 
202
199
  declare module '@cronocode/react-box/components/baseSvg' {
203
- type ColorType = ${l};
204
- type BackgroundType = ${t};
205
- type ShadowType = ${_};
206
-
207
200
  namespace Augmented {
208
201
  interface Props {
209
202
  fill?: ColorType;
@@ -219,12 +212,12 @@ declare module '@cronocode/react-box/components/baseSvg' {
219
212
  }
220
213
  `;
221
214
  return {
222
- themeCss: [$, ...s, ...h, ...b].join(`
215
+ themeCss: [e.join(`
216
+ `), ...n, ...i, ...h].join(`
223
217
  `),
224
- boxDts: p,
225
- baseSvgDts: d
218
+ boxDts: p
226
219
  };
227
220
  }
228
221
  export {
229
- C as boxTheme
222
+ d as boxTheme
230
223
  };