@kapiuara/ui 0.9.0 → 0.11.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 +29 -11
- package/dist/components/data/KapiBarChart.d.ts +84 -0
- package/dist/components/data/KapiBarChart.js +87 -0
- package/dist/components/data/KapiEventCalendar.d.ts +70 -0
- package/dist/components/data/KapiEventCalendar.js +225 -0
- package/dist/components/data/KapiHeatmap.d.ts +62 -0
- package/dist/components/data/KapiHeatmap.js +120 -0
- package/dist/components/data/KapiLineChart.d.ts +50 -0
- package/dist/components/data/KapiLineChart.js +105 -0
- package/dist/components/data/KapiPaginationFooter.js +6 -5
- package/dist/components/data/KapiSparkline.d.ts +41 -0
- package/dist/components/data/KapiSparkline.js +55 -0
- package/dist/components/data/KapiTable.d.ts +1 -1
- package/dist/components/data/KapiTable.js +371 -359
- package/dist/components/data/barChartLogic.d.ts +59 -0
- package/dist/components/data/barChartLogic.js +53 -0
- package/dist/components/data/chartFrame.d.ts +96 -0
- package/dist/components/data/chartFrame.js +89 -0
- package/dist/components/data/eventCalendarLogic.d.ts +70 -0
- package/dist/components/data/eventCalendarLogic.js +45 -0
- package/dist/components/data/heatmapLogic.d.ts +15 -0
- package/dist/components/data/heatmapLogic.js +15 -0
- package/dist/components/data/index.d.ts +19 -0
- package/dist/components/data/lineChartLogic.d.ts +30 -0
- package/dist/components/data/lineChartLogic.js +21 -0
- package/dist/components/data/sparklineLogic.d.ts +28 -0
- package/dist/components/data/sparklineLogic.js +18 -0
- package/dist/components/display/KapiStat.d.ts +1 -1
- package/dist/components/feedback/KapiBulkBar.d.ts +1 -1
- package/dist/components/inputs/KapiDatePicker.d.ts +8 -2
- package/dist/components/inputs/KapiDatePicker.js +120 -106
- package/dist/components/inputs/KapiDateRangePicker.d.ts +26 -5
- package/dist/components/inputs/KapiDateRangePicker.js +146 -111
- package/dist/components/inputs/datePickerLogic.d.ts +9 -0
- package/dist/components/inputs/datePickerLogic.js +25 -25
- package/dist/components/inputs/dateRangeLogic.d.ts +23 -4
- package/dist/components/inputs/dateRangeLogic.js +48 -22
- package/dist/components/inputs/facetedSearchLogic.d.ts +1 -1
- package/dist/components/layout/KapiContextSlot.js +108 -88
- package/dist/components/layout/KapiMasonry.d.ts +30 -0
- package/dist/components/layout/KapiMasonry.js +33 -0
- package/dist/components/layout/KapiPageHeader.js +136 -58
- package/dist/components/layout/KapiRail.d.ts +8 -2
- package/dist/components/layout/KapiRail.js +118 -67
- package/dist/components/layout/KapiShell.js +67 -37
- package/dist/components/layout/index.d.ts +2 -0
- package/dist/components/layout/masonryLogic.d.ts +40 -0
- package/dist/components/layout/masonryLogic.js +8 -0
- package/dist/components/layout/pageHeaderLogic.d.ts +25 -0
- package/dist/components/layout/pageHeaderLogic.js +16 -2
- package/dist/components/layout/railLogic.d.ts +41 -1
- package/dist/components/layout/railLogic.js +36 -4
- package/dist/components/layout/reopenBus.d.ts +53 -0
- package/dist/components/layout/reopenBus.js +6 -0
- package/dist/components/layout/useMasonrySpans.d.ts +32 -0
- package/dist/components/layout/useMasonrySpans.js +44 -0
- package/dist/components/layout/useRailOverflow.d.ts +17 -0
- package/dist/components/layout/useRailOverflow.js +41 -0
- package/dist/components/locale/labelRegistry.d.ts +10 -1
- package/dist/components/navigation/KapiFilterChips.js +1 -1
- package/dist/components/navigation/filterChipsLogic.d.ts +7 -1
- package/dist/components/navigation/filterChipsLogic.js +3 -3
- package/dist/components/overlays/KapiContextMenu.d.ts +3 -0
- package/dist/components/overlays/KapiContextMenu.js +2 -1
- package/dist/components/overlays/KapiDropdown.d.ts +3 -1
- package/dist/components/overlays/KapiDropdown.js +29 -26
- package/dist/components/overlays/KapiMenuButton.js +1 -0
- package/dist/components/overlays/KapiOffcanvasStack.d.ts +2 -2
- package/dist/hooks/breakpointOpenLogic.d.ts +20 -5
- package/dist/hooks/breakpointOpenLogic.js +2 -2
- package/dist/hooks/dataColorLogic.d.ts +23 -0
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/numberFormatLogic.d.ts +7 -0
- package/dist/hooks/numberFormatLogic.js +5 -2
- package/dist/hooks/seriesPaletteLogic.d.ts +24 -0
- package/dist/hooks/themeContrastLogic.js +1 -0
- package/dist/hooks/themeDeriveLogic.d.ts +11 -1
- package/dist/hooks/themeDeriveLogic.js +40 -31
- package/dist/hooks/themeRadiiLogic.d.ts +1 -1
- package/dist/hooks/themeRadiiLogic.js +1 -0
- package/dist/hooks/useKapiTheme.js +27 -27
- package/dist/hooks/useMediaQuery.d.ts +7 -0
- package/dist/hooks/useMediaQuery.js +4 -4
- package/dist/hooks/useWheelZoom.d.ts +30 -0
- package/dist/hooks/useWheelZoom.js +27 -0
- package/dist/hooks/wheelZoomLogic.d.ts +18 -0
- package/dist/hooks/wheelZoomLogic.js +9 -0
- package/dist/index.js +125 -113
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +3 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
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
2
|
var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
4
3
|
"--kapi-radius-xs": .6,
|
|
5
4
|
"--kapi-radius-inner": .7,
|
|
@@ -8,21 +7,28 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
8
7
|
"--kapi-radius-md": 1,
|
|
9
8
|
"--kapi-radius-group": 1.1
|
|
10
9
|
}, c = {
|
|
10
|
+
"--kapi-radius-check": .6,
|
|
11
|
+
"--kapi-radius-box": 1
|
|
12
|
+
}, l = {
|
|
11
13
|
"--kapi-radius-lg": 12 / 18,
|
|
12
14
|
"--kapi-radius-xl": 14 / 18,
|
|
13
15
|
"--kapi-radius": 16 / 18,
|
|
14
16
|
"--kapi-radius-surface": 1
|
|
15
|
-
},
|
|
16
|
-
let t = {}, n = [
|
|
17
|
+
}, u = (e, t) => `${Math.min(999, Math.round(e * t * 10) / 10)}px`, d = (e) => {
|
|
18
|
+
let t = {}, n = [
|
|
19
|
+
[e.control, s],
|
|
20
|
+
[e.box, c],
|
|
21
|
+
[e.surface, l]
|
|
22
|
+
];
|
|
17
23
|
for (let [e, r] of n) {
|
|
18
24
|
let n = e?.trim();
|
|
19
25
|
if (!n || !a.test(n)) continue;
|
|
20
26
|
let i = parseFloat(n);
|
|
21
|
-
for (let [e, n] of Object.entries(r)) t[e] =
|
|
27
|
+
for (let [e, n] of Object.entries(r)) t[e] = u(i, n);
|
|
22
28
|
}
|
|
23
29
|
let r = e.squircle?.trim();
|
|
24
30
|
return r && o.test(r) && (t["--kapi-radius-squircle"] = r), t;
|
|
25
|
-
},
|
|
31
|
+
}, f = {
|
|
26
32
|
light: {
|
|
27
33
|
bg: "#f4f2fb",
|
|
28
34
|
card: "#ffffff",
|
|
@@ -45,64 +51,64 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
45
51
|
warning: "#e0a44e",
|
|
46
52
|
danger: "#f06a8a"
|
|
47
53
|
}
|
|
48
|
-
},
|
|
54
|
+
}, p = Object.keys(f.light), m = 4.5, h = {
|
|
49
55
|
"--kapi-ink-2": 12,
|
|
50
56
|
"--kapi-ink-3": 22,
|
|
51
57
|
"--kapi-muted": 28,
|
|
52
58
|
"--kapi-muted-2": 32
|
|
53
|
-
},
|
|
59
|
+
}, g = {
|
|
54
60
|
r: 255,
|
|
55
61
|
g: 255,
|
|
56
62
|
b: 255,
|
|
57
63
|
a: 1
|
|
58
|
-
},
|
|
64
|
+
}, _ = {
|
|
59
65
|
r: 0,
|
|
60
66
|
g: 0,
|
|
61
67
|
b: 0,
|
|
62
68
|
a: 1
|
|
63
|
-
},
|
|
69
|
+
}, v = [g, {
|
|
64
70
|
r: 15,
|
|
65
71
|
g: 13,
|
|
66
72
|
b: 23,
|
|
67
73
|
a: 1
|
|
68
|
-
}],
|
|
74
|
+
}], y = [
|
|
69
75
|
"success",
|
|
70
76
|
"info",
|
|
71
77
|
"warning",
|
|
72
78
|
"danger"
|
|
73
|
-
],
|
|
79
|
+
], b = (e) => ({
|
|
74
80
|
...e,
|
|
75
81
|
a: 1
|
|
76
|
-
}),
|
|
82
|
+
}), x = (t, r, i, a) => {
|
|
77
83
|
for (let o = i; o > 0; o--) {
|
|
78
84
|
let i = n(r, t, o);
|
|
79
|
-
if (a.every((t) => e(i, t) >=
|
|
85
|
+
if (a.every((t) => e(i, t) >= m)) return i;
|
|
80
86
|
}
|
|
81
87
|
return t;
|
|
82
|
-
},
|
|
83
|
-
let a =
|
|
84
|
-
for (let n of
|
|
88
|
+
}, S = (e, t) => `rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`, C = (e) => {
|
|
89
|
+
let a = f[e.base], o = e.base === "dark", s = {}, c = {}, l = /* @__PURE__ */ new Set();
|
|
90
|
+
for (let n of p) {
|
|
85
91
|
let i = e.colors[n] === void 0 ? null : r(e.colors[n]);
|
|
86
|
-
i && (l.add(n), s[`--kapi-${n}`] = t(i)), c[n] =
|
|
92
|
+
i && (l.add(n), s[`--kapi-${n}`] = t(i)), c[n] = b(i ?? r(a[n]));
|
|
87
93
|
}
|
|
88
|
-
let
|
|
89
|
-
|
|
90
|
-
let { bg:
|
|
91
|
-
E && (s["--kapi-surface"] = T(O), s["--kapi-soft"] = T(k), s["--kapi-border"] = T(A), s["--kapi-divider"] = T(n(C,
|
|
94
|
+
let u = e.colors.font?.trim();
|
|
95
|
+
u && (s["--kapi-font"] = u), e.radii && Object.assign(s, d(e.radii));
|
|
96
|
+
let { bg: m, card: g, line: C, ink: w } = c, T = (e) => t(e), E = l.has("bg") || l.has("card") || l.has("line"), D = E || l.has("ink"), O = n(m, g, 60), k = n(m, g, 30), A = n(C, w, 92), j = n(m, w, 96);
|
|
97
|
+
E && (s["--kapi-surface"] = T(O), s["--kapi-soft"] = T(k), s["--kapi-border"] = T(A), s["--kapi-divider"] = T(n(C, g, 50)), s["--kapi-tab"] = T(j), s["--kapi-sk-base"] = T(n(m, w, 94)), s["--kapi-sk-shine"] = T(o ? A : n(g, m, 50)));
|
|
92
98
|
let M = [
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
m,
|
|
100
|
+
g,
|
|
95
101
|
O,
|
|
96
102
|
k,
|
|
97
103
|
j
|
|
98
104
|
], N = {};
|
|
99
|
-
for (let [e, t] of Object.entries(
|
|
100
|
-
l.has("primary") && (s["--kapi-primary-fg"] = T(i(c.primary,
|
|
101
|
-
let P =
|
|
105
|
+
for (let [e, t] of Object.entries(h)) N[e] = x(w, m, t, M), D && (s[e] = T(N[e]));
|
|
106
|
+
l.has("primary") && (s["--kapi-primary-fg"] = T(i(c.primary, v)));
|
|
107
|
+
let P = y.filter((e) => l.has(e)).map((e) => [e, c[e]]);
|
|
102
108
|
D && P.push(["neutral", N["--kapi-muted-2"]]);
|
|
103
|
-
for (let [e, t] of P) s[`--kapi-${e}-bg`] = T(n(t,
|
|
104
|
-
D && (s["--kapi-neutral"] = T(N["--kapi-muted-2"])), l.has("ink") && (s["--kapi-tip-bg"] = T(w), s["--kapi-tip-fg"] = T(i(w,
|
|
105
|
-
let F = o ?
|
|
109
|
+
for (let [e, t] of P) s[`--kapi-${e}-bg`] = T(n(t, g, o ? 16 : 12)), s[`--kapi-${e}-border`] = T(n(t, g, o ? 35 : 28)), s[`--kapi-${e}-fg`] = T(i(t, v));
|
|
110
|
+
D && (s["--kapi-neutral"] = T(N["--kapi-muted-2"])), l.has("ink") && (s["--kapi-tip-bg"] = T(w), s["--kapi-tip-fg"] = T(i(w, v)));
|
|
111
|
+
let F = o ? _ : n(w, _, 60), I = o ? {
|
|
106
112
|
base: .55,
|
|
107
113
|
soft: .3,
|
|
108
114
|
tour: .65,
|
|
@@ -119,7 +125,10 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
119
125
|
strong: .6,
|
|
120
126
|
edge: .06
|
|
121
127
|
};
|
|
122
|
-
return l.has("ink") && !o && (s["--kapi-scrim"] =
|
|
128
|
+
return l.has("ink") && !o && (s["--kapi-scrim"] = S(F, I.base), s["--kapi-scrim-soft"] = S(F, I.soft), s["--kapi-scrim-tour"] = S(F, I.tour), s["--kapi-scrim-drawer"] = S(F, I.drawer), s["--kapi-scrim-cmdk"] = S(F, I.cmdk), s["--kapi-scrim-strong"] = S(F, I.strong), s["--kapi-edge-shade"] = S(F, I.edge)), e.series?.slice(0, 8).forEach((e, n) => {
|
|
129
|
+
let i = r(e);
|
|
130
|
+
i && (s[`--kapi-series-${n + 1}`] = t(i));
|
|
131
|
+
}), s;
|
|
123
132
|
};
|
|
124
133
|
//#endregion
|
|
125
|
-
export { a as RADIUS_PX_PATTERN, o as RADIUS_SHAPE_PATTERN,
|
|
134
|
+
export { a as RADIUS_PX_PATTERN, o as RADIUS_SHAPE_PATTERN, C as deriveTheme };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type KapiThemeRadii } from "./themeDeriveLogic";
|
|
2
2
|
/** Shared empty value, so "no radii" is referentially stable across renders. */
|
|
3
3
|
export declare const NO_THEME_RADII: KapiThemeRadii;
|
|
4
|
-
/** Keeps only known knobs whose value is a well-formed length (`control`/`surface`: px; `squircle`: px or %). */
|
|
4
|
+
/** Keeps only known knobs whose value is a well-formed length (`control`/`box`/`surface`: px; `squircle`: px or %). */
|
|
5
5
|
export declare const sanitizeThemeRadii: (input: unknown) => KapiThemeRadii;
|
|
6
6
|
/** Parses the stored JSON. Broken or invalid JSON counts as "no radii"; it never throws. */
|
|
7
7
|
export declare const parseStoredThemeRadii: (raw: string | null | undefined) => KapiThemeRadii;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { parseColor as e } from "./colorLogic.js";
|
|
3
|
+
import { deriveTheme as t } from "./themeDeriveLogic.js";
|
|
4
|
+
import { defaultStorage as n, readWithLegacy as r, storageKey as i } from "./storageLogic.js";
|
|
5
|
+
import { useMediaQuery as a } from "./useMediaQuery.js";
|
|
6
6
|
import { NO_THEME_COLORS as o, mergeThemeColors as s, parseStoredThemeColors as c, sanitizeThemeColors as l, serializeThemeColors as u } from "./themeColorsLogic.js";
|
|
7
7
|
import { NO_THEME_RADII as d, mergeThemeRadii as f, parseStoredThemeRadii as p, sanitizeThemeRadii as m, serializeThemeRadii as h } from "./themeRadiiLogic.js";
|
|
8
8
|
import { createContext as g, useCallback as _, useContext as v, useEffect as y, useMemo as b, useState as x } from "react";
|
|
9
9
|
//#region src/hooks/useKapiTheme.ts
|
|
10
10
|
var S = "(prefers-color-scheme: dark)", C = (e) => ({
|
|
11
|
-
theme:
|
|
12
|
-
accent:
|
|
13
|
-
font:
|
|
14
|
-
motion:
|
|
15
|
-
customTheme:
|
|
16
|
-
radii:
|
|
11
|
+
theme: i(e, "theme"),
|
|
12
|
+
accent: i(e, "accent"),
|
|
13
|
+
font: i(e, "font"),
|
|
14
|
+
motion: i(e, "motion"),
|
|
15
|
+
customTheme: i(e, "customTheme"),
|
|
16
|
+
radii: i(e, "radii")
|
|
17
17
|
}), w = {
|
|
18
18
|
theme: "v2_theme",
|
|
19
19
|
accent: "v2_accent",
|
|
@@ -25,24 +25,24 @@ var T = {
|
|
|
25
25
|
nunito: "'Nunito Variable', 'Nunito', system-ui, sans-serif",
|
|
26
26
|
roboto: "'Roboto', system-ui, sans-serif",
|
|
27
27
|
system: "system-ui, -apple-system, 'Segoe UI', sans-serif"
|
|
28
|
-
}, E = (
|
|
28
|
+
}, E = (e, t, i) => r(n(), C(e)[t], w[t]) || i, D = (e, t) => {
|
|
29
29
|
try {
|
|
30
30
|
localStorage.setItem(e, t);
|
|
31
31
|
} catch {}
|
|
32
32
|
}, O = (e) => e === "light" || e === "dark", k = (e) => O(e) || e === "system", A = (e, t) => e === "system" ? t ? "dark" : "light" : e, j = (e) => {
|
|
33
33
|
let t = E(e, "theme", "light");
|
|
34
34
|
return k(t) ? t : "light";
|
|
35
|
-
}, M = (e) => e === "dark" ? "light" : "dark", N = (e) => e in T, P = (e) => e === "auto" || e === "reduced", F = (
|
|
36
|
-
let
|
|
37
|
-
...
|
|
35
|
+
}, M = (e) => e === "dark" ? "light" : "dark", N = (e) => e in T, P = (e) => e === "auto" || e === "reduced", F = (n, r) => {
|
|
36
|
+
let i = n.fontChosen && r ? {
|
|
37
|
+
...r,
|
|
38
38
|
font: void 0
|
|
39
|
-
} :
|
|
40
|
-
return o && delete
|
|
41
|
-
"--kapi-font": T[
|
|
42
|
-
...
|
|
43
|
-
base:
|
|
44
|
-
colors:
|
|
45
|
-
radii: f(
|
|
39
|
+
} : r, a = s(i, n.accent ? { primary: n.accent } : null, n.customTheme), o = a.primary && !e(a.primary) ? a.primary : void 0;
|
|
40
|
+
return o && delete a.primary, {
|
|
41
|
+
"--kapi-font": T[n.font] ?? T.nunito,
|
|
42
|
+
...t({
|
|
43
|
+
base: n.theme ?? "light",
|
|
44
|
+
colors: a,
|
|
45
|
+
radii: f(n.radii)
|
|
46
46
|
}),
|
|
47
47
|
...o ? { "--kapi-primary": o } : {}
|
|
48
48
|
};
|
|
@@ -65,7 +65,7 @@ var T = {
|
|
|
65
65
|
setMotion: () => {},
|
|
66
66
|
toggleMotion: () => {}
|
|
67
67
|
}), L = ({ namespace: e } = {}) => {
|
|
68
|
-
let t = b(() => C(e), [e]), [n,
|
|
68
|
+
let t = b(() => C(e), [e]), [n, r] = x(() => j(e)), i = A(n, a(S)), [o, s] = x(() => E(e, "accent", "")), [d, f] = x(() => c(E(e, "customTheme", ""))), [g, v] = x(() => p(E(e, "radii", ""))), [w, T] = x(() => N(E(e, "font", ""))), [O, k] = x(() => {
|
|
69
69
|
let t = E(e, "font", "nunito");
|
|
70
70
|
return N(t) ? t : "nunito";
|
|
71
71
|
}), [F, I] = x(() => {
|
|
@@ -73,7 +73,7 @@ var T = {
|
|
|
73
73
|
return P(t) ? t : "auto";
|
|
74
74
|
}), [L, R] = x(e);
|
|
75
75
|
if (L !== e) {
|
|
76
|
-
R(e),
|
|
76
|
+
R(e), r(j(e)), s(E(e, "accent", "")), f(c(E(e, "customTheme", ""))), v(p(E(e, "radii", "")));
|
|
77
77
|
let t = E(e, "font", "nunito");
|
|
78
78
|
k(N(t) ? t : "nunito"), T(N(E(e, "font", "")));
|
|
79
79
|
let n = E(e, "motion", "auto");
|
|
@@ -86,11 +86,11 @@ var T = {
|
|
|
86
86
|
O,
|
|
87
87
|
w
|
|
88
88
|
]), y(() => D(t.motion, F), [t, F]);
|
|
89
|
-
let z = _(() =>
|
|
89
|
+
let z = _(() => r(M(i)), [i]), B = _((e) => r(e), []), V = _((e) => s(e || ""), []), H = _((e) => f(l(e)), []), U = _((e) => v(m(e)), []), W = _((e) => {
|
|
90
90
|
k(e), T(!0);
|
|
91
91
|
}, []), G = _(() => I((e) => e === "reduced" ? "auto" : "reduced"), []);
|
|
92
92
|
return b(() => ({
|
|
93
|
-
theme:
|
|
93
|
+
theme: i,
|
|
94
94
|
preference: n,
|
|
95
95
|
accent: o,
|
|
96
96
|
customTheme: d,
|
|
@@ -99,7 +99,7 @@ var T = {
|
|
|
99
99
|
fontChosen: w,
|
|
100
100
|
motion: F,
|
|
101
101
|
setTheme: B,
|
|
102
|
-
setPreference:
|
|
102
|
+
setPreference: r,
|
|
103
103
|
toggle: z,
|
|
104
104
|
setAccent: V,
|
|
105
105
|
setCustomTheme: H,
|
|
@@ -108,7 +108,7 @@ var T = {
|
|
|
108
108
|
setMotion: I,
|
|
109
109
|
toggleMotion: G
|
|
110
110
|
}), [
|
|
111
|
-
|
|
111
|
+
i,
|
|
112
112
|
n,
|
|
113
113
|
o,
|
|
114
114
|
d,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/** Breakpoint móvil del shell (mantener sincronizado con shell.css). */
|
|
2
2
|
export declare const SHELL_MOBILE_QUERY = "(max-width: 768px)";
|
|
3
|
+
/**
|
|
4
|
+
* Escritorio angosto: el rail sigue vertical pero el panel ya no entra cómodo. 1024 no es un
|
|
5
|
+
* número nuevo, es el breakpoint que la cáscara ya usa para su padding (`shell.css`). Medido con
|
|
6
|
+
* rail y panel abiertos, el contenido queda en 674px a 1024 contra 930 a 1280; plegando el panel
|
|
7
|
+
* a su riel de 44px recupera 214.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SHELL_NARROW_QUERY = "(max-width: 1024px)";
|
|
3
10
|
/** `matchMedia` seguro (SSR / jsdom sin matchMedia → false). */
|
|
4
11
|
export declare const matchesQuery: (query: string) => boolean;
|
|
5
12
|
/** true mientras el viewport cumple la media query. */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect as e, useState as t } from "react";
|
|
3
3
|
//#region src/hooks/useMediaQuery.ts
|
|
4
|
-
var n = "(max-width: 768px)", r = (e) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(e).matches,
|
|
5
|
-
let [
|
|
4
|
+
var n = "(max-width: 768px)", r = "(max-width: 1024px)", i = (e) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(e).matches, a = (n) => {
|
|
5
|
+
let [r, a] = t(() => i(n));
|
|
6
6
|
return e(() => {
|
|
7
7
|
if (typeof window.matchMedia != "function") return;
|
|
8
8
|
let e = window.matchMedia(n), t = () => a(e.matches);
|
|
9
9
|
return t(), e.addEventListener("change", t), () => e.removeEventListener("change", t);
|
|
10
|
-
}, [n]),
|
|
10
|
+
}, [n]), r;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
13
|
-
export { n as SHELL_MOBILE_QUERY, r as
|
|
13
|
+
export { n as SHELL_MOBILE_QUERY, r as SHELL_NARROW_QUERY, i as matchesQuery, a as useMediaQuery };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export type UseWheelZoomOptions = {
|
|
3
|
+
/** Nivel actual. */
|
|
4
|
+
value: number;
|
|
5
|
+
/** Nivel nuevo, ya acotado y pegado al paso. Sólo se llama si el valor cambió. */
|
|
6
|
+
onChange: (value: number) => void;
|
|
7
|
+
/** Mínimo. */
|
|
8
|
+
min: number;
|
|
9
|
+
/** Máximo. */
|
|
10
|
+
max: number;
|
|
11
|
+
/** Cuánto cambia por cada evento de rueda. */
|
|
12
|
+
step: number;
|
|
13
|
+
/** Sólo con Ctrl/Cmd apretado; sin él la rueda scrollea normal. @default true */
|
|
14
|
+
requireModifier?: boolean | undefined;
|
|
15
|
+
/** Escucha sólo mientras sea true. @default true */
|
|
16
|
+
enabled?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Zoom con Ctrl + rueda del mouse sobre un elemento. Devolvé el ref al elemento (`<div ref={ref} />`).
|
|
20
|
+
*
|
|
21
|
+
* El pellizco de trackpad llega como eventos `wheel` con `ctrlKey: true`, así que el mismo código cubre
|
|
22
|
+
* los dos gestos. Un paso por evento (ver `nextWheelZoom`): deltaY negativo acerca.
|
|
23
|
+
*
|
|
24
|
+
* POR QUÉ ES UN HOOK Y NO UN `onWheel`: React registra `wheel` como listener PASIVO en el contenedor
|
|
25
|
+
* raíz, y en un listener pasivo `preventDefault()` se ignora sin avisar. Con Ctrl apretado el navegador
|
|
26
|
+
* entonces zoomea la PÁGINA entera además de tu control (medido en Chromium: `defaultPrevented: false`
|
|
27
|
+
* con el listener pasivo, `true` con uno no pasivo). Acá el listener se ata a mano con
|
|
28
|
+
* `{ passive: false }`, que es lo único que le devuelve el zoom al elemento.
|
|
29
|
+
*/
|
|
30
|
+
export declare const useWheelZoom: <T extends HTMLElement = HTMLDivElement>(options: UseWheelZoomOptions) => RefObject<T | null>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { nextWheelZoom as e } from "./wheelZoomLogic.js";
|
|
3
|
+
import { useEffect as t, useRef as n } from "react";
|
|
4
|
+
//#region src/hooks/useWheelZoom.ts
|
|
5
|
+
var r = (r) => {
|
|
6
|
+
let i = n(null), a = n(r);
|
|
7
|
+
a.current = r;
|
|
8
|
+
let o = r.enabled ?? !0;
|
|
9
|
+
return t(() => {
|
|
10
|
+
let t = i.current;
|
|
11
|
+
if (!t || !o) return;
|
|
12
|
+
let n = (t) => {
|
|
13
|
+
let { value: n, onChange: r, min: i, max: o, step: s, requireModifier: c = !0 } = a.current;
|
|
14
|
+
if (c && !t.ctrlKey && !t.metaKey) return;
|
|
15
|
+
t.preventDefault();
|
|
16
|
+
let l = e(n, t.deltaY, {
|
|
17
|
+
min: i,
|
|
18
|
+
max: o,
|
|
19
|
+
step: s
|
|
20
|
+
});
|
|
21
|
+
l !== n && r(l);
|
|
22
|
+
};
|
|
23
|
+
return t.addEventListener("wheel", n, { passive: !1 }), () => t.removeEventListener("wheel", n);
|
|
24
|
+
}, [o]), i;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { r as useWheelZoom };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type WheelZoomRange = {
|
|
2
|
+
min: number;
|
|
3
|
+
max: number;
|
|
4
|
+
step: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Nivel siguiente para un `deltaY` de rueda: un paso por evento, acotado y pegado a la grilla del paso.
|
|
8
|
+
*
|
|
9
|
+
* Se usa el SIGNO de `deltaY`, no su magnitud. Con el trackpad llegan muchos eventos seguidos y el zoom
|
|
10
|
+
* avanza rápido; la alternativa (acumular delta hasta un umbral) vuelve impredecible cuánto zoom hace un
|
|
11
|
+
* gesto, y los pasos tienen que ser los mismos que los de los botones +/− del visor. `deltaY < 0`
|
|
12
|
+
* (rueda hacia arriba, pellizco de apertura) acerca; `deltaY === 0` no hace nada.
|
|
13
|
+
*
|
|
14
|
+
* La grilla está anclada en `min`: con `min: 50` y `step: 25`, desde 110 acercar da 125 y alejar da 100.
|
|
15
|
+
* Un `value` fuera de rango se acota primero (NaN cae en `min`). Con un `step` no positivo o un rango
|
|
16
|
+
* inválido devuelve `value` tal cual: no hay grilla sobre la cual moverse.
|
|
17
|
+
*/
|
|
18
|
+
export declare const nextWheelZoom: (value: number, deltaY: number, range: WheelZoomRange) => number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/hooks/wheelZoomLogic.ts
|
|
2
|
+
var e = 1e-9, t = (t, n, r) => {
|
|
3
|
+
let { min: i, max: a, step: o } = r;
|
|
4
|
+
if (!(Number.isFinite(i) && Number.isFinite(a) && Number.isFinite(o) && o > 0 && i <= a) || n === 0 || Number.isNaN(n)) return t;
|
|
5
|
+
let s = ((Number.isNaN(t) ? i : Math.min(a, Math.max(i, t))) - i) / o, c = n < 0 ? Math.floor(s + e) + 1 : Math.ceil(s - e) - 1;
|
|
6
|
+
return Math.min(a, Math.max(i, i + c * o));
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as nextWheelZoom };
|