@kbach/react 0.6.15 → 0.6.16

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.
@@ -856,25 +856,6 @@ function resolveColor(value, colors, isArbitrary) {
856
856
  }
857
857
  }
858
858
  }
859
- if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
860
- if (hex in colors) {
861
- const alias = colors[hex];
862
- if (typeof alias === "string") hex = alias;
863
- else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
864
- } else {
865
- const aliasLastDash = hex.lastIndexOf("-");
866
- if (aliasLastDash > 0) {
867
- const aliasColorName = hex.slice(0, aliasLastDash);
868
- const aliasShade = hex.slice(aliasLastDash + 1);
869
- const aliasScale = colors[aliasColorName];
870
- if (aliasScale && typeof aliasScale === "object") {
871
- hex = aliasScale[aliasShade] ?? null;
872
- } else if (typeof aliasScale === "string") {
873
- hex = aliasScale;
874
- }
875
- }
876
- }
877
- }
878
859
  if (!hex) return null;
879
860
  if (!opacityPart) {
880
861
  if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
@@ -890,6 +871,8 @@ function resolveColor(value, colors, isArbitrary) {
890
871
  alpha = parseFloat(opacityPart) / 100;
891
872
  }
892
873
  if (isNaN(alpha)) return hex;
874
+ if (alpha < 0) alpha = 0;
875
+ else if (alpha > 1) alpha = 1;
893
876
  return hexToRgba(hex, alpha);
894
877
  }
