@kbach/react-native 1.1.1-beta.0 → 1.1.1-beta.2

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.
@@ -10,15 +10,23 @@ import {
10
10
  subscribeDynamicTokens,
11
11
  subscribeGlobalDarkMode,
12
12
  toggleGlobalDarkMode
13
- } from "./chunk-FSO4WVCH.mjs";
13
+ } from "./chunk-BN6RWNCE.mjs";
14
14
  import {
15
15
  defaultTheme,
16
16
  getTheme,
17
17
  resolveClassName,
18
18
  setTheme
19
- } from "./chunk-R7E5D3D6.mjs";
19
+ } from "./chunk-TCSCNQQ7.mjs";
20
20
 
21
21
  // src/config.ts
22
+ function composeMap(compose) {
23
+ const out = {};
24
+ for (const [name, value] of Object.entries(compose)) {
25
+ const text = Array.isArray(value) ? value.join(" ") : value;
26
+ if (typeof text === "string" && text.trim() !== "" && name.trim() !== "") out[name.trim()] = text.trim();
27
+ }
28
+ return out;
29
+ }
22
30
  function parseHexRgb(hex) {
23
31
  const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
24
32
  if (!m) return null;
@@ -88,6 +96,9 @@ function resolveKbachConfig(config) {
88
96
  if (config.extend?.container) {
89
97
  theme = { ...theme, container: { ...theme.container, ...config.extend.container } };
90
98
  }
99
+ if (config.compose) {
100
+ theme = { ...theme, compose: { ...theme.compose, ...composeMap(config.compose) } };
101
+ }
91
102
  if (config.darkMode) {
92
103
  theme = { ...theme, darkMode: config.darkMode };
93
104
  }
@@ -914,6 +914,130 @@ function parsePercentRelativeExpr(token) {
914
914
  return parsePercentRelativeMinMaxClamp(token);
915
915
  }
916
916
 
917
+ // src/jsEngine/groups.ts
918
+ function expandVariantGroups(input) {
919
+ if (!input.includes(":(")) return input;
920
+ const out = [];
921
+ for (const token of splitTopLevel(input)) expandToken(token, "", false, out);
922
+ return out.join(" ");
923
+ }
924
+ function splitTopLevel(s) {
925
+ const parts = [];
926
+ let depth = 0;
927
+ let start = -1;
928
+ for (let i = 0; i < s.length; i++) {
929
+ const ch = s[i];
930
+ if (ch === "(" || ch === "[") depth++;
931
+ else if (ch === ")" || ch === "]") depth--;
932
+ const space = /\s/.test(ch);
933
+ if (space && depth <= 0) {
934
+ if (start >= 0) {
935
+ parts.push(s.slice(start, i));
936
+ start = -1;
937
+ }
938
+ depth = Math.max(depth, 0);
939
+ } else if (start < 0 && !space) {
940
+ start = i;
941
+ }
942
+ }
943
+ if (start >= 0) parts.push(s.slice(start));
944
+ return parts;
945
+ }
946
+ function groupOpen(token) {
947
+ let brackets = 0;
948
+ for (let i = 0; i < token.length; i++) {
949
+ const ch = token[i];
950
+ if (ch === "[") brackets++;
951
+ else if (ch === "]") brackets--;
952
+ else if (ch === "(" && brackets === 0 && i > 1 && token[i - 1] === ":") return i;
953
+ }
954
+ return -1;
955
+ }
956
+ function groupClose(token, open) {
957
+ let depth = 0;
958
+ for (let i = open; i < token.length; i++) {
959
+ const ch = token[i];
960
+ if (ch === "(" || ch === "[") depth++;
961
+ else if (ch === ")" || ch === "]") {
962
+ depth--;
963
+ if (depth === 0) return ch === ")" ? i : -1;
964
+ }
965
+ }
966
+ return -1;
967
+ }
968
+ function pushClass(prefix, cls, important, out) {
969
+ if (!cls) return;
970
+ const bare = cls.split(":").pop() ?? cls;
971
+ out.push(prefix + cls + (important && !cls.endsWith("!") && !bare.startsWith("!") ? "!" : ""));
972
+ }
973
+ function expandToken(token, prefix, important, out) {
974
+ const open = groupOpen(token);
975
+ if (open < 0) return pushClass(prefix, token, important, out);
976
+ const close = groupClose(token, open);
977
+ if (close < 0) return pushClass(prefix, token, important, out);
978
+ const rest = token.slice(close + 1);
979
+ if (rest !== "" && rest !== "!") return pushClass(prefix, token, important, out);
980
+ const innerPrefix = prefix + token.slice(0, open);
981
+ for (const part of splitTopLevel(token.slice(open + 1, close))) expandToken(part, innerPrefix, rest === "!" || important, out);
982
+ }
983
+
984
+ // src/jsEngine/compose.ts
985
+ var MAX_DEPTH = 8;
986
+ function splitVariants(token) {
987
+ let depth = 0;
988
+ let last = -1;
989
+ for (let i = 0; i < token.length; i++) {
990
+ const ch = token[i];
991
+ if (ch === "[" || ch === "(") depth++;
992
+ else if (ch === "]" || ch === ")") depth--;
993
+ else if (ch === ":" && depth === 0) last = i;
994
+ }
995
+ return last < 0 ? ["", token] : [token.slice(0, last + 1), token.slice(last + 1)];
996
+ }
997
+ function stripImportant(base) {
998
+ if (base.endsWith("!")) return [base.slice(0, -1), true];
999
+ if (base.startsWith("!")) return [base.slice(1), true];
1000
+ return [base, false];
1001
+ }
1002
+ function withImportant(cls, important) {
1003
+ const [, base] = splitVariants(cls);
1004
+ return important && !cls.endsWith("!") && !base.startsWith("!") ? cls + "!" : cls;
1005
+ }
1006
+ function expandInto(prefix, value, important, compose, path, out) {
1007
+ for (const cls of expandVariantGroups(value).split(/\s+/).filter(Boolean)) {
1008
+ const [variants, base] = splitVariants(cls);
1009
+ const [name, bang] = stripImportant(base);
1010
+ const inner = Object.prototype.hasOwnProperty.call(compose, name) ? compose[name] : void 0;
1011
+ if (inner !== void 0 && path.length < MAX_DEPTH && !path.includes(name)) {
1012
+ path.push(name);
1013
+ expandInto(prefix + variants, inner, important || bang, compose, path, out);
1014
+ path.pop();
1015
+ } else {
1016
+ out.push(withImportant(prefix + cls, important));
1017
+ }
1018
+ }
1019
+ }
1020
+ function expandComposeToken(token, compose) {
1021
+ if (!compose) return null;
1022
+ const [variants, base] = splitVariants(token);
1023
+ const [name, important] = stripImportant(base);
1024
+ if (!Object.prototype.hasOwnProperty.call(compose, name)) return null;
1025
+ const out = [];
1026
+ expandInto(variants, compose[name], important, compose, [name], out);
1027
+ return out;
1028
+ }
1029
+ function expandComposeClasses(classString, compose) {
1030
+ if (!compose || Object.keys(compose).length === 0) return classString;
1031
+ const composed = [];
1032
+ const own = [];
1033
+ for (const token of classString.split(/\s+/).filter(Boolean)) {
1034
+ const classes = expandComposeToken(token, compose);
1035
+ if (classes) composed.push(...classes);
1036
+ else own.push(token);
1037
+ }
1038
+ return composed.length === 0 ? classString : [...composed, ...own].join(" ");
1039
+ }
1040
+
917
1041
  // src/jsxRuntimeCore.ts
918
1042
  var DYNAMIC_TOKEN_MATCH_RE = /var\(--([a-zA-Z0-9-]+)\)/g;
919
1043
  function substituteDynamicTokens(classStrRaw) {
@@ -1028,6 +1152,7 @@ function ReactiveElement({
1028
1152
  hostType,
1029
1153
  hostRest,
1030
1154
  classStrRaw,
1155
+ classNameProp,
1031
1156
  userStyle,
1032
1157
  resolveStyle: resolveStyle2,
1033
1158
  elementKey,
@@ -1103,28 +1228,46 @@ function ReactiveElement({
1103
1228
  return makeElement(
1104
1229
  isStaticChildren,
1105
1230
  hostType,
1106
- { ...hostRestWithLayout, className: classStrRaw, style: finalStyle },
1231
+ { ...hostRestWithLayout, className: classNameProp, style: finalStyle },
1107
1232
  elementKey
1108
1233
  );
1109
1234
  }
1235
+ var flatCache = /* @__PURE__ */ new Map();
1236
+ var flatCacheTheme = null;
1237
+ function flatClasses(classNameProp) {
1238
+ const theme = (0, import_theme.getTheme)();
1239
+ if (!theme.compose && !classNameProp.includes(":(")) return classNameProp;
1240
+ if (theme !== flatCacheTheme) {
1241
+ flatCache.clear();
1242
+ flatCacheTheme = theme;
1243
+ }
1244
+ let flat = flatCache.get(classNameProp);
1245
+ if (flat === void 0) {
1246
+ flat = expandComposeClasses(classNameProp.includes(":(") ? expandVariantGroups(classNameProp) : classNameProp, theme.compose);
1247
+ if (flatCache.size >= 500) flatCache.clear();
1248
+ flatCache.set(classNameProp, flat);
1249
+ }
1250
+ return flat;
1251
+ }
1110
1252
  function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
1111
1253
  if (type === null || typeof type === "symbol" || !rawProps) {
1112
1254
  return makeElement(isStaticChildren, type, rawProps ?? {}, key);
1113
1255
  }
1114
- const { className: classStrRaw, style: userStyle, ...rest } = rawProps;
1115
- if (typeof classStrRaw !== "string") {
1256
+ const { className: classNameProp, style: userStyle, ...rest } = rawProps;
1257
+ if (typeof classNameProp !== "string") {
1116
1258
  return makeElement(isStaticChildren, type, rawProps, key);
1117
1259
  }
1260
+ const classStrRaw = flatClasses(classNameProp);
1118
1261
  if (DARK_MODIFIER_RE.test(classStrRaw) || BREAKPOINT_MODIFIER_RE.test(classStrRaw) || HOVER_MODIFIER_RE.test(classStrRaw) || FOCUS_MODIFIER_RE.test(classStrRaw) || classStrRaw.includes("var(--") || PERCENT_RELATIVE_CALC_HINT_RE.test(classStrRaw) || usesModeAwareColor(classStrRaw)) {
1119
1262
  return (0, import_jsx_runtime.jsx)(
1120
1263
  ReactiveElement,
1121
- { hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
1264
+ { hostType: type, hostRest: rest, classStrRaw, classNameProp, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
1122
1265
  key
1123
1266
  );
1124
1267
  }
1125
1268
  const staticStates = { hover: false, focus: false, disabled: rest.disabled === true };
1126
1269
  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);
1127
- return makeElement(isStaticChildren, type, { ...rest, className: classStrRaw, style: finalStyle }, key);
1270
+ return makeElement(isStaticChildren, type, { ...rest, className: classNameProp, style: finalStyle }, key);
1128
1271
  }
1129
1272
  function createJsxFunctions(resolveStyle2) {
1130
1273
  function jsx2(type, props, key) {
@@ -1151,73 +1294,6 @@ var import_react_native2 = require("react-native");
1151
1294
  var import_theme2 = require("./theme");
1152
1295
  var import_darkModeStore2 = require("./darkModeStore");
1153
1296
 
1154
- // src/jsEngine/groups.ts
1155
- function expandVariantGroups(input) {
1156
- if (!input.includes(":(")) return input;
1157
- const out = [];
1158
- for (const token of splitTopLevel(input)) expandToken(token, "", false, out);
1159
- return out.join(" ");
1160
- }
1161
- function splitTopLevel(s) {
1162
- const parts = [];
1163
- let depth = 0;
1164
- let start = -1;
1165
- for (let i = 0; i < s.length; i++) {
1166
- const ch = s[i];
1167
- if (ch === "(" || ch === "[") depth++;
1168
- else if (ch === ")" || ch === "]") depth--;
1169
- const space = /\s/.test(ch);
1170
- if (space && depth <= 0) {
1171
- if (start >= 0) {
1172
- parts.push(s.slice(start, i));
1173
- start = -1;
1174
- }
1175
- depth = Math.max(depth, 0);
1176
- } else if (start < 0 && !space) {
1177
- start = i;
1178
- }
1179
- }
1180
- if (start >= 0) parts.push(s.slice(start));
1181
- return parts;
1182
- }
1183
- function groupOpen(token) {
1184
- let brackets = 0;
1185
- for (let i = 0; i < token.length; i++) {
1186
- const ch = token[i];
1187
- if (ch === "[") brackets++;
1188
- else if (ch === "]") brackets--;
1189
- else if (ch === "(" && brackets === 0 && i > 1 && token[i - 1] === ":") return i;
1190
- }
1191
- return -1;
1192
- }
1193
- function groupClose(token, open) {
1194
- let depth = 0;
1195
- for (let i = open; i < token.length; i++) {
1196
- const ch = token[i];
1197
- if (ch === "(" || ch === "[") depth++;
1198
- else if (ch === ")" || ch === "]") {
1199
- depth--;
1200
- if (depth === 0) return ch === ")" ? i : -1;
1201
- }
1202
- }
1203
- return -1;
1204
- }
1205
- function pushClass(prefix, cls, important, out) {
1206
- if (!cls) return;
1207
- const bare = cls.split(":").pop() ?? cls;
1208
- out.push(prefix + cls + (important && !cls.endsWith("!") && !bare.startsWith("!") ? "!" : ""));
1209
- }
1210
- function expandToken(token, prefix, important, out) {
1211
- const open = groupOpen(token);
1212
- if (open < 0) return pushClass(prefix, token, important, out);
1213
- const close = groupClose(token, open);
1214
- if (close < 0) return pushClass(prefix, token, important, out);
1215
- const rest = token.slice(close + 1);
1216
- if (rest !== "" && rest !== "!") return pushClass(prefix, token, important, out);
1217
- const innerPrefix = prefix + token.slice(0, open);
1218
- for (const part of splitTopLevel(token.slice(open + 1, close))) expandToken(part, innerPrefix, rest === "!" || important, out);
1219
- }
1220
-
1221
1297
  // src/jsEngine/shared.ts
1222
1298
  function decl(property, value) {
1223
1299
  return { property, value };
@@ -2517,7 +2593,7 @@ Fix: use a plain px/rem calc, a fraction utility (e.g. w-1/2), or resolve this v
2517
2593
  return { value: null, warning };
2518
2594
  }
2519
2595
  function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, width) {
2520
- classString = expandVariantGroups(classString);
2596
+ classString = expandComposeClasses(expandVariantGroups(classString), theme.compose);
2521
2597
  const style = {};
2522
2598
  const warnings = [];
2523
2599
  let shadowOffset = null;