@kapiuara/ui 0.5.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.
Files changed (74) hide show
  1. package/README.md +123 -5
  2. package/dist/components/chat/KapiChatDivider.d.ts +15 -0
  3. package/dist/components/chat/KapiChatDivider.js +17 -0
  4. package/dist/components/chat/KapiChatList.d.ts +57 -0
  5. package/dist/components/chat/KapiChatList.js +71 -0
  6. package/dist/components/chat/KapiChatThread.d.ts +35 -0
  7. package/dist/components/chat/KapiChatThread.js +85 -0
  8. package/dist/components/chat/KapiComposer.d.ts +60 -0
  9. package/dist/components/chat/KapiComposer.js +91 -0
  10. package/dist/components/chat/KapiMessageBubble.d.ts +43 -0
  11. package/dist/components/chat/KapiMessageBubble.js +67 -0
  12. package/dist/components/chat/KapiTypingIndicator.d.ts +27 -0
  13. package/dist/components/chat/KapiTypingIndicator.js +34 -0
  14. package/dist/components/chat/chatLogic.d.ts +76 -0
  15. package/dist/components/chat/chatLogic.js +34 -0
  16. package/dist/components/chat/index.d.ts +14 -0
  17. package/dist/components/data/KapiTable.d.ts +25 -1
  18. package/dist/components/data/KapiTable.js +408 -390
  19. package/dist/components/data/index.d.ts +1 -1
  20. package/dist/components/data/tableLogic.d.ts +7 -0
  21. package/dist/components/data/tableLogic.js +21 -16
  22. package/dist/components/display/KapiCommentComposer.d.ts +4 -0
  23. package/dist/components/display/KapiCommentComposer.js +43 -46
  24. package/dist/components/display/commentLogic.d.ts +9 -2
  25. package/dist/components/display/commentLogic.js +1 -1
  26. package/dist/components/display/index.d.ts +1 -0
  27. package/dist/components/inputs/KapiButton.d.ts +9 -2
  28. package/dist/components/inputs/KapiButton.js +25 -15
  29. package/dist/components/inputs/KapiFacetedSearch.d.ts +29 -5
  30. package/dist/components/inputs/KapiFacetedSearch.js +161 -119
  31. package/dist/components/inputs/KapiSegmented.d.ts +2 -1
  32. package/dist/components/inputs/KapiSegmented.js +45 -44
  33. package/dist/components/inputs/facetedSearchLogic.d.ts +40 -9
  34. package/dist/components/inputs/facetedSearchLogic.js +38 -20
  35. package/dist/components/inputs/index.d.ts +2 -2
  36. package/dist/components/layout/KapiPanelParts.js +9 -9
  37. package/dist/components/layout/KapiRail.d.ts +1 -1
  38. package/dist/components/layout/KapiRail.js +60 -53
  39. package/dist/components/layout/KapiShell.d.ts +9 -2
  40. package/dist/components/layout/KapiShell.js +22 -22
  41. package/dist/components/locale/labelRegistry.d.ts +10 -0
  42. package/dist/components/navigation/KapiContextPanel.js +86 -86
  43. package/dist/components/navigation/KapiPanelGroup.js +18 -18
  44. package/dist/components/navigation/KapiTabs.d.ts +3 -1
  45. package/dist/components/navigation/KapiTabs.js +47 -46
  46. package/dist/components/navigation/MiniNavItem.js +1 -1
  47. package/dist/components/overlays/KapiCanvasForm.js +2 -6
  48. package/dist/components/overlays/KapiConfirm.js +1 -6
  49. package/dist/hooks/colorLogic.d.ts +26 -0
  50. package/dist/hooks/colorLogic.js +53 -0
  51. package/dist/hooks/dateFormat.d.ts +7 -0
  52. package/dist/hooks/dateFormat.js +16 -2
  53. package/dist/hooks/index.d.ts +7 -1
  54. package/dist/hooks/numberFormatLogic.d.ts +6 -0
  55. package/dist/hooks/numberFormatLogic.js +7 -0
  56. package/dist/hooks/rightClick.d.ts +10 -0
  57. package/dist/hooks/rightClick.js +10 -4
  58. package/dist/hooks/themeColorsLogic.d.ts +11 -0
  59. package/dist/hooks/themeColorsLogic.js +37 -0
  60. package/dist/hooks/themeContrastLogic.d.ts +23 -0
  61. package/dist/hooks/themeContrastLogic.js +46 -0
  62. package/dist/hooks/themeDeriveLogic.d.ts +52 -0
  63. package/dist/hooks/themeDeriveLogic.js +103 -0
  64. package/dist/hooks/useDragScroll.js +26 -23
  65. package/dist/hooks/useGlobalRightClick.js +28 -25
  66. package/dist/hooks/useKapiTheme.d.ts +28 -4
  67. package/dist/hooks/useKapiTheme.js +82 -50
  68. package/dist/hooks/useSubmitDraft.d.ts +34 -0
  69. package/dist/hooks/useSubmitDraft.js +28 -0
  70. package/dist/index.d.ts +1 -0
  71. package/dist/index.js +129 -119
  72. package/dist/kapi.css +1 -1
  73. package/dist/kapi.layered.css +1 -1
  74. package/package.json +3 -3
