@kbach/react-native 1.0.0-beta.30 → 1.0.0-beta.32

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
@@ -223,6 +223,63 @@ var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
223
223
  function isSafeArbitraryValue(value) {
224
224
  return !value.includes("{") && !value.includes("}") && !value.includes(";");
225
225
  }
226
+ function normalizeMathWhitespace(raw) {
227
+ if (!(raw.startsWith("calc(") || raw.startsWith("min(") || raw.startsWith("max(") || raw.startsWith("clamp("))) {
228
+ return raw;
229
+ }
230
+ const chars = Array.from(raw);
231
+ let out = "";
232
+ let i = 0;
233
+ let prevEndsValue = false;
234
+ while (i < chars.length) {
235
+ const c = chars[i];
236
+ if (c === "v" && chars[i + 1] === "a" && chars[i + 2] === "r" && chars[i + 3] === "(") {
237
+ const start = i;
238
+ let depth = 0;
239
+ while (i < chars.length) {
240
+ if (chars[i] === "(") depth++;
241
+ else if (chars[i] === ")") {
242
+ depth--;
243
+ if (depth === 0) {
244
+ i++;
245
+ break;
246
+ }
247
+ }
248
+ i++;
249
+ }
250
+ out += chars.slice(start, i).join("");
251
+ prevEndsValue = true;
252
+ continue;
253
+ }
254
+ if (c === "+" || c === "-") {
255
+ if (prevEndsValue) {
256
+ out += ` ${c} `;
257
+ i++;
258
+ while (i < chars.length && /\s/.test(chars[i])) i++;
259
+ prevEndsValue = false;
260
+ continue;
261
+ }
262
+ out += c;
263
+ prevEndsValue = false;
264
+ } else if (c === "(" || c === ",") {
265
+ out += c;
266
+ if (c === ",") out += " ";
267
+ prevEndsValue = false;
268
+ } else if (c === ")") {
269
+ out += c;
270
+ prevEndsValue = true;
271
+ } else if (/\s/.test(c)) {
272
+ } else if (c === "*" || c === "/") {
273
+ out += c;
274
+ prevEndsValue = false;
275
+ } else {
276
+ out += c;
277
+ prevEndsValue = true;
278
+ }
279
+ i++;
280
+ }
281
+ return out;
282
+ }
226
283
  function splitRespectingBrackets(token) {
227
284
  const parts = [];
228
285
  let depth = 0;
@@ -258,7 +315,7 @@ function parseClass(token) {
258
315
  const property = raw.slice(0, colonIdx);
259
316
  const rawValue = raw.slice(colonIdx + 1);
260
317
  if (property !== "" && rawValue !== "" && isSafeArbitraryValue(raw)) {
261
- const value = rawValue.replace(/_/g, " ");
318
+ const value = normalizeMathWhitespace(rawValue.replace(/_/g, " "));
262
319
  return {
263
320
  modifiers,
264
321
  utility: ARBITRARY_PROPERTY_SENTINEL,
@@ -280,7 +337,7 @@ function parseClass(token) {
280
337
  if (!isSafeArbitraryValue(raw)) {
281
338
  continue;
282
339
  }
283
- const spaced = raw.replace(/_/g, " ");
340
+ const spaced = normalizeMathWhitespace(raw.replace(/_/g, " "));
284
341
  return {
285
342
  modifiers,
286
343
  utility: prefix.slice(0, -1),
@@ -1533,6 +1590,14 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
1533
1590
  if (minWidth === void 0) return null;
1534
1591
  return width >= minWidth;
1535
1592
  }
1593
+ if (modifier.startsWith("min-[") && modifier.endsWith("]")) {
1594
+ const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
1595
+ return px === null ? null : width >= px;
1596
+ }
1597
+ if (modifier.startsWith("max-[") && modifier.endsWith("]")) {
1598
+ const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
1599
+ return px === null ? null : width <= px;
1600
+ }
1536
1601
  return null;
1537
1602
  }
1538
1603
  function kebabToCamel(s) {