895
878
  function parseHexRgb(hex) {
@@ -2587,6 +2570,14 @@ function getBuiltinStandaloneNames() {
2587
2570
  }
2588
2571
 
2589
2572
  // src/core/parser.ts
2573
+ var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
2574
+ function isSafeArbitraryValue(value) {
2575
+ if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
2576
+ if (process.env.NODE_ENV !== "production") {
2577
+ kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
2578
+ }
2579
+ return false;
2580
+ }
2590
2581
  function parseClass(className) {
2591
2582
  const trimmed = className.trim();
2592
2583
  if (!trimmed) return null;
@@ -2625,6 +2616,7 @@ function parseClass(className) {
2625
2616
  if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
2626
2617
  const utility = remaining.slice(0, bracketStart - 1);
2627
2618
  const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
2619
+ if (!isSafeArbitraryValue(value)) return null;
2628
2620
  return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
2629
2621
  }
2630
2622
  if (remaining.endsWith("]") && bracketStart === -1) {
@@ -2634,6 +2626,7 @@ function parseClass(className) {
2634
2626
  }
2635
2627
  if (remaining.startsWith("[") && remaining.endsWith("]")) {
2636
2628
  const value = remaining.slice(1, -1).replace(/_/g, " ");
2629
+ if (!isSafeArbitraryValue(value)) return null;
2637
2630
  return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
2638
2631
  }
2639
2632
  if (getBuiltinStandaloneNames().has(remaining)) {
@@ -2788,17 +2781,20 @@ function getDefaultFontFamily() {
2788
2781
  return globalThis[FONT_KEY];
2789
2782
  }
2790
2783
  var _styleEl = null;
2784
+ var _ruleIndexByKey = /* @__PURE__ */ new Map();
2791
2785
  function evictInjectedRule(rule) {
2786
+ const idx = _ruleIndexByKey.get(rule);
2787
+ _ruleIndexByKey.delete(rule);
2788
+ if (idx === void 0) return;
2792
2789
  const sheet = _styleEl?.sheet;
2793
2790
  if (!sheet) return;
2794
- for (let i = 0; i < sheet.cssRules.length; i++) {
2795
- if (sheet.cssRules[i].cssText === rule) {
2796
- try {
2797
- sheet.deleteRule(i);
2798
- } catch {
2799
- }
2800
- return;
2801
- }
2791
+ try {
2792
+ sheet.deleteRule(idx);
2793
+ } catch {
2794
+ return;
2795
+ }
2796
+ for (const [key, i] of _ruleIndexByKey) {
2797
+ if (i > idx) _ruleIndexByKey.set(key, i - 1);
2802
2798
  }
2803
2799
  }
2804
2800
  var _injectedRules = new LRUCache(5e4, evictInjectedRule);
@@ -2815,11 +2811,15 @@ function getStyleEl() {
2815
2811
  }
2816
2812
  function injectRule(rule) {
2817
2813
  if (isRuntimeCSSDisabled()) return;
2818
- if (_injectedRules.has(rule)) return;
2819
- _injectedRules.set(rule, true);
2814
+ if (_injectedRules.get(rule)) return;
2820
2815
  try {
2821
2816
  const sheet = getStyleEl().sheet;
2822
- if (sheet) sheet.insertRule(rule, sheet.cssRules.length);
2817
+ if (sheet) {
2818
+ const idx = sheet.cssRules.length;
2819
+ sheet.insertRule(rule, idx);
2820
+ _ruleIndexByKey.set(rule, idx);
2821
+ _injectedRules.set(rule, true);
2822
+ }
2823
2823
  } catch {
2824
2824
  }
2825
2825
  }
@@ -3295,17 +3295,19 @@ var useSyncExternalStore = import_react.default.useSyncExternalStore ?? function
3295
3295
  };
3296
3296
 
3297
3297
  // src/useGlobalDarkMode.ts
3298
- function useGlobalDarkMode() {
3298
+ var NOOP_SUB = (_) => () => {
3299
+ };
3300
+ var FALSE_SNAP = () => false;
3301
+ function useConditionalGlobalDarkMode(active) {
3299
3302
  return useSyncExternalStore(
3300
- subscribeGlobalDarkMode,
3301
- getGlobalDarkMode,
3302
- () => false
3303
- // SSR: default light
3303
+ active ? subscribeGlobalDarkMode : NOOP_SUB,
3304
+ active ? getGlobalDarkMode : FALSE_SNAP,
3305
+ FALSE_SNAP
3304
3306
  );
3305
3307
  }
3306
3308
 
3307
3309
  // src/useGlobalWidth.ts
3308
- var NOOP_SUB = (_) => () => {
3310
+ var NOOP_SUB2 = (_) => () => {
3309
3311
  };
3310
3312
  var ZERO_SNAP = () => 0;
3311
3313
  var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
@@ -3339,7 +3341,7 @@ function getWebWidth() {
3339
3341
  }
3340
3342
  function useConditionalWidth(active) {
3341
3343
  return useSyncExternalStore(
3342
- active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
3344
+ active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB2,
3343
3345
  active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
3344
3346
  ZERO_SNAP
3345
3347
  );
@@ -3412,27 +3414,48 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
3412
3414
  onBlur,
3413
3415
  ...rest
3414
3416
  }, ref) {
3415
- const isDark = useGlobalDarkMode();
3417
+ const isWebPlatform = getEffectiveIsWeb();
3418
+ const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
3416
3419
  const needsWidth = hasResponsiveBuckets(resolvedStyle);
3417
- const width = useConditionalWidth(needsWidth);
3420
+ const width = useConditionalWidth(needsWidth && !isWebPlatform);
3418
3421
  const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
3419
3422
  const [pressed, setPressed] = (0, import_react2.useState)(false);
3420
3423
  const [hovered, setHovered] = (0, import_react2.useState)(false);
3421
3424
  const [focused, setFocused] = (0, import_react2.useState)(false);
3422
- const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => setPressed(true)), [onPressIn]);
3423
- const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => setPressed(false)), [onPressOut]);
3424
- const handlePointerDown = (0, import_react2.useCallback)(chain(onPointerDown, () => setPressed(true)), [onPointerDown]);
3425
- const handlePointerUp = (0, import_react2.useCallback)(chain(onPointerUp, () => setPressed(false)), [onPointerUp]);
3426
- const handlePointerLeave = (0, import_react2.useCallback)(chain(onPointerLeave, () => setPressed(false)), [onPointerLeave]);
3427
- const handlePointerCancel = (0, import_react2.useCallback)(chain(onPointerCancel, () => setPressed(false)), [onPointerCancel]);
3428
- const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
3429
- const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
3430
- const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => setFocused(true)), [onFocus]);
3431
- const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
3425
+ const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => {
3426
+ if (!isWebPlatform) setPressed(true);
3427
+ }), [onPressIn, isWebPlatform]);
3428
+ const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => {
3429
+ if (!isWebPlatform) setPressed(false);
3430
+ }), [onPressOut, isWebPlatform]);
3431
+ const handlePointerDown = (0, import_react2.useCallback)(chain(onPointerDown, () => {
3432
+ if (!isWebPlatform) setPressed(true);
3433
+ }), [onPointerDown, isWebPlatform]);
3434
+ const handlePointerUp = (0, import_react2.useCallback)(chain(onPointerUp, () => {
3435
+ if (!isWebPlatform) setPressed(false);
3436
+ }), [onPointerUp, isWebPlatform]);
3437
+ const handlePointerLeave = (0, import_react2.useCallback)(chain(onPointerLeave, () => {
3438
+ if (!isWebPlatform) setPressed(false);
3439
+ }), [onPointerLeave, isWebPlatform]);
3440
+ const handlePointerCancel = (0, import_react2.useCallback)(chain(onPointerCancel, () => {
3441
+ if (!isWebPlatform) setPressed(false);
3442
+ }), [onPointerCancel, isWebPlatform]);
3443
+ const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => {
3444
+ if (!isWebPlatform) setHovered(true);
3445
+ }), [onMouseEnter, isWebPlatform]);
3446
+ const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => {
3447
+ if (!isWebPlatform) setHovered(false);
3448
+ }), [onMouseLeave, isWebPlatform]);
3449
+ const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => {
3450
+ if (!isWebPlatform) setFocused(true);
3451
+ }), [onFocus, isWebPlatform]);
3452
+ const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => {
3453
+ if (!isWebPlatform) setFocused(false);
3454
+ }), [onBlur, isWebPlatform]);
3432
3455
  const { children, disabled, checked, ...restForComponent } = rest;
