@kapiuara/ui 0.7.0 → 0.9.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.
Files changed (38) hide show
  1. package/README.md +100 -3
  2. package/dist/components/data/KapiPagination.d.ts +13 -4
  3. package/dist/components/data/KapiPagination.js +31 -88
  4. package/dist/components/data/KapiPaginationFooter.d.ts +35 -0
  5. package/dist/components/data/KapiPaginationFooter.js +106 -0
  6. package/dist/components/data/KapiTable.d.ts +71 -4
  7. package/dist/components/data/KapiTable.js +421 -439
  8. package/dist/components/data/datasetSelectionLogic.d.ts +22 -0
  9. package/dist/components/data/datasetSelectionLogic.js +5 -0
  10. package/dist/components/data/index.d.ts +2 -1
  11. package/dist/components/display/KapiTruncate.d.ts +32 -0
  12. package/dist/components/display/KapiTruncate.js +43 -0
  13. package/dist/components/display/index.d.ts +3 -0
  14. package/dist/components/display/truncateLogic.d.ts +6 -0
  15. package/dist/components/display/truncateLogic.js +4 -0
  16. package/dist/components/inputs/KapiSegmented.d.ts +7 -1
  17. package/dist/components/inputs/KapiSegmented.js +1 -0
  18. package/dist/components/layout/KapiContextSlot.d.ts +34 -6
  19. package/dist/components/layout/KapiContextSlot.js +115 -71
  20. package/dist/components/layout/KapiPageHeader.js +49 -24
  21. package/dist/components/layout/KapiShell.d.ts +19 -3
  22. package/dist/components/layout/KapiShell.js +20 -19
  23. package/dist/components/layout/pageHeaderLogic.d.ts +13 -0
  24. package/dist/components/layout/pageHeaderLogic.js +4 -0
  25. package/dist/components/navigation/panelMiniLogic.d.ts +10 -1
  26. package/dist/components/navigation/panelMiniLogic.js +2 -2
  27. package/dist/components/overlays/KapiOffcanvas.js +124 -118
  28. package/dist/hooks/index.d.ts +1 -1
  29. package/dist/hooks/themeDeriveLogic.d.ts +15 -0
  30. package/dist/hooks/themeDeriveLogic.js +54 -32
  31. package/dist/hooks/themeRadiiLogic.d.ts +11 -0
  32. package/dist/hooks/themeRadiiLogic.js +31 -0
  33. package/dist/hooks/useKapiTheme.d.ts +10 -3
  34. package/dist/hooks/useKapiTheme.js +66 -57
  35. package/dist/index.js +111 -108
  36. package/dist/kapi.css +1 -1
  37. package/dist/kapi.layered.css +1 -1
  38. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Lógica pura de la reserva de alto del `KapiPageHeader`.
3
+ *
4
+ * Al colapsar, el header pierde alto y ese alto sale del flujo del documento: el rango de
5
+ * scroll se achica y el navegador recorta la posición (el "salto"). Un espaciador que devuelve
6
+ * exactamente lo perdido mantiene constante el largo total.
7
+ */
8
+ /**
9
+ * Alto del espaciador: lo que el header perdió respecto de su alto expandido.
10
+ * Nunca negativo: si el actual iguala o supera al expandido (o no hay layout, como en jsdom,
11
+ * donde todo mide 0), no hay nada que devolver.
12
+ */
13
+ export declare const pageHeaderSpacerHeight: (expanded: number, current: number) => number;
@@ -0,0 +1,4 @@
1
+ //#region src/components/layout/pageHeaderLogic.ts
2
+ var e = (e) => Number.isFinite(e) && e > 0 ? e : 0, t = (t, n) => Math.max(0, e(t) - e(n));
3
+ //#endregion
4
+ export { t as pageHeaderSpacerHeight };
@@ -3,7 +3,16 @@ import { type ReactNode } from "react";
3
3
  export type KapiPanelCollapsedMode = "hidden" | "mini";
4
4
  /** El panel se dibuja en mini sólo plegado, con `collapsedMode="mini"` y fuera de móvil (ahí es un drawer). */
5
5
  export declare const resolveMini: ({ collapsedMode, open, mobile }: {
6
- collapsedMode?: KapiPanelCollapsedMode | undefined;
6
+ collapsedMode?: KapiPanelCollapsedMode | "none" | undefined;
7
+ open: boolean;
8
+ mobile: boolean;
9
+ }) => boolean;
10
+ /**
11
+ * El panel no deja nada al plegar (ni tira ni botón de reabrir) sólo con `collapsedMode="none"`, plegado y fuera
12
+ * de móvil: en móvil es un drawer y su botón de abrir sigue ahí, igual que con `hidden` y `mini`.
13
+ */
14
+ export declare const resolveGone: ({ collapsedMode, open, mobile }: {
15
+ collapsedMode?: KapiPanelCollapsedMode | "none" | undefined;
7
16
  open: boolean;
8
17
  mobile: boolean;
9
18
  }) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { isValidElement as e } from "react";
