@kbach/react-native 1.0.0-beta.11 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1095,6 +1095,36 @@ function lookupHex(theme, key) {
1095
1095
  const entry = theme.colors[key];
1096
1096
  return typeof entry === "string" ? entry : null;
1097
1097
  }
1098
+ function hexToRgb(hex) {
1099
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
1100
+ if (!m) return null;
1101
+ let h = m[1];
1102
+ if (h.length === 3) h = h.split("").map((c) => c + c).join("");
1103
+ const n = parseInt(h, 16);
1104
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
1105
+ }
1106
+ function splitOpacity(value) {
1107
+ const slash = value.lastIndexOf("/");
1108
+ if (slash === -1) return [value, null];
1109
+ const opacityText = value.slice(slash + 1);
1110
+ const n = Number(opacityText);
1111
+ if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
1112
+ return [value.slice(0, slash), n];
1113
+ }
1114
+ return [value, null];
1115
+ }
1116
+ function colorValue(theme, parsed) {
1117
+ const value = parsed.value;
1118
+ if (value === null) return null;
1119
+ if (parsed.isArbitrary) return value;
1120
+ const [name, opacity] = splitOpacity(value);
1121
+ const hex = lookupHex(theme, name);
1122
+ if (hex === null) return null;
1123
+ if (opacity === null) return hex;
1124
+ const rgb = hexToRgb(hex);
1125
+ if (rgb === null) return hex;
1126
+ return `rgba(${rgb.join(",")},${opacity / 100})`;
1127
+ }
1098
1128
 
1099
1129
  // src/jsEngine/resolvers/border.ts
1100
1130
  function radiusSize(key) {
@@ -1154,8 +1184,8 @@ function borderValue(theme, parsed) {
1154
1184
  if (value === "solid" || value === "dashed" || value === "dotted" || value === "double" || value === "hidden" || value === "none") {
1155
1185
  return [decl("border-style", value)];
1156
1186
  }
1157
- const hex = lookupHex(theme, value);
1158
- return hex === null ? null : [decl("border-color", hex)];
1187
+ const color = colorValue(theme, parsed);
1188
+ return color === null ? null : [decl("border-color", color)];
1159
1189
  }
1160
1190
  function borderSideValue(theme, parsed, sideProperty) {
1161
1191
  const value = parsed.value;
@@ -1168,8 +1198,8 @@ function borderSideValue(theme, parsed, sideProperty) {
1168
1198
  if (value === "solid" || value === "dashed" || value === "dotted" || value === "double" || value === "hidden" || value === "none") {
1169
1199
  return [decl(`${sideProperty}-style`, value)];
1170
1200
  }
1171
- const hex = lookupHex(theme, value);
1172
- return hex === null ? null : [decl(`${sideProperty}-color`, hex)];
1201
+ const color = colorValue(theme, parsed);
1202
+ return color === null ? null : [decl(`${sideProperty}-color`, color)];
1173
1203
  }
1174
1204
  function borderAxisValue(theme, parsed, sideA, sideB) {
1175
1205
  const value = parsed.value;
@@ -1182,8 +1212,8 @@ function borderAxisValue(theme, parsed, sideA, sideB) {
1182
1212
  if (value === "solid" || value === "dashed" || value === "dotted" || value === "double" || value === "hidden" || value === "none") {
1183
1213
  return [decl(`${sideA}-style`, value), decl(`${sideB}-style`, value)];
1184
1214
  }
1185
- const hex = lookupHex(theme, value);
1186
- return hex === null ? null : [decl(`${sideA}-color`, hex), decl(`${sideB}-color`, hex)];
1215
+ const color = colorValue(theme, parsed);
1216
+ return color === null ? null : [decl(`${sideA}-color`, color), decl(`${sideB}-color`, color)];
1187
1217
  }
1188
1218
  function radiusProperties(side) {
1189
1219
  switch (side) {
@@ -1245,8 +1275,8 @@ function outlineValue(theme, parsed) {
1245
1275
  const w = outlineWidthValue(value);
1246
1276
  if (w !== null) return [decl("outline-width", w)];
1247
1277
  if (OUTLINE_STYLES.includes(value)) return [decl("outline-style", value)];
1248
- const hex = lookupHex(theme, value);
1249
- return hex === null ? null : [decl("outline-color", hex)];
1278
+ const color = colorValue(theme, parsed);
1279
+ return color === null ? null : [decl("outline-color", color)];
1250
1280
  }
1251
1281
  function outlineOffsetValue(parsed) {
1252
1282
  const value = parsed.value;
@@ -1282,7 +1312,7 @@ function ringValue(theme, parsed) {
1282
1312
  const w = ringWidth(value);
1283
1313
  if (w !== null) return [decl("--kb-ring-width", w), decl("box-shadow", RING_BOX_SHADOW)];
1284
1314
  }
1285
- const color = parsed.isArbitrary ? value : lookupHex(theme, value);
1315
+ const color = colorValue(theme, parsed);
1286
1316
  if (color === null) return null;
1287
1317
  return [decl("--kb-ring-color", color), decl("box-shadow", RING_BOX_SHADOW)];
1288
1318
  }
@@ -1293,7 +1323,7 @@ function ringOffsetValue(theme, parsed) {
1293
1323
  const w = ringWidth(value);
1294
1324
  if (w !== null) return [decl("--kb-ring-offset-width", w), decl("box-shadow", RING_BOX_SHADOW)];
1295
1325
  }
1296
- const color = parsed.isArbitrary ? value : lookupHex(theme, value);
1326
+ const color = colorValue(theme, parsed);
1297
1327
  if (color === null) return null;
1298
1328
  return [decl("--kb-ring-offset-color", color), decl("box-shadow", RING_BOX_SHADOW)];
1299
1329
  }
@@ -1500,9 +1530,7 @@ function resolveLeadingTrackingNative(parsed) {
1500
1530
  return null;
1501
1531
  }
1502
1532
  function nativeHexColor(parsed, theme) {
1503
- const value = parsed.value;
1504
- if (value === null) return null;
1505
- return parsed.isArbitrary ? value : lookupHex(theme, value);
1533
+ return colorValue(theme, parsed);
1506
1534
  }
1507
1535
  function resolveTextNative(parsed, theme) {
1508
1536
  if (!parsed.isArbitrary && parsed.value !== null) {
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-TDWBXJH5.mjs";
8
8
  import {
9
9
  resolveStyle
10
- } from "./chunk-XHL653X2.mjs";
10
+ } from "./chunk-JMNJCPGK.mjs";
11
11
  import {
12
12
  getGlobalDarkMode,
13
13
  getGlobalThemeMode,