@kapiuara/ui 0.17.0 → 0.18.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 (84) hide show
  1. package/README.md +259 -9
  2. package/dist/components/data/KapiScatterChart.d.ts +56 -0
  3. package/dist/components/data/KapiScatterChart.js +90 -0
  4. package/dist/components/data/chartFrame.d.ts +20 -2
  5. package/dist/components/data/chartFrame.js +33 -24
  6. package/dist/components/data/index.d.ts +4 -0
  7. package/dist/components/data/scatterLogic.d.ts +56 -0
  8. package/dist/components/data/scatterLogic.js +43 -0
  9. package/dist/components/display/KapiAvatarGroup.d.ts +14 -2
  10. package/dist/components/display/KapiAvatarGroup.js +25 -23
  11. package/dist/components/display/KapiTimeline.d.ts +14 -0
  12. package/dist/components/display/KapiTimeline.js +28 -21
  13. package/dist/components/display/avatarGroupSlots.d.ts +6 -0
  14. package/dist/components/display/avatarGroupSlots.js +9 -0
  15. package/dist/components/display/index.d.ts +1 -1
  16. package/dist/components/feedback/KapiAlert.d.ts +6 -1
  17. package/dist/components/feedback/KapiAlert.js +45 -44
  18. package/dist/components/feedback/KapiCountdown.d.ts +12 -1
  19. package/dist/components/feedback/KapiCountdown.js +34 -31
  20. package/dist/components/feedback/KapiEmpty.d.ts +6 -1
  21. package/dist/components/feedback/KapiEmpty.js +20 -18
  22. package/dist/components/feedback/KapiProgress.js +1 -1
  23. package/dist/components/feedback/KapiSpinner.d.ts +48 -0
  24. package/dist/components/feedback/KapiSpinner.js +27 -0
  25. package/dist/components/feedback/KapiToastContainer.js +1 -1
  26. package/dist/components/feedback/KapiTour.js +1 -1
  27. package/dist/components/feedback/alertSlots.d.ts +9 -0
  28. package/dist/components/feedback/alertSlots.js +12 -0
  29. package/dist/components/feedback/countdownSlots.d.ts +6 -0
  30. package/dist/components/feedback/countdownSlots.js +9 -0
  31. package/dist/components/feedback/emptySlots.d.ts +8 -0
  32. package/dist/components/feedback/emptySlots.js +11 -0
  33. package/dist/components/feedback/index.d.ts +5 -3
  34. package/dist/components/inputs/KapiFileUpload.d.ts +14 -1
  35. package/dist/components/inputs/KapiFileUpload.js +80 -67
  36. package/dist/components/inputs/formBridgeLogic.d.ts +104 -0
  37. package/dist/components/inputs/formBridgeLogic.js +25 -0
  38. package/dist/components/inputs/index.d.ts +2 -0
  39. package/dist/components/locale/labelRegistry.d.ts +8 -0
  40. package/dist/components/navigation/KapiSteps.d.ts +26 -5
  41. package/dist/components/navigation/KapiSteps.js +55 -43
  42. package/dist/components/overlays/KapiImageViewer.d.ts +63 -0
  43. package/dist/components/overlays/KapiImageViewer.js +106 -0
  44. package/dist/components/overlays/KapiShortcutsHelp.d.ts +53 -0
  45. package/dist/components/overlays/KapiShortcutsHelp.js +55 -0
  46. package/dist/components/overlays/KapiTooltip.d.ts +49 -10
  47. package/dist/components/overlays/KapiTooltip.js +110 -58
  48. package/dist/components/overlays/KapiViewport.d.ts +63 -0
  49. package/dist/components/overlays/KapiViewport.js +195 -0
  50. package/dist/components/overlays/index.d.ts +8 -0
  51. package/dist/components/overlays/shortcutsHelpSlots.d.ts +9 -0
  52. package/dist/components/overlays/shortcutsHelpSlots.js +12 -0
  53. package/dist/components/overlays/viewportLogic.d.ts +73 -0
  54. package/dist/components/overlays/viewportLogic.js +54 -0
  55. package/dist/components/slotCatalog.d.ts +33 -0
  56. package/dist/components/slotCatalog.js +30 -20
  57. package/dist/css/base.css +1 -1
  58. package/dist/css/components/data/KapiScatterChart.css +1 -0
  59. package/dist/css/components/display/display.css +1 -1
  60. package/dist/css/components/inputs/KapiFileUpload.css +1 -1
  61. package/dist/css/components/navigation/KapiSteps.css +1 -1
  62. package/dist/css/components/overlays/KapiViewport.css +1 -0
  63. package/dist/css/components/overlays/overlays.css +1 -1
  64. package/dist/hooks/elementSizeLogic.d.ts +15 -0
  65. package/dist/hooks/elementSizeLogic.js +7 -0
  66. package/dist/hooks/hotkeyLogic.d.ts +9 -0
  67. package/dist/hooks/hotkeyLogic.js +16 -15
  68. package/dist/hooks/hotkeyRegistry.d.ts +44 -0
  69. package/dist/hooks/hotkeyRegistry.js +32 -0
  70. package/dist/hooks/index.d.ts +10 -0
  71. package/dist/hooks/useDebouncedValue.d.ts +30 -0
  72. package/dist/hooks/useDebouncedValue.js +26 -0
  73. package/dist/hooks/useDisclosure.d.ts +39 -0
  74. package/dist/hooks/useDisclosure.js +35 -0
  75. package/dist/hooks/useElementSize.d.ts +27 -0
  76. package/dist/hooks/useElementSize.js +29 -0
  77. package/dist/hooks/useHotkey.d.ts +8 -0
  78. package/dist/hooks/useHotkey.js +27 -15
  79. package/dist/index.js +201 -188
  80. package/dist/kapi.css +1 -1
  81. package/dist/kapi.layered.css +1 -1
  82. package/dist/logic.d.ts +4 -0
  83. package/dist/logic.js +33 -29
  84. package/package.json +1 -1
