@kuntiwar/tonalkit 0.0.0-stage → 1.0.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/dist/index.js ADDED
@@ -0,0 +1,2501 @@
1
+ "use client";
2
+ import {
3
+ blueTheme,
4
+ breakpointKeys,
5
+ breakpoints,
6
+ createTheme,
7
+ darkTheme,
8
+ pinkTheme,
9
+ themeToCss,
10
+ themeToCssVars,
11
+ themes,
12
+ typographyScale
13
+ } from "./chunk-DKFQD2ME.js";
14
+
15
+ // src/provider/ThemeProvider.tsx
16
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
17
+
18
+ // src/utils/cx.ts
19
+ function cx(...values) {
20
+ const out = [];
21
+ for (const v of values) {
22
+ if (!v && v !== 0) continue;
23
+ if (Array.isArray(v)) {
24
+ const inner = cx(...v);
25
+ if (inner) out.push(inner);
26
+ } else out.push(String(v));
27
+ }
28
+ return out.join(" ");
29
+ }
30
+
31
+ // src/provider/ThemeProvider.tsx
32
+ import { jsx } from "react/jsx-runtime";
33
+ var defaultVars = themeToCssVars(blueTheme);
34
+ var ThemeContext = createContext({
35
+ theme: blueTheme,
36
+ setTheme: () => {
37
+ },
38
+ cssVars: defaultVars
39
+ });
40
+ function resolve(t) {
41
+ return typeof t === "string" ? themes[t] ?? blueTheme : t;
42
+ }
43
+ function ThemeProvider({
44
+ theme: themeProp,
45
+ defaultTheme = "blue",
46
+ onThemeChange,
47
+ target = "wrapper",
48
+ paintSurface = true,
49
+ className,
50
+ style,
51
+ children
52
+ }) {
53
+ const [inner, setInner] = useState(() => resolve(defaultTheme));
54
+ const theme = themeProp !== void 0 ? resolve(themeProp) : inner;
55
+ const setTheme = useCallback(
56
+ (next) => {
57
+ const t = resolve(next);
58
+ if (themeProp === void 0) setInner(t);
59
+ onThemeChange?.(t);
60
+ },
61
+ [themeProp, onThemeChange]
62
+ );
63
+ const cssVars = useMemo(() => themeToCssVars(theme), [theme]);
64
+ const value = useMemo(() => ({ theme, setTheme, cssVars }), [theme, setTheme, cssVars]);
65
+ useEffect(() => {
66
+ if (target !== "root") return;
67
+ const el = document.documentElement;
68
+ const entries = Object.entries(cssVars);
69
+ for (const [k, v] of entries) el.style.setProperty(k, v);
70
+ const prevScheme = el.style.colorScheme;
71
+ el.style.colorScheme = theme.mode;
72
+ el.dataset.tkTheme = theme.name;
73
+ return () => {
74
+ for (const [k] of entries) el.style.removeProperty(k);
75
+ el.style.colorScheme = prevScheme;
76
+ delete el.dataset.tkTheme;
77
+ };
78
+ }, [target, cssVars, theme]);
79
+ if (target === "root") {
80
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children: /* @__PURE__ */ jsx("div", { className: cx("tk-root", paintSurface && "tk-root--surface", className), "data-tk-theme": theme.name, style, children }) });
81
+ }
82
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children: /* @__PURE__ */ jsx(
83
+ "div",
84
+ {
85
+ className: cx("tk-root", paintSurface && "tk-root--surface", className),
86
+ "data-tk-theme": theme.name,
87
+ style: { ...cssVars, colorScheme: theme.mode, ...style },
88
+ children
89
+ }
90
+ ) });
91
+ }
92
+ function useTheme() {
93
+ return useContext(ThemeContext);
94
+ }
95
+
96
+ // src/hooks/useMediaQuery.ts
97
+ import { useCallback as useCallback2, useSyncExternalStore } from "react";
98
+ function useMediaQuery(query) {
99
+ const subscribe = useCallback2(
100
+ (cb) => {
101
+ if (typeof window === "undefined" || !window.matchMedia) return () => {
102
+ };
103
+ const mql = window.matchMedia(query);
104
+ mql.addEventListener("change", cb);
105
+ return () => mql.removeEventListener("change", cb);
106
+ },
107
+ [query]
108
+ );
109
+ const get = () => typeof window !== "undefined" && window.matchMedia ? window.matchMedia(query).matches : false;
110
+ return useSyncExternalStore(subscribe, get, () => false);
111
+ }
112
+ function useBreakpointUp(bp) {
113
+ return useMediaQuery(`(min-width: ${breakpoints[bp]}px)`);
114
+ }
115
+ function useBreakpoint() {
116
+ const sm = useBreakpointUp("sm");
117
+ const md = useBreakpointUp("md");
118
+ const lg = useBreakpointUp("lg");
119
+ const xl = useBreakpointUp("xl");
120
+ const flags = [true, sm, md, lg, xl];
121
+ let current = "xs";
122
+ breakpointKeys.forEach((k, i) => {
123
+ if (flags[i]) current = k;
124
+ });
125
+ return current;
126
+ }
127
+
128
+ // src/hooks/useControllableState.ts
129
+ import { useCallback as useCallback3, useRef, useState as useState2 } from "react";
130
+ function useControllableState({ value, defaultValue, onChange }) {
131
+ const [inner, setInner] = useState2(defaultValue);
132
+ const controlled = value !== void 0;
133
+ const current = controlled ? value : inner;
134
+ const onChangeRef = useRef(onChange);
135
+ onChangeRef.current = onChange;
136
+ const currentRef = useRef(current);
137
+ currentRef.current = current;
138
+ const set = useCallback3(
139
+ (next) => {
140
+ if (Object.is(next, currentRef.current)) return;
141
+ if (!controlled) setInner(next);
142
+ onChangeRef.current?.(next);
143
+ },
144
+ [controlled]
145
+ );
146
+ return [current, set];
147
+ }
148
+
149
+ // src/layout/Container.tsx
150
+ import { forwardRef } from "react";
151
+ import { jsx as jsx2 } from "react/jsx-runtime";
152
+ var Container = forwardRef(function Container2({ maxWidth = "lg", disableGutters, as: Tag = "div", className, ...rest }, ref) {
153
+ return /* @__PURE__ */ jsx2(
154
+ Tag,
155
+ {
156
+ ref,
157
+ className: cx("tk-container", maxWidth ? `tk-container--${maxWidth}` : "tk-container--fluid", disableGutters && "tk-container--disable-gutters", className),
158
+ ...rest
159
+ }
160
+ );
161
+ });
162
+
163
+ // src/layout/Grid.tsx
164
+ import { forwardRef as forwardRef2 } from "react";
165
+ import { jsx as jsx3 } from "react/jsx-runtime";
166
+ var unit = (n) => `calc(var(--tk-space, 4px) * ${n})`;
167
+ var Grid = forwardRef2(function Grid2({ columns = 12, gap = 4, rowGap, columnGap, alignItems, justifyItems, as: Tag = "div", className, style, ...rest }, ref) {
168
+ const s = {
169
+ "--tk-grid-cols": columns,
170
+ "--tk-grid-row-gap": unit(rowGap ?? gap),
171
+ "--tk-grid-col-gap": unit(columnGap ?? gap),
172
+ alignItems,
173
+ justifyItems,
174
+ ...style
175
+ };
176
+ return /* @__PURE__ */ jsx3(Tag, { ref, className: cx("tk-grid", className), style: s, ...rest });
177
+ });
178
+ var Col = forwardRef2(function Col2({ span, xs, sm, md, lg, xl, offset, full, as: Tag = "div", className, style, ...rest }, ref) {
179
+ const spans = { xs: xs ?? span, sm, md, lg, xl };
180
+ const offsets = typeof offset === "number" ? { xs: offset } : offset ?? {};
181
+ const classes = [];
182
+ for (const bp of breakpointKeys) {
183
+ const v = spans[bp];
184
+ if (v !== void 0) classes.push(v === "auto" ? `tk-col-${bp}-auto` : `tk-col-${bp}-${Math.min(12, Math.max(1, v))}`);
185
+ const o = offsets[bp];
186
+ if (o !== void 0) classes.push(`tk-col-offset-${bp}-${Math.min(11, Math.max(0, o))}`);
187
+ }
188
+ return /* @__PURE__ */ jsx3(
189
+ Tag,
190
+ {
191
+ ref,
192
+ className: cx("tk-col", full && "tk-col--full", classes, className),
193
+ style: { minWidth: 0, ...style },
194
+ ...rest
195
+ }
196
+ );
197
+ });
198
+
199
+ // src/layout/Stack.tsx
200
+ import { Children, Fragment, forwardRef as forwardRef3, isValidElement } from "react";
201
+ import { jsx as jsx4 } from "react/jsx-runtime";
202
+ var Stack = forwardRef3(function Stack2({ direction = "column", spacing = 2, alignItems, justifyContent, wrap, divider, as: Tag = "div", className, style, children, ...rest }, ref) {
203
+ const items = Children.toArray(children);
204
+ const content = divider ? items.flatMap((child, i) => {
205
+ const key = isValidElement(child) && child.key != null ? String(child.key) : String(i);
206
+ return i === 0 ? [/* @__PURE__ */ jsx4(Fragment, { children: child }, key)] : [/* @__PURE__ */ jsx4(Fragment, { children: divider }, `d-${key}`), /* @__PURE__ */ jsx4(Fragment, { children: child }, key)];
207
+ }) : items;
208
+ return /* @__PURE__ */ jsx4(
209
+ Tag,
210
+ {
211
+ ref,
212
+ className: cx("tk-stack", `tk-stack--${direction}`, wrap && "tk-stack--wrap", className),
213
+ style: { gap: `calc(var(--tk-space, 4px) * ${spacing})`, alignItems, justifyContent, ...style },
214
+ ...rest,
215
+ children: content
216
+ }
217
+ );
218
+ });
219
+
220
+ // src/components/Icon/Icon.tsx
221
+ import { forwardRef as forwardRef4 } from "react";
222
+ import { jsx as jsx5 } from "react/jsx-runtime";
223
+ var iconPaths = {
224
+ add: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",
225
+ remove: "M19 13H5v-2h14v2z",
226
+ close: "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",
227
+ check: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z",
228
+ "check-circle": "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z",
229
+ info: "M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z",
230
+ warning: "M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",
231
+ error: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z",
232
+ "chevron-left": "M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z",
233
+ "chevron-right": "M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z",
234
+ "expand-more": "M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z",
235
+ "expand-less": "M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z",
236
+ "first-page": "M18.41 16.59 13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z",
237
+ "last-page": "M5.59 7.41 10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z",
238
+ menu: "M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z",
239
+ search: "M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",
240
+ home: "M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z",
241
+ person: "M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z",
242
+ settings: "M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z",
243
+ mail: "M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4-8 5-8-5V6l8 5 8-5v2z",
244
+ notifications: "M12 22c1.1 0 2-.9 2-2h-4c0 1.1.89 2 2 2zm6-6v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2z",
245
+ star: "M12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z",
246
+ favorite: "M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z",
247
+ delete: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",
248
+ edit: "M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",
249
+ upload: "M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z",
250
+ download: "M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",
251
+ file: "M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm-1 7V3.5L18.5 9H13z",
252
+ calendar: "M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V10h14v10zm0-12H5V6h14v2z",
253
+ "visibility": "M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z",
254
+ "visibility-off": "M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78 3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z",
255
+ "more-vert": "M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z",
256
+ copy: "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",
257
+ folder: "M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",
258
+ dashboard: "M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"
259
+ };
260
+ var Icon = forwardRef4(function Icon2({ name, size = 24, title, className, children, style, ...rest }, ref) {
261
+ const dim = typeof size === "number" ? `${size}px` : size;
262
+ return /* @__PURE__ */ jsx5(
263
+ "svg",
264
+ {
265
+ ref,
266
+ className: cx("tk-icon", className),
267
+ viewBox: "0 0 24 24",
268
+ width: dim,
269
+ height: dim,
270
+ fill: "currentColor",
271
+ focusable: "false",
272
+ role: title ? "img" : void 0,
273
+ "aria-hidden": title ? void 0 : true,
274
+ "aria-label": title,
275
+ style,
276
+ ...rest,
277
+ children: name ? /* @__PURE__ */ jsx5("path", { d: iconPaths[name] }) : children
278
+ }
279
+ );
280
+ });
281
+
282
+ // src/hooks/useFloating.ts
283
+ import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
284
+
285
+ // src/hooks/useIsomorphicLayoutEffect.ts
286
+ import { useEffect as useEffect2, useLayoutEffect } from "react";
287
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect2;
288
+
289
+ // src/hooks/useFloating.ts
290
+ var opposite = { top: "bottom", bottom: "top", left: "right", right: "left" };
291
+ var PAD = 8;
292
+ function place(anchor, float, placement, offset) {
293
+ const [side, align = "center"] = placement.split("-");
294
+ let top = 0;
295
+ let left = 0;
296
+ if (side === "top") top = anchor.top - float.height - offset;
297
+ else if (side === "bottom") top = anchor.top + anchor.height + offset;
298
+ else if (side === "left") left = anchor.left - float.width - offset;
299
+ else left = anchor.left + anchor.width + offset;
300
+ if (side === "top" || side === "bottom") {
301
+ if (align === "start") left = anchor.left;
302
+ else if (align === "end") left = anchor.left + anchor.width - float.width;
303
+ else left = anchor.left + anchor.width / 2 - float.width / 2;
304
+ } else {
305
+ if (align === "start") top = anchor.top;
306
+ else if (align === "end") top = anchor.top + anchor.height - float.height;
307
+ else top = anchor.top + anchor.height / 2 - float.height / 2;
308
+ }
309
+ return { top, left };
310
+ }
311
+ function computePosition(anchor, float, placement, offset, vw, vh) {
312
+ const [side, align] = placement.split("-");
313
+ let used = placement;
314
+ let pos = place(anchor, float, placement, offset);
315
+ const overflows = (p) => p.top < PAD || p.left < PAD || p.top + float.height > vh - PAD || p.left + float.width > vw - PAD;
316
+ if (overflows(pos)) {
317
+ const flipped = align ? `${opposite[side]}-${align}` : opposite[side];
318
+ const alt = place(anchor, float, flipped, offset);
319
+ const mainFits = side === "top" || side === "bottom" ? alt.top >= PAD && alt.top + float.height <= vh - PAD : alt.left >= PAD && alt.left + float.width <= vw - PAD;
320
+ if (mainFits) {
321
+ pos = alt;
322
+ used = flipped;
323
+ }
324
+ }
325
+ const left = Math.max(PAD, Math.min(pos.left, vw - float.width - PAD));
326
+ const top = Math.max(PAD, Math.min(pos.top, vh - float.height - PAD));
327
+ return { top, left, placement: used };
328
+ }
329
+ function useFloating({ open, anchorRef, point, placement = "bottom", offset = 8 }) {
330
+ const floatingRef = useRef2(null);
331
+ const [state, setState] = useState3(null);
332
+ const update = useCallback4(() => {
333
+ const el = floatingRef.current;
334
+ if (!el) return;
335
+ let anchor = null;
336
+ if (point) anchor = { top: point.y, left: point.x, width: 0, height: 0 };
337
+ else if (anchorRef?.current) {
338
+ const r = anchorRef.current.getBoundingClientRect();
339
+ anchor = { top: r.top, left: r.left, width: r.width, height: r.height };
340
+ }
341
+ if (!anchor) return;
342
+ const fr = el.getBoundingClientRect();
343
+ const next = computePosition(anchor, { top: 0, left: 0, width: fr.width, height: fr.height }, placement, offset, window.innerWidth, window.innerHeight);
344
+ setState((prev) => prev && prev.top === next.top && prev.left === next.left && prev.placement === next.placement ? prev : next);
345
+ }, [anchorRef, point, placement, offset]);
346
+ useIsomorphicLayoutEffect(() => {
347
+ if (!open) {
348
+ setState(null);
349
+ return;
350
+ }
351
+ update();
352
+ }, [open, update]);
353
+ useEffect3(() => {
354
+ if (!open) return;
355
+ const onChange = () => update();
356
+ window.addEventListener("resize", onChange);
357
+ window.addEventListener("scroll", onChange, true);
358
+ let ro;
359
+ if (typeof ResizeObserver !== "undefined" && floatingRef.current) {
360
+ ro = new ResizeObserver(onChange);
361
+ ro.observe(floatingRef.current);
362
+ }
363
+ return () => {
364
+ window.removeEventListener("resize", onChange);
365
+ window.removeEventListener("scroll", onChange, true);
366
+ ro?.disconnect();
367
+ };
368
+ }, [open, update]);
369
+ const style = {
370
+ position: "fixed",
371
+ top: state?.top ?? 0,
372
+ left: state?.left ?? 0,
373
+ visibility: state ? "visible" : "hidden"
374
+ };
375
+ return { floatingRef, style, placement: state?.placement ?? placement, update };
376
+ }
377
+
378
+ // src/hooks/usePresence.ts
379
+ import { useEffect as useEffect4, useState as useState4 } from "react";
380
+ function usePresence(open, exitMs = 200) {
381
+ const [mounted, setMounted] = useState4(open);
382
+ const [visible, setVisible] = useState4(false);
383
+ useEffect4(() => {
384
+ if (open) {
385
+ setMounted(true);
386
+ let inner = 0;
387
+ const outer = requestAnimationFrame(() => {
388
+ inner = requestAnimationFrame(() => setVisible(true));
389
+ });
390
+ return () => {
391
+ cancelAnimationFrame(outer);
392
+ cancelAnimationFrame(inner);
393
+ };
394
+ }
395
+ setVisible(false);
396
+ const t = setTimeout(() => setMounted(false), exitMs);
397
+ return () => clearTimeout(t);
398
+ }, [open, exitMs]);
399
+ return { mounted, visible };
400
+ }
401
+
402
+ // src/components/Accordion/Accordion.tsx
403
+ import { createContext as createContext2, forwardRef as forwardRef6, useContext as useContext2, useId } from "react";
404
+
405
+ // src/components/Collapse/Collapse.tsx
406
+ import { forwardRef as forwardRef5 } from "react";
407
+ import { jsx as jsx6 } from "react/jsx-runtime";
408
+ var Collapse = forwardRef5(function Collapse2({ open, className, children, ...rest }, ref) {
409
+ return /* @__PURE__ */ jsx6("div", { ref, className: cx("tk-collapse", open && "tk-collapse--open", className), "aria-hidden": !open, ...rest, children: /* @__PURE__ */ jsx6("div", { className: "tk-collapse__inner", children }) });
410
+ });
411
+
412
+ // src/components/Accordion/Accordion.tsx
413
+ import { jsx as jsx7, jsxs } from "react/jsx-runtime";
414
+ var Ctx = createContext2(null);
415
+ var Accordion = forwardRef6(function Accordion2({ type = "single", collapsible = true, value, defaultValue = [], onChange, variant = "outlined", className, children, ...rest }, ref) {
416
+ const baseId = useId();
417
+ const [open, setOpen] = useControllableState({ value, defaultValue, onChange });
418
+ const toggle = (v) => {
419
+ const isOpen = open.includes(v);
420
+ if (type === "multiple") setOpen(isOpen ? open.filter((x) => x !== v) : [...open, v]);
421
+ else if (isOpen) {
422
+ if (collapsible) setOpen([]);
423
+ } else setOpen([v]);
424
+ };
425
+ return /* @__PURE__ */ jsx7(Ctx.Provider, { value: { open, toggle, variant, baseId }, children: /* @__PURE__ */ jsx7("div", { ref, className: cx("tk-accordion", `tk-accordion--${variant}`, className), ...rest, children }) });
426
+ });
427
+ var AccordionItem = forwardRef6(function AccordionItem2({ value, title, subtitle, icon, disabled, className, children, ...rest }, ref) {
428
+ const ctx = useContext2(Ctx);
429
+ if (!ctx) throw new Error("AccordionItem must be used inside <Accordion>");
430
+ const isOpen = ctx.open.includes(value);
431
+ const headerId = `${ctx.baseId}-h-${value}`;
432
+ const panelId = `${ctx.baseId}-p-${value}`;
433
+ return /* @__PURE__ */ jsxs("div", { ref, className: cx("tk-accordion__item", isOpen && "tk-accordion__item--open", disabled && "tk-accordion__item--disabled", className), ...rest, children: [
434
+ /* @__PURE__ */ jsx7("h3", { className: "tk-accordion__heading", children: /* @__PURE__ */ jsxs("button", { type: "button", id: headerId, className: "tk-accordion__trigger", "aria-expanded": isOpen, "aria-controls": panelId, disabled, onClick: () => ctx.toggle(value), children: [
435
+ icon ? /* @__PURE__ */ jsx7("span", { className: "tk-accordion__icon", children: icon }) : null,
436
+ /* @__PURE__ */ jsxs("span", { className: "tk-accordion__titles", children: [
437
+ /* @__PURE__ */ jsx7("span", { className: "tk-accordion__title", children: title }),
438
+ subtitle ? /* @__PURE__ */ jsx7("span", { className: "tk-accordion__subtitle", children: subtitle }) : null
439
+ ] }),
440
+ /* @__PURE__ */ jsx7(Icon, { name: "expand-more", className: "tk-accordion__chevron" })
441
+ ] }) }),
442
+ /* @__PURE__ */ jsx7(Collapse, { open: isOpen, id: panelId, role: "region", "aria-labelledby": headerId, children: /* @__PURE__ */ jsx7("div", { className: "tk-accordion__content", children }) })
443
+ ] });
444
+ });
445
+
446
+ // src/components/Alert/Alert.tsx
447
+ import { forwardRef as forwardRef7 } from "react";
448
+
449
+ // src/utils/colors.ts
450
+ var colorClass = (c) => c ? `tk-c-${c}` : void 0;
451
+
452
+ // src/components/Alert/Alert.tsx
453
+ import { jsx as jsx8, jsxs as jsxs2 } from "react/jsx-runtime";
454
+ var defaultIcons = { info: "info", success: "check-circle", warning: "warning", error: "error" };
455
+ var Alert = forwardRef7(function Alert2({ severity = "info", variant = "tonal", title, icon, onClose, action, className, children, ...rest }, ref) {
456
+ return /* @__PURE__ */ jsxs2("div", { ref, role: "alert", className: cx("tk-alert", `tk-alert--${variant}`, colorClass(severity), className), ...rest, children: [
457
+ icon !== false ? /* @__PURE__ */ jsx8("span", { className: "tk-alert__icon", children: icon ?? /* @__PURE__ */ jsx8(Icon, { name: defaultIcons[severity] }) }) : null,
458
+ /* @__PURE__ */ jsxs2("div", { className: "tk-alert__body", children: [
459
+ title ? /* @__PURE__ */ jsx8("div", { className: "tk-alert__title", children: title }) : null,
460
+ children ? /* @__PURE__ */ jsx8("div", { className: "tk-alert__message", children }) : null
461
+ ] }),
462
+ action ? /* @__PURE__ */ jsx8("div", { className: "tk-alert__action", children: action }) : null,
463
+ onClose ? /* @__PURE__ */ jsx8("button", { type: "button", className: "tk-alert__close", "aria-label": "Close", onClick: onClose, children: /* @__PURE__ */ jsx8(Icon, { name: "close", size: 20 }) }) : null
464
+ ] });
465
+ });
466
+
467
+ // src/components/Avatar/Avatar.tsx
468
+ import { Children as Children2, forwardRef as forwardRef8, useState as useState5 } from "react";
469
+ import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
470
+ var palette = ["primary", "secondary", "tertiary", "info", "success", "warning", "error"];
471
+ function initialsOf(name) {
472
+ const parts = name.trim().split(/\s+/).filter(Boolean);
473
+ if (parts.length === 0) return "";
474
+ const first = parts[0][0] ?? "";
475
+ const last = parts.length > 1 ? parts[parts.length - 1][0] ?? "" : "";
476
+ return (first + last).toUpperCase();
477
+ }
478
+ function hash(str) {
479
+ let h = 0;
480
+ for (let i = 0; i < str.length; i++) h = h * 31 + str.charCodeAt(i) | 0;
481
+ return Math.abs(h);
482
+ }
483
+ var dims = { sm: 32, md: 40, lg: 56, xl: 96 };
484
+ var Avatar = forwardRef8(function Avatar2({ src, alt, name, size = "md", shape = "circle", status, children, className, style, ...rest }, ref) {
485
+ const [failed, setFailed] = useState5(false);
486
+ const px = typeof size === "number" ? size : dims[size];
487
+ const tone = name ? palette[hash(name) % palette.length] : "secondary";
488
+ const showImg = src && !failed;
489
+ const content = showImg ? /* @__PURE__ */ jsx9("img", { className: "tk-avatar__img", src, alt: alt ?? name ?? "", onError: () => setFailed(true) }) : name ? /* @__PURE__ */ jsx9("span", { "aria-label": name, role: "img", children: initialsOf(name) }) : children ?? /* @__PURE__ */ jsx9(Icon, { name: "person", size: px * 0.6 });
490
+ return /* @__PURE__ */ jsxs3(
491
+ "span",
492
+ {
493
+ ref,
494
+ className: cx("tk-avatar", `tk-c-${tone}`, shape === "rounded" && "tk-avatar--rounded", className),
495
+ style: { "--tk-avatar-size": `${px}px`, ...style },
496
+ ...rest,
497
+ children: [
498
+ content,
499
+ status ? /* @__PURE__ */ jsx9("span", { className: cx("tk-avatar__status", `tk-avatar__status--${status}`), role: "img", "aria-label": status }) : null
500
+ ]
501
+ }
502
+ );
503
+ });
504
+ var AvatarGroup = forwardRef8(function AvatarGroup2({ max = 4, size = "md", className, children, ...rest }, ref) {
505
+ const items = Children2.toArray(children);
506
+ const shown = items.slice(0, max);
507
+ const extra = items.length - shown.length;
508
+ return /* @__PURE__ */ jsxs3("div", { ref, role: "group", className: cx("tk-avatar-group", className), ...rest, children: [
509
+ shown,
510
+ extra > 0 ? /* @__PURE__ */ jsx9(Avatar, { size, className: "tk-avatar--more", children: `+${extra}` }) : null
511
+ ] });
512
+ });
513
+
514
+ // src/components/Badge/Badge.tsx
515
+ import { forwardRef as forwardRef9 } from "react";
516
+ import { Fragment as Fragment2, jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
517
+ var Badge = forwardRef9(function Badge2({ count, content, dot, max = 99, showZero, invisible, color = "error", position = "top-end", overlap = "rectangular", srLabel, children, className, ...rest }, ref) {
518
+ const hidden = invisible || !dot && content === void 0 && (count === void 0 || count === 0 && !showZero);
519
+ let text = content;
520
+ if (text === void 0 && count !== void 0) text = count > max ? `${max}+` : String(count);
521
+ const anchored = children !== void 0;
522
+ const bubbleClass = cx("tk-badge", dot && "tk-badge--dot", hidden && "tk-badge--hidden", anchored && "tk-badge--anchored", anchored && `tk-badge--${position}`, overlap === "circular" && "tk-badge--circular", colorClass(color), !anchored && className);
523
+ const inner = /* @__PURE__ */ jsxs4(Fragment2, { children: [
524
+ !dot && text,
525
+ srLabel && !hidden ? /* @__PURE__ */ jsx10("span", { className: "tk-visually-hidden", children: srLabel }) : null
526
+ ] });
527
+ if (!anchored) {
528
+ return /* @__PURE__ */ jsx10("span", { ref, className: bubbleClass, ...rest, children: inner });
529
+ }
530
+ return /* @__PURE__ */ jsxs4("span", { ref, className: cx("tk-badge-anchor", className), ...rest, children: [
531
+ children,
532
+ /* @__PURE__ */ jsx10("span", { className: bubbleClass, children: inner })
533
+ ] });
534
+ });
535
+
536
+ // src/components/Breadcrumb/Breadcrumb.tsx
537
+ import { forwardRef as forwardRef10, useState as useState6 } from "react";
538
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
539
+ var Breadcrumb = forwardRef10(function Breadcrumb2({ items, separator, maxItems, itemsBeforeCollapse = 1, itemsAfterCollapse = 2, className, ...rest }, ref) {
540
+ const [expanded, setExpanded] = useState6(false);
541
+ const collapse = !expanded && maxItems !== void 0 && items.length > maxItems;
542
+ const visible = collapse ? [...items.slice(0, itemsBeforeCollapse), "ellipsis", ...items.slice(items.length - itemsAfterCollapse)] : items;
543
+ const sep = separator ?? /* @__PURE__ */ jsx11(Icon, { name: "chevron-right", size: 18 });
544
+ return /* @__PURE__ */ jsx11("nav", { ref, "aria-label": "Breadcrumb", className: cx("tk-breadcrumb", className), ...rest, children: /* @__PURE__ */ jsx11("ol", { className: "tk-breadcrumb__list", children: visible.map((item, i) => {
545
+ const last = i === visible.length - 1;
546
+ return /* @__PURE__ */ jsxs5("li", { className: "tk-breadcrumb__item", children: [
547
+ item === "ellipsis" ? /* @__PURE__ */ jsx11("button", { type: "button", className: "tk-breadcrumb__ellipsis", "aria-label": "Show hidden pages", onClick: () => setExpanded(true), children: "\u2026" }) : last ? /* @__PURE__ */ jsxs5("span", { className: "tk-breadcrumb__current", "aria-current": "page", children: [
548
+ item.icon,
549
+ item.label
550
+ ] }) : item.href || item.onClick ? /* @__PURE__ */ jsxs5("a", { className: "tk-breadcrumb__link", href: item.href, onClick: item.onClick, children: [
551
+ item.icon,
552
+ item.label
553
+ ] }) : /* @__PURE__ */ jsxs5("span", { className: "tk-breadcrumb__text", children: [
554
+ item.icon,
555
+ item.label
556
+ ] }),
557
+ !last ? /* @__PURE__ */ jsx11("span", { className: "tk-breadcrumb__sep", "aria-hidden": "true", children: sep }) : null
558
+ ] }, item === "ellipsis" ? "ellipsis" : i);
559
+ }) }) });
560
+ });
561
+
562
+ // src/components/Button/Button.tsx
563
+ import { forwardRef as forwardRef12 } from "react";
564
+
565
+ // src/components/Loader/Loader.tsx
566
+ import { forwardRef as forwardRef11 } from "react";
567
+ import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
568
+ var sizes = { sm: 16, md: 24, lg: 40 };
569
+ var Spinner = forwardRef11(function Spinner2({ size = "md", color, label = "Loading", className, style, ...rest }, ref) {
570
+ const px = typeof size === "number" ? size : sizes[size];
571
+ return /* @__PURE__ */ jsx12(
572
+ "span",
573
+ {
574
+ ref,
575
+ role: "progressbar",
576
+ "aria-label": label,
577
+ className: cx("tk-spinner", colorClass(color), className),
578
+ style: { "--tk-spinner-size": `${px}px`, ...style },
579
+ ...rest,
580
+ children: /* @__PURE__ */ jsx12("svg", { viewBox: "0 0 48 48", focusable: "false", "aria-hidden": "true", children: /* @__PURE__ */ jsx12("circle", { cx: "24", cy: "24", r: "20" }) })
581
+ }
582
+ );
583
+ });
584
+ var Loader = forwardRef11(function Loader2({ variant = "spinner", size = "md", color, label, className, ...rest }, ref) {
585
+ return /* @__PURE__ */ jsxs6("div", { ref, role: "status", "aria-live": "polite", className: cx("tk-loader", `tk-loader--${size}`, colorClass(color), className), ...rest, children: [
586
+ variant === "spinner" ? /* @__PURE__ */ jsx12(Spinner, { size, color, label: label ?? "Loading" }) : /* @__PURE__ */ jsxs6("span", { className: cx("tk-loader__anim", `tk-loader__anim--${variant}`), "aria-hidden": "true", children: [
587
+ /* @__PURE__ */ jsx12("i", {}),
588
+ /* @__PURE__ */ jsx12("i", {}),
589
+ /* @__PURE__ */ jsx12("i", {})
590
+ ] }),
591
+ label ? /* @__PURE__ */ jsx12("span", { className: "tk-loader__label", children: label }) : /* @__PURE__ */ jsx12("span", { className: "tk-visually-hidden", children: "Loading" })
592
+ ] });
593
+ });
594
+
595
+ // src/components/Button/Button.tsx
596
+ import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
597
+ var Button = forwardRef12(function Button2({ variant = "filled", size = "md", color = "primary", startIcon, endIcon, loading, fullWidth, iconOnly, shape = "round", selected, badge, as: Tag = "button", className, children, disabled, type, onClick, ...rest }, ref) {
598
+ const isButton = Tag === "button";
599
+ const inactive = disabled || loading;
600
+ return /* @__PURE__ */ jsxs7(
601
+ Tag,
602
+ {
603
+ ref,
604
+ className: cx("tk-btn", `tk-btn--${variant}`, `tk-btn--${size}`, colorClass(color), iconOnly && "tk-btn--icon", shape === "square" && "tk-btn--square", fullWidth && "tk-btn--full", selected && "tk-btn--selected", loading && "tk-btn--loading", (startIcon || loading) && !iconOnly && "tk-btn--has-start", endIcon && !iconOnly && "tk-btn--has-end", className),
605
+ type: isButton ? type ?? "button" : void 0,
606
+ disabled: isButton ? inactive : void 0,
607
+ "aria-disabled": !isButton && inactive ? true : void 0,
608
+ "aria-busy": loading || void 0,
609
+ "aria-pressed": selected === void 0 ? void 0 : selected,
610
+ onClick: inactive ? void 0 : onClick,
611
+ ...rest,
612
+ children: [
613
+ loading ? /* @__PURE__ */ jsx13(Spinner, { size: size === "lg" ? 24 : 18, className: "tk-btn__spinner" }) : startIcon ? /* @__PURE__ */ jsx13("span", { className: "tk-btn__icon", children: startIcon }) : null,
614
+ children !== void 0 && children !== null && !iconOnly ? /* @__PURE__ */ jsx13("span", { className: "tk-btn__label", children }) : iconOnly && !loading ? /* @__PURE__ */ jsx13("span", { className: "tk-btn__icon", children }) : null,
615
+ endIcon && !iconOnly ? /* @__PURE__ */ jsx13("span", { className: "tk-btn__icon", children: endIcon }) : null,
616
+ badge !== void 0 && badge !== false ? /* @__PURE__ */ jsx13(Badge, { className: "tk-btn__badge", dot: badge === true, content: badge === true ? void 0 : String(badge) }) : null
617
+ ]
618
+ }
619
+ );
620
+ });
621
+
622
+ // src/components/Calendar/Calendar.tsx
623
+ import { forwardRef as forwardRef13, useEffect as useEffect5, useId as useId2, useMemo as useMemo2, useRef as useRef3, useState as useState7 } from "react";
624
+
625
+ // src/components/Calendar/dates.ts
626
+ var startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
627
+ var startOfMonth = (d) => new Date(d.getFullYear(), d.getMonth(), 1);
628
+ var addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
629
+ var addMonths = (d, n) => {
630
+ const target = new Date(d.getFullYear(), d.getMonth() + n, 1);
631
+ const last = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate();
632
+ return new Date(target.getFullYear(), target.getMonth(), Math.min(d.getDate(), last));
633
+ };
634
+ var isSameDay = (a, b) => !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
635
+ var isSameMonth = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
636
+ var compareDay = (a, b) => startOfDay(a).getTime() - startOfDay(b).getTime();
637
+ var keyOf = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
638
+ function monthGrid(month, weekStartsOn) {
639
+ const first = startOfMonth(month);
640
+ const offset = (first.getDay() - weekStartsOn + 7) % 7;
641
+ const start = addDays(first, -offset);
642
+ return Array.from({ length: 6 }, (_, w) => Array.from({ length: 7 }, (_2, d) => addDays(start, w * 7 + d)));
643
+ }
644
+
645
+ // src/components/Calendar/Calendar.tsx
646
+ import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
647
+ var emptyRange = { start: null, end: null };
648
+ var Calendar = forwardRef13(function Calendar2(props, ref) {
649
+ const {
650
+ mode = "single",
651
+ month: monthProp,
652
+ defaultMonth,
653
+ onMonthChange,
654
+ locale = "en-US",
655
+ weekStartsOn = 0,
656
+ min,
657
+ max,
658
+ disabledDate,
659
+ showOutsideDays = true,
660
+ showToday,
661
+ disabled,
662
+ className,
663
+ value: _v,
664
+ defaultValue: _dv,
665
+ onChange: _oc,
666
+ ...rest
667
+ } = props;
668
+ const isRange = mode === "range";
669
+ const [selected, setSelected] = useControllableState({
670
+ value: props.value,
671
+ defaultValue: props.defaultValue ?? (isRange ? emptyRange : null),
672
+ onChange: (v) => props.onChange?.(v)
673
+ });
674
+ const range2 = isRange ? selected ?? emptyRange : emptyRange;
675
+ const single = !isRange ? selected : null;
676
+ const today = useMemo2(() => startOfDay(/* @__PURE__ */ new Date()), []);
677
+ const initial = defaultMonth ?? (isRange ? range2.start : single) ?? today;
678
+ const [month, setMonthState] = useControllableState({ value: monthProp ? startOfMonth(monthProp) : void 0, defaultValue: startOfMonth(initial), onChange: onMonthChange });
679
+ const [view, setView] = useState7("days");
680
+ const [focusDate, setFocusDate] = useState7(() => single && isSameMonth(single, month) ? single : isSameMonth(today, month) ? today : month);
681
+ const [hover, setHover] = useState7(null);
682
+ const gridRef = useRef3(null);
683
+ const shouldFocus = useRef3(false);
684
+ const titleId = useId2();
685
+ const setMonth = (d) => setMonthState(startOfMonth(d));
686
+ const weeks = useMemo2(() => monthGrid(month, weekStartsOn), [month, weekStartsOn]);
687
+ const monthLabel = useMemo2(() => new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }).format(month), [locale, month]);
688
+ const weekdays = useMemo2(() => {
689
+ const short = new Intl.DateTimeFormat(locale, { weekday: "short" });
690
+ const long = new Intl.DateTimeFormat(locale, { weekday: "long" });
691
+ return Array.from({ length: 7 }, (_, i) => {
692
+ const d = new Date(2023, 0, 1 + (i + weekStartsOn) % 7);
693
+ return { short: short.format(d), long: long.format(d) };
694
+ });
695
+ }, [locale, weekStartsOn]);
696
+ const dayLabel = useMemo2(() => new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", month: "long", day: "numeric" }), [locale]);
697
+ const isDisabled = (d) => !!disabled || !!min && compareDay(d, min) < 0 || !!max && compareDay(d, max) > 0 || !!disabledDate?.(d);
698
+ useEffect5(() => {
699
+ if (!shouldFocus.current) return;
700
+ shouldFocus.current = false;
701
+ gridRef.current?.querySelector(`[data-date="${keyOf(focusDate)}"]`)?.focus();
702
+ });
703
+ const moveFocus = (d) => {
704
+ shouldFocus.current = true;
705
+ setFocusDate(d);
706
+ if (!isSameMonth(d, month)) setMonth(d);
707
+ };
708
+ const pick = (d) => {
709
+ if (isDisabled(d)) return;
710
+ setFocusDate(d);
711
+ if (!isRange) {
712
+ setSelected(d);
713
+ if (!isSameMonth(d, month)) setMonth(d);
714
+ return;
715
+ }
716
+ const { start, end } = range2;
717
+ if (!start || start && end) setSelected({ start: d, end: null });
718
+ else if (compareDay(d, start) < 0) setSelected({ start: d, end: null });
719
+ else setSelected({ start, end: d });
720
+ if (!isSameMonth(d, month)) setMonth(d);
721
+ };
722
+ const onKey = (e) => {
723
+ const map = {
724
+ ArrowLeft: addDays(focusDate, -1),
725
+ ArrowRight: addDays(focusDate, 1),
726
+ ArrowUp: addDays(focusDate, -7),
727
+ ArrowDown: addDays(focusDate, 7),
728
+ PageUp: addMonths(focusDate, e.shiftKey ? -12 : -1),
729
+ PageDown: addMonths(focusDate, e.shiftKey ? 12 : 1),
730
+ Home: addDays(focusDate, -((focusDate.getDay() - weekStartsOn + 7) % 7)),
731
+ End: addDays(focusDate, 6 - (focusDate.getDay() - weekStartsOn + 7) % 7)
732
+ };
733
+ const next = map[e.key];
734
+ if (next) {
735
+ e.preventDefault();
736
+ moveFocus(next);
737
+ }
738
+ };
739
+ const years = useMemo2(() => {
740
+ const y = month.getFullYear();
741
+ return Array.from({ length: 25 }, (_, i) => y - 12 + i);
742
+ }, [month]);
743
+ const previewEnd = isRange && range2.start && !range2.end ? hover : range2.end;
744
+ return /* @__PURE__ */ jsxs8("div", { ref, className: cx("tk-cal", disabled && "tk-cal--disabled", className), ...rest, children: [
745
+ /* @__PURE__ */ jsxs8("div", { className: "tk-cal__header", children: [
746
+ /* @__PURE__ */ jsxs8("button", { type: "button", className: "tk-cal__title", id: titleId, "aria-live": "polite", "aria-expanded": view === "years", onClick: () => setView(view === "days" ? "years" : "days"), disabled, children: [
747
+ monthLabel,
748
+ /* @__PURE__ */ jsx14(Icon, { name: view === "years" ? "expand-less" : "expand-more", size: 20 })
749
+ ] }),
750
+ /* @__PURE__ */ jsxs8("div", { className: "tk-cal__nav", children: [
751
+ /* @__PURE__ */ jsx14("button", { type: "button", className: "tk-cal__navbtn", "aria-label": "Previous month", disabled: disabled || view === "years", onClick: () => setMonth(addMonths(month, -1)), children: /* @__PURE__ */ jsx14(Icon, { name: "chevron-left" }) }),
752
+ /* @__PURE__ */ jsx14("button", { type: "button", className: "tk-cal__navbtn", "aria-label": "Next month", disabled: disabled || view === "years", onClick: () => setMonth(addMonths(month, 1)), children: /* @__PURE__ */ jsx14(Icon, { name: "chevron-right" }) })
753
+ ] })
754
+ ] }),
755
+ view === "years" ? /* @__PURE__ */ jsx14("div", { className: "tk-cal__years", role: "listbox", "aria-label": "Select year", children: years.map((y) => /* @__PURE__ */ jsx14("button", { type: "button", role: "option", "aria-selected": y === month.getFullYear(), className: cx("tk-cal__year", y === month.getFullYear() && "tk-cal__year--selected", y === today.getFullYear() && "tk-cal__year--today"), onClick: () => {
756
+ setMonth(new Date(y, month.getMonth(), 1));
757
+ setFocusDate(new Date(y, month.getMonth(), 1));
758
+ setView("days");
759
+ }, children: y }, y)) }) : /* @__PURE__ */ jsxs8("div", { ref: gridRef, role: "grid", "aria-labelledby": titleId, className: "tk-cal__grid", onKeyDown: onKey, onMouseLeave: () => setHover(null), children: [
760
+ /* @__PURE__ */ jsx14("div", { role: "row", className: "tk-cal__row", children: weekdays.map((w, i) => /* @__PURE__ */ jsx14("div", { role: "columnheader", className: "tk-cal__weekday", "aria-label": w.long, children: w.short.slice(0, 2) }, i)) }),
761
+ weeks.map((week, wi) => /* @__PURE__ */ jsx14("div", { role: "row", className: "tk-cal__row", children: week.map((d) => {
762
+ const outside = !isSameMonth(d, month);
763
+ if (outside && !showOutsideDays) return /* @__PURE__ */ jsx14("div", { role: "gridcell", className: "tk-cal__cell" }, keyOf(d));
764
+ const sel = isRange ? isSameDay(d, range2.start) || isSameDay(d, range2.end) : isSameDay(d, single);
765
+ const lo = range2.start && previewEnd ? compareDay(range2.start, previewEnd) <= 0 ? range2.start : previewEnd : null;
766
+ const hi = range2.start && previewEnd ? compareDay(range2.start, previewEnd) <= 0 ? previewEnd : range2.start : null;
767
+ const inRange = isRange && !!lo && !!hi && compareDay(d, lo) > 0 && compareDay(d, hi) < 0;
768
+ const isStart = isRange && !!lo && isSameDay(d, lo) && !!hi && !isSameDay(lo, hi);
769
+ const isEnd = isRange && !!hi && isSameDay(d, hi) && !!lo && !isSameDay(lo, hi);
770
+ const dis = isDisabled(d);
771
+ return /* @__PURE__ */ jsx14("div", { role: "gridcell", className: cx("tk-cal__cell", inRange && "tk-cal__cell--range", isStart && "tk-cal__cell--range-start", isEnd && "tk-cal__cell--range-end"), "aria-selected": sel || inRange || void 0, children: /* @__PURE__ */ jsx14(
772
+ "button",
773
+ {
774
+ type: "button",
775
+ "data-date": keyOf(d),
776
+ tabIndex: isSameDay(d, focusDate) ? 0 : -1,
777
+ "aria-label": dayLabel.format(d),
778
+ "aria-current": isSameDay(d, today) ? "date" : void 0,
779
+ "aria-disabled": dis || void 0,
780
+ disabled: dis,
781
+ className: cx("tk-cal__day", sel && "tk-cal__day--selected", isSameDay(d, today) && "tk-cal__day--today", outside && "tk-cal__day--outside"),
782
+ onClick: () => pick(d),
783
+ onMouseEnter: () => setHover(d),
784
+ onFocus: () => setFocusDate(d),
785
+ children: d.getDate()
786
+ }
787
+ ) }, keyOf(d));
788
+ }) }, wi))
789
+ ] }),
790
+ showToday && view === "days" ? /* @__PURE__ */ jsx14("div", { className: "tk-cal__footer", children: /* @__PURE__ */ jsx14("button", { type: "button", className: "tk-cal__today", disabled: disabled || isDisabled(today), onClick: () => {
791
+ pick(today);
792
+ moveFocus(today);
793
+ }, children: "Today" }) }) : null
794
+ ] });
795
+ });
796
+
797
+ // src/components/Card/Card.tsx
798
+ import { forwardRef as forwardRef14 } from "react";
799
+ import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
800
+ var Card = forwardRef14(function Card2({ variant = "elevated", interactive, orientation = "vertical", as: Tag = "div", className, onClick, ...rest }, ref) {
801
+ const clickable = interactive ?? !!onClick;
802
+ return /* @__PURE__ */ jsx15(
803
+ Tag,
804
+ {
805
+ ref,
806
+ className: cx("tk-card", `tk-card--${variant}`, orientation === "horizontal" && "tk-card--horizontal", clickable && "tk-card--interactive", className),
807
+ onClick,
808
+ tabIndex: clickable && Tag === "div" ? 0 : void 0,
809
+ role: clickable && Tag === "div" ? "button" : void 0,
810
+ onKeyDown: clickable && Tag === "div" && onClick ? (e) => {
811
+ if (e.key === "Enter" || e.key === " ") {
812
+ e.preventDefault();
813
+ e.currentTarget.click();
814
+ }
815
+ } : void 0,
816
+ ...rest
817
+ }
818
+ );
819
+ });
820
+ var CardHeader = forwardRef14(function CardHeader2({ title, subtitle, avatar, action, className, ...rest }, ref) {
821
+ return /* @__PURE__ */ jsxs9("div", { ref, className: cx("tk-card__header", className), ...rest, children: [
822
+ avatar ? /* @__PURE__ */ jsx15("div", { className: "tk-card__avatar", children: avatar }) : null,
823
+ /* @__PURE__ */ jsxs9("div", { className: "tk-card__heading", children: [
824
+ /* @__PURE__ */ jsx15("div", { className: "tk-card__title", children: title }),
825
+ subtitle ? /* @__PURE__ */ jsx15("div", { className: "tk-card__subtitle", children: subtitle }) : null
826
+ ] }),
827
+ action ? /* @__PURE__ */ jsx15("div", { className: "tk-card__action", children: action }) : null
828
+ ] });
829
+ });
830
+ var CardMedia = forwardRef14(function CardMedia2({ src, alt = "", height = 180, className, style, children, ...rest }, ref) {
831
+ return /* @__PURE__ */ jsxs9("div", { ref, className: cx("tk-card__media", className), style: { height, ...style }, ...rest, children: [
832
+ src ? /* @__PURE__ */ jsx15("img", { src, alt }) : null,
833
+ children
834
+ ] });
835
+ });
836
+ var CardContent = forwardRef14(function CardContent2({ className, ...rest }, ref) {
837
+ return /* @__PURE__ */ jsx15("div", { ref, className: cx("tk-card__content", className), ...rest });
838
+ });
839
+ var CardActions = forwardRef14(function CardActions2({ align = "start", className, ...rest }, ref) {
840
+ return /* @__PURE__ */ jsx15("div", { ref, className: cx("tk-card__actions", `tk-card__actions--${align}`, className), ...rest });
841
+ });
842
+
843
+ // src/components/Checkbox/Checkbox.tsx
844
+ import { forwardRef as forwardRef15, useEffect as useEffect6, useId as useId3, useRef as useRef4 } from "react";
845
+
846
+ // src/utils/refs.ts
847
+ function mergeRefs(...refs) {
848
+ return (node) => {
849
+ for (const ref of refs) {
850
+ if (!ref) continue;
851
+ if (typeof ref === "function") ref(node);
852
+ else ref.current = node;
853
+ }
854
+ };
855
+ }
856
+
857
+ // src/components/Checkbox/Checkbox.tsx
858
+ import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
859
+ var Checkbox = forwardRef15(function Checkbox2({ label, description, indeterminate, error, color, labelPlacement = "end", className, id: idProp, disabled, ...rest }, ref) {
860
+ const autoId = useId3();
861
+ const id = idProp ?? autoId;
862
+ const inner = useRef4(null);
863
+ useEffect6(() => {
864
+ if (inner.current) inner.current.indeterminate = !!indeterminate;
865
+ }, [indeterminate]);
866
+ return /* @__PURE__ */ jsxs10("label", { className: cx("tk-check", colorClass(error ? "error" : color), labelPlacement === "start" && "tk-check--reverse", disabled && "tk-check--disabled", className), htmlFor: id, children: [
867
+ /* @__PURE__ */ jsxs10("span", { className: "tk-check__control", children: [
868
+ /* @__PURE__ */ jsx16("input", { ref: mergeRefs(ref, inner), id, type: "checkbox", className: "tk-check__input", disabled, "aria-invalid": error || void 0, ...rest }),
869
+ /* @__PURE__ */ jsx16("span", { className: "tk-check__box", "aria-hidden": "true", children: /* @__PURE__ */ jsxs10("svg", { viewBox: "0 0 24 24", className: "tk-check__mark", children: [
870
+ /* @__PURE__ */ jsx16("path", { className: "tk-check__tick", d: "M5 12.5l4.5 4.5L19 7.5" }),
871
+ /* @__PURE__ */ jsx16("path", { className: "tk-check__dash", d: "M6 12h12" })
872
+ ] }) })
873
+ ] }),
874
+ label || description ? /* @__PURE__ */ jsxs10("span", { className: "tk-check__text", children: [
875
+ label ? /* @__PURE__ */ jsx16("span", { className: "tk-check__label", children: label }) : null,
876
+ description ? /* @__PURE__ */ jsx16("span", { className: "tk-check__desc", children: description }) : null
877
+ ] }) : null
878
+ ] });
879
+ });
880
+
881
+ // src/components/Chip/Chip.tsx
882
+ import { forwardRef as forwardRef16 } from "react";
883
+ import { Fragment as Fragment3, jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
884
+ var Chip = forwardRef16(function Chip2({ variant = "assist", selected, onClick, onDelete, icon, avatar, elevated, disabled, size = "md", className, children, ...rest }, ref) {
885
+ const interactive = !!onClick || variant === "filter";
886
+ const leading = avatar ? /* @__PURE__ */ jsx17("span", { className: "tk-chip__avatar", children: avatar }) : variant === "filter" && selected ? /* @__PURE__ */ jsx17(Icon, { name: "check", size: 18 }) : icon ? /* @__PURE__ */ jsx17("span", { className: "tk-chip__icon", children: icon }) : null;
887
+ const main = /* @__PURE__ */ jsxs11(Fragment3, { children: [
888
+ leading,
889
+ /* @__PURE__ */ jsx17("span", { className: "tk-chip__label", children })
890
+ ] });
891
+ return /* @__PURE__ */ jsxs11(
892
+ "div",
893
+ {
894
+ ref,
895
+ className: cx("tk-chip", `tk-chip--${variant}`, `tk-chip--${size}`, selected && "tk-chip--selected", elevated && "tk-chip--elevated", disabled && "tk-chip--disabled", onDelete && "tk-chip--deletable", leading && "tk-chip--has-leading", className),
896
+ ...rest,
897
+ children: [
898
+ interactive ? /* @__PURE__ */ jsx17("button", { type: "button", className: "tk-chip__main", disabled, "aria-pressed": variant === "filter" || selected !== void 0 ? !!selected : void 0, onClick, children: main }) : /* @__PURE__ */ jsx17("span", { className: "tk-chip__main", children: main }),
899
+ onDelete ? /* @__PURE__ */ jsx17(
900
+ "button",
901
+ {
902
+ type: "button",
903
+ className: "tk-chip__delete",
904
+ disabled,
905
+ "aria-label": "Remove",
906
+ onClick: onDelete,
907
+ children: /* @__PURE__ */ jsx17(Icon, { name: "close", size: 18 })
908
+ }
909
+ ) : null
910
+ ]
911
+ }
912
+ );
913
+ });
914
+
915
+ // src/components/ContextMenu/ContextMenu.tsx
916
+ import { forwardRef as forwardRef17, useCallback as useCallback5, useEffect as useEffect9, useRef as useRef6, useState as useState9 } from "react";
917
+
918
+ // src/hooks/useOutsideClick.ts
919
+ import { useEffect as useEffect7, useRef as useRef5 } from "react";
920
+ function useOutsideClick(refs, handler, enabled = true) {
921
+ const handlerRef = useRef5(handler);
922
+ handlerRef.current = handler;
923
+ const refsRef = useRef5(refs);
924
+ refsRef.current = refs;
925
+ useEffect7(() => {
926
+ if (!enabled) return;
927
+ const onDown = (e) => {
928
+ const target = e.target;
929
+ if (!target) return;
930
+ if (refsRef.current.some((r) => r.current && r.current.contains(target))) return;
931
+ handlerRef.current(e);
932
+ };
933
+ document.addEventListener("pointerdown", onDown, true);
934
+ return () => document.removeEventListener("pointerdown", onDown, true);
935
+ }, [enabled]);
936
+ }
937
+
938
+ // src/utils/Portal.tsx
939
+ import { useEffect as useEffect8, useState as useState8 } from "react";
940
+ import { createPortal } from "react-dom";
941
+ import { jsx as jsx18 } from "react/jsx-runtime";
942
+ function Portal({ children }) {
943
+ const { theme, cssVars } = useTheme();
944
+ const [mounted, setMounted] = useState8(false);
945
+ useEffect8(() => setMounted(true), []);
946
+ if (!mounted || typeof document === "undefined") return null;
947
+ return createPortal(
948
+ /* @__PURE__ */ jsx18("div", { className: "tk-root tk-portal", "data-tk-theme": theme.name, style: { ...cssVars, colorScheme: theme.mode }, children }),
949
+ document.body
950
+ );
951
+ }
952
+
953
+ // src/components/ContextMenu/ContextMenu.tsx
954
+ import { Fragment as Fragment4, jsx as jsx19, jsxs as jsxs12 } from "react/jsx-runtime";
955
+ var ContextMenu = forwardRef17(function ContextMenu2({ items, trigger = "double-right-click", doubleClickDelay = 500, disabled, onOpenChange, as: Tag = "div", className, children, onKeyDown, ...rest }, ref) {
956
+ const [point, setPoint] = useState9(null);
957
+ const open = point !== null;
958
+ const last = useRef6(null);
959
+ const menuRef = useRef6(null);
960
+ const wrapRef = useRef6(null);
961
+ const { floatingRef, style } = useFloating({ open, point, placement: "bottom-start", offset: 2 });
962
+ const setOpen = useCallback5((p) => {
963
+ setPoint(p);
964
+ onOpenChange?.(p !== null);
965
+ }, [onOpenChange]);
966
+ const close = useCallback5(() => {
967
+ setOpen(null);
968
+ wrapRef.current?.focus?.({ preventScroll: true });
969
+ }, [setOpen]);
970
+ const onContextMenu = (e) => {
971
+ if (disabled) return;
972
+ e.preventDefault();
973
+ const now = Date.now();
974
+ const prev = last.current;
975
+ const near = prev && Math.hypot(prev.x - e.clientX, prev.y - e.clientY) < 24;
976
+ if (trigger === "right-click" || prev && near && now - prev.t <= doubleClickDelay) {
977
+ last.current = null;
978
+ setOpen({ x: e.clientX, y: e.clientY });
979
+ } else {
980
+ last.current = { t: now, x: e.clientX, y: e.clientY };
981
+ }
982
+ };
983
+ const handleKeyDown = (e) => {
984
+ onKeyDown?.(e);
985
+ if (disabled || e.defaultPrevented) return;
986
+ if (e.key === "ContextMenu" || e.shiftKey && e.key === "F10") {
987
+ e.preventDefault();
988
+ const r = e.currentTarget.getBoundingClientRect();
989
+ setOpen({ x: r.left + Math.min(24, r.width / 2), y: r.top + Math.min(24, r.height / 2) });
990
+ }
991
+ };
992
+ useOutsideClick([menuRef], () => setOpen(null), open);
993
+ useEffect9(() => {
994
+ if (!open) return;
995
+ const onScroll = () => setOpen(null);
996
+ window.addEventListener("resize", onScroll);
997
+ window.addEventListener("blur", onScroll);
998
+ return () => {
999
+ window.removeEventListener("resize", onScroll);
1000
+ window.removeEventListener("blur", onScroll);
1001
+ };
1002
+ }, [open, setOpen]);
1003
+ useEffect9(() => {
1004
+ if (open) menuRef.current?.querySelector('[role="menuitem"]:not([aria-disabled="true"])')?.focus();
1005
+ }, [open]);
1006
+ const enabledItems = () => Array.from(menuRef.current?.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])') ?? []);
1007
+ const onMenuKey = (e) => {
1008
+ const els = enabledItems();
1009
+ const i = els.indexOf(document.activeElement);
1010
+ if (e.key === "ArrowDown") {
1011
+ e.preventDefault();
1012
+ els[(i + 1) % els.length]?.focus();
1013
+ } else if (e.key === "ArrowUp") {
1014
+ e.preventDefault();
1015
+ els[(i - 1 + els.length) % els.length]?.focus();
1016
+ } else if (e.key === "Home") {
1017
+ e.preventDefault();
1018
+ els[0]?.focus();
1019
+ } else if (e.key === "End") {
1020
+ e.preventDefault();
1021
+ els[els.length - 1]?.focus();
1022
+ } else if (e.key === "Escape") {
1023
+ e.preventDefault();
1024
+ e.stopPropagation();
1025
+ close();
1026
+ } else if (e.key === "Tab") {
1027
+ e.preventDefault();
1028
+ close();
1029
+ }
1030
+ };
1031
+ const select = (item) => {
1032
+ if (item.disabled) return;
1033
+ setOpen(null);
1034
+ wrapRef.current?.focus?.({ preventScroll: true });
1035
+ item.onSelect?.();
1036
+ };
1037
+ return /* @__PURE__ */ jsxs12(Fragment4, { children: [
1038
+ /* @__PURE__ */ jsx19(
1039
+ Tag,
1040
+ {
1041
+ ref: (n) => {
1042
+ wrapRef.current = n;
1043
+ if (typeof ref === "function") ref(n);
1044
+ else if (ref) ref.current = n;
1045
+ },
1046
+ className: cx("tk-contextmenu-area", className),
1047
+ onContextMenu,
1048
+ onKeyDown: handleKeyDown,
1049
+ ...rest,
1050
+ children
1051
+ }
1052
+ ),
1053
+ open ? /* @__PURE__ */ jsx19(Portal, { children: /* @__PURE__ */ jsx19(
1054
+ "div",
1055
+ {
1056
+ ref: (n) => {
1057
+ menuRef.current = n;
1058
+ floatingRef.current = n;
1059
+ },
1060
+ role: "menu",
1061
+ "aria-orientation": "vertical",
1062
+ style,
1063
+ className: "tk-menu",
1064
+ onKeyDown: onMenuKey,
1065
+ onContextMenu: (e) => e.preventDefault(),
1066
+ children: items.map((item, i) => {
1067
+ if (item.divider) return /* @__PURE__ */ jsx19("div", { role: "separator", className: "tk-menu__divider" }, item.id ?? `d${i}`);
1068
+ if (item.heading) return /* @__PURE__ */ jsx19("div", { className: "tk-menu__heading", role: "presentation", children: item.label }, item.id ?? `h${i}`);
1069
+ return /* @__PURE__ */ jsxs12(
1070
+ "div",
1071
+ {
1072
+ role: "menuitem",
1073
+ tabIndex: -1,
1074
+ "aria-disabled": item.disabled || void 0,
1075
+ className: cx("tk-menu__item", item.danger && "tk-menu__item--danger", item.disabled && "tk-menu__item--disabled"),
1076
+ onClick: () => select(item),
1077
+ onKeyDown: (e) => {
1078
+ if (e.key === "Enter" || e.key === " ") {
1079
+ e.preventDefault();
1080
+ select(item);
1081
+ }
1082
+ },
1083
+ onMouseMove: (e) => {
1084
+ if (!item.disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus({ preventScroll: true });
1085
+ },
1086
+ children: [
1087
+ /* @__PURE__ */ jsx19("span", { className: "tk-menu__icon", children: item.icon }),
1088
+ /* @__PURE__ */ jsx19("span", { className: "tk-menu__label", children: item.label }),
1089
+ item.shortcut ? /* @__PURE__ */ jsx19("span", { className: "tk-menu__shortcut", children: item.shortcut }) : null
1090
+ ]
1091
+ },
1092
+ item.id ?? i
1093
+ );
1094
+ })
1095
+ }
1096
+ ) }) : null
1097
+ ] });
1098
+ });
1099
+
1100
+ // src/components/Dialog/Dialog.tsx
1101
+ import { forwardRef as forwardRef19, useId as useId4 } from "react";
1102
+
1103
+ // src/components/Modal/Modal.tsx
1104
+ import { forwardRef as forwardRef18, useEffect as useEffect12, useRef as useRef7 } from "react";
1105
+
1106
+ // src/hooks/useFocusTrap.ts
1107
+ import { useEffect as useEffect10 } from "react";
1108
+ var FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"]),[contenteditable="true"]';
1109
+ function useFocusTrap(ref, active) {
1110
+ useEffect10(() => {
1111
+ if (!active) return;
1112
+ const node = ref.current;
1113
+ if (!node) return;
1114
+ const previouslyFocused = document.activeElement;
1115
+ const focusables = () => Array.from(node.querySelectorAll(FOCUSABLE)).filter((el) => el.offsetParent !== null || el === document.activeElement);
1116
+ if (!node.contains(document.activeElement)) {
1117
+ const first = node.querySelector("[data-tk-autofocus]") ?? focusables()[0];
1118
+ (first ?? node).focus({ preventScroll: true });
1119
+ }
1120
+ const onKeyDown = (e) => {
1121
+ if (e.key !== "Tab") return;
1122
+ const items = focusables();
1123
+ if (items.length === 0) {
1124
+ e.preventDefault();
1125
+ node.focus();
1126
+ return;
1127
+ }
1128
+ const first = items[0];
1129
+ const last = items[items.length - 1];
1130
+ const activeEl = document.activeElement;
1131
+ if (e.shiftKey && (activeEl === first || activeEl === node)) {
1132
+ e.preventDefault();
1133
+ last.focus();
1134
+ } else if (!e.shiftKey && activeEl === last) {
1135
+ e.preventDefault();
1136
+ first.focus();
1137
+ }
1138
+ };
1139
+ node.addEventListener("keydown", onKeyDown);
1140
+ return () => {
1141
+ node.removeEventListener("keydown", onKeyDown);
1142
+ previouslyFocused?.focus?.({ preventScroll: true });
1143
+ };
1144
+ }, [active, ref]);
1145
+ }
1146
+
1147
+ // src/hooks/useScrollLock.ts
1148
+ import { useEffect as useEffect11 } from "react";
1149
+ var locks = 0;
1150
+ var saved = null;
1151
+ function useScrollLock(active) {
1152
+ useEffect11(() => {
1153
+ if (!active) return;
1154
+ const body = document.body;
1155
+ if (locks === 0) {
1156
+ saved = { overflow: body.style.overflow, paddingRight: body.style.paddingRight };
1157
+ const scrollbar = window.innerWidth - document.documentElement.clientWidth;
1158
+ body.style.overflow = "hidden";
1159
+ if (scrollbar > 0) body.style.paddingRight = `${scrollbar}px`;
1160
+ }
1161
+ locks += 1;
1162
+ return () => {
1163
+ locks -= 1;
1164
+ if (locks === 0 && saved) {
1165
+ body.style.overflow = saved.overflow;
1166
+ body.style.paddingRight = saved.paddingRight;
1167
+ saved = null;
1168
+ }
1169
+ };
1170
+ }, [active]);
1171
+ }
1172
+
1173
+ // src/components/Modal/Modal.tsx
1174
+ import { jsx as jsx20, jsxs as jsxs13 } from "react/jsx-runtime";
1175
+ var Modal = forwardRef18(function Modal2({ open, onClose, size = "md", closeOnBackdrop = true, closeOnEsc = true, role = "dialog", className, backdropClassName, children, onKeyDown, ...rest }, ref) {
1176
+ const { mounted, visible } = usePresence(open, 200);
1177
+ const panelRef = useRef7(null);
1178
+ useFocusTrap(panelRef, open && mounted);
1179
+ useScrollLock(open);
1180
+ const onCloseRef = useRef7(onClose);
1181
+ onCloseRef.current = onClose;
1182
+ useEffect12(() => {
1183
+ if (!open || !closeOnEsc) return;
1184
+ const handler = (e) => {
1185
+ if (e.key !== "Escape" || e.defaultPrevented) return;
1186
+ const all = document.querySelectorAll(".tk-modal");
1187
+ if (all[all.length - 1] !== panelRef.current?.closest(".tk-modal")) return;
1188
+ e.preventDefault();
1189
+ onCloseRef.current?.();
1190
+ };
1191
+ document.addEventListener("keydown", handler);
1192
+ return () => document.removeEventListener("keydown", handler);
1193
+ }, [open, closeOnEsc]);
1194
+ if (!mounted) return null;
1195
+ const onBackdrop = (e) => {
1196
+ if (closeOnBackdrop && e.target === e.currentTarget) onClose?.();
1197
+ };
1198
+ return /* @__PURE__ */ jsx20(Portal, { children: /* @__PURE__ */ jsxs13("div", { className: cx("tk-modal", visible && "tk-modal--open"), children: [
1199
+ /* @__PURE__ */ jsx20("div", { className: cx("tk-modal__backdrop", backdropClassName), "aria-hidden": "true" }),
1200
+ /* @__PURE__ */ jsx20("div", { className: "tk-modal__wrap", onMouseDown: onBackdrop, children: /* @__PURE__ */ jsx20(
1201
+ "div",
1202
+ {
1203
+ ref: mergeRefs(ref, panelRef),
1204
+ role,
1205
+ "aria-modal": "true",
1206
+ tabIndex: -1,
1207
+ className: cx("tk-modal__panel", `tk-modal__panel--${size}`, className),
1208
+ onKeyDown: (e) => onKeyDown?.(e),
1209
+ ...rest,
1210
+ children
1211
+ }
1212
+ ) })
1213
+ ] }) });
1214
+ });
1215
+
1216
+ // src/components/Dialog/Dialog.tsx
1217
+ import { jsx as jsx21, jsxs as jsxs14 } from "react/jsx-runtime";
1218
+ var Dialog = forwardRef19(function Dialog2({ title, description, icon, actions, variant = "basic", size = "sm", closeOnBackdrop, className, children, ...rest }, ref) {
1219
+ const titleId = useId4();
1220
+ const descId = useId4();
1221
+ return /* @__PURE__ */ jsxs14(
1222
+ Modal,
1223
+ {
1224
+ ref,
1225
+ size,
1226
+ role: variant === "alert" ? "alertdialog" : "dialog",
1227
+ closeOnBackdrop: closeOnBackdrop ?? variant !== "alert",
1228
+ "aria-labelledby": title ? titleId : void 0,
1229
+ "aria-describedby": description ? descId : void 0,
1230
+ className: cx("tk-dialog", icon && "tk-dialog--icon", className),
1231
+ ...rest,
1232
+ children: [
1233
+ icon || title || description ? /* @__PURE__ */ jsxs14("div", { className: "tk-dialog__header", children: [
1234
+ icon ? /* @__PURE__ */ jsx21("div", { className: "tk-dialog__icon", children: icon }) : null,
1235
+ title ? /* @__PURE__ */ jsx21("h2", { id: titleId, className: "tk-dialog__title", children: title }) : null,
1236
+ description ? /* @__PURE__ */ jsx21("p", { id: descId, className: "tk-dialog__desc", children: description }) : null
1237
+ ] }) : null,
1238
+ children ? /* @__PURE__ */ jsx21("div", { className: "tk-dialog__body", children }) : null,
1239
+ actions ? /* @__PURE__ */ jsx21("div", { className: "tk-dialog__actions", children: actions }) : null
1240
+ ]
1241
+ }
1242
+ );
1243
+ });
1244
+
1245
+ // src/components/Divider/Divider.tsx
1246
+ import { forwardRef as forwardRef20 } from "react";
1247
+ import { jsx as jsx22 } from "react/jsx-runtime";
1248
+ var Divider = forwardRef20(function Divider2({ orientation = "horizontal", variant = "full", align = "center", className, children, ...rest }, ref) {
1249
+ const cls = cx("tk-divider", `tk-divider--${orientation}`, variant !== "full" && `tk-divider--${variant}`, children && "tk-divider--labelled", children && `tk-divider--${align}`, className);
1250
+ if (children) {
1251
+ return /* @__PURE__ */ jsx22("div", { ref, role: "separator", "aria-orientation": orientation, className: cls, ...rest, children: /* @__PURE__ */ jsx22("span", { className: "tk-divider__label", children }) });
1252
+ }
1253
+ return /* @__PURE__ */ jsx22("hr", { ref, "aria-orientation": orientation, className: cls, ...rest });
1254
+ });
1255
+
1256
+ // src/components/FileUpload/FileUpload.tsx
1257
+ import { forwardRef as forwardRef21, useId as useId5, useRef as useRef8, useState as useState10 } from "react";
1258
+ import { Fragment as Fragment5, jsx as jsx23, jsxs as jsxs15 } from "react/jsx-runtime";
1259
+ function formatBytes(bytes) {
1260
+ if (bytes < 1024) return `${bytes} B`;
1261
+ const units = ["KB", "MB", "GB"];
1262
+ let n = bytes / 1024;
1263
+ let i = 0;
1264
+ while (n >= 1024 && i < units.length - 1) {
1265
+ n /= 1024;
1266
+ i++;
1267
+ }
1268
+ return `${n.toFixed(n < 10 ? 1 : 0)} ${units[i]}`;
1269
+ }
1270
+ function matchesAccept(file, accept) {
1271
+ if (!accept) return true;
1272
+ const rules = accept.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
1273
+ const name = file.name.toLowerCase();
1274
+ const type = file.type.toLowerCase();
1275
+ return rules.some((r) => r.startsWith(".") ? name.endsWith(r) : r.endsWith("/*") ? type.startsWith(r.slice(0, -1)) : type === r);
1276
+ }
1277
+ var FileUpload = forwardRef21(function FileUpload2({ accept, multiple, maxSize, maxFiles, value, defaultValue = [], onChange, onReject, disabled, variant = "dropzone", title, hint, showFileList = true, error, helperText, className, ...rest }, ref) {
1278
+ const [files, setFiles] = useControllableState({ value, defaultValue, onChange });
1279
+ const [dragging, setDragging] = useState10(false);
1280
+ const [rejections, setRejections] = useState10([]);
1281
+ const inputRef = useRef8(null);
1282
+ const id = useId5();
1283
+ const add = (incoming) => {
1284
+ if (disabled || incoming.length === 0) return;
1285
+ const rejected = [];
1286
+ let accepted = [];
1287
+ for (const f of incoming) {
1288
+ if (!matchesAccept(f, accept)) rejected.push({ file: f, reason: "type" });
1289
+ else if (maxSize !== void 0 && f.size > maxSize) rejected.push({ file: f, reason: "size" });
1290
+ else accepted.push(f);
1291
+ }
1292
+ const base = multiple ? files : [];
1293
+ if (!multiple) accepted = accepted.slice(0, 1);
1294
+ if (maxFiles !== void 0) {
1295
+ const room = Math.max(0, maxFiles - base.length);
1296
+ for (const f of accepted.slice(room)) rejected.push({ file: f, reason: "count" });
1297
+ accepted = accepted.slice(0, room);
1298
+ }
1299
+ setRejections(rejected);
1300
+ if (rejected.length) onReject?.(rejected);
1301
+ if (accepted.length) setFiles([...base, ...accepted]);
1302
+ };
1303
+ const onDrop = (e) => {
1304
+ e.preventDefault();
1305
+ setDragging(false);
1306
+ add(Array.from(e.dataTransfer.files));
1307
+ };
1308
+ const open = () => !disabled && inputRef.current?.click();
1309
+ const reasonText = (r) => r.reason === "type" ? "file type not allowed" : r.reason === "size" ? `larger than ${formatBytes(maxSize ?? 0)}` : `limit of ${maxFiles} files reached`;
1310
+ return /* @__PURE__ */ jsxs15("div", { ref, className: cx("tk-upload", disabled && "tk-upload--disabled", error && "tk-upload--error", className), ...rest, children: [
1311
+ /* @__PURE__ */ jsx23(
1312
+ "input",
1313
+ {
1314
+ ref: inputRef,
1315
+ id,
1316
+ type: "file",
1317
+ className: "tk-visually-hidden",
1318
+ accept,
1319
+ multiple,
1320
+ disabled,
1321
+ tabIndex: -1,
1322
+ onChange: (e) => {
1323
+ add(Array.from(e.target.files ?? []));
1324
+ e.target.value = "";
1325
+ }
1326
+ }
1327
+ ),
1328
+ variant === "dropzone" ? /* @__PURE__ */ jsxs15(
1329
+ "div",
1330
+ {
1331
+ role: "button",
1332
+ tabIndex: disabled ? -1 : 0,
1333
+ "aria-disabled": disabled,
1334
+ className: cx("tk-upload__zone", dragging && "tk-upload__zone--drag"),
1335
+ onClick: open,
1336
+ onKeyDown: (e) => {
1337
+ if (e.key === "Enter" || e.key === " ") {
1338
+ e.preventDefault();
1339
+ open();
1340
+ }
1341
+ },
1342
+ onDragOver: (e) => {
1343
+ e.preventDefault();
1344
+ if (!disabled) setDragging(true);
1345
+ },
1346
+ onDragLeave: () => setDragging(false),
1347
+ onDrop,
1348
+ children: [
1349
+ /* @__PURE__ */ jsx23(Icon, { name: "upload", size: 32, className: "tk-upload__icon" }),
1350
+ /* @__PURE__ */ jsx23("div", { className: "tk-upload__title", children: title ?? /* @__PURE__ */ jsxs15(Fragment5, { children: [
1351
+ /* @__PURE__ */ jsx23("span", { className: "tk-upload__link", children: "Click to upload" }),
1352
+ " or drag and drop"
1353
+ ] }) }),
1354
+ hint ? /* @__PURE__ */ jsx23("div", { className: "tk-upload__hint", children: hint }) : null
1355
+ ]
1356
+ }
1357
+ ) : /* @__PURE__ */ jsxs15("div", { className: "tk-upload__button-row", children: [
1358
+ /* @__PURE__ */ jsx23(Button, { variant: "outlined", startIcon: /* @__PURE__ */ jsx23(Icon, { name: "upload" }), disabled, onClick: open, children: title ?? "Choose file" }),
1359
+ hint ? /* @__PURE__ */ jsx23("span", { className: "tk-upload__hint", children: hint }) : null
1360
+ ] }),
1361
+ helperText ? /* @__PURE__ */ jsx23("div", { className: "tk-upload__helper", children: helperText }) : null,
1362
+ rejections.length > 0 ? /* @__PURE__ */ jsx23("ul", { className: "tk-upload__errors", role: "alert", children: rejections.map((r, i) => /* @__PURE__ */ jsxs15("li", { children: [
1363
+ r.file.name,
1364
+ ": ",
1365
+ reasonText(r)
1366
+ ] }, i)) }) : null,
1367
+ showFileList && files.length > 0 ? /* @__PURE__ */ jsx23("ul", { className: "tk-upload__list", children: files.map((f, i) => /* @__PURE__ */ jsxs15("li", { className: "tk-upload__item", children: [
1368
+ /* @__PURE__ */ jsx23(Icon, { name: "file", className: "tk-upload__file-icon" }),
1369
+ /* @__PURE__ */ jsx23("span", { className: "tk-upload__name", children: f.name }),
1370
+ /* @__PURE__ */ jsx23("span", { className: "tk-upload__size", children: formatBytes(f.size) }),
1371
+ /* @__PURE__ */ jsx23("button", { type: "button", className: "tk-upload__remove", "aria-label": `Remove ${f.name}`, disabled, onClick: () => setFiles(files.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx23(Icon, { name: "close", size: 18 }) })
1372
+ ] }, `${f.name}-${i}`)) }) : null
1373
+ ] });
1374
+ });
1375
+
1376
+ // src/components/Input/Input.tsx
1377
+ import { forwardRef as forwardRef22, useId as useId6, useRef as useRef9, useState as useState11 } from "react";
1378
+
1379
+ // src/components/Input/FieldShell.tsx
1380
+ import { jsx as jsx24, jsxs as jsxs16 } from "react/jsx-runtime";
1381
+ function FieldShell({
1382
+ id,
1383
+ variant = "outlined",
1384
+ label,
1385
+ helperText,
1386
+ error,
1387
+ disabled,
1388
+ startAdornment,
1389
+ endAdornment,
1390
+ fullWidth,
1391
+ size = "md",
1392
+ focused,
1393
+ filled,
1394
+ multiline,
1395
+ required,
1396
+ counter: counter2,
1397
+ helperId,
1398
+ className,
1399
+ style,
1400
+ children,
1401
+ onContainerMouseDown
1402
+ }) {
1403
+ const floating = focused || filled;
1404
+ return /* @__PURE__ */ jsxs16(
1405
+ "div",
1406
+ {
1407
+ className: cx("tk-field", `tk-field--${variant}`, `tk-field--${size}`, floating && "tk-field--float", focused && "tk-field--focused", error && "tk-field--error", disabled && "tk-field--disabled", fullWidth && "tk-field--full", multiline && "tk-field--multiline", !!label && "tk-field--has-label", className),
1408
+ style,
1409
+ children: [
1410
+ /* @__PURE__ */ jsxs16("div", { className: "tk-field__container", onMouseDown: onContainerMouseDown, children: [
1411
+ startAdornment ? /* @__PURE__ */ jsx24("span", { className: "tk-field__adorn tk-field__adorn--start", children: startAdornment }) : null,
1412
+ /* @__PURE__ */ jsxs16("div", { className: "tk-field__control", children: [
1413
+ children,
1414
+ label ? /* @__PURE__ */ jsxs16("label", { className: "tk-field__label", htmlFor: id, children: [
1415
+ label,
1416
+ required ? " *" : ""
1417
+ ] }) : null
1418
+ ] }),
1419
+ endAdornment ? /* @__PURE__ */ jsx24("span", { className: "tk-field__adorn tk-field__adorn--end", children: endAdornment }) : null,
1420
+ variant === "outlined" ? /* @__PURE__ */ jsx24("fieldset", { className: "tk-field__outline", "aria-hidden": "true", children: /* @__PURE__ */ jsx24("legend", { className: "tk-field__legend", children: label ? /* @__PURE__ */ jsxs16("span", { children: [
1421
+ label,
1422
+ required ? " *" : ""
1423
+ ] }) : null }) }) : /* @__PURE__ */ jsx24("span", { className: "tk-field__indicator", "aria-hidden": "true" })
1424
+ ] }),
1425
+ helperText || counter2 ? /* @__PURE__ */ jsxs16("div", { className: "tk-field__footer", children: [
1426
+ /* @__PURE__ */ jsx24("span", { id: helperId, className: "tk-field__helper", children: helperText }),
1427
+ counter2 ? /* @__PURE__ */ jsx24("span", { className: "tk-field__counter", children: counter2 }) : null
1428
+ ] }) : null
1429
+ ]
1430
+ }
1431
+ );
1432
+ }
1433
+
1434
+ // src/components/Input/Input.tsx
1435
+ import { Fragment as Fragment6, jsx as jsx25, jsxs as jsxs17 } from "react/jsx-runtime";
1436
+ function setNativeValue(el, value) {
1437
+ const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
1438
+ const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;
1439
+ setter?.call(el, value);
1440
+ el.dispatchEvent(new Event("input", { bubbles: true }));
1441
+ }
1442
+ var Input = forwardRef22(function Input2({ variant, label, helperText, error, disabled, startAdornment, endAdornment, fullWidth, size, clearable, onClear, showCounter, wrapperClassName, id: idProp, type = "text", value, defaultValue, onChange, onFocus, onBlur, maxLength, required, className, style, ...rest }, ref) {
1443
+ const autoId = useId6();
1444
+ const id = idProp ?? autoId;
1445
+ const helperId = `${id}-helper`;
1446
+ const inner = useRef9(null);
1447
+ const [focused, setFocused] = useState11(false);
1448
+ const [innerValue, setInnerValue] = useState11(String(defaultValue ?? ""));
1449
+ const [reveal, setReveal] = useState11(false);
1450
+ const controlled = value !== void 0;
1451
+ const current = controlled ? String(value ?? "") : innerValue;
1452
+ const isPassword = type === "password";
1453
+ const handleChange = (e) => {
1454
+ if (!controlled) setInnerValue(e.target.value);
1455
+ onChange?.(e);
1456
+ };
1457
+ const trailing = /* @__PURE__ */ jsxs17(Fragment6, { children: [
1458
+ clearable && current && !disabled ? /* @__PURE__ */ jsx25("button", { type: "button", className: "tk-field__action", "aria-label": "Clear", tabIndex: -1, onClick: () => {
1459
+ if (inner.current) setNativeValue(inner.current, "");
1460
+ inner.current?.focus();
1461
+ onClear?.();
1462
+ }, children: /* @__PURE__ */ jsx25(Icon, { name: "close", size: 20 }) }) : null,
1463
+ isPassword ? /* @__PURE__ */ jsx25("button", { type: "button", className: "tk-field__action", "aria-label": reveal ? "Hide password" : "Show password", "aria-pressed": reveal, onClick: () => setReveal((r) => !r), disabled, children: /* @__PURE__ */ jsx25(Icon, { name: reveal ? "visibility-off" : "visibility", size: 20 }) }) : null,
1464
+ endAdornment
1465
+ ] });
1466
+ const hasTrailing = clearable && current || isPassword || endAdornment;
1467
+ return /* @__PURE__ */ jsx25(
1468
+ FieldShell,
1469
+ {
1470
+ id,
1471
+ helperId,
1472
+ variant,
1473
+ label,
1474
+ helperText,
1475
+ error,
1476
+ disabled,
1477
+ startAdornment,
1478
+ endAdornment: hasTrailing ? trailing : void 0,
1479
+ fullWidth,
1480
+ size,
1481
+ focused,
1482
+ filled: current.length > 0,
1483
+ required,
1484
+ className: wrapperClassName,
1485
+ style,
1486
+ counter: showCounter && maxLength ? `${current.length} / ${maxLength}` : void 0,
1487
+ onContainerMouseDown: (e) => {
1488
+ if (e.target !== inner.current && !e.target.closest("button")) {
1489
+ e.preventDefault();
1490
+ inner.current?.focus();
1491
+ }
1492
+ },
1493
+ children: /* @__PURE__ */ jsx25(
1494
+ "input",
1495
+ {
1496
+ ref: mergeRefs(ref, inner),
1497
+ id,
1498
+ className: ["tk-field__input", className].filter(Boolean).join(" "),
1499
+ type: isPassword && reveal ? "text" : type,
1500
+ value: controlled ? value : void 0,
1501
+ defaultValue: controlled ? void 0 : defaultValue,
1502
+ disabled,
1503
+ required,
1504
+ maxLength,
1505
+ "aria-invalid": error || void 0,
1506
+ "aria-describedby": helperText ? helperId : void 0,
1507
+ onChange: handleChange,
1508
+ onFocus: (e) => {
1509
+ setFocused(true);
1510
+ onFocus?.(e);
1511
+ },
1512
+ onBlur: (e) => {
1513
+ setFocused(false);
1514
+ onBlur?.(e);
1515
+ },
1516
+ ...rest
1517
+ }
1518
+ )
1519
+ }
1520
+ );
1521
+ });
1522
+
1523
+ // src/components/InputTags/InputTags.tsx
1524
+ import { forwardRef as forwardRef23, useId as useId7, useRef as useRef10, useState as useState12 } from "react";
1525
+ import { jsx as jsx26, jsxs as jsxs18 } from "react/jsx-runtime";
1526
+ var InputTags = forwardRef23(function InputTags2({ value, defaultValue = [], onChange, placeholder, delimiters = ["Enter", ","], max, allowDuplicates = false, validate, addOnBlur = true, onReject, variant, label, helperText, error, disabled, startAdornment, endAdornment, fullWidth, size, id: idProp, name, className }, ref) {
1527
+ const autoId = useId7();
1528
+ const id = idProp ?? autoId;
1529
+ const [tags, setTags] = useControllableState({ value, defaultValue, onChange });
1530
+ const [text, setText] = useState12("");
1531
+ const [focused, setFocused] = useState12(false);
1532
+ const [invalid, setInvalid] = useState12(null);
1533
+ const inputRef = useRef10(null);
1534
+ const commit = (raw) => {
1535
+ const tag = raw.trim();
1536
+ if (!tag) return false;
1537
+ if (max !== void 0 && tags.length >= max) {
1538
+ onReject?.(tag, "max");
1539
+ return false;
1540
+ }
1541
+ if (!allowDuplicates && tags.includes(tag)) {
1542
+ onReject?.(tag, "duplicate");
1543
+ return false;
1544
+ }
1545
+ if (validate) {
1546
+ const res = validate(tag);
1547
+ if (res !== true) {
1548
+ setInvalid(typeof res === "string" ? res : "Invalid value");
1549
+ onReject?.(tag, "invalid");
1550
+ return false;
1551
+ }
1552
+ }
1553
+ setInvalid(null);
1554
+ setTags([...tags, tag]);
1555
+ return true;
1556
+ };
1557
+ const onKeyDown = (e) => {
1558
+ if (delimiters.includes(e.key)) {
1559
+ if (text.trim()) {
1560
+ e.preventDefault();
1561
+ if (commit(text)) setText("");
1562
+ } else if (e.key === ",") e.preventDefault();
1563
+ } else if (e.key === "Backspace" && !text && tags.length) {
1564
+ setTags(tags.slice(0, -1));
1565
+ }
1566
+ };
1567
+ const onPaste = (e) => {
1568
+ const pasted = e.clipboardData.getData("text");
1569
+ if (!/[,\n]/.test(pasted)) return;
1570
+ e.preventDefault();
1571
+ let next = [...tags];
1572
+ for (const part of pasted.split(/[,\n]/)) {
1573
+ const t = part.trim();
1574
+ if (!t || max !== void 0 && next.length >= max || !allowDuplicates && next.includes(t)) continue;
1575
+ if (validate && validate(t) !== true) continue;
1576
+ next = [...next, t];
1577
+ }
1578
+ setTags(next);
1579
+ };
1580
+ const helperId = `${id}-helper`;
1581
+ const message = invalid ?? helperText;
1582
+ return /* @__PURE__ */ jsx26(
1583
+ FieldShell,
1584
+ {
1585
+ id,
1586
+ helperId,
1587
+ variant,
1588
+ label,
1589
+ helperText: message,
1590
+ error: error || !!invalid,
1591
+ disabled,
1592
+ startAdornment,
1593
+ endAdornment,
1594
+ fullWidth,
1595
+ size,
1596
+ className,
1597
+ focused,
1598
+ filled: tags.length > 0 || text.length > 0,
1599
+ multiline: true,
1600
+ counter: max !== void 0 ? `${tags.length} / ${max}` : void 0,
1601
+ onContainerMouseDown: (e) => {
1602
+ if (!e.target.closest("button")) {
1603
+ e.preventDefault();
1604
+ inputRef.current?.focus();
1605
+ }
1606
+ },
1607
+ children: /* @__PURE__ */ jsxs18("div", { className: "tk-field__tags", children: [
1608
+ tags.map((tag, i) => /* @__PURE__ */ jsx26(Chip, { variant: "input", size: "md", disabled, onDelete: () => setTags(tags.filter((_, j) => j !== i)), children: tag }, `${tag}-${i}`)),
1609
+ /* @__PURE__ */ jsx26(
1610
+ "input",
1611
+ {
1612
+ ref: (node) => {
1613
+ inputRef.current = node;
1614
+ if (typeof ref === "function") ref(node);
1615
+ else if (ref) ref.current = node;
1616
+ },
1617
+ id,
1618
+ name,
1619
+ className: "tk-field__input",
1620
+ value: text,
1621
+ disabled,
1622
+ placeholder,
1623
+ autoComplete: "off",
1624
+ "aria-invalid": error || !!invalid || void 0,
1625
+ "aria-describedby": message ? helperId : void 0,
1626
+ onChange: (e) => {
1627
+ setText(e.target.value);
1628
+ if (invalid) setInvalid(null);
1629
+ },
1630
+ onKeyDown,
1631
+ onPaste,
1632
+ onFocus: () => setFocused(true),
1633
+ onBlur: () => {
1634
+ setFocused(false);
1635
+ if (addOnBlur && text.trim() && commit(text)) setText("");
1636
+ }
1637
+ }
1638
+ )
1639
+ ] })
1640
+ }
1641
+ );
1642
+ });
1643
+
1644
+ // src/components/Navbar/Navbar.tsx
1645
+ import { forwardRef as forwardRef24, useEffect as useEffect13, useState as useState13 } from "react";
1646
+ import { jsx as jsx27, jsxs as jsxs19 } from "react/jsx-runtime";
1647
+ var Navbar = forwardRef24(function Navbar2({ brand, title, links, actions, onMenuClick, position = "static", variant = "surface", elevateOnScroll, bordered, className, ...rest }, ref) {
1648
+ const [scrolled, setScrolled] = useState13(false);
1649
+ useEffect13(() => {
1650
+ if (!elevateOnScroll) return;
1651
+ const onScroll = () => setScrolled(window.scrollY > 4);
1652
+ onScroll();
1653
+ window.addEventListener("scroll", onScroll, { passive: true });
1654
+ return () => window.removeEventListener("scroll", onScroll);
1655
+ }, [elevateOnScroll]);
1656
+ return /* @__PURE__ */ jsx27(
1657
+ "header",
1658
+ {
1659
+ ref,
1660
+ className: cx("tk-navbar", `tk-navbar--${variant}`, `tk-navbar--${position}`, (scrolled || bordered) && "tk-navbar--raised", scrolled && "tk-navbar--scrolled", className),
1661
+ ...rest,
1662
+ children: /* @__PURE__ */ jsxs19("div", { className: "tk-navbar__inner", children: [
1663
+ onMenuClick ? /* @__PURE__ */ jsx27("button", { type: "button", className: "tk-navbar__menu", "aria-label": "Open menu", onClick: onMenuClick, children: /* @__PURE__ */ jsx27(Icon, { name: "menu" }) }) : null,
1664
+ brand ? /* @__PURE__ */ jsx27("div", { className: "tk-navbar__brand", children: brand }) : null,
1665
+ title ? /* @__PURE__ */ jsx27("div", { className: "tk-navbar__title", children: title }) : null,
1666
+ links?.length ? /* @__PURE__ */ jsx27("nav", { className: "tk-navbar__links", "aria-label": "Primary", children: links.map((l, i) => /* @__PURE__ */ jsxs19(
1667
+ "a",
1668
+ {
1669
+ className: cx("tk-navbar__link", l.active && "tk-navbar__link--active", l.disabled && "tk-navbar__link--disabled"),
1670
+ href: l.href,
1671
+ "aria-current": l.active ? "page" : void 0,
1672
+ "aria-disabled": l.disabled || void 0,
1673
+ onClick: l.disabled ? (e) => e.preventDefault() : l.onClick,
1674
+ children: [
1675
+ l.icon,
1676
+ l.label
1677
+ ]
1678
+ },
1679
+ i
1680
+ )) }) : null,
1681
+ /* @__PURE__ */ jsx27("div", { className: "tk-navbar__spacer" }),
1682
+ actions ? /* @__PURE__ */ jsx27("div", { className: "tk-navbar__actions", children: actions }) : null
1683
+ ] })
1684
+ }
1685
+ );
1686
+ });
1687
+
1688
+ // src/components/Pagination/Pagination.tsx
1689
+ import { forwardRef as forwardRef25, useMemo as useMemo3 } from "react";
1690
+ import { jsx as jsx28 } from "react/jsx-runtime";
1691
+ var range = (start, end) => Array.from({ length: Math.max(0, end - start + 1) }, (_, i) => start + i);
1692
+ function usePagination({ count, page, siblingCount = 1, boundaryCount = 1, showFirstLast = false }) {
1693
+ return useMemo3(() => {
1694
+ const startPages = range(1, Math.min(boundaryCount, count));
1695
+ const endPages = range(Math.max(count - boundaryCount + 1, boundaryCount + 1), count);
1696
+ const siblingsStart = Math.max(Math.min(page - siblingCount, count - boundaryCount - siblingCount * 2 - 1), boundaryCount + 2);
1697
+ const siblingsEnd = Math.min(Math.max(page + siblingCount, boundaryCount + siblingCount * 2 + 2), endPages.length > 0 ? endPages[0] - 2 : count - 1);
1698
+ const items = [
1699
+ ...showFirstLast ? ["first"] : [],
1700
+ "prev",
1701
+ ...startPages,
1702
+ ...siblingsStart > boundaryCount + 2 ? ["start-ellipsis"] : boundaryCount + 1 < count - boundaryCount ? [boundaryCount + 1] : [],
1703
+ ...range(siblingsStart, siblingsEnd),
1704
+ ...siblingsEnd < count - boundaryCount - 1 ? ["end-ellipsis"] : count - boundaryCount > boundaryCount ? [count - boundaryCount] : [],
1705
+ ...endPages,
1706
+ "next",
1707
+ ...showFirstLast ? ["last"] : []
1708
+ ];
1709
+ return items;
1710
+ }, [count, page, siblingCount, boundaryCount, showFirstLast]);
1711
+ }
1712
+ var Pagination = forwardRef25(function Pagination2({ count, page, defaultPage = 1, onChange, siblingCount, boundaryCount, showFirstLast, variant = "text", size = "md", shape = "round", disabled, className, ...rest }, ref) {
1713
+ const [current, setCurrent] = useControllableState({ value: page, defaultValue: defaultPage, onChange });
1714
+ const items = usePagination({ count, page: current, siblingCount, boundaryCount, showFirstLast });
1715
+ const go = (p) => !disabled && p >= 1 && p <= count && setCurrent(p);
1716
+ return /* @__PURE__ */ jsx28("nav", { ref, "aria-label": "Pagination", className: cx("tk-pagination", `tk-pagination--${variant}`, `tk-pagination--${size}`, shape === "square" && "tk-pagination--square", className), ...rest, children: /* @__PURE__ */ jsx28("ul", { className: "tk-pagination__list", children: items.map((item, i) => {
1717
+ if (item === "start-ellipsis" || item === "end-ellipsis") return /* @__PURE__ */ jsx28("li", { className: "tk-pagination__ellipsis", "aria-hidden": "true", children: "\u2026" }, item);
1718
+ const nav = typeof item === "string";
1719
+ const target = item === "prev" ? current - 1 : item === "next" ? current + 1 : item === "first" ? 1 : item === "last" ? count : item;
1720
+ const isDisabled = disabled || nav && (item === "prev" || item === "first" ? current <= 1 : current >= count);
1721
+ const selected = !nav && item === current;
1722
+ const label = item === "prev" ? "Previous page" : item === "next" ? "Next page" : item === "first" ? "First page" : item === "last" ? "Last page" : `Page ${item}`;
1723
+ const icon = item === "prev" ? "chevron-left" : item === "next" ? "chevron-right" : item === "first" ? "first-page" : "last-page";
1724
+ return /* @__PURE__ */ jsx28("li", { children: /* @__PURE__ */ jsx28("button", { type: "button", className: cx("tk-pagination__item", selected && "tk-pagination__item--selected"), "aria-label": label, "aria-current": selected ? "page" : void 0, disabled: isDisabled, onClick: () => go(target), children: nav ? /* @__PURE__ */ jsx28(Icon, { name: icon, size: 20 }) : item }) }, `${item}-${i}`);
1725
+ }) }) });
1726
+ });
1727
+
1728
+ // src/components/Panel/Panel.tsx
1729
+ import { forwardRef as forwardRef26, useId as useId8 } from "react";
1730
+ import { Fragment as Fragment7, jsx as jsx29, jsxs as jsxs20 } from "react/jsx-runtime";
1731
+ var Panel = forwardRef26(function Panel2({ title, subtitle, icon, headerActions, footer, toggleable, collapsed, defaultCollapsed = false, onToggle, variant = "outlined", className, children, ...rest }, ref) {
1732
+ const id = useId8();
1733
+ const [isCollapsed, setCollapsed] = useControllableState({ value: collapsed, defaultValue: defaultCollapsed, onChange: onToggle });
1734
+ const hasHeader = title || subtitle || icon || headerActions || toggleable;
1735
+ const open = !toggleable || !isCollapsed;
1736
+ const headerContent = /* @__PURE__ */ jsxs20(Fragment7, { children: [
1737
+ icon ? /* @__PURE__ */ jsx29("span", { className: "tk-panel__icon", children: icon }) : null,
1738
+ /* @__PURE__ */ jsxs20("span", { className: "tk-panel__titles", children: [
1739
+ title ? /* @__PURE__ */ jsx29("span", { className: "tk-panel__title", children: title }) : null,
1740
+ subtitle ? /* @__PURE__ */ jsx29("span", { className: "tk-panel__subtitle", children: subtitle }) : null
1741
+ ] })
1742
+ ] });
1743
+ return /* @__PURE__ */ jsxs20("div", { ref, className: cx("tk-panel", `tk-panel--${variant}`, className), ...rest, children: [
1744
+ hasHeader ? /* @__PURE__ */ jsxs20("div", { className: "tk-panel__header", children: [
1745
+ toggleable ? /* @__PURE__ */ jsxs20("button", { type: "button", className: "tk-panel__toggle", "aria-expanded": open, "aria-controls": id, onClick: () => setCollapsed(!isCollapsed), children: [
1746
+ headerContent,
1747
+ /* @__PURE__ */ jsx29(Icon, { name: "expand-more", className: cx("tk-panel__chevron", open && "tk-panel__chevron--open") })
1748
+ ] }) : /* @__PURE__ */ jsx29("div", { className: "tk-panel__toggle tk-panel__toggle--static", children: headerContent }),
1749
+ headerActions ? /* @__PURE__ */ jsx29("div", { className: "tk-panel__actions", children: headerActions }) : null
1750
+ ] }) : null,
1751
+ /* @__PURE__ */ jsxs20(Collapse, { open, id, children: [
1752
+ /* @__PURE__ */ jsx29("div", { className: "tk-panel__body", children }),
1753
+ footer ? /* @__PURE__ */ jsx29("div", { className: "tk-panel__footer", children: footer }) : null
1754
+ ] })
1755
+ ] });
1756
+ });
1757
+
1758
+ // src/components/Popover/Popover.tsx
1759
+ import { cloneElement, forwardRef as forwardRef27, isValidElement as isValidElement2, useCallback as useCallback6, useEffect as useEffect14, useId as useId9, useRef as useRef11 } from "react";
1760
+ import { Fragment as Fragment8, jsx as jsx30, jsxs as jsxs21 } from "react/jsx-runtime";
1761
+ var Popover = forwardRef27(function Popover2({ content, open, defaultOpen = false, onOpenChange, placement = "bottom-start", offset = 8, trigger = "click", closeOnOutsideClick = true, closeOnEsc = true, children, className, anchorClassName, ...rest }, ref) {
1762
+ const id = useId9();
1763
+ const [isOpen, setOpen] = useControllableState({ value: open, defaultValue: defaultOpen, onChange: onOpenChange });
1764
+ const anchorRef = useRef11(null);
1765
+ const panelRef = useRef11(null);
1766
+ const hoverTimer = useRef11(void 0);
1767
+ const { floatingRef, style } = useFloating({ open: isOpen, anchorRef, placement, offset });
1768
+ const close = useCallback6(() => {
1769
+ setOpen(false);
1770
+ }, [setOpen]);
1771
+ useOutsideClick([anchorRef, panelRef], close, isOpen && closeOnOutsideClick);
1772
+ useEffect14(() => {
1773
+ if (!isOpen || !closeOnEsc) return;
1774
+ const onKey = (e) => {
1775
+ if (e.key === "Escape") {
1776
+ close();
1777
+ anchorRef.current?.querySelector("button,a,[tabindex]")?.focus();
1778
+ }
1779
+ };
1780
+ document.addEventListener("keydown", onKey);
1781
+ return () => document.removeEventListener("keydown", onKey);
1782
+ }, [isOpen, closeOnEsc, close]);
1783
+ useEffect14(() => () => clearTimeout(hoverTimer.current), []);
1784
+ const enter = () => {
1785
+ clearTimeout(hoverTimer.current);
1786
+ setOpen(true);
1787
+ };
1788
+ const leave = () => {
1789
+ hoverTimer.current = setTimeout(close, 150);
1790
+ };
1791
+ const child = isValidElement2(children) ? cloneElement(children, { "aria-haspopup": "dialog", "aria-expanded": isOpen, "aria-controls": isOpen ? id : void 0 }) : children;
1792
+ return /* @__PURE__ */ jsxs21(Fragment8, { children: [
1793
+ /* @__PURE__ */ jsx30(
1794
+ "span",
1795
+ {
1796
+ ref: anchorRef,
1797
+ className: cx("tk-popover-anchor", anchorClassName),
1798
+ onClick: trigger === "click" ? () => setOpen(!isOpen) : void 0,
1799
+ onMouseEnter: trigger === "hover" ? enter : void 0,
1800
+ onMouseLeave: trigger === "hover" ? leave : void 0,
1801
+ children: child
1802
+ }
1803
+ ),
1804
+ isOpen ? /* @__PURE__ */ jsx30(Portal, { children: /* @__PURE__ */ jsx30(
1805
+ "div",
1806
+ {
1807
+ ref: (n) => {
1808
+ panelRef.current = n;
1809
+ floatingRef.current = n;
1810
+ if (typeof ref === "function") ref(n);
1811
+ else if (ref) ref.current = n;
1812
+ },
1813
+ id,
1814
+ role: "dialog",
1815
+ style,
1816
+ className: cx("tk-popover", className),
1817
+ onMouseEnter: trigger === "hover" ? enter : void 0,
1818
+ onMouseLeave: trigger === "hover" ? leave : void 0,
1819
+ ...rest,
1820
+ children: content
1821
+ }
1822
+ ) }) : null
1823
+ ] });
1824
+ });
1825
+
1826
+ // src/components/Progress/Progress.tsx
1827
+ import { forwardRef as forwardRef28 } from "react";
1828
+ import { jsx as jsx31, jsxs as jsxs22 } from "react/jsx-runtime";
1829
+ var clamp = (n) => Math.min(100, Math.max(0, n));
1830
+ var ProgressBar = forwardRef28(function ProgressBar2({ value, buffer, indeterminate, color, size = "sm", showValue, label, className, ...rest }, ref) {
1831
+ const unknown = indeterminate || value === void 0;
1832
+ const v = clamp(value ?? 0);
1833
+ return /* @__PURE__ */ jsxs22("div", { ref, className: cx("tk-progress", `tk-progress--${size}`, colorClass(color), className), ...rest, children: [
1834
+ /* @__PURE__ */ jsxs22(
1835
+ "div",
1836
+ {
1837
+ className: cx("tk-progress__track", unknown && "tk-progress__track--indeterminate"),
1838
+ role: "progressbar",
1839
+ "aria-label": label,
1840
+ "aria-valuemin": 0,
1841
+ "aria-valuemax": 100,
1842
+ "aria-valuenow": unknown ? void 0 : v,
1843
+ children: [
1844
+ buffer !== void 0 && !unknown ? /* @__PURE__ */ jsx31("span", { className: "tk-progress__buffer", style: { width: `${clamp(buffer)}%` } }) : null,
1845
+ /* @__PURE__ */ jsx31("span", { className: "tk-progress__bar", style: unknown ? void 0 : { width: `${v}%` } }),
1846
+ unknown ? /* @__PURE__ */ jsx31("span", { className: "tk-progress__bar tk-progress__bar--2" }) : null
1847
+ ]
1848
+ }
1849
+ ),
1850
+ showValue && !unknown ? /* @__PURE__ */ jsxs22("span", { className: "tk-progress__value", children: [
1851
+ Math.round(v),
1852
+ "%"
1853
+ ] }) : null
1854
+ ] });
1855
+ });
1856
+ var ProgressCircle = forwardRef28(function ProgressCircle2({ value, indeterminate, color, size = 48, thickness = 4, showValue, label, className, style, ...rest }, ref) {
1857
+ const unknown = indeterminate || value === void 0;
1858
+ const v = clamp(value ?? 0);
1859
+ const r = (size - thickness) / 2;
1860
+ const c = 2 * Math.PI * r;
1861
+ return /* @__PURE__ */ jsxs22(
1862
+ "div",
1863
+ {
1864
+ ref,
1865
+ role: "progressbar",
1866
+ "aria-label": label,
1867
+ "aria-valuemin": 0,
1868
+ "aria-valuemax": 100,
1869
+ "aria-valuenow": unknown ? void 0 : v,
1870
+ className: cx("tk-progress-circle", unknown && "tk-progress-circle--indeterminate", colorClass(color), className),
1871
+ style: { width: size, height: size, ...style },
1872
+ ...rest,
1873
+ children: [
1874
+ /* @__PURE__ */ jsxs22("svg", { viewBox: `0 0 ${size} ${size}`, width: size, height: size, "aria-hidden": "true", children: [
1875
+ /* @__PURE__ */ jsx31("circle", { className: "tk-progress-circle__track", cx: size / 2, cy: size / 2, r, strokeWidth: thickness }),
1876
+ /* @__PURE__ */ jsx31(
1877
+ "circle",
1878
+ {
1879
+ className: "tk-progress-circle__bar",
1880
+ cx: size / 2,
1881
+ cy: size / 2,
1882
+ r,
1883
+ strokeWidth: thickness,
1884
+ strokeDasharray: unknown ? `${c * 0.25} ${c}` : c,
1885
+ strokeDashoffset: unknown ? 0 : c * (1 - v / 100)
1886
+ }
1887
+ )
1888
+ ] }),
1889
+ showValue && !unknown ? /* @__PURE__ */ jsxs22("span", { className: "tk-progress-circle__value", children: [
1890
+ Math.round(v),
1891
+ "%"
1892
+ ] }) : null
1893
+ ]
1894
+ }
1895
+ );
1896
+ });
1897
+
1898
+ // src/components/Radio/Radio.tsx
1899
+ import { createContext as createContext3, forwardRef as forwardRef29, useContext as useContext3, useId as useId10 } from "react";
1900
+ import { jsx as jsx32, jsxs as jsxs23 } from "react/jsx-runtime";
1901
+ var RadioGroupContext = createContext3(null);
1902
+ var RadioGroup = forwardRef29(function RadioGroup2({ value, defaultValue, onChange, name, label, orientation = "vertical", disabled, color, className, children, ...rest }, ref) {
1903
+ const autoName = useId10();
1904
+ const labelId = useId10();
1905
+ const [current, setCurrent] = useControllableState({ value, defaultValue, onChange: (v) => v !== void 0 && onChange?.(v) });
1906
+ return /* @__PURE__ */ jsx32(RadioGroupContext.Provider, { value: { name: name ?? autoName, value: current, onChange: (v) => setCurrent(v), disabled, color }, children: /* @__PURE__ */ jsxs23("div", { ref, role: "radiogroup", "aria-labelledby": label ? labelId : void 0, className: cx("tk-radio-group", `tk-radio-group--${orientation}`, className), ...rest, children: [
1907
+ label ? /* @__PURE__ */ jsx32("div", { id: labelId, className: "tk-radio-group__label", children: label }) : null,
1908
+ /* @__PURE__ */ jsx32("div", { className: "tk-radio-group__items", children })
1909
+ ] }) });
1910
+ });
1911
+ var Radio = forwardRef29(function Radio2({ value, label, description, color, className, id: idProp, disabled, checked, onChange, name, ...rest }, ref) {
1912
+ const group = useContext3(RadioGroupContext);
1913
+ const autoId = useId10();
1914
+ const id = idProp ?? autoId;
1915
+ const isDisabled = disabled ?? group?.disabled;
1916
+ return /* @__PURE__ */ jsxs23("label", { className: cx("tk-radio", colorClass(color ?? group?.color), isDisabled && "tk-radio--disabled", className), htmlFor: id, children: [
1917
+ /* @__PURE__ */ jsxs23("span", { className: "tk-radio__control", children: [
1918
+ /* @__PURE__ */ jsx32(
1919
+ "input",
1920
+ {
1921
+ ref,
1922
+ id,
1923
+ type: "radio",
1924
+ className: "tk-radio__input",
1925
+ name: group?.name ?? name,
1926
+ value,
1927
+ disabled: isDisabled,
1928
+ checked: group ? group.value === value : checked,
1929
+ onChange: (e) => {
1930
+ if (group) group.onChange(value);
1931
+ onChange?.(e);
1932
+ },
1933
+ ...rest
1934
+ }
1935
+ ),
1936
+ /* @__PURE__ */ jsx32("span", { className: "tk-radio__circle", "aria-hidden": "true" })
1937
+ ] }),
1938
+ label || description ? /* @__PURE__ */ jsxs23("span", { className: "tk-radio__text", children: [
1939
+ label ? /* @__PURE__ */ jsx32("span", { className: "tk-radio__label", children: label }) : null,
1940
+ description ? /* @__PURE__ */ jsx32("span", { className: "tk-radio__desc", children: description }) : null
1941
+ ] }) : null
1942
+ ] });
1943
+ });
1944
+
1945
+ // src/components/Sidebar/Sidebar.tsx
1946
+ import { forwardRef as forwardRef31, useEffect as useEffect16, useRef as useRef13, useState as useState15 } from "react";
1947
+
1948
+ // src/components/Tooltip/Tooltip.tsx
1949
+ import { cloneElement as cloneElement2, forwardRef as forwardRef30, isValidElement as isValidElement3, useCallback as useCallback7, useEffect as useEffect15, useId as useId11, useRef as useRef12, useState as useState14 } from "react";
1950
+ import { Fragment as Fragment9, jsx as jsx33, jsxs as jsxs24 } from "react/jsx-runtime";
1951
+ var Tooltip = forwardRef30(function Tooltip2({ content, title, variant = "plain", actions, placement = "top", delay = 300, disabled, children, className, ...rest }, ref) {
1952
+ const id = useId11();
1953
+ const [open, setOpen] = useState14(false);
1954
+ const anchorRef = useRef12(null);
1955
+ const timer = useRef12(void 0);
1956
+ const { floatingRef, style, placement: used } = useFloating({ open, anchorRef, placement, offset: 8 });
1957
+ const show = useCallback7(() => {
1958
+ clearTimeout(timer.current);
1959
+ timer.current = setTimeout(() => setOpen(true), delay);
1960
+ }, [delay]);
1961
+ const hide = useCallback7(() => {
1962
+ clearTimeout(timer.current);
1963
+ setOpen(false);
1964
+ }, []);
1965
+ useEffect15(() => () => clearTimeout(timer.current), []);
1966
+ useEffect15(() => {
1967
+ if (!open) return;
1968
+ const onKey = (e) => e.key === "Escape" && hide();
1969
+ document.addEventListener("keydown", onKey);
1970
+ return () => document.removeEventListener("keydown", onKey);
1971
+ }, [open, hide]);
1972
+ const child = isValidElement3(children) ? cloneElement2(children, { "aria-describedby": open && !disabled ? id : void 0 }) : children;
1973
+ return /* @__PURE__ */ jsxs24(Fragment9, { children: [
1974
+ /* @__PURE__ */ jsx33(
1975
+ "span",
1976
+ {
1977
+ ref: (n) => {
1978
+ anchorRef.current = n;
1979
+ if (typeof ref === "function") ref(n);
1980
+ else if (ref) ref.current = n;
1981
+ },
1982
+ className: cx("tk-tooltip-anchor", className),
1983
+ onMouseEnter: disabled ? void 0 : show,
1984
+ onMouseLeave: variant === "rich" ? () => {
1985
+ timer.current = setTimeout(hide, 120);
1986
+ } : hide,
1987
+ onFocus: disabled ? void 0 : show,
1988
+ onBlur: hide,
1989
+ ...rest,
1990
+ children: child
1991
+ }
1992
+ ),
1993
+ open && !disabled ? /* @__PURE__ */ jsx33(Portal, { children: /* @__PURE__ */ jsxs24(
1994
+ "div",
1995
+ {
1996
+ ref: floatingRef,
1997
+ id,
1998
+ role: "tooltip",
1999
+ style,
2000
+ className: cx("tk-tooltip", `tk-tooltip--${variant}`, `tk-tooltip--${used.split("-")[0]}`),
2001
+ onMouseEnter: () => clearTimeout(timer.current),
2002
+ onMouseLeave: hide,
2003
+ children: [
2004
+ variant === "rich" && title ? /* @__PURE__ */ jsx33("div", { className: "tk-tooltip__title", children: title }) : null,
2005
+ /* @__PURE__ */ jsx33("div", { className: "tk-tooltip__content", children: content }),
2006
+ variant === "rich" && actions ? /* @__PURE__ */ jsx33("div", { className: "tk-tooltip__actions", children: actions }) : null
2007
+ ]
2008
+ }
2009
+ ) }) : null
2010
+ ] });
2011
+ });
2012
+
2013
+ // src/components/Sidebar/Sidebar.tsx
2014
+ import { Fragment as Fragment10, jsx as jsx34, jsxs as jsxs25 } from "react/jsx-runtime";
2015
+ function containsActive(item, id) {
2016
+ return !!id && !!item.children?.some((c) => c.id === id || containsActive(c, id));
2017
+ }
2018
+ function Node({ item, depth, activeId, collapsed, onSelect }) {
2019
+ const hasChildren = !!item.children?.length;
2020
+ const [expanded, setExpanded] = useState15(() => containsActive(item, activeId));
2021
+ useEffect16(() => {
2022
+ if (containsActive(item, activeId)) setExpanded(true);
2023
+ }, [activeId, item]);
2024
+ if (item.divider) return /* @__PURE__ */ jsx34("li", { role: "separator", className: "tk-sidebar__divider" });
2025
+ if (item.heading) return collapsed ? null : /* @__PURE__ */ jsx34("li", { className: "tk-sidebar__heading", children: item.label });
2026
+ const active = item.id === activeId;
2027
+ const Tag = item.href && !hasChildren ? "a" : "button";
2028
+ const handle = (e) => {
2029
+ if (item.disabled) return;
2030
+ if (hasChildren && !collapsed) setExpanded((v) => !v);
2031
+ onSelect?.(item.id, item, e);
2032
+ };
2033
+ const iconNode = item.icon ? /* @__PURE__ */ jsx34("span", { className: "tk-sidebar__icon", children: collapsed && item.badge !== void 0 ? /* @__PURE__ */ jsx34(Badge, { dot: true, overlap: "circular", color: "error", children: item.icon }) : item.icon }) : null;
2034
+ const content = /* @__PURE__ */ jsxs25(
2035
+ Tag,
2036
+ {
2037
+ className: cx("tk-sidebar__item", active && "tk-sidebar__item--active", item.disabled && "tk-sidebar__item--disabled"),
2038
+ ...Tag === "a" ? { href: item.href } : { type: "button" },
2039
+ "aria-current": active ? "page" : void 0,
2040
+ "aria-expanded": hasChildren ? expanded : void 0,
2041
+ "aria-disabled": item.disabled || void 0,
2042
+ disabled: Tag === "button" ? item.disabled : void 0,
2043
+ style: depth > 0 && !collapsed ? { paddingInlineStart: 16 + depth * 16 } : void 0,
2044
+ onClick: handle,
2045
+ children: [
2046
+ iconNode,
2047
+ !collapsed ? /* @__PURE__ */ jsx34("span", { className: "tk-sidebar__label", children: item.label }) : /* @__PURE__ */ jsx34("span", { className: "tk-visually-hidden", children: item.label }),
2048
+ !collapsed && item.badge !== void 0 ? /* @__PURE__ */ jsx34("span", { className: "tk-sidebar__badge", children: item.badge }) : null,
2049
+ !collapsed && hasChildren ? /* @__PURE__ */ jsx34(Icon, { name: "expand-more", size: 20, className: cx("tk-sidebar__chevron", expanded && "tk-sidebar__chevron--open") }) : null
2050
+ ]
2051
+ }
2052
+ );
2053
+ return /* @__PURE__ */ jsxs25("li", { className: "tk-sidebar__node", children: [
2054
+ collapsed ? /* @__PURE__ */ jsx34(Tooltip, { content: item.label, placement: "right", delay: 150, children: content }) : content,
2055
+ hasChildren && !collapsed ? /* @__PURE__ */ jsx34(Collapse, { open: expanded, children: /* @__PURE__ */ jsx34("ul", { className: "tk-sidebar__list", children: item.children.map((c) => /* @__PURE__ */ jsx34(Node, { item: c, depth: depth + 1, activeId, collapsed: false, onSelect }, c.id)) }) }) : null
2056
+ ] });
2057
+ }
2058
+ var Sidebar = forwardRef31(function Sidebar2({ items, activeId, onSelect, collapsed, defaultCollapsed = false, onCollapsedChange, collapsible, header, footer, variant = "permanent", open = false, onClose, width = 280, dense, className, style, "aria-label": ariaLabel = "Main navigation", ...rest }, ref) {
2059
+ const [isCollapsed, setCollapsed] = useControllableState({ value: collapsed, defaultValue: defaultCollapsed, onChange: onCollapsedChange });
2060
+ const temporary = variant === "temporary";
2061
+ const { mounted, visible } = usePresence(temporary && open, 250);
2062
+ const panelRef = useRef13(null);
2063
+ useFocusTrap(panelRef, temporary && open && mounted);
2064
+ useScrollLock(temporary && open);
2065
+ const onCloseRef = useRef13(onClose);
2066
+ onCloseRef.current = onClose;
2067
+ useEffect16(() => {
2068
+ if (!temporary || !open) return;
2069
+ const h = (e) => {
2070
+ if (e.key === "Escape") onCloseRef.current?.();
2071
+ };
2072
+ document.addEventListener("keydown", h);
2073
+ return () => document.removeEventListener("keydown", h);
2074
+ }, [temporary, open]);
2075
+ const rail = !temporary && isCollapsed;
2076
+ const body = /* @__PURE__ */ jsxs25(Fragment10, { children: [
2077
+ header || collapsible ? /* @__PURE__ */ jsxs25("div", { className: "tk-sidebar__header", children: [
2078
+ collapsible && !temporary ? /* @__PURE__ */ jsx34("button", { type: "button", className: "tk-sidebar__toggle", "aria-label": isCollapsed ? "Expand sidebar" : "Collapse sidebar", "aria-expanded": !isCollapsed, onClick: () => setCollapsed(!isCollapsed), children: /* @__PURE__ */ jsx34(Icon, { name: "menu" }) }) : null,
2079
+ !rail && header ? /* @__PURE__ */ jsx34("div", { className: "tk-sidebar__brand", children: header }) : null
2080
+ ] }) : null,
2081
+ /* @__PURE__ */ jsx34("nav", { className: "tk-sidebar__nav", "aria-label": ariaLabel, children: /* @__PURE__ */ jsx34("ul", { className: "tk-sidebar__list", children: items.map((item) => /* @__PURE__ */ jsx34(
2082
+ Node,
2083
+ {
2084
+ item,
2085
+ depth: 0,
2086
+ activeId,
2087
+ collapsed: rail,
2088
+ onSelect: (id, it, e) => {
2089
+ onSelect?.(id, it, e);
2090
+ if (temporary && !it.children?.length) onClose?.();
2091
+ }
2092
+ },
2093
+ item.id
2094
+ )) }) }),
2095
+ footer && !rail ? /* @__PURE__ */ jsx34("div", { className: "tk-sidebar__footer", children: footer }) : null
2096
+ ] });
2097
+ if (!temporary) {
2098
+ return /* @__PURE__ */ jsx34("aside", { ref, className: cx("tk-sidebar", rail && "tk-sidebar--rail", dense && "tk-sidebar--dense", className), style: { width: rail ? 80 : width, ...style }, ...rest, children: body });
2099
+ }
2100
+ if (!mounted) return null;
2101
+ return /* @__PURE__ */ jsx34(Portal, { children: /* @__PURE__ */ jsxs25("div", { className: cx("tk-drawer", visible && "tk-drawer--open"), children: [
2102
+ /* @__PURE__ */ jsx34("div", { className: "tk-drawer__scrim", onClick: onClose, "aria-hidden": "true" }),
2103
+ /* @__PURE__ */ jsx34(
2104
+ "aside",
2105
+ {
2106
+ ref: mergeRefs(ref, panelRef),
2107
+ role: "dialog",
2108
+ "aria-modal": "true",
2109
+ "aria-label": ariaLabel,
2110
+ tabIndex: -1,
2111
+ className: cx("tk-sidebar", "tk-sidebar--temporary", dense && "tk-sidebar--dense", className),
2112
+ style: { width, ...style },
2113
+ ...rest,
2114
+ children: body
2115
+ }
2116
+ )
2117
+ ] }) });
2118
+ });
2119
+
2120
+ // src/components/Skeleton/Skeleton.tsx
2121
+ import { forwardRef as forwardRef32 } from "react";
2122
+ import { jsx as jsx35 } from "react/jsx-runtime";
2123
+ var Skeleton = forwardRef32(function Skeleton2({ variant = "text", width, height, animation = "pulse", lines = 1, className, style, ...rest }, ref) {
2124
+ const base = cx("tk-skeleton", `tk-skeleton--${variant}`, animation && `tk-skeleton--${animation}`);
2125
+ if (variant === "text" && lines > 1) {
2126
+ return /* @__PURE__ */ jsx35("div", { ref, "aria-hidden": "true", className: cx("tk-skeleton-lines", className), style, ...rest, children: Array.from({ length: lines }, (_, i) => /* @__PURE__ */ jsx35("span", { className: base, style: { width: i === lines - 1 ? "60%" : width, height } }, i)) });
2127
+ }
2128
+ return /* @__PURE__ */ jsx35("div", { ref, "aria-hidden": "true", className: cx(base, className), style: { width, height, ...style }, ...rest });
2129
+ });
2130
+
2131
+ // src/components/Stepper/Stepper.tsx
2132
+ import { forwardRef as forwardRef33 } from "react";
2133
+ import { jsx as jsx36, jsxs as jsxs26 } from "react/jsx-runtime";
2134
+ var Stepper = forwardRef33(function Stepper2({ steps, activeStep, orientation = "horizontal", onStepClick, linear = true, alternativeLabel, className, ...rest }, ref) {
2135
+ return /* @__PURE__ */ jsx36("ol", { ref, className: cx("tk-stepper", `tk-stepper--${orientation}`, alternativeLabel && orientation === "horizontal" && "tk-stepper--alt", className), ...rest, children: steps.map((step, i) => {
2136
+ const completed = step.completed ?? i < activeStep;
2137
+ const active = i === activeStep;
2138
+ const clickable = !!onStepClick && !step.disabled && (!linear || completed || active);
2139
+ const state = step.error ? "error" : active ? "active" : completed ? "completed" : "upcoming";
2140
+ const indicator = /* @__PURE__ */ jsx36("span", { className: "tk-step__indicator", "aria-hidden": "true", children: step.error ? /* @__PURE__ */ jsx36(Icon, { name: "warning", size: 16 }) : step.icon ? step.icon : completed && !active ? /* @__PURE__ */ jsx36(Icon, { name: "check", size: 16 }) : i + 1 });
2141
+ const labels = /* @__PURE__ */ jsxs26("span", { className: "tk-step__labels", children: [
2142
+ /* @__PURE__ */ jsx36("span", { className: "tk-step__label", children: step.label }),
2143
+ step.optional ? /* @__PURE__ */ jsx36("span", { className: "tk-step__desc", children: "Optional" }) : null,
2144
+ step.description ? /* @__PURE__ */ jsx36("span", { className: "tk-step__desc", children: step.description }) : null
2145
+ ] });
2146
+ const head = clickable ? /* @__PURE__ */ jsxs26("button", { type: "button", className: "tk-step__head", onClick: () => onStepClick?.(i), "aria-current": active ? "step" : void 0, children: [
2147
+ indicator,
2148
+ labels
2149
+ ] }) : /* @__PURE__ */ jsxs26("div", { className: "tk-step__head", "aria-current": active ? "step" : void 0, children: [
2150
+ indicator,
2151
+ labels
2152
+ ] });
2153
+ return /* @__PURE__ */ jsxs26("li", { className: cx("tk-step", `tk-step--${state}`, i === steps.length - 1 && "tk-step--last"), children: [
2154
+ head,
2155
+ orientation === "vertical" ? /* @__PURE__ */ jsx36("div", { className: "tk-step__body", children: /* @__PURE__ */ jsx36(Collapse, { open: active && !!step.content, children: /* @__PURE__ */ jsx36("div", { className: "tk-step__content", children: step.content }) }) }) : null
2156
+ ] }, i);
2157
+ }) });
2158
+ });
2159
+
2160
+ // src/components/Tabs/Tabs.tsx
2161
+ import { createContext as createContext4, forwardRef as forwardRef34, useContext as useContext4, useId as useId12, useState as useState16 } from "react";
2162
+ import { useRef as useRef14 } from "react";
2163
+ import { jsx as jsx37, jsxs as jsxs27 } from "react/jsx-runtime";
2164
+ var Ctx2 = createContext4(null);
2165
+ var useTabs = () => {
2166
+ const c = useContext4(Ctx2);
2167
+ if (!c) throw new Error("Tab components must be used inside <Tabs>");
2168
+ return c;
2169
+ };
2170
+ var Tabs = forwardRef34(function Tabs2({ value, defaultValue, onChange, variant = "primary", fullWidth, className, children, ...rest }, ref) {
2171
+ const baseId = useId12();
2172
+ const [current, setCurrent] = useControllableState({ value, defaultValue, onChange: (v) => v !== void 0 && onChange?.(v) });
2173
+ return /* @__PURE__ */ jsx37(Ctx2.Provider, { value: { value: current, setValue: (v) => setCurrent(v), baseId, variant, fullWidth }, children: /* @__PURE__ */ jsx37("div", { ref, className: cx("tk-tabs", className), ...rest, children }) });
2174
+ });
2175
+ var TabList = forwardRef34(function TabList2({ className, children, onKeyDown, ...rest }, ref) {
2176
+ const { value, variant, fullWidth } = useTabs();
2177
+ const listRef = useRef14(null);
2178
+ const [indicator, setIndicator] = useState16(null);
2179
+ useIsomorphicLayoutEffect(() => {
2180
+ const list = listRef.current;
2181
+ if (!list) return;
2182
+ const measure = () => {
2183
+ const active = list.querySelector('[role="tab"][aria-selected="true"]');
2184
+ if (!active) return setIndicator(null);
2185
+ const label = variant === "primary" ? active.querySelector(".tk-tab__content") : null;
2186
+ const target = label ?? active;
2187
+ const lr = list.getBoundingClientRect();
2188
+ const tr = target.getBoundingClientRect();
2189
+ setIndicator({ left: tr.left - lr.left + list.scrollLeft, width: tr.width });
2190
+ active.scrollIntoView?.({ block: "nearest", inline: "nearest" });
2191
+ };
2192
+ measure();
2193
+ const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : void 0;
2194
+ ro?.observe(list);
2195
+ return () => ro?.disconnect();
2196
+ }, [value, variant, children]);
2197
+ const handleKey = (e) => {
2198
+ onKeyDown?.(e);
2199
+ const tabs = Array.from(listRef.current?.querySelectorAll('[role="tab"]:not([disabled])') ?? []);
2200
+ const i = tabs.indexOf(document.activeElement);
2201
+ if (i < 0) return;
2202
+ const rtl = getComputedStyle(listRef.current).direction === "rtl";
2203
+ let next = -1;
2204
+ if (e.key === (rtl ? "ArrowLeft" : "ArrowRight")) next = (i + 1) % tabs.length;
2205
+ else if (e.key === (rtl ? "ArrowRight" : "ArrowLeft")) next = (i - 1 + tabs.length) % tabs.length;
2206
+ else if (e.key === "Home") next = 0;
2207
+ else if (e.key === "End") next = tabs.length - 1;
2208
+ if (next >= 0) {
2209
+ e.preventDefault();
2210
+ tabs[next].focus();
2211
+ tabs[next].click();
2212
+ }
2213
+ };
2214
+ return /* @__PURE__ */ jsxs27("div", { ref: mergeRefs(ref, listRef), role: "tablist", className: cx("tk-tablist", `tk-tablist--${variant}`, fullWidth && "tk-tablist--full", className), onKeyDown: handleKey, ...rest, children: [
2215
+ children,
2216
+ indicator ? /* @__PURE__ */ jsx37("span", { className: "tk-tablist__indicator", style: { transform: `translateX(${indicator.left}px)`, width: indicator.width } }) : null
2217
+ ] });
2218
+ });
2219
+ var Tab = forwardRef34(function Tab2({ value, icon, badge, className, children, onClick, ...rest }, ref) {
2220
+ const ctx = useTabs();
2221
+ const selected = ctx.value === value;
2222
+ return /* @__PURE__ */ jsx37(
2223
+ "button",
2224
+ {
2225
+ ref,
2226
+ type: "button",
2227
+ role: "tab",
2228
+ id: `${ctx.baseId}-tab-${value}`,
2229
+ "aria-selected": selected,
2230
+ "aria-controls": `${ctx.baseId}-panel-${value}`,
2231
+ tabIndex: selected ? 0 : -1,
2232
+ className: cx("tk-tab", selected && "tk-tab--selected", icon && children && "tk-tab--icon-label", className),
2233
+ onClick: (e) => {
2234
+ onClick?.(e);
2235
+ if (!e.defaultPrevented) ctx.setValue(value);
2236
+ },
2237
+ ...rest,
2238
+ children: /* @__PURE__ */ jsxs27("span", { className: "tk-tab__content", children: [
2239
+ icon ? /* @__PURE__ */ jsx37("span", { className: "tk-tab__icon", children: icon }) : null,
2240
+ children ? /* @__PURE__ */ jsx37("span", { className: "tk-tab__label", children }) : null,
2241
+ badge !== void 0 && badge !== false ? /* @__PURE__ */ jsx37(Badge, { className: "tk-tab__badge", dot: badge === true, count: typeof badge === "number" ? badge : void 0 }) : null
2242
+ ] })
2243
+ }
2244
+ );
2245
+ });
2246
+ var TabPanel = forwardRef34(function TabPanel2({ value, keepMounted, className, children, ...rest }, ref) {
2247
+ const ctx = useTabs();
2248
+ const active = ctx.value === value;
2249
+ return /* @__PURE__ */ jsx37("div", { ref, role: "tabpanel", id: `${ctx.baseId}-panel-${value}`, "aria-labelledby": `${ctx.baseId}-tab-${value}`, hidden: !active, tabIndex: 0, className: cx("tk-tabpanel", className), ...rest, children: active || keepMounted ? children : null });
2250
+ });
2251
+
2252
+ // src/components/Textarea/Textarea.tsx
2253
+ import { forwardRef as forwardRef35, useCallback as useCallback8, useId as useId13, useRef as useRef15, useState as useState17 } from "react";
2254
+ import { jsx as jsx38 } from "react/jsx-runtime";
2255
+ var Textarea = forwardRef35(function Textarea2({ variant, label, helperText, error, disabled, startAdornment, endAdornment, fullWidth, size, autoResize, minRows = 3, maxRows, showCounter, id: idProp, value, defaultValue, onChange, onFocus, onBlur, maxLength, required, className, style, ...rest }, ref) {
2256
+ const autoId = useId13();
2257
+ const id = idProp ?? autoId;
2258
+ const helperId = `${id}-helper`;
2259
+ const inner = useRef15(null);
2260
+ const [focused, setFocused] = useState17(false);
2261
+ const [innerValue, setInnerValue] = useState17(String(defaultValue ?? ""));
2262
+ const controlled = value !== void 0;
2263
+ const current = controlled ? String(value ?? "") : innerValue;
2264
+ const resize = useCallback8(() => {
2265
+ const el = inner.current;
2266
+ if (!el || !autoResize) return;
2267
+ const cs = getComputedStyle(el);
2268
+ const line = parseFloat(cs.lineHeight) || 24;
2269
+ const pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom);
2270
+ el.style.height = "auto";
2271
+ const max = maxRows ? line * maxRows + pad : Infinity;
2272
+ el.style.height = `${Math.min(el.scrollHeight, max)}px`;
2273
+ el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
2274
+ }, [autoResize, maxRows]);
2275
+ useIsomorphicLayoutEffect(resize, [resize, current]);
2276
+ const handleChange = (e) => {
2277
+ if (!controlled) setInnerValue(e.target.value);
2278
+ onChange?.(e);
2279
+ };
2280
+ return /* @__PURE__ */ jsx38(
2281
+ FieldShell,
2282
+ {
2283
+ id,
2284
+ helperId,
2285
+ variant,
2286
+ label,
2287
+ helperText,
2288
+ error,
2289
+ disabled,
2290
+ startAdornment,
2291
+ endAdornment,
2292
+ fullWidth,
2293
+ size,
2294
+ focused,
2295
+ filled: current.length > 0,
2296
+ multiline: true,
2297
+ required,
2298
+ style,
2299
+ counter: showCounter && maxLength ? `${current.length} / ${maxLength}` : void 0,
2300
+ children: /* @__PURE__ */ jsx38(
2301
+ "textarea",
2302
+ {
2303
+ ref: mergeRefs(ref, inner),
2304
+ id,
2305
+ className: cx("tk-field__input", "tk-field__textarea", autoResize && "tk-field__textarea--auto", className),
2306
+ rows: minRows,
2307
+ value: controlled ? value : void 0,
2308
+ defaultValue: controlled ? void 0 : defaultValue,
2309
+ disabled,
2310
+ required,
2311
+ maxLength,
2312
+ "aria-invalid": error || void 0,
2313
+ "aria-describedby": helperText ? helperId : void 0,
2314
+ onChange: handleChange,
2315
+ onFocus: (e) => {
2316
+ setFocused(true);
2317
+ onFocus?.(e);
2318
+ },
2319
+ onBlur: (e) => {
2320
+ setFocused(false);
2321
+ onBlur?.(e);
2322
+ },
2323
+ ...rest
2324
+ }
2325
+ )
2326
+ }
2327
+ );
2328
+ });
2329
+
2330
+ // src/components/Toast/Toast.tsx
2331
+ import { createContext as createContext5, useCallback as useCallback9, useContext as useContext5, useEffect as useEffect17, useMemo as useMemo4, useRef as useRef16, useState as useState18 } from "react";
2332
+ import { jsx as jsx39, jsxs as jsxs28 } from "react/jsx-runtime";
2333
+ var ToastContext = createContext5(null);
2334
+ function useToast() {
2335
+ const ctx = useContext5(ToastContext);
2336
+ if (!ctx) throw new Error("useToast must be used inside <ToastProvider>");
2337
+ return ctx;
2338
+ }
2339
+ var icons = { info: "info", success: "check-circle", warning: "warning", error: "error" };
2340
+ function ToastItem({ item, defaultDuration, onDismiss, onRemove }) {
2341
+ const { id, options, closing } = item;
2342
+ const duration = options.duration ?? defaultDuration;
2343
+ const [paused, setPaused] = useState18(false);
2344
+ const remaining = useRef16(duration);
2345
+ const startedAt = useRef16(0);
2346
+ useEffect17(() => {
2347
+ if (closing || duration === 0 || paused) return;
2348
+ startedAt.current = Date.now();
2349
+ const t = setTimeout(() => onDismiss(id), remaining.current);
2350
+ return () => {
2351
+ clearTimeout(t);
2352
+ remaining.current = Math.max(500, remaining.current - (Date.now() - startedAt.current));
2353
+ };
2354
+ }, [closing, duration, paused, id, onDismiss]);
2355
+ useEffect17(() => {
2356
+ if (!closing) return;
2357
+ const t = setTimeout(() => onRemove(id), 200);
2358
+ return () => clearTimeout(t);
2359
+ }, [closing, id, onRemove]);
2360
+ const severity = options.severity ?? "neutral";
2361
+ const icon = options.icon === false ? null : options.icon ?? (severity !== "neutral" ? /* @__PURE__ */ jsx39(Icon, { name: icons[severity] }) : null);
2362
+ return /* @__PURE__ */ jsxs28(
2363
+ "div",
2364
+ {
2365
+ role: severity === "error" ? "alert" : "status",
2366
+ className: cx("tk-toast", `tk-toast--${severity}`, closing && "tk-toast--closing"),
2367
+ onMouseEnter: () => setPaused(true),
2368
+ onMouseLeave: () => setPaused(false),
2369
+ onFocus: () => setPaused(true),
2370
+ onBlur: () => setPaused(false),
2371
+ children: [
2372
+ icon ? /* @__PURE__ */ jsx39("span", { className: "tk-toast__icon", children: icon }) : null,
2373
+ /* @__PURE__ */ jsxs28("div", { className: "tk-toast__body", children: [
2374
+ options.title ? /* @__PURE__ */ jsx39("div", { className: "tk-toast__title", children: options.title }) : null,
2375
+ /* @__PURE__ */ jsx39("div", { className: "tk-toast__message", children: options.message })
2376
+ ] }),
2377
+ options.action ? /* @__PURE__ */ jsx39("button", { type: "button", className: "tk-toast__action", onClick: () => {
2378
+ options.action?.onClick?.();
2379
+ onDismiss(id);
2380
+ }, children: options.action.label }) : null,
2381
+ options.closable !== false ? /* @__PURE__ */ jsx39("button", { type: "button", className: "tk-toast__close", "aria-label": "Close", onClick: () => onDismiss(id), children: /* @__PURE__ */ jsx39(Icon, { name: "close", size: 20 }) }) : null
2382
+ ]
2383
+ }
2384
+ );
2385
+ }
2386
+ var counter = 0;
2387
+ function ToastProvider({ children, placement = "bottom-center", duration = 5e3, max = 4 }) {
2388
+ const [items, setItems] = useState18([]);
2389
+ const remove = useCallback9((id) => {
2390
+ setItems((list) => {
2391
+ const found = list.find((i) => i.id === id);
2392
+ if (found) found.options.onClose?.();
2393
+ return list.filter((i) => i.id !== id);
2394
+ });
2395
+ }, []);
2396
+ const dismiss = useCallback9((id) => setItems((list) => list.map((i) => i.id === id ? { ...i, closing: true } : i)), []);
2397
+ const dismissAll = useCallback9(() => setItems((list) => list.map((i) => ({ ...i, closing: true }))), []);
2398
+ const show = useCallback9((options) => {
2399
+ const id = options.id ?? `toast-${++counter}`;
2400
+ setItems((list) => {
2401
+ const without = list.filter((i) => i.id !== id);
2402
+ const next = [...without, { id, options, closing: false }];
2403
+ const active = next.filter((i) => !i.closing);
2404
+ const overflow = active.length - max;
2405
+ if (overflow > 0) {
2406
+ const drop = new Set(active.slice(0, overflow).map((i) => i.id));
2407
+ return next.map((i) => drop.has(i.id) ? { ...i, closing: true } : i);
2408
+ }
2409
+ return next;
2410
+ });
2411
+ return id;
2412
+ }, [max]);
2413
+ const api = useMemo4(() => ({
2414
+ show,
2415
+ info: (message, o) => show({ ...o, message, severity: "info" }),
2416
+ success: (message, o) => show({ ...o, message, severity: "success" }),
2417
+ warning: (message, o) => show({ ...o, message, severity: "warning" }),
2418
+ error: (message, o) => show({ ...o, message, severity: "error" }),
2419
+ dismiss,
2420
+ dismissAll
2421
+ }), [show, dismiss, dismissAll]);
2422
+ const ordered = placement.startsWith("top") ? [...items].reverse() : items;
2423
+ return /* @__PURE__ */ jsxs28(ToastContext.Provider, { value: api, children: [
2424
+ children,
2425
+ items.length > 0 ? /* @__PURE__ */ jsx39(Portal, { children: /* @__PURE__ */ jsx39("div", { className: cx("tk-toaster", `tk-toaster--${placement}`), children: ordered.map((item) => /* @__PURE__ */ jsx39(ToastItem, { item, defaultDuration: duration, onDismiss: dismiss, onRemove: remove }, item.id)) }) }) : null
2426
+ ] });
2427
+ }
2428
+ export {
2429
+ Accordion,
2430
+ AccordionItem,
2431
+ Alert,
2432
+ Avatar,
2433
+ AvatarGroup,
2434
+ Badge,
2435
+ Breadcrumb,
2436
+ Button,
2437
+ Calendar,
2438
+ Card,
2439
+ CardActions,
2440
+ CardContent,
2441
+ CardHeader,
2442
+ CardMedia,
2443
+ Checkbox,
2444
+ Chip,
2445
+ Col,
2446
+ Collapse,
2447
+ Container,
2448
+ ContextMenu,
2449
+ Dialog,
2450
+ Divider,
2451
+ FileUpload,
2452
+ Grid,
2453
+ Icon,
2454
+ Input,
2455
+ InputTags,
2456
+ Loader,
2457
+ Modal,
2458
+ Navbar,
2459
+ Pagination,
2460
+ Panel,
2461
+ Popover,
2462
+ ProgressBar,
2463
+ ProgressCircle,
2464
+ Radio,
2465
+ RadioGroup,
2466
+ Sidebar,
2467
+ Skeleton,
2468
+ Spinner,
2469
+ Stack,
2470
+ Stepper,
2471
+ Tab,
2472
+ TabList,
2473
+ TabPanel,
2474
+ Tabs,
2475
+ Textarea,
2476
+ ThemeProvider,
2477
+ ToastProvider,
2478
+ Tooltip,
2479
+ blueTheme,
2480
+ breakpointKeys,
2481
+ breakpoints,
2482
+ createTheme,
2483
+ darkTheme,
2484
+ formatBytes,
2485
+ iconPaths,
2486
+ pinkTheme,
2487
+ themeToCss,
2488
+ themeToCssVars,
2489
+ themes,
2490
+ typographyScale,
2491
+ useBreakpoint,
2492
+ useBreakpointUp,
2493
+ useControllableState,
2494
+ useFloating,
2495
+ useMediaQuery,
2496
+ usePagination,
2497
+ usePresence,
2498
+ useTheme,
2499
+ useToast
2500
+ };
2501
+ //# sourceMappingURL=index.js.map