3433
3456
  const computedStyle = (0, import_react2.useMemo)(
3434
3457
  () => {
3435
- if (isWeb) return {};
3458
+ if (isWebPlatform) return {};
3436
3459
  const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!disabled, checked: !!checked }, breakpoints);
3437
3460
  stripInternalMarkers(s);
3438
3461
  if (typeof Component !== "string") stripWebOnlyProps(s);
@@ -3440,7 +3463,7 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
3440
3463
  },
3441
3464
  [resolvedStyle, isDark, pressed, hovered, focused, width, disabled, checked]
3442
3465
  );
3443
- const skipComputedInline = isWeb || !isNative && typeof Component === "string";
3466
+ const skipComputedInline = isWebPlatform;
3444
3467
  const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
3445
3468
  const componentProps = {
3446
3469
  ref,
@@ -3482,20 +3505,21 @@ InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
3482
3505
  var import_react3 = __toESM(require("react"));
3483
3506
  var DarkWrapper = import_react3.default.forwardRef(
3484
3507
  function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
3485
- const isDark = useGlobalDarkMode();
3508
+ const isWebPlatform = getEffectiveIsWeb();
3509
+ const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
3486
3510
  const needsWidth = hasResponsiveBuckets(resolvedStyle);
3487
- const width = useConditionalWidth(needsWidth);
3511
+ const width = useConditionalWidth(needsWidth && !isWebPlatform);
3488
3512
  const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
3489
3513
  const screens = getGlobalScreens();
3490
3514
  const isNonStringComponent = typeof Component !== "string";
3491
3515
  const computedStyle = (0, import_react3.useMemo)(() => {
3492
- if (isWeb) return {};
3516
+ if (isWebPlatform) return {};
3493
3517
  const s = flatten(resolvedStyle, isDark, {}, breakpoints);
3494
3518
  stripInternalMarkers(s);
3495
3519
  if (isNonStringComponent) stripWebOnlyProps(s);
3496
3520
  return s;
3497
3521
  }, [resolvedStyle, isDark, width, screens, isNonStringComponent]);
3498
- const skipComputedInline = isWeb || !isNative && typeof Component === "string";
3522
+ const skipComputedInline = isWebPlatform;
3499
3523
  const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
3500
3524
  const props = { ref, ...rest, style: finalStyle };
3501
3525
  return Array.isArray(children) ? import_react3.default.createElement(Component, props, ...children) : import_react3.default.createElement(Component, props, children);
@@ -3832,7 +3856,7 @@ function makeElement(isStaticChildren, type, props, key) {
3832
3856
  }
3833
3857
  function processElement(type, rawProps, key, isStaticChildren) {
3834
3858
  if (type === null || typeof type === "symbol") return makeElement(isStaticChildren, type, rawProps ?? {}, key);
3835
- const webTag = isWeb ? getWebTag(type, rawProps ?? void 0) : null;
3859
+ const webTag = getEffectiveIsWeb() ? getWebTag(type, rawProps ?? void 0) : null;
3836
3860
  const effectiveType = webTag ?? type;
3837
3861
  const originalName = webTag ? type?.displayName ?? type?.name : void 0;
3838
3862
  if (!rawProps) return (0, import_jsx_runtime.jsx)(effectiveType, null, key);
@@ -3856,7 +3880,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
3856
3880
  }, key);
3857
3881
  }