3
3
  //#region src/components/navigation/panelMiniLogic.ts
4
- var t = ({ collapsedMode: e = "hidden", open: t, mobile: n }) => e === "mini" && !t && !n, n = (t) => t == null || typeof t == "boolean" ? "" : typeof t == "string" || typeof t == "number" ? String(t) : Array.isArray(t) ? t.map(n).join("") : e(t) ? n(t.props.children) : "", r = (e) => e.match(/[\p{L}\p{N}]/u)?.[0]?.toUpperCase() ?? "", i = (e, t) => t === null ? e : `${e} · ${t}`;
4
+ var t = ({ collapsedMode: e = "hidden", open: t, mobile: n }) => e === "mini" && !t && !n, n = ({ collapsedMode: e = "hidden", open: t, mobile: n }) => e === "none" && !t && !n, r = (t) => t == null || typeof t == "boolean" ? "" : typeof t == "string" || typeof t == "number" ? String(t) : Array.isArray(t) ? t.map(r).join("") : e(t) ? r(t.props.children) : "", i = (e) => e.match(/[\p{L}\p{N}]/u)?.[0]?.toUpperCase() ?? "", a = (e, t) => t === null ? e : `${e} · ${t}`;
5
5
  //#endregion
6
- export { r as miniInitial, i as miniTooltipLabel, n as nodeText, t as resolveMini };
6
+ export { i as miniInitial, a as miniTooltipLabel, r as nodeText, n as resolveGone, t as resolveMini };
@@ -2,202 +2,208 @@
2
2
  import { useLabels as e } from "../locale/KapiLocaleProvider.js";
3
3
  import { joinClasses as t } from "../rootProps.js";
4
4
  import { maxTransitionMs as n } from "./dialogUtils.js";
5
- import { getPortalRoot as r, useBackdropClose as i, useNativeDialog as a } from "./useNativeDialog.js";
6
- import { DEFAULT_PUSH_RATIO as o, depthOf as s, levelOf as c, offcanvasStackStore as l, phaseReducer as u, pushTransform as ee } from "./offcanvasStack.js";
7
- import { normalizeSide as te, pushForSide as ne, sideDataAttr as d, sizeVar as re } from "./offcanvasSide.js";
8
- import { companionDockClasses as ie, isCompanionActive as ae, resolveCompanionOrder as oe, resolveCompanionWidth as se } from "./offcanvasCompanion.js";
9
- import { resolveInitialWidth as ce, resolveMaxWidth as f, stepOffcanvasWidth as le, widthFromDrag as ue } from "./offcanvasResize.js";
5
+ import { useExitPresence as r } from "./useExitPresence.js";
6
+ import { getPortalRoot as i, useBackdropClose as a, useNativeDialog as o } from "./useNativeDialog.js";
7
+ import { DEFAULT_PUSH_RATIO as s, depthOf as c, levelOf as ee, offcanvasStackStore as l, phaseReducer as u, pushTransform as te } from "./offcanvasStack.js";
8
+ import { normalizeSide as ne, pushForSide as re, sideDataAttr as ie, sizeVar as ae } from "./offcanvasSide.js";
9
+ import { companionDockClasses as oe, isCompanionActive as se, resolveCompanionOrder as ce, resolveCompanionWidth as le, supportsCompanion as ue } from "./offcanvasCompanion.js";
10
+ import { resolveInitialWidth as de, resolveMaxWidth as d, stepOffcanvasWidth as fe, widthFromDrag as pe } from "./offcanvasResize.js";
10
11
  /* empty css */
