@kbach/react 0.3.2 → 0.3.4

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.
@@ -1801,9 +1801,6 @@ function clearPluginUtilities() {
1801
1801
  function getPluginStandaloneMap() {
1802
1802
  return PLUGIN_STANDALONE;
1803
1803
  }
1804
- function getPluginResolverMap() {
1805
- return PLUGIN_RESOLVERS;
1806
- }
1807
1804
 
1808
1805
  // src/core/cache.ts
1809
1806
  var LRUCache = class {
@@ -2085,6 +2082,28 @@ function getConfig() {
2085
2082
  store.resolved = buildConfig({});
2086
2083
  return store.resolved;
2087
2084
  }
2085
+ function resolveOneRef(ref, colors) {
2086
+ const m = /^([a-z][a-z0-9]*)-(\d+)$/.exec(ref);
2087
+ if (!m) return null;
2088
+ const entry = colors[m[1]];
2089
+ if (!entry || typeof entry !== "object") return null;
2090
+ return entry[m[2]] ?? null;
2091
+ }
2092
+ function resolveColorRefs(colors) {
2093
+ const out = {};
2094
+ for (const [key, val] of Object.entries(colors)) {
2095
+ if (typeof val === "string") {
2096
+ out[key] = resolveOneRef(val, colors) ?? val;
2097
+ } else {
2098
+ const shades = {};
2099
+ for (const [shade, hex] of Object.entries(val)) {
2100
+ shades[shade] = resolveOneRef(hex, colors) ?? hex;
2101
+ }
2102
+ out[key] = shades;
2103
+ }
2104
+ }
2105
+ return out;
2106
+ }
2088
2107
  function buildConfig(userConfig) {
2089
2108
  let theme = { ...defaultTheme };
2090
2109
  if (userConfig.theme) {
@@ -2103,6 +2122,7 @@ function buildConfig(userConfig) {
2103
2122
  }
2104
2123
  }
2105
2124
  }
2125
+ theme = { ...theme, colors: resolveColorRefs(theme.colors) };
2106
2126
  const resolved = {
2107
2127
  darkMode: userConfig.darkMode ?? "attribute",
2108
2128
  theme,
@@ -2118,7 +2138,6 @@ function buildConfig(userConfig) {
2118
2138
  }
2119
2139
  function makePluginAPI(theme) {
2120
2140
  const standalone = getPluginStandaloneMap();
2121
- const resolvers = getPluginResolverMap();
2122
2141
  return {
2123
2142
  addUtility(name, styles) {
2124
2143
  standalone[name] = styles;
@@ -2149,11 +2168,16 @@ function onConfigChange(listener) {
2149
2168
  function updateConfig(userConfig) {
2150
2169
  const store = getConfigStore();
2151
2170
  store.resolved = buildConfig(userConfig);
2171
+ store._src = userConfig;
2152
2172
  clearCache();
2153
2173
  for (const listener of store.listeners) {
2154
2174
  listener(store.resolved);
2155
2175
  }
2156
2176
  }
2177
+ function initConfig(userConfig) {
2178
+ if (getConfigStore()._src === userConfig) return;
2179
+ updateConfig(userConfig);
2180
+ }
2157
2181
  var customVariants = new Proxy(
2158
2182
  {},
2159
2183
  {
@@ -2287,6 +2311,7 @@ export {
2287
2311
  buildConfig,
2288
2312
  onConfigChange,
2289
2313
  updateConfig,
2314
+ initConfig,
2290
2315
  syncGlobalDarkMode,
2291
2316
  setGlobalDarkMode,
2292
2317
  useGlobalDarkMode,
@@ -5,7 +5,7 @@ import {
5
5
  isWeb,
6
6
  resolve,
7
7
  useGlobalDarkMode
8
- } from "./chunk-V5KHX4CZ.mjs";
8
+ } from "./chunk-ADRZPFQC.mjs";
9
9
 
10
10
  // src/jsx-runtime.tsx
11
11
  import { jsx as _jsx, jsxs as _jsxs, Fragment } from "react/jsx-runtime";
package/dist/index.d.mts CHANGED
@@ -122,6 +122,13 @@ declare function flatten(resolved: ResolvedStyle, isDark: boolean, state?: {
122
122
  declare function getConfig(): ResolvedConfig;
123
123
  declare function buildConfig(userConfig: FrameworkConfig): ResolvedConfig;
124
124
  declare function updateConfig(userConfig: FrameworkConfig): void;
125
+ /**
126
+ * Like updateConfig, but only calls it when the config object reference has
127
+ * actually changed. Used by the Babel-injected IIFE so that:
128
+ * - multiple files with kbach classes don't re-run the update on every load
129
+ * - Fast Refresh DOES re-run when kbach.config.js changes (new module → new object)
130
+ */
131
+ declare function initConfig(userConfig: FrameworkConfig): void;
125
132
 
126
133
  interface ThemeContextValue {
127
134
  /** The user-selected mode ('light' | 'dark' | 'system') */
@@ -335,4 +342,4 @@ declare function kb(classString: string, isDark?: boolean): StyleValue | string;
335
342
  */
336
343
  declare function cx(...classes: Array<string | false | null | undefined>): string;
337
344
 
338
- export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useStyles, useTheme, wrapColors };
345
+ export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, initConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useStyles, useTheme, wrapColors };
package/dist/index.d.ts CHANGED
@@ -122,6 +122,13 @@ declare function flatten(resolved: ResolvedStyle, isDark: boolean, state?: {
122
122
  declare function getConfig(): ResolvedConfig;
123
123
  declare function buildConfig(userConfig: FrameworkConfig): ResolvedConfig;
124
124
  declare function updateConfig(userConfig: FrameworkConfig): void;
125
+ /**
126
+ * Like updateConfig, but only calls it when the config object reference has
127
+ * actually changed. Used by the Babel-injected IIFE so that:
128
+ * - multiple files with kbach classes don't re-run the update on every load
129
+ * - Fast Refresh DOES re-run when kbach.config.js changes (new module → new object)
130
+ */
131
+ declare function initConfig(userConfig: FrameworkConfig): void;
125
132
 
126
133
  interface ThemeContextValue {
127
134
  /** The user-selected mode ('light' | 'dark' | 'system') */
@@ -335,4 +342,4 @@ declare function kb(classString: string, isDark?: boolean): StyleValue | string;
335
342
  */
336
343
  declare function cx(...classes: Array<string | false | null | undefined>): string;
337
344
 
338
- export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useStyles, useTheme, wrapColors };
345
+ export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, initConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useStyles, useTheme, wrapColors };
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  defaultTheme: () => defaultTheme,
41
41
  flatten: () => flatten,
42
42
  getConfig: () => getConfig,
43
+ initConfig: () => initConfig,
43
44
  kb: () => kb,
44
45
  parseClass: () => parseClass,
45
46
  parseClasses: () => parseClasses,
@@ -1964,9 +1965,6 @@ function clearPluginUtilities() {
1964
1965
  function getPluginStandaloneMap() {
1965
1966
  return PLUGIN_STANDALONE;
1966
1967
  }
1967
- function getPluginResolverMap() {
1968
- return PLUGIN_RESOLVERS;
1969
- }
1970
1968
 
1971
1969
  // src/core/resolver.ts
1972
1970
  var styleCache = new LRUCache(1e4);
@@ -2212,6 +2210,28 @@ function getConfig() {
2212
2210
  store.resolved = buildConfig({});
2213
2211
  return store.resolved;
2214
2212
  }
2213
+ function resolveOneRef(ref, colors) {
2214
+ const m = /^([a-z][a-z0-9]*)-(\d+)$/.exec(ref);
2215
+ if (!m) return null;
2216
+ const entry = colors[m[1]];
2217
+ if (!entry || typeof entry !== "object") return null;
2218
+ return entry[m[2]] ?? null;
2219
+ }
2220
+ function resolveColorRefs(colors) {
2221
+ const out = {};
2222
+ for (const [key, val] of Object.entries(colors)) {
2223
+ if (typeof val === "string") {
2224
+ out[key] = resolveOneRef(val, colors) ?? val;
2225
+ } else {
2226
+ const shades = {};
2227
+ for (const [shade, hex] of Object.entries(val)) {
2228
+ shades[shade] = resolveOneRef(hex, colors) ?? hex;
2229
+ }
2230
+ out[key] = shades;
2231
+ }
2232
+ }
2233
+ return out;
2234
+ }
2215
2235
  function buildConfig(userConfig) {
2216
2236
  let theme = { ...defaultTheme };
2217
2237
  if (userConfig.theme) {
@@ -2230,6 +2250,7 @@ function buildConfig(userConfig) {
2230
2250
  }
2231
2251
  }
2232
2252
  }
2253
+ theme = { ...theme, colors: resolveColorRefs(theme.colors) };
2233
2254
  const resolved = {
2234
2255
  darkMode: userConfig.darkMode ?? "attribute",
2235
2256
  theme,
@@ -2245,7 +2266,6 @@ function buildConfig(userConfig) {
2245
2266
  }
2246
2267
  function makePluginAPI(theme) {
2247
2268
  const standalone = getPluginStandaloneMap();
2248
- const resolvers = getPluginResolverMap();
2249
2269
  return {
2250
2270
  addUtility(name, styles) {
2251
2271
  standalone[name] = styles;
@@ -2276,11 +2296,16 @@ function onConfigChange(listener) {
2276
2296
  function updateConfig(userConfig) {
2277
2297
  const store = getConfigStore();
2278
2298
  store.resolved = buildConfig(userConfig);
2299
+ store._src = userConfig;
2279
2300
  clearCache();
2280
2301
  for (const listener of store.listeners) {
2281
2302
  listener(store.resolved);
2282
2303
  }
2283
2304
  }
2305
+ function initConfig(userConfig) {
2306
+ if (getConfigStore()._src === userConfig) return;
2307
+ updateConfig(userConfig);
2308
+ }
2284
2309
  var customVariants = new Proxy(
2285
2310
  {},
2286
2311
  {
@@ -2409,7 +2434,8 @@ function ThemeProvider({
2409
2434
  }, []);
2410
2435
  (0, import_react3.useEffect)(() => {
2411
2436
  if (!configOverride) return;
2412
- setResolvedConfig(buildConfig(configOverride));
2437
+ updateConfig(configOverride);
2438
+ setResolvedConfig(getConfig());
2413
2439
  }, [configOverride]);
2414
2440
  (0, import_react3.useEffect)(() => {
2415
2441
  if (configOverride) return;
@@ -2747,6 +2773,7 @@ function cx(...classes) {
2747
2773
  defaultTheme,
2748
2774
  flatten,
2749
2775
  getConfig,
2776
+ initConfig,
2750
2777
  kb,
2751
2778
  parseClass,
2752
2779
  parseClasses,
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  defaultTheme,
7
7
  flatten,
8
8
  getConfig,
9
+ initConfig,
9
10
  isWeb,
10
11
  onConfigChange,
11
12
  parseClass,
@@ -15,7 +16,7 @@ import {
15
16
  syncGlobalDarkMode,
16
17
  updateConfig,
17
18
  useGlobalDarkMode
18
- } from "./chunk-V5KHX4CZ.mjs";
19
+ } from "./chunk-ADRZPFQC.mjs";
19
20
 
20
21
  // src/context.tsx
21
22
  import { createContext, useContext } from "react";
@@ -176,7 +177,8 @@ function ThemeProvider({
176
177
  }, []);
177
178
  useEffect(() => {
178
179
  if (!configOverride) return;
179
- setResolvedConfig(buildConfig(configOverride));
180
+ updateConfig(configOverride);
181
+ setResolvedConfig(getConfig());
180
182
  }, [configOverride]);
181
183
  useEffect(() => {
182
184
  if (configOverride) return;
@@ -447,6 +449,7 @@ export {
447
449
  defaultTheme,
448
450
  flatten,
449
451
  getConfig,
452
+ initConfig,
450
453
  kb,
451
454
  parseClass,
452
455
  parseClasses,
@@ -1870,9 +1870,6 @@ function clearPluginUtilities() {
1870
1870
  function getPluginStandaloneMap() {
1871
1871
  return PLUGIN_STANDALONE;
1872
1872
  }
1873
- function getPluginResolverMap() {
1874
- return PLUGIN_RESOLVERS;
1875
- }
1876
1873
 
1877
1874
  // src/core/resolver.ts
1878
1875
  var styleCache = new LRUCache(1e4);
@@ -2115,6 +2112,28 @@ function getConfig() {
2115
2112
  store.resolved = buildConfig({});
2116
2113
  return store.resolved;
2117
2114
  }
2115
+ function resolveOneRef(ref, colors) {
2116
+ const m = /^([a-z][a-z0-9]*)-(\d+)$/.exec(ref);
2117
+ if (!m) return null;
2118
+ const entry = colors[m[1]];
2119
+ if (!entry || typeof entry !== "object") return null;
2120
+ return entry[m[2]] ?? null;
2121
+ }
2122
+ function resolveColorRefs(colors) {
2123
+ const out = {};
2124
+ for (const [key, val] of Object.entries(colors)) {
2125
+ if (typeof val === "string") {
2126
+ out[key] = resolveOneRef(val, colors) ?? val;
2127
+ } else {
2128
+ const shades = {};
2129
+ for (const [shade, hex] of Object.entries(val)) {
2130
+ shades[shade] = resolveOneRef(hex, colors) ?? hex;
2131
+ }
2132
+ out[key] = shades;
2133
+ }
2134
+ }
2135
+ return out;
2136
+ }
2118
2137
  function buildConfig(userConfig) {
2119
2138
  let theme = { ...defaultTheme };
2120
2139
  if (userConfig.theme) {
@@ -2133,6 +2152,7 @@ function buildConfig(userConfig) {
2133
2152
  }
2134
2153
  }
2135
2154
  }
2155
+ theme = { ...theme, colors: resolveColorRefs(theme.colors) };
2136
2156
  const resolved = {
2137
2157
  darkMode: userConfig.darkMode ?? "attribute",
2138
2158
  theme,
@@ -2148,7 +2168,6 @@ function buildConfig(userConfig) {
2148
2168
  }
2149
2169
  function makePluginAPI(theme) {
2150
2170
  const standalone = getPluginStandaloneMap();
2151
- const resolvers = getPluginResolverMap();
2152
2171
  return {
2153
2172
  addUtility(name, styles) {
2154
2173
  standalone[name] = styles;
@@ -2,8 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-Q5RMVTAU.mjs";
6
- import "./chunk-V5KHX4CZ.mjs";
5
+ } from "./chunk-J322Q3UR.mjs";
6
+ import "./chunk-ADRZPFQC.mjs";
7
7
 
8
8
  // src/jsx-dev-runtime.tsx
9
9
  function jsxDEV(type, props, key, isStaticChildren, _source, _self) {
@@ -1869,9 +1869,6 @@ function clearPluginUtilities() {
1869
1869
  function getPluginStandaloneMap() {
1870
1870
  return PLUGIN_STANDALONE;
1871
1871
  }
1872
- function getPluginResolverMap() {
1873
- return PLUGIN_RESOLVERS;
1874
- }
1875
1872
 
1876
1873
  // src/core/resolver.ts
1877
1874
  var styleCache = new LRUCache(1e4);
@@ -2114,6 +2111,28 @@ function getConfig() {
2114
2111
  store.resolved = buildConfig({});
2115
2112
  return store.resolved;
2116
2113
  }
2114
+ function resolveOneRef(ref, colors) {
2115
+ const m = /^([a-z][a-z0-9]*)-(\d+)$/.exec(ref);
2116
+ if (!m) return null;
2117
+ const entry = colors[m[1]];
2118
+ if (!entry || typeof entry !== "object") return null;
2119
+ return entry[m[2]] ?? null;
2120
+ }
2121
+ function resolveColorRefs(colors) {
2122
+ const out = {};
2123
+ for (const [key, val] of Object.entries(colors)) {
2124
+ if (typeof val === "string") {
2125
+ out[key] = resolveOneRef(val, colors) ?? val;
2126
+ } else {
2127
+ const shades = {};
2128
+ for (const [shade, hex] of Object.entries(val)) {
2129
+ shades[shade] = resolveOneRef(hex, colors) ?? hex;
2130
+ }
2131
+ out[key] = shades;
2132
+ }
2133
+ }
2134
+ return out;
2135
+ }
2117
2136
  function buildConfig(userConfig) {
2118
2137
  let theme = { ...defaultTheme };
2119
2138
  if (userConfig.theme) {
@@ -2132,6 +2151,7 @@ function buildConfig(userConfig) {
2132
2151
  }
2133
2152
  }
2134
2153
  }
2154
+ theme = { ...theme, colors: resolveColorRefs(theme.colors) };
2135
2155
  const resolved = {
2136
2156
  darkMode: userConfig.darkMode ?? "attribute",
2137
2157
  theme,
@@ -2147,7 +2167,6 @@ function buildConfig(userConfig) {
2147
2167
  }
2148
2168
  function makePluginAPI(theme) {
2149
2169
  const standalone = getPluginStandaloneMap();
2150
- const resolvers = getPluginResolverMap();
2151
2170
  return {
2152
2171
  addUtility(name, styles) {
2153
2172
  standalone[name] = styles;
@@ -2,8 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-Q5RMVTAU.mjs";
6
- import "./chunk-V5KHX4CZ.mjs";
5
+ } from "./chunk-J322Q3UR.mjs";
6
+ import "./chunk-ADRZPFQC.mjs";
7
7
  export {
8
8
  Fragment,
9
9
  jsx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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",