3858
3882
  if (!classStr && !__kbachStyles) {
3859
- if (isWeb) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
3883
+ if (getEffectiveIsWeb()) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
3860
3884
  const defaultFont = getCachedDefaultFont();
3861
3885
  if (!defaultFont) return makeElement(isStaticChildren, effectiveType, workingProps, key);
3862
3886
  const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
@@ -3885,7 +3909,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
3885
3909
  ...passProps
3886
3910
  }, key);
3887
3911
  }
3888
- const skipComputedInline = isWeb || !isNative && typeof effectiveType === "string";
3912
+ const skipComputedInline = getEffectiveIsWeb();
3889
3913
  let finalStyle;
3890
3914
  if (!skipComputedInline) {
3891
3915
  const computedStyle = flatten(resolved, false);
@@ -3,8 +3,8 @@ import {
3
3
  Fragment,
4
4
  jsx,
5
5
  jsxs
6
- } from "./chunk-THJIAZ6E.mjs";
7
- import "./chunk-YH2IOSKT.mjs";
6
+ } from "./chunk-YUX2JPTM.mjs";
7
+ import "./chunk-GJSZUC6Q.mjs";
8
8
 
9
9
  // src/jsx-dev-runtime.tsx
10
10
  function jsxDEV(type, props, key, isStaticChildren, source, self) {
@@ -857,25 +857,6 @@ function resolveColor(value, colors, isArbitrary) {
857
857
  }
858
858
  }
859
859
  }
860
- if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
861
- if (hex in colors) {
862
- const alias = colors[hex];
863
- if (typeof alias === "string") hex = alias;
864
- else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
865
- } else {
866
- const aliasLastDash = hex.lastIndexOf("-");
867
- if (aliasLastDash > 0) {
868
- const aliasColorName = hex.slice(0, aliasLastDash);
869
- const aliasShade = hex.slice(aliasLastDash + 1);
870
- const aliasScale = colors[aliasColorName];
871
- if (aliasScale && typeof aliasScale === "object") {
872
- hex = aliasScale[aliasShade] ?? null;
873
- } else if (typeof aliasScale === "string") {
874
- hex = aliasScale;
875
- }
876
- }
877
- }
878
- }
879
860
  if (!hex) return null;
880
861
  if (!opacityPart) {
881
862
  if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
@@ -891,6 +872,8 @@ function resolveColor(value, colors, isArbitrary) {
891
872
  alpha = parseFloat(opacityPart) / 100;
892
873
  }
893
874
  if (isNaN(alpha)) return hex;
875
+ if (alpha < 0) alpha = 0;
876
+ else if (alpha > 1) alpha = 1;
894
877
  return hexToRgba(hex, alpha);
895
878
  }
