neatkit 0.6.0 → 0.7.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.
package/dist/Content.cjs CHANGED
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("react"),l=require("./units-PzuiQNnw.cjs"),C=[{minWidth:l.breakpoint("xl"),marginPercent:32,preferredWidth:1200},{minWidth:l.breakpoint("lg"),marginPercent:20,preferredWidth:1100},{minWidth:l.breakpoint("md"),marginPercent:14,preferredWidth:l.breakpoint("md")},{minWidth:l.breakpoint("sm"),marginPercent:8,preferredWidth:650}],W=16;function M(e){for(const t of C)if(e>=t.minWidth)return t}function k(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<l.breakpoint("sm")||t<=0)return;const n=M(e);if(!n)return;const r=e*n.marginPercent/100,s=e-r*2,m=Math.min(n.preferredWidth,e-W),a=Math.max(s,m);let o=Math.floor(a/t);return o%2===0&&(o-=1),o=Math.max(o,1),Math.min((o-1)*t,e)}const R=typeof window>"u"?c.useEffect:c.useLayoutEffect;function w(e,t){if(typeof e=="function"){e(t);return}e&&(e.current=t)}function N(e){const t=window.getComputedStyle(e),n=Number.parseFloat(t.paddingLeft)+Number.parseFloat(t.paddingRight);return Math.max(e.clientWidth-n,0)}function P(e){const n=window.getComputedStyle(e).getPropertyValue("--nk-cell").trim().match(/^([+]?(?:\d+\.?\d*|\.\d+))px$/i);if(!n)return;const r=Number.parseFloat(n[1]);return Number.isFinite(r)&&r>0?r:void 0}function S(e,t){const n=c.useRef(null),r=c.useRef(null),s=c.useRef(void 0),[m,a]=c.useState(void 0),o=c.useCallback(i=>{if(!t){if(s.current===void 0)return;s.current=void 0,a(void 0);return}const u=N(i),d=P(i),h=d===void 0?void 0:k(u,d);s.current!==h&&(s.current=h,a(h))},[t]),f=c.useCallback(i=>{var d;if((d=r.current)==null||d.disconnect(),r.current=null,typeof ResizeObserver>"u")return;const u=new ResizeObserver(()=>o(i));u.observe(i),r.current=u},[o]),g=c.useCallback(i=>{var u;(u=r.current)==null||u.disconnect(),r.current=null,n.current=i,w(e,i),!(!i||typeof window>"u"||!t)&&(o(i),f(i))},[f,t,e,o]);return R(()=>{n.current&&o(n.current)}),c.useEffect(()=>(n.current&&t&&f(n.current),()=>{var i;(i=r.current)==null||i.disconnect(),r.current=null}),[f,t]),{rootReference:g,innerWidth:m}}const x=c.forwardRef(function(t,n){const{accent:r,as:s,children:m,className:a,constrain:o=!0,minHeight:f="auto",mode:g="grid",spacing:i="standard",style:u,theme:d="light",...h}=t,{rootReference:v,innerWidth:p}=S(n,o),b=s??"div",y=r!==void 0?{...u,"--nk-accent":r}:u;return c.createElement(b,{...h,ref:v,className:["nk-content",a].filter(Boolean).join(" "),"data-constrain":o,"data-min-height":f,"data-mode":g,"data-spacing":i,"data-theme":d,style:y},c.createElement("div",{className:"nk-content__inner",style:p===void 0?void 0:{width:`${p}px`}},m))});exports.default=x;
1
+ "use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("react"),l=require("./units-PzuiQNnw.cjs"),C=[{minWidth:l.breakpoint("xl"),marginPercent:32,preferredWidth:1200},{minWidth:l.breakpoint("lg"),marginPercent:20,preferredWidth:1100},{minWidth:l.breakpoint("md"),marginPercent:14,preferredWidth:l.breakpoint("md")},{minWidth:l.breakpoint("sm"),marginPercent:8,preferredWidth:650}],w=16;function W(e){for(const t of C)if(e>=t.minWidth)return t}function M(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<l.breakpoint("sm")||t<=0)return;const r=W(e);if(!r)return;const i=e*r.marginPercent/100,s=e-i*2,h=Math.min(r.preferredWidth,e-w),d=Math.max(s,h);let o=Math.floor(d/t);return o%2===0&&(o-=1),o=Math.max(o,1),Math.min((o-1)*t,e)}const k=typeof window>"u"?c.useEffect:c.useLayoutEffect;function R(e,t){if(typeof e=="function"){e(t);return}e&&(e.current=t)}function N(e){const t=window.getComputedStyle(e),r=Number.parseFloat(t.paddingLeft)+Number.parseFloat(t.paddingRight);return Math.max(e.clientWidth-r,0)}function P(e){const r=window.getComputedStyle(e).getPropertyValue("--nk-cell").trim().match(/^([+]?(?:\d+\.?\d*|\.\d+))px$/i);if(!r)return;const i=Number.parseFloat(r[1]);return Number.isFinite(i)&&i>0?i:void 0}function S(e,t){const r=c.useRef(null),i=c.useRef(null),s=c.useRef(void 0),[h,d]=c.useState(void 0),o=c.useCallback(n=>{if(!t){if(s.current===void 0)return;s.current=void 0,d(void 0);return}const u=N(n),f=P(n),m=f===void 0?void 0:M(u,f);s.current!==m&&(s.current=m,d(m))},[t]),a=c.useCallback(n=>{var f;if((f=i.current)==null||f.disconnect(),i.current=null,typeof ResizeObserver>"u")return;const u=new ResizeObserver(()=>o(n));u.observe(n),i.current=u},[o]),g=c.useCallback(n=>{var u;(u=i.current)==null||u.disconnect(),i.current=null,r.current=n,R(e,n),!(!n||typeof window>"u"||!t)&&(o(n),a(n))},[a,e,o,t]);return k(()=>{r.current&&o(r.current)}),c.useEffect(()=>(r.current&&t&&a(r.current),()=>{var n;(n=i.current)==null||n.disconnect(),i.current=null}),[a,t]),{rootReference:g,innerWidth:h}}const x=c.forwardRef(function(t,r){const{as:i,children:s,className:h,style:d,theme:o="light",accent:a,mode:g="grid",width:n="narrow",height:u="content",spacing:f="standard",...m}=t,{rootReference:v,innerWidth:p}=S(r,n==="narrow"),b=i??"div",y=a!==void 0?{...d,"--nk-accent":a}:d;return c.createElement(b,{...m,ref:v,className:["nk-content",h].filter(Boolean).join(" "),"data-theme":o,"data-mode":g,"data-width":n,"data-height":u,"data-spacing":f,style:y},c.createElement("div",{className:"nk-content__inner",style:p===void 0?void 0:{width:`${p}px`}},s))});exports.default=x;
package/dist/Content.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { useRef as g, useState as b, useCallback as p, useEffect as C, useLayoutEffect as N, forwardRef as R, createElement as y } from "react";
2
+ import { useRef as g, useState as b, useCallback as p, useEffect as w, useLayoutEffect as N, forwardRef as R, createElement as y } from "react";
3
3
  import { b as f } from "./units-BmjPCccF.js";
