@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.
@@ -637,25 +637,6 @@ function resolveColor(value, colors, isArbitrary) {
637
637
  }
638
638
  }
639
639
  }
640
- if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
641
- if (hex in colors) {
642
- const alias = colors[hex];
643
- if (typeof alias === "string") hex = alias;
644
- else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
645
- } else {
646
- const aliasLastDash = hex.lastIndexOf("-");
647
- if (aliasLastDash > 0) {
648
- const aliasColorName = hex.slice(0, aliasLastDash);
649
- const aliasShade = hex.slice(aliasLastDash + 1);
650
- const aliasScale = colors[aliasColorName];
651
- if (aliasScale && typeof aliasScale === "object") {
652
- hex = aliasScale[aliasShade] ?? null;
653
- } else if (typeof aliasScale === "string") {
654
- hex = aliasScale;
655
- }
656
- }
657
- }
658
- }
659
640
  if (!hex) return null;
660
641
  if (!opacityPart) {
661
642
  if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
@@ -671,6 +652,8 @@ function resolveColor(value, colors, isArbitrary) {
671
652
  alpha = parseFloat(opacityPart) / 100;
672
653
  }
673
654
  if (isNaN(alpha)) return hex;
655
+ if (alpha < 0) alpha = 0;
656
+ else if (alpha > 1) alpha = 1;
674
657
  return hexToRgba(hex, alpha);
675
658
  }
676
659
  function parseHexRgb(hex) {
@@ -2485,6 +2468,14 @@ function isKnownModifier(name) {
2485
2468
  }
2486
2469
 
2487
2470
  // src/core/parser.ts
2471
+ var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
2472
+ function isSafeArbitraryValue(value) {
2473
+ if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
2474
+ if (process.env.NODE_ENV !== "production") {
2475
+ kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
2476
+ }
2477
+ return false;
2478
+ }
2488
2479
  function parseClass(className) {
2489
2480
  const trimmed = className.trim();
2490
2481
  if (!trimmed) return null;
@@ -2523,6 +2514,7 @@ function parseClass(className) {
2523
2514
  if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
2524
2515
  const utility = remaining.slice(0, bracketStart - 1);
2525
2516
  const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
2517
+ if (!isSafeArbitraryValue(value)) return null;
2526
2518
  return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
2527
2519
  }
2528
2520
  if (remaining.endsWith("]") && bracketStart === -1) {
@@ -2532,6 +2524,7 @@ function parseClass(className) {
2532
2524
  }
2533
2525
  if (remaining.startsWith("[") && remaining.endsWith("]")) {
2534
2526
  const value = remaining.slice(1, -1).replace(/_/g, " ");
2527
+ if (!isSafeArbitraryValue(value)) return null;
2535
2528
  return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
2536
2529
  }
2537
2530
  if (getBuiltinStandaloneNames().has(remaining)) {
@@ -2667,17 +2660,20 @@ function setDefaultFontFamily(font) {
2667
2660
  globalThis[FONT_KEY] = font;
2668
2661
  }
2669
2662
  var _styleEl = null;
2663
+ var _ruleIndexByKey = /* @__PURE__ */ new Map();
2670
2664
  function evictInjectedRule(rule) {
2665
+ const idx = _ruleIndexByKey.get(rule);
2666
+ _ruleIndexByKey.delete(rule);
2667
+ if (idx === void 0) return;
2671
2668
  const sheet = _styleEl?.sheet;
2672
2669
  if (!sheet) return;
2673
- for (let i = 0; i < sheet.cssRules.length; i++) {
2674
- if (sheet.cssRules[i].cssText === rule) {
2675
- try {
2676
- sheet.deleteRule(i);
2677
- } catch {
2678
- }
2679
- return;
2680
- }
2670
+ try {
2671
+ sheet.deleteRule(idx);
2672
+ } catch {
2673
+ return;
2674
+ }
2675
+ for (const [key, i] of _ruleIndexByKey) {
2676
+ if (i > idx) _ruleIndexByKey.set(key, i - 1);
2681
2677
  }
2682
2678
  }
2683
2679
  var _injectedRules = new LRUCache(5e4, evictInjectedRule);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.6.15",
3
+ "version": "0.6.16",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",