@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.
@@ -1,10 +1,10 @@
1
- import "./chunk-LOTFFRZP.mjs";
1
+ import "./chunk-XPVSILI4.mjs";
2
2
  import {
3
3
  Fragment,
4
4
  jsx,
5
5
  jsxs
6
- } from "./chunk-UJYEYY6S.mjs";
7
- import "./chunk-DDNGWPS4.mjs";
6
+ } from "./chunk-FLPPVP5G.mjs";
7
+ import "./chunk-ZYE4VIZE.mjs";
8
8
 
9
9
  // src/jsxRuntimeCore.ts
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -181,59 +181,159 @@ var Evaluator = class {
181
181
  };
182
182
 
183
183
  // src/layoutCalc.ts
184
- var PERCENT_CALC_TOKEN_RE = /^(w|h)-\[calc\(([^)]+)\)\]$/;
184
+ var NEG = (v) => ({ percent: -v.percent, px: -v.px });
185
+ var ADD = (a, b) => ({ percent: a.percent + b.percent, px: a.px + b.px });
186
+ var SUB = (a, b) => ({ percent: a.percent - b.percent, px: a.px - b.px });
187
+ function MUL(a, b) {
188
+ if (a.percent === 0) return { percent: b.percent * a.px, px: b.px * a.px };
189
+ if (b.percent === 0) return { percent: a.percent * b.px, px: a.px * b.px };
190
+ return null;
191
+ }
192
+ function DIV(a, b) {
193
+ if (b.percent !== 0 || b.px === 0) return null;
194
+ return { percent: a.percent / b.px, px: a.px / b.px };
195
+ }
196
+ var PercentAwareEvaluator = class {
197
+ constructor(s) {
198
+ this.pos = 0;
199
+ this.s = s;
200
+ }
201
+ parseExprToEnd() {
202
+ const value = this.expr();
203
+ if (value === null) return null;
204
+ this.skipWs();
205
+ return this.pos === this.s.length ? value : null;
206
+ }
207
+ skipWs() {
208
+ while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
209
+ }
210
+ peek() {
211
+ this.skipWs();
212
+ return this.s[this.pos];
213
+ }
214
+ expr() {
215
+ let value = this.term();
216
+ if (value === null) return null;
217
+ for (; ; ) {
218
+ const ch = this.peek();
219
+ if (ch === "+") {
220
+ this.pos++;
221
+ const rhs = this.term();
222
+ if (rhs === null) return null;
223
+ value = ADD(value, rhs);
224
+ } else if (ch === "-") {
225
+ this.pos++;
226
+ const rhs = this.term();
227
+ if (rhs === null) return null;
228
+ value = SUB(value, rhs);
229
+ } else {
230
+ return value;
231
+ }
232
+ }
233
+ }
234
+ term() {
235
+ let value = this.factor();
236
+ if (value === null) return null;
237
+ for (; ; ) {
238
+ const ch = this.peek();
239
+ if (ch === "*") {
240
+ this.pos++;
241
+ const rhs = this.factor();
242
+ if (rhs === null) return null;
243
+ const result = MUL(value, rhs);
244
+ if (result === null) return null;
245
+ value = result;
246
+ } else if (ch === "/") {
247
+ this.pos++;
248
+ const rhs = this.factor();
249
+ if (rhs === null) return null;
250
+ const result = DIV(value, rhs);
251
+ if (result === null) return null;
252
+ value = result;
253
+ } else {
254
+ return value;
255
+ }
256
+ }
257
+ }
258
+ factor() {
259
+ const ch = this.peek();
260
+ if (ch === void 0) return null;
261
+ if (ch === "(") {
262
+ this.pos++;
263
+ const value = this.expr();
264
+ if (value === null || this.peek() !== ")") return null;
265
+ this.pos++;
266
+ return value;
267
+ }
268
+ if (ch === "-") {
269
+ this.pos++;
270
+ const value = this.factor();
271
+ return value === null ? null : NEG(value);
272
+ }
273
+ return this.numberWithUnit();
274
+ }
275
+ numberWithUnit() {
276
+ this.skipWs();
277
+ const start = this.pos;
278
+ while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
279
+ if (this.pos === start) return null;
280
+ const n = Number(this.s.slice(start, this.pos));
281
+ if (!Number.isFinite(n)) return null;
282
+ if (this.s[this.pos] === "%") {
283
+ this.pos++;
284
+ return { percent: n, px: 0 };
285
+ }
286
+ const unitStart = this.pos;
287
+ while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
288
+ const unit = this.s.slice(unitStart, this.pos);
289
+ switch (unit) {
290
+ case "":
291
+ return { percent: 0, px: n };
292
+ case "px":
293
+ return { percent: 0, px: n };
294
+ case "rem":
295
+ return { percent: 0, px: n * 16 };
296
+ default:
297
+ return null;
298
+ }
299
+ }
300
+ };
301
+ var PERCENT_TOKEN_OUTER_RE = /^(w|h)-\[(.+)\]$/;
185
302
  function parsePercentRelativeCalc(token) {
186
- const m = PERCENT_CALC_TOKEN_RE.exec(token);
303
+ const m = PERCENT_TOKEN_OUTER_RE.exec(token);
187
304
  if (!m) return null;
188
305
  const property = m[1] === "w" ? "width" : "height";
189
- const inner = m[2].replace(/_/g, " ").trim();
190
- let mm = /^(-?[\d.]+)%\s*([+-])\s*(.+)$/.exec(inner);
191
- if (mm) {
192
- const percentCoefficient = Number(mm[1]);
193
- const magnitude = reduceConstantMath(`calc(${mm[3].trim()})`);
194
- if (!Number.isFinite(percentCoefficient) || magnitude === null) return null;
195
- return { property, percentCoefficient, constantPx: mm[2] === "+" ? magnitude : -magnitude };
196
- }
197
- mm = /^(.+?)\s*([+-])\s*(-?[\d.]+)%$/.exec(inner);
198
- if (mm) {
199
- const constantPx = reduceConstantMath(`calc(${mm[1].trim()})`);
200
- const percentMagnitude = Number(mm[3]);
201
- if (constantPx === null || !Number.isFinite(percentMagnitude)) return null;
202
- return { property, percentCoefficient: mm[2] === "+" ? percentMagnitude : -percentMagnitude, constantPx };
203
- }
204
- return null;
306
+ const inner = stripCall(m[2].replace(/_/g, " ").trim(), "calc");
307
+ if (inner === null) return null;
308
+ const result = new PercentAwareEvaluator(inner).parseExprToEnd();
309
+ if (result === null || result.percent === 0) return null;
310
+ return { property, percentCoefficient: result.percent, constantPx: result.px };
205
311
  }