896
879
  function parseHexRgb(hex) {
@@ -2588,6 +2571,14 @@ function getBuiltinStandaloneNames() {
2588
2571
  }
2589
2572
 
2590
2573
  // src/core/parser.ts
2574
+ var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
2575
+ function isSafeArbitraryValue(value) {
2576
+ if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
2577
+ if (process.env.NODE_ENV !== "production") {
2578
+ kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
2579
+ }
2580
+ return false;
2581
+ }
2591
2582
  function parseClass(className) {
2592
2583
  const trimmed = className.trim();
2593
2584
  if (!trimmed) return null;
@@ -2626,6 +2617,7 @@ function parseClass(className) {
2626
2617
  if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
2627
2618
  const utility = remaining.slice(0, bracketStart - 1);
2628
2619
  const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
2620
+ if (!isSafeArbitraryValue(value)) return null;
2629
2621
  return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
2630
2622
  }
2631
2623
  if (remaining.endsWith("]") && bracketStart === -1) {
@@ -2635,6 +2627,7 @@ function parseClass(className) {
2635
2627
  }
2636
2628
  if (remaining.startsWith("[") && remaining.endsWith("]")) {
2637
2629
  const value = remaining.slice(1, -1).replace(/_/g, " ");
2630
+ if (!isSafeArbitraryValue(value)) return null;
2638
2631
  return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
2639
2632
  }
2640
2633
  if (getBuiltinStandaloneNames().has(remaining)) {
@@ -2789,17 +2782,20 @@ function getDefaultFontFamily() {
2789
2782
  return globalThis[FONT_KEY];
2790
2783
  }
2791
2784
  var _styleEl = null;
2785
+ var _ruleIndexByKey = /* @__PURE__ */ new Map();
2792
2786
  function evictInjectedRule(rule) {
2787
+ const idx = _ruleIndexByKey.get(rule);
2788
+ _ruleIndexByKey.delete(rule);
2789
+ if (idx === void 0) return;
2793
2790
  const sheet = _styleEl?.sheet;
2794
2791
  if (!sheet) return;
2795
- for (let i = 0; i < sheet.cssRules.length; i++) {
2796
- if (sheet.cssRules[i].cssText === rule) {
2797
- try {
2798
- sheet.deleteRule(i);
2799
- } catch {
2800
- }
2801
- return;
2802
- }
2792
+ try {
2793
+ sheet.deleteRule(idx);
2794
+ } catch {
2795
+ return;
2796
+ }
2797
+ for (const [key, i] of _ruleIndexByKey) {
2798
+ if (i > idx) _ruleIndexByKey.set(key, i - 1);
2803
2799
  }
2804
2800
  }
2805
2801
  var _injectedRules = new LRUCache(5e4, evictInjectedRule);
@@ -2816,11 +2812,15 @@ function getStyleEl() {
2816
2812
  }
2817
2813
  function injectRule(rule) {
2818
2814
  if (isRuntimeCSSDisabled()) return;
2819
- if (_injectedRules.has(rule)) return;
2820
- _injectedRules.set(rule, true);
2815
+ if (_injectedRules.get(rule)) return;
2821
2816
  try {
2822
2817
  const sheet = getStyleEl().sheet;
2823
- if (sheet) sheet.insertRule(rule, sheet.cssRules.length);
2818
+ if (sheet) {
2819
+ const idx = sheet.cssRules.length;
2820
+ sheet.insertRule(rule, idx);
2821
+ _ruleIndexByKey.set(rule, idx);
2822
+ _injectedRules.set(rule, true);
2823
+ }
2824
2824
  } catch {
2825
2825
  }
2826
2826
  }
@@ -3296,17 +3296,19 @@ var useSyncExternalStore = import_react.default.useSyncExternalStore ?? function
3296
3296
  };
3297
3297
 
3298
3298
  // src/useGlobalDarkMode.ts
3299
- function useGlobalDarkMode() {
3299
+ var NOOP_SUB = (_) => () => {
3300
+ };
3301
+ var FALSE_SNAP = () => false;
3302
+ function useConditionalGlobalDarkMode(active) {
3300
3303
  return useSyncExternalStore(
3301
- subscribeGlobalDarkMode,
3302
- getGlobalDarkMode,
3303
- () => false
3304
- // SSR: default light
3304
+ active ? subscribeGlobalDarkMode : NOOP_SUB,
3305
+ active ? getGlobalDarkMode : FALSE_SNAP,
3306
+ FALSE_SNAP
3305
3307
  );
3306
3308
  }
3307
3309
 
3308
3310
  // src/useGlobalWidth.ts
3309
- var NOOP_SUB = (_) => () => {
3311
+ var NOOP_SUB2 = (_) => () => {
3310
3312
  };
3311
3313
  var ZERO_SNAP = () => 0;
3312
3314
  var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
@@ -3340,7 +3342,7 @@ function getWebWidth() {
3340
3342
  }
3341
3343
  function useConditionalWidth(active) {
3342
3344
  return useSyncExternalStore(
3343
- active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
3345
+ active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB2,
3344
3346
  active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
3345
3347
  ZERO_SNAP
3346
3348
  );
@@ -3413,27 +3415,48 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
3413
3415
  onBlur,
3414
3416
  ...rest
3415
3417
  }, ref) {
3416
- const isDark = useGlobalDarkMode();
3418
+ const isWebPlatform = getEffectiveIsWeb();
3419
+ const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
3417
3420
  const needsWidth = hasResponsiveBuckets(resolvedStyle);
3418
- const width = useConditionalWidth(needsWidth);
3421
+ const width = useConditionalWidth(needsWidth && !isWebPlatform);
3419
3422
  const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
3420
3423
  const [pressed, setPressed] = (0, import_react2.useState)(false);
3421
3424
  const [hovered, setHovered] = (0, import_react2.useState)(false);
3422
3425
  const [focused, setFocused] = (0, import_react2.useState)(false);
3423
- const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => setPressed(true)), [onPressIn]);
3424
- const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => setPressed(false)), [onPressOut]);
3425
- const handlePointerDown = (0, import_react2.useCallback)(chain(onPointerDown, () => setPressed(true)), [onPointerDown]);
3426
- const handlePointerUp = (0, import_react2.useCallback)(chain(onPointerUp, () => setPressed(false)), [onPointerUp]);
3427
- const handlePointerLeave = (0, import_react2.useCallback)(chain(onPointerLeave, () => setPressed(false)), [onPointerLeave]);
3428
- const handlePointerCancel = (0, import_react2.useCallback)(chain(onPointerCancel, () => setPressed(false)), [onPointerCancel]);
3429
- const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
3430
- const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
3431
- const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => setFocused(true)), [onFocus]);
3432
- const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
3426
+ const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => {
3427
+ if (!isWebPlatform) setPressed(true);
3428
+ }), [onPressIn, isWebPlatform]);
3429
+ const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => {
3430
+ if (!isWebPlatform) setPressed(false);
3431
+ }), [onPressOut, isWebPlatform]);
3432
+ const handlePointerDown = (0, import_react2.useCallback)(chain(onPointerDown, () => {
3433
+ if (!isWebPlatform) setPressed(true);
3434
+ }), [onPointerDown, isWebPlatform]);
3435
+ const handlePointerUp = (0, import_react2.useCallback)(chain(onPointerUp, () => {
3436
+ if (!isWebPlatform) setPressed(false);
3437
+ }), [onPointerUp, isWebPlatform]);
3438
+ const handlePointerLeave = (0, import_react2.useCallback)(chain(onPointerLeave, () => {
3439
+ if (!isWebPlatform) setPressed(false);
3440
+ }), [onPointerLeave, isWebPlatform]);
3441
+ const handlePointerCancel = (0, import_react2.useCallback)(chain(onPointerCancel, () => {
3442
+ if (!isWebPlatform) setPressed(false);
3443
+ }), [onPointerCancel, isWebPlatform]);
3444
+ const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => {
3445
+ if (!isWebPlatform) setHovered(true);
3446
+ }), [onMouseEnter, isWebPlatform]);
3447
+ const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => {
3448
+ if (!isWebPlatform) setHovered(false);
3449
+ }), [onMouseLeave, isWebPlatform]);
3450
+ const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => {
3451
+ if (!isWebPlatform) setFocused(true);
3452
+ }), [onFocus, isWebPlatform]);
3453
+ const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => {
3454
+ if (!isWebPlatform) setFocused(false);
3455
+ }), [onBlur, isWebPlatform]);
3433
3456
  const { children, disabled, checked, ...restForComponent } = rest;
