@kapiuara/ui 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/README.md +69 -4
- package/dist/components/chat/KapiComposer.d.ts +2 -2
- package/dist/components/chat/KapiComposer.js +47 -45
- package/dist/components/data/KapiTable.d.ts +25 -1
- package/dist/components/data/KapiTable.js +408 -390
- package/dist/components/data/index.d.ts +1 -1
- package/dist/components/data/tableLogic.d.ts +7 -0
- package/dist/components/data/tableLogic.js +21 -16
- package/dist/components/inputs/KapiButton.d.ts +9 -2
- package/dist/components/inputs/KapiButton.js +25 -15
- package/dist/components/inputs/KapiFacetedSearch.d.ts +29 -5
- package/dist/components/inputs/KapiFacetedSearch.js +161 -119
- package/dist/components/inputs/KapiSegmented.d.ts +2 -1
- package/dist/components/inputs/KapiSegmented.js +45 -44
- package/dist/components/inputs/facetedSearchLogic.d.ts +40 -9
- package/dist/components/inputs/facetedSearchLogic.js +38 -20
- package/dist/components/inputs/index.d.ts +2 -2
- package/dist/components/layout/KapiRail.d.ts +1 -1
- package/dist/components/layout/KapiRail.js +57 -50
- package/dist/components/layout/KapiShell.d.ts +9 -2
- package/dist/components/layout/KapiShell.js +22 -22
- package/dist/components/navigation/KapiTabs.d.ts +3 -1
- package/dist/components/navigation/KapiTabs.js +47 -46
- package/dist/components/overlays/KapiCanvasForm.js +2 -6
- package/dist/components/overlays/KapiConfirm.js +1 -6
- package/dist/hooks/colorLogic.d.ts +26 -0
- package/dist/hooks/colorLogic.js +53 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/numberFormatLogic.d.ts +6 -0
- package/dist/hooks/numberFormatLogic.js +7 -0
- package/dist/hooks/rightClick.d.ts +10 -0
- package/dist/hooks/rightClick.js +10 -4
- package/dist/hooks/themeColorsLogic.d.ts +11 -0
- package/dist/hooks/themeColorsLogic.js +37 -0
- package/dist/hooks/themeContrastLogic.d.ts +23 -0
- package/dist/hooks/themeContrastLogic.js +46 -0
- package/dist/hooks/themeDeriveLogic.d.ts +52 -0
- package/dist/hooks/themeDeriveLogic.js +103 -0
- package/dist/hooks/useDragScroll.js +26 -23
- package/dist/hooks/useGlobalRightClick.js +28 -25
- package/dist/hooks/useKapiTheme.d.ts +28 -4
- package/dist/hooks/useKapiTheme.js +82 -50
- package/dist/index.js +129 -126
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/hooks/numberFormatLogic.ts
|
|
2
|
+
var e = /* @__PURE__ */ new Map(), t = (t) => {
|
|
3
|
+
let n = e.get(t);
|
|
4
|
+
return n || (n = new Intl.NumberFormat(t, { maximumFractionDigits: 0 }), e.set(t, n)), n;
|
|
5
|
+
}, n = (e, n = "es") => Number.isFinite(e) ? t(n).format(Math.round(e)) : "";
|
|
6
|
+
//#endregion
|
|
7
|
+
export { n as formatCount };
|
|
@@ -25,6 +25,16 @@ export declare const clampMenuPosition: (x: number, y: number, size: {
|
|
|
25
25
|
left: number;
|
|
26
26
|
top: number;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Ejes en los que `el` realmente scrollea: el autor lo permite (`overflow` en `auto`/`scroll`) y además hay
|
|
30
|
+
* desborde. Ojo: `overflow: hidden` NO impide el scroll programático (sigue siendo un contenedor de scroll;
|
|
31
|
+
* sólo recorta y esconde la barra), así que asignar `scrollLeft`/`scrollTop` en un eje `hidden` con desborde
|
|
32
|
+
* lo mueve de verdad. Un arrastre tiene que escribir sólo los ejes que devuelve esto.
|
|
33
|
+
*/
|
|
34
|
+
export declare const scrollableAxes: (el: HTMLElement) => {
|
|
35
|
+
x: boolean;
|
|
36
|
+
y: boolean;
|
|
37
|
+
};
|
|
28
38
|
/** Primer ancestro (incluido el nodo) que realmente scrollea en X o en Y. */
|
|
29
39
|
export declare const findScrollableAncestor: (node: EventTarget | null) => HTMLElement | null;
|
|
30
40
|
export declare const isInteractiveTarget: (target: EventTarget | null) => boolean;
|
package/dist/hooks/rightClick.js
CHANGED
|
@@ -19,12 +19,18 @@ var t = "button, a, input, select, textarea, label, [role=button], [data-no-drag
|
|
|
19
19
|
top: c
|
|
20
20
|
};
|
|
21
21
|
}, o = (e) => {
|
|
22
|
+
let t = getComputedStyle(e);
|
|
23
|
+
return {
|
|
24
|
+
x: /(auto|scroll)/.test(t.overflowX) && e.scrollWidth > e.clientWidth,
|
|
25
|
+
y: /(auto|scroll)/.test(t.overflowY) && e.scrollHeight > e.clientHeight
|
|
26
|
+
};
|
|
27
|
+
}, s = (e) => {
|
|
22
28
|
for (let t = e; t && t !== document.body; t = t.parentElement) {
|
|
23
29
|
if (!(t instanceof HTMLElement)) continue;
|
|
24
|
-
let
|
|
25
|
-
if (
|
|
30
|
+
let { x: e, y: n } = o(t);
|
|
31
|
+
if (e || n) return t;
|
|
26
32
|
}
|
|
27
33
|
return null;
|
|
28
|
-
},
|
|
34
|
+
}, c = (e) => e instanceof Element && e.closest("button, a, input, select, textarea, label, [role=button], [data-no-drag]") !== null, l = (e, t) => (e || t) !== "touch";
|
|
29
35
|
//#endregion
|
|
30
|
-
export { t as INTERACTIVE_SELECTOR, i as POINT_MENU_PLACEMENT, a as clampMenuPosition, n as exceedsDragThreshold,
|
|
36
|
+
export { t as INTERACTIVE_SELECTOR, i as POINT_MENU_PLACEMENT, a as clampMenuPosition, n as exceedsDragThreshold, s as findScrollableAncestor, r as isDoubleRightClick, c as isInteractiveTarget, o as scrollableAxes, l as shouldInterceptContextMenu };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KapiThemeColors } from "./themeDeriveLogic";
|
|
2
|
+
/** Shared empty value, so "no theme" is referentially stable across renders. */
|
|
3
|
+
export declare const NO_THEME_COLORS: KapiThemeColors;
|
|
4
|
+
/** Keeps only known keys with non-empty string values. */
|
|
5
|
+
export declare const sanitizeThemeColors: (input: unknown) => KapiThemeColors;
|
|
6
|
+
/** Parses the stored JSON. Broken or invalid JSON counts as "no theme"; it never throws. */
|
|
7
|
+
export declare const parseStoredThemeColors: (raw: string | null | undefined) => KapiThemeColors;
|
|
8
|
+
/** Serializes for storage; "no theme" is the empty string (like the accent). */
|
|
9
|
+
export declare const serializeThemeColors: (colors: KapiThemeColors) => string;
|
|
10
|
+
/** Merges layers left to right: a later layer wins color by color; unset values never clobber. */
|
|
11
|
+
export declare const mergeThemeColors: (...layers: (KapiThemeColors | null | undefined)[]) => KapiThemeColors;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/hooks/themeColorsLogic.ts
|
|
2
|
+
var e = [
|
|
3
|
+
"bg",
|
|
4
|
+
"card",
|
|
5
|
+
"line",
|
|
6
|
+
"primary",
|
|
7
|
+
"ink",
|
|
8
|
+
"success",
|
|
9
|
+
"info",
|
|
10
|
+
"warning",
|
|
11
|
+
"danger",
|
|
12
|
+
"font"
|
|
13
|
+
], t = Object.freeze({}), n = (n) => {
|
|
14
|
+
if (typeof n != "object" || !n || Array.isArray(n)) return t;
|
|
15
|
+
let r = n, i = {};
|
|
16
|
+
for (let t of e) {
|
|
17
|
+
let e = r[t];
|
|
18
|
+
typeof e == "string" && e.trim() && (i[t] = e.trim());
|
|
19
|
+
}
|
|
20
|
+
return Object.keys(i).length ? i : t;
|
|
21
|
+
}, r = (e) => {
|
|
22
|
+
if (!e) return t;
|
|
23
|
+
try {
|
|
24
|
+
return n(JSON.parse(e));
|
|
25
|
+
} catch {
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
}, i = (e) => Object.keys(e).length ? JSON.stringify(e) : "", a = (...t) => {
|
|
29
|
+
let n = {};
|
|
30
|
+
for (let r of t) if (r) for (let t of e) {
|
|
31
|
+
let e = r[t];
|
|
32
|
+
e && (n[t] = e);
|
|
33
|
+
}
|
|
34
|
+
return n;
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { t as NO_THEME_COLORS, a as mergeThemeColors, r as parseStoredThemeColors, n as sanitizeThemeColors, i as serializeThemeColors };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** One text-on-background pair that falls below the threshold. */
|
|
2
|
+
export type KapiThemeContrastFailure = {
|
|
3
|
+
/** Token that carries the text, e.g. `--kapi-muted`. */
|
|
4
|
+
foreground: string;
|
|
5
|
+
/** Token behind it, e.g. `--kapi-card`. */
|
|
6
|
+
background: string;
|
|
7
|
+
/** Measured WCAG contrast ratio, 1 to 21. */
|
|
8
|
+
ratio: number;
|
|
9
|
+
/** The minimum it had to reach. */
|
|
10
|
+
threshold: number;
|
|
11
|
+
};
|
|
12
|
+
/** Options of `checkThemeContrast`. */
|
|
13
|
+
export type KapiThemeContrastOptions = {
|
|
14
|
+
/** Minimum ratio a pair must reach. @default 4.5 */
|
|
15
|
+
threshold?: number | undefined;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Measures the text pairs of a RESOLVED token map and returns those under `threshold` (4.5:1 by
|
|
19
|
+
* default), worst first. A pair is skipped when either token is missing or isn't a plain color
|
|
20
|
+
* (hex or `rgb()`): values that are still `color-mix()` or `var()` can't be measured here, so
|
|
21
|
+
* resolve them first (e.g. from `getComputedStyle`) to include them. Alpha is ignored.
|
|
22
|
+
*/
|
|
23
|
+
export declare const checkThemeContrast: (tokens: Readonly<Partial<Record<string, string>>>, options?: KapiThemeContrastOptions) => KapiThemeContrastFailure[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { contrastRatio as e, parseColor as t } from "./colorLogic.js";
|
|
2
|
+
//#region src/hooks/themeContrastLogic.ts
|
|
3
|
+
var n = 4.5, r = [
|
|
4
|
+
"--kapi-bg",
|
|
5
|
+
"--kapi-card",
|
|
6
|
+
"--kapi-surface",
|
|
7
|
+
"--kapi-soft"
|
|
8
|
+
], i = [
|
|
9
|
+
"--kapi-ink",
|
|
10
|
+
"--kapi-ink-2",
|
|
11
|
+
"--kapi-ink-3",
|
|
12
|
+
"--kapi-muted",
|
|
13
|
+
"--kapi-muted-2"
|
|
14
|
+
], a = [
|
|
15
|
+
"primary",
|
|
16
|
+
"success",
|
|
17
|
+
"info",
|
|
18
|
+
"warning",
|
|
19
|
+
"danger"
|
|
20
|
+
], o = [
|
|
21
|
+
...i.flatMap((e) => r.map((t) => [e, t])),
|
|
22
|
+
...a.flatMap((e) => [
|
|
23
|
+
[`--kapi-${e}`, "--kapi-card"],
|
|
24
|
+
[`--kapi-${e}`, "--kapi-bg"],
|
|
25
|
+
...e === "primary" ? [] : [[`--kapi-${e}`, `--kapi-${e}-bg`]]
|
|
26
|
+
]),
|
|
27
|
+
...[...a, "neutral"].map((e) => [`--kapi-${e}-fg`, `--kapi-${e}`]),
|
|
28
|
+
["--kapi-neutral", "--kapi-card"],
|
|
29
|
+
["--kapi-tip-fg", "--kapi-tip-bg"]
|
|
30
|
+
], s = (r, i = {}) => {
|
|
31
|
+
let a = i.threshold ?? n, s = [];
|
|
32
|
+
for (let [n, i] of o) {
|
|
33
|
+
let o = t(r[n] ?? ""), c = t(r[i] ?? "");
|
|
34
|
+
if (!o || !c) continue;
|
|
35
|
+
let l = e(o, c);
|
|
36
|
+
l < a && s.push({
|
|
37
|
+
foreground: n,
|
|
38
|
+
background: i,
|
|
39
|
+
ratio: l,
|
|
40
|
+
threshold: a
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return s.sort((e, t) => e.ratio - t.ratio);
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { s as checkThemeContrast };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { KapiTokenName } from "@kapiuara/tokens";
|
|
2
|
+
/** The base colors a custom theme sets; everything else is derived from them. */
|
|
3
|
+
export type KapiThemeColors = {
|
|
4
|
+
/** Page background (`--kapi-bg`). */
|
|
5
|
+
bg?: string | undefined;
|
|
6
|
+
/** Card and raised-surface background (`--kapi-card`). */
|
|
7
|
+
card?: string | undefined;
|
|
8
|
+
/** Hairlines and dividers' base (`--kapi-line`). */
|
|
9
|
+
line?: string | undefined;
|
|
10
|
+
/** Brand color (`--kapi-primary`). */
|
|
11
|
+
primary?: string | undefined;
|
|
12
|
+
/** Main text color (`--kapi-ink`). */
|
|
13
|
+
ink?: string | undefined;
|
|
14
|
+
/** Success state color (`--kapi-success`). */
|
|
15
|
+
success?: string | undefined;
|
|
16
|
+
/** Informational state color (`--kapi-info`). */
|
|
17
|
+
info?: string | undefined;
|
|
18
|
+
/** Warning state color (`--kapi-warning`). */
|
|
19
|
+
warning?: string | undefined;
|
|
20
|
+
/** Danger state color (`--kapi-danger`). */
|
|
21
|
+
danger?: string | undefined;
|
|
22
|
+
/** Font stack, passed through as-is (`--kapi-font`). */
|
|
23
|
+
font?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
/** A user theme: which built-in theme it stands on, and the base values it overrides. */
|
|
26
|
+
export type KapiCustomTheme = {
|
|
27
|
+
/** The built-in theme that supplies everything not derived, and the defaults for unset colors. */
|
|
28
|
+
base: "light" | "dark";
|
|
29
|
+
/** The base values; an unset or unparseable color falls back to the base theme's own. */
|
|
30
|
+
colors: KapiThemeColors;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Derives the override map for a user theme. Colors that are unset or can't be parsed fall back
|
|
34
|
+
* to the base theme's for the math; alpha is ignored (colors are treated as opaque). The values
|
|
35
|
+
* the user set are echoed back as tokens.
|
|
36
|
+
*
|
|
37
|
+
* Derived tokens are emitted PER FAMILY, only when an input they depend on was actually set,
|
|
38
|
+
* because emitting more overwrites hand-tuned values the user never asked to change (setting just
|
|
39
|
+
* the accent must touch nothing but `--kapi-primary`, as `accent` does today):
|
|
40
|
+
* - surfaces (`surface`, `soft`, `border`, `divider`, `tab`, `sk-base`, `sk-shine`): `bg`, `card` or `line`;
|
|
41
|
+
* - ink ramp (`ink-2`, `ink-3`, `muted`, `muted-2`) and neutral (`neutral` + `-bg`/`-border`/`-fg`, which
|
|
42
|
+
* follow `muted-2`): `ink`, or any surface input (the contrast cap depends on the surfaces);
|
|
43
|
+
* - each state (`success`/`info`/`warning`/`danger` with `-bg`, `-border`, `-fg`): that state's color;
|
|
44
|
+
* - `--kapi-primary-fg`: `primary`;
|
|
45
|
+
* - tooltip (`tip-bg`, `tip-fg`): `ink`; scrims (`scrim*`, `edge-shade`): `ink` on a light base (on a dark
|
|
46
|
+
* base they are neutral black and equal the base theme's, so they are never emitted).
|
|
47
|
+
*
|
|
48
|
+
* The ink ramp is capped by contrast: each step lightens toward the background, but stops where
|
|
49
|
+
* it would drop under 4.5:1 against any surface that carries text. That cap is what makes a user
|
|
50
|
+
* theme safe to ship.
|
|
51
|
+
*/
|
|
52
|
+
export declare const deriveTheme: (theme: KapiCustomTheme) => Partial<Record<KapiTokenName, string>>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { contrastRatio as e, formatHex as t, mixColors as n, parseColor as r, readableForeground as i } from "./colorLogic.js";
|
|
2
|
+
//#region src/hooks/themeDeriveLogic.ts
|
|
3
|
+
var a = {
|
|
4
|
+
light: {
|
|
5
|
+
bg: "#f4f2fb",
|
|
6
|
+
card: "#ffffff",
|
|
7
|
+
line: "#ece8f7",
|
|
8
|
+
primary: "#5457e0",
|
|
9
|
+
ink: "#342f4a",
|
|
10
|
+
success: "#137a44",
|
|
11
|
+
info: "#1b649f",
|
|
12
|
+
warning: "#9a580b",
|
|
13
|
+
danger: "#b02240"
|
|
14
|
+
},
|
|
15
|
+
dark: {
|
|
16
|
+
bg: "#14121d",
|
|
17
|
+
card: "#1e1b2b",
|
|
18
|
+
line: "#322d45",
|
|
19
|
+
primary: "#8487f2",
|
|
20
|
+
ink: "#ece9f7",
|
|
21
|
+
success: "#4ec98a",
|
|
22
|
+
info: "#6bb6ef",
|
|
23
|
+
warning: "#e0a44e",
|
|
24
|
+
danger: "#f06a8a"
|
|
25
|
+
}
|
|
26
|
+
}, o = Object.keys(a.light), s = 4.5, c = {
|
|
27
|
+
"--kapi-ink-2": 12,
|
|
28
|
+
"--kapi-ink-3": 22,
|
|
29
|
+
"--kapi-muted": 28,
|
|
30
|
+
"--kapi-muted-2": 32
|
|
31
|
+
}, l = {
|
|
32
|
+
r: 255,
|
|
33
|
+
g: 255,
|
|
34
|
+
b: 255,
|
|
35
|
+
a: 1
|
|
36
|
+
}, u = {
|
|
37
|
+
r: 0,
|
|
38
|
+
g: 0,
|
|
39
|
+
b: 0,
|
|
40
|
+
a: 1
|
|
41
|
+
}, d = [l, {
|
|
42
|
+
r: 15,
|
|
43
|
+
g: 13,
|
|
44
|
+
b: 23,
|
|
45
|
+
a: 1
|
|
46
|
+
}], f = [
|
|
47
|
+
"success",
|
|
48
|
+
"info",
|
|
49
|
+
"warning",
|
|
50
|
+
"danger"
|
|
51
|
+
], p = (e) => ({
|
|
52
|
+
...e,
|
|
53
|
+
a: 1
|
|
54
|
+
}), m = (t, r, i, a) => {
|
|
55
|
+
for (let o = i; o > 0; o--) {
|
|
56
|
+
let i = n(r, t, o);
|
|
57
|
+
if (a.every((t) => e(i, t) >= s)) return i;
|
|
58
|
+
}
|
|
59
|
+
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) {
|
|
63
|
+
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]));
|
|
65
|
+
}
|
|
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,
|
|
74
|
+
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 ? {
|
|
84
|
+
base: .55,
|
|
85
|
+
soft: .3,
|
|
86
|
+
tour: .65,
|
|
87
|
+
drawer: .55,
|
|
88
|
+
cmdk: .55,
|
|
89
|
+
strong: .7,
|
|
90
|
+
edge: .35
|
|
91
|
+
} : {
|
|
92
|
+
base: .42,
|
|
93
|
+
soft: .2,
|
|
94
|
+
tour: .55,
|
|
95
|
+
drawer: .45,
|
|
96
|
+
cmdk: .36,
|
|
97
|
+
strong: .6,
|
|
98
|
+
edge: .06
|
|
99
|
+
};
|
|
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;
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { g as deriveTheme };
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { exceedsDragThreshold as e, isDoubleRightClick as t, isInteractiveTarget as n } from "./rightClick.js";
|
|
3
|
-
import { useEffect as
|
|
2
|
+
import { exceedsDragThreshold as e, isDoubleRightClick as t, isInteractiveTarget as n, scrollableAxes as r } from "./rightClick.js";
|
|
3
|
+
import { useEffect as i, useRef as a } from "react";
|
|
4
4
|
//#region src/hooks/useDragScroll.ts
|
|
5
|
-
var
|
|
6
|
-
let
|
|
7
|
-
return
|
|
8
|
-
let
|
|
9
|
-
if (!
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
var o = (o = {}) => {
|
|
6
|
+
let s = a(null), c = a(o);
|
|
7
|
+
return c.current = o, i(() => {
|
|
8
|
+
let i = s.current;
|
|
9
|
+
if (!i) return;
|
|
10
|
+
let a = !1, o = !1, l = 0, u = 0, d = 0, f = 0, p = {
|
|
11
|
+
x: !1,
|
|
12
|
+
y: !1
|
|
13
|
+
}, m = 0, h = (e) => {
|
|
14
|
+
e.button === 2 && (n(e.target) || (e.stopPropagation(), a = !0, o = !1, l = e.pageX, u = e.pageY, d = i.scrollLeft, f = i.scrollTop, p = r(i)));
|
|
15
|
+
}, g = (t) => {
|
|
16
|
+
if (!a) return;
|
|
17
|
+
let n = t.pageX - l, r = t.pageY - u;
|
|
18
|
+
!o && e(n, r) && (o = !0, i.classList.add("kapi-grabbing")), o && (t.preventDefault(), p.x && (i.scrollLeft = d - n), p.y && (i.scrollTop = f - r));
|
|
19
|
+
}, _ = () => {
|
|
20
|
+
a = !1, i.classList.remove("kapi-grabbing");
|
|
21
|
+
}, v = (e) => {
|
|
22
|
+
if (e.preventDefault(), e.stopPropagation(), o) {
|
|
23
|
+
o = !1, m = 0;
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
23
26
|
let n = Date.now();
|
|
24
|
-
t(n,
|
|
27
|
+
t(n, m) ? (c.current.onMenu?.(e.clientX, e.clientY), m = 0) : m = n;
|
|
25
28
|
};
|
|
26
|
-
return
|
|
27
|
-
|
|
29
|
+
return i.addEventListener("mousedown", h), window.addEventListener("mousemove", g), window.addEventListener("mouseup", _), i.addEventListener("contextmenu", v), () => {
|
|
30
|
+
i.removeEventListener("mousedown", h), window.removeEventListener("mousemove", g), window.removeEventListener("mouseup", _), i.removeEventListener("contextmenu", v);
|
|
28
31
|
};
|
|
29
|
-
}, []),
|
|
32
|
+
}, []), s;
|
|
30
33
|
};
|
|
31
34
|
//#endregion
|
|
32
|
-
export {
|
|
35
|
+
export { o as useDragScroll };
|
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { exceedsDragThreshold as e, findScrollableAncestor as t, isDoubleRightClick as n, isInteractiveTarget as r,
|
|
3
|
-
import { useEffect as
|
|
2
|
+
import { exceedsDragThreshold as e, findScrollableAncestor as t, isDoubleRightClick as n, isInteractiveTarget as r, scrollableAxes as i, shouldInterceptContextMenu as a } from "./rightClick.js";
|
|
3
|
+
import { useEffect as o, useRef as s } from "react";
|
|
4
4
|
//#region src/hooks/useGlobalRightClick.ts
|
|
5
|
-
var
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
if (!
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
var c = ({ onMenu: c, enabled: l = !0 } = {}) => {
|
|
6
|
+
let u = s(c);
|
|
7
|
+
u.current = c, o(() => {
|
|
8
|
+
if (!l) return;
|
|
9
|
+
let o = 0, s = !1, c = !1, d = null, f = 0, p = 0, m = 0, h = 0, g = {
|
|
10
|
+
x: !1,
|
|
11
|
+
y: !1
|
|
12
|
+
}, _ = null, v = (e) => {
|
|
13
|
+
_ = e.pointerType;
|
|
14
|
+
}, y = (e) => {
|
|
15
|
+
e.button === 2 && (r(e.target) || (d = t(e.target), d && (s = !0, c = !1, f = e.pageX, p = e.pageY, m = d.scrollLeft, h = d.scrollTop, g = i(d))));
|
|
16
|
+
}, b = (t) => {
|
|
17
|
+
if (!s || !d) return;
|
|
18
|
+
let n = t.pageX - f, r = t.pageY - p;
|
|
19
|
+
!c && e(n, r) && (c = !0, document.body.style.userSelect = "none"), c && (t.preventDefault(), g.x && (d.scrollLeft = m - n), g.y && (d.scrollTop = h - r));
|
|
20
|
+
}, x = () => {
|
|
21
|
+
s = !1, d = null, document.body.style.userSelect = "";
|
|
22
|
+
}, S = (e) => {
|
|
20
23
|
let t = "pointerType" in e ? e.pointerType : void 0;
|
|
21
|
-
if (!
|
|
22
|
-
if (e.preventDefault(),
|
|
23
|
-
|
|
24
|
+
if (!a(t, _)) return;
|
|
25
|
+
if (e.preventDefault(), c) {
|
|
26
|
+
c = !1, o = 0;
|
|
24
27
|
return;
|
|
25
28
|
}
|
|
26
29
|
let r = Date.now();
|
|
27
|
-
n(r,
|
|
30
|
+
n(r, o) ? (u.current?.(e.clientX, e.clientY), o = 0) : o = r;
|
|
28
31
|
};
|
|
29
|
-
return document.addEventListener("pointerdown",
|
|
30
|
-
document.removeEventListener("pointerdown",
|
|
32
|
+
return document.addEventListener("pointerdown", v, !0), document.addEventListener("mousedown", y), window.addEventListener("mousemove", b), window.addEventListener("mouseup", x), document.addEventListener("contextmenu", S), () => {
|
|
33
|
+
document.removeEventListener("pointerdown", v, !0), document.removeEventListener("mousedown", y), window.removeEventListener("mousemove", b), window.removeEventListener("mouseup", x), document.removeEventListener("contextmenu", S);
|
|
31
34
|
};
|
|
32
|
-
}, [
|
|
35
|
+
}, [l]);
|
|
33
36
|
};
|
|
34
37
|
//#endregion
|
|
35
|
-
export {
|
|
38
|
+
export { c as useGlobalRightClick };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type CSSProperties } from "react";
|
|
2
|
+
import { type KapiThemeColors } from "./themeDeriveLogic";
|
|
2
3
|
export type KapiTheme = "light" | "dark";
|
|
3
4
|
/** Lo que elige la persona: un tema fijo o `system` (sigue a `prefers-color-scheme` del SO). */
|
|
4
5
|
export type KapiThemePreference = KapiTheme | "system";
|
|
@@ -8,11 +9,11 @@ export type KapiFontKey = "nunito" | "roboto" | "system";
|
|
|
8
9
|
/** Movimiento: `auto` sigue al SO (prefers-reduced-motion); `reduced` lo apaga siempre. */
|
|
9
10
|
export type KapiMotion = "auto" | "reduced";
|
|
10
11
|
/** Preferencias del tema que se guardan. */
|
|
11
|
-
export type KapiThemeStorageName = "theme" | "accent" | "font" | "motion";
|
|
12
|
+
export type KapiThemeStorageName = "theme" | "accent" | "font" | "motion" | "customTheme";
|
|
12
13
|
/** Claves de localStorage del tema para un namespace (default `kapi` → `kapi:theme`…). */
|
|
13
14
|
export declare const themeStorageKeys: (namespace?: string) => Record<KapiThemeStorageName, string>;
|
|
14
15
|
/** Claves viejas (sin namespace): se migran a las nuevas en la primera lectura y se borran. */
|
|
15
|
-
export declare const LEGACY_THEME_KEYS: Record<KapiThemeStorageName, string
|
|
16
|
+
export declare const LEGACY_THEME_KEYS: Partial<Record<KapiThemeStorageName, string>>;
|
|
16
17
|
export declare const THEME_KEY: string;
|
|
17
18
|
export declare const ACCENT_KEY: string;
|
|
18
19
|
export declare const FONT_KEY: string;
|
|
@@ -26,7 +27,16 @@ export type KapiThemeState = {
|
|
|
26
27
|
preference: KapiThemePreference;
|
|
27
28
|
/** Color de acento (hex) o "" para el primario por defecto. */
|
|
28
29
|
accent: string;
|
|
30
|
+
/**
|
|
31
|
+
* Colores que fijó la persona (se aplican sobre el tema de marca y el acento); `{}` si no hay.
|
|
32
|
+
* Ojo: gana sobre `accent` y sobre la fuente del selector. Quien fije un `primary` propio debería limpiar
|
|
33
|
+
* el acento (`setAccent(null)`); quien fije un `font` propio, no dejarlo en contradicción con `font`
|
|
34
|
+
* (el selector). Si no, ese valor queda como estado muerto y reaparece al resetear el tema propio.
|
|
35
|
+
*/
|
|
36
|
+
customTheme: KapiThemeColors;
|
|
29
37
|
font: KapiFontKey;
|
|
38
|
+
/** `true` si la persona eligió una fuente (hay `kapi:font` guardada); si no, la de la marca manda. */
|
|
39
|
+
fontChosen: boolean;
|
|
30
40
|
/** Preferencia de movimiento del usuario (independiente del `prefers-reduced-motion` del SO). */
|
|
31
41
|
motion: KapiMotion;
|
|
32
42
|
/** Fija un tema (deja de seguir al SO). */
|
|
@@ -36,6 +46,11 @@ export type KapiThemeState = {
|
|
|
36
46
|
/** Alterna sobre el tema que se ve y lo deja fijo. */
|
|
37
47
|
toggle: () => void;
|
|
38
48
|
setAccent: (hex?: string | null) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Fija los colores propios (reemplaza los anteriores); `null` o `{}` los borra. Gana sobre el acento:
|
|
51
|
+
* al fijar un `primary` o un `font` propios corresponde reconciliar el acento y el selector de fuente.
|
|
52
|
+
*/
|
|
53
|
+
setCustomTheme: (colors?: KapiThemeColors | null) => void;
|
|
39
54
|
setFont: (f: KapiFontKey) => void;
|
|
40
55
|
setMotion: (m: KapiMotion) => void;
|
|
41
56
|
/** Alterna entre `auto` y `reduced`. */
|
|
@@ -53,8 +68,17 @@ export declare const readThemePreference: (namespace?: string) => KapiThemePrefe
|
|
|
53
68
|
export declare const toggledPreference: (shown: KapiTheme) => KapiTheme;
|
|
54
69
|
export declare const isFontKey: (v: string) => v is KapiFontKey;
|
|
55
70
|
export declare const isMotion: (v: string) => v is KapiMotion;
|
|
56
|
-
/**
|
|
57
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Style de la raíz .kapi derivado del estado. Los colores se apilan de menor a mayor prioridad:
|
|
73
|
+
* `brand` (la identidad del producto), el acento y `customTheme` (lo que fijó la persona); todo
|
|
74
|
+
* pasa por `deriveTheme` sobre la base `theme` (claro si falta). Sin colores sólo sale `--kapi-font`.
|
|
75
|
+
* Fuente: default < `brand.font` < la fuente que eligió la persona (`fontChosen`) < `customTheme.font`.
|
|
76
|
+
*
|
|
77
|
+
* Un `primary` que `parseColor` no entiende (`red`, `hsl()`: sólo lee hex y `rgb()`), venga del acento, de
|
|
78
|
+
* la marca o del tema propio, se emite tal cual como `--kapi-primary` y se omite sólo el
|
|
79
|
+
* `--kapi-primary-fg` calculado, que es lo único que necesita los números.
|
|
80
|
+
*/
|
|
81
|
+
export declare const themeRootStyle: (state: Pick<KapiThemeState, "font" | "accent"> & Partial<Pick<KapiThemeState, "theme" | "customTheme" | "fontChosen">>, brand?: KapiThemeColors) => CSSProperties;
|
|
58
82
|
export declare const KapiThemeContext: import("react").Context<KapiThemeState>;
|
|
59
83
|
export type KapiThemeStateOptions = {
|
|
60
84
|
/**
|