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