@kapiuara/ui 0.8.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.
- package/README.md +54 -2
- package/dist/components/data/KapiPagination.d.ts +13 -4
- package/dist/components/data/KapiPagination.js +31 -88
- package/dist/components/data/KapiPaginationFooter.d.ts +35 -0
- package/dist/components/data/KapiPaginationFooter.js +106 -0
- package/dist/components/data/KapiTable.d.ts +38 -4
- package/dist/components/data/KapiTable.js +280 -321
- package/dist/components/layout/KapiContextSlot.d.ts +34 -6
- package/dist/components/layout/KapiContextSlot.js +115 -71
- package/dist/components/layout/KapiPageHeader.js +49 -24
- package/dist/components/layout/pageHeaderLogic.d.ts +13 -0
- package/dist/components/layout/pageHeaderLogic.js +4 -0
- package/dist/components/navigation/panelMiniLogic.d.ts +10 -1
- package/dist/components/navigation/panelMiniLogic.js +2 -2
- package/dist/components/overlays/KapiOffcanvas.js +124 -118
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/themeDeriveLogic.d.ts +15 -0
- package/dist/hooks/themeDeriveLogic.js +54 -32
- package/dist/hooks/themeRadiiLogic.d.ts +11 -0
- package/dist/hooks/themeRadiiLogic.js +31 -0
- package/dist/hooks/useKapiTheme.d.ts +10 -3
- package/dist/hooks/useKapiTheme.js +66 -57
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +1 -1
|
@@ -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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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
|
|
12
|
-
import { useEffect as
|
|
13
|
-
import { X as
|
|
14
|
-
import { createPortal as
|
|
15
|
-
var
|
|
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
|
-
},
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
},
|
|
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 =
|
|
27
|
-
|
|
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),
|
|
31
|
-
},
|
|
32
|
-
let t =
|
|
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 =
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
let t =
|
|
40
|
-
n !== null && (e.preventDefault(), e.stopPropagation(),
|
|
41
|
-
},
|
|
42
|
-
|
|
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:
|
|
45
|
+
id: i
|
|
45
46
|
}), () => l.dispatch({
|
|
46
47
|
type: "remove",
|
|
47
|
-
id:
|
|
48
|
-
})), [
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
id: i
|
|
49
|
+
})), [i]);
|
|
50
|
+
let G = _(g);
|
|
51
|
+
G.current = g, h(() => {
|
|
52
|
+
F.current?.getBoundingClientRect(), G.current();
|
|
52
53
|
}, []);
|
|
53
|
-
let
|
|
54
|
-
|
|
54
|
+
let K = _(b);
|
|
55
|
+
K.current = b, me(() => {
|
|
55
56
|
if (u !== "exit") return;
|
|
56
|
-
let e =
|
|
57
|
+
let e = F.current;
|
|
57
58
|
if (!e) {
|
|
58
|
-
|
|
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
|
-
|
|
64
|
+
K.current();
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
let i = !1, a = () => {
|
|
67
|
-
i || (i = !0,
|
|
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 +
|
|
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
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
...
|
|
81
|
-
[
|
|
82
|
-
"--kapi-offc-push-x": `${
|
|
83
|
-
"--kapi-offc-push-s":
|
|
84
|
-
},
|
|
85
|
-
|
|
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
|
-
|
|
91
|
+
q && /* @__PURE__ */ f("div", {
|
|
89
92
|
className: "kapi-offc__resize",
|
|
90
93
|
role: "separator",
|
|
91
94
|
"aria-orientation": "vertical",
|
|
92
|
-
"aria-label":
|
|
93
|
-
"aria-valuemin":
|
|
94
|
-
"aria-valuemax":
|
|
95
|
-
"aria-valuenow":
|
|
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:
|
|
98
|
-
onPointerMove:
|
|
99
|
-
onPointerUp:
|
|
100
|
-
onPointerCancel:
|
|
101
|
-
onKeyDown:
|
|
100
|
+
onPointerDown: Ie,
|
|
101
|
+
onPointerMove: Le,
|
|
102
|
+
onPointerUp: U,
|
|
103
|
+
onPointerCancel: U,
|
|
104
|
+
onKeyDown: Re
|
|
102
105
|
}),
|
|
103
|
-
/* @__PURE__ */
|
|
106
|
+
/* @__PURE__ */ p("div", {
|
|
104
107
|
className: "kapi-offc__head",
|
|
105
|
-
children: [/* @__PURE__ */
|
|
106
|
-
id:
|
|
108
|
+
children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("div", {
|
|
109
|
+
id: M,
|
|
107
110
|
className: "kapi-modal__title",
|
|
108
|
-
children:
|
|
109
|
-
}),
|
|
111
|
+
children: C
|
|
112
|
+
}), w && /* @__PURE__ */ f("div", {
|
|
110
113
|
className: "kapi-modal__sub",
|
|
111
|
-
children:
|
|
112
|
-
})] }), /* @__PURE__ */
|
|
114
|
+
children: w
|
|
115
|
+
})] }), /* @__PURE__ */ f("button", {
|
|
113
116
|
type: "button",
|
|
114
117
|
className: "kapi-modal__x",
|
|
115
|
-
onClick:
|
|
116
|
-
"aria-label":
|
|
117
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
126
|
+
/* @__PURE__ */ f("div", {
|
|
124
127
|
className: "kapi-offc__body",
|
|
125
|
-
children:
|
|
128
|
+
children: _e
|
|
126
129
|
}),
|
|
127
|
-
|
|
130
|
+
T && /* @__PURE__ */ f("div", {
|
|
128
131
|
className: "kapi-offc__foot",
|
|
129
|
-
children:
|
|
132
|
+
children: T
|
|
130
133
|
})
|
|
131
134
|
]
|
|
132
|
-
}, "main"),
|
|
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":
|
|
136
|
-
style: { "--kapi-offc-companion-w":
|
|
141
|
+
"aria-labelledby": Q.title ? N : void 0,
|
|
142
|
+
style: { "--kapi-offc-companion-w": le(Q.width) },
|
|
137
143
|
children: [
|
|
138
|
-
(
|
|
144
|
+
(Q.title || Q.onClose) && /* @__PURE__ */ p("div", {
|
|
139
145
|
className: "kapi-offc__head",
|
|
140
|
-
children: [/* @__PURE__ */
|
|
141
|
-
id:
|
|
146
|
+
children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("div", {
|
|
147
|
+
id: N,
|
|
142
148
|
className: "kapi-modal__title",
|
|
143
|
-
children:
|
|
144
|
-
}),
|
|
149
|
+
children: Q.title
|
|
150
|
+
}), Q.subtitle && /* @__PURE__ */ f("div", {
|
|
145
151
|
className: "kapi-modal__sub",
|
|
146
|
-
children:
|
|
147
|
-
})] }),
|
|
152
|
+
children: Q.subtitle
|
|
153
|
+
})] }), Q.onClose && /* @__PURE__ */ f("button", {
|
|
148
154
|
type: "button",
|
|
149
155
|
className: "kapi-modal__x",
|
|
150
|
-
onClick:
|
|
151
|
-
"aria-label":
|
|
152
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
164
|
+
/* @__PURE__ */ f("div", {
|
|
159
165
|
className: "kapi-offc__body",
|
|
160
|
-
children:
|
|
166
|
+
children: Q.children
|
|
161
167
|
}),
|
|
162
|
-
|
|
168
|
+
Q.footer && /* @__PURE__ */ f("div", {
|
|
163
169
|
className: "kapi-offc__foot",
|
|
164
|
-
children:
|
|
170
|
+
children: Q.footer
|
|
165
171
|
})
|
|
166
172
|
]
|
|
167
|
-
}, "companion") : null,
|
|
168
|
-
return /* @__PURE__ */
|
|
169
|
-
ref:
|
|
170
|
-
id:
|
|
171
|
-
className: t("kapi-offc",
|
|
172
|
-
"data-side":
|
|
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":
|
|
175
|
-
"data-pushed":
|
|
180
|
+
"data-level": je,
|
|
181
|
+
"data-pushed": L > 0 ? "" : void 0,
|
|
176
182
|
"aria-modal": "true",
|
|
177
|
-
"aria-labelledby":
|
|
178
|
-
style:
|
|
179
|
-
...
|
|
180
|
-
...
|
|
181
|
-
children: /* @__PURE__ */
|
|
182
|
-
className:
|
|
183
|
-
children:
|
|
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
|
-
},
|
|
187
|
-
let
|
|
188
|
-
s.current = t,
|
|
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]),
|
|
196
|
+
}, [e]), h(() => {
|
|
191
197
|
(a === "exit" || a === "open") && l.dispatch({
|
|
192
198
|
type: "mark",
|
|
193
|
-
id:
|
|
199
|
+
id: r,
|
|
194
200
|
state: a === "exit" ? "closing" : "open"
|
|
195
201
|
});
|
|
196
|
-
}, [a,
|
|
197
|
-
let c =
|
|
198
|
-
return a === "unmounted" || !c ? null :
|
|
202
|
+
}, [a, r]);
|
|
203
|
+
let c = i();
|
|
204
|
+
return a === "unmounted" || !c ? null : b(/* @__PURE__ */ f(S, {
|
|
199
205
|
...n,
|
|
200
|
-
stackId:
|
|
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 {
|
|
215
|
+
export { x as DEFAULT_OFFCANVAS_LABELS, C as KapiOffcanvas };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -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
|
-
},
|
|
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
|
-
},
|
|
53
|
+
}, h = {
|
|
32
54
|
r: 255,
|
|
33
55
|
g: 255,
|
|
34
56
|
b: 255,
|
|
35
57
|
a: 1
|
|
36
|
-
},
|
|
58
|
+
}, g = {
|
|
37
59
|
r: 0,
|
|
38
60
|
g: 0,
|
|
39
61
|
b: 0,
|
|
40
62
|
a: 1
|
|
41
|
-
},
|
|
63
|
+
}, _ = [h, {
|
|
42
64
|
r: 15,
|
|
43
65
|
g: 13,
|
|
44
66
|
b: 23,
|
|
45
67
|
a: 1
|
|
46
|
-
}],
|
|
68
|
+
}], v = [
|
|
47
69
|
"success",
|
|
48
70
|
"info",
|
|
49
71
|
"warning",
|
|
50
72
|
"danger"
|
|
51
|
-
],
|
|
73
|
+
], y = (e) => ({
|
|
52
74
|
...e,
|
|
53
75
|
a: 1
|
|
54
|
-
}),
|
|
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) >=
|
|
79
|
+
if (a.every((t) => e(i, t) >= p)) return i;
|
|
58
80
|
}
|
|
59
81
|
return t;
|
|
60
|
-
},
|
|
61
|
-
let
|
|
62
|
-
for (let n of
|
|
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 && (
|
|
86
|
+
i && (l.add(n), s[`--kapi-${n}`] = t(i)), c[n] = y(i ?? r(a[n]));
|
|
65
87
|
}
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
let { bg:
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
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 {
|
|
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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CSSProperties } from "react";
|
|
2
|
-
import { type KapiThemeColors } from "./themeDeriveLogic";
|
|
2
|
+
import { type KapiThemeColors, type KapiThemeRadii } from "./themeDeriveLogic";
|
|
3
3
|
export type KapiTheme = "light" | "dark";
|
|
4
4
|
/** Lo que elige la persona: un tema fijo o `system` (sigue a `prefers-color-scheme` del SO). */
|
|
5
5
|
export type KapiThemePreference = KapiTheme | "system";
|
|
@@ -9,7 +9,7 @@ export type KapiFontKey = "nunito" | "roboto" | "system";
|
|
|
9
9
|
/** Movimiento: `auto` sigue al SO (prefers-reduced-motion); `reduced` lo apaga siempre. */
|
|
10
10
|
export type KapiMotion = "auto" | "reduced";
|
|
11
11
|
/** Preferencias del tema que se guardan. */
|
|
12
|
-
export type KapiThemeStorageName = "theme" | "accent" | "font" | "motion" | "customTheme";
|
|
12
|
+
export type KapiThemeStorageName = "theme" | "accent" | "font" | "motion" | "customTheme" | "radii";
|
|
13
13
|
/** Claves de localStorage del tema para un namespace (default `kapi` → `kapi:theme`…). */
|
|
14
14
|
export declare const themeStorageKeys: (namespace?: string) => Record<KapiThemeStorageName, string>;
|
|
15
15
|
/** Claves viejas (sin namespace): se migran a las nuevas en la primera lectura y se borran. */
|
|
@@ -34,6 +34,11 @@ export type KapiThemeState = {
|
|
|
34
34
|
* (el selector). Si no, ese valor queda como estado muerto y reaparece al resetear el tema propio.
|
|
35
35
|
*/
|
|
36
36
|
customTheme: KapiThemeColors;
|
|
37
|
+
/**
|
|
38
|
+
* Radius knobs que fijó la persona (`control`, `surface`, `squircle`); `{}` si no hay. Se guardan aparte
|
|
39
|
+
* de `customTheme` (`kapi:radii`) para no cambiar la forma de lo que ya hay guardado.
|
|
40
|
+
*/
|
|
41
|
+
radii: KapiThemeRadii;
|
|
37
42
|
font: KapiFontKey;
|
|
38
43
|
/** `true` si la persona eligió una fuente (hay `kapi:font` guardada); si no, la de la marca manda. */
|
|
39
44
|
fontChosen: boolean;
|
|
@@ -51,6 +56,8 @@ export type KapiThemeState = {
|
|
|
51
56
|
* al fijar un `primary` o un `font` propios corresponde reconciliar el acento y el selector de fuente.
|
|
52
57
|
*/
|
|
53
58
|
setCustomTheme: (colors?: KapiThemeColors | null) => void;
|
|
59
|
+
/** Fija los radios propios (reemplaza los anteriores); `null` o `{}` los borra. */
|
|
60
|
+
setRadii: (radii?: KapiThemeRadii | null) => void;
|
|
54
61
|
setFont: (f: KapiFontKey) => void;
|
|
55
62
|
setMotion: (m: KapiMotion) => void;
|
|
56
63
|
/** Alterna entre `auto` y `reduced`. */
|
|
@@ -78,7 +85,7 @@ export declare const isMotion: (v: string) => v is KapiMotion;
|
|
|
78
85
|
* la marca o del tema propio, se emite tal cual como `--kapi-primary` y se omite sólo el
|
|
79
86
|
* `--kapi-primary-fg` calculado, que es lo único que necesita los números.
|
|
80
87
|
*/
|
|
81
|
-
export declare const themeRootStyle: (state: Pick<KapiThemeState, "font" | "accent"> & Partial<Pick<KapiThemeState, "theme" | "customTheme" | "fontChosen">>, brand?: KapiThemeColors) => CSSProperties;
|
|
88
|
+
export declare const themeRootStyle: (state: Pick<KapiThemeState, "font" | "accent"> & Partial<Pick<KapiThemeState, "theme" | "customTheme" | "radii" | "fontChosen">>, brand?: KapiThemeColors) => CSSProperties;
|
|
82
89
|
export declare const KapiThemeContext: import("react").Context<KapiThemeState>;
|
|
83
90
|
export type KapiThemeStateOptions = {
|
|
84
91
|
/**
|