11
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
12
- import { useEffect as de, useId as h, useLayoutEffect as g, useReducer as _, useRef as v, useState as y, useSyncExternalStore as fe } from "react";
13
- import { X as b } from "lucide-react";
14
- import { createPortal as x } from "react-dom";
15
- var pe = 120, S = {
12
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
13
+ import { useEffect as me, useId as m, useLayoutEffect as h, useReducer as g, useRef as _, useState as v, useSyncExternalStore as he } from "react";
14
+ import { X as y } from "lucide-react";
15
+ import { createPortal as b } from "react-dom";
16
+ var ge = 120, x = {
16
17
  resize: "Redimensionar panel",
17
18
  close: "Cerrar",
18
19
  closePanel: "Cerrar panel"
19
- }, C = ({ stackId: r, phase: u, onEntered: _, onExited: x, onClose: C, title: w, subtitle: T, children: me, footer: E, side: he, width: D = 520, height: ge, pushRatio: _e = o, pushOffset: ve = 16, closeOnBackdrop: ye = !0, closeOnEscape: be = !0, closeLabel: xe, labels: Se, className: Ce, style: O, id: k, companion: A, resizable: we = !1, minWidth: j = 320, maxWidth: M, onResize: N }) => {
20
- let P = e("offcanvas", S, Se), Te = xe ?? P.close, F = h(), I = h(), L = te(he), R = v(null), z = fe(l.subscribe, l.getSnapshot, l.getServerSnapshot), B = s(z, r), Ee = Math.max(0, c(z, r)), { scale: De, translateX: Oe } = ne(L, ee(B, _e, ve)), [V, ke] = y(() => ce(D, 520)), [Ae, H] = y(!1), U = v(null), W = v(N);
21
- W.current = N;
22
- let G = (e) => {
23
- ke(e), e !== V && W.current?.(e);
24
- }, je = (e) => {
20
+ }, S = ({ stackId: i, phase: u, onEntered: g, onExited: b, onClose: S, title: C, subtitle: w, children: _e, footer: T, side: ve, width: E = 520, height: ye, pushRatio: be = s, pushOffset: xe = 16, closeOnBackdrop: Se = !0, closeOnEscape: Ce = !0, closeLabel: we, labels: Te, className: Ee, style: De, id: Oe, companion: D, resizable: ke = !1, minWidth: O = 320, maxWidth: k, onResize: A }) => {
21
+ let j = e("offcanvas", x, Te), Ae = we ?? j.close, M = m(), N = m(), P = ne(ve), F = _(null), I = he(l.subscribe, l.getSnapshot, l.getServerSnapshot), L = c(I, i), je = Math.max(0, ee(I, i)), { scale: Me, translateX: Ne } = re(P, te(L, be, xe)), [R, Pe] = v(() => de(E, 520)), [Fe, z] = v(!1), B = _(null), V = _(A);
22
+ V.current = A;
23
+ let H = (e) => {
24
+ Pe(e), e !== R && V.current?.(e);
25
+ }, Ie = (e) => {
25
26
  if (e.button !== 0) return;
26
- let t = R.current?.offsetWidth ?? V;
27
- U.current = {
27
+ let t = F.current?.offsetWidth ?? R;
28
+ B.current = {
28
29
  startX: e.clientX,
29
30
  startWidth: t
30
- }, e.currentTarget.setPointerCapture(e.pointerId), H(!0), e.preventDefault();
31
- }, Me = (e) => {
32
- let t = U.current;
31
+ }, e.currentTarget.setPointerCapture(e.pointerId), z(!0), e.preventDefault();
32
+ }, Le = (e) => {
33
+ let t = B.current;
33
34
  if (!t) return;
34
- let n = f(M, window.innerWidth);
35
- G(ue(L, t.startWidth, t.startX, e.clientX, j, n));
36
- }, K = (e) => {
37
- U.current = null, e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), H(!1);
38
- }, Ne = (e) => {
39
- let t = f(M, window.innerWidth), n = le(L, V, e.key, j, t);
40
- n !== null && (e.preventDefault(), e.stopPropagation(), G(n));
41
- }, q = u === "open" ? C : void 0, { ref: Pe, dialogProps: Fe } = a({ onRequestClose: be ? q : void 0 }), J = i(ye ? q : void 0);
42
- g(() => (l.dispatch({
35
+ let n = d(k, window.innerWidth);
36
+ H(pe(P, t.startWidth, t.startX, e.clientX, O, n));
37
+ }, U = (e) => {
38
+ B.current = null, e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), z(!1);
39
+ }, Re = (e) => {
40
+ let t = d(k, window.innerWidth), n = fe(P, R, e.key, O, t);
41
+ n !== null && (e.preventDefault(), e.stopPropagation(), H(n));
42
+ }, W = u === "open" ? S : void 0, { ref: ze, dialogProps: Be } = o({ onRequestClose: Ce ? W : void 0 }), Ve = a(Se ? W : void 0);
43
+ h(() => (l.dispatch({
43
44
  type: "add",
44
- id: r
45
+ id: i
45
46
  }), () => l.dispatch({
46
47
  type: "remove",
47
- id: r
48
- })), [r]);
49
- let Y = v(_);
50
- Y.current = _, g(() => {
51
- R.current?.getBoundingClientRect(), Y.current();
48
+ id: i
49
+ })), [i]);
50
+ let G = _(g);
51
+ G.current = g, h(() => {
52
+ F.current?.getBoundingClientRect(), G.current();
52
53
  }, []);
53
- let X = v(x);
54
- X.current = x, de(() => {
54
+ let K = _(b);
55
+ K.current = b, me(() => {
55
56
  if (u !== "exit") return;
56
- let e = R.current;
57
+ let e = F.current;
57
58
  if (!e) {
58
- X.current();
59
+ K.current();
59
60
  return;
60
61
  }
61
62
  let t = getComputedStyle(e), r = n(t.transitionDuration, t.transitionDelay);
62
63
  if (r <= 0) {
63
- X.current();
64
+ K.current();
64
65
  return;
65
66
  }
66
67
  let i = !1, a = () => {
67
- i || (i = !0, X.current());
68
+ i || (i = !0, K.current());
68
69
  }, o = (t) => {
69
70
  t.target === e && t.propertyName === "transform" && a();
70
71
  };
71
72
  e.addEventListener("transitionend", o);
72
- let s = window.setTimeout(a, r + pe);
73
+ let s = window.setTimeout(a, r + ge);
73
74
  return () => {
74
75
  i = !0, e.removeEventListener("transitionend", o), window.clearTimeout(s);
75
76
  };
76
77
  }, [u]);
77
- let Z = we && (L === "left" || L === "right"), Q = re(L, D, ge, "520px");
78
- Z && (Q.value = `${V}px`);
79
- let Ie = {
80
- ...O,
81
- [Q.name]: Q.value,
82
- "--kapi-offc-push-x": `${Oe}px`,
83
- "--kapi-offc-push-s": De
84
- }, $ = ae(L, A), Le = /* @__PURE__ */ m("div", {
85
- ref: R,
78
+ let q = ke && (P === "left" || P === "right"), J = ae(P, E, ye, "520px");
79
+ q && (J.value = `${R}px`);
80
+ let He = {
81
+ ...De,
82
+ [J.name]: J.value,
83
+ "--kapi-offc-push-x": `${Ne}px`,
84
+ "--kapi-offc-push-s": Me
85
+ }, Ue = se(P, D), Y = _(null), { present: We, closing: X } = r(Ue, Y), Z = _(D);
86
+ D && (Z.current = D);
87
+ let Q = D ?? Z.current, $ = We && ue(P) && Q !== void 0, Ge = /* @__PURE__ */ p("div", {
88
+ ref: F,
86
89
  className: "kapi-offc__panel",
87
90
  children: [
88
- Z && /* @__PURE__ */ p("div", {
91
+ q && /* @__PURE__ */ f("div", {
89
92
  className: "kapi-offc__resize",
90
93
  role: "separator",
91
94
  "aria-orientation": "vertical",
92
- "aria-label": P.resize,
93
- "aria-valuemin": j,
94
- "aria-valuemax": f(M, typeof window > "u" ? void 0 : window.innerWidth),
95
- "aria-valuenow": V,
95
+ "aria-label": j.resize,
96
+ "aria-valuemin": O,
97
+ "aria-valuemax": d(k, typeof window > "u" ? void 0 : window.innerWidth),
98
+ "aria-valuenow": R,
96
99
  tabIndex: 0,
97
- onPointerDown: je,
98
- onPointerMove: Me,
99
- onPointerUp: K,
100
- onPointerCancel: K,
101
- onKeyDown: Ne
100
+ onPointerDown: Ie,
101
+ onPointerMove: Le,
102
+ onPointerUp: U,
103
+ onPointerCancel: U,
104
+ onKeyDown: Re
102
105
  }),
103
- /* @__PURE__ */ m("div", {
106
+ /* @__PURE__ */ p("div", {
104
107
  className: "kapi-offc__head",
105
- children: [/* @__PURE__ */ m("div", { children: [/* @__PURE__ */ p("div", {
106
- id: F,
108
+ children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("div", {
109
+ id: M,
107
110
  className: "kapi-modal__title",
108
- children: w
109
- }), T && /* @__PURE__ */ p("div", {
111
+ children: C
112
+ }), w && /* @__PURE__ */ f("div", {
110
113
  className: "kapi-modal__sub",
111
- children: T
112
- })] }), /* @__PURE__ */ p("button", {
114
+ children: w
115
+ })] }), /* @__PURE__ */ f("button", {
113
116
  type: "button",
114
117
  className: "kapi-modal__x",
115
- onClick: q,
116
- "aria-label": Te,
117
- children: /* @__PURE__ */ p(b, {
118
+ onClick: W,
119
+ "aria-label": Ae,
120
+ children: /* @__PURE__ */ f(y, {
118
121
  size: 17,
119
122
  strokeWidth: 2.2
120
123
  })
121
124
  })]
122
125
  }),
123
- /* @__PURE__ */ p("div", {
126
+ /* @__PURE__ */ f("div", {
124
127
  className: "kapi-offc__body",
125
- children: me
128
+ children: _e
126
129
  }),
127
- E && /* @__PURE__ */ p("div", {
130
+ T && /* @__PURE__ */ f("div", {
128
131
  className: "kapi-offc__foot",
129
- children: E
132
+ children: T
130
133
  })
131
134
  ]
132
- }, "main"), Re = A && $ ? /* @__PURE__ */ m("div", {
135
+ }, "main"), Ke = Q && $ ? /* @__PURE__ */ p("div", {
136
+ ref: Y,
137
+ "data-closing": X || void 0,
138
+ inert: X || void 0,
133
139
  className: "kapi-offc__panel kapi-offc__companion",
134
140
  role: "complementary",
135
- "aria-labelledby": A.title ? I : void 0,
136
- style: { "--kapi-offc-companion-w": se(A.width) },
141
+ "aria-labelledby": Q.title ? N : void 0,
142
+ style: { "--kapi-offc-companion-w": le(Q.width) },
137
143
  children: [
138
- (A.title || A.onClose) && /* @__PURE__ */ m("div", {
144
+ (Q.title || Q.onClose) && /* @__PURE__ */ p("div", {
139
145
  className: "kapi-offc__head",
140
- children: [/* @__PURE__ */ m("div", { children: [/* @__PURE__ */ p("div", {
141
- id: I,
146
+ children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("div", {
147
+ id: N,
142
148
  className: "kapi-modal__title",
143
- children: A.title
144
- }), A.subtitle && /* @__PURE__ */ p("div", {
149
+ children: Q.title
150
+ }), Q.subtitle && /* @__PURE__ */ f("div", {
145
151
  className: "kapi-modal__sub",
146
- children: A.subtitle
147
- })] }), A.onClose && /* @__PURE__ */ p("button", {
152
+ children: Q.subtitle
153
+ })] }), Q.onClose && /* @__PURE__ */ f("button", {
148
154
  type: "button",
149
155
  className: "kapi-modal__x",
150
- onClick: A.onClose,
151
- "aria-label": A.closeLabel ?? P.closePanel,
152
- children: /* @__PURE__ */ p(b, {
156
+ onClick: Q.onClose,
157
+ "aria-label": Q.closeLabel ?? j.closePanel,
158
+ children: /* @__PURE__ */ f(y, {
153
159
  size: 17,
154
160
  strokeWidth: 2.2
155
161
  })
156
162
  })]
157
163
  }),
158
- /* @__PURE__ */ p("div", {
164
+ /* @__PURE__ */ f("div", {
159
165
  className: "kapi-offc__body",
160
- children: A.children
166
+ children: Q.children
161
167
  }),
162
- A.footer && /* @__PURE__ */ p("div", {
168
+ Q.footer && /* @__PURE__ */ f("div", {
163
169
  className: "kapi-offc__foot",
164
- children: A.footer
170
+ children: Q.footer
165
171
  })
166
172
  ]
167
- }, "companion") : null, ze = oe(L).map((e) => e === "main" ? Le : Re).filter((e) => e !== null);
168
- return /* @__PURE__ */ p("dialog", {
169
- ref: Pe,
170
- id: k,
171
- className: t("kapi-offc", Ae && "is-resizing", Ce),
172
- "data-side": d(L),
173
+ }, "companion") : null, qe = ce(P).map((e) => e === "main" ? Ge : Ke).filter((e) => e !== null);
174
+ return /* @__PURE__ */ f("dialog", {
175
+ ref: ze,
176
+ id: Oe,
177
+ className: t("kapi-offc", Fe && "is-resizing", Ee),
178
+ "data-side": ie(P),
173
179
  "data-state": u === "open" ? "open" : "closed",
174
- "data-level": Ee,
175
- "data-pushed": B > 0 ? "" : void 0,
180
+ "data-level": je,
181
+ "data-pushed": L > 0 ? "" : void 0,
176
182
  "aria-modal": "true",
177
- "aria-labelledby": F,
178
- style: Ie,
179
- ...Fe,
180
- ...J,
181
- children: /* @__PURE__ */ p("div", {
182
- className: ie($),
183
- children: ze
183
+ "aria-labelledby": M,
184
+ style: He,
185
+ ...Be,
186
+ ...Ve,
187
+ children: /* @__PURE__ */ f("div", {
188
+ className: oe($),
189
+ children: qe
184
190
  })
185
191
  });
186
- }, w = ({ open: e, onExited: t, ...n }) => {
187
- let i = h(), [a, o] = _(u, "unmounted"), s = v(t);
188
- s.current = t, g(() => {
192
+ }, C = ({ open: e, onExited: t, ...n }) => {
193
+ let r = m(), [a, o] = g(u, "unmounted"), s = _(t);
194
+ s.current = t, h(() => {
189
195
  o(e ? "open" : "close");
190
- }, [e]), g(() => {
196
+ }, [e]), h(() => {
191
197
  (a === "exit" || a === "open") && l.dispatch({
192
198
  type: "mark",
193
- id: i,
199
+ id: r,
194
200
  state: a === "exit" ? "closing" : "open"
195
201
  });
196
- }, [a, i]);
197
- let c = r();
198
- return a === "unmounted" || !c ? null : x(/* @__PURE__ */ p(C, {
202
+ }, [a, r]);
203
+ let c = i();
204
+ return a === "unmounted" || !c ? null : b(/* @__PURE__ */ f(S, {
199
205
  ...n,
200
- stackId: i,
206
+ stackId: r,
201
207
  phase: a,
202
208
  onEntered: () => o("entered"),
203
209
  onExited: () => {
@@ -206,4 +212,4 @@ var pe = 120, S = {
206
212
  }), c);
207
213
  };
208
214
  //#endregion
209
- export { S as DEFAULT_OFFCANVAS_LABELS, w as KapiOffcanvas };
215
+ export { x as DEFAULT_OFFCANVAS_LABELS, C as KapiOffcanvas };
@@ -50,6 +50,6 @@ export type { UseScrollEdgesOptions, UseScrollEdgesResult } from "./useScrollEdg
50
50
  export { DEFAULT_PAGE_FRACTION, DEFAULT_SCROLL_EDGE_TOLERANCE, maxScroll, pageSize, pageTarget, revealTarget, sameScrollEdges, scrollEdges } from "./scrollEdgesLogic";
51
51
  export type { KapiScrollAxis, ScrollEdges as KapiScrollEdges, ScrollMetrics as KapiScrollMetrics } from "./scrollEdgesLogic";
52
52
  export { deriveTheme } from "./themeDeriveLogic";
53
- export type { KapiCustomTheme, KapiThemeColors } from "./themeDeriveLogic";
53
+ export type { KapiCustomTheme, KapiThemeColors, KapiThemeRadii } from "./themeDeriveLogic";
54
54
  export { checkThemeContrast } from "./themeContrastLogic";
55
55
  export type { KapiThemeContrastFailure, KapiThemeContrastOptions } from "./themeContrastLogic";
@@ -22,13 +22,28 @@ export type KapiThemeColors = {
22
22
  /** Font stack, passed through as-is (`--kapi-font`). */
23
23
  font?: string | undefined;
24
24
  };
25
+ /** The radius knobs a custom theme sets; each one derives a tier of the radius scale. */
26
+ export type KapiThemeRadii = {
27
+ /** Anchor of the control tier, a px length (`10px`): xs, inner, sm, ctl-sm, md and group (`--kapi-radius-md`). */
28
+ control?: string | undefined;
29
+ /** Anchor of the surface tier, a px length (`18px`): lg, xl, the card radius and surfaces (`--kapi-radius-surface`). */
30
+ surface?: string | undefined;
31
+ /** Corner of square fixed-size controls, a percentage or px length, passed as-is (`--kapi-radius-squircle`). */
32
+ squircle?: string | undefined;
33
+ };
25
34
  /** A user theme: which built-in theme it stands on, and the base values it overrides. */
26
35
  export type KapiCustomTheme = {
27
36
  /** The built-in theme that supplies everything not derived, and the defaults for unset colors. */
28
37
  base: "light" | "dark";
29
38
  /** The base values; an unset or unparseable color falls back to the base theme's own. */
30
39
  colors: KapiThemeColors;
40
+ /** The radius knobs; an unset or invalid one leaves its whole tier at the base theme's values. */
41
+ radii?: KapiThemeRadii | undefined;
31
42
  };
43
+ /** A px length such as `10px` or `999px`: what the `control` and `surface` knobs accept. */
44
+ export declare const RADIUS_PX_PATTERN: RegExp;
45
+ /** A px length or a percentage such as `32%`: what the `squircle` knob accepts. */
46
+ export declare const RADIUS_SHAPE_PATTERN: RegExp;
32
47
  /**
33
48
  * Derives the override map for a user theme. Colors that are unset or can't be parsed fall back
34
49
  * to the base theme's for the math; alpha is ignored (colors are treated as opaque). The values
@@ -1,6 +1,28 @@
1
1
  import { contrastRatio as e, formatHex as t, mixColors as n, parseColor as r, readableForeground as i } from "./colorLogic.js";
2
2
  //#region src/hooks/themeDeriveLogic.ts
3
- var a = {
3
+ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
4
+ "--kapi-radius-xs": .6,
5
+ "--kapi-radius-inner": .7,
6
+ "--kapi-radius-sm": .8,
7
+ "--kapi-radius-ctl-sm": .9,
8
+ "--kapi-radius-md": 1,
9
+ "--kapi-radius-group": 1.1
10
+ }, c = {
11
+ "--kapi-radius-lg": 12 / 18,
12
+ "--kapi-radius-xl": 14 / 18,
13
+ "--kapi-radius": 16 / 18,
14
+ "--kapi-radius-surface": 1
15
+ }, l = (e, t) => `${Math.min(999, Math.round(e * t * 10) / 10)}px`, u = (e) => {
16
+ let t = {}, n = [[e.control, s], [e.surface, c]];
17
+ for (let [e, r] of n) {
18
+ let n = e?.trim();
19
+ if (!n || !a.test(n)) continue;
20
+ let i = parseFloat(n);
21
+ for (let [e, n] of Object.entries(r)) t[e] = l(i, n);
22
+ }
23
+ let r = e.squircle?.trim();
24
+ return r && o.test(r) && (t["--kapi-radius-squircle"] = r), t;
25
+ }, d = {
4
26
  light: {
5
27
  bg: "#f4f2fb",
6
28
  card: "#ffffff",
@@ -23,64 +45,64 @@ var a = {
23
45
  warning: "#e0a44e",
24
46
  danger: "#f06a8a"
25
47
  }
26
- }, o = Object.keys(a.light), s = 4.5, c = {
48
+ }, f = Object.keys(d.light), p = 4.5, m = {
27
49
  "--kapi-ink-2": 12,
28
50
  "--kapi-ink-3": 22,
29
51
  "--kapi-muted": 28,
30
52
  "--kapi-muted-2": 32
31
- }, l = {
53
+ }, h = {
32
54
  r: 255,
33
55
  g: 255,
34
56
  b: 255,
35
57
  a: 1
36
- }, u = {
58
+ }, g = {
37
59
  r: 0,
38
60
  g: 0,
39
61
  b: 0,
40
62
  a: 1
41
- }, d = [l, {
63
+ }, _ = [h, {
42
64
  r: 15,
43
65
  g: 13,
44
66
  b: 23,
45
67
  a: 1
46
- }], f = [
68
+ }], v = [
47
69
  "success",
48
70
  "info",
49
71
  "warning",
50
72
  "danger"
51
- ], p = (e) => ({
73
+ ], y = (e) => ({
52
74
  ...e,
53
75
  a: 1
54
- }), m = (t, r, i, a) => {
76
+ }), b = (t, r, i, a) => {
55
77
  for (let o = i; o > 0; o--) {
56
78
  let i = n(r, t, o);
57
- if (a.every((t) => e(i, t) >= s)) return i;
79
+ if (a.every((t) => e(i, t) >= p)) return i;
58
80
  }
59
81
  return t;
60
- }, h = (e, t) => `rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`, g = (e) => {
61
- let s = a[e.base], l = e.base === "dark", g = {}, _ = {}, v = /* @__PURE__ */ new Set();
62
- for (let n of o) {
82
+ }, x = (e, t) => `rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`, S = (e) => {
83
+ let a = d[e.base], o = e.base === "dark", s = {}, c = {}, l = /* @__PURE__ */ new Set();
84
+ for (let n of f) {
63
85
  let i = e.colors[n] === void 0 ? null : r(e.colors[n]);
64
- i && (v.add(n), g[`--kapi-${n}`] = t(i)), _[n] = p(i ?? r(s[n]));
86
+ i && (l.add(n), s[`--kapi-${n}`] = t(i)), c[n] = y(i ?? r(a[n]));
65
87
  }
66
- let y = e.colors.font?.trim();
67
- y && (g["--kapi-font"] = y);
68
- let { bg: b, card: x, line: S, ink: C } = _, w = (e) => t(e), T = v.has("bg") || v.has("card") || v.has("line"), E = T || v.has("ink"), D = n(b, x, 60), O = n(b, x, 30), k = n(S, C, 92), A = n(b, C, 96);
69
- T && (g["--kapi-surface"] = w(D), g["--kapi-soft"] = w(O), g["--kapi-border"] = w(k), g["--kapi-divider"] = w(n(S, x, 50)), g["--kapi-tab"] = w(A), g["--kapi-sk-base"] = w(n(b, C, 94)), g["--kapi-sk-shine"] = w(l ? k : n(x, b, 50)));
70
- let j = [
71
- b,
72
- x,
73
- D,
88
+ let p = e.colors.font?.trim();
89
+ p && (s["--kapi-font"] = p), e.radii && Object.assign(s, u(e.radii));
90
+ let { bg: h, card: S, line: C, ink: w } = c, T = (e) => t(e), E = l.has("bg") || l.has("card") || l.has("line"), D = E || l.has("ink"), O = n(h, S, 60), k = n(h, S, 30), A = n(C, w, 92), j = n(h, w, 96);
91
+ E && (s["--kapi-surface"] = T(O), s["--kapi-soft"] = T(k), s["--kapi-border"] = T(A), s["--kapi-divider"] = T(n(C, S, 50)), s["--kapi-tab"] = T(j), s["--kapi-sk-base"] = T(n(h, w, 94)), s["--kapi-sk-shine"] = T(o ? A : n(S, h, 50)));
92
+ let M = [
93
+ h,
94
+ S,
74
95
  O,
75
- A
76
- ], M = {};
77
- for (let [e, t] of Object.entries(c)) M[e] = m(C, b, t, j), E && (g[e] = w(M[e]));
78
- v.has("primary") && (g["--kapi-primary-fg"] = w(i(_.primary, d)));
79
- let N = f.filter((e) => v.has(e)).map((e) => [e, _[e]]);
80
- E && N.push(["neutral", M["--kapi-muted-2"]]);
81
- for (let [e, t] of N) g[`--kapi-${e}-bg`] = w(n(t, x, l ? 16 : 12)), g[`--kapi-${e}-border`] = w(n(t, x, l ? 35 : 28)), g[`--kapi-${e}-fg`] = w(i(t, d));
82
- E && (g["--kapi-neutral"] = w(M["--kapi-muted-2"])), v.has("ink") && (g["--kapi-tip-bg"] = w(C), g["--kapi-tip-fg"] = w(i(C, d)));
83
- let P = l ? u : n(C, u, 60), F = l ? {
96
+ k,
97
+ j
98
+ ], N = {};
99
+ for (let [e, t] of Object.entries(m)) N[e] = b(w, h, t, M), D && (s[e] = T(N[e]));
100
+ l.has("primary") && (s["--kapi-primary-fg"] = T(i(c.primary, _)));
101
+ let P = v.filter((e) => l.has(e)).map((e) => [e, c[e]]);
102
+ D && P.push(["neutral", N["--kapi-muted-2"]]);
103
+ for (let [e, t] of P) s[`--kapi-${e}-bg`] = T(n(t, S, o ? 16 : 12)), s[`--kapi-${e}-border`] = T(n(t, S, o ? 35 : 28)), s[`--kapi-${e}-fg`] = T(i(t, _));
104
+ D && (s["--kapi-neutral"] = T(N["--kapi-muted-2"])), l.has("ink") && (s["--kapi-tip-bg"] = T(w), s["--kapi-tip-fg"] = T(i(w, _)));
105
+ let F = o ? g : n(w, g, 60), I = o ? {
84
106
  base: .55,
85
107
  soft: .3,
86
108
  tour: .65,
@@ -97,7 +119,7 @@ var a = {
97
119
  strong: .6,
98
120
  edge: .06
99
121
  };
100
- return v.has("ink") && !l && (g["--kapi-scrim"] = h(P, F.base), g["--kapi-scrim-soft"] = h(P, F.soft), g["--kapi-scrim-tour"] = h(P, F.tour), g["--kapi-scrim-drawer"] = h(P, F.drawer), g["--kapi-scrim-cmdk"] = h(P, F.cmdk), g["--kapi-scrim-strong"] = h(P, F.strong), g["--kapi-edge-shade"] = h(P, F.edge)), g;
122
+ return l.has("ink") && !o && (s["--kapi-scrim"] = x(F, I.base), s["--kapi-scrim-soft"] = x(F, I.soft), s["--kapi-scrim-tour"] = x(F, I.tour), s["--kapi-scrim-drawer"] = x(F, I.drawer), s["--kapi-scrim-cmdk"] = x(F, I.cmdk), s["--kapi-scrim-strong"] = x(F, I.strong), s["--kapi-edge-shade"] = x(F, I.edge)), s;
101
123
  };
102
124
  //#endregion
103
- export { g as deriveTheme };
125
+ export { a as RADIUS_PX_PATTERN, o as RADIUS_SHAPE_PATTERN, S as deriveTheme };
@@ -0,0 +1,11 @@
1
+ import { type KapiThemeRadii } from "./themeDeriveLogic";
2
+ /** Shared empty value, so "no radii" is referentially stable across renders. */
3
+ export declare const NO_THEME_RADII: KapiThemeRadii;
4
+ /** Keeps only known knobs whose value is a well-formed length (`control`/`surface`: px; `squircle`: px or %). */
5
+ export declare const sanitizeThemeRadii: (input: unknown) => KapiThemeRadii;
6
+ /** Parses the stored JSON. Broken or invalid JSON counts as "no radii"; it never throws. */
7
+ export declare const parseStoredThemeRadii: (raw: string | null | undefined) => KapiThemeRadii;
8
+ /** Serializes for storage; "no radii" is the empty string (like the colors). */
9
+ export declare const serializeThemeRadii: (radii: KapiThemeRadii) => string;
10
+ /** Merges layers left to right: a later layer wins knob by knob; unset values never clobber. */
11
+ export declare const mergeThemeRadii: (...layers: (KapiThemeRadii | null | undefined)[]) => KapiThemeRadii;
@@ -0,0 +1,31 @@
1
+ import { RADIUS_PX_PATTERN as e, RADIUS_SHAPE_PATTERN as t } from "./themeDeriveLogic.js";
2
+ //#region src/hooks/themeRadiiLogic.ts
3
+ var n = {
4
+ control: e,
5
+ surface: e,
6
+ squircle: t
7
+ }, r = Object.freeze({}), i = (e) => {
8
+ if (typeof e != "object" || !e || Array.isArray(e)) return r;
9
+ let t = e, i = {};
10
+ for (let e of Object.keys(n)) {
11
+ let r = t[e];
12
+ typeof r == "string" && n[e].test(r.trim()) && (i[e] = r.trim());
13
+ }
14
+ return Object.keys(i).length ? i : r;
15
+ }, a = (e) => {
16
+ if (!e) return r;
17
+ try {
18
+ return i(JSON.parse(e));
19
+ } catch {
20
+ return r;
21
+ }
22
+ }, o = (e) => Object.keys(e).length ? JSON.stringify(e) : "", s = (...e) => {
23
+ let t = {};
24
+ for (let r of e) if (r) for (let e of Object.keys(n)) {
25
+ let n = r[e];
26
+ n && (t[e] = n);
27
+ }
28
+ return t;
29
+ };
30
+ //#endregion
31
+ export { r as NO_THEME_RADII, s as mergeThemeRadii, a as parseStoredThemeRadii, i as sanitizeThemeRadii, o as serializeThemeRadii };