206
312
  function resolvePercentRelativeCalc(basisPx, calc) {
207
313
  return basisPx * calc.percentCoefficient / 100 + calc.constantPx;
208
314
  }
209
- var PERCENT_MIN_MAX_CLAMP_TOKEN_RE = /^(w|h)-\[(min|max|clamp)\(([^)]+)\)\]$/;
210
- function parseOperand(arg) {
211
- const trimmed = arg.trim();
212
- const pct = /^(-?[\d.]+)%$/.exec(trimmed);
213
- if (pct) {
214
- const percentCoefficient = Number(pct[1]);
215
- return Number.isFinite(percentCoefficient) ? { percentCoefficient, constantPx: 0 } : null;
216
- }
217
- const constantPx = reduceConstantMath(`calc(${trimmed})`);
218
- return constantPx === null ? null : { percentCoefficient: 0, constantPx };
219
- }
220
315
  function parsePercentRelativeMinMaxClamp(token) {
221
- const m = PERCENT_MIN_MAX_CLAMP_TOKEN_RE.exec(token);
316
+ const m = PERCENT_TOKEN_OUTER_RE.exec(token);
222
317
  if (!m) return null;
223
318
  const property = m[1] === "w" ? "width" : "height";
224
- const kind = m[2];
225
- const args = splitTopLevelCommas(m[3].replace(/_/g, " "));
319
+ const spaced = m[2].replace(/_/g, " ");
320
+ let kind;
321
+ let inner;
322
+ if ((inner = stripCall(spaced, "min")) !== null) kind = "min";
323
+ else if ((inner = stripCall(spaced, "max")) !== null) kind = "max";
324
+ else if ((inner = stripCall(spaced, "clamp")) !== null) kind = "clamp";
325
+ else return null;
326
+ const args = splitTopLevelCommas(inner);
226
327
  if (kind === "clamp" && args.length !== 3) return null;
227
328
  if (kind !== "clamp" && args.length < 1) return null;
228
- const operands = args.map(parseOperand);
329
+ const operands = args.map((arg) => new PercentAwareEvaluator(arg.trim()).parseExprToEnd());
229
330
  if (operands.some((o) => o === null)) return null;
230
331
  const resolved = operands;
231
- if (!resolved.some((o) => o.percentCoefficient !== 0)) return null;
232
- const resolveOperand = (o, basisPx) => basisPx * o.percentCoefficient / 100 + o.constantPx;
332
+ if (!resolved.some((o) => o.percent !== 0)) return null;
233
333
  return {
234
334
  property,
235
335
  resolve(basisPx) {
236
- const values = resolved.map((o) => resolveOperand(o, basisPx));
336
+ const values = resolved.map((o) => basisPx * o.percent / 100 + o.px);
237
337
  if (kind === "min") return Math.min(...values);
238
338
  if (kind === "max") return Math.max(...values);
239
339
  const [min, preferred, max] = values;
@@ -421,6 +521,63 @@ var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
421
521
  function isSafeArbitraryValue(value) {
422
522
  return !value.includes("{") && !value.includes("}") && !value.includes(";");
423
523
  }
524
+ function normalizeMathWhitespace(raw) {
525
+ if (!(raw.startsWith("calc(") || raw.startsWith("min(") || raw.startsWith("max(") || raw.startsWith("clamp("))) {
526
+ return raw;
527
+ }
528
+ const chars = Array.from(raw);
529
+ let out = "";
530
+ let i = 0;
531
+ let prevEndsValue = false;
532
+ while (i < chars.length) {
533
+ const c = chars[i];
534
+ if (c === "v" && chars[i + 1] === "a" && chars[i + 2] === "r" && chars[i + 3] === "(") {
535
+ const start = i;
536
+ let depth = 0;
537
+ while (i < chars.length) {
538
+ if (chars[i] === "(") depth++;
539
+ else if (chars[i] === ")") {
540
+ depth--;
541
+ if (depth === 0) {
542
+ i++;
543
+ break;
544
+ }
545
+ }
546
+ i++;
547
+ }
548
+ out += chars.slice(start, i).join("");
549
+ prevEndsValue = true;
550
+ continue;
551
+ }
552
+ if (c === "+" || c === "-") {
553
+ if (prevEndsValue) {
554
+ out += ` ${c} `;
555
+ i++;
556
+ while (i < chars.length && /\s/.test(chars[i])) i++;
557
+ prevEndsValue = false;
558
+ continue;
559
+ }
560
+ out += c;
561
+ prevEndsValue = false;
562
+ } else if (c === "(" || c === ",") {
563
+ out += c;
564
+ if (c === ",") out += " ";
565
+ prevEndsValue = false;
566
+ } else if (c === ")") {
567
+ out += c;
568
+ prevEndsValue = true;
569
+ } else if (/\s/.test(c)) {
570
+ } else if (c === "*" || c === "/") {
571
+ out += c;
572
+ prevEndsValue = false;
573
+ } else {
574
+ out += c;
575
+ prevEndsValue = true;
576
+ }
577
+ i++;
578
+ }
579
+ return out;
580
+ }
424
581
  function splitRespectingBrackets(token) {
425
582
  const parts = [];
426
583
  let depth = 0;
@@ -456,7 +613,7 @@ function parseClass(token) {
456
613
  const property = raw.slice(0, colonIdx);
457
614
  const rawValue = raw.slice(colonIdx + 1);
458
615
  if (property !== "" && rawValue !== "" && isSafeArbitraryValue(raw)) {
459
- const value = rawValue.replace(/_/g, " ");
616
+ const value = normalizeMathWhitespace(rawValue.replace(/_/g, " "));
460
617
  return {
461
618
  modifiers,
462
619
  utility: ARBITRARY_PROPERTY_SENTINEL,
@@ -478,7 +635,7 @@ function parseClass(token) {
478
635
  if (!isSafeArbitraryValue(raw)) {
479
636
  continue;
480
637
  }
481
- const spaced = raw.replace(/_/g, " ");
638
+ const spaced = normalizeMathWhitespace(raw.replace(/_/g, " "));
482
639
  return {
483
640
  modifiers,
484
641
  utility: prefix.slice(0, -1),
@@ -519,7 +676,7 @@ function substituteDynamicTokens(classStrRaw) {
519
676
  return value ?? whole;
520
677
  });
521
678
  }
522
- var PERCENT_RELATIVE_CALC_HINT_RE = /[wh]-\[(calc|min|max|clamp)\([^)]*%[^)]*\)\]/;
679
+ var PERCENT_RELATIVE_CALC_HINT_RE = /[wh]-\[(calc|min|max|clamp)\(.*%.*\)\]/;
523
680
  function extractPercentRelativeCalcs(classStrRaw) {
524
681
  const found = [];
525
682
  for (const token of classStrRaw.split(/\s+/)) {
@@ -532,26 +689,64 @@ function stripPercentRelativeCalcTokens(classStrRaw) {
532
689
  return classStrRaw.split(/\s+/).filter((token) => token && parsePercentRelativeExpr(token) === null).join(" ");
533
690
  }
534
691
  var STATE_MODIFIER_NAMES = /* @__PURE__ */ new Set(["hover", "focus", "disabled"]);
535
- var STATE_MODIFIER_HINT_RE = /(^|\s|:)(hover|focus|disabled):/;
692
+ var STATIC_ARIA_SHORTCUT_NAMES = /* @__PURE__ */ new Set([
693
+ "aria-checked",
694
+ "aria-disabled",
695
+ "aria-expanded",
696
+ "aria-hidden",
697
+ "aria-pressed",
698
+ "aria-readonly",
699
+ "aria-required",
700
+ "aria-selected",
701
+ "aria-busy"
702
+ ]);
703
+ var STATE_MODIFIER_HINT_RE = /(^|\s|:)(hover|focus|disabled|aria-checked|aria-disabled|aria-expanded|aria-hidden|aria-pressed|aria-readonly|aria-required|aria-selected|aria-busy):|data-\[|aria-\[/;
704
+ function bracketContent(name, prefix) {
705
+ if (!name.startsWith(prefix)) return null;
706
+ const rest = name.slice(prefix.length);
707
+ if (!rest.startsWith("[") || !rest.endsWith("]")) return null;
708
+ return rest.slice(1, -1);
709
+ }
710
+ function evalAttrCondition(hostRest, attrPrefix, inner) {
711
+ const eqIdx = inner.indexOf("=");
712
+ if (eqIdx === -1) return Boolean(hostRest[`${attrPrefix}${inner}`]);
713
+ const key = inner.slice(0, eqIdx);
714
+ const value = inner.slice(eqIdx + 1);
715
+ return String(hostRest[`${attrPrefix}${key}`]) === value;
716
+ }
717
+ function isAriaTruthy(value) {
718
+ return value === true || value === "true";
719
+ }
720
+ function propBasedModifierState(name, states, hostRest) {
721
+ if (STATE_MODIFIER_NAMES.has(name)) return states[name];
722
+ if (STATIC_ARIA_SHORTCUT_NAMES.has(name)) return isAriaTruthy(hostRest[name]);
723
+ const dataInner = bracketContent(name, "data-");
724
+ if (dataInner !== null) return evalAttrCondition(hostRest, "data-", dataInner);
725
+ const ariaInner = bracketContent(name, "aria-");
726
+ if (ariaInner !== null) return evalAttrCondition(hostRest, "aria-", ariaInner);
727
+ return null;
728
+ }
536
729
  function stripModifiers(parts, namesToStrip) {
537
730
  const utility = parts[parts.length - 1] ?? "";
538
731
  const modifiers = parts.slice(0, -1).filter((m) => !namesToStrip.has(m));
539
732
  return [...modifiers, utility].join(":");
540
733
  }
541
- function substituteStateModifiers(classStrRaw, states) {
734
+ function substituteStateModifiers(classStrRaw, states, hostRest) {
542
735
  if (!STATE_MODIFIER_HINT_RE.test(classStrRaw)) return classStrRaw;
543
736
  const kept = [];
544
737
  for (const token of classStrRaw.split(/\s+/)) {
545
738
  if (!token) continue;
546
739
  const parts = splitRespectingBrackets(token);
547
740
  const modifiers = parts.slice(0, -1);
548
- const required = modifiers.filter((m) => STATE_MODIFIER_NAMES.has(m));
741
+ const resolved = modifiers.map((m) => [m, propBasedModifierState(m, states, hostRest)]);
742
+ const required = resolved.filter(([, v]) => v !== null);
549
743
  if (required.length === 0) {
550
744
  kept.push(token);
551
745
  continue;
552
746
  }
553
- if (required.every((m) => states[m])) {
554
- kept.push(stripModifiers(parts, STATE_MODIFIER_NAMES));
747
+ if (required.every(([, v]) => v === true)) {
748
+ const requiredNames = new Set(required.map(([m]) => m));
749
+ kept.push(stripModifiers(parts, requiredNames));
555
750
  }
556
751
  }
557
752
  return kept.join(" ");
@@ -559,8 +754,8 @@ function substituteStateModifiers(classStrRaw, states) {
559
754
  function makeElement(isStaticChildren, type, props, key) {
560
755
  return (isStaticChildren ? import_jsx_runtime.jsxs : import_jsx_runtime.jsx)(type, props, key);
561
756
  }
562
- function resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, pressed, layoutOverrides, states = { hover: false, focus: false, disabled: false }) {
563
- const stateResolved = substituteStateModifiers(classStrRaw, states);
757
+ function resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, pressed, hostRest, layoutOverrides, states = { hover: false, focus: false, disabled: false }) {
758
+ const stateResolved = substituteStateModifiers(classStrRaw, states, hostRest);
564
759
  const cleaned = stripPercentRelativeCalcTokens(substituteDynamicTokens(stateResolved));
565
760
  const resolved = resolveStyle2(cleaned, pressed);
566
761
  if (layoutOverrides) {
@@ -575,7 +770,7 @@ function resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, pressed, layout
575
770
  return [resolved, userStyle];
576
771
  }
577
772
  var DARK_MODIFIER_RE = /(^|\s|:)dark:/;
578
- var BREAKPOINT_MODIFIER_RE = /(^|\s|:)(sm|md|lg|xl|2xl):/;
773
+ var BREAKPOINT_MODIFIER_RE = /(^|\s|:)(sm|md|lg|xl|2xl):|(^|\s|:)(min|max)-\[[^\]]*\]:/;
579
774
  var HOVER_MODIFIER_RE = /(^|\s|:)hover:/;
580
775
  var FOCUS_MODIFIER_RE = /(^|\s|:)focus:/;
581
776
  function ReactiveElement({
@@ -653,7 +848,7 @@ function ReactiveElement({
653
848
  };
654
849
  }
655
850
  const states = { hover: isHovered, focus: isFocused, disabled: hostRest.disabled === true };
656
- const finalStyle = hostType === import_react_native.Pressable ? (state) => resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, state.pressed, layoutOverrides, states) : resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, false, layoutOverrides, states);
851
+ const finalStyle = hostType === import_react_native.Pressable ? (state) => resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, state.pressed, hostRest, layoutOverrides, states) : resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, false, hostRest, layoutOverrides, states);
657
852
  return makeElement(
658
853
  isStaticChildren,
659
854
  hostType,
@@ -677,7 +872,7 @@ function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
677
872
  );
678
873
  }
679
874
  const staticStates = { hover: false, focus: false, disabled: rest.disabled === true };
680
- const finalStyle = type === import_react_native.Pressable ? (state) => resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, state.pressed, void 0, staticStates) : resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, false, void 0, staticStates);
875
+ const finalStyle = type === import_react_native.Pressable ? (state) => resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, state.pressed, rest, void 0, staticStates) : resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, false, rest, void 0, staticStates);
681
876
  return makeElement(isStaticChildren, type, { ...rest, className: classStrRaw, style: finalStyle }, key);
682
877
  }
683
878
  function createJsxFunctions(resolveStyle2) {
@@ -1769,6 +1964,14 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
1769
1964
  if (minWidth === void 0) return null;
1770
1965
  return width >= minWidth;
1771
1966
  }
1967
+ if (modifier.startsWith("min-[") && modifier.endsWith("]")) {
1968
+ const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
1969
+ return px === null ? null : width >= px;
1970
+ }
1971
+ if (modifier.startsWith("max-[") && modifier.endsWith("]")) {
1972
+ const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
1973
+ return px === null ? null : width <= px;
1974
+ }
1772
1975
  return null;
1773
1976
  }
1774
1977
  function kebabToCamel(s) {