3434
3457
  const computedStyle = (0, import_react2.useMemo)(
3435
3458
  () => {
3436
- if (isWeb) return {};
3459
+ if (isWebPlatform) return {};
3437
3460
  const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!disabled, checked: !!checked }, breakpoints);
3438
3461
  stripInternalMarkers(s);
3439
3462
  if (typeof Component !== "string") stripWebOnlyProps(s);
@@ -3441,7 +3464,7 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
3441
3464
  },
3442
3465
  [resolvedStyle, isDark, pressed, hovered, focused, width, disabled, checked]
3443
3466
  );
3444
- const skipComputedInline = isWeb || !isNative && typeof Component === "string";
3467
+ const skipComputedInline = isWebPlatform;
3445
3468
  const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
3446
3469
  const componentProps = {
3447
3470
  ref,
@@ -3483,20 +3506,21 @@ InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
3483
3506
  var import_react3 = __toESM(require("react"));
3484
3507
  var DarkWrapper = import_react3.default.forwardRef(
3485
3508
  function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
3486
- const isDark = useGlobalDarkMode();
3509
+ const isWebPlatform = getEffectiveIsWeb();
3510
+ const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
3487
3511
  const needsWidth = hasResponsiveBuckets(resolvedStyle);
3488
- const width = useConditionalWidth(needsWidth);
3512
+ const width = useConditionalWidth(needsWidth && !isWebPlatform);
3489
3513
  const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
3490
3514
  const screens = getGlobalScreens();
3491
3515
  const isNonStringComponent = typeof Component !== "string";
3492
3516
  const computedStyle = (0, import_react3.useMemo)(() => {
3493
- if (isWeb) return {};
3517
+ if (isWebPlatform) return {};
3494
3518
  const s = flatten(resolvedStyle, isDark, {}, breakpoints);
3495
3519
  stripInternalMarkers(s);
3496
3520
  if (isNonStringComponent) stripWebOnlyProps(s);
3497
3521
  return s;
3498
3522
  }, [resolvedStyle, isDark, width, screens, isNonStringComponent]);
3499
- const skipComputedInline = isWeb || !isNative && typeof Component === "string";
3523
+ const skipComputedInline = isWebPlatform;
3500
3524
  const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
3501
3525
  const props = { ref, ...rest, style: finalStyle };
3502
3526
  return Array.isArray(children) ? import_react3.default.createElement(Component, props, ...children) : import_react3.default.createElement(Component, props, children);
@@ -3838,7 +3862,7 @@ function makeElement(isStaticChildren, type, props, key) {
3838
3862
  }
3839
3863
  function processElement(type, rawProps, key, isStaticChildren) {
3840
3864
  if (type === null || typeof type === "symbol") return makeElement(isStaticChildren, type, rawProps ?? {}, key);
3841
- const webTag = isWeb ? getWebTag(type, rawProps ?? void 0) : null;
3865
+ const webTag = getEffectiveIsWeb() ? getWebTag(type, rawProps ?? void 0) : null;
3842
3866
  const effectiveType = webTag ?? type;
3843
3867
  const originalName = webTag ? type?.displayName ?? type?.name : void 0;
3844
3868
  if (!rawProps) return (0, import_jsx_runtime.jsx)(effectiveType, null, key);
@@ -3862,7 +3886,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
3862
3886
  }, key);
3863
3887
  }