@@ -0,0 +1,53 @@
1
+ //#region src/hooks/colorLogic.ts
2
+ var e = (e, t, n) => Math.min(n, Math.max(t, e)), t = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, n = String.raw`[+-]?(?:\d+\.?\d*|\.\d+)`, r = new RegExp(String.raw`^rgba?\(\s*(${n})(?:\s*,\s*|\s+)(${n})(?:\s*,\s*|\s+)(${n})` + String.raw`(?:\s*[,/]\s*(${n})(%?))?\s*\)$`, "i"), i = (e) => {
3
+ let t = e.length === 3 ? e.split("").map((e) => e + e).join("") : e, n = (e) => parseInt(t.slice(e, e + 2), 16);
4
+ return {
5
+ r: n(0),
6
+ g: n(2),
7
+ b: n(4),
8
+ a: t.length === 8 ? n(6) / 255 : 1
9
+ };
10
+ }, a = (n) => {
11
+ let a = n.trim(), o = t.exec(a);
12
+ if (o) return i(o[1]);
13
+ let s = r.exec(a);
14
+ if (!s) return null;
15
+ let [c, l, u] = [
16
+ s[1],
17
+ s[2],
18
+ s[3]
19
+ ].map((t) => e(Number(t), 0, 255)), d = 1;
20
+ return s[4] !== void 0 && (d = e(s[5] === "%" ? Number(s[4]) / 100 : Number(s[4]), 0, 1)), {
21
+ r: Math.round(c),
22
+ g: Math.round(l),
23
+ b: Math.round(u),
24
+ a: d
25
+ };
26
+ }, o = (e) => {
27
+ let t = e / 255;
28
+ return t <= .03928 ? t / 12.92 : ((t + .055) / 1.055) ** 2.4;
29
+ }, s = (e) => .2126 * o(e.r) + .7152 * o(e.g) + .0722 * o(e.b), c = (e, t) => {
30
+ let n = s(e), r = s(t);
31
+ return (Math.max(n, r) + .05) / (Math.min(n, r) + .05);
32
+ }, l = (t, n, r) => {
33
+ let i = e(r, 0, 100) / 100, a = (e, t) => e * i + t * (1 - i);
34
+ return {
35
+ r: a(t.r, n.r),
36
+ g: a(t.g, n.g),
37
+ b: a(t.b, n.b),
38
+ a: a(t.a, n.a)
39
+ };
40
+ }, u = (e, t) => {
41
+ let n = t[0], r = c(e, n);
42
+ for (let i of t.slice(1)) {
43
+ let t = c(e, i);
44
+ t > r && (n = i, r = t);
45
+ }
46
+ return n;
47
+ }, d = (t) => "#" + [
48
+ t.r,
49
+ t.g,
50
+ t.b
51
+ ].map((t) => Math.round(e(t, 0, 255)).toString(16).padStart(2, "0")).join("");
52
+ //#endregion
53
+ export { c as contrastRatio, d as formatHex, l as mixColors, a as parseColor, u as readableForeground, s as relativeLuminance };
@@ -5,6 +5,13 @@ export declare const isoDateTime: (date: Date | string) => string | null;
5
5
  * devuelve "". Trunca en vez de redondear: 59,5 minutos es "hace 59 minutos", nunca "hace 60 minutos".
6
6
  */
7
7
  export declare const formatRelativeTime: (date: Date | string, now?: Date, locale?: string) => string;
