@kbach/react 0.2.4 → 0.2.6

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.
@@ -1043,6 +1043,25 @@ function resolveColor(value, colors, isArbitrary) {
1043
1043
  }
1044
1044
  }
1045
1045
  }
1046
+ if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
1047
+ if (hex in colors) {
1048
+ const alias = colors[hex];
1049
+ if (typeof alias === "string") hex = alias;
1050
+ else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
1051
+ } else {
1052
+ const aliasLastDash = hex.lastIndexOf("-");
1053
+ if (aliasLastDash > 0) {
1054
+ const aliasColorName = hex.slice(0, aliasLastDash);
1055
+ const aliasShade = hex.slice(aliasLastDash + 1);
1056
+ const aliasScale = colors[aliasColorName];
1057
+ if (aliasScale && typeof aliasScale === "object") {
1058
+ hex = aliasScale[aliasShade] ?? null;
1059
+ } else if (typeof aliasScale === "string") {
1060
+ hex = aliasScale;
1061
+ }
1062
+ }
1063
+ }
1064
+ }
1046
1065
  if (!hex) return null;
1047
1066
  if (!opacityPart) return hex;
1048
1067
  let alpha;
@@ -5,7 +5,7 @@ import {
5
5
  isWeb,
6
6
  resolve,
7
7
  useGlobalDarkMode
8
- } from "./chunk-IYY3U6L2.mjs";
8
+ } from "./chunk-7YSVROUJ.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
@@ -145,17 +145,16 @@ interface ThemeProviderProps {
145
145
  /** Initial mode. Falls back to persisted value, then 'system'. */
146
146
  defaultMode?: ThemeMode;
147
147
  /**
148
- * Explicit color scheme override for native with `defaultMode="system"`.
148
+ * System color scheme for native `defaultMode="system"`.
149
149
  *
150
- * On some Android devices the system scheme is not detected on startup
151
- * (the `appearanceChanged` event only fires on *changes*, not on launch when
152
- * the device was already dark). Pass `useColorScheme()` from `react-native`
153
- * here to guarantee correct detection:
150
+ * Pass the value of `useColorScheme()` from `react-native`. When importing
151
+ * `ThemeProvider` from `@kbach/native` this is handled automatically.
154
152
  *
153
+ * @example
155
154
  * ```tsx
156
155
  * import { useColorScheme } from 'react-native';
157
- * const scheme = useColorScheme();
158
- * <ThemeProvider defaultMode="system" colorScheme={scheme}>…</ThemeProvider>
156
+ * const colorScheme = useColorScheme();
157
+ * <ThemeProvider defaultMode="system" colorScheme={colorScheme}>…</ThemeProvider>
159
158
  * ```
160
159
  */
161
160
  colorScheme?: 'light' | 'dark' | null;
@@ -164,7 +163,7 @@ interface ThemeProviderProps {
164
163
  /** Disable persistence to localStorage */
165
164
  disablePersistence?: boolean;
166
165
  }
167
- declare function ThemeProvider({ children, defaultMode, colorScheme: colorSchemeProp, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
166
+ declare function ThemeProvider({ children, defaultMode, colorScheme, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
168
167
 
169
168
  type ToggleVariant = 'button' | 'switch' | 'icon-button';
170
169
  interface ThemeToggleProps {
package/dist/index.d.ts CHANGED
@@ -145,17 +145,16 @@ interface ThemeProviderProps {
145
145
  /** Initial mode. Falls back to persisted value, then 'system'. */
146
146
  defaultMode?: ThemeMode;
147
147
  /**
148
- * Explicit color scheme override for native with `defaultMode="system"`.
148
+ * System color scheme for native `defaultMode="system"`.
149
149
  *
150
- * On some Android devices the system scheme is not detected on startup
151
- * (the `appearanceChanged` event only fires on *changes*, not on launch when
152
- * the device was already dark). Pass `useColorScheme()` from `react-native`
153
- * here to guarantee correct detection:
150
+ * Pass the value of `useColorScheme()` from `react-native`. When importing
151
+ * `ThemeProvider` from `@kbach/native` this is handled automatically.
154
152
  *
153
+ * @example
155
154
  * ```tsx
156
155
  * import { useColorScheme } from 'react-native';
157
- * const scheme = useColorScheme();
158
- * <ThemeProvider defaultMode="system" colorScheme={scheme}>…</ThemeProvider>
156
+ * const colorScheme = useColorScheme();
157
+ * <ThemeProvider defaultMode="system" colorScheme={colorScheme}>…</ThemeProvider>
159
158
  * ```
160
159
  */
161
160
  colorScheme?: 'light' | 'dark' | null;
@@ -164,7 +163,7 @@ interface ThemeProviderProps {
164
163
  /** Disable persistence to localStorage */
165
164
  disablePersistence?: boolean;
166
165
  }
167
- declare function ThemeProvider({ children, defaultMode, colorScheme: colorSchemeProp, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
166
+ declare function ThemeProvider({ children, defaultMode, colorScheme, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
168
167
 
169
168
  type ToggleVariant = 'button' | 'switch' | 'icon-button';
170
169
  interface ThemeToggleProps {
package/dist/index.js CHANGED
@@ -1143,6 +1143,25 @@ function resolveColor(value, colors, isArbitrary) {
1143
1143
  }
1144
1144
  }
1145
1145
  }
1146
+ if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
1147
+ if (hex in colors) {
1148
+ const alias = colors[hex];
1149
+ if (typeof alias === "string") hex = alias;
1150
+ else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
1151
+ } else {
1152
+ const aliasLastDash = hex.lastIndexOf("-");
1153
+ if (aliasLastDash > 0) {
1154
+ const aliasColorName = hex.slice(0, aliasLastDash);
1155
+ const aliasShade = hex.slice(aliasLastDash + 1);
1156
+ const aliasScale = colors[aliasColorName];
1157
+ if (aliasScale && typeof aliasScale === "object") {
1158
+ hex = aliasScale[aliasShade] ?? null;
1159
+ } else if (typeof aliasScale === "string") {
1160
+ hex = aliasScale;
1161
+ }
1162
+ }
1163
+ }
1164
+ }
1146
1165
  if (!hex) return null;
1147
1166
  if (!opacityPart) return hex;
1148
1167
  let alpha;
@@ -2065,11 +2084,6 @@ function subscribeGlobalDarkMode(callback) {
2065
2084
 
2066
2085
  // src/ThemeProvider.tsx
2067
2086
  var import_jsx_runtime = require("react/jsx-runtime");
2068
- var _useColorScheme;
2069
- try {
2070
- ({ useColorScheme: _useColorScheme } = require("react-native"));
2071
- } catch {
2072
- }
2073
2087
  var STORAGE_KEY = "kbach-theme";
2074
2088
  function loadPersistedMode() {
2075
2089
  try {
@@ -2098,23 +2112,20 @@ function applyWebTheme(resolvedMode, strategy) {
2098
2112
  function ThemeProvider({
2099
2113
  children,
2100
2114
  defaultMode = "system",
2101
- colorScheme: colorSchemeProp,
2115
+ colorScheme,
2102
2116
  config: configOverride,
2103
2117
  disablePersistence = false
2104
2118
  }) {
2105
2119
  const [resolvedConfig, setResolvedConfig] = (0, import_react2.useState)(
2106
2120
  () => configOverride ? buildConfig(configOverride) : getConfig()
2107
2121
  );
2108
- const [nativeSchemeFallback, setNativeSchemeFallback] = (0, import_react2.useState)(null);
2109
- const hookScheme = _useColorScheme?.();
2110
- const nativeScheme = colorSchemeProp !== void 0 ? colorSchemeProp ?? null : hookScheme ?? nativeSchemeFallback;
2111
2122
  const [webScheme, setWebScheme] = (0, import_react2.useState)(() => {
2112
2123
  if (isWeb && typeof window !== "undefined") {
2113
2124
  return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2114
2125
  }
2115
2126
  return "light";
2116
2127
  });
2117
- const systemScheme = isWeb ? webScheme : nativeScheme === "dark" ? "dark" : "light";
2128
+ const systemScheme = isWeb ? webScheme : colorScheme === "dark" ? "dark" : "light";
2118
2129
  const [mode, _setMode] = (0, import_react2.useState)(() => {
2119
2130
  if (!disablePersistence) {
2120
2131
  const persisted = loadPersistedMode();
@@ -2132,18 +2143,6 @@ function ThemeProvider({
2132
2143
  const resolvedMode = mode === "system" ? systemScheme : mode;
2133
2144
  const isDark = resolvedMode === "dark";
2134
2145
  syncGlobalDarkMode(isDark);
2135
- (0, import_react2.useEffect)(() => {
2136
- if (isWeb) return;
2137
- try {
2138
- const { TurboModuleRegistry } = require("react-native");
2139
- const native = TurboModuleRegistry?.get?.("Appearance");
2140
- const scheme = native?.getColorScheme?.();
2141
- if (scheme === "dark" || scheme === "light") {
2142
- setNativeSchemeFallback(scheme);
2143
- }
2144
- } catch {
2145
- }
2146
- }, []);
2147
2146
  (0, import_react2.useEffect)(() => {
2148
2147
  applyWebTheme(resolvedMode, resolvedConfig.darkMode);
2149
2148
  setGlobalDarkMode(isDark);
package/dist/index.mjs CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  syncGlobalDarkMode,
16
16
  updateConfig,
17
17
  useGlobalDarkMode
18
- } from "./chunk-IYY3U6L2.mjs";
18
+ } from "./chunk-7YSVROUJ.mjs";
19
19
 
20
20
  // src/context.tsx
21
21
  import { createContext, useContext } from "react";
@@ -39,11 +39,6 @@ import {
39
39
  useState
40
40
  } from "react";
41
41
  import { jsx } from "react/jsx-runtime";
42
- var _useColorScheme;
43
- try {
44
- ({ useColorScheme: _useColorScheme } = __require("react-native"));
45
- } catch {
46
- }
47
42
  var STORAGE_KEY = "kbach-theme";
48
43
  function loadPersistedMode() {
49
44
  try {
@@ -72,23 +67,20 @@ function applyWebTheme(resolvedMode, strategy) {
72
67
  function ThemeProvider({
73
68
  children,
74
69
  defaultMode = "system",
75
- colorScheme: colorSchemeProp,
70
+ colorScheme,
76
71
  config: configOverride,
77
72
  disablePersistence = false
78
73
  }) {
79
74
  const [resolvedConfig, setResolvedConfig] = useState(
80
75
  () => configOverride ? buildConfig(configOverride) : getConfig()
81
76
  );
82
- const [nativeSchemeFallback, setNativeSchemeFallback] = useState(null);
83
- const hookScheme = _useColorScheme?.();
84
- const nativeScheme = colorSchemeProp !== void 0 ? colorSchemeProp ?? null : hookScheme ?? nativeSchemeFallback;
85
77
  const [webScheme, setWebScheme] = useState(() => {
86
78
  if (isWeb && typeof window !== "undefined") {
87
79
  return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
88
80
  }
89
81
  return "light";
90
82
  });
91
- const systemScheme = isWeb ? webScheme : nativeScheme === "dark" ? "dark" : "light";
83
+ const systemScheme = isWeb ? webScheme : colorScheme === "dark" ? "dark" : "light";
92
84
  const [mode, _setMode] = useState(() => {
93
85
  if (!disablePersistence) {
94
86
  const persisted = loadPersistedMode();
@@ -106,18 +98,6 @@ function ThemeProvider({
106
98
  const resolvedMode = mode === "system" ? systemScheme : mode;
107
99
  const isDark = resolvedMode === "dark";
108
100
  syncGlobalDarkMode(isDark);
109
- useEffect(() => {
110
- if (isWeb) return;
111
- try {
112
- const { TurboModuleRegistry } = __require("react-native");
113
- const native = TurboModuleRegistry?.get?.("Appearance");
114
- const scheme = native?.getColorScheme?.();
115
- if (scheme === "dark" || scheme === "light") {
116
- setNativeSchemeFallback(scheme);
117
- }
118
- } catch {
119
- }
120
- }, []);
121
101
  useEffect(() => {
122
102
  applyWebTheme(resolvedMode, resolvedConfig.darkMode);
123
103
  setGlobalDarkMode(isDark);
@@ -1112,6 +1112,25 @@ function resolveColor(value, colors, isArbitrary) {
1112
1112
  }
1113
1113
  }
1114
1114
  }
1115
+ if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
1116
+ if (hex in colors) {
1117
+ const alias = colors[hex];
1118
+ if (typeof alias === "string") hex = alias;
1119
+ else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
1120
+ } else {
1121
+ const aliasLastDash = hex.lastIndexOf("-");
1122
+ if (aliasLastDash > 0) {
1123
+ const aliasColorName = hex.slice(0, aliasLastDash);
1124
+ const aliasShade = hex.slice(aliasLastDash + 1);
1125
+ const aliasScale = colors[aliasColorName];
1126
+ if (aliasScale && typeof aliasScale === "object") {
1127
+ hex = aliasScale[aliasShade] ?? null;
1128
+ } else if (typeof aliasScale === "string") {
1129
+ hex = aliasScale;
1130
+ }
1131
+ }
1132
+ }
1133
+ }
1115
1134
  if (!hex) return null;
1116
1135
  if (!opacityPart) return hex;
1117
1136
  let alpha;
@@ -2,8 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-23GRUDYB.mjs";
6
- import "./chunk-IYY3U6L2.mjs";
5
+ } from "./chunk-XW4LEBBB.mjs";
6
+ import "./chunk-7YSVROUJ.mjs";
7
7
 
8
8
  // src/jsx-dev-runtime.tsx
9
9
  function jsxDEV(type, props, key, isStaticChildren, _source, _self) {
@@ -1111,6 +1111,25 @@ function resolveColor(value, colors, isArbitrary) {
1111
1111
  }
1112
1112
  }
1113
1113
  }
1114
+ if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
1115
+ if (hex in colors) {
1116
+ const alias = colors[hex];
1117
+ if (typeof alias === "string") hex = alias;
1118
+ else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
1119
+ } else {
1120
+ const aliasLastDash = hex.lastIndexOf("-");
1121
+ if (aliasLastDash > 0) {
1122
+ const aliasColorName = hex.slice(0, aliasLastDash);
1123
+ const aliasShade = hex.slice(aliasLastDash + 1);
1124
+ const aliasScale = colors[aliasColorName];
1125
+ if (aliasScale && typeof aliasScale === "object") {
1126
+ hex = aliasScale[aliasShade] ?? null;
1127
+ } else if (typeof aliasScale === "string") {
1128
+ hex = aliasScale;
1129
+ }
1130
+ }
1131
+ }
1132
+ }
1114
1133
  if (!hex) return null;
1115
1134
  if (!opacityPart) return hex;
1116
1135
  let alpha;
@@ -2,8 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-23GRUDYB.mjs";
6
- import "./chunk-IYY3U6L2.mjs";
5
+ } from "./chunk-XW4LEBBB.mjs";
6
+ import "./chunk-7YSVROUJ.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.2.4",
3
+ "version": "0.2.6",
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",