3864
3888
  if (!classStr && !__kbachStyles) {
3865
- if (isWeb) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
3889
+ if (getEffectiveIsWeb()) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
3866
3890
  const defaultFont = getCachedDefaultFont();
3867
3891
  if (!defaultFont) return makeElement(isStaticChildren, effectiveType, workingProps, key);
3868
3892
  const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
@@ -3891,7 +3915,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
3891
3915
  ...passProps
3892
3916
  }, key);
3893
3917
  }
3894
- const skipComputedInline = isWeb || !isNative && typeof effectiveType === "string";
3918
+ const skipComputedInline = getEffectiveIsWeb();
3895
3919
  let finalStyle;
3896
3920
  if (!skipComputedInline) {
3897
3921
  const computedStyle = flatten(resolved, false);
@@ -4,10 +4,10 @@ import {
4
4
  _invalidateDefaultFontCache,
5
5
  jsx,
6
6
  jsxs
7
- } from "./chunk-THJIAZ6E.mjs";
7
+ } from "./chunk-YUX2JPTM.mjs";
8
8
  import {
9
9
  registerWebElement
10
- } from "./chunk-YH2IOSKT.mjs";
10
+ } from "./chunk-GJSZUC6Q.mjs";
11
11
  export {
12
12
  Fragment,
13
13
  _invalidateDefaultFontCache,
@@ -671,25 +671,6 @@ function resolveColor(value, colors, isArbitrary) {
671
671
  }
672
672
  }