@@ -10,10 +10,10 @@ import { onViewportChange as o } from "../../hooks/rafThrottle.js";
10
10
  import { placementViewport as s } from "../../hooks/viewportInsetLogic.js";
11
11
  import { resolveDirection as c } from "../../hooks/directionLogic.js";
12
12
  /* empty css */
13
- import { cloneElement as l, isValidElement as u, useEffect as d, useId as f, useLayoutEffect as p, useRef as m, useState as h } from "react";
14
- import { jsx as g, jsxs as _ } from "react/jsx-runtime";
13
+ import { cloneElement as l, isValidElement as ee, useEffect as u, useId as te, useLayoutEffect as d, useRef as f, useState as p } from "react";
14
+ import { jsx as m, jsxs as ne } from "react/jsx-runtime";
15
15
  //#region src/components/overlays/KapiTooltip.tsx
16
- var v = 280, y = 7, b = 28, x = 12, S = 44, C = (e, t) => e === "end" ? t === "rtl" ? "left" : "right" : e === "start" ? t === "rtl" ? "right" : "left" : e, w = (e) => Math.min(v, String(e).length * y + b), T = (e, t, n, r, i = Infinity) => {
16
+ var h = 280, g = 7, _ = 28, v = 12, y = 44, b = (e, t) => e === "end" ? t === "rtl" ? "left" : "right" : e === "start" ? t === "rtl" ? "right" : "left" : e, x = (e) => typeof e == "string" || typeof e == "number" ? Math.min(h, String(e).length * g + _) : h, S = (e, t, n, r, i = Infinity) => {
17
17
  let o = t.bottom ?? t.top, s = t.left ?? t.right, c = {
18
18
  top: t.top,
19
19
  bottom: o,
@@ -23,23 +23,23 @@ var v = 280, y = 7, b = 28, x = 12, S = 44, C = (e, t) => e === "end" ? t === "r
23
23
  height: o - t.top
24
24
  }, l = e === "top" || e === "bottom";
25
25
  return a(c, {
26
- width: w(n),
27
- height: S
26
+ width: x(n),
27
+ height: y
28
28
  }, {
29
29
  width: r,
30
30
  height: i
31
31
  }, {
32
32
  side: e,
33
- offset: l ? 0 : x,
33
+ offset: l ? 0 : v,
34
34
  flip: "if-overflow",
35
35
  shift: !1
36
36
  }).side;
37
- }, E = 10, D = 8, O = {
37
+ }, C = 10, w = 8, T = {
38
38
  align: "center",
39
39
  flip: !1,
40
40
  shift: !1,
41
41
  mainMin: -Infinity
42
- }, k = (e, t) => {
42
+ }, E = (e, t) => {
43
43
  let n = e === "top" || e === "bottom", { top: r, left: i } = a({
44
44
  top: t.top,
45
45
  bottom: t.bottom,
@@ -54,75 +54,127 @@ var v = 280, y = 7, b = 28, x = 12, S = 44, C = (e, t) => e === "end" ? t === "r
54
54
  width: Infinity,
55
55
  height: Infinity
56
56
  }, {
57
- ...O,
57
+ ...T,
58
58
  side: e,
59
- offset: n ? D : E
59
+ offset: n ? w : C
60
60
  });
61
61
  return {
62
62
  x: i,
63
63
  y: r
64
64
  };
65
- }, A = (e, t) => {
65
+ }, D = (e, t) => {
66
66
  try {
67
67
  return e.matches(t);
68
68
  } catch {
69
69
  return null;
70
70
  }
71
- }, j = (e, t) => i(typeof e == "string" ? e : void 0, t), M = ({ label: i, children: a, prefer: v = "end", className: y, style: b, id: x, ref: S }) => {
72
- let w = f(), E = m(null), D = t(E, S), O = n(), [M, N] = h(() => C(v, c(null, O))), [P, F] = h(!1), [I, L] = h(!1), R = m({
71
+ }, O = (e, t) => i(typeof e == "string" ? e : void 0, t), k = ({ label: i, children: a, target: h, prefer: g = "end", disabled: _, multiline: v, openDelay: y = 0, opened: x, className: C, style: w, id: T, ref: k }) => {
72
+ let A = te(), j = f(null), M = t(j, k), N = n(), [P, re] = p(() => b(g, c(null, N))), [F, I] = p(!1), [ie, L] = p(!1), R = f(!1), z = x !== void 0, B = _ ? !1 : x ?? ie, V = f({
73
73
  hover: !1,
74
74
  focus: !1
75
- }), z = () => {
76
- let e = E.current;
77
- if (!e) return;
78
- let t = e.getBoundingClientRect(), n = s(e), r = T(C(v, c(e, O)), t, i, n.width, n.height), { x: a, y: o } = k(r, t);
79
- e.style.setProperty("--kapi-tip-x", `${Math.round(a)}px`), e.style.setProperty("--kapi-tip-y", `${Math.round(o)}px`), N(r);
80
- }, B = m(z);
81
- p(() => {
82
- B.current = z;
75
+ }), H = f(null), U = () => {
76
+ H.current !== null && clearTimeout(H.current), H.current = null;
77
+ }, W = f(null), ae = () => W.current ?? j.current, G = () => {
78
+ let e = ae(), t = j.current;
79
+ if (!e || !t) return;
80
+ let n = e.getBoundingClientRect(), r = s(e), a = S(b(g, c(e, N)), n, i, r.width, r.height), { x: o, y: l } = E(a, n);
81
+ t.style.setProperty("--kapi-tip-x", `${Math.round(o)}px`), t.style.setProperty("--kapi-tip-y", `${Math.round(l)}px`), re(a);
82
+ }, K = f(G);
83
+ d(() => {
84
+ K.current = G;
83
85
  });
84
- let V = m(null), H = m(!1), U = (e) => {
85
- let t = V.current;
86
+ let q = f(null), J = f(!1), Y = (e) => {
87
+ let t = q.current;
86
88
  if (!t || typeof t.showPopover != "function") return;
87
- let n = A(t, ":popover-open") ?? H.current;
88
- e && !n && t.showPopover(), !e && n && t.hidePopover(), H.current = e;
89
- }, W = (e) => {
90
- R.current[e] = !0, F(!1), L(!0), z(), U(!0);
91
- }, G = (e) => {
92
- R.current[e] = !1, !(R.current.hover || R.current.focus) && (F(!1), L(!1), U(!1));
89
+ let n = D(t, ":popover-open") ?? J.current;
90
+ e && !n && t.showPopover(), !e && n && t.hidePopover(), J.current = e;
91
+ }, X = () => {
92
+ I(!1), L(!0), K.current(), Y(!0);
93
+ }, Z = (e) => {
94
+ _ || z || (V.current[e] = !0, e === "focus" || y <= 0 ? (U(), X()) : (U(), H.current = setTimeout(() => {
95
+ H.current = null, (V.current.hover || V.current.focus) && X();
96
+ }, y)));
97
+ }, Q = (e) => {
98
+ _ || z || (V.current[e] = !1, !(V.current.hover || V.current.focus) && (U(), I(!1), L(!1), Y(!1)));
93
99
  };
94
100
  d(() => {
95
- if (!I) return;
96
- let e = r(E.current);
97
- return o(() => B.current(), e ? { target: e } : {});
98
- }, [I]);
99
- let K = (e) => {
100
- e.key === "Escape" && !P && F(!0);
101
- }, q = u(a) ? a : null, J = q ? l(q, { "aria-describedby": j(q.props["aria-describedby"], w) }) : a;
102
- return /* @__PURE__ */ _("span", {
103
- id: x,
104
- className: e("kapi-tip", y),
105
- style: b,
106
- ref: D,
107
- "data-side": M,
108
- "data-dismissed": P || void 0,
109
- "aria-describedby": q ? void 0 : w,
110
- onMouseEnter: () => W("hover"),
101
+ z && (B ? (R.current || I(!1), G(), Y(!0)) : Y(!1), R.current = B);
102
+ }, [
103
+ z,
104
+ B,
105
+ i,
106
+ g
107
+ ]), u(() => {
108
+ _ && (U(), V.current.hover = !1, V.current.focus = !1, L(!1), Y(!1));
109
+ }, [_]), u(() => U, []), u(() => {
110
+ if (!B) return;
111
+ let e = r(j.current);
112
+ return o(() => K.current(), e ? { target: e } : {});
113
+ }, [B]);
114
+ let oe = () => I(!0), se = (e) => {
115
+ e.key === "Escape" && !F && oe();
116
+ };
117
+ u(() => {
118
+ if (h === void 0) return;
119
+ let e = (j.current?.ownerDocument ?? (typeof document > "u" ? null : document))?.getElementById(h) ?? null;
120
+ if (W.current = e, !e || _) return;
121
+ let t = e.getAttribute("aria-describedby"), n = O(t, A);
122
+ n !== void 0 && e.setAttribute("aria-describedby", n);
123
+ let r = () => Z("hover"), i = () => Q("hover"), a = () => {
124
+ (D(e, ":focus-visible") ?? !0) && Z("focus");
125
+ }, o = () => Q("focus"), s = (e) => {
126
+ e.key === "Escape" && oe();
127
+ };
128
+ return e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", i), e.addEventListener("focus", a), e.addEventListener("blur", o), e.addEventListener("keydown", s), () => {
129
+ e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", i), e.removeEventListener("focus", a), e.removeEventListener("blur", o), e.removeEventListener("keydown", s), t === null ? e.removeAttribute("aria-describedby") : e.setAttribute("aria-describedby", t), W.current = null, V.current = {
130
+ hover: !1,
131
+ focus: !1
132
+ };
133
+ };
134
+ }, [
135
+ h,
136
+ A,
137
+ _,
138
+ y,
139
+ z
140
+ ]);
141
+ let ce = /* @__PURE__ */ m("span", {
142
+ ref: q,
143
+ className: e("kapi-tip__bubble", v && "kapi-tip__bubble--multiline"),
144
+ role: "tooltip",
145
+ id: A,
146
+ popover: "manual",
147
+ children: i
148
+ });
149
+ if (h !== void 0) return /* @__PURE__ */ m("span", {
150
+ id: T,
151
+ className: e("kapi-tip", C),
152
+ style: w,
153
+ ref: M,
154
+ "data-side": P,
155
+ "data-open": B && !F ? "" : void 0,
156
+ "data-dismissed": F || void 0,
157
+ children: ce
158
+ });
159
+ let $ = ee(a) ? a : null, le = $ && !_ ? l($, { "aria-describedby": O($.props["aria-describedby"], A) }) : a;
160
+ return /* @__PURE__ */ ne("span", {
161
+ id: T,
162
+ className: e("kapi-tip", C),
163
+ style: w,
164
+ ref: M,
165
+ "data-side": P,
166
+ "data-open": B && !F ? "" : void 0,
167
+ "data-dismissed": F || void 0,
168
+ "aria-describedby": $ || _ ? void 0 : A,
169
+ onMouseEnter: () => Z("hover"),
111
170
  onFocus: (e) => {
112
- (A(e.target, ":focus-visible") ?? !0) && W("focus");
171
+ (D(e.target, ":focus-visible") ?? !0) && Z("focus");
113
172
  },
114
- onMouseLeave: () => G("hover"),
115
- onBlur: () => G("focus"),
116
- onKeyDown: K,
117
- children: [J, /* @__PURE__ */ g("span", {
118
- ref: V,
119
- className: "kapi-tip__bubble",
120
- role: "tooltip",
121
- id: w,
122
- popover: "manual",
123
- children: i
124
- })]
173
+ onMouseLeave: () => Q("hover"),
174
+ onBlur: () => Q("focus"),
175
+ onKeyDown: se,
176
+ children: [le, ce]
125
177
  });
126
178
  };
127
179
  //#endregion
128
- export { M as KapiTooltip, w as estimateTooltipWidth, C as physicalTooltipSide, T as resolveTooltipSide, k as tooltipAnchor, j as tooltipDescribedBy };
180
+ export { k as KapiTooltip, x as estimateTooltipWidth, b as physicalTooltipSide, S as resolveTooltipSide, E as tooltipAnchor, O as tooltipDescribedBy };
@@ -0,0 +1,63 @@
1
+ import { type HTMLAttributes, type ReactNode, type Ref } from "react";
2
+ import type { KapiLabelsOverride } from "../labelsLogic.js";
3
+ import { type KapiViewportState } from "./viewportLogic.js";
4
+ export type { KapiViewportState };
5
+ /** Textos de `KapiViewport`. */
6
+ export type KapiViewportLabels = {
7
+ /** Botón de acercar. */
8
+ zoomIn: string;
9
+ /** Botón de alejar. */
10
+ zoomOut: string;
11
+ /** Botón de ajustar a la pantalla. */
12
+ fit: string;
13
+ /** Botón de pantalla completa. */
14
+ fullscreen: string;
15
+ /** Botón de salir de pantalla completa. */
16
+ exitFullscreen: string;
17
+ };
18
+ export declare const DEFAULT_VIEWPORT_LABELS: KapiViewportLabels;
19
+ /** Atributos nativos (`id`, `style`, `data-*`…) van al marco. */
20
+ export type KapiViewportProps = Omit<HTMLAttributes<HTMLDivElement>, "children" | "onScroll"> & {
21
+ /** Ref al `<div>` del marco. */
22
+ ref?: Ref<HTMLDivElement> | undefined;
23
+ /** Lo que se mira: una imagen, un SVG, un plano. */
24
+ children: ReactNode;
25
+ /** Ancho natural del contenido, en píxeles. De acá sale el ajuste y el acotado del arrastre. */
26
+ contentWidth: number;
27
+ /** Alto natural del contenido. */
28
+ contentHeight: number;
29
+ /** Escala mínima. @default 0.25 */
30
+ minScale?: number | undefined;
31
+ /** Escala máxima. @default 8 */
32
+ maxScale?: number | undefined;
33
+ /** Cuánto cambia la escala por paso de rueda o por botón. Los dos usan el mismo. @default 0.25 */
34
+ scaleStep?: number | undefined;
35
+ /** Estado controlado (escala y desplazamiento). */
36
+ state?: KapiViewportState | undefined;
37
+ /** Estado inicial. Sin él, el contenido arranca ajustado al marco. */
38
+ defaultState?: KapiViewportState | undefined;
39
+ /** Avisa cada cambio de escala o de posición. */
40
+ onStateChange?: ((state: KapiViewportState) => void) | undefined;
41
+ /** Oculta la barra de botones (acercar, alejar, ajustar, pantalla completa). */
42
+ hideControls?: boolean | undefined;
43
+ /** Saca el botón de pantalla completa sin sacar los demás. */
44
+ hideFullscreen?: boolean | undefined;
45
+ /** Textos fijos de los botones. */
46
+ labels?: KapiLabelsOverride<KapiViewportLabels> | undefined;
47
+ };
48
+ /**
49
+ * Marco con zoom y arrastre: rueda, doble clic, pellizco, arrastre, ajustar y pantalla completa.
50
+ *
51
+ * Toda la matemática vive en `viewportLogic.ts`, pura y testeada; acá sólo se escuchan eventos. Dos
52
+ * decisiones que no se ven en el código:
53
+ *
54
+ * - **La rueda usa el mismo motor de pasos que los botones** (`nextWheelZoom`), no un factor
55
+ * continuo propio: si no, un gesto de trackpad y tres clics en `+` dejarían escalas distintas y
56
+ * el `Ajustar` volvería a un lugar que no coincide con ninguna.
57
+ * - **Acercar deja quieto el punto bajo el cursor.** Sin eso el contenido crece desde el centro y
58
+ * lo que la persona estaba mirando se le va de la pantalla.
59
+ *
60
+ * El contenido más chico que el marco **no se arrastra**: queda centrado, para que una imagen chica
61
+ * no se pueda sacar de la vista.
62
+ */
63
+ export declare const KapiViewport: ({ children, contentWidth, contentHeight, minScale, maxScale, scaleStep, state, defaultState, onStateChange, hideControls, hideFullscreen, labels, className, ref, ...rest }: KapiViewportProps) => import("react").JSX.Element;
@@ -0,0 +1,195 @@
1
+ "use client";
2
+ import "#kapi-css/components/overlays/KapiViewport.css";
3
+ import { joinClasses as e } from "../rootProps.js";
4
+ import { useLabels as t } from "../locale/KapiLocaleProvider.js";
5
+ import { docOf as n } from "../../hooks/ownerDocument.js";
6
+ import { KapiIconButton as r } from "../inputs/KapiIconButton.js";
7
+ import { useControllableState as ee } from "../../hooks/useControllableState.js";
8
+ import { useElementSize as i } from "../../hooks/useElementSize.js";
9
+ import { nextWheelZoom as a } from "../../hooks/wheelZoomLogic.js";
10
+ import { VIEWPORT_IDENTITY as te, clampViewport as o, doubleTapScale as ne, fitScale as re, fitViewport as s, pinchCenter as c, pinchDistance as l, zoomAt as u } from "./viewportLogic.js";
11
+ /* empty css */
12
+ import { useCallback as ie, useEffect as d, useRef as f, useState as ae } from "react";
13
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
14
+ import { Maximize2 as oe, Minimize2 as se, Minus as h, Plus as g, Scan as _ } from "lucide-react";
15
+ //#region src/components/overlays/KapiViewport.tsx
16
+ var v = {
17
+ zoomIn: "Acercar",
18
+ zoomOut: "Alejar",
19
+ fit: "Ajustar a la pantalla",
20
+ fullscreen: "Pantalla completa",
21
+ exitFullscreen: "Salir de pantalla completa"
22
+ }, y = ({ children: y, contentWidth: b, contentHeight: x, minScale: S = .25, maxScale: C = 8, scaleStep: ce = .25, state: w, defaultState: T, onStateChange: le, hideControls: ue, hideFullscreen: de, labels: fe, className: pe, ref: E, ...me }) => {
23
+ let D = t("viewport", v, fe), { ref: O, width: k, height: A } = i(), j = f(null), M = f(null), [N, P] = ae(!1), F = {
24
+ width: b,
25
+ height: x
26
+ }, I = {
27
+ width: k,
28
+ height: A
29
+ }, L = {
30
+ min: S,
31
+ max: C
32
+ }, R = re(F, I), [z, B] = ee(w, T ?? te, le), V = k > 0 && A > 0, H = V ? o(z, F, I, L) : z, U = b > 0 && x > 0, W = f(T !== void 0 || w !== void 0);
33
+ d(() => {
34
+ !W.current && V && U && (W.current = !0, B(s(F, I, L)));
35
+ }, [
36
+ V,
37
+ U,
38
+ B,
39
+ b,
40
+ x,
41
+ k,
42
+ A,
43
+ S,
44
+ C
45
+ ]);
46
+ let G = ie((e) => B(o(e, F, I, L)), [
47
+ B,
48
+ b,
49
+ x,
50
+ k,
51
+ A,
52
+ S,
53
+ C
54
+ ]), K = (e, t) => {
55
+ let n = j.current?.getBoundingClientRect();
56
+ return n ? {
57
+ x: e - (n.left + n.width / 2),
58
+ y: t - (n.top + n.height / 2)
59
+ } : {
60
+ x: 0,
61
+ y: 0
62
+ };
63
+ }, q = (e, t) => {
64
+ let n = u(H, e, t, F, I, L);
65
+ (n.scale !== H.scale || n.x !== H.x || n.y !== H.y) && B(n);
66
+ }, J = (e, t) => q(a(H.scale, e, {
67
+ min: S,
68
+ max: C,
69
+ step: ce
70
+ }), t), Y = f(() => void 0);
71
+ Y.current = (e) => {
72
+ e.preventDefault(), J(e.deltaY, K(e.clientX, e.clientY));
73
+ }, d(() => {
74
+ let e = M.current;
75
+ if (!e) return;
76
+ let t = (e) => Y.current(e);
77
+ return e.addEventListener("wheel", t, { passive: !1 }), () => e.removeEventListener("wheel", t);
78
+ }, []);
79
+ let X = f(/* @__PURE__ */ new Map()), Z = f(null), Q = f(null), he = (e) => {
80
+ if (X.current.set(e.pointerId, {
81
+ x: e.clientX,
82
+ y: e.clientY
83
+ }), X.current.size === 2) {
84
+ let e = [...X.current.values()];
85
+ Z.current = {
86
+ dist: l(e),
87
+ scale: H.scale
88
+ }, Q.current = null;
89
+ } else X.current.size === 1 && (e.currentTarget.setPointerCapture(e.pointerId), Q.current = {
90
+ x: e.clientX,
91
+ y: e.clientY,
92
+ ox: H.x,
93
+ oy: H.y
94
+ });
95
+ }, ge = (e) => {
96
+ if (!X.current.has(e.pointerId)) return;
97
+ if (X.current.set(e.pointerId, {
98
+ x: e.clientX,
99
+ y: e.clientY
100
+ }), Z.current && X.current.size >= 2) {
101
+ let e = [...X.current.values()], t = l(e);
102
+ if (Z.current.dist > 0 && t > 0) {
103
+ let n = c(e);
104
+ q(Z.current.scale * (t / Z.current.dist), K(n.x, n.y));
105
+ }
106
+ return;
107
+ }
108
+ let t = Q.current;
109
+ t && G({
110
+ scale: H.scale,
111
+ x: t.ox + (e.clientX - t.x),
112
+ y: t.oy + (e.clientY - t.y)
113
+ });
114
+ }, $ = (e) => {
115
+ X.current.delete(e.pointerId), X.current.size < 2 && (Z.current = null), X.current.size === 0 && (Q.current = null);
116
+ };
117
+ d(() => {
118
+ let e = n(j.current);
119
+ if (!e) return;
120
+ let t = () => P(e.fullscreenElement === j.current);
121
+ return e.addEventListener("fullscreenchange", t), t(), () => e.removeEventListener("fullscreenchange", t);
122
+ }, []);
123
+ let _e = () => {
124
+ let e = j.current, t = n(e);
125
+ e && t && (t.fullscreenElement ? t.exitFullscreen?.() : e.requestFullscreen?.())?.catch(() => void 0);
126
+ }, ve = V && (b * H.scale > k || x * H.scale > A);
127
+ return /* @__PURE__ */ m("div", {
128
+ ...me,
129
+ ref: (e) => {
130
+ j.current = e, O(e), typeof E == "function" ? E(e) : E && (E.current = e);
131
+ },
132
+ className: e("kapi-viewport", ve && "is-pannable", pe),
133
+ children: [/* @__PURE__ */ p("div", {
134
+ ref: M,
135
+ className: "kapi-viewport__stage",
136
+ style: {
137
+ transform: `translate(${H.x}px, ${H.y}px) scale(${H.scale})`,
138
+ width: b,
139
+ height: x
140
+ },
141
+ onPointerDown: he,
142
+ onPointerMove: ge,
143
+ onPointerUp: $,
144
+ onPointerCancel: $,
145
+ onDoubleClick: (e) => q(ne(H.scale, R, L), K(e.clientX, e.clientY)),
146
+ children: y
147
+ }), !ue && /* @__PURE__ */ m("div", {
148
+ className: "kapi-viewport__controls",
149
+ children: [
150
+ /* @__PURE__ */ p(r, {
151
+ "aria-label": D.zoomOut,
152
+ icon: /* @__PURE__ */ p(h, {
153
+ size: 16,
154
+ strokeWidth: 2.2
155
+ }),
156
+ onClick: () => J(1, {
157
+ x: 0,
158
+ y: 0
159
+ }),
160
+ disabled: H.scale <= S
161
+ }),
162
+ /* @__PURE__ */ p(r, {
163
+ "aria-label": D.zoomIn,
164
+ icon: /* @__PURE__ */ p(g, {
165
+ size: 16,
166
+ strokeWidth: 2.2
167
+ }),
168
+ onClick: () => J(-1, {
169
+ x: 0,
170
+ y: 0
171
+ }),
172
+ disabled: H.scale >= C
173
+ }),
174
+ /* @__PURE__ */ p(r, {
175
+ "aria-label": D.fit,
176
+ icon: /* @__PURE__ */ p(_, {
177
+ size: 16,
178
+ strokeWidth: 2
179
+ }),
180
+ onClick: () => G(s(F, I, L))
181
+ }),
182
+ !de && /* @__PURE__ */ p(r, {
183
+ "aria-label": N ? D.exitFullscreen : D.fullscreen,
184
+ icon: p(N ? se : oe, {
185
+ size: 16,
186
+ strokeWidth: 2
187
+ }),
188
+ onClick: _e
189
+ })
190
+ ]
191
+ })]
192
+ });
193
+ };
194
+ //#endregion
195
+ export { v as DEFAULT_VIEWPORT_LABELS, y as KapiViewport };
@@ -46,3 +46,11 @@ samePlacement,
46
46
  /** @deprecated Interno, se quita en 1.0. */
47
47
  shiftIntoView } from "./popoverLogic.js";
48
48
  export type { KapiPlacePopoverOptions, KapiPopoverAlign, KapiPopoverAnchor, KapiPopoverFlip, KapiPopoverPlacement, KapiPopoverPoint, KapiPopoverRect, KapiPopoverSide, KapiPopoverSize, KapiPopoverWidth } from "./popoverLogic.js";
49
+ export { KapiShortcutsHelp, DEFAULT_SHORTCUTS_HELP_LABELS } from "./KapiShortcutsHelp.js";
50
+ export type { KapiShortcutsHelpProps, KapiShortcutsHelpLabels, KapiShortcutsHelpClassNames } from "./KapiShortcutsHelp.js";
51
+ export { KapiViewport, DEFAULT_VIEWPORT_LABELS } from "./KapiViewport.js";
52
+ export type { KapiViewportProps, KapiViewportLabels, KapiViewportState } from "./KapiViewport.js";
53
+ export { KapiImageViewer, DEFAULT_IMAGE_VIEWER_LABELS } from "./KapiImageViewer.js";
54
+ export type { KapiImageViewerProps, KapiImageViewerLabels, KapiImageViewerItem } from "./KapiImageViewer.js";
55
+ export { VIEWPORT_IDENTITY, clampViewport, doubleTapScale, fitScale, fitViewport, panBounds, pinchCenter, pinchDistance, zoomAt } from "./viewportLogic.js";
56
+ export type { KapiViewportLimits, KapiViewportSize } from "./viewportLogic.js";
@@ -0,0 +1,9 @@
1
+ /** Partes de `shortcutsHelp` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
2
+ export declare const SHORTCUTS_HELP_SLOTS: import("../slotsLogic.js").SlotTable<"shortcutsHelp", {
3
+ readonly group: "kapi-shortcuts__group";
4
+ readonly groupTitle: "kapi-shortcuts__title";
5
+ readonly list: "kapi-shortcuts__list";
6
+ readonly row: "kapi-shortcuts__row";
7
+ readonly keys: "kapi-shortcuts__keys";
8
+ readonly description: "kapi-shortcuts__what";
9
+ }>;
@@ -0,0 +1,12 @@
1
+ import { defineSlots as e } from "../slotsLogic.js";
2
+ //#region src/components/overlays/shortcutsHelpSlots.ts
3
+ var t = e("shortcutsHelp", {
4
+ group: "kapi-shortcuts__group",
5
+ groupTitle: "kapi-shortcuts__title",
6
+ list: "kapi-shortcuts__list",
7
+ row: "kapi-shortcuts__row",
8
+ keys: "kapi-shortcuts__keys",
9
+ description: "kapi-shortcuts__what"
10
+ });
11
+ //#endregion
12
+ export { t as SHORTCUTS_HELP_SLOTS };
@@ -0,0 +1,73 @@
1
+ /** Estado del visor: cuánto se acercó y cuánto se corrió el contenido, en píxeles de pantalla. */
2
+ export type KapiViewportState = {
3
+ /** Factor de escala. 1 es el tamaño natural del contenido. */
4
+ scale: number;
5
+ /** Desplazamiento horizontal del contenido respecto del centro del marco. */
6
+ x: number;
7
+ /** Desplazamiento vertical. */
8
+ y: number;
9
+ };
10
+ /** Un tamaño en píxeles. */
11
+ export type KapiViewportSize = {
12
+ width: number;
13
+ height: number;
14
+ };
15
+ /** Hasta dónde se puede acercar y alejar. */
16
+ export type KapiViewportLimits = {
17
+ /** Escala mínima. */
18
+ min: number;
19
+ /** Escala máxima. */
20
+ max: number;
21
+ };
22
+ /** El estado de arranque: tamaño natural, centrado. */
23
+ export declare const VIEWPORT_IDENTITY: KapiViewportState;
24
+ /**
25
+ * Escala a la que el contenido entra entero en el marco, sin deformarse (la menor de las dos
26
+ * razones). Un contenido o un marco de lado cero devuelve 1: no hay nada que ajustar y dividir
27
+ * daría infinito.
28
+ */
29
+ export declare const fitScale: (content: KapiViewportSize, frame: KapiViewportSize) => number;
30
+ /**
31
+ * Cuánto puede correrse el contenido en cada eje sin dejar un borde adentro del marco.
32
+ *
33
+ * Cuando el contenido escalado es MÁS CHICO que el marco el margen es cero, o sea que queda
34
+ * centrado y no se puede arrastrar: dejarlo moverse haría que una foto chica se vaya de la
35
+ * pantalla y haya que buscarla.
36
+ */
37
+ export declare const panBounds: (content: KapiViewportSize, frame: KapiViewportSize, scale: number) => KapiViewportSize;
38
+ /** Acota un estado: la escala a sus límites y el desplazamiento a lo que el contenido permite. */
39
+ export declare const clampViewport: (state: KapiViewportState, content: KapiViewportSize, frame: KapiViewportSize, limits: KapiViewportLimits) => KapiViewportState;
40
+ /**
41
+ * Cambia la escala dejando quieto el punto que está bajo el cursor.
42
+ *
43
+ * Es lo que hace que acercar con la rueda se sienta bien: sin esto el contenido se agranda desde el
44
+ * centro y lo que la persona estaba mirando se le escapa de la pantalla. `point` va en coordenadas
45
+ * **relativas al centro del marco**, que es el mismo origen del desplazamiento.
46
+ */
47
+ export declare const zoomAt: (state: KapiViewportState, nextScale: number, point: {
48
+ x: number;
49
+ y: number;
50
+ }, content: KapiViewportSize, frame: KapiViewportSize, limits: KapiViewportLimits) => KapiViewportState;
51
+ /** Estado que ajusta el contenido al marco y lo centra. */
52
+ export declare const fitViewport: (content: KapiViewportSize, frame: KapiViewportSize, limits: KapiViewportLimits) => KapiViewportState;
53
+ /**
54
+ * ¿El doble clic acerca o vuelve a ajustar? Acerca mientras esté cerca del ajuste; una vez
55
+ * acercado, el segundo doble clic devuelve al ajuste. Un solo gesto para ir y volver.
56
+ */
57
+ export declare const doubleTapScale: (current: number, fitted: number, limits: KapiViewportLimits) => number;
58
+ /**
59
+ * Distancia entre dos dedos, para el pellizco. Devuelve 0 con menos de dos puntos, que es lo que
60
+ * deja al llamador distinguir "no hay gesto" sin mirar la longitud.
61
+ */
62
+ export declare const pinchDistance: (points: readonly {
63
+ x: number;
64
+ y: number;
65
+ }[]) => number;
66
+ /** Punto medio entre dos dedos: el foco del pellizco. Con menos de dos puntos, el origen. */
67
+ export declare const pinchCenter: (points: readonly {
68
+ x: number;
69
+ y: number;
70
+ }[]) => {
71
+ x: number;
72
+ y: number;
73
+ };
@@ -0,0 +1,54 @@
1
+ //#region src/components/overlays/viewportLogic.ts
2
+ var e = (e, t, n) => Math.min(n, Math.max(t, e)), t = (e, t) => Number.isFinite(e) ? e : t, n = {
3
+ scale: 1,
4
+ x: 0,
5
+ y: 0
6
+ }, r = (e, n) => {
7
+ let r = t(e.width, 0), i = t(e.height, 0), a = t(n.width, 0), o = t(n.height, 0);
8
+ return r <= 0 || i <= 0 || a <= 0 || o <= 0 ? 1 : Math.min(a / r, o / i);
9
+ }, i = (e, n, r) => {
10
+ let i = t(r, 1), a = t(e.width, 0) * i, o = t(e.height, 0) * i;
11
+ return {
12
+ width: Math.max(0, (a - t(n.width, 0)) / 2),
13
+ height: Math.max(0, (o - t(n.height, 0)) / 2)
14
+ };
15
+ }, a = (n, r, a, o) => {
16
+ let s = t(o.min, 1), c = Math.max(s, t(o.max, s)), l = e(t(n.scale, 1), s, c), u = i(r, a, l);
17
+ return {
18
+ scale: l,
19
+ x: e(t(n.x, 0), -u.width, u.width),
20
+ y: e(t(n.y, 0), -u.height, u.height)
21
+ };
22
+ }, o = (n, r, i, o, s, c) => {
23
+ let l = t(c.min, 1), u = Math.max(l, t(c.max, l)), d = t(n.scale, 1), f = e(t(r, d), l, u);
24
+ if (f === d) return a(n, o, s, c);
25
+ let p = f / d, m = t(i.x, 0), h = t(i.y, 0);
26
+ return a({
27
+ scale: f,
28
+ x: m - (m - t(n.x, 0)) * p,
29
+ y: h - (h - t(n.y, 0)) * p
30
+ }, o, s, c);
31
+ }, s = (e, t, n) => a({
32
+ scale: r(e, t),
33
+ x: 0,
34
+ y: 0
35
+ }, e, t, n), c = (n, r, i) => {
36
+ let a = t(i.min, 1), o = Math.max(a, t(i.max, a));
37
+ return Math.abs(t(n, 1) - t(r, 1)) < .01 ? e(Math.max(r * 2, 1), a, o) : e(r, a, o);
38
+ }, l = (e) => {
39
+ if (e.length < 2) return 0;
40
+ let [n, r] = e;
41
+ return Math.hypot(t(r.x, 0) - t(n.x, 0), t(r.y, 0) - t(n.y, 0));
42
+ }, u = (e) => {
43
+ if (e.length < 2) return {
44
+ x: 0,
45
+ y: 0
46
+ };
47
+ let [n, r] = e;
48
+ return {
49
+ x: (t(n.x, 0) + t(r.x, 0)) / 2,
50
+ y: (t(n.y, 0) + t(r.y, 0)) / 2
51
+ };
52
+ };
53
+ //#endregion
54
+ export { n as VIEWPORT_IDENTITY, a as clampViewport, c as doubleTapScale, r as fitScale, s as fitViewport, i as panBounds, u as pinchCenter, l as pinchDistance, o as zoomAt };