native-variants 0.1.63 → 0.1.69

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.
Files changed (37) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +125 -125
  3. package/dist/example.js +1 -0
  4. package/dist/index.d.ts +17 -8
  5. package/dist/index.js +72 -22
  6. package/dist/index.js.map +1 -1
  7. package/dist/lib/cn.d.ts +82 -2
  8. package/dist/lib/cn.js +138 -8
  9. package/dist/lib/cn.js.map +1 -1
  10. package/dist/lib/create-nva.d.ts +209 -6
  11. package/dist/lib/create-nva.js +460 -47
  12. package/dist/lib/create-nva.js.map +1 -1
  13. package/dist/lib/media-query.d.ts +84 -2
  14. package/dist/lib/media-query.js +103 -9
  15. package/dist/lib/media-query.js.map +1 -1
  16. package/dist/provider/create-provider.d.ts +44 -4
  17. package/dist/provider/create-provider.js +1 -1
  18. package/dist/provider/create-provider.jsx +110 -9
  19. package/dist/provider/create-provider.jsx.map +1 -1
  20. package/dist/provider/theme-provider.d.ts +266 -0
  21. package/dist/provider/theme-provider.js +1 -0
  22. package/dist/provider/theme-provider.jsx +328 -0
  23. package/dist/provider/theme-provider.jsx.map +1 -0
  24. package/dist/tokens/default-tokens.d.ts +2737 -0
  25. package/dist/tokens/default-tokens.js +1067 -0
  26. package/dist/tokens/default-tokens.js.map +1 -0
  27. package/dist/types.d.ts +318 -3
  28. package/dist/utils/alpha.d.ts +68 -0
  29. package/dist/utils/alpha.js +147 -4
  30. package/dist/utils/alpha.js.map +1 -1
  31. package/dist/utils/compose-text.d.ts +64 -2
  32. package/dist/utils/compose-text.js +103 -3
  33. package/dist/utils/compose-text.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/utils/compose-refs.d.ts +0 -4
  36. package/dist/utils/compose-refs.js +0 -39
  37. package/dist/utils/compose-refs.js.map +0 -1
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ThemeProvider = ThemeProvider;
37
+ exports.useTheme = useTheme;
38
+ exports.useThemeColors = useThemeColors;
39
+ exports.useIsDark = useIsDark;
40
+ exports.useColorScheme = useColorScheme;
41
+ exports.createThemedStyles = createThemedStyles;
42
+ const react_1 = __importStar(require("react"));
43
+ const react_native_1 = require("react-native");
44
+ // Create context with any type to allow generic usage
45
+ const ThemeContext = (0, react_1.createContext)(undefined);
46
+ /**
47
+ * Resolves the actual color scheme from mode and system preference.
48
+ */
49
+ function resolveColorScheme(mode, systemScheme) {
50
+ if (mode === "system") {
51
+ return systemScheme === "dark" ? "dark" : "light";
52
+ }
53
+ return mode;
54
+ }
55
+ /**
56
+ * ThemeProvider component.
57
+ * Provides theme context with dark/light mode support.
58
+ *
59
+ * **Important:** This provider requires colors to be passed explicitly.
60
+ * Get colors from createNVA's colorScheme output.
61
+ *
62
+ * @template T - The colors type
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * // 1. Create your theme with createNVA
67
+ * const { theme, colorScheme, styled } = createNVA({
68
+ * theme: {
69
+ * colors: {
70
+ * default: {
71
+ * background: "#ffffff",
72
+ * foreground: "#000000",
73
+ * primary: "#3b82f6",
74
+ * },
75
+ * dark: {
76
+ * background: "#0a0a0a",
77
+ * foreground: "#ffffff",
78
+ * primary: "#60a5fa",
79
+ * },
80
+ * },
81
+ * },
82
+ * });
83
+ *
84
+ * // 2. Wrap your app with ThemeProvider
85
+ * function App() {
86
+ * return (
87
+ * <ThemeProvider colors={colorScheme}>
88
+ * <MyApp />
89
+ * </ThemeProvider>
90
+ * );
91
+ * }
92
+ *
93
+ * // 3. Use colors in components
94
+ * function MyComponent() {
95
+ * const { colors, isDark, toggle } = useTheme();
96
+ *
97
+ * return (
98
+ * <View style={{ backgroundColor: colors.background }}>
99
+ * <Text style={{ color: colors.foreground }}>
100
+ * {isDark ? "Dark Mode" : "Light Mode"}
101
+ * </Text>
102
+ * <Button onPress={toggle} title="Toggle" />
103
+ * </View>
104
+ * );
105
+ * }
106
+ *
107
+ * // With AsyncStorage persistence
108
+ * import AsyncStorage from "@react-native-async-storage/async-storage";
109
+ *
110
+ * <ThemeProvider
111
+ * colors={colorScheme}
112
+ * defaultMode="system"
113
+ * onGetStorage={async () => {
114
+ * const mode = await AsyncStorage.getItem("theme-mode");
115
+ * return mode as ThemeMode | null;
116
+ * }}
117
+ * onSetStorage={async (mode) => {
118
+ * await AsyncStorage.setItem("theme-mode", mode);
119
+ * }}
120
+ * >
121
+ * <App />
122
+ * </ThemeProvider>
123
+ * ```
124
+ */
125
+ function ThemeProvider({ children, colors, defaultMode = "system", onGetStorage, onSetStorage, }) {
126
+ const [mode, setModeState] = (0, react_1.useState)(defaultMode);
127
+ const [systemScheme, setSystemScheme] = (0, react_1.useState)(react_native_1.Appearance.getColorScheme());
128
+ const [isHydrated, setIsHydrated] = (0, react_1.useState)(!onGetStorage);
129
+ // Load persisted mode on mount
130
+ (0, react_1.useEffect)(() => {
131
+ if (onGetStorage) {
132
+ onGetStorage().then((storedMode) => {
133
+ if (storedMode) {
134
+ setModeState(storedMode);
135
+ }
136
+ setIsHydrated(true);
137
+ });
138
+ }
139
+ }, [onGetStorage]);
140
+ // Listen to system color scheme changes
141
+ (0, react_1.useEffect)(() => {
142
+ const subscription = react_native_1.Appearance.addChangeListener(({ colorScheme }) => {
143
+ setSystemScheme(colorScheme);
144
+ });
145
+ return () => subscription.remove();
146
+ }, []);
147
+ // Set mode with optional persistence
148
+ const setMode = (0, react_1.useCallback)((newMode) => {
149
+ setModeState(newMode);
150
+ if (onSetStorage) {
151
+ onSetStorage(newMode);
152
+ }
153
+ }, [onSetStorage]);
154
+ // Toggle between light and dark
155
+ const toggle = (0, react_1.useCallback)(() => {
156
+ const currentScheme = resolveColorScheme(mode, systemScheme);
157
+ const newMode = currentScheme === "light" ? "dark" : "light";
158
+ setMode(newMode);
159
+ }, [mode, systemScheme, setMode]);
160
+ // Compute context value
161
+ const value = (0, react_1.useMemo)(() => {
162
+ const colorScheme = resolveColorScheme(mode, systemScheme);
163
+ return {
164
+ colorScheme,
165
+ mode,
166
+ isDark: colorScheme === "dark",
167
+ colors: (colorScheme === "dark" ? colors.dark : colors.default),
168
+ setMode,
169
+ toggle,
170
+ };
171
+ }, [mode, systemScheme, colors, setMode, toggle]);
172
+ // Don't render until hydrated to prevent flash
173
+ if (!isHydrated) {
174
+ return null;
175
+ }
176
+ return (<ThemeContext.Provider value={value}>
177
+ {children}
178
+ </ThemeContext.Provider>);
179
+ }
180
+ /**
181
+ * Hook to access theme context.
182
+ * Must be used within a ThemeProvider.
183
+ *
184
+ * @template T - The colors type
185
+ * @returns Theme context value with colors and controls
186
+ * @throws Error if used outside ThemeProvider
187
+ *
188
+ * @example
189
+ * ```tsx
190
+ * function MyComponent() {
191
+ * const { colors, isDark, toggle, setMode } = useTheme<MyColors>();
192
+ *
193
+ * return (
194
+ * <View style={{ backgroundColor: colors.background }}>
195
+ * <Text style={{ color: colors.foreground }}>
196
+ * Current mode: {isDark ? "Dark" : "Light"}
197
+ * </Text>
198
+ * <Button onPress={toggle} title="Toggle Theme" />
199
+ * <Button onPress={() => setMode("system")} title="Use System" />
200
+ * </View>
201
+ * );
202
+ * }
203
+ * ```
204
+ */
205
+ function useTheme() {
206
+ const context = (0, react_1.useContext)(ThemeContext);
207
+ if (!context) {
208
+ throw new Error("useTheme must be used within a ThemeProvider. " +
209
+ "Make sure to wrap your app with <ThemeProvider colors={colorScheme}>.");
210
+ }
211
+ return context;
212
+ }
213
+ /**
214
+ * Hook to access only theme colors.
215
+ * Convenience wrapper around useTheme that returns just the colors.
216
+ *
217
+ * @template T - The colors type
218
+ * @returns Current theme colors
219
+ *
220
+ * @example
221
+ * ```tsx
222
+ * function MyComponent() {
223
+ * const colors = useThemeColors<MyColors>();
224
+ *
225
+ * return (
226
+ * <View style={{ backgroundColor: colors.background }}>
227
+ * <Text style={{ color: colors.primary }}>Hello</Text>
228
+ * </View>
229
+ * );
230
+ * }
231
+ * ```
232
+ */
233
+ function useThemeColors() {
234
+ const { colors } = useTheme();
235
+ return colors;
236
+ }
237
+ /**
238
+ * Hook to check if dark mode is active.
239
+ * Convenience wrapper for quick dark mode checks.
240
+ *
241
+ * @returns Boolean indicating if dark mode is active
242
+ *
243
+ * @example
244
+ * ```tsx
245
+ * function MyComponent() {
246
+ * const isDark = useIsDark();
247
+ *
248
+ * return (
249
+ * <Image source={isDark ? darkLogo : lightLogo} />
250
+ * );
251
+ * }
252
+ * ```
253
+ */
254
+ function useIsDark() {
255
+ const { isDark } = useTheme();
256
+ return isDark;
257
+ }
258
+ /**
259
+ * Hook to get the current color scheme.
260
+ * Returns "light" or "dark" based on current theme.
261
+ *
262
+ * @returns Current color scheme
263
+ *
264
+ * @example
265
+ * ```tsx
266
+ * function MyComponent() {
267
+ * const colorScheme = useColorScheme();
268
+ *
269
+ * return (
270
+ * <StatusBar barStyle={colorScheme === "dark" ? "light-content" : "dark-content"} />
271
+ * );
272
+ * }
273
+ * ```
274
+ */
275
+ function useColorScheme() {
276
+ const { colorScheme } = useTheme();
277
+ return colorScheme;
278
+ }
279
+ /**
280
+ * Creates a themed style helper that automatically uses current theme colors.
281
+ * Useful for creating styled components with theme access.
282
+ *
283
+ * @template T - The colors type
284
+ * @template S - The styles record type
285
+ * @param styleFactory - Function that receives colors and returns styles
286
+ * @returns Hook that returns computed styles
287
+ *
288
+ * @example
289
+ * ```tsx
290
+ * type MyColors = { card: string; border: string; cardForeground: string };
291
+ *
292
+ * const useCardStyles = createThemedStyles<MyColors, {
293
+ * container: ViewStyle;
294
+ * title: TextStyle;
295
+ * }>((colors) => ({
296
+ * container: {
297
+ * backgroundColor: colors.card,
298
+ * borderColor: colors.border,
299
+ * borderWidth: 1,
300
+ * borderRadius: 8,
301
+ * padding: 16,
302
+ * },
303
+ * title: {
304
+ * color: colors.cardForeground,
305
+ * fontSize: 18,
306
+ * fontWeight: "600",
307
+ * },
308
+ * }));
309
+ *
310
+ * function Card({ title, children }) {
311
+ * const styles = useCardStyles();
312
+ *
313
+ * return (
314
+ * <View style={styles.container}>
315
+ * <Text style={styles.title}>{title}</Text>
316
+ * {children}
317
+ * </View>
318
+ * );
319
+ * }
320
+ * ```
321
+ */
322
+ function createThemedStyles(styleFactory) {
323
+ return function useThemedStyles() {
324
+ const { colors } = useTheme();
325
+ return (0, react_1.useMemo)(() => styleFactory(colors), [colors]);
326
+ };
327
+ }
328
+ //# sourceMappingURL=theme-provider.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-provider.jsx","sourceRoot":"","sources":["../../src/provider/theme-provider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuKA,s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