@splenddev/kreativ-ui 0.2.8 → 0.2.9

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 CHANGED
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
 
3
- import { createContext, forwardRef, useState, useId, useRef, useEffect, useCallback, useLayoutEffect, useMemo, useContext, useReducer } from 'react';
3
+ import { createContext, forwardRef, useState, useId, useRef, useEffect, useMemo, useCallback, useLayoutEffect, useContext, useReducer, Children, isValidElement } from 'react';
4
4
  import { useReducedMotion, motion, AnimatePresence } from 'framer-motion';
5
5
  import { clsx } from 'clsx';
6
6
  import { twMerge } from 'tailwind-merge';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
- import { ChevronDown, X, Heading, Bold, Italic, ListOrdered, ClipboardList, Code, Link, Check, Lock, Hash, Search, Link2, Phone, Mail, EyeOff, Eye, Sun, Moon, Monitor } from 'lucide-react';
8
+ import { ChevronDown, X, Heading, Bold, Italic, ListOrdered, ClipboardList, Code, Link, Minus, Check, Lock, Hash, Search, Link2, Phone, Mail, EyeOff, Eye, Sun, Moon, Monitor } from 'lucide-react';
9
9
  import { cva } from 'class-variance-authority';
10
10
 
11
11
  console.log("BANNER TEST");
@@ -28,20 +28,24 @@ function useTheme() {
28
28
  return ctx;
29
29
  }
30
30
  __name(useTheme, "useTheme");
31
- function useSizeStyle(size, iconOnly = false, component = "button", options = {}) {
32
- const { includeHeight = true } = options;
31
+ var applySizeOffset = /* @__PURE__ */ __name((value, offset) => {
32
+ if (!value || !offset) return value;
33
+ return `calc(${value} - ${offset})`;
34
+ }, "applySizeOffset");
35
+ function useSizeStyle(size, iconOnly = false, componentName = "componentName", options = {}) {
36
+ const { widthFromHeight = false, includeHeight = true, sizeOffset, fontSizeOffset } = options;
33
37
  const { theme, fallbackSize } = useTheme();
34
38
  return useMemo(() => {
35
39
  const scale = theme.sizes;
36
40
  const token = scale[size] ?? scale[fallbackSize] ?? Object.values(scale)[0] ?? {};
37
41
  const style = {};
38
42
  if (includeHeight && token.height) {
39
- style.height = token.height;
43
+ style.height = applySizeOffset(token.height, sizeOffset);
40
44
  }
41
45
  if (token.width) {
42
- style.width = token.width;
43
- } else if (iconOnly && includeHeight && token.height) {
44
- style.width = token.height;
46
+ style.width = applySizeOffset(token.width, sizeOffset);
47
+ } else if ((iconOnly || widthFromHeight) && includeHeight && token.height) {
48
+ style.width = applySizeOffset(token.height, sizeOffset);
45
49
  }
46
50
  if (!iconOnly && token.paddingX) {
47
51
  style.paddingLeft = token.paddingX;
@@ -52,343 +56,32 @@ function useSizeStyle(size, iconOnly = false, component = "button", options = {}
52
56
  style.paddingBottom = token.paddingY;
53
57
  }
54
58
  if (token.fontSize) {
55
- style.fontSize = token.fontSize;
59
+ style.fontSize = applySizeOffset(token.fontSize, fontSizeOffset);
56
60
  }
57
61
  if (token.gap) {
58
62
  style.gap = iconOnly ? 0 : token.gap;
59
63
  }
60
64
  if (token.radius) {
61
- const varName = `--kui-${component}-radius`;
65
+ const varName = `--kui-${componentName}-radius`;
62
66
  style[varName] = token.radius;
63
67
  }
64
68
  return {
65
69
  style,
66
- iconSize: token.iconSize
70
+ iconSize: token.iconSize,
71
+ fontSize: applySizeOffset(token.fontSize, fontSizeOffset),
72
+ gap: token.gap
67
73
  };
68
- }, [theme.sizes, size, fallbackSize, iconOnly, includeHeight, component]);
74
+ }, [
75
+ theme.sizes,
76
+ size,
77
+ fallbackSize,
78
+ iconOnly,
79
+ includeHeight,
80
+ componentName,
81
+ widthFromHeight
82
+ ]);
69
83
  }
70
84
  __name(useSizeStyle, "useSizeStyle");
