@kapiuara/ui 0.9.0 → 0.10.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 +19 -6
- package/dist/components/data/KapiPaginationFooter.js +5 -5
- package/dist/components/data/KapiTable.d.ts +1 -1
- package/dist/components/feedback/KapiBulkBar.d.ts +1 -1
- package/dist/components/layout/KapiPageHeader.js +106 -46
- package/dist/components/layout/pageHeaderLogic.d.ts +25 -0
- package/dist/components/layout/pageHeaderLogic.js +16 -2
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/themeDeriveLogic.d.ts +3 -1
- package/dist/hooks/themeDeriveLogic.js +37 -30
- package/dist/hooks/themeRadiiLogic.d.ts +1 -1
- package/dist/hooks/themeRadiiLogic.js +1 -0
- package/dist/hooks/useWheelZoom.d.ts +30 -0
- package/dist/hooks/useWheelZoom.js +27 -0
- package/dist/hooks/wheelZoomLogic.d.ts +18 -0
- package/dist/hooks/wheelZoomLogic.js +9 -0
- package/dist/index.js +9 -8
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -782,6 +782,15 @@ useHotkey("/", () => ref.current?.focus());
|
|
|
782
782
|
`KapiNotificationBell now={fecha}` fija la hora de referencia de las fechas relativas (tests y capturas).
|
|
783
783
|
`KapiPanelItem icon={<Inbox size={15} />}` suma un ícono decorativo antes del texto.
|
|
784
784
|
|
|
785
|
+
`useWheelZoom({ value, onChange, min, max, step })` da zoom con Ctrl + rueda (y pellizco de trackpad) sobre un
|
|
786
|
+
elemento. No se puede hacer con `onWheel`: React lo registra pasivo y `preventDefault()` no frena el zoom de la
|
|
787
|
+
página; el hook ata el listener con `{ passive: false }`.
|
|
788
|
+
|
|
789
|
+
```tsx
|
|
790
|
+
const ref = useWheelZoom<HTMLDivElement>({ value: zoom, onChange: setZoom, min: 50, max: 300, step: 25 });
|
|
791
|
+
<div ref={ref}>…</div>;
|
|
792
|
+
```
|
|
793
|
+
|
|
785
794
|
## Tema y color de marca
|
|
786
795
|
|
|
787
796
|
Todos los colores salen de tokens `--kapi-*` en `.kapi`; el tema oscuro es `data-theme="dark"` en esa
|
|
@@ -828,23 +837,27 @@ un objeto nuevo por render vuelve a derivar el tema.
|
|
|
828
837
|
|
|
829
838
|
### Radios del tema
|
|
830
839
|
|
|
831
|
-
Los radios van aparte de los colores, en **
|
|
840
|
+
Los radios van aparte de los colores, en **cuatro perillas** y no en los doce tokens sueltos:
|
|
832
841
|
|
|
833
842
|
```tsx
|
|
834
843
|
const { setRadii } = useKapiThemeState(); // se guarda en kapi:radii
|
|
835
|
-
setRadii({ control: "999px" }); // campos, botones
|
|
844
|
+
setRadii({ control: "999px" }); // campos, botones e insignias en pastilla; las casillas y el textarea no
|
|
836
845
|
```
|
|
837
846
|
|
|
838
|
-
- `control` (px) ancla el tier de los controles: emite `--kapi-radius-xs`, `-inner`, `-sm`, `-ctl-sm`,
|
|
839
|
-
y `-group`, cada uno como un múltiplo fijo de la perilla.
|
|
847
|
+
- `control` (px) ancla el tier de los controles: emite `--kapi-radius-xs`, `-inner`, `-sm`, `-ctl-sm`,
|
|
848
|
+
`-md` y `-group`, cada uno como un múltiplo fijo de la perilla.
|
|
849
|
+
- `box` (px) ancla el de las cajas, los controles donde una pastilla está mal: emite `--kapi-radius-box`
|
|
850
|
+
(el textarea) y `--kapi-radius-check`, el 60% de la perilla (la casilla). Por eso `control: "999px"` ya no vuelve círculo a la casilla ni
|
|
851
|
+
pastilla al textarea; para eso hay que fijar `box` a propósito (`box: "999px"`).
|
|
840
852
|
- `surface` (px) ancla el de las superficies: `--kapi-radius-lg`, `-xl`, `--kapi-radius` y
|
|
841
853
|
`--kapi-radius-surface` (modal, toast, caja de carga). Las filas en modo card de `KapiTable` vienen de
|
|
842
854
|
arrastre, porque su `--card-radius` deriva de `--kapi-radius-xl`.
|
|
843
855
|
- `squircle` (px o porcentaje, se emite tal cual) es la esquina de los controles cuadrados de lado fijo
|
|
844
856
|
(avatar de `KapiPersonHeader`, botón flotante y sus acciones): `50%` los vuelve círculos.
|
|
845
857
|
|
|
846
|
-
Son **
|
|
847
|
-
una sola perilla unos controles en pastilla volverían redondas las tarjetas y las tablas
|
|
858
|
+
Son **tres tiers y no uno** a propósito: `--kapi-radius-xl` y `--kapi-radius` los usan contenedores, así que con
|
|
859
|
+
una sola perilla unos controles en pastilla volverían redondas las tarjetas y las tablas, y las casillas serían
|
|
860
|
+
círculos que no se distinguen de un radio. Una perilla sin setear
|
|
848
861
|
o con un valor inválido no emite nada y su tier se queda con el del tema base; `--kapi-radius-pill` nunca se
|
|
849
862
|
deriva, y ningún valor derivado pasa de 999px.
|
|
850
863
|
|
|
@@ -3,7 +3,7 @@ import { KapiSelect as e } from "../inputs/KapiSelect.js";
|
|
|
3
3
|
import { joinClasses as t } from "../rootProps.js";
|
|
4
4
|
/* empty css */
|
|
5
5
|
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
6
|
-
import {
|
|
6
|
+
import { ChevronFirst as i, ChevronLast as a, ChevronLeft as o, ChevronRight as s } from "lucide-react";
|
|
7
7
|
//#region src/components/data/KapiPaginationFooter.tsx
|
|
8
8
|
function c({ as: c, info: l, pageSize: u, total: d, onPageChange: f, pageSizeOptions: p, onPageSizeChange: m, showEdges: h, labels: g, className: _, ...v }) {
|
|
9
9
|
return /* @__PURE__ */ r(c, {
|
|
@@ -46,7 +46,7 @@ function c({ as: c, info: l, pageSize: u, total: d, onPageChange: f, pageSizeOpt
|
|
|
46
46
|
onClick: () => {
|
|
47
47
|
l.canPrev && f(1);
|
|
48
48
|
},
|
|
49
|
-
children: /* @__PURE__ */ n(
|
|
49
|
+
children: /* @__PURE__ */ n(i, {
|
|
50
50
|
size: 16,
|
|
51
51
|
strokeWidth: 2
|
|
52
52
|
})
|
|
@@ -59,7 +59,7 @@ function c({ as: c, info: l, pageSize: u, total: d, onPageChange: f, pageSizeOpt
|
|
|
59
59
|
onClick: () => {
|
|
60
60
|
l.canPrev && f(l.page - 1);
|
|
61
61
|
},
|
|
62
|
-
children: /* @__PURE__ */ n(
|
|
62
|
+
children: /* @__PURE__ */ n(o, {
|
|
63
63
|
size: 16,
|
|
64
64
|
strokeWidth: 2
|
|
65
65
|
})
|
|
@@ -80,7 +80,7 @@ function c({ as: c, info: l, pageSize: u, total: d, onPageChange: f, pageSizeOpt
|
|
|
80
80
|
onClick: () => {
|
|
81
81
|
l.canNext && f(l.page + 1);
|
|
82
82
|
},
|
|
83
|
-
children: /* @__PURE__ */ n(
|
|
83
|
+
children: /* @__PURE__ */ n(s, {
|
|
84
84
|
size: 16,
|
|
85
85
|
strokeWidth: 2
|
|
86
86
|
})
|
|
@@ -93,7 +93,7 @@ function c({ as: c, info: l, pageSize: u, total: d, onPageChange: f, pageSizeOpt
|
|
|
93
93
|
onClick: () => {
|
|
94
94
|
l.canNext && f(l.totalPages);
|
|
95
95
|
},
|
|
96
|
-
children: /* @__PURE__ */ n(
|
|
96
|
+
children: /* @__PURE__ */ n(a, {
|
|
97
97
|
size: 16,
|
|
98
98
|
strokeWidth: 2
|
|
99
99
|
})
|
|
@@ -231,7 +231,7 @@ export type KapiTableProps<T, K extends keyof T = keyof T> = KapiRootProps & {
|
|
|
231
231
|
selectedIds?: ReadonlyArray<T[K]>;
|
|
232
232
|
/** Recibe los ids seleccionados cada vez que cambia la selección (controlada o no). */
|
|
233
233
|
onSelectedIdsChange?: (ids: Array<T[K]>) => void;
|
|
234
|
-
/** Con `selectable` y selección no vacía: barra sticky de acciones masivas con las acciones que devuelve esta función. */
|
|
234
|
+
/** Con `selectable` y selección no vacía: barra sticky de acciones masivas con las acciones que devuelve esta función. La barra es densa: pasale `size="sm"` a los controles para que queden a la altura de su "Limpiar". */
|
|
235
235
|
bulkActions?: (ctx: {
|
|
236
236
|
ids: Array<T[K]>;
|
|
237
237
|
clear: () => void;
|
|
@@ -7,7 +7,7 @@ export type KapiBulkBarProps = Omit<HTMLAttributes<HTMLDivElement>, "children" |
|
|
|
7
7
|
count: number;
|
|
8
8
|
/** Vacía la selección. */
|
|
9
9
|
onClear: () => void;
|
|
10
|
-
/** Botones de acción masiva. */
|
|
10
|
+
/** Botones de acción masiva. La barra es una superficie densa: su propio "Limpiar" es `size="sm"`, así que las acciones van en `sm` para quedar a la misma altura (32px). */
|
|
11
11
|
children?: ReactNode;
|
|
12
12
|
/** Texto del botón de limpiar. Gana sobre `labels.clear` ("Limpiar"). */
|
|
13
13
|
clearLabel?: string;
|
|
@@ -1,72 +1,132 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { prefersReducedMotion as e } from "../../hooks/reducedMotion.js";
|
|
3
|
+
import { maxTransitionMs as t } from "../overlays/dialogUtils.js";
|
|
4
|
+
import { useScrollCollapse as n } from "../../hooks/useScrollCollapse.js";
|
|
5
|
+
import { pageHeaderBox as r } from "./pageHeaderLogic.js";
|
|
4
6
|
/* empty css */
|
|
5
|
-
import { Fragment as
|
|
6
|
-
import { useLayoutEffect as
|
|
7
|
+
import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
8
|
+
import { useLayoutEffect as s, useRef as c } from "react";
|
|
7
9
|
//#region src/components/layout/KapiPageHeader.tsx
|
|
8
|
-
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
var l = "kapi-pageheader--collapsed", u = "kapi-pageheader--animating", d = "kapi-pageheader--measuring", f = 80, p = (e, t) => {
|
|
11
|
+
let n = e.style.height;
|
|
12
|
+
e.classList.add(d), e.style.height = "", e.classList.toggle(l, !1);
|
|
13
|
+
let r = e.getBoundingClientRect().height;
|
|
14
|
+
e.classList.toggle(l, !0);
|
|
15
|
+
let i = e.getBoundingClientRect().height;
|
|
16
|
+
return e.classList.toggle(l, t), e.style.height = n, e.getBoundingClientRect(), e.classList.remove(d), {
|
|
17
|
+
expanded: r,
|
|
18
|
+
collapsed: i
|
|
19
|
+
};
|
|
20
|
+
}, m = (e, t) => {
|
|
21
|
+
let n = r(e, t);
|
|
22
|
+
return t ? n : {
|
|
23
|
+
height: null,
|
|
24
|
+
reserve: n.reserve
|
|
25
|
+
};
|
|
26
|
+
}, h = (e, t, n) => {
|
|
27
|
+
let r = () => {
|
|
28
|
+
t.height === null ? e.style.removeProperty("height") : e.style.height = `${t.height}px`, e.style.setProperty("--kapi-pageheader-reserve", `${t.reserve}px`);
|
|
29
|
+
};
|
|
30
|
+
n ? r() : (e.style.transition = "none", r(), e.getBoundingClientRect(), e.style.transition = "");
|
|
31
|
+
};
|
|
32
|
+
function g({ title: l, subtitle: d, meta: g, actions: _, chip: v, collapseOnScroll: y = !0, sticky: b = !0, scrollRoot: x = null, responsive: S = !0, className: C, ...w }) {
|
|
33
|
+
let { collapsed: T, sentinelRef: E } = n({ root: x }), D = y && T, O = c(null), k = c({
|
|
34
|
+
expanded: 0,
|
|
35
|
+
collapsed: 0
|
|
36
|
+
}), A = c(D);
|
|
37
|
+
A.current = D;
|
|
38
|
+
let j = c(!1), M = c(!1);
|
|
39
|
+
s(() => {
|
|
40
|
+
let e = O.current;
|
|
12
41
|
if (!e) return;
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
42
|
+
let t = () => {
|
|
43
|
+
M.current || (k.current = p(e, A.current), h(e, m(k.current, A.current), !1));
|
|
44
|
+
};
|
|
45
|
+
t();
|
|
46
|
+
let n = !0;
|
|
47
|
+
if (document.fonts?.ready.then(() => {
|
|
48
|
+
n && t();
|
|
49
|
+
}), typeof ResizeObserver > "u") return () => {
|
|
50
|
+
n = !1;
|
|
51
|
+
};
|
|
52
|
+
let r = e.getBoundingClientRect().width, i = new ResizeObserver((e) => {
|
|
53
|
+
let n = e[e.length - 1];
|
|
54
|
+
if (!n) return;
|
|
55
|
+
let i = n.borderBoxSize?.[0]?.inlineSize ?? n.contentRect.width;
|
|
56
|
+
i !== r && (r = i, t());
|
|
57
|
+
});
|
|
58
|
+
return i.observe(e), () => {
|
|
59
|
+
n = !1, i.disconnect();
|
|
18
60
|
};
|
|
19
|
-
if (n(), typeof ResizeObserver > "u") return;
|
|
20
|
-
let r = new ResizeObserver(n);
|
|
21
|
-
return r.observe(e), () => r.disconnect();
|
|
22
61
|
}, [
|
|
23
|
-
b,
|
|
24
|
-
f,
|
|
25
|
-
s,
|
|
26
|
-
c,
|
|
27
62
|
l,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
63
|
+
d,
|
|
64
|
+
g,
|
|
65
|
+
_,
|
|
66
|
+
v,
|
|
67
|
+
y,
|
|
68
|
+
S
|
|
69
|
+
]), s(() => {
|
|
70
|
+
let n = O.current;
|
|
71
|
+
if (!n) return;
|
|
72
|
+
let { expanded: i } = k.current, a = r(k.current, D), o = j.current && !e(n);
|
|
73
|
+
j.current = !0;
|
|
74
|
+
let s = () => {
|
|
75
|
+
M.current = !1, n.classList.remove(u), D || n.style.removeProperty("height");
|
|
76
|
+
};
|
|
77
|
+
if (!o) {
|
|
78
|
+
h(n, m(k.current, D), !1);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
n.style.height === "" && i > 0 && (n.style.height = `${i}px`, n.getBoundingClientRect()), M.current = !0, n.classList.add(u), h(n, a, !0);
|
|
82
|
+
let c = (e) => {
|
|
83
|
+
e.target === n && e.propertyName === "height" && s();
|
|
84
|
+
};
|
|
85
|
+
n.addEventListener("transitionend", c);
|
|
86
|
+
let l = getComputedStyle(n), d = window.setTimeout(s, t(l.transitionDuration, l.transitionDelay) + f);
|
|
87
|
+
return () => {
|
|
88
|
+
n.removeEventListener("transitionend", c), window.clearTimeout(d);
|
|
89
|
+
};
|
|
90
|
+
}, [D]);
|
|
91
|
+
let N = [
|
|
32
92
|
"kapi-pageheader",
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
93
|
+
b && "kapi-pageheader--sticky",
|
|
94
|
+
S && "kapi-pageheader--cq",
|
|
95
|
+
D && "kapi-pageheader--collapsed",
|
|
96
|
+
C
|
|
37
97
|
].filter(Boolean).join(" ");
|
|
38
|
-
return /* @__PURE__ */ i
|
|
39
|
-
ref:
|
|
98
|
+
return /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ a("div", {
|
|
99
|
+
ref: E,
|
|
40
100
|
className: "kapi-pageheader__sentinel",
|
|
41
101
|
"aria-hidden": !0
|
|
42
|
-
}), /* @__PURE__ */
|
|
43
|
-
...
|
|
44
|
-
ref:
|
|
45
|
-
className:
|
|
46
|
-
children: [/* @__PURE__ */
|
|
102
|
+
}), /* @__PURE__ */ o("header", {
|
|
103
|
+
...w,
|
|
104
|
+
ref: O,
|
|
105
|
+
className: N,
|
|
106
|
+
children: [/* @__PURE__ */ o("div", {
|
|
47
107
|
className: "kapi-pageheader__main",
|
|
48
108
|
children: [
|
|
49
|
-
/* @__PURE__ */
|
|
109
|
+
/* @__PURE__ */ o("div", {
|
|
50
110
|
className: "kapi-pageheader__titlerow",
|
|
51
|
-
children: [/* @__PURE__ */
|
|
111
|
+
children: [/* @__PURE__ */ a("h1", {
|
|
52
112
|
className: "kapi-pageheader__title",
|
|
53
|
-
children:
|
|
54
|
-
}),
|
|
113
|
+
children: l
|
|
114
|
+
}), v]
|
|
55
115
|
}),
|
|
56
|
-
|
|
116
|
+
d && /* @__PURE__ */ a("div", {
|
|
57
117
|
className: "kapi-pageheader__subtitle",
|
|
58
|
-
children:
|
|
118
|
+
children: d
|
|
59
119
|
}),
|
|
60
|
-
|
|
120
|
+
g && /* @__PURE__ */ a("div", {
|
|
61
121
|
className: "kapi-pageheader__meta",
|
|
62
|
-
children:
|
|
122
|
+
children: g
|
|
63
123
|
})
|
|
64
124
|
]
|
|
65
|
-
}),
|
|
125
|
+
}), _ && /* @__PURE__ */ a("div", {
|
|
66
126
|
className: "kapi-pageheader__actions",
|
|
67
|
-
children:
|
|
127
|
+
children: _
|
|
68
128
|
})]
|
|
69
129
|
})] });
|
|
70
130
|
}
|
|
71
131
|
//#endregion
|
|
72
|
-
export {
|
|
132
|
+
export { g as KapiPageHeader };
|
|
@@ -11,3 +11,28 @@
|
|
|
11
11
|
* donde todo mide 0), no hay nada que devolver.
|
|
12
12
|
*/
|
|
13
13
|
export declare const pageHeaderSpacerHeight: (expanded: number, current: number) => number;
|
|
14
|
+
/** Altos naturales del header en sus dos estados, medidos con el ancho actual. */
|
|
15
|
+
export type KapiPageHeaderHeights = {
|
|
16
|
+
expanded: number;
|
|
17
|
+
collapsed: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Caja que el componente escribe en el DOM: `height` en px (`null` = no imponer alto, queda
|
|
21
|
+
* `auto`) y la reserva que se devuelve al flujo como margen inferior.
|
|
22
|
+
*/
|
|
23
|
+
export type KapiPageHeaderBox = {
|
|
24
|
+
height: number | null;
|
|
25
|
+
reserve: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Caja del header para un estado, pensada para que el alto y la reserva animen JUNTOS.
|
|
29
|
+
*
|
|
30
|
+
* Invariante: `height + reserve === expanded` en los dos estados. Si ambos transicionan con la
|
|
31
|
+
* misma curva y duración, la suma vale `expanded` en todo frame (también si la animación se
|
|
32
|
+
* interrumpe a mitad: las dos distancias que faltan son iguales y opuestas), así que el largo del
|
|
33
|
+
* documento no cambia nunca y el navegador no tiene nada que recortar.
|
|
34
|
+
*
|
|
35
|
+
* Sin layout (jsdom) o con una medición fallida devuelve `height: null`: no se impone ningún alto,
|
|
36
|
+
* para que un header real no quede en 0px.
|
|
37
|
+
*/
|
|
38
|
+
export declare const pageHeaderBox: (heights: KapiPageHeaderHeights, isCollapsed: boolean) => KapiPageHeaderBox;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
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))
|
|
2
|
+
var e = (e) => Number.isFinite(e) && e > 0 ? e : 0, t = (t, n) => Math.max(0, e(t) - e(n)), n = (n, r) => {
|
|
3
|
+
let i = e(n.expanded), a = e(n.collapsed);
|
|
4
|
+
if (i <= 0 || a <= 0) return {
|
|
5
|
+
height: null,
|
|
6
|
+
reserve: 0
|
|
7
|
+
};
|
|
8
|
+
let o = t(i, a);
|
|
9
|
+
return r ? {
|
|
10
|
+
height: a,
|
|
11
|
+
reserve: o
|
|
12
|
+
} : {
|
|
13
|
+
height: i,
|
|
14
|
+
reserve: 0
|
|
15
|
+
};
|
|
16
|
+
};
|
|
3
17
|
//#endregion
|
|
4
|
-
export { t as pageHeaderSpacerHeight };
|
|
18
|
+
export { n as pageHeaderBox, t as pageHeaderSpacerHeight };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export type { BeforeUnloadLike as KapiBeforeUnloadLike, UnsavedGuard as KapiUnsa
|
|
|
11
11
|
export { KAPI_ROOT_SELECTOR, resolveKapiRoot, useKapiRoot } from "./kapiRoot";
|
|
12
12
|
export { REDUCED_MOTION_QUERY, prefersReducedMotion } from "./reducedMotion";
|
|
13
13
|
export { SHELL_MOBILE_QUERY, matchesQuery, useMediaQuery } from "./useMediaQuery";
|
|
14
|
+
export { useWheelZoom } from "./useWheelZoom";
|
|
15
|
+
export type { UseWheelZoomOptions } from "./useWheelZoom";
|
|
14
16
|
export { useHotkey } from "./useHotkey";
|
|
15
17
|
export type { UseHotkeyOptions } from "./useHotkey";
|
|
16
18
|
export { usePersistentState } from "./usePersistentState";
|
|
@@ -26,6 +26,8 @@ export type KapiThemeColors = {
|
|
|
26
26
|
export type KapiThemeRadii = {
|
|
27
27
|
/** Anchor of the control tier, a px length (`10px`): xs, inner, sm, ctl-sm, md and group (`--kapi-radius-md`). */
|
|
28
28
|
control?: string | undefined;
|
|
29
|
+
/** Anchor of the box tier, a px length (`10px`): check and box, the shape of checkboxes and textareas (`--kapi-radius-box`). */
|
|
30
|
+
box?: string | undefined;
|
|
29
31
|
/** Anchor of the surface tier, a px length (`18px`): lg, xl, the card radius and surfaces (`--kapi-radius-surface`). */
|
|
30
32
|
surface?: string | undefined;
|
|
31
33
|
/** Corner of square fixed-size controls, a percentage or px length, passed as-is (`--kapi-radius-squircle`). */
|
|
@@ -40,7 +42,7 @@ export type KapiCustomTheme = {
|
|
|
40
42
|
/** The radius knobs; an unset or invalid one leaves its whole tier at the base theme's values. */
|
|
41
43
|
radii?: KapiThemeRadii | undefined;
|
|
42
44
|
};
|
|
43
|
-
/** A px length such as `10px` or `999px`: what the `control` and `surface` knobs accept. */
|
|
45
|
+
/** A px length such as `10px` or `999px`: what the `control`, `box` and `surface` knobs accept. */
|
|
44
46
|
export declare const RADIUS_PX_PATTERN: RegExp;
|
|
45
47
|
/** A px length or a percentage such as `32%`: what the `squircle` knob accepts. */
|
|
46
48
|
export declare const RADIUS_SHAPE_PATTERN: RegExp;
|
|
@@ -8,21 +8,28 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
8
8
|
"--kapi-radius-md": 1,
|
|
9
9
|
"--kapi-radius-group": 1.1
|
|
10
10
|
}, c = {
|
|
11
|
+
"--kapi-radius-check": .6,
|
|
12
|
+
"--kapi-radius-box": 1
|
|
13
|
+
}, l = {
|
|
11
14
|
"--kapi-radius-lg": 12 / 18,
|
|
12
15
|
"--kapi-radius-xl": 14 / 18,
|
|
13
16
|
"--kapi-radius": 16 / 18,
|
|
14
17
|
"--kapi-radius-surface": 1
|
|
15
|
-
},
|
|
16
|
-
let t = {}, n = [
|
|
18
|
+
}, u = (e, t) => `${Math.min(999, Math.round(e * t * 10) / 10)}px`, d = (e) => {
|
|
19
|
+
let t = {}, n = [
|
|
20
|
+
[e.control, s],
|
|
21
|
+
[e.box, c],
|
|
22
|
+
[e.surface, l]
|
|
23
|
+
];
|
|
17
24
|
for (let [e, r] of n) {
|
|
18
25
|
let n = e?.trim();
|
|
19
26
|
if (!n || !a.test(n)) continue;
|
|
20
27
|
let i = parseFloat(n);
|
|
21
|
-
for (let [e, n] of Object.entries(r)) t[e] =
|
|
28
|
+
for (let [e, n] of Object.entries(r)) t[e] = u(i, n);
|
|
22
29
|
}
|
|
23
30
|
let r = e.squircle?.trim();
|
|
24
31
|
return r && o.test(r) && (t["--kapi-radius-squircle"] = r), t;
|
|
25
|
-
},
|
|
32
|
+
}, f = {
|
|
26
33
|
light: {
|
|
27
34
|
bg: "#f4f2fb",
|
|
28
35
|
card: "#ffffff",
|
|
@@ -45,64 +52,64 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
45
52
|
warning: "#e0a44e",
|
|
46
53
|
danger: "#f06a8a"
|
|
47
54
|
}
|
|
48
|
-
},
|
|
55
|
+
}, p = Object.keys(f.light), m = 4.5, h = {
|
|
49
56
|
"--kapi-ink-2": 12,
|
|
50
57
|
"--kapi-ink-3": 22,
|
|
51
58
|
"--kapi-muted": 28,
|
|
52
59
|
"--kapi-muted-2": 32
|
|
53
|
-
},
|
|
60
|
+
}, g = {
|
|
54
61
|
r: 255,
|
|
55
62
|
g: 255,
|
|
56
63
|
b: 255,
|
|
57
64
|
a: 1
|
|
58
|
-
},
|
|
65
|
+
}, _ = {
|
|
59
66
|
r: 0,
|
|
60
67
|
g: 0,
|
|
61
68
|
b: 0,
|
|
62
69
|
a: 1
|
|
63
|
-
},
|
|
70
|
+
}, v = [g, {
|
|
64
71
|
r: 15,
|
|
65
72
|
g: 13,
|
|
66
73
|
b: 23,
|
|
67
74
|
a: 1
|
|
68
|
-
}],
|
|
75
|
+
}], y = [
|
|
69
76
|
"success",
|
|
70
77
|
"info",
|
|
71
78
|
"warning",
|
|
72
79
|
"danger"
|
|
73
|
-
],
|
|
80
|
+
], b = (e) => ({
|
|
74
81
|
...e,
|
|
75
82
|
a: 1
|
|
76
|
-
}),
|
|
83
|
+
}), x = (t, r, i, a) => {
|
|
77
84
|
for (let o = i; o > 0; o--) {
|
|
78
85
|
let i = n(r, t, o);
|
|
79
|
-
if (a.every((t) => e(i, t) >=
|
|
86
|
+
if (a.every((t) => e(i, t) >= m)) return i;
|
|
80
87
|
}
|
|
81
88
|
return t;
|
|
82
|
-
},
|
|
83
|
-
let a =
|
|
84
|
-
for (let n of
|
|
89
|
+
}, S = (e, t) => `rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`, C = (e) => {
|
|
90
|
+
let a = f[e.base], o = e.base === "dark", s = {}, c = {}, l = /* @__PURE__ */ new Set();
|
|
91
|
+
for (let n of p) {
|
|
85
92
|
let i = e.colors[n] === void 0 ? null : r(e.colors[n]);
|
|
86
|
-
i && (l.add(n), s[`--kapi-${n}`] = t(i)), c[n] =
|
|
93
|
+
i && (l.add(n), s[`--kapi-${n}`] = t(i)), c[n] = b(i ?? r(a[n]));
|
|
87
94
|
}
|
|
88
|
-
let
|
|
89
|
-
|
|
90
|
-
let { bg:
|
|
91
|
-
E && (s["--kapi-surface"] = T(O), s["--kapi-soft"] = T(k), s["--kapi-border"] = T(A), s["--kapi-divider"] = T(n(C,
|
|
95
|
+
let u = e.colors.font?.trim();
|
|
96
|
+
u && (s["--kapi-font"] = u), e.radii && Object.assign(s, d(e.radii));
|
|
97
|
+
let { bg: m, card: g, 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(m, g, 60), k = n(m, g, 30), A = n(C, w, 92), j = n(m, w, 96);
|
|
98
|
+
E && (s["--kapi-surface"] = T(O), s["--kapi-soft"] = T(k), s["--kapi-border"] = T(A), s["--kapi-divider"] = T(n(C, g, 50)), s["--kapi-tab"] = T(j), s["--kapi-sk-base"] = T(n(m, w, 94)), s["--kapi-sk-shine"] = T(o ? A : n(g, m, 50)));
|
|
92
99
|
let M = [
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
m,
|
|
101
|
+
g,
|
|
95
102
|
O,
|
|
96
103
|
k,
|
|
97
104
|
j
|
|
98
105
|
], N = {};
|
|
99
|
-
for (let [e, t] of Object.entries(
|
|
100
|
-
l.has("primary") && (s["--kapi-primary-fg"] = T(i(c.primary,
|
|
101
|
-
let P =
|
|
106
|
+
for (let [e, t] of Object.entries(h)) N[e] = x(w, m, t, M), D && (s[e] = T(N[e]));
|
|
107
|
+
l.has("primary") && (s["--kapi-primary-fg"] = T(i(c.primary, v)));
|
|
108
|
+
let P = y.filter((e) => l.has(e)).map((e) => [e, c[e]]);
|
|
102
109
|
D && P.push(["neutral", N["--kapi-muted-2"]]);
|
|
103
|
-
for (let [e, t] of P) s[`--kapi-${e}-bg`] = T(n(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 ?
|
|
110
|
+
for (let [e, t] of P) s[`--kapi-${e}-bg`] = T(n(t, g, o ? 16 : 12)), s[`--kapi-${e}-border`] = T(n(t, g, o ? 35 : 28)), s[`--kapi-${e}-fg`] = T(i(t, v));
|
|
111
|
+
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, v)));
|
|
112
|
+
let F = o ? _ : n(w, _, 60), I = o ? {
|
|
106
113
|
base: .55,
|
|
107
114
|
soft: .3,
|
|
108
115
|
tour: .65,
|
|
@@ -119,7 +126,7 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
119
126
|
strong: .6,
|
|
120
127
|
edge: .06
|
|
121
128
|
};
|
|
122
|
-
return l.has("ink") && !o && (s["--kapi-scrim"] =
|
|
129
|
+
return l.has("ink") && !o && (s["--kapi-scrim"] = S(F, I.base), s["--kapi-scrim-soft"] = S(F, I.soft), s["--kapi-scrim-tour"] = S(F, I.tour), s["--kapi-scrim-drawer"] = S(F, I.drawer), s["--kapi-scrim-cmdk"] = S(F, I.cmdk), s["--kapi-scrim-strong"] = S(F, I.strong), s["--kapi-edge-shade"] = S(F, I.edge)), s;
|
|
123
130
|
};
|
|
124
131
|
//#endregion
|
|
125
|
-
export { a as RADIUS_PX_PATTERN, o as RADIUS_SHAPE_PATTERN,
|
|
132
|
+
export { a as RADIUS_PX_PATTERN, o as RADIUS_SHAPE_PATTERN, C as deriveTheme };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type KapiThemeRadii } from "./themeDeriveLogic";
|
|
2
2
|
/** Shared empty value, so "no radii" is referentially stable across renders. */
|
|
3
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 %). */
|
|
4
|
+
/** Keeps only known knobs whose value is a well-formed length (`control`/`box`/`surface`: px; `squircle`: px or %). */
|
|
5
5
|
export declare const sanitizeThemeRadii: (input: unknown) => KapiThemeRadii;
|
|
6
6
|
/** Parses the stored JSON. Broken or invalid JSON counts as "no radii"; it never throws. */
|
|
7
7
|
export declare const parseStoredThemeRadii: (raw: string | null | undefined) => KapiThemeRadii;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export type UseWheelZoomOptions = {
|
|
3
|
+
/** Nivel actual. */
|
|
4
|
+
value: number;
|
|
5
|
+
/** Nivel nuevo, ya acotado y pegado al paso. Sólo se llama si el valor cambió. */
|
|
6
|
+
onChange: (value: number) => void;
|
|
7
|
+
/** Mínimo. */
|
|
8
|
+
min: number;
|
|
9
|
+
/** Máximo. */
|
|
10
|
+
max: number;
|
|
11
|
+
/** Cuánto cambia por cada evento de rueda. */
|
|
12
|
+
step: number;
|
|
13
|
+
/** Sólo con Ctrl/Cmd apretado; sin él la rueda scrollea normal. @default true */
|
|
14
|
+
requireModifier?: boolean | undefined;
|
|
15
|
+
/** Escucha sólo mientras sea true. @default true */
|
|
16
|
+
enabled?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Zoom con Ctrl + rueda del mouse sobre un elemento. Devolvé el ref al elemento (`<div ref={ref} />`).
|
|
20
|
+
*
|
|
21
|
+
* El pellizco de trackpad llega como eventos `wheel` con `ctrlKey: true`, así que el mismo código cubre
|
|
22
|
+
* los dos gestos. Un paso por evento (ver `nextWheelZoom`): deltaY negativo acerca.
|
|
23
|
+
*
|
|
24
|
+
* POR QUÉ ES UN HOOK Y NO UN `onWheel`: React registra `wheel` como listener PASIVO en el contenedor
|
|
25
|
+
* raíz, y en un listener pasivo `preventDefault()` se ignora sin avisar. Con Ctrl apretado el navegador
|
|
26
|
+
* entonces zoomea la PÁGINA entera además de tu control (medido en Chromium: `defaultPrevented: false`
|
|
27
|
+
* con el listener pasivo, `true` con uno no pasivo). Acá el listener se ata a mano con
|
|
28
|
+
* `{ passive: false }`, que es lo único que le devuelve el zoom al elemento.
|
|
29
|
+
*/
|
|
30
|
+
export declare const useWheelZoom: <T extends HTMLElement = HTMLDivElement>(options: UseWheelZoomOptions) => RefObject<T | null>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { nextWheelZoom as e } from "./wheelZoomLogic.js";
|
|
3
|
+
import { useEffect as t, useRef as n } from "react";
|
|
4
|
+
//#region src/hooks/useWheelZoom.ts
|
|
5
|
+
var r = (r) => {
|
|
6
|
+
let i = n(null), a = n(r);
|
|
7
|
+
a.current = r;
|
|
8
|
+
let o = r.enabled ?? !0;
|
|
9
|
+
return t(() => {
|
|
10
|
+
let t = i.current;
|
|
11
|
+
if (!t || !o) return;
|
|
12
|
+
let n = (t) => {
|
|
13
|
+
let { value: n, onChange: r, min: i, max: o, step: s, requireModifier: c = !0 } = a.current;
|
|
14
|
+
if (c && !t.ctrlKey && !t.metaKey) return;
|
|
15
|
+
t.preventDefault();
|
|
16
|
+
let l = e(n, t.deltaY, {
|
|
17
|
+
min: i,
|
|
18
|
+
max: o,
|
|
19
|
+
step: s
|
|
20
|
+
});
|
|
21
|
+
l !== n && r(l);
|
|
22
|
+
};
|
|
23
|
+
return t.addEventListener("wheel", n, { passive: !1 }), () => t.removeEventListener("wheel", n);
|
|
24
|
+
}, [o]), i;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { r as useWheelZoom };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type WheelZoomRange = {
|
|
2
|
+
min: number;
|
|
3
|
+
max: number;
|
|
4
|
+
step: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Nivel siguiente para un `deltaY` de rueda: un paso por evento, acotado y pegado a la grilla del paso.
|
|
8
|
+
*
|
|
9
|
+
* Se usa el SIGNO de `deltaY`, no su magnitud. Con el trackpad llegan muchos eventos seguidos y el zoom
|
|
10
|
+
* avanza rápido; la alternativa (acumular delta hasta un umbral) vuelve impredecible cuánto zoom hace un
|
|
11
|
+
* gesto, y los pasos tienen que ser los mismos que los de los botones +/− del visor. `deltaY < 0`
|
|
12
|
+
* (rueda hacia arriba, pellizco de apertura) acerca; `deltaY === 0` no hace nada.
|
|
13
|
+
*
|
|
14
|
+
* La grilla está anclada en `min`: con `min: 50` y `step: 25`, desde 110 acercar da 125 y alejar da 100.
|
|
15
|
+
* Un `value` fuera de rango se acota primero (NaN cae en `min`). Con un `step` no positivo o un rango
|
|
16
|
+
* inválido devuelve `value` tal cual: no hay grilla sobre la cual moverse.
|
|
17
|
+
*/
|
|
18
|
+
export declare const nextWheelZoom: (value: number, deltaY: number, range: WheelZoomRange) => number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/hooks/wheelZoomLogic.ts
|
|
2
|
+
var e = 1e-9, t = (t, n, r) => {
|
|
3
|
+
let { min: i, max: a, step: o } = r;
|
|
4
|
+
if (!(Number.isFinite(i) && Number.isFinite(a) && Number.isFinite(o) && o > 0 && i <= a) || n === 0 || Number.isNaN(n)) return t;
|
|
5
|
+
let s = ((Number.isNaN(t) ? i : Math.min(a, Math.max(i, t))) - i) / o, c = n < 0 ? Math.floor(s + e) + 1 : Math.ceil(s - e) - 1;
|
|
6
|
+
return Math.min(a, Math.max(i, i + c * o));
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as nextWheelZoom };
|