4
4
  const x = [
5
5
  {
@@ -23,109 +23,109 @@ const x = [
23
23
  preferredWidth: 650
24
24
  }
25
25
  ], P = 16;
26
- function F(e) {
27
- for (const t of x)
28
- if (e >= t.minWidth) return t;
26
+ function F(t) {
27
+ for (const e of x)
28
+ if (t >= e.minWidth) return e;
29
29
  }
30
- function L(e, t) {
31
- if (!Number.isFinite(e) || !Number.isFinite(t) || e < f("sm") || t <= 0)
30
+ function L(t, e) {
31
+ if (!Number.isFinite(t) || !Number.isFinite(e) || t < f("sm") || e <= 0)
32
32
  return;
33
- const n = F(e);
34
- if (!n) return;
35
- const r = e * n.marginPercent / 100, u = e - r * 2, m = Math.min(
36
- n.preferredWidth,
37
- e - P
33
+ const r = F(t);
34
+ if (!r) return;
35
+ const i = t * r.marginPercent / 100, u = t - i * 2, m = Math.min(
36
+ r.preferredWidth,
37
+ t - P
38
38
  ), d = Math.max(u, m);
39
- let o = Math.floor(d / t);
40
- return o % 2 === 0 && (o -= 1), o = Math.max(o, 1), Math.min((o - 1) * t, e);
39
+ let o = Math.floor(d / e);
40
+ return o % 2 === 0 && (o -= 1), o = Math.max(o, 1), Math.min((o - 1) * e, t);
41
41
  }
42
- const S = typeof window > "u" ? C : N;
43
- function k(e, t) {
44
- if (typeof e == "function") {
45
- e(t);
42
+ const S = typeof window > "u" ? w : N;
43
+ function k(t, e) {
44
+ if (typeof t == "function") {
45
+ t(e);
46
46
  return;
47
47
  }
48
- e && (e.current = t);
48
+ t && (t.current = e);
49
49
  }
50
- function z(e) {
51
- const t = window.getComputedStyle(e), n = Number.parseFloat(t.paddingLeft) + Number.parseFloat(t.paddingRight);
52
- return Math.max(e.clientWidth - n, 0);
50
+ function z(t) {
51
+ const e = window.getComputedStyle(t), r = Number.parseFloat(e.paddingLeft) + Number.parseFloat(e.paddingRight);
52
+ return Math.max(t.clientWidth - r, 0);
53
53
  }
54
- function I(e) {
55
- const n = window.getComputedStyle(e).getPropertyValue("--nk-cell").trim().match(
54
+ function I(t) {
55
+ const r = window.getComputedStyle(t).getPropertyValue("--nk-cell").trim().match(
56
56
  /^([+]?(?:\d+\.?\d*|\.\d+))px$/i
57
57
  );
58
- if (!n) return;
59
- const r = Number.parseFloat(n[1]);
60
- return Number.isFinite(r) && r > 0 ? r : void 0;
58
+ if (!r) return;
59
+ const i = Number.parseFloat(r[1]);
60
+ return Number.isFinite(i) && i > 0 ? i : void 0;
61
61
  }
62
- function O(e, t) {
63
- const n = g(null), r = g(null), u = g(void 0), [m, d] = b(void 0), o = p((i) => {
64
- if (!t) {
62
+ function O(t, e) {
63
+ const r = g(null), i = g(null), u = g(void 0), [m, d] = b(void 0), o = p((n) => {
64
+ if (!e) {
65
65
  if (u.current === void 0) return;
66
66
  u.current = void 0, d(void 0);
67
67
  return;
68
68
  }
69
- const c = z(i), s = I(i), l = s === void 0 ? void 0 : L(c, s);
70
- u.current !== l && (u.current = l, d(l));
71
- }, [t]), a = p(
72
- (i) => {
73
- var s;
74
- if ((s = r.current) == null || s.disconnect(), r.current = null, typeof ResizeObserver > "u") return;
69
+ const c = z(n), a = I(n), h = a === void 0 ? void 0 : L(c, a);
70
+ u.current !== h && (u.current = h, d(h));
71
+ }, [e]), s = p(
72
+ (n) => {
73
+ var a;
74
+ if ((a = i.current) == null || a.disconnect(), i.current = null, typeof ResizeObserver > "u") return;
75
75
  const c = new ResizeObserver(
76
- () => o(i)
76
+ () => o(n)
77
77
  );
78
- c.observe(i), r.current = c;
78
+ c.observe(n), i.current = c;
79
79
  },
80
80
  [o]
81
- ), h = p(
82
- (i) => {
81
+ ), l = p(
82
+ (n) => {
83
83
  var c;
84
- (c = r.current) == null || c.disconnect(), r.current = null, n.current = i, k(e, i), !(!i || typeof window > "u" || !t) && (o(i), a(i));
84
+ (c = i.current) == null || c.disconnect(), i.current = null, r.current = n, k(t, n), !(!n || typeof window > "u" || !e) && (o(n), s(n));
85
85
  },
86
86
  [
87
- a,
87
+ s,
88
88
  t,
89
- e,
90
- o
89
+ o,
90
+ e
91
91
  ]
92
92
  );
93
93
  return S(() => {
94
- n.current && o(n.current);
95
- }), C(() => (n.current && t && a(n.current), () => {
96
- var i;
97
- (i = r.current) == null || i.disconnect(), r.current = null;
98
- }), [a, t]), { rootReference: h, innerWidth: m };
94
+ r.current && o(r.current);
95
+ }), w(() => (r.current && e && s(r.current), () => {
96
+ var n;
97
+ (n = i.current) == null || n.disconnect(), i.current = null;
98
+ }), [s, e]), { rootReference: l, innerWidth: m };
99
99
  }
100
100
  const A = R(
101
- function(t, n) {
101
+ function(e, r) {
102
102
  const {
103
- accent: r,
104
- as: u,
105
- children: m,
106
- className: d,
107
- constrain: o = !0,
108
- minHeight: a = "auto",
109
- mode: h = "grid",
110
- spacing: i = "standard",
111
- style: c,
112
- theme: s = "light",
113
- ...l
114
- } = t, { rootReference: W, innerWidth: v } = O(
115
- n,
116
- o
117
- ), w = u ?? "div", M = r !== void 0 ? { ...c, "--nk-accent": r } : c;
103
+ as: i,
104
+ children: u,
105
+ className: m,
106
+ style: d,
107
+ theme: o = "light",
108
+ accent: s,
109
+ mode: l = "grid",
110
+ width: n = "narrow",
111
+ height: c = "content",
112
+ spacing: a = "standard",
113
+ ...h
114
+ } = e, { rootReference: C, innerWidth: v } = O(
115
+ r,
116
+ n === "narrow"
117
+ ), W = i ?? "div", M = s !== void 0 ? { ...d, "--nk-accent": s } : d;
118
118
  return y(
119
- w,
119
+ W,
120
120
  {
121
- ...l,
122
- ref: W,
123
- className: ["nk-content", d].filter(Boolean).join(" "),
124
- "data-constrain": o,
125
- "data-min-height": a,
126
- "data-mode": h,
127
- "data-spacing": i,
128
- "data-theme": s,
121
+ ...h,
122
+ ref: C,
123
+ className: ["nk-content", m].filter(Boolean).join(" "),
124
+ "data-theme": o,
125
+ "data-mode": l,
126
+ "data-width": n,
127
+ "data-height": c,
128
+ "data-spacing": a,
129
129
  style: M
130
130
  },
131
131
  y(
@@ -134,7 +134,7 @@ const A = R(
134
134
  className: "nk-content__inner",
135
135
  style: v === void 0 ? void 0 : { width: `${v}px` }
136
136
  },
137
- m
137
+ u
138
138
  )
139
139
  );
140
140
  }
@@ -4,9 +4,11 @@ import "./styles/content.css";
4
4
  export type ContentTheme = "light" | "dark";
5
5
  /** A type representing Content's visual background modes. */
6
6
  export type ContentMode = "grid" | "none";
7
+ /** A type representing Content's horizontal layout behavior. */
8
+ export type ContentWidth = "narrow" | "full";
7
9
  /** A type representing Content's minimum-height behavior. */
8
- export type ContentMinHeight = "auto" | "available" | "viewport";
9
- /** A type representing Content's vertical spacing behavior. */
10
+ export type ContentHeight = "content" | "available" | "viewport";
11
+ /** A type representing Content's spacing behavior on both axes. */
10
12
  export type ContentSpacing = "standard" | "none";
11
13
  /** A type representing CSS custom properties accepted by Content styles. */
12
14
  type ContentCustomProperties = {
@@ -24,12 +26,12 @@ type ContentOwnProps = {
24
26
  accent?: string;
25
27
  /** The visual background treatment applied to Content. */
26
28
  mode?: ContentMode;
29
+ /** The horizontal layout applied to Content. */
30
+ width?: ContentWidth;
27
31
  /** The minimum height applied to Content. */
28
- minHeight?: ContentMinHeight;
29
- /** The vertical spacing applied within Content. */
32
+ height?: ContentHeight;
33
+ /** The spacing applied around content within Content. */
30
34
  spacing?: ContentSpacing;
31
- /** Whether Content applies its responsive cell-aligned inner width. */
32
- constrain?: boolean;
33
35
  };
34
36
  /** A type representing properties for a polymorphic Content element. */
35
37
  export type ContentProps<Component extends ElementType = "div"> = ContentOwnProps & {
@@ -10,9 +10,9 @@ type ContentLayout = {
10
10
  * Measures a Content root and progressively enhances its inner width.
11
11
  *
12
12
  * @param forwardedReference - The public reference assigned to the root.
13
- * @param constrain - Whether responsive inner-width sizing is enabled.
13
+ * @param snap - Whether cell-aligned inner-width sizing is enabled.
14
14
  *
15
15
  * @returns The merged root reference and calculated inner width.
16
16
  */
17
- export declare function useContentLayout(forwardedReference: ForwardedRef<HTMLElement>, constrain: boolean): ContentLayout;
17
+ export declare function useContentLayout(forwardedReference: ForwardedRef<HTMLElement>, snap: boolean): ContentLayout;
18
18
  export {};
@@ -1,2 +1,2 @@
1
1
  export { default } from "./Content";
2
- export type { ContentMinHeight, ContentMode, ContentProps, ContentSpacing, ContentTheme, } from "./Content";
2
+ export type { ContentHeight, ContentMode, ContentProps, ContentSpacing, ContentTheme, ContentWidth, } from "./Content";