8
+ /**
9
+ * Etiqueta de un día para separadores de un hilo, según el día local respecto de `now`: hoy y ayer salen de
10
+ * `Intl.RelativeTimeFormat` con `numeric: "auto"` ("hoy", "ayer"); de 2 a 6 días atrás, el nombre del día
11
+ * ("miércoles"); más viejo, día y mes ("12 de marzo") y, de otro año, día, mes y año. Una fecha inválida
12
+ * devuelve "".
13
+ */
14
+ export declare const formatDayLabel: (date: Date, now?: Date, locale?: string) => string;
8
15
  /**
9
16
  * Fecha absoluta con `Intl.DateTimeFormat` (default `{ dateStyle: "medium" }`: "12 mar 2026").
10
17
  * Acepta `Date` o string parseable; una fecha inválida devuelve "".
@@ -7,9 +7,23 @@ var e = 6e4, t = 60 * e, n = 24 * t, r = 7 * n, i = 30 * n, a = 365 * n, o = /*
7
7
  if (!Number.isFinite(d)) return "";
8
8
  let f = d - l.getTime(), p = Math.abs(f), m = s(u);
9
9
  return p < e ? m.format(0, "second") : p < t ? m.format(Math.trunc(f / e), "minute") : p < n ? m.format(Math.trunc(f / t), "hour") : p < r ? m.format(Math.trunc(f / n), "day") : p < i ? m.format(Math.trunc(f / r), "week") : p < a ? m.format(Math.trunc(f / i), "month") : m.format(Math.trunc(f / a), "year");
10
- }, f = (e, t = "es", n = { dateStyle: "medium" }) => {
10
+ }, f = (e) => new Date(e.getFullYear(), e.getMonth(), e.getDate()).getTime(), p = (e, t = /* @__PURE__ */ new Date(), r = "es") => {
11
+ if (!Number.isFinite(e.getTime())) return "";
12
+ let i = Math.round((f(t) - f(e)) / n);
13
+ if (i >= 0 && i <= 1) return s(r).format(-i, "day");
14
+ if (i >= 2 && i <= 6) return new Intl.DateTimeFormat(r, { weekday: "long" }).format(e);
15
+ let a = e.getFullYear() === t.getFullYear();
16
+ return new Intl.DateTimeFormat(r, a ? {
17
+ day: "numeric",
18
+ month: "long"
19
+ } : {
20
+ day: "numeric",
21
+ month: "long",
22
+ year: "numeric"
23
+ }).format(e);
24
+ }, m = (e, t = "es", n = { dateStyle: "medium" }) => {
11
25
  let r = c(e);
12
26
  return Number.isFinite(r) ? new Intl.DateTimeFormat(t, n).format(r) : "";
13
27
  };
14
28
  //#endregion
15
- export { f as formatDate, d as formatRelativeTime, u as isoDateTime };
29
+ export { m as formatDate, p as formatDayLabel, d as formatRelativeTime, u as isoDateTime };
@@ -42,8 +42,14 @@ export type { OnlineEventTarget as KapiOnlineEventTarget, OnlineStatus as KapiOn
42
42
  export { useObjectUrl } from "./useObjectUrl";
43
43
  export { downloadBlob, fileKind, fileNameFromContentDisposition, fileNameFromUrl, formatFileSize } from "./downloadLogic";
44
44
  export type { KapiFileKind } from "./downloadLogic";
45
- export { formatDate, formatRelativeTime, isoDateTime } from "./dateFormat";
45
+ export { formatDate, formatDayLabel, formatRelativeTime, isoDateTime } from "./dateFormat";
46
+ export { contrastRatio, formatHex, mixColors, parseColor, readableForeground, relativeLuminance } from "./colorLogic";
47
+ export type { KapiRgbColor } from "./colorLogic";
46
48
  export { useScrollEdges } from "./useScrollEdges";
47
49
  export type { UseScrollEdgesOptions, UseScrollEdgesResult } from "./useScrollEdges";
48
50
  export { DEFAULT_PAGE_FRACTION, DEFAULT_SCROLL_EDGE_TOLERANCE, maxScroll, pageSize, pageTarget, revealTarget, sameScrollEdges, scrollEdges } from "./scrollEdgesLogic";
49
51
  export type { KapiScrollAxis, ScrollEdges as KapiScrollEdges, ScrollMetrics as KapiScrollMetrics } from "./scrollEdgesLogic";
52
+ export { deriveTheme } from "./themeDeriveLogic";
53
+ export type { KapiCustomTheme, KapiThemeColors } from "./themeDeriveLogic";
54
+ export { checkThemeContrast } from "./themeContrastLogic";
55
+ export type { KapiThemeContrastFailure, KapiThemeContrastOptions } from "./themeContrastLogic";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Counter shown beside a label: `14760` → "14.760" in Spanish, while `4760` stays "4760" because
3
+ * Spanish does not group four digits. Rounds to an integer, so a fractional count never leaks
4
+ * decimals into a badge. `NaN` or infinite → "" (the caller renders nothing rather than "NaN").
5
+ */
6
+ export declare const formatCount: (value: number, locale?: string) => string;
@@ -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;
@@ -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 e = getComputedStyle(t), n = /(auto|scroll)/.test(e.overflowY) && t.scrollHeight > t.clientHeight, r = /(auto|scroll)/.test(e.overflowX) && t.scrollWidth > t.clientWidth;
25
- if (n || r) return t;
30
+ let { x: e, y: n } = o(t);
31
+ if (e || n) return t;
26
32
  }