71
-
72
- // src/theme/recipes/defineRecipe.ts
73
- function defineRecipe(recipe) {
74
- return recipe;
75
- }
76
- __name(defineRecipe, "defineRecipe");
77
-
78
- // src/theme/recipes/mergeRecipes.ts
79
- function mergeRecipeDefinition(base, override) {
80
- return {
81
- ...base,
82
- base: override.base ?? base.base,
83
- variants: {
84
- ...base.variants,
85
- ...override.variants
86
- },
87
- defaultVariants: {
88
- ...base.defaultVariants,
89
- ...override.defaultVariants
90
- },
91
- compoundVariants: override.compoundVariants ?? base.compoundVariants
92
- };
93
- }
94
- __name(mergeRecipeDefinition, "mergeRecipeDefinition");
95
- function mergeRecipes(base, override) {
96
- if (!override) {
97
- return base;
98
- }
99
- const result = {
100
- ...base
101
- };
102
- for (const [name, recipeOverride] of Object.entries(override)) {
103
- const baseRecipe = base[name];
104
- if (!baseRecipe) {
105
- result[name] = recipeOverride;
106
- continue;
107
- }
108
- result[name] = mergeRecipeDefinition(
109
- baseRecipe,
110
- recipeOverride
111
- );
112
- }
113
- return result;
114
- }
115
- __name(mergeRecipes, "mergeRecipes");
116
-
117
- // src/theme/recipes/resolveRecipe.ts
118
- function matchesConditions(conditions, props) {
119
- return Object.entries(conditions).every(
120
- ([key, expected]) => props[key] === expected
121
- );
122
- }
123
- __name(matchesConditions, "matchesConditions");
124
- function resolveRecipe(recipe, props = {}) {
125
- if (!recipe) return "";
126
- const resolvedProps = {
127
- ...recipe.defaultVariants,
128
- ...props
129
- };
130
- const classes = [];
131
- if (recipe.base) {
132
- classes.push(recipe.base);
133
- }
134
- if (recipe.variants) {
135
- for (const [variantName, variantValues] of Object.entries(
136
- recipe.variants
137
- )) {
138
- const value = resolvedProps[variantName];
139
- if (value === void 0) continue;
140
- const variantClass = variantValues[String(value)];
141
- if (variantClass) {
142
- classes.push(variantClass);
143
- }
144
- }
145
- }
146
- if (recipe.compoundVariants) {
147
- for (const compound of recipe.compoundVariants) {
148
- if (matchesConditions(compound.conditions, resolvedProps)) {
149
- classes.push(compound.className);
150
- }
151
- }
152
- }
153
- return cn(...classes);
154
- }
155
- __name(resolveRecipe, "resolveRecipe");
156
-
157
- // src/theme/defaults/recipes/button.ts
158
- var buttonBase = "inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none";
159
- var buttonVariants = {
160
- solid: "",
161
- outline: "border bg-transparent",
162
- ghost: "bg-transparent",
163
- soft: "",
164
- link: "bg-transparent p-0 h-auto hover:underline"
165
- };
166
- var buttonColors = {
167
- brand: {
168
- solid: "bg-brand text-brand-fg hover:bg-brand-hover",
169
- outline: "border-brand text-brand hover:bg-brand/10",
170
- ghost: "text-brand hover:bg-brand/10",
171
- soft: "bg-brand/10 text-brand hover:bg-brand/20",
172
- link: "text-brand"
173
- },
174
- destructive: {
175
- solid: "bg-destructive text-destructive-fg hover:bg-destructive-hover",
176
- outline: "border-destructive text-destructive hover:bg-destructive/10",
177
- ghost: "text-destructive hover:bg-destructive/10",
178
- soft: "bg-destructive/10 text-destructive hover:bg-destructive/20",
179
- link: "text-destructive"
180
- },
181
- success: {
182
- solid: "bg-success text-success-fg hover:bg-success-hover",
183
- outline: "border-success text-success hover:bg-success/10",
184
- ghost: "text-success hover:bg-success/10",
185
- soft: "bg-success/10 text-success hover:bg-success/20",
186
- link: "text-success"
187
- },
188
- warning: {
189
- solid: "bg-warning text-warning-fg hover:bg-warning-hover",
190
- outline: "border-warning text-warning hover:bg-warning/10",
191
- ghost: "text-warning hover:bg-warning/10",
192
- soft: "bg-warning/10 text-warning hover:bg-warning/20",
193
- link: "text-warning"
194
- },
195
- info: {
196
- solid: "bg-info text-info-fg hover:bg-info-hover",
197
- outline: "border-info text-info hover:bg-info/10",
198
- ghost: "text-info hover:bg-info/10",
199
- soft: "bg-info/10 text-info hover:bg-info/20",
200
- link: "text-info"
201
- },
202
- white: {
203
- solid: "bg-white text-black hover:bg-gray-50",
204
- outline: "border-white/30 text-white hover:bg-white/10",
205
- ghost: "text-white hover:bg-white/10",
206
- soft: "bg-white/10 text-white hover:bg-white/20",
207
- link: "text-white"
208
- },
209
- neutral: {
210
- solid: "bg-surface-raised text-text hover:bg-surface-sunken",
211
- outline: "border-border text-text hover:bg-surface-raised",
212
- ghost: "text-text hover:bg-surface-raised",
213
- soft: "bg-surface-raised text-text hover:bg-surface-sunken",
214
- link: "text-text"
215
- }
216
- };
217
- var buildCompoundVariants = /* @__PURE__ */ __name(() => {
218
- const compounds = [];
219
- for (const [color, variantMap] of Object.entries(buttonColors)) {
220
- for (const [variant, className] of Object.entries(variantMap)) {
221
- compounds.push({
222
- conditions: { color, variant },
223
- className
224
- });
225
- }
226
- }
227
- return compounds;
228
- }, "buildCompoundVariants");
229
- var buttonRecipe = defineRecipe({
230
- base: buttonBase,
231
- variants: {
232
- variant: buttonVariants,
233
- color: Object.fromEntries(
234
- Object.keys(buttonColors).map((color) => [color, ""])
235
- )
236
- },
237
- defaultVariants: {
238
- variant: "solid",
239
- color: "brand"
240
- },
241
- compoundVariants: buildCompoundVariants()
242
- });
243
-
244
- // src/theme/defaults/recipes/input.ts
245
- var inputBase = "flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:pointer-events-none disabled:cursor-not-allowed";
246
- var inputRecipe = defineRecipe({
247
- base: inputBase,
248
- variants: {
249
- variant: {
250
- outline: "",
251
- filled: "",
252
- ghost: ""
253
- }
254
- },
255
- defaultVariants: {
256
- variant: "outline"
257
- }
258
- });
259
-
260
- // src/theme/defaults/recipes/formControl.ts
261
- var formControlBase = "group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-colors duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-2 ";
262
- var formControlVariants = {
263
- outline: "border border-border bg-transparent text-text hover:border-brand",
264
- filled: "border border-transparent bg-surface-raised text-text hover:bg-surface",
265
- ghost: "border border-transparent bg-transparent text-text hover:bg-surface-raised"
266
- };
267
- var formControlStates = {
268
- none: "focus-within:ring-brand/20",
269
- error: "border-destructive focus-within:ring-destructive/20",
270
- success: "border-success focus-within:ring-success/20"
271
- };
272
- var formControlRecipe = defineRecipe({
273
- base: formControlBase,
274
- variants: {
275
- variant: formControlVariants,
276
- state: formControlStates,
277
- rounded: {
278
- true: "rounded-full",
279
- false: ""
280
- },
281
- fullWidth: {
282
- true: "w-full",
283
- false: ""
284
- },
285
- disabled: {
286
- true: "pointer-events-none cursor-not-allowed opacity-50",
287
- false: ""
288
- },
289
- hasAdornment: {
290
- true: "px-2",
291
- false: ""
292
- }
293
- },
294
- defaultVariants: {
295
- variant: "outline",
296
- state: "none",
297
- rounded: false,
298
- fullWidth: true,
299
- disabled: false,
300
- hasAdornment: false
301
- }
302
- });
303
-
304
- // src/utils/color.ts
305
- var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
306
- function rgbToHex(value) {
307
- const trimmed = value.trim();
308
- if (HEX_RE.test(trimmed)) {
309
- if (trimmed.length === 4) {
310
- return ("#" + [...trimmed.slice(1)].map((char) => char + char).join("")).toUpperCase();
311
- }
312
- return trimmed.toUpperCase();
313
- }
314
- const values = trimmed.replace(/[^\d,]/g, "").split(",").map(Number);
315
- if (values.length !== 3 || values.some(Number.isNaN)) {
316
- return "#000000";
317
- }
318
- return "#" + values.map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
319
- }
320
- __name(rgbToHex, "rgbToHex");
321
- function hexToRgbString(hex) {
322
- if (!HEX_RE.test(hex)) return null;
323
- const full = hex.length === 4 ? "#" + [...hex.slice(1)].map((c) => c + c).join("") : hex;
324
- const r = parseInt(full.slice(1, 3), 16);
325
- const g = parseInt(full.slice(3, 5), 16);
326
- const b = parseInt(full.slice(5, 7), 16);
327
- return `${r} ${g} ${b}`;
328
- }
329
- __name(hexToRgbString, "hexToRgbString");
330
-
331
- // src/utils/resolveTokenReference.ts
332
- function resolveTokenReference(value, tokens) {
333
- if (typeof value !== "string") {
334
- return typeof value === "number" ? value : "";
335
- }
336
- const match = value.match(/^\{(.+)\}$/);
337
- if (!match) {
338
- return value;
339
- }
340
- const path = match[1].split(".");
341
- let current = tokens;
342
- for (const key of path) {
343
- if (typeof current !== "object" || current === null || !(key in current)) {
344
- return "";
345
- }
346
- current = current[key];
347
- }
348
- if (typeof current === "object" && current !== null && "value" in current) {
349
- const tokenValue = current.value;
350
- if (typeof tokenValue === "string" || typeof tokenValue === "number") {
351
- return tokenValue;
352
- }
353
- return "";
354
- }
355
- return typeof current === "string" || typeof current === "number" ? current : "";
356
- }
357
- __name(resolveTokenReference, "resolveTokenReference");
358
-
359
- // src/theme/typography/resolveTypography.ts
360
- function resolveTypography(typography, tokens) {
361
- if (!typography) return {};
362
- return {
363
- fontFamily: resolveTokenReference(typography.fontFamily, tokens),
364
- fontSize: resolveTokenReference(typography.fontSize, tokens),
365
- fontWeight: resolveTokenReference(typography.fontWeight, tokens),
366
- lineHeight: resolveTokenReference(typography.lineHeight, tokens),
367
- letterSpacing: resolveTokenReference(
368
- typography.letterSpacing,
369
- tokens
370
- )
371
- };
372
- }
373
- __name(resolveTypography, "resolveTypography");
374
-
375
- // src/theme/typography/defineTypography.ts
376
- function defineTypography(typography) {
377
- return typography;
378
- }
379
- __name(defineTypography, "defineTypography");
380
-
381
- // src/theme/token/defineToken.ts
382
- function defineToken(value) {
383
- return {
384
- value
385
- };
386
- }
387
- __name(defineToken, "defineToken");
388
- function defineSemanticToken(light, dark) {
389
- return { value: { light, dark } };
390
- }
391
- __name(defineSemanticToken, "defineSemanticToken");
392
85
  var BREAKPOINTS = {
393
86
  sm: 640,
394
87
  md: 768,
@@ -440,27 +133,71 @@ function useFloatingSide(triggerRef, open) {
440
133
  }
441
134
  __name(useFloatingSide, "useFloatingSide");
442
135
  var TRANSITION_DURATION = 1500;
443
- function useStateTransition(state) {
444
- const previousState = useRef(state);
445
- const [transitionState, setTransitionState] = useState();
136
+ function useStatusTransition(status) {
137
+ const previousStatus = useRef(status);
138
+ const [transitionStatus, setTransitionStatus] = useState();
446
139
  useEffect(() => {
447
- if (state === previousState.current) {
140
+ if (status === previousStatus.current) {
448
141
  return;
449
142
  }
450
- previousState.current = state;
451
- if (state === "none") {
452
- setTransitionState(void 0);
143
+ previousStatus.current = status;
144
+ if (status === "none") {
145
+ setTransitionStatus(void 0);
453
146
  return;
454
147
  }
455
- setTransitionState(state);
148
+ setTransitionStatus(status);
456
149
  const timeout = window.setTimeout(() => {
457
- setTransitionState(void 0);
150
+ setTransitionStatus(void 0);
458
151
  }, TRANSITION_DURATION);
459
152
  return () => window.clearTimeout(timeout);
460
- }, [state]);
461
- return transitionState;
153
+ }, [status]);
154
+ return transitionStatus;
155
+ }
156
+ __name(useStatusTransition, "useStatusTransition");
157
+
158
+ // src/utils/resolveTokenReference.ts
159
+ function resolveTokenReference(value, tokens) {
160
+ if (typeof value !== "string") {
161
+ return typeof value === "number" ? value : "";
162
+ }
163
+ const match = value.match(/^\{(.+)\}$/);
164
+ if (!match) {
165
+ return value;
166
+ }
167
+ const path = match[1].split(".");
168
+ let current = tokens;
169
+ for (const key of path) {
170
+ if (typeof current !== "object" || current === null || !(key in current)) {
171
+ return "";
172
+ }
173
+ current = current[key];
174
+ }
175
+ if (typeof current === "object" && current !== null && "value" in current) {
176
+ const tokenValue = current.value;
177
+ if (typeof tokenValue === "string" || typeof tokenValue === "number") {
178
+ return tokenValue;
179
+ }
180
+ return "";
181
+ }
182
+ return typeof current === "string" || typeof current === "number" ? current : "";
462
183
  }
463
- __name(useStateTransition, "useStateTransition");
184
+ __name(resolveTokenReference, "resolveTokenReference");
185
+
186
+ // src/theme/typography/resolveTypography.ts
187
+ function resolveTypography(typography, tokens) {
188
+ if (!typography) return {};
189
+ return {
190
+ fontFamily: resolveTokenReference(typography.fontFamily, tokens),
191
+ fontSize: resolveTokenReference(typography.fontSize, tokens),
192
+ fontWeight: resolveTokenReference(typography.fontWeight, tokens),
193
+ lineHeight: resolveTokenReference(typography.lineHeight, tokens),
194
+ letterSpacing: resolveTokenReference(
195
+ typography.letterSpacing,
196
+ tokens
197
+ )
198
+ };
199
+ }
200
+ __name(resolveTypography, "resolveTypography");
464
201
 
465
202
  // src/hooks/useTypography.ts
466
203
  function useTypography(name) {
@@ -471,6 +208,62 @@ function useTypography(name) {
471
208
  );
472
209
  }
473
210
  __name(useTypography, "useTypography");
211
+ function useClearableField(elementRef, initialValue, onClear) {
212
+ const [hasValue, setHasValue] = useState(() => Boolean(initialValue ?? ""));
213
+ const clear = useCallback(() => {
214
+ const element = elementRef.current;
215
+ if (!element) return;
216
+ const prototype = element instanceof HTMLTextAreaElement ? window.HTMLTextAreaElement.prototype : window.HTMLInputElement.prototype;
217
+ const setter = Object.getOwnPropertyDescriptor(prototype, "value")?.set;
218
+ setter?.call(element, "");
219
+ element.dispatchEvent(new Event("input", { bubbles: true }));
220
+ element.focus();
221
+ setHasValue(false);
222
+ onClear?.();
223
+ }, [elementRef, onClear]);
224
+ return { hasValue, setHasValue, clear };
225
+ }
226
+ __name(useClearableField, "useClearableField");
227
+
228
+ // src/theme/recipes/resolveRecipe.ts
229
+ function matchesConditions(conditions, props) {
230
+ return Object.entries(conditions).every(
231
+ ([key, expected]) => props[key] === expected
232
+ );
233
+ }
234
+ __name(matchesConditions, "matchesConditions");
235
+ function resolveRecipe(recipe, props = {}) {
236
+ if (!recipe) return "";
237
+ const resolvedProps = {
238
+ ...recipe.defaultVariants,
239
+ ...props
240
+ };
241
+ const classes = [];
242
+ if (recipe.base) {
243
+ classes.push(recipe.base);
244
+ }
245
+ if (recipe.variants) {
246
+ for (const [variantName, variantValues] of Object.entries(
247
+ recipe.variants
248
+ )) {
249
+ const value = resolvedProps[variantName];
250
+ if (value === void 0) continue;
251
+ const variantClass = variantValues[String(value)];
252
+ if (variantClass) {
253
+ classes.push(variantClass);
254
+ }
255
+ }
256
+ }
257
+ if (recipe.compoundVariants) {
258
+ for (const compound of recipe.compoundVariants) {
259
+ if (matchesConditions(compound.conditions, resolvedProps)) {
260
+ classes.push(compound.className);
261
+ }
262
+ }
263
+ }
264
+ return cn(...classes);
265
+ }
266
+ __name(resolveRecipe, "resolveRecipe");
474
267
  var ACTIVATION_KEYS = /* @__PURE__ */ new Set(["Enter", " "]);
475
268
  var Button = forwardRef(
476
269
  ({
@@ -565,9 +358,11 @@ var Button = forwardRef(
565
358
  className: resolvedClassName,
566
359
  style: resolvedStyle,
567
360
  "aria-busy": isLoading || void 0,
361
+ "aria-disabled": disabled,
568
362
  animate: {
569
363
  scale: isKeyboardPressed ? 0.975 : 1
570
364
  },
365
+ type: "button",
571
366
  whileHover: isInteractive ? { scale: 1.015 } : void 0,
572
367
  whileTap: isInteractive ? { scale: 0.975 } : void 0,
573
368
  transition: prefersReducedMotion ? { duration: 0 } : {
@@ -584,6 +379,33 @@ var Button = forwardRef(
584
379
  }
585
380
  );
586
381
  Button.displayName = "Button";
382
+
383
+ // src/utils/color.ts
384
+ var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
385
+ function rgbToHex(value) {
386
+ const trimmed = value.trim();
387
+ if (HEX_RE.test(trimmed)) {
388
+ if (trimmed.length === 4) {
389
+ return ("#" + [...trimmed.slice(1)].map((char) => char + char).join("")).toUpperCase();
390
+ }
391
+ return trimmed.toUpperCase();
392
+ }
393
+ const values = trimmed.replace(/[^\d,]/g, "").split(",").map(Number);
394
+ if (values.length !== 3 || values.some(Number.isNaN)) {
395
+ return "#000000";
396
+ }
397
+ return "#" + values.map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
398
+ }
399
+ __name(rgbToHex, "rgbToHex");
400
+ function hexToRgbString(hex) {
401
+ if (!HEX_RE.test(hex)) return null;
402
+ const full = hex.length === 4 ? "#" + [...hex.slice(1)].map((c) => c + c).join("") : hex;
403
+ const r = parseInt(full.slice(1, 3), 16);
404
+ const g = parseInt(full.slice(3, 5), 16);
405
+ const b = parseInt(full.slice(5, 7), 16);
406
+ return `${r} ${g} ${b}`;
407
+ }
408
+ __name(hexToRgbString, "hexToRgbString");
587
409
  var defaultTransition = {
588
410
  type: "none",
589
411
  duration: 300,
@@ -876,6 +698,8 @@ function useOptionalFormField() {
876
698
  return useContext(FormFieldContext);
877
699
  }
878
700
  __name(useOptionalFormField, "useOptionalFormField");
701
+
702
+ // src/utils/mergeRef.ts
879
703
  function mergeRefs(...refs) {
880
704
  return (node) => {
881
705
  refs.forEach((ref) => {
@@ -897,10 +721,11 @@ var Input = forwardRef(
897
721
  size = "md",
898
722
  error,
899
723
  success,
724
+ warning,
900
725
  startIcon,
901
726
  endIcon,
902
727
  fullWidth = true,
903
- disabled,
728
+ disabled = false,
904
729
  rounded = false,
905
730
  isLoading = false,
906
731
  clearable = false,
@@ -908,42 +733,62 @@ var Input = forwardRef(
908
733
  kind = "text",
909
734
  hideKindIcon = false,
910
735
  id: externalId,
736
+ trim = false,
911
737
  type: typeProp,
912
738
  inputMode: inputModeProp,
913
739
  autoComplete: autoCompleteProp,
914
740
  placeholder: placeholderProp,
915
741
  onChange: onChangeProp,
916
- readOnly: readOnlyProp,
742
+ onValueChange: onValueChangeProp,
743
+ onBlur: onBlurProp,
917
744
  value,
918
745
  defaultValue,
919
746
  style,
920
747
  ...props
921
748
  }, ref) => {
922
749
  const autoId = useId();
750
+ const internalRef = useRef(null);
923
751
  const { theme } = useTheme();
924
752
  const field = useOptionalFormField();
925
753
  const id = externalId ?? field?.id ?? autoId;
926
- const isInvalid = error || field?.invalid || false;
927
- const describedBy = field?.describedBy ?? void 0;
928
754
  const isRequired = field?.required ?? props.required;
929
- const internalRef = useRef(null);
755
+ const describedBy = field?.describedBy;
756
+ const state = error ? "error" : success ? "success" : warning ? "warning" : field?.status ?? "none";
757
+ const isInvalid = state === "error";
758
+ const statusTransition = useStatusTransition(state);
930
759
  const { style: sizeStyle, iconSize } = useSizeStyle(size, false, "input");
931
- const [hasValue, setHasValue] = useState(
932
- () => Boolean(value ?? defaultValue ?? "")
933
- );
934
760
  const [visible, setVisible] = useState(false);
761
+ const { hasValue, setHasValue, clear } = useClearableField(
762
+ internalRef,
763
+ value ?? defaultValue,
764
+ onClear
765
+ );
935
766
  useEffect(() => {
936
767
  if (value !== void 0) {
937
768
  setHasValue(Boolean(value));
938
769
  }
939
- }, [value]);
770
+ }, [value, setHasValue]);
940
771
  const kindDefaults = inputKindDefaults[kind];
941
772
  const resolvedType = typeProp ?? kindDefaults.type;
942
773
  const isPasswordField = resolvedType === "password";
943
774
  const effectiveType = isPasswordField ? visible ? "text" : "password" : resolvedType;
944
775
  const KindIcon = inputKindIcons[kind];
945
- const defaultStartIcon = !hideKindIcon && KindIcon ? /* @__PURE__ */ jsx(KindIcon, { size: Number(iconSize) || 15 }) : void 0;
946
- const startSlot = startIcon || defaultStartIcon ? /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-center justify-center", children: startIcon ?? defaultStartIcon }) : null;
776
+ const defaultStartIcon = !hideKindIcon && KindIcon ? /* @__PURE__ */ jsx(KindIcon, {}) : void 0;
777
+ const startAdornment = useMemo(() => {
778
+ const icon = startIcon ?? defaultStartIcon;
779
+ if (!icon) return null;
780
+ return /* @__PURE__ */ jsx(
781
+ "span",
782
+ {
783
+ className: "flex shrink-0 items-center justify-center",
784
+ style: {
785
+ width: iconSize,
786
+ height: iconSize
787
+ },
788
+ children: icon
789
+ }
790
+ );
791
+ }, [startIcon, defaultStartIcon, iconSize]);
947
792
  const builtInEnd = [];
948
793
  if (isPasswordField) {
949
794
  builtInEnd.push(
@@ -951,11 +796,27 @@ var Input = forwardRef(
951
796
  "button",
952
797
  {
953
798
  type: "button",
954
- tabIndex: -1,
955
799
  onClick: () => setVisible((current) => !current),
956
800
  "aria-label": visible ? "Hide password" : "Show password",
957
- className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
958
- children: visible ? /* @__PURE__ */ jsx(EyeOff, { size: 16 }) : /* @__PURE__ */ jsx(Eye, { size: 16 })
801
+ "aria-pressed": visible,
802
+ className: "\r\n flex items-center justify-center\r\n text-text-muted\r\n transition-colors\r\n hover:text-text\r\n focus-visible:outline\r\n focus-visible:outline-2\r\n focus-visible:outline-offset-2\r\n ",
803
+ children: visible ? /* @__PURE__ */ jsx(
804
+ EyeOff,
805
+ {
806
+ style: {
807
+ width: iconSize,
808
+ height: iconSize
809
+ }
810
+ }
811
+ ) : /* @__PURE__ */ jsx(
812
+ Eye,
813
+ {
814
+ style: {
815
+ width: iconSize,
816
+ height: iconSize
817
+ }
818
+ }
819
+ )
959
820
  },
960
821
  "toggle-visibility"
961
822
  )
@@ -967,28 +828,46 @@ var Input = forwardRef(
967
828
  "button",
968
829
  {
969
830
  type: "button",
970
- tabIndex: -1,
971
- onClick: handleClear,
831
+ onClick: clear,
972
832
  "aria-label": "Clear input",
973
- className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
974
- children: /* @__PURE__ */ jsx(X, { size: 14 })
833
+ className: "\r\n flex items-center justify-center\r\n text-text-muted\r\n transition-colors\r\n hover:text-text\r\n focus-visible:outline\r\n focus-visible:outline-2\r\n focus-visible:outline-offset-2\r\n ",
834
+ children: /* @__PURE__ */ jsx(
835
+ X,
836
+ {
837
+ style: {
838
+ width: iconSize,
839
+ height: iconSize
840
+ }
841
+ }
842
+ )
975
843
  },
976
844
  "clear"
977
845
  )
978
846
  );
979
847
  }
980
- const endSlot = isLoading ? /* @__PURE__ */ jsx(Spinner, { size: Number(iconSize) || 14 }) : endIcon ? endIcon : builtInEnd.length ? /* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center gap-1.5", children: builtInEnd }) : null;
981
- const hasIcon = Boolean(startSlot || endSlot);
982
- const state = error ? "error" : success ? "success" : "none";
983
- const stateTransition = useStateTransition(state);
848
+ const endAdornment = isLoading ? /* @__PURE__ */ jsx(Spinner, { size: iconSize || 14 }) : endIcon || builtInEnd.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
849
+ endIcon && /* @__PURE__ */ jsx(
850
+ "span",
851
+ {
852
+ className: "flex items-center justify-center",
853
+ style: {
854
+ width: iconSize,
855
+ height: iconSize
856
+ },
857
+ children: endIcon
858
+ }
859
+ ),
860
+ builtInEnd
861
+ ] }) : null;
862
+ const hasAdornment = Boolean(startAdornment) || Boolean(endAdornment);
984
863
  const wrapperClasses = cn(
985
864
  resolveRecipe(theme.recipes.FormControl, {
986
865
  variant,
987
866
  state,
988
867
  rounded,
989
868
  fullWidth,
990
- disabled: Boolean(disabled || isLoading),
991
- hasIcon
869
+ disabled: disabled || isLoading,
870
+ hasAdornment
992
871
  }),
993
872
  className
994
873
  );
@@ -1005,44 +884,42 @@ var Input = forwardRef(
1005
884
  function handleChange(event) {
1006
885
  setHasValue(Boolean(event.target.value));
1007
886
  onChangeProp?.(event);
887
+ onValueChangeProp?.(event.target.value);
1008
888
  }
1009
889
  __name(handleChange, "handleChange");
1010
- function handleClear() {
1011
- const element = internalRef.current;
1012
- if (!element) return;
1013
- const setter = Object.getOwnPropertyDescriptor(
1014
- window.HTMLInputElement.prototype,
1015
- "value"
1016
- )?.set;
1017
- setter?.call(element, "");
1018
- element.dispatchEvent(
1019
- new Event("input", {
1020
- bubbles: true
1021
- })
1022
- );
1023
- element.focus();
1024
- setHasValue(false);
1025
- onClear?.();
890
+ function handleBlur(event) {
891
+ if (trim && !disabled && !isLoading) {
892
+ const trimmedValue = event.currentTarget.value.trim();
893
+ if (trimmedValue !== event.currentTarget.value) {
894
+ event.currentTarget.value = trimmedValue;
895
+ setHasValue(Boolean(trimmedValue));
896
+ onValueChangeProp?.(trimmedValue);
897
+ }
898
+ }
899
+ onBlurProp?.(event);
1026
900
  }
1027
- __name(handleClear, "handleClear");
901
+ __name(handleBlur, "handleBlur");
902
+ const wasInvalidRef = useRef(isInvalid);
1028
903
  useEffect(() => {
1029
- if (!error) return;
1030
- const element = internalRef.current;
1031
- if (!element) return;
1032
- element.scrollIntoView({
904
+ const justBecameInvalid = isInvalid && !wasInvalidRef.current;
905
+ wasInvalidRef.current = isInvalid;
906
+ if (!justBecameInvalid) {
907
+ return;
908
+ }
909
+ internalRef.current?.scrollIntoView({
1033
910
  behavior: "smooth",
1034
911
  block: "center"
1035
912
  });
1036
- }, [error]);
913
+ }, [isInvalid]);
1037
914
  return /* @__PURE__ */ jsxs(
1038
915
  "div",
1039
916
  {
1040
917
  className: wrapperClasses,
1041
918
  style: resolvedStyle,
1042
919
  "data-state": state,
1043
- "data-state-transition": stateTransition,
920
+ "data-state-transition": statusTransition,
1044
921
  children: [
1045
- startSlot,
922
+ startAdornment,
1046
923
  /* @__PURE__ */ jsx(
1047
924
  "input",
1048
925
  {
@@ -1056,31 +933,54 @@ var Input = forwardRef(
1056
933
  value,
1057
934
  defaultValue,
1058
935
  onChange: handleChange,
1059
- readOnly: isLoading || readOnlyProp,
1060
- disabled: isLoading || disabled,
936
+ onBlur: handleBlur,
937
+ disabled: disabled || isLoading,
1061
938
  "aria-busy": isLoading || void 0,
1062
939
  "aria-invalid": isInvalid || void 0,
1063
940
  "aria-describedby": describedBy,
1064
941
  "aria-required": isRequired || void 0,
1065
942
  className: inputClasses,
1066
- "data-variant": variant,
1067
- "data-size": size,
1068
- "data-success": success || void 0,
1069
943
  "data-disabled": disabled || void 0,
1070
- "data-loading": isLoading || void 0
944
+ "data-loading": isLoading || void 0,
945
+ "data-size": size,
946
+ "data-state": state,
947
+ "data-variant": variant
1071
948
  }
1072
949
  ),
1073
- endSlot
950
+ endAdornment
1074
951
  ]
1075
- },
1076
- stateTransition ?? "idle"
952
+ }
1077
953
  );
1078
954
  }
1079
955
  );
1080
956
  Input.displayName = "Input";
957
+
958
+ // src/utils/env.ts
959
+ function readProcessEnv() {
960
+ try {
961
+ return typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
962
+ } catch {
963
+ return void 0;
964
+ }
965
+ }
966
+ __name(readProcessEnv, "readProcessEnv");
967
+ function readImportMetaEnv() {
968
+ try {
969
+ return typeof import.meta !== "undefined" ? import.meta.env?.MODE : void 0;
970
+ } catch {
971
+ return void 0;
972
+ }
973
+ }
974
+ __name(readImportMetaEnv, "readImportMetaEnv");
975
+ function isDev() {
976
+ const mode = readProcessEnv() ?? readImportMetaEnv();
977
+ return mode !== void 0 && mode !== "production";
978
+ }
979
+ __name(isDev, "isDev");
1081
980
  function FormField({
1082
981
  id: externalId,
1083
- error,
982
+ status = "none",
983
+ message: formMessage,
1084
984
  required = false,
1085
985
  className,
1086
986
  children
@@ -1090,24 +990,52 @@ function FormField({
1090
990
  const labelId = `${id}-label`;
1091
991
  const descriptionId = `${id}-description`;
1092
992
  const messageId = `${id}-message`;
1093
- const [reportedMessage, setReportedMessage] = useState(
1094
- void 0
1095
- );
993
+ const [reportedValidity, setReportedValidity] = useState(null);
994
+ const reportValidity = useCallback((result) => {
995
+ setReportedValidity(result);
996
+ }, []);
997
+ const reportedMessage = reportedValidity?.invalid ? reportedValidity.message : void 0;
1096
998
  const [labelCount, setLabelCount] = useState(0);
1097
- const reportValidity = useCallback(
1098
- (result) => {
1099
- if (error !== void 0) return;
1100
- setReportedMessage(result?.invalid ? result.message : void 0);
1101
- },
1102
- [error]
1103
- );
999
+ function countMessageComponents(children2) {
1000
+ let count = 0;
1001
+ Children.forEach(children2, (child) => {
1002
+ if (!isValidElement(child)) {
1003
+ return;
1004
+ }
1005
+ if (child.type === FormFieldMessage) {
1006
+ count += 1;
1007
+ return;
1008
+ }
1009
+ if (child.props.children) {
1010
+ count += countMessageComponents(child.props.children);
1011
+ }
1012
+ });
1013
+ return count;
1014
+ }
1015
+ __name(countMessageComponents, "countMessageComponents");
1104
1016
  const registerLabel = useCallback(() => {
1105
- setLabelCount((n) => n + 1);
1106
- return () => setLabelCount((n) => n - 1);
1017
+ setLabelCount((count) => count + 1);
1018
+ return () => {
1019
+ setLabelCount((count) => count - 1);
1020
+ };
1107
1021
  }, []);
1108
1022
  const hasExternalLabel = labelCount > 0;
1109
- const displayedMessage = error ?? reportedMessage;
1110
- const state = displayedMessage ? "error" : "none";
1023
+ const displayedMessage = formMessage ?? reportedMessage;
1024
+ const message = displayedMessage;
1025
+ const invalid = status === "error" || Boolean(formMessage) || Boolean(reportedValidity?.invalid);
1026
+ const messageCount = countMessageComponents(children);
1027
+ const hasCustomMessage = messageCount > 0;
1028
+ const describedBy = [descriptionId, message || hasCustomMessage ? messageId : void 0].filter(Boolean).join(" ") || void 0;
1029
+ useEffect(() => {
1030
+ if (!isDev()) {
1031
+ return;
1032
+ }
1033
+ if (messageCount > 1) {
1034
+ console.warn(
1035
+ "[Kreativ UI] Multiple <FormField.Message /> components were detected inside the same <FormField>. Only one custom message should be provided."
1036
+ );
1037
+ }
1038
+ }, [messageCount]);
1111
1039
  return /* @__PURE__ */ jsx(
1112
1040
  FormFieldContext.Provider,
1113
1041
  {
@@ -1116,9 +1044,10 @@ function FormField({
1116
1044
  labelId,
1117
1045
  descriptionId,
1118
1046
  messageId,
1119
- state,
1120
- describedBy: [descriptionId, displayedMessage ? messageId : void 0].filter(Boolean).join(" ") || void 0,
1121
- invalid: Boolean(displayedMessage),
1047
+ message,
1048
+ status,
1049
+ describedBy,
1050
+ invalid,
1122
1051
  required,
1123
1052
  reportValidity,
1124
1053
  registerLabel,
@@ -1126,7 +1055,7 @@ function FormField({
1126
1055
  },
1127
1056
  children: /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2", className), children: [
1128
1057
  children,
1129
- displayedMessage && /* @__PURE__ */ jsx(FormFieldMessage, { children: displayedMessage })
1058
+ !hasCustomMessage && /* @__PURE__ */ jsx(FormFieldMessage, {})
1130
1059
  ] })
1131
1060
  }
1132
1061
  );
@@ -1149,7 +1078,7 @@ function FormFieldLabel({
1149
1078
  {
1150
1079
  id: field.labelId,
1151
1080
  htmlFor: field.id,
1152
- className: cn("text-sm font-medium text-text", className),
1081
+ className: cn("font-medium text-text text-sm", className),
1153
1082
  children: [
1154
1083
  children,
1155
1084
  field.required && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "ml-1 text-destructive", children: "*" })
@@ -1174,15 +1103,30 @@ function FormFieldDescription({
1174
1103
  );
1175
1104
  }
1176
1105
  __name(FormFieldDescription, "FormFieldDescription");
1106
+ var statusClasses = {
1107
+ error: "text-destructive animate-kui-shake [animation-delay:500ms]",
1108
+ success: "text-success",
1109
+ warning: "text-warning"
1110
+ };
1177
1111
  function FormFieldMessage({ children }) {
1178
- const { messageId } = useFormField();
1112
+ const { messageId, message, status, invalid } = useFormField();
1113
+ const content = children ?? message;
1114
+ if (!content) {
1115
+ return null;
1116
+ }
1117
+ const effectiveStatus = status !== "none" ? status : invalid ? "error" : "none";
1179
1118
  return /* @__PURE__ */ jsx(
1180
1119
  "p",
1181
1120
  {
1182
1121
  id: messageId,
1183
- role: "alert",
1184
- className: "\r\n animate-kui-shake [animation-delay:500ms]\r\n text-sm text-destructive\r\n ",
1185
- children
1122
+ role: effectiveStatus === "error" ? "alert" : void 0,
1123
+ "aria-live": effectiveStatus === "error" ? "assertive" : "polite",
1124
+ "data-status": effectiveStatus,
1125
+ className: cn(
1126
+ "text-sm",
1127
+ effectiveStatus !== "none" && statusClasses[effectiveStatus]
1128
+ ),
1129
+ children: content
1186
1130
  }
1187
1131
  );
1188
1132
  }
@@ -1651,38 +1595,48 @@ Select.Item = SelectItem;
1651
1595
  Select.Value = SelectValue;
1652
1596
  Select.Group = SelectGroup;
1653
1597
  Select.Label = SelectLabel;
1654
-
1655
- // src/components/Textarea/Textarea.styles.ts
1656
- var textareaBase = cn(
1657
- "flex w-full min-w-0 bg-transparent font-sans outline-none border-0",
1658
- "text-text placeholder:text-text-muted",
1659
- "transition-colors duration-[var(--kui-duration-fast)]",
1660
- "disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed"
1661
- );
1662
- var textareaResizeVariants = {
1663
- none: "resize-none",
1664
- both: "resize",
1665
- horizontal: "resize-x",
1666
- vertical: "resize-y"
1667
- };
1668
1598
  function mergeRefs2(...refs) {
1669
1599
  return (node) => {
1670
- refs.forEach((r) => {
1671
- if (!r) return;
1672
- if (typeof r === "function") r(node);
1673
- else r.current = node;
1600
+ refs.forEach((ref) => {
1601
+ if (!ref) return;
1602
+ if (typeof ref === "function") {
1603
+ ref(node);
1604
+ } else {
1605
+ ref.current = node;
1606
+ }
1674
1607
  });
1675
1608
  };
1676
1609
  }
1677
1610
  __name(mergeRefs2, "mergeRefs");
1611
+ function resolveFieldState({
1612
+ error,
1613
+ success,
1614
+ warning,
1615
+ hasReachedMaxLength,
1616
+ internalInvalid,
1617
+ fieldInvalid
1618
+ }) {
1619
+ const isInvalid = error === true || hasReachedMaxLength || internalInvalid === true || fieldInvalid === true;
1620
+ const isSuccess = !isInvalid && (success ?? internalInvalid === false);
1621
+ const isWarning = !isInvalid && !isSuccess && warning === true;
1622
+ const state = isInvalid ? "error" : isSuccess ? "success" : isWarning ? "warning" : "none";
1623
+ return { isInvalid, isSuccess, isWarning, state };
1624
+ }
1625
+ __name(resolveFieldState, "resolveFieldState");
1678
1626
  var TextareaCore = forwardRef(
1679
1627
  ({
1680
- className,
1681
1628
  value: valueProp,
1682
1629
  defaultValue,
1630
+ onValueChange: onValueChangeProp,
1631
+ onChange: onChangeProp,
1632
+ onBlur: onBlurProp,
1633
+ className,
1634
+ style: customStyle,
1683
1635
  size = "md",
1684
- fullWidth = true,
1636
+ variant = "outline",
1685
1637
  resize = "vertical",
1638
+ fullWidth = true,
1639
+ embedded = false,
1686
1640
  autoResize = false,
1687
1641
  minRows,
1688
1642
  maxRows,
@@ -1690,43 +1644,71 @@ var TextareaCore = forwardRef(
1690
1644
  onClear,
1691
1645
  characterCounter = false,
1692
1646
  debounceDelay = 0,
1693
- trimOnBlur = false,
1647
+ trim = false,
1694
1648
  error,
1695
1649
  success,
1696
- onValidate,
1650
+ warning,
1651
+ validate,
1652
+ validateOn = "blur",
1697
1653
  disabled,
1698
1654
  id: externalId,
1655
+ required,
1699
1656
  maxLength,
1700
- variant = "outline",
1701
- onValueChange: onValueChangeProp,
1702
- onChange: onChangeProp,
1703
- onBlur: onBlurProp,
1704
1657
  rows,
1705
1658
  ...props
1706
1659
  }, ref) => {
1707
1660
  const autoId = useId();
1708
1661
  const field = useOptionalFormField();
1709
- const id = field?.id ?? externalId ?? autoId;
1710
1662
  const { theme } = useTheme();
1663
+ const id = field?.id ?? externalId ?? autoId;
1711
1664
  const internalRef = useRef(null);
1712
1665
  const debounceTimer = useRef(null);
1666
+ const typography = useTypography("body");
1667
+ const { style: sizeStyle } = useSizeStyle(size, false, "textarea", {
1668
+ includeHeight: false
1669
+ });
1713
1670
  const [draft, setDraft] = useState(() => valueProp ?? defaultValue ?? "");
1714
1671
  useEffect(() => {
1715
- if (valueProp !== void 0) setDraft(valueProp);
1672
+ if (valueProp !== void 0) {
1673
+ setDraft(valueProp);
1674
+ }
1716
1675
  }, [valueProp]);
1717
1676
  const [internalValidation, setInternalValidation] = useState({});
1718
- const isInvalid = error ?? field?.invalid ?? internalValidation.invalid ?? false;
1719
- const isSuccess = success ?? (onValidate ? internalValidation.invalid === false : false);
1720
- const state = isInvalid ? "error" : isSuccess ? "success" : "none";
1721
- useEffect(
1722
- () => () => {
1723
- if (debounceTimer.current) clearTimeout(debounceTimer.current);
1724
- },
1725
- []
1677
+ const maxLengthExceeded = maxLength !== void 0 && draft.length > maxLength;
1678
+ const hasValue = draft.length > 0;
1679
+ const hasMaxLength = typeof maxLength === "number";
1680
+ const hasReachedMaxLength = hasMaxLength && draft.length >= maxLength;
1681
+ const maxLengthMessage = hasReachedMaxLength ? `Maximum length of ${maxLength} characters reached.` : void 0;
1682
+ const { isInvalid, isSuccess, isWarning, state } = useMemo(
1683
+ () => resolveFieldState({
1684
+ error,
1685
+ success,
1686
+ warning,
1687
+ hasReachedMaxLength,
1688
+ internalInvalid: internalValidation.invalid,
1689
+ fieldInvalid: field?.invalid
1690
+ }),
1691
+ [
1692
+ error,
1693
+ success,
1694
+ warning,
1695
+ hasReachedMaxLength,
1696
+ internalValidation.invalid,
1697
+ field?.invalid
1698
+ ]
1726
1699
  );
1700
+ useEffect(() => {
1701
+ return () => {
1702
+ if (debounceTimer.current) {
1703
+ clearTimeout(debounceTimer.current);
1704
+ }
1705
+ };
1706
+ }, []);
1727
1707
  function commitValue(next, { immediate = false } = {}) {
1728
1708
  setDraft(next);
1729
- if (debounceTimer.current) clearTimeout(debounceTimer.current);
1709
+ if (debounceTimer.current) {
1710
+ clearTimeout(debounceTimer.current);
1711
+ }
1730
1712
  if (debounceDelay > 0 && !immediate) {
1731
1713
  debounceTimer.current = setTimeout(() => {
1732
1714
  onValueChangeProp?.(next);
@@ -1736,84 +1718,137 @@ var TextareaCore = forwardRef(
1736
1718
  }
1737
1719
  }
1738
1720
  __name(commitValue, "commitValue");
1739
- function handleChange(e) {
1740
- commitValue(e.target.value);
1741
- onChangeProp?.(e);
1721
+ function getValidationResult(value) {
1722
+ if (maxLength !== void 0 && value.length >= maxLength) {
1723
+ return {
1724
+ invalid: true,
1725
+ message: maxLengthMessage
1726
+ };
1727
+ }
1728
+ if (!validate) {
1729
+ return null;
1730
+ }
1731
+ const result = validate(value);
1732
+ if (result === true) {
1733
+ return {
1734
+ invalid: false,
1735
+ message: void 0
1736
+ };
1737
+ }
1738
+ if (result === false) {
1739
+ return {
1740
+ invalid: true,
1741
+ message: void 0
1742
+ };
1743
+ }
1744
+ return {
1745
+ invalid: true,
1746
+ message: result
1747
+ };
1742
1748
  }
1743
- __name(handleChange, "handleChange");
1744
- function runValidation(next) {
1745
- if (!onValidate || error !== void 0 || success !== void 0) return;
1746
- const result = onValidate(next);
1747
- const parsed = result === true ? { invalid: false, message: void 0 } : result === false ? { invalid: true, message: void 0 } : { invalid: true, message: result };
1748
- setInternalValidation(parsed);
1749
- field?.reportValidity(parsed.invalid ? parsed : null);
1749
+ __name(getValidationResult, "getValidationResult");
1750
+ function runValidation(value) {
1751
+ const result = getValidationResult(value);
1752
+ setInternalValidation(result ?? {});
1753
+ field?.reportValidity(result?.invalid ? result : null);
1750
1754
  }
1751
1755
  __name(runValidation, "runValidation");
1752
- function handleBlur(e) {
1756
+ function handleChange(event) {
1757
+ const next = event.target.value;
1758
+ commitValue(next);
1759
+ onChangeProp?.(event);
1760
+ const shouldValidate = validateOn === "change" || validateOn === "both";
1761
+ if (shouldValidate) {
1762
+ runValidation(next);
1763
+ } else if (internalValidation.invalid) {
1764
+ setInternalValidation({});
1765
+ field?.reportValidity(null);
1766
+ }
1767
+ }
1768
+ __name(handleChange, "handleChange");
1769
+ function handleBlur(event) {
1753
1770
  let finalValue = draft;
1754
- if (trimOnBlur) {
1771
+ if (trim) {
1755
1772
  const trimmed = draft.trim();
1756
1773
  if (trimmed !== draft) {
1757
- commitValue(trimmed, { immediate: true });
1774
+ commitValue(trimmed, {
1775
+ immediate: true
1776
+ });
1758
1777
  finalValue = trimmed;
1759
1778
  }
1760
1779
  }
1761
- runValidation(finalValue);
1762
- onBlurProp?.(e);
1780
+ if (validateOn === "blur" || validateOn === "both") {
1781
+ runValidation(finalValue);
1782
+ }
1783
+ onBlurProp?.(event);
1763
1784
  }
1764
1785
  __name(handleBlur, "handleBlur");
1765
1786
  function handleClear() {
1766
- commitValue("", { immediate: true });
1767
- internalRef.current?.focus();
1787
+ commitValue("", {
1788
+ immediate: true
1789
+ });
1768
1790
  setInternalValidation({});
1769
1791
  field?.reportValidity(null);
1792
+ internalRef.current?.focus();
1770
1793
  onClear?.();
1771
1794
  }
1772
1795
  __name(handleClear, "handleClear");
1773
1796
  useLayoutEffect(() => {
1774
1797
  if (!autoResize) return;
1775
- const el = internalRef.current;
1776
- if (!el) return;
1777
- const computed = window.getComputedStyle(el);
1798
+ const element = internalRef.current;
1799
+ if (!element) return;
1800
+ const computed = window.getComputedStyle(element);
1778
1801
  const lineHeight = parseFloat(computed.lineHeight) || parseFloat(computed.fontSize) * 1.2;
1779
1802
  const paddingY = parseFloat(computed.paddingTop) + parseFloat(computed.paddingBottom);
1780
1803
  const borderY = parseFloat(computed.borderTopWidth) + parseFloat(computed.borderBottomWidth);
1781
- const minHeight = minRows ? lineHeight * minRows + paddingY + borderY : void 0;
1782
- const maxHeight = maxRows ? lineHeight * maxRows + paddingY + borderY : void 0;
1783
- el.style.height = "auto";
1784
- let next = el.scrollHeight;
1785
- if (minHeight) next = Math.max(next, minHeight);
1786
- if (maxHeight) next = Math.min(next, maxHeight);
1787
- el.style.height = `${next}px`;
1788
- el.style.overflowY = maxHeight && el.scrollHeight > maxHeight ? "auto" : "hidden";
1804
+ const minHeight = minRows !== void 0 ? lineHeight * minRows + paddingY + borderY : void 0;
1805
+ const maxHeight = maxRows !== void 0 ? lineHeight * maxRows + paddingY + borderY : void 0;
1806
+ element.style.height = "auto";
1807
+ let nextHeight = element.scrollHeight;
1808
+ if (minHeight !== void 0) {
1809
+ nextHeight = Math.max(nextHeight, minHeight);
1810
+ }
1811
+ if (maxHeight !== void 0) {
1812
+ nextHeight = Math.min(nextHeight, maxHeight);
1813
+ }
1814
+ element.style.height = `${nextHeight}px`;
1815
+ element.style.overflowY = maxHeight !== void 0 && element.scrollHeight > maxHeight ? "auto" : "hidden";
1789
1816
  }, [autoResize, draft, minRows, maxRows]);
1790
- const hasValue = draft.length > 0;
1791
1817
  const showClear = clearable && hasValue && !disabled;
1792
1818
  const showCounter = characterCounter;
1793
- const nearLimit = maxLength ? draft.length >= maxLength * 0.9 : false;
1819
+ const nearLimit = hasMaxLength && draft.length >= Math.max(0, maxLength - 10);
1794
1820
  const needsBottomSpace = showClear || showCounter;
1795
1821
  const messageId = !field?.describedBy && (isInvalid || isSuccess) ? `${id}-message` : void 0;
1796
1822
  const counterId = showCounter ? `${id}-counter` : void 0;
1797
1823
  const describedBy = cn(field?.describedBy, messageId, counterId).trim() || void 0;
1798
- const wrapperClassName = cn(
1799
- resolveRecipe(theme.recipes.FormControl, {
1800
- variant,
1801
- state,
1802
- fullWidth,
1803
- disabled: !!disabled
1804
- }),
1805
- "items-start",
1806
- className
1807
- );
1808
- const { style: sizeStyle } = useSizeStyle(size, false, "textarea", {
1809
- includeHeight: false
1824
+ const wrapperClassName = resolveRecipe(theme.recipes.FormControl, {
1825
+ variant,
1826
+ state,
1827
+ fullWidth,
1828
+ disabled: !!disabled,
1829
+ embedded
1830
+ });
1831
+ const textareaClasses = resolveRecipe(theme.recipes.Textarea, {
1832
+ variant,
1833
+ resize,
1834
+ autoResize
1810
1835
  });
1811
- const textareaStyle = { ...sizeStyle };
1836
+ const textareaStyle = {
1837
+ ...typography,
1838
+ ...sizeStyle,
1839
+ ...customStyle
1840
+ };
1812
1841
  if (needsBottomSpace) {
1813
1842
  const existingBottom = sizeStyle.paddingBottom;
1814
1843
  textareaStyle.paddingBottom = existingBottom ? `calc(${existingBottom} + 1.25rem)` : "1.5rem";
1815
1844
  }
1816
- return /* @__PURE__ */ jsxs("div", { className: wrapperClassName, children: [
1845
+ const counterClassName = cn(
1846
+ "pointer-events-none absolute",
1847
+ "bottom-1.5 right-2.5",
1848
+ "font-mono text-[11px]",
1849
+ maxLengthExceeded ? "text-destructive" : hasReachedMaxLength ? "text-warning" : nearLimit ? "text-warning" : "text-text-muted"
1850
+ );
1851
+ return /* @__PURE__ */ jsxs("div", { className: cn(wrapperClassName, "items-start"), children: [
1817
1852
  /* @__PURE__ */ jsx(
1818
1853
  "textarea",
1819
1854
  {
@@ -1827,17 +1862,17 @@ var TextareaCore = forwardRef(
1827
1862
  rows: autoResize ? void 0 : rows ?? minRows,
1828
1863
  "aria-invalid": isInvalid || void 0,
1829
1864
  "aria-describedby": describedBy,
1865
+ "aria-required": required,
1866
+ required,
1830
1867
  style: textareaStyle,
1831
- className: cn(
1832
- textareaBase,
1833
- !autoResize && textareaResizeVariants[resize],
1834
- autoResize && "resize-none overflow-hidden"
1835
- ),
1868
+ className: cn(textareaClasses, "py-3", className),
1836
1869
  "data-size": size,
1837
1870
  "data-invalid": isInvalid || void 0,
1838
1871
  "data-success": isSuccess || void 0,
1872
+ "data-warning": isWarning || void 0,
1839
1873
  "data-disabled": disabled || void 0,
1840
1874
  "data-autoresize": autoResize || void 0,
1875
+ "data-maxlength-reached": hasReachedMaxLength || void 0,
1841
1876
  ...props
1842
1877
  }
1843
1878
  ),
@@ -1847,30 +1882,26 @@ var TextareaCore = forwardRef(
1847
1882
  type: "button",
1848
1883
  "aria-label": "Clear textarea",
1849
1884
  onClick: handleClear,
1850
- className: "absolute right-2 top-2 flex items-center justify-center text-text-muted transition-colors hover:text-text",
1851
- children: /* @__PURE__ */ jsx(X, { size: 14 })
1852
- }
1853
- ),
1854
- showCounter && /* @__PURE__ */ jsxs(
1855
- "div",
1856
- {
1857
- id: counterId,
1858
1885
  className: cn(
1859
- "pointer-events-none absolute bottom-1.5 right-2.5 font-mono text-[11px]",
1860
- nearLimit ? "text-danger" : "text-text-muted"
1886
+ "absolute right-2 top-2",
1887
+ "flex items-center justify-center",
1888
+ "text-text-muted",
1889
+ "transition-colors",
1890
+ "hover:text-text"
1861
1891
  ),
1862
- children: [
1863
- draft.length,
1864
- maxLength ? `/${maxLength}` : ""
1865
- ]
1892
+ children: /* @__PURE__ */ jsx(X, { size: 14 })
1866
1893
  }
1867
1894
  ),
1895
+ showCounter && /* @__PURE__ */ jsxs("div", { id: counterId, className: counterClassName, children: [
1896
+ draft.length,
1897
+ maxLength ? `/${maxLength}` : ""
1898
+ ] }),
1868
1899
  internalValidation.message && !field && /* @__PURE__ */ jsx(
1869
1900
  "p",
1870
1901
  {
1871
1902
  id: messageId,
1872
1903
  role: "alert",
1873
- className: "mt-1.5 px-0.5 text-xs text-danger",
1904
+ className: cn("mt-1.5 px-0.5", "text-xs text-destructive"),
1874
1905
  children: internalValidation.message
1875
1906
  }
1876
1907
  )
@@ -1962,29 +1993,6 @@ function insertLink(value, start, end) {
1962
1993
  return { value: next, selectionStart: urlStart, selectionEnd: urlStart + 3 };
1963
1994
  }
1964
1995
  __name(insertLink, "insertLink");
1965
-
1966
- // src/utils/env.ts
1967
- function readProcessEnv() {
1968
- try {
1969
- return typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
1970
- } catch {
1971
- return void 0;
1972
- }
1973
- }
1974
- __name(readProcessEnv, "readProcessEnv");
1975
- function readImportMetaEnv() {
1976
- try {
1977
- return typeof import.meta !== "undefined" ? import.meta.env?.MODE : void 0;
1978
- } catch {
1979
- return void 0;
1980
- }
1981
- }
1982
- __name(readImportMetaEnv, "readImportMetaEnv");
1983
- function isDev() {
1984
- const mode = readProcessEnv() ?? readImportMetaEnv();
1985
- return mode !== void 0 && mode !== "production";
1986
- }
1987
- __name(isDev, "isDev");
1988
1996
  var TOOLBAR = [
1989
1997
  {
1990
1998
  label: "Heading",
@@ -2025,6 +2033,13 @@ var MarkdownEditor = forwardRef(
2025
2033
  defaultValue,
2026
2034
  onValueChange,
2027
2035
  className,
2036
+ fullWidth,
2037
+ variant,
2038
+ success,
2039
+ error,
2040
+ warning,
2041
+ disabled,
2042
+ maxLength,
2028
2043
  ...textareaProps
2029
2044
  }, ref) => {
2030
2045
  const baseId = useId();
@@ -2033,8 +2048,22 @@ var MarkdownEditor = forwardRef(
2033
2048
  defaultTab
2034
2049
  );
2035
2050
  const tab = tabProp ?? uncontrolledTab;
2051
+ const { theme } = useTheme();
2052
+ const field = useOptionalFormField();
2053
+ const footerMessage = hint;
2036
2054
  const [draft, setDraft] = useState(() => valueProp ?? defaultValue ?? "");
2037
2055
  const value = valueProp ?? draft;
2056
+ const maxLengthReached = typeof maxLength === "number" && value.length >= maxLength;
2057
+ const state = error || maxLengthReached ? "error" : success ? "success" : warning ? "warning" : field?.status ?? "none";
2058
+ const editorClasses = cn(
2059
+ resolveRecipe(theme.recipes.MarkdownEditor, {
2060
+ variant,
2061
+ state,
2062
+ fullWidth,
2063
+ disabled: !!disabled
2064
+ }),
2065
+ className
2066
+ );
2038
2067
  function setTab(next) {
2039
2068
  if (tabProp === void 0) setUncontrolledTab(next);
2040
2069
  onTabChange?.(next);
@@ -2046,6 +2075,7 @@ var MarkdownEditor = forwardRef(
2046
2075
  }
2047
2076
  __name(commit, "commit");
2048
2077
  function runAction(action) {
2078
+ if (disabled) return;
2049
2079
  const el = textareaRef.current;
2050
2080
  if (!el) return;
2051
2081
  const { selectionStart, selectionEnd } = el;
@@ -2075,94 +2105,91 @@ var MarkdownEditor = forwardRef(
2075
2105
  );
2076
2106
  }
2077
2107
  }, [renderMarkdown]);
2078
- return /* @__PURE__ */ jsxs(
2079
- "div",
2080
- {
2081
- className: cn(
2082
- "rounded-(--kui-radii-md) border border-border",
2083
- className
2084
- ),
2085
- children: [
2086
- /* @__PURE__ */ jsxs(
2087
- "div",
2088
- {
2089
- role: "tablist",
2090
- "aria-label": "Markdown editor mode",
2091
- id: tablistId,
2092
- className: "flex items-center gap-4 border-b border-border px-3",
2093
- children: [
2094
- ["write", "preview"].map((t) => /* @__PURE__ */ jsx(
2095
- "button",
2096
- {
2097
- type: "button",
2098
- role: "tab",
2099
- id: `${baseId}-${t}-tab`,
2100
- "aria-selected": tab === t,
2101
- "aria-controls": t === "write" ? writePanelId : previewPanelId,
2102
- onClick: () => setTab(t),
2103
- className: cn(
2104
- "border-b-2 py-2.5 text-sm capitalize transition-colors",
2105
- tab === t ? "border-brand text-text" : "border-transparent text-text-muted hover:text-text"
2106
- ),
2107
- children: t
2108
- },
2109
- t
2110
- )),
2111
- tab === "write" && /* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-1 py-1.5", children: TOOLBAR.map(({ label, icon: Icon, action }) => /* @__PURE__ */ jsx(
2112
- "button",
2113
- {
2114
- type: "button",
2115
- "aria-label": label,
2116
- onClick: () => runAction(action),
2117
- className: "rounded-(--kui-radii-sm) p-1.5 text-text-muted transition-colors hover:bg-surface-raised hover:text-text",
2118
- children: /* @__PURE__ */ jsx(Icon, { size: 15 })
2119
- },
2120
- label
2121
- )) })
2122
- ]
2123
- }
2124
- ),
2125
- /* @__PURE__ */ jsx(
2126
- "div",
2108
+ return /* @__PURE__ */ jsxs("div", { className: editorClasses, children: [
2109
+ /* @__PURE__ */ jsxs(
2110
+ "div",
2111
+ {
2112
+ role: "tablist",
2113
+ "aria-label": "Markdown editor mode",
2114
+ id: tablistId,
2115
+ className: "flex items-center gap-4 border-b border-border px-3",
2116
+ children: [
2117
+ ["write", "preview"].map((t) => /* @__PURE__ */ jsx(
2118
+ "button",
2119
+ {
2120
+ type: "button",
2121
+ role: "tab",
2122
+ id: `${baseId}-${t}-tab`,
2123
+ "aria-selected": tab === t,
2124
+ "aria-controls": t === "write" ? writePanelId : previewPanelId,
2125
+ onClick: () => setTab(t),
2126
+ disabled,
2127
+ className: cn(
2128
+ "border-b-2 py-2.5 text-sm capitalize transition-colors",
2129
+ "disabled:pointer-events-none disabled:cursor-not-allowed",
2130
+ tab === t ? "border-brand text-text" : "border-transparent text-text-muted hover:text-text"
2131
+ ),
2132
+ children: t
2133
+ },
2134
+ t
2135
+ )),
2136
+ tab === "write" && /* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-1 py-1.5", children: TOOLBAR.map(({ label, icon: Icon, action }) => /* @__PURE__ */ jsx(
2137
+ "button",
2138
+ {
2139
+ type: "button",
2140
+ "aria-label": label,
2141
+ onClick: () => runAction(action),
2142
+ disabled,
2143
+ className: "rounded-(--kui-radii-sm) p-1.5 text-text-muted transition-colors hover:bg-surface-raised hover:text-text disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
2144
+ children: /* @__PURE__ */ jsx(Icon, { size: 15 })
2145
+ },
2146
+ label
2147
+ )) })
2148
+ ]
2149
+ }
2150
+ ),
2151
+ /* @__PURE__ */ jsx(
2152
+ "div",
2153
+ {
2154
+ id: writePanelId,
2155
+ role: "tabpanel",
2156
+ "aria-labelledby": `${baseId}-write-tab`,
2157
+ hidden: tab !== "write",
2158
+ children: /* @__PURE__ */ jsx(
2159
+ TextareaCore,
2127
2160
  {
2128
- id: writePanelId,
2129
- role: "tabpanel",
2130
- "aria-labelledby": `${baseId}-write-tab`,
2131
- hidden: tab !== "write",
2132
- children: /* @__PURE__ */ jsx(
2133
- TextareaCore,
2134
- {
2135
- ref: (node) => {
2136
- textareaRef.current = node;
2137
- if (typeof ref === "function") ref(node);
2138
- else if (ref)
2139
- ref.current = node;
2140
- },
2141
- value,
2142
- onValueChange: commit,
2143
- resize: "vertical",
2144
- variant: "ghost",
2145
- className: "rounded-none border-0",
2146
- ...textareaProps
2161
+ ref: (node) => {
2162
+ textareaRef.current = node;
2163
+ if (typeof ref === "function") {
2164
+ ref(node);
2165
+ } else if (ref) {
2166
+ ref.current = node;
2147
2167
  }
2148
- )
2149
- }
2150
- ),
2151
- /* @__PURE__ */ jsx(
2152
- "div",
2153
- {
2154
- id: previewPanelId,
2155
- role: "tabpanel",
2156
- "aria-labelledby": `${baseId}-preview-tab`,
2157
- hidden: tab !== "preview",
2158
- className: "min-h-32 p-3 text-sm text-text",
2159
- children: renderMarkdown ? renderedPreview : /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: "No renderMarkdown provided \u2014 showing raw text." })
2168
+ },
2169
+ value,
2170
+ onValueChange: commit,
2171
+ embedded: true,
2172
+ resize: "vertical",
2173
+ disabled,
2174
+ maxLength,
2175
+ ...textareaProps
2160
2176
  }
2161
- ),
2162
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 border-t border-border px-3 py-2 text-xs text-text-muted", children: hint })
2163
- ]
2164
- }
2165
- );
2177
+ )
2178
+ }
2179
+ ),
2180
+ /* @__PURE__ */ jsx(
2181
+ "div",
2182
+ {
2183
+ id: previewPanelId,
2184
+ role: "tabpanel",
2185
+ "aria-labelledby": `${baseId}-preview-tab`,
2186
+ hidden: tab !== "preview",
2187
+ className: "min-h-32 p-3 text-sm text-text",
2188
+ children: renderMarkdown ? renderedPreview : /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: "No renderMarkdown provided \u2014 showing raw text." })
2189
+ }
2190
+ ),
2191
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 border-t border-border px-3 py-2 text-xs z-1", children: footerMessage })
2192
+ ] });
2166
2193
  }
2167
2194
  );
2168
2195
  MarkdownEditor.displayName = "MarkdownEditor";
@@ -2175,60 +2202,6 @@ var Textarea = forwardRef(
2175
2202
  }
2176
2203
  );
2177
2204
  Textarea.displayName = "Textarea";
2178
- var checkboxBoxVariants = cva(
2179
- "flex shrink-0 items-center justify-center rounded-[calc(var(--kui-radii-md)-2px)] border transition-colors duration-[var(--kui-duration-fast)]",
2180
- {
2181
- variants: {
2182
- size: {
2183
- sm: "h-4 w-4",
2184
- md: "h-5 w-5",
2185
- lg: "h-6 w-6"
2186
- },
2187
- state: {
2188
- none: "",
2189
- error: "border-danger",
2190
- success: "border-success"
2191
- },
2192
- checked: {
2193
- true: "bg-brand border-brand text-brand-fg",
2194
- false: "border-border bg-transparent"
2195
- },
2196
- disabled: {
2197
- true: "cursor-not-allowed",
2198
- false: "cursor-pointer"
2199
- }
2200
- },
2201
- defaultVariants: {
2202
- size: "md",
2203
- state: "none",
2204
- checked: false,
2205
- disabled: false
2206
- },
2207
- compoundVariants: [
2208
- { checked: false, state: "error", class: "border-danger" },
2209
- { checked: false, state: "success", class: "border-success" }
2210
- ]
2211
- }
2212
- );
2213
- var checkboxIconSizes = {
2214
- sm: 10,
2215
- md: 12,
2216
- lg: 14
2217
- };
2218
- function DashIcon({ size }) {
2219
- return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
2220
- }
2221
- __name(DashIcon, "DashIcon");
2222
- function mergeRefs3(...refs) {
2223
- return (node) => {
2224
- refs.forEach((r) => {
2225
- if (!r) return;
2226
- if (typeof r === "function") r(node);
2227
- else r.current = node;
2228
- });
2229
- };
2230
- }
2231
- __name(mergeRefs3, "mergeRefs");
2232
2205
  var Checkbox = forwardRef(
2233
2206
  ({
2234
2207
  className,
@@ -2236,9 +2209,10 @@ var Checkbox = forwardRef(
2236
2209
  defaultChecked,
2237
2210
  onCheckedChange,
2238
2211
  indeterminate = false,
2239
- size = "md",
2212
+ size = "sm",
2240
2213
  error,
2241
2214
  success,
2215
+ status,
2242
2216
  disabled,
2243
2217
  label,
2244
2218
  description,
@@ -2249,97 +2223,136 @@ var Checkbox = forwardRef(
2249
2223
  }, ref) => {
2250
2224
  const autoId = useId();
2251
2225
  const field = useOptionalFormField();
2226
+ const { theme } = useTheme();
2252
2227
  const id = field?.id ?? externalId ?? autoId;
2253
- const internalRef = useRef(null);
2228
+ const inputRef = useRef(null);
2254
2229
  const [internalChecked, setInternalChecked] = useState(
2255
2230
  defaultChecked ?? false
2256
2231
  );
2257
- const checked = checkedProp !== void 0 ? checkedProp : internalChecked;
2232
+ const isControlled = checkedProp !== void 0;
2233
+ const checked = isControlled ? checkedProp : internalChecked;
2258
2234
  const hasWarned = useRef(false);
2259
2235
  useEffect(() => {
2260
- if (process.env?.NODE_ENV === "production") return;
2261
- if (hasWarned.current) return;
2236
+ if (!isDev() || hasWarned.current) return;
2262
2237
  if (label && field?.hasExternalLabel) {
2263
2238
  console.warn(
2264
- "[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. That renders two <label> elements pointing at the same input, which double-announces in screen readers. Use Checkbox's `label` prop instead of <FormField.Label> when the control is a checkbox."
2239
+ "[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. Checkbox owns its label. Use the Checkbox `label` prop instead of <FormField.Label>."
2265
2240
  );
2266
2241
  hasWarned.current = true;
2267
2242
  }
2268
2243
  }, [label, field?.hasExternalLabel]);
2269
2244
  useEffect(() => {
2270
- if (internalRef.current)
2271
- internalRef.current.indeterminate = indeterminate;
2245
+ if (inputRef.current) {
2246
+ inputRef.current.indeterminate = indeterminate;
2247
+ }
2272
2248
  }, [indeterminate]);
2273
2249
  const isInvalid = error ?? field?.invalid ?? false;
2274
2250
  const isSuccess = success ?? false;
2275
- const state = isInvalid ? "error" : isSuccess ? "success" : "none";
2276
- function handleChange(e) {
2277
- const next = e.target.checked;
2278
- if (checkedProp === void 0) setInternalChecked(next);
2279
- onCheckedChange?.(next);
2280
- onChangeProp?.(e);
2251
+ const state = status ? status : isInvalid ? "error" : isSuccess ? "success" : "none";
2252
+ const hasLabels = label || description;
2253
+ const {
2254
+ style: sizeStyle,
2255
+ iconSize,
2256
+ fontSize
2257
+ } = useSizeStyle(size, !hasLabels, "checkbox", {
2258
+ widthFromHeight: true,
2259
+ sizeOffset: "7px"
2260
+ });
2261
+ const checkboxClasses = resolveRecipe(theme.recipes.Checkbox, {
2262
+ state,
2263
+ checked: checked || indeterminate,
2264
+ disabled: !!disabled
2265
+ });
2266
+ const statusTransition = useStatusTransition(state);
2267
+ const descriptionId = description ? `${id}-description` : void 0;
2268
+ const describedBy = [field?.describedBy, descriptionId].filter(Boolean).join(" ") || void 0;
2269
+ function handleChange(event) {
2270
+ const nextChecked = event.target.checked;
2271
+ if (!isControlled) {
2272
+ setInternalChecked(nextChecked);
2273
+ }
2274
+ onCheckedChange?.(nextChecked);
2275
+ onChangeProp?.(event);
2281
2276
  }
2282
2277
  __name(handleChange, "handleChange");
2283
- const descriptionId = description ? `${id}-description` : void 0;
2284
- const describedBy = field?.describedBy ?? descriptionId;
2278
+ const wasInvalidRef = useRef(isInvalid);
2279
+ useEffect(() => {
2280
+ const justBecameInvalid = isInvalid && !wasInvalidRef.current;
2281
+ wasInvalidRef.current = isInvalid;
2282
+ if (!justBecameInvalid) {
2283
+ return;
2284
+ }
2285
+ inputRef.current?.scrollIntoView({
2286
+ behavior: "smooth",
2287
+ block: "center"
2288
+ });
2289
+ }, [isInvalid]);
2285
2290
  return /* @__PURE__ */ jsxs(
2286
2291
  "div",
2287
2292
  {
2288
2293
  className: cn(
2289
- "flex gap-2.5",
2294
+ "inline-flex items-start gap-2",
2290
2295
  disabled && "cursor-not-allowed opacity-50",
2291
2296
  className
2292
2297
  ),
2293
2298
  children: [
2294
- /* @__PURE__ */ jsxs("div", { className: "relative mt-0.5 inline-flex", children: [
2299
+ /* @__PURE__ */ jsxs("div", { className: "relative inline-flex shrink-0", children: [
2295
2300
  /* @__PURE__ */ jsx(
2296
2301
  "input",
2297
2302
  {
2298
- ref: mergeRefs3(internalRef, ref),
2299
- type: "checkbox",
2303
+ ...props,
2304
+ ref: mergeRefs(inputRef, ref),
2300
2305
  id,
2306
+ type: "checkbox",
2301
2307
  checked,
2302
2308
  disabled,
2303
2309
  required: required ?? field?.required,
2304
2310
  onChange: handleChange,
2305
2311
  "aria-invalid": isInvalid || void 0,
2306
2312
  "aria-describedby": describedBy,
2307
- className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
2308
2313
  "data-invalid": isInvalid || void 0,
2309
- ...props
2314
+ className: cn(
2315
+ "peer absolute inset-0 z-10 m-0 h-full w-full",
2316
+ "cursor-pointer opacity-0",
2317
+ "disabled:cursor-not-allowed"
2318
+ )
2310
2319
  }
2311
2320
  ),
2312
2321
  /* @__PURE__ */ jsx(
2313
- "div",
2322
+ "span",
2314
2323
  {
2315
2324
  "aria-hidden": "true",
2316
- className: cn(
2317
- checkboxBoxVariants({
2318
- size,
2319
- state,
2320
- checked: checked || indeterminate,
2321
- disabled: !!disabled
2322
- }),
2323
- "peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
2324
- ),
2325
- children: indeterminate ? /* @__PURE__ */ jsx(DashIcon, { size: checkboxIconSizes[size] }) : checked ? /* @__PURE__ */ jsx(Check, { size: checkboxIconSizes[size] }) : null
2325
+ className: checkboxClasses,
2326
+ style: sizeStyle,
2327
+ "data-state-transition": statusTransition,
2328
+ children: /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center shrink-0", children: indeterminate ? /* @__PURE__ */ jsx(Minus, { strokeWidth: 3, size: iconSize }) : checked ? /* @__PURE__ */ jsx(Check, { strokeWidth: 3, size: iconSize }) : null })
2326
2329
  }
2327
2330
  )
2328
2331
  ] }),
2329
- (label || description) && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
2330
- label && /* @__PURE__ */ jsx(
2331
- "label",
2332
- {
2333
- htmlFor: id,
2334
- className: cn(
2335
- "text-sm text-text",
2336
- !disabled && "cursor-pointer"
2337
- ),
2338
- children: label
2339
- }
2340
- ),
2341
- description && /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-xs text-text-muted", children: description })
2342
- ] })
2332
+ hasLabels && /* @__PURE__ */ jsxs(
2333
+ "label",
2334
+ {
2335
+ htmlFor: id,
2336
+ className: cn(
2337
+ "flex flex-col gap-px",
2338
+ !disabled && "cursor-pointer"
2339
+ ),
2340
+ children: [
2341
+ label && /* @__PURE__ */ jsx("span", { className: "text-text", style: { fontSize }, children: label }),
2342
+ description && /* @__PURE__ */ jsx(
2343
+ "span",
2344
+ {
2345
+ id: descriptionId,
2346
+ className: "text-text-muted",
2347
+ style: {
2348
+ fontSize: fontSize ? `calc(${fontSize} - 1px)` : void 0
2349
+ },
2350
+ children: description
2351
+ }
2352
+ )
2353
+ ]
2354
+ }
2355
+ )
2343
2356
  ]
2344
2357
  }
2345
2358
  );
@@ -2420,7 +2433,7 @@ var radioBubbleVariants = cva(
2420
2433
  },
2421
2434
  state: {
2422
2435
  none: "",
2423
- error: "border-danger",
2436
+ error: "border-destructive",
2424
2437
  success: "border-success"
2425
2438
  },
2426
2439
  checked: {
@@ -2432,9 +2445,14 @@ var radioBubbleVariants = cva(
2432
2445
  false: "cursor-pointer"
2433
2446
  }
2434
2447
  },
2435
- defaultVariants: { size: "md", state: "none", checked: false, disabled: false },
2448
+ defaultVariants: {
2449
+ size: "md",
2450
+ state: "none",
2451
+ checked: false,
2452
+ disabled: false
2453
+ },
2436
2454
  compoundVariants: [
2437
- { checked: false, state: "error", class: "border-danger" },
2455
+ { checked: false, state: "error", class: "border-destructive" },
2438
2456
  { checked: false, state: "success", class: "border-success" }
2439
2457
  ]
2440
2458
  }
@@ -2516,6 +2534,7 @@ var switchTrackVariants = cva(
2516
2534
  }
2517
2535
  );
2518
2536
  var switchThumbConfig = {
2537
+ xs: { thumb: "h-3 w-3", translate: "translate-x-3" },
2519
2538
  sm: { thumb: "h-3 w-3", translate: "translate-x-3" },
2520
2539
  md: { thumb: "h-4 w-4", translate: "translate-x-4" },
2521
2540
  lg: { thumb: "h-5 w-5", translate: "translate-x-5" }
@@ -2568,7 +2587,7 @@ function Switch({
2568
2587
  {
2569
2588
  "aria-hidden": "true",
2570
2589
  className: cn(
2571
- switchTrackVariants({ size, checked, disabled: !!disabled }),
2590
+ switchTrackVariants({ checked, disabled: !!disabled }),
2572
2591
  "peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
2573
2592
  ),
2574
2593
  children: /* @__PURE__ */ jsx(
@@ -2598,7 +2617,7 @@ function useComboboxContext(componentName) {
2598
2617
  return ctx;
2599
2618
  }
2600
2619
  __name(useComboboxContext, "useComboboxContext");
2601
- var inputBase2 = [
2620
+ var inputBase = [
2602
2621
  "flex",
2603
2622
  "items-center",
2604
2623
  "font-sans",
@@ -2621,7 +2640,7 @@ var inputWrapperVariants = cva(
2621
2640
  },
2622
2641
  state: {
2623
2642
  none: "focus-within:ring-2 focus-within:ring-brand/20",
2624
- error: "border-danger focus-within:ring-2 focus-within:ring-danger/20",
2643
+ error: "border-destructive focus-within:ring-2 focus-within:ring-destructive/20",
2625
2644
  success: "border-success focus-within:ring-2 focus-within:ring-success/20"
2626
2645
  },
2627
2646
  rounded: {
@@ -2652,6 +2671,7 @@ var inputWrapperVariants = cva(
2652
2671
  }
2653
2672
  );
2654
2673
  var inputSizeVariants = {
2674
+ xs: "h-8 px-2 text-xs",
2655
2675
  sm: "h-8 px-2 text-xs",
2656
2676
  md: "h-10 px-3 text-sm",
2657
2677
  lg: "h-12 px-4 text-base"
@@ -2757,7 +2777,7 @@ var ComboboxInput = forwardRef(
2757
2777
  onKeyDown: handleKeyDown,
2758
2778
  onBlur: handleBlur,
2759
2779
  "data-state": ctx.open ? "open" : "closed",
2760
- className: cn(inputBase2, "flex-1 border-0 bg-transparent outline-none", inputSizeVariants[size], "px-0")
2780
+ className: cn(inputBase, "flex-1 border-0 bg-transparent outline-none", inputSizeVariants[size], "px-0")
2761
2781
  }
2762
2782
  ),
2763
2783
  showClear && /* @__PURE__ */ jsx(
@@ -3102,7 +3122,7 @@ var MultiSelectTrigger = forwardRef(
3102
3122
  ref: ctx.triggerRef,
3103
3123
  className: cn(
3104
3124
  inputWrapperVariants({ variant: ctx.variant, state, fullWidth: true, disabled: ctx.disabled, rounded: ctx.rounded }),
3105
- multiSelectSizeVariants({ size: ctx.size }),
3125
+ multiSelectSizeVariants({}),
3106
3126
  "flex flex-wrap items-center gap-1",
3107
3127
  className
3108
3128
  ),
@@ -3132,7 +3152,7 @@ var MultiSelectTrigger = forwardRef(
3132
3152
  "span",
3133
3153
  {
3134
3154
  className: cn(
3135
- chipSizeVariants({ size: ctx.size }),
3155
+ chipSizeVariants({}),
3136
3156
  "bg-brand/15 text-brand"
3137
3157
  ),
3138
3158
  children: [
@@ -3372,15 +3392,235 @@ function MultiSelect({
3372
3392
  }),
3373
3393
  [value, toggleValue, removeValue, disabled, variant, size, open, triggerId, contentId, field?.invalid, field?.describedBy, field?.required, required, placeholder, maxVisibleChips, activeValue, registerItem, optionId, error, success, rounded, clearable, handleClear]
3374
3394
  );
3375
- return /* @__PURE__ */ jsx(MultiSelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
3376
- children,
3377
- name && value.map((v) => /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[]`, value: v, disabled }, v))
3378
- ] }) });
3395
+ return /* @__PURE__ */ jsx(MultiSelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
3396
+ children,
3397
+ name && value.map((v) => /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[]`, value: v, disabled }, v))
3398
+ ] }) });
3399
+ }
3400
+ __name(MultiSelect, "MultiSelect");
3401
+ MultiSelect.Trigger = MultiSelectTrigger;
3402
+ MultiSelect.Content = MultiSelectContent;
3403
+ MultiSelect.Item = MultiSelectItem;
3404
+ var InputField = forwardRef(
3405
+ ({
3406
+ id,
3407
+ label,
3408
+ description,
3409
+ message,
3410
+ required,
3411
+ optional,
3412
+ labelStart,
3413
+ labelEnd,
3414
+ labelClassName,
3415
+ status = "none",
3416
+ ...inputProps
3417
+ }, ref) => {
3418
+ const error = status === "error";
3419
+ const success = status === "success";
3420
+ const warning = status === "warning";
3421
+ return /* @__PURE__ */ jsxs(FormField, { id, message, required, children: [
3422
+ label && /* @__PURE__ */ jsxs(FormField.Label, { className: labelClassName, children: [
3423
+ labelStart,
3424
+ label,
3425
+ optional && /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: " (optional)" }),
3426
+ labelEnd
3427
+ ] }),
3428
+ /* @__PURE__ */ jsx(FormField.Control, { children: /* @__PURE__ */ jsx(
3429
+ Input,
3430
+ {
3431
+ ...inputProps,
3432
+ ref,
3433
+ id,
3434
+ error,
3435
+ success,
3436
+ warning,
3437
+ required
3438
+ }
3439
+ ) }),
3440
+ description && /* @__PURE__ */ jsx(FormField.Description, { children: description }),
3441
+ /* @__PURE__ */ jsx(FormField.Message, { children: message })
3442
+ ] });
3443
+ }
3444
+ );
3445
+ InputField.displayName = "InputField";
3446
+
3447
+ // src/provider/cssVariables.ts
3448
+ function toKebabCase(str) {
3449
+ return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
3450
+ }
3451
+ __name(toKebabCase, "toKebabCase");
3452
+ function colorToRgbChannels(value) {
3453
+ const trimmed = value.trim();
3454
+ const rgbMatch = trimmed.match(
3455
+ /^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i
3456
+ );
3457
+ if (rgbMatch) {
3458
+ return `${rgbMatch[1]} ${rgbMatch[2]} ${rgbMatch[3]}`;
3459
+ }
3460
+ if (trimmed.startsWith("#")) {
3461
+ const hex = trimmed.slice(1);
3462
+ if (hex.length === 3) {
3463
+ const r = parseInt(hex[0] + hex[0], 16);
3464
+ const g = parseInt(hex[1] + hex[1], 16);
3465
+ const b = parseInt(hex[2] + hex[2], 16);
3466
+ return `${r} ${g} ${b}`;
3467
+ }
3468
+ if (hex.length === 6) {
3469
+ const r = parseInt(hex.slice(0, 2), 16);
3470
+ const g = parseInt(hex.slice(2, 4), 16);
3471
+ const b = parseInt(hex.slice(4, 6), 16);
3472
+ return `${r} ${g} ${b}`;
3473
+ }
3474
+ }
3475
+ if (/^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(trimmed)) {
3476
+ return trimmed;
3477
+ }
3478
+ return value;
3479
+ }
3480
+ __name(colorToRgbChannels, "colorToRgbChannels");
3481
+ function getTokenValue(reference, tokens) {
3482
+ const path = reference.replace(/^\{/, "").replace(/\}$/, "").split(".");
3483
+ let current = tokens;
3484
+ for (const segment of path) {
3485
+ if (typeof current !== "object" || current === null || !(segment in current)) {
3486
+ return void 0;
3487
+ }
3488
+ current = current[segment];
3489
+ }
3490
+ if (typeof current === "object" && current !== null && "value" in current) {
3491
+ const value = current.value;
3492
+ if (typeof value === "string" || typeof value === "number") {
3493
+ return value;
3494
+ }
3495
+ }
3496
+ return void 0;
3497
+ }
3498
+ __name(getTokenValue, "getTokenValue");
3499
+ function resolveReference(reference, tokens, seen = /* @__PURE__ */ new Set()) {
3500
+ if (seen.has(reference)) {
3501
+ console.error(
3502
+ `[kreativ-ui] Circular token reference detected: ${reference}`
3503
+ );
3504
+ return void 0;
3505
+ }
3506
+ const nextSeen = new Set(seen);
3507
+ nextSeen.add(reference);
3508
+ const value = getTokenValue(reference, tokens);
3509
+ if (value === void 0) {
3510
+ console.warn(
3511
+ `[kreativ-ui] Unable to resolve token reference: ${reference}`
3512
+ );
3513
+ return void 0;
3514
+ }
3515
+ if (typeof value === "number") {
3516
+ return String(value);
3517
+ }
3518
+ if (value.startsWith("{") && value.endsWith("}")) {
3519
+ return resolveReference(value, tokens, nextSeen);
3520
+ }
3521
+ return value;
3522
+ }
3523
+ __name(resolveReference, "resolveReference");
3524
+ function resolveValue(value, tokens) {
3525
+ if (typeof value === "number") {
3526
+ return String(value);
3527
+ }
3528
+ if (typeof value !== "string") {
3529
+ return void 0;
3530
+ }
3531
+ if (value.startsWith("{") && value.endsWith("}")) {
3532
+ return resolveReference(value, tokens);
3533
+ }
3534
+ return value;
3535
+ }
3536
+ __name(resolveValue, "resolveValue");
3537
+ function flattenTokens(value, path, result, tokens) {
3538
+ if (typeof value !== "object" || value === null) {
3539
+ return;
3540
+ }
3541
+ if ("value" in value) {
3542
+ const tokenValue = value.value;
3543
+ const resolved = resolveValue(tokenValue, tokens);
3544
+ if (resolved !== void 0) {
3545
+ result[path.join(".")] = resolved;
3546
+ }
3547
+ return;
3548
+ }
3549
+ for (const [key, child] of Object.entries(value)) {
3550
+ flattenTokens(child, [...path, key], result, tokens);
3551
+ }
3552
+ }
3553
+ __name(flattenTokens, "flattenTokens");
3554
+ function resolveSemanticValue(value, mode, tokens) {
3555
+ if (typeof value === "object" && value !== null && "light" in value && "dark" in value) {
3556
+ const modeValue = value[mode];
3557
+ return resolveValue(modeValue, tokens);
3558
+ }
3559
+ return resolveValue(value, tokens);
3560
+ }
3561
+ __name(resolveSemanticValue, "resolveSemanticValue");
3562
+ function resolveSemanticTokens(semanticTokens, tokens, mode) {
3563
+ const result = {};
3564
+ function walk(value, path) {
3565
+ if (typeof value !== "object" || value === null) {
3566
+ return;
3567
+ }
3568
+ if ("value" in value) {
3569
+ const semanticValue = value.value;
3570
+ const resolved = resolveSemanticValue(semanticValue, mode, tokens);
3571
+ if (resolved !== void 0) {
3572
+ result[path.join(".")] = resolved;
3573
+ }
3574
+ return;
3575
+ }
3576
+ for (const [key, child] of Object.entries(
3577
+ value
3578
+ )) {
3579
+ walk(child, [...path, key]);
3580
+ }
3581
+ }
3582
+ __name(walk, "walk");
3583
+ walk(semanticTokens, []);
3584
+ return result;
3585
+ }
3586
+ __name(resolveSemanticTokens, "resolveSemanticTokens");
3587
+ function resolveTokens(tokens, semanticTokens, mode) {
3588
+ const primitiveTokens = {};
3589
+ flattenTokens(tokens, [], primitiveTokens, tokens);
3590
+ const resolvedSemanticTokens = resolveSemanticTokens(
3591
+ semanticTokens,
3592
+ tokens,
3593
+ mode
3594
+ );
3595
+ return {
3596
+ ...primitiveTokens,
3597
+ ...resolvedSemanticTokens
3598
+ };
3379
3599
  }
3380
- __name(MultiSelect, "MultiSelect");
3381
- MultiSelect.Trigger = MultiSelectTrigger;
3382
- MultiSelect.Content = MultiSelectContent;
3383
- MultiSelect.Item = MultiSelectItem;
3600
+ __name(resolveTokens, "resolveTokens");
3601
+ function tokensToCssVars(tokens, mode, intensity) {
3602
+ const cssVars = {};
3603
+ for (const [path, value] of Object.entries(tokens)) {
3604
+ const parts = path.split(".");
3605
+ const isSemanticColor = parts.length === 2 && parts[0] === "colors";
3606
+ const isPrimitiveColor = parts.length >= 3 && parts[0] === "colors";
3607
+ const varName = isSemanticColor ? `--kui-${toKebabCase(parts[1])}` : `--kui-${parts.map(toKebabCase).join("-")}`;
3608
+ const outputValue = isSemanticColor || isPrimitiveColor ? colorToRgbChannels(value) : value;
3609
+ cssVars[varName] = outputValue;
3610
+ }
3611
+ return {
3612
+ ...cssVars,
3613
+ "--kui-mode": mode,
3614
+ "--kui-intensity": String(intensity)
3615
+ };
3616
+ }
3617
+ __name(tokensToCssVars, "tokensToCssVars");
3618
+
3619
+ // src/theme/recipes/defineRecipe.ts
3620
+ function defineRecipe(recipe) {
3621
+ return recipe;
3622
+ }
3623
+ __name(defineRecipe, "defineRecipe");
3384
3624
 
3385
3625
  // src/theme/defaults/tokens.ts
3386
3626
  var defaultTokens = {
@@ -3528,17 +3768,38 @@ var defaultSemanticTokens = {
3528
3768
  }
3529
3769
  };
3530
3770
 
3771
+ // src/theme/typography/defineTypography.ts
3772
+ function defineTypography(typography) {
3773
+ return typography;
3774
+ }
3775
+ __name(defineTypography, "defineTypography");
3776
+
3777
+ // src/theme/typography/extendTypography.ts
3778
+ function extendTypography(override) {
3779
+ if (!override) {
3780
+ return { ...defaultTypography };
3781
+ }
3782
+ const result = { ...defaultTypography };
3783
+ for (const key of Object.keys(override)) {
3784
+ const variant = key;
3785
+ result[variant] = {
3786
+ ...defaultTypography[variant],
3787
+ ...override[variant]
3788
+ };
3789
+ }
3790
+ return result;
3791
+ }
3792
+ __name(extendTypography, "extendTypography");
3793
+
3531
3794
  // src/theme/defaults/typography.ts
3532
- var defaultTypography = {
3795
+ var defaultTypography = defineTypography({
3533
3796
  body: {
3534
3797
  fontFamily: "{fonts.body}",
3535
- fontSize: "{fontSizes.md}",
3536
3798
  fontWeight: "{fontWeights.normal}",
3537
3799
  lineHeight: "{lineHeights.normal}"
3538
3800
  },
3539
3801
  bodySmall: {
3540
3802
  fontFamily: "{fonts.body}",
3541
- fontSize: "{fontSizes.sm}",
3542
3803
  fontWeight: "{fontWeights.normal}",
3543
3804
  lineHeight: "{lineHeights.normal}"
3544
3805
  },
@@ -3554,22 +3815,290 @@ var defaultTypography = {
3554
3815
  fontWeight: "{fontWeights.semibold}",
3555
3816
  lineHeight: "{lineHeights.tight}"
3556
3817
  },
3818
+ label: {
3819
+ fontFamily: "{fonts.body}",
3820
+ fontWeight: "{fontWeights.medium}",
3821
+ lineHeight: "{lineHeights.normal}"
3822
+ },
3557
3823
  caption: {
3558
3824
  fontFamily: "{fonts.body}",
3559
3825
  fontSize: "{fontSizes.xs}",
3560
3826
  fontWeight: "{fontWeights.normal}",
3561
3827
  lineHeight: "{lineHeights.normal}"
3562
3828
  },
3563
- mono: {
3564
- fontFamily: "{fonts.mono}",
3565
- fontSize: "{fontSizes.xs}",
3566
- fontWeight: "{fontWeights.normal}",
3567
- lineHeight: "{lineHeights.normal}"
3829
+ mono: {
3830
+ fontFamily: "{fonts.mono}",
3831
+ fontSize: "{fontSizes.xs}",
3832
+ fontWeight: "{fontWeights.normal}",
3833
+ lineHeight: "{lineHeights.normal}"
3834
+ }
3835
+ });
3836
+
3837
+ // src/theme/defaults/recipes/button.ts
3838
+ var buttonBase = "inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none";
3839
+ var buttonVariants = {
3840
+ solid: "",
3841
+ outline: "border bg-transparent",
3842
+ ghost: "bg-transparent",
3843
+ soft: "",
3844
+ link: "bg-transparent p-0 h-auto hover:underline"
3845
+ };
3846
+ var buttonColors = {
3847
+ brand: {
3848
+ solid: "bg-brand text-brand-fg hover:bg-brand-hover",
3849
+ outline: "border-brand text-brand hover:bg-brand/10",
3850
+ ghost: "text-brand hover:bg-brand/10",
3851
+ soft: "bg-brand/10 text-brand hover:bg-brand/20",
3852
+ link: "text-brand"
3853
+ },
3854
+ destructive: {
3855
+ solid: "bg-destructive text-destructive-fg hover:bg-destructive-hover",
3856
+ outline: "border-destructive text-destructive hover:bg-destructive/10",
3857
+ ghost: "text-destructive hover:bg-destructive/10",
3858
+ soft: "bg-destructive/10 text-destructive hover:bg-destructive/20",
3859
+ link: "text-destructive"
3860
+ },
3861
+ success: {
3862
+ solid: "bg-success text-success-fg hover:bg-success-hover",
3863
+ outline: "border-success text-success hover:bg-success/10",
3864
+ ghost: "text-success hover:bg-success/10",
3865
+ soft: "bg-success/10 text-success hover:bg-success/20",
3866
+ link: "text-success"
3867
+ },
3868
+ warning: {
3869
+ solid: "bg-warning text-warning-fg hover:bg-warning-hover",
3870
+ outline: "border-warning text-warning hover:bg-warning/10",
3871
+ ghost: "text-warning hover:bg-warning/10",
3872
+ soft: "bg-warning/10 text-warning hover:bg-warning/20",
3873
+ link: "text-warning"
3874
+ },
3875
+ info: {
3876
+ solid: "bg-info text-info-fg hover:bg-info-hover",
3877
+ outline: "border-info text-info hover:bg-info/10",
3878
+ ghost: "text-info hover:bg-info/10",
3879
+ soft: "bg-info/10 text-info hover:bg-info/20",
3880
+ link: "text-info"
3881
+ },
3882
+ white: {
3883
+ solid: "bg-white text-black hover:bg-gray-50",
3884
+ outline: "border-white/30 text-white hover:bg-white/10",
3885
+ ghost: "text-white hover:bg-white/10",
3886
+ soft: "bg-white/10 text-white hover:bg-white/20",
3887
+ link: "text-white"
3888
+ },
3889
+ neutral: {
3890
+ solid: "bg-surface-raised text-text hover:bg-surface-sunken",
3891
+ outline: "border-border text-text hover:bg-surface-raised",
3892
+ ghost: "text-text hover:bg-surface-raised",
3893
+ soft: "bg-surface-raised text-text hover:bg-surface-sunken",
3894
+ link: "text-text"
3895
+ }
3896
+ };
3897
+ var buildCompoundVariants = /* @__PURE__ */ __name(() => {
3898
+ const compounds = [];
3899
+ for (const [color, variantMap] of Object.entries(buttonColors)) {
3900
+ for (const [variant, className] of Object.entries(variantMap)) {
3901
+ compounds.push({
3902
+ conditions: { color, variant },
3903
+ className
3904
+ });
3905
+ }
3906
+ }
3907
+ return compounds;
3908
+ }, "buildCompoundVariants");
3909
+ var buttonRecipe = defineRecipe({
3910
+ base: buttonBase,
3911
+ variants: {
3912
+ variant: buttonVariants,
3913
+ color: Object.fromEntries(
3914
+ Object.keys(buttonColors).map((color) => [color, ""])
3915
+ )
3916
+ },
3917
+ defaultVariants: {
3918
+ variant: "solid",
3919
+ color: "brand"
3920
+ },
3921
+ compoundVariants: buildCompoundVariants()
3922
+ });
3923
+
3924
+ // src/theme/defaults/recipes/formControl.ts
3925
+ var formControlBase = "group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-[border-color,box-shadow] duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-offset-2 focus-within:ring-offset-surface";
3926
+ var formControlVariants = {
3927
+ outline: "border border-border bg-transparent text-text",
3928
+ filled: "border border-transparent bg-surface-raised text-text",
3929
+ ghost: "border border-transparent bg-transparent text-text"
3930
+ };
3931
+ var standaloneStates = {
3932
+ none: "hover:border-brand focus-within:ring-2 focus-within:ring-brand/20",
3933
+ error: "border-destructive hover:border-destructive focus-within:ring-2 focus-within:ring-destructive/20",
3934
+ success: "border-success hover:border-success focus-within:ring-2 focus-within:ring-success/20",
3935
+ warning: "border-warning hover:border-warning focus-within:ring-2 focus-within:ring-warning/20"
3936
+ };
3937
+ var formControlRecipe = defineRecipe({
3938
+ base: formControlBase,
3939
+ variants: {
3940
+ variant: formControlVariants,
3941
+ embedded: {
3942
+ true: "rounded-none border-0 shadow-none hover:border-0 hover:bg-transparent focus-within:ring-0 focus-within:ring-offset-0",
3943
+ false: ""
3944
+ },
3945
+ state: standaloneStates,
3946
+ rounded: {
3947
+ true: "rounded-full",
3948
+ false: ""
3949
+ },
3950
+ fullWidth: {
3951
+ true: "w-full",
3952
+ false: ""
3953
+ },
3954
+ disabled: {
3955
+ true: "cursor-not-allowed opacity-50 border-border hover:border-border focus-within:ring-0",
3956
+ false: ""
3957
+ },
3958
+ hasAdornment: {
3959
+ true: "px-2",
3960
+ false: ""
3961
+ }
3962
+ },
3963
+ compoundVariants: [
3964
+ {
3965
+ conditions: { embedded: true, state: "none" },
3966
+ className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
3967
+ },
3968
+ {
3969
+ conditions: { embedded: true, state: "error" },
3970
+ className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
3971
+ },
3972
+ {
3973
+ conditions: { embedded: true, state: "success" },
3974
+ className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
3975
+ },
3976
+ {
3977
+ conditions: { embedded: true, state: "warning" },
3978
+ className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
3979
+ },
3980
+ {
3981
+ conditions: {
3982
+ disabled: true,
3983
+ state: "error"
3984
+ },
3985
+ className: "border-border hover:border-border focus-within:ring-0"
3986
+ },
3987
+ {
3988
+ conditions: {
3989
+ disabled: true,
3990
+ state: "success"
3991
+ },
3992
+ className: "border-border hover:border-border focus-within:ring-0"
3993
+ },
3994
+ {
3995
+ conditions: {
3996
+ disabled: true,
3997
+ state: "warning"
3998
+ },
3999
+ className: "border-border hover:border-border focus-within:ring-0"
4000
+ },
4001
+ {
4002
+ conditions: {
4003
+ embedded: true,
4004
+ disabled: true
4005
+ },
4006
+ className: "border-0! hover:border-0! focus-within:ring-0! cursor-default"
4007
+ }
4008
+ ],
4009
+ defaultVariants: {
4010
+ variant: "outline",
4011
+ state: "none",
4012
+ embedded: false,
4013
+ rounded: false,
4014
+ fullWidth: true,
4015
+ disabled: false,
4016
+ hasAdornment: false
4017
+ }
4018
+ });
4019
+
4020
+ // src/theme/defaults/recipes/input.ts
4021
+ var inputBase2 = "flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:cursor-not-allowed";
4022
+ var inputRecipe = defineRecipe({
4023
+ base: inputBase2,
4024
+ variants: {
4025
+ variant: {
4026
+ outline: "",
4027
+ filled: "",
4028
+ ghost: ""
4029
+ }
4030
+ },
4031
+ defaultVariants: {
4032
+ variant: "outline"
4033
+ }
4034
+ });
4035
+
4036
+ // src/theme/defaults/recipes/textarea.ts
4037
+ var textareaRecipe = defineRecipe({
4038
+ base: "flex w-full min-w-0 bg-transparent outline-none border-0 text-text placeholder:text-text-muted transition-colors duration-[var(--kui-duration-fast)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 kui-scrollbar",
4039
+ variants: {
4040
+ variant: {
4041
+ outline: "",
4042
+ filled: "",
4043
+ ghost: ""
4044
+ },
4045
+ resize: {
4046
+ none: "resize-none",
4047
+ both: "resize",
4048
+ horizontal: "resize-x",
4049
+ vertical: "resize-y"
4050
+ },
4051
+ autoResize: {
4052
+ true: "resize-none overflow-hidden",
4053
+ false: ""
4054
+ }
4055
+ },
4056
+ defaultVariants: {
4057
+ variant: "outline",
4058
+ resize: "vertical",
4059
+ autoResize: false
4060
+ }
4061
+ });
4062
+
4063
+ // src/theme/defaults/recipes/markdownEditor.ts
4064
+ var markdownEditorRecipe = defineRecipe({
4065
+ base: "group relative w-full overflow-hidden rounded-[var(--kui-radii-md)] transition-[border-color,box-shadow] duration-[var(--kui-duration-fast)]",
4066
+ variants: {
4067
+ variant: {
4068
+ outline: "border border-border bg-transparent",
4069
+ filled: "border border-transparent bg-surface-raised",
4070
+ ghost: "border border-transparent bg-transparent"
4071
+ },
4072
+ state: {
4073
+ none: "hover:border-brand focus-within:ring-2 focus-within:ring-brand/20",
4074
+ error: "border-destructive focus-within:ring-2 focus-within:ring-destructive/20",
4075
+ success: "border-success focus-within:ring-2 focus-within:ring-success/20",
4076
+ warning: "border-warning focus-within:ring-2 focus-within:ring-warning/20"
4077
+ },
4078
+ disabled: {
4079
+ true: "cursor-not-allowed opacity-50 border-border hover:border-border focus-within:ring-0",
4080
+ false: ""
4081
+ },
4082
+ fullWidth: {
4083
+ true: "w-full",
4084
+ false: ""
4085
+ }
4086
+ },
4087
+ defaultVariants: {
4088
+ variant: "outline",
4089
+ state: "none",
4090
+ fullWidth: true
3568
4091
  }
3569
- };
4092
+ });
3570
4093
 
3571
- // src/theme/defaults/theme.ts
3572
- var defaultSizes = {
4094
+ // src/theme/size/defineSize.ts
4095
+ function defineSizes(sizes) {
4096
+ return sizes;
4097
+ }
4098
+ __name(defineSizes, "defineSizes");
4099
+
4100
+ // src/theme/defaults/sizes.ts
4101
+ var defaultSizes = defineSizes({
3573
4102
  xs: {
3574
4103
  height: "1.75rem",
3575
4104
  paddingX: "0.5rem",
@@ -3595,18 +4124,77 @@ var defaultSizes = {
3595
4124
  radius: "1rem"
3596
4125
  },
3597
4126
  lg: {
3598
- height: "3rem",
4127
+ height: "3.5rem",
3599
4128
  paddingX: "1.5rem",
3600
4129
  fontSize: "1rem",
3601
4130
  gap: "0.625rem",
3602
4131
  iconSize: "1.25rem",
3603
4132
  radius: "1.15rem"
3604
4133
  }
3605
- };
4134
+ });
4135
+
4136
+ // src/theme/defaults/recipes/checkbox.ts
4137
+ var checkboxRecipe = defineRecipe({
4138
+ base: "relative inline-flex shrink-0 items-center justify-center border transition-colors duration-[var(--kui-duration-fast)] peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1",
4139
+ variants: {
4140
+ state: {
4141
+ none: "border-border",
4142
+ error: "border-destructive",
4143
+ success: "border-success",
4144
+ warning: "border-warning"
4145
+ },
4146
+ checked: {
4147
+ true: "border-brand bg-brand text-brand-fg",
4148
+ false: "bg-transparent"
4149
+ },
4150
+ disabled: {
4151
+ true: "cursor-not-allowed",
4152
+ false: "cursor-pointer"
4153
+ },
4154
+ rounded: {
4155
+ true: "rounded-full",
4156
+ false: "rounded-[calc(var(--kui-checkbox-radius)-4px)]"
4157
+ }
4158
+ },
4159
+ compoundVariants: [
4160
+ {
4161
+ conditions: {
4162
+ checked: false,
4163
+ state: "error"
4164
+ },
4165
+ className: "border-destructive"
4166
+ },
4167
+ {
4168
+ conditions: {
4169
+ checked: false,
4170
+ state: "success"
4171
+ },
4172
+ className: "border-success"
4173
+ },
4174
+ {
4175
+ conditions: {
4176
+ checked: false,
4177
+ state: "warning"
4178
+ },
4179
+ className: "border-warning"
4180
+ }
4181
+ ],
4182
+ defaultVariants: {
4183
+ state: "none",
4184
+ checked: false,
4185
+ disabled: false,
4186
+ rounded: false
4187
+ }
4188
+ });
4189
+
4190
+ // src/theme/defaults/theme.ts
3606
4191
  var defaultRecipes = {
3607
4192
  Button: buttonRecipe,
3608
4193
  FormControl: formControlRecipe,
3609
- Input: inputRecipe
4194
+ Input: inputRecipe,
4195
+ Textarea: textareaRecipe,
4196
+ MarkdownEditor: markdownEditorRecipe,
4197
+ Checkbox: checkboxRecipe
3610
4198
  };
3611
4199
  var defaultTheme = {
3612
4200
  tokens: defaultTokens,
@@ -3617,241 +4205,49 @@ var defaultTheme = {
3617
4205
  sizes: defaultSizes
3618
4206
  };
3619
4207
 
3620
- // src/provider/cssVariables.ts
3621
- function toKebabCase(str) {
3622
- return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
3623
- }
3624
- __name(toKebabCase, "toKebabCase");
3625
- function colorToRgbChannels(value) {
3626
- const trimmed = value.trim();
3627
- const rgbMatch = trimmed.match(
3628
- /^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i
3629
- );
3630
- if (rgbMatch) {
3631
- return `${rgbMatch[1]} ${rgbMatch[2]} ${rgbMatch[3]}`;
3632
- }
3633
- if (trimmed.startsWith("#")) {
3634
- const hex = trimmed.slice(1);
3635
- if (hex.length === 3) {
3636
- const r = parseInt(hex[0] + hex[0], 16);
3637
- const g = parseInt(hex[1] + hex[1], 16);
3638
- const b = parseInt(hex[2] + hex[2], 16);
3639
- return `${r} ${g} ${b}`;
3640
- }
3641
- if (hex.length === 6) {
3642
- const r = parseInt(hex.slice(0, 2), 16);
3643
- const g = parseInt(hex.slice(2, 4), 16);
3644
- const b = parseInt(hex.slice(4, 6), 16);
3645
- return `${r} ${g} ${b}`;
3646
- }
3647
- }
3648
- if (/^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(trimmed)) {
3649
- return trimmed;
3650
- }
3651
- return value;
3652
- }
3653
- __name(colorToRgbChannels, "colorToRgbChannels");
3654
- function getTokenValue(reference, tokens) {
3655
- const path = reference.replace(/^\{/, "").replace(/\}$/, "").split(".");
3656
- let current = tokens;
3657
- for (const segment of path) {
3658
- if (typeof current !== "object" || current === null || !(segment in current)) {
3659
- return void 0;
3660
- }
3661
- current = current[segment];
3662
- }
3663
- if (typeof current === "object" && current !== null && "value" in current) {
3664
- const value = current.value;
3665
- if (typeof value === "string" || typeof value === "number") {
3666
- return value;
3667
- }
3668
- }
3669
- return void 0;
3670
- }
3671
- __name(getTokenValue, "getTokenValue");
3672
- function resolveReference(reference, tokens, seen = /* @__PURE__ */ new Set()) {
3673
- if (seen.has(reference)) {
3674
- console.error(
3675
- `[kreativ-ui] Circular token reference detected: ${reference}`
3676
- );
3677
- return void 0;
3678
- }
3679
- const nextSeen = new Set(seen);
3680
- nextSeen.add(reference);
3681
- const value = getTokenValue(reference, tokens);
3682
- if (value === void 0) {
3683
- console.warn(
3684
- `[kreativ-ui] Unable to resolve token reference: ${reference}`
3685
- );
3686
- return void 0;
3687
- }
3688
- if (typeof value === "number") {
3689
- return String(value);
3690
- }
3691
- if (value.startsWith("{") && value.endsWith("}")) {
3692
- return resolveReference(value, tokens, nextSeen);
3693
- }
3694
- return value;
3695
- }
3696
- __name(resolveReference, "resolveReference");
3697
- function resolveValue(value, tokens) {
3698
- if (typeof value === "number") {
3699
- return String(value);
3700
- }
3701
- if (typeof value !== "string") {
3702
- return void 0;
3703
- }
3704
- if (value.startsWith("{") && value.endsWith("}")) {
3705
- return resolveReference(value, tokens);
3706
- }
3707
- return value;
3708
- }
3709
- __name(resolveValue, "resolveValue");
3710
- function flattenTokens(value, path, result, tokens) {
3711
- if (typeof value !== "object" || value === null) {
3712
- return;
3713
- }
3714
- if ("value" in value) {
3715
- const tokenValue = value.value;
3716
- const resolved = resolveValue(tokenValue, tokens);
3717
- if (resolved !== void 0) {
3718
- result[path.join(".")] = resolved;
3719
- }
3720
- return;
3721
- }
3722
- for (const [key, child] of Object.entries(value)) {
3723
- flattenTokens(child, [...path, key], result, tokens);
3724
- }
3725
- }
3726
- __name(flattenTokens, "flattenTokens");
3727
- function resolveSemanticValue(value, mode, tokens) {
3728
- if (typeof value === "object" && value !== null && "light" in value && "dark" in value) {
3729
- const modeValue = value[mode];
3730
- return resolveValue(modeValue, tokens);
4208
+ // src/theme/recipes/extendRecipe.ts
4209
+ function extendRecipes(override) {
4210
+ if (!override) {
4211
+ return defaultRecipes;
3731
4212
  }
3732
- return resolveValue(value, tokens);
3733
- }
3734
- __name(resolveSemanticValue, "resolveSemanticValue");
3735
- function resolveSemanticTokens(semanticTokens, tokens, mode) {
3736
- const result = {};
3737
- function walk(value, path) {
3738
- if (typeof value !== "object" || value === null) {
3739
- return;
3740
- }
3741
- if ("value" in value) {
3742
- const semanticValue = value.value;
3743
- const resolved = resolveSemanticValue(semanticValue, mode, tokens);
3744
- if (resolved !== void 0) {
3745
- result[path.join(".")] = resolved;
3746
- }
3747
- return;
3748
- }
3749
- for (const [key, child] of Object.entries(
3750
- value
3751
- )) {
3752
- walk(child, [...path, key]);
3753
- }
4213
+ const result = { ...defaultRecipes };
4214
+ for (const [name, recipeOverride] of Object.entries(override)) {
4215
+ const key = name;
4216
+ const base = defaultRecipes[key];
4217
+ result[key] = {
4218
+ ...base,
4219
+ ...recipeOverride,
4220
+ ...base?.compoundVariants || recipeOverride?.compoundVariants ? {
4221
+ compoundVariants: [
4222
+ ...base?.compoundVariants ?? [],
4223
+ ...recipeOverride?.compoundVariants ?? []
4224
+ ]
4225
+ } : {},
4226
+ ...base?.variants || recipeOverride?.variants ? {
4227
+ variants: {
4228
+ ...base?.variants,
4229
+ ...recipeOverride?.variants
4230
+ }
4231
+ } : {}
4232
+ };
3754
4233
  }
3755
- __name(walk, "walk");
3756
- walk(semanticTokens, []);
3757
4234
  return result;
3758
4235
  }
3759
- __name(resolveSemanticTokens, "resolveSemanticTokens");
3760
- function resolveTokens(tokens, semanticTokens, mode) {
3761
- const primitiveTokens = {};
3762
- flattenTokens(tokens, [], primitiveTokens, tokens);
3763
- const resolvedSemanticTokens = resolveSemanticTokens(
3764
- semanticTokens,
3765
- tokens,
3766
- mode
3767
- );
4236
+ __name(extendRecipes, "extendRecipes");
4237
+
4238
+ // src/theme/token/defineToken.ts
4239
+ function defineToken(value) {
3768
4240
  return {
3769
- ...primitiveTokens,
3770
- ...resolvedSemanticTokens
4241
+ value
3771
4242
  };
3772
4243
  }
3773
- __name(resolveTokens, "resolveTokens");
3774
- function tokensToCssVars(tokens, mode, intensity) {
3775
- const cssVars = {};
3776
- for (const [path, value] of Object.entries(tokens)) {
3777
- const parts = path.split(".");
3778
- const isSemanticColor = parts.length === 2 && parts[0] === "colors";
3779
- const isPrimitiveColor = parts.length >= 3 && parts[0] === "colors";
3780
- const varName = isSemanticColor ? `--kui-${toKebabCase(parts[1])}` : `--kui-${parts.map(toKebabCase).join("-")}`;
3781
- const outputValue = isSemanticColor || isPrimitiveColor ? colorToRgbChannels(value) : value;
3782
- cssVars[varName] = outputValue;
3783
- }
3784
- return {
3785
- ...cssVars,
3786
- "--kui-mode": mode,
3787
- "--kui-intensity": String(intensity)
3788
- };
4244
+ __name(defineToken, "defineToken");
4245
+ function defineSemanticToken(light, dark) {
4246
+ return { value: { light, dark } };
3789
4247
  }
3790
- __name(tokensToCssVars, "tokensToCssVars");
4248
+ __name(defineSemanticToken, "defineSemanticToken");
3791
4249
 
3792
- // src/theme/mergeTheme.ts
3793
- var CSS_SIZE = /^-?\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr)$|^(auto|min-content|max-content|fit-content)$/;
3794
- var CSS_KEYWORDS = /* @__PURE__ */ new Set([
3795
- "auto",
3796
- "min-content",
3797
- "max-content",
3798
- "fit-content"
3799
- ]);
3800
- var SIZE_FIELDS = [
3801
- "height",
3802
- "width",
3803
- "paddingX",
3804
- "paddingY",
3805
- "fontSize",
3806
- "gap",
3807
- "iconSize",
3808
- "radius"
3809
- ];
3810
- function isCssKeyword(value) {
3811
- return CSS_KEYWORDS.has(value);
3812
- }
3813
- __name(isCssKeyword, "isCssKeyword");
3814
- function toPx(value) {
3815
- if (isCssKeyword(value)) return void 0;
3816
- const num = parseFloat(value);
3817
- if (Number.isNaN(num)) return void 0;
3818
- if (value.endsWith("px")) return num;
3819
- if (value.endsWith("rem") || value.endsWith("em")) {
3820
- return num * 16;
3821
- }
3822
- return void 0;
3823
- }
3824
- __name(toPx, "toPx");
3825
- function validateSizeToken(key, token) {
3826
- SIZE_FIELDS.forEach((field) => {
3827
- const value = token[field];
3828
- if (value === void 0) return;
3829
- if (!CSS_SIZE.test(value)) {
3830
- console.error(
3831
- `[kreativ-ui] Invalid size "${key}.${field}": "${value}" is not a valid CSS size.`
3832
- );
3833
- return;
3834
- }
3835
- if (isCssKeyword(value)) return;
3836
- const num = parseFloat(value);
3837
- if (num < 0) {
3838
- console.error(
3839
- `[kreativ-ui] Invalid size "${key}.${field}": "${value}" is negative.`
3840
- );
3841
- }
3842
- });
3843
- if (token.height && token.fontSize) {
3844
- const heightPx = toPx(token.height);
3845
- const fontSizePx = toPx(token.fontSize);
3846
- if (heightPx !== void 0 && fontSizePx !== void 0 && fontSizePx >= heightPx) {
3847
- console.warn(
3848
- `[kreativ-ui] Size "${key}" has conflicting dimensions: height=${token.height} (${heightPx}px), fontSize=${token.fontSize} (${fontSizePx}px).
3849
- Font size meets or exceeds the box height \u2014 text may clip or overflow.`
3850
- );
3851
- }
3852
- }
3853
- }
3854
- __name(validateSizeToken, "validateSizeToken");
4250
+ // src/utils/deepMerge.ts
3855
4251
  function isPlainObject(value) {
3856
4252
  return typeof value === "object" && value !== null && !Array.isArray(value);
3857
4253
  }
@@ -3877,53 +4273,49 @@ function deepMerge(base, override) {
3877
4273
  return result;
3878
4274
  }
3879
4275
  __name(deepMerge, "deepMerge");
3880
- function mergeDesignTokens(base, override) {
3881
- return deepMerge(base, override);
3882
- }
3883
- __name(mergeDesignTokens, "mergeDesignTokens");
3884
- function mergeSemanticTokens(base, override) {
3885
- return deepMerge(base, override);
4276
+
4277
+ // src/theme/token/extendTokens.ts
4278
+ function extendTokens(override) {
4279
+ return deepMerge(defaultTokens, override);
3886
4280
  }
3887
- __name(mergeSemanticTokens, "mergeSemanticTokens");
3888
- function mergeTypography(base, override) {
3889
- return deepMerge(base, override);
4281
+ __name(extendTokens, "extendTokens");
4282
+ function extendSemanticTokens(override) {
4283
+ return deepMerge(defaultSemanticTokens, override);
3890
4284
  }
3891
- __name(mergeTypography, "mergeTypography");
3892
- function mergeSizes(base, override) {
4285
+ __name(extendSemanticTokens, "extendSemanticTokens");
4286
+
4287
+ // src/theme/size/extendSize.ts
4288
+ function extendSizes(override) {
4289
+ const result = {
4290
+ ...defaultSizes
4291
+ };
3893
4292
  if (!override) {
3894
- return base;
4293
+ return result;
3895
4294
  }
3896
- const merged = {
3897
- ...base
3898
- };
3899
- for (const [key, overrideToken] of Object.entries(override)) {
3900
- const next = {
3901
- ...merged[key],
3902
- ...overrideToken
4295
+ for (const [key, value] of Object.entries(override)) {
4296
+ result[key] = {
4297
+ ...defaultSizes[key] ?? {},
4298
+ ...value
3903
4299
  };
3904
- validateSizeToken(key, next);
3905
- merged[key] = next;
3906
4300
  }
3907
- return merged;
4301
+ return result;
3908
4302
  }
3909
- __name(mergeSizes, "mergeSizes");
3910
- function mergeTheme(base, override) {
4303
+ __name(extendSizes, "extendSizes");
4304
+
4305
+ // src/theme/extendTheme.ts
4306
+ function extendTheme(override) {
3911
4307
  if (!override) {
3912
- return base;
4308
+ return defaultTheme;
3913
4309
  }
3914
4310
  return {
3915
- tokens: mergeDesignTokens(base.tokens, override.tokens),
3916
- semanticTokens: mergeSemanticTokens(
3917
- base.semanticTokens,
3918
- override.semanticTokens
3919
- ),
3920
- typography: mergeTypography(base.typography, override.typography),
3921
- recipes: mergeRecipes(base.recipes, override.recipes),
3922
- intensity: override.intensity ?? base.intensity,
3923
- sizes: mergeSizes(base.sizes, override.sizes)
4311
+ ...defaultTheme,
4312
+ ...override,
4313
+ sizes: extendSizes(override.sizes),
4314
+ typography: extendTypography(override.typography),
4315
+ recipes: extendRecipes(override.recipes)
3924
4316
  };
3925
4317
  }
3926
- __name(mergeTheme, "mergeTheme");
4318
+ __name(extendTheme, "extendTheme");
3927
4319
  function useSystemPrefersDark() {
3928
4320
  const [prefersDark, setPrefersDark] = useState(false);
3929
4321
  useEffect(() => {
@@ -3950,10 +4342,7 @@ function UIProvider({
3950
4342
  const [mode, setMode] = useState(defaultMode);
3951
4343
  const systemPrefersDark = useSystemPrefersDark();
3952
4344
  const resolvedMode = mode === "system" ? systemPrefersDark ? "dark" : "light" : mode;
3953
- const theme = useMemo(
3954
- () => mergeTheme(defaultTheme, themeOverride),
3955
- [themeOverride]
3956
- );
4345
+ const theme = useMemo(() => extendTheme(themeOverride), [themeOverride]);
3957
4346
  const resolvedTokens = useMemo(
3958
4347
  () => resolveTokens(theme.tokens, theme.semanticTokens, resolvedMode),
3959
4348
  [theme.tokens, theme.semanticTokens, resolvedMode]
@@ -3993,6 +4382,6 @@ function UIProvider({
3993
4382
  }
3994
4383
  __name(UIProvider, "UIProvider");
3995
4384
 
3996
- export { Button, Checkbox, Combobox, ComboboxContent, ComboboxInput, ComboboxItem, FormField, FormFieldControl, FormFieldDescription, FormFieldLabel, FormFieldMessage, Input, MarkdownEditor, MultiSelect, MultiSelectContent, MultiSelectContext, MultiSelectItem, MultiSelectTrigger, Radio, RadioGroup, Select, SelectContent, SelectContext, SelectGroup, SelectGroupContext, SelectItem, SelectTrigger, SelectValue, Switch, Textarea, TextareaCore, ThemeContext, ThemeToggler, UIProvider, buttonBase, buttonColors, buttonRecipe, buttonVariants, cn, defaultRecipes, defaultSizes, defaultTheme, defineRecipe, defineSemanticToken, defineToken, defineTypography, formControlBase, formControlRecipe, formControlStates, formControlVariants, hexToRgbString, inputBase, inputKindDefaults, inputRecipe, mergeRecipes, resolveRecipe, resolveTypography, rgbToHex, tokensToCssVars, useBreakpoint, useFloatingSide, useMultiSelectContext, useSelectContext, useSizeStyle, useStateTransition, useTheme, useTypography };
4385
+ export { Button, Checkbox, Combobox, ComboboxContent, ComboboxInput, ComboboxItem, FormField, FormFieldControl, FormFieldDescription, FormFieldLabel, FormFieldMessage, Input, InputField, MarkdownEditor, MultiSelect, MultiSelectContent, MultiSelectItem, MultiSelectTrigger, Radio, RadioGroup, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, Switch, Textarea, ThemeContext, ThemeToggler, UIProvider, cn, defineRecipe, defineSemanticToken, defineToken, defineTypography, extendRecipes, extendSemanticTokens, extendTheme, extendTokens, extendTypography, hexToRgbString, rgbToHex, useBreakpoint, useClearableField, useFloatingSide, useSizeStyle, useStatusTransition, useTheme, useTypography };
3997
4386
  //# sourceMappingURL=index.js.map
3998
4387
  //# sourceMappingURL=index.js.map