673
673
  }
674
- if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
675
- if (hex in colors) {
676
- const alias = colors[hex];
677
- if (typeof alias === "string") hex = alias;
678
- else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
679
- } else {
680
- const aliasLastDash = hex.lastIndexOf("-");
681
- if (aliasLastDash > 0) {
682
- const aliasColorName = hex.slice(0, aliasLastDash);
683
- const aliasShade = hex.slice(aliasLastDash + 1);
684
- const aliasScale = colors[aliasColorName];
685
- if (aliasScale && typeof aliasScale === "object") {
686
- hex = aliasScale[aliasShade] ?? null;
687
- } else if (typeof aliasScale === "string") {
688
- hex = aliasScale;
689
- }
690
- }
691
- }
692
- }
693
674
  if (!hex) return null;
694
675
  if (!opacityPart) {
695
676
  if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
@@ -705,6 +686,8 @@ function resolveColor(value, colors, isArbitrary) {
705
686
  alpha = parseFloat(opacityPart) / 100;
706
687
  }
707
688
  if (isNaN(alpha)) return hex;
689
+ if (alpha < 0) alpha = 0;
690
+ else if (alpha > 1) alpha = 1;
708
691
  return hexToRgba(hex, alpha);
709
692
  }
710
693
  function parseHexRgb(hex) {
@@ -2519,6 +2502,14 @@ function isKnownModifier(name) {
2519
2502
  }
2520
2503
 
2521
2504
  // src/core/parser.ts
2505
+ var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
2506
+ function isSafeArbitraryValue(value) {
2507
+ if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
2508
+ if (process.env.NODE_ENV !== "production") {
2509
+ kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
2510
+ }
2511
+ return false;
2512
+ }
2522
2513
  function parseClass(className) {
2523
2514
  const trimmed = className.trim();
2524
2515
  if (!trimmed) return null;
@@ -2557,6 +2548,7 @@ function parseClass(className) {
2557
2548
  if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
2558
2549
  const utility = remaining.slice(0, bracketStart - 1);
2559
2550
  const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
2551
+ if (!isSafeArbitraryValue(value)) return null;
2560
2552
  return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
2561
2553
  }
2562
2554
  if (remaining.endsWith("]") && bracketStart === -1) {
@@ -2566,6 +2558,7 @@ function parseClass(className) {
2566
2558
  }
2567
2559
  if (remaining.startsWith("[") && remaining.endsWith("]")) {
2568
2560
  const value = remaining.slice(1, -1).replace(/_/g, " ");
2561
+ if (!isSafeArbitraryValue(value)) return null;
2569
2562
  return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
2570
2563
  }
2571
2564
  if (getBuiltinStandaloneNames().has(remaining)) {
@@ -2701,17 +2694,20 @@ function setDefaultFontFamily(font) {
2701
2694
  globalThis[FONT_KEY] = font;
2702
2695
  }
2703
2696
  var _styleEl = null;
2697
+ var _ruleIndexByKey = /* @__PURE__ */ new Map();
2704
2698
  function evictInjectedRule(rule) {
2699
+ const idx = _ruleIndexByKey.get(rule);
2700
+ _ruleIndexByKey.delete(rule);
2701
+ if (idx === void 0) return;
2705
2702
  const sheet = _styleEl?.sheet;
2706
2703
  if (!sheet) return;
2707
- for (let i = 0; i < sheet.cssRules.length; i++) {
2708
- if (sheet.cssRules[i].cssText === rule) {
2709
- try {
2710
- sheet.deleteRule(i);
2711
- } catch {
2712
- }
2713
- return;
2714
- }
2704
+ try {
2705
+ sheet.deleteRule(idx);
2706
+ } catch {
2707
+ return;
2708
+ }
2709
+ for (const [key, i] of _ruleIndexByKey) {
2710
+ if (i > idx) _ruleIndexByKey.set(key, i - 1);
2715
2711
  }
2716
2712
  }
2717
2713
  var _injectedRules = new LRUCache(5e4, evictInjectedRule);