27
33
  return null;
28
- }, s = (e) => e instanceof Element && e.closest("button, a, input, select, textarea, label, [role=button], [data-no-drag]") !== null, c = (e, t) => (e || t) !== "touch";
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, o as findScrollableAncestor, r as isDoubleRightClick, s as isInteractiveTarget, c as shouldInterceptContextMenu };
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 r, useRef as i } from "react";
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 a = (a = {}) => {
6
- let o = i(null), s = i(a);
7
- return s.current = a, r(() => {
8
- let r = o.current;
9
- if (!r) return;
10
- let i = !1, a = !1, c = 0, l = 0, u = 0, d = 0, f = 0, p = (e) => {
11
- e.button === 2 && (n(e.target) || (e.stopPropagation(), i = !0, a = !1, c = e.pageX, l = e.pageY, u = r.scrollLeft, d = r.scrollTop));
12
- }, m = (t) => {
13
- if (!i) return;
14
- let n = t.pageX - c, o = t.pageY - l;
15
- !a && e(n, o) && (a = !0, r.classList.add("kapi-grabbing")), a && (t.preventDefault(), r.scrollLeft = u - n, r.scrollTop = d - o);
16
- }, h = () => {
17
- i = !1, r.classList.remove("kapi-grabbing");
18
- }, g = (e) => {
19
- if (e.preventDefault(), e.stopPropagation(), a) {
20
- a = !1, f = 0;
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, f) ? (s.current.onMenu?.(e.clientX, e.clientY), f = 0) : f = n;
27
+ t(n, m) ? (c.current.onMenu?.(e.clientX, e.clientY), m = 0) : m = n;
25
28
  };
26
- return r.addEventListener("mousedown", p), window.addEventListener("mousemove", m), window.addEventListener("mouseup", h), r.addEventListener("contextmenu", g), () => {
27
- r.removeEventListener("mousedown", p), window.removeEventListener("mousemove", m), window.removeEventListener("mouseup", h), r.removeEventListener("contextmenu", g);
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
- }, []), o;
32
+ }, []), s;
30
33
  };
31
34
  //#endregion
32
- export { a as useDragScroll };
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, shouldInterceptContextMenu as i } from "./rightClick.js";
3
- import { useEffect as a, useRef as o } from "react";
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 s = ({ onMenu: s, enabled: c = !0 } = {}) => {
6
- let l = o(s);
7
- l.current = s, a(() => {
8
- if (!c) return;
9
- let a = 0, o = !1, s = !1, u = null, d = 0, f = 0, p = 0, m = 0, h = null, g = (e) => {
10
- h = e.pointerType;
11
- }, _ = (e) => {
12
- e.button === 2 && (r(e.target) || (u = t(e.target), u && (o = !0, s = !1, d = e.pageX, f = e.pageY, p = u.scrollLeft, m = u.scrollTop)));
13
- }, v = (t) => {
14
- if (!o || !u) return;
15
- let n = t.pageX - d, r = t.pageY - f;
16
- !s && e(n, r) && (s = !0, document.body.style.userSelect = "none"), s && (t.preventDefault(), u.scrollLeft = p - n, u.scrollTop = m - r);
17
- }, y = () => {
18
- o = !1, u = null, document.body.style.userSelect = "";
19
- }, b = (e) => {
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 (!i(t, h)) return;
22
- if (e.preventDefault(), s) {
23
- s = !1, a = 0;
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, a) ? (l.current?.(e.clientX, e.clientY), a = 0) : a = r;
30
+ n(r, o) ? (u.current?.(e.clientX, e.clientY), o = 0) : o = r;
28
31
  };
29
- return document.addEventListener("pointerdown", g, !0), document.addEventListener("mousedown", _), window.addEventListener("mousemove", v), window.addEventListener("mouseup", y), document.addEventListener("contextmenu", b), () => {
30
- document.removeEventListener("pointerdown", g, !0), document.removeEventListener("mousedown", _), window.removeEventListener("mousemove", v), window.removeEventListener("mouseup", y), document.removeEventListener("contextmenu", b);
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
- }, [c]);
35
+ }, [l]);
33
36
  };
34
37
  //#endregion
35
- export { s as useGlobalRightClick };
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
- /** Style de la raíz .kapi derivado del estado (fuente + acento como tokens). */
57
- export declare const themeRootStyle: (state: Pick<KapiThemeState, "font" | "accent">) => CSSProperties;
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
  /**