@idealyst/theme 1.1.7 → 1.1.8

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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Component Style Types Registry
3
+ *
4
+ * This module provides type definitions for component styles used with
5
+ * defineStyle, extendStyle, and overrideStyle.
6
+ *
7
+ * Components register their style types via module augmentation:
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // In Text.styles.tsx
12
+ * declare module '@idealyst/theme' {
13
+ * interface ComponentStyleRegistry {
14
+ * Text: TextStyleDef;
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+
20
+ import type { TextStyle, ViewStyle } from 'react-native';
21
+
22
+ /**
23
+ * Registry interface that components augment to register their style types.
24
+ * This enables type-safe extendStyle and overrideStyle calls.
25
+ */
26
+ export interface ComponentStyleRegistry {
27
+ // Components augment this interface to add their style types
28
+ // Example: Text: { text: (params: TextStyleParams) => TextStyleObject }
29
+ }
30
+
31
+ /**
32
+ * Get the style definition type for a component.
33
+ * Returns the registered type or a loose Record type for unregistered components.
34
+ */
35
+ export type ComponentStyleDef<K extends string> = K extends keyof ComponentStyleRegistry
36
+ ? ComponentStyleRegistry[K]
37
+ : Record<string, any>;
38
+
39
+ /**
40
+ * Deep partial type that works with functions.
41
+ * For style functions, preserves the function signature but makes the return type partial.
42
+ */
43
+ export type DeepPartialStyle<T> = T extends (...args: infer A) => infer R
44
+ ? (...args: A) => DeepPartialStyle<R>
45
+ : T extends object
46
+ ? { [K in keyof T]?: DeepPartialStyle<T[K]> }
47
+ : T;
48
+
49
+ /**
50
+ * Style definition for extendStyle - requires functions with same params as base.
51
+ * All style properties must be functions to access dynamic params.
52
+ */
53
+ export type ExtendStyleDef<K extends string> = DeepPartialStyle<ComponentStyleDef<K>>;
54
+
55
+ /**
56
+ * Style definition for overrideStyle - requires full implementation with functions.
57
+ */
58
+ export type OverrideStyleDef<K extends string> = ComponentStyleDef<K>;
59
+
60
+ /**
61
+ * Helper to extract the params type from a dynamic style function.
62
+ * Use this to type your extension functions.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * type TextParams = StyleParams<TextStyleDef['text']>;
67
+ * // TextParams = { color?: TextColorVariant }
68
+ * ```
69
+ */
70
+ export type StyleParams<T> = T extends (params: infer P) => any ? P : never;
71
+
72
+ // =============================================================================
73
+ // Common Style Types
74
+ // =============================================================================
75
+
76
+ /**
77
+ * Base style object with optional variants and compound variants.
78
+ */
79
+ export interface StyleWithVariants<TVariants extends Record<string, any> = Record<string, any>> {
80
+ variants?: {
81
+ [K in keyof TVariants]?: {
82
+ [V in TVariants[K] extends string | boolean ? TVariants[K] : string]?: ViewStyle | TextStyle;
83
+ };
84
+ };
85
+ compoundVariants?: Array<{
86
+ [K in keyof TVariants]?: TVariants[K];
87
+ } & { styles: ViewStyle | TextStyle }>;
88
+ }
89
+
90
+ /**
91
+ * Dynamic style function type.
92
+ */
93
+ export type DynamicStyleFn<TParams, TStyle> = (params: TParams) => TStyle;
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Idealyst Style Generator CLI
4
+ *
5
+ * Reads idealyst.config.ts and generates flat Unistyles-compatible style files.
6
+ *
7
+ * Usage:
8
+ * npx ts-node packages/theme/src/config/cli.ts [config-path] [output-dir]
9
+ *
10
+ * Defaults:
11
+ * config-path: ./idealyst.config.ts
12
+ * output-dir: ./generated
13
+ */
14
+
15
+ import * as fs from 'fs';
16
+ import * as path from 'path';
17
+
18
+ // Dynamic import for ESM compatibility
19
+ async function main() {
20
+ const args = process.argv.slice(2);
21
+ const configPath = args[0] || './idealyst.config.ts';
22
+ const outputDir = args[1] || './generated';
23
+
24
+ console.log('🎨 Idealyst Style Generator');
25
+ console.log(` Config: ${configPath}`);
26
+ console.log(` Output: ${outputDir}`);
27
+ console.log('');
28
+
29
+ // Resolve paths
30
+ const resolvedConfigPath = path.resolve(process.cwd(), configPath);
31
+ const resolvedOutputDir = path.resolve(process.cwd(), outputDir);
32
+
33
+ // Check config exists
34
+ if (!fs.existsSync(resolvedConfigPath)) {
35
+ console.error(`❌ Config file not found: ${resolvedConfigPath}`);
36
+ console.error('');
37
+ console.error('Create an idealyst.config.ts file with your theme configuration.');
38
+ console.error('See the documentation for examples.');
39
+ process.exit(1);
40
+ }
41
+
42
+ // Import config dynamically
43
+ // Note: This requires ts-node or a pre-compiled config
44
+ let config;
45
+ try {
46
+ // Try to import the config
47
+ const configModule = await import(resolvedConfigPath);
48
+ config = configModule.default || configModule;
49
+ } catch (err) {
50
+ console.error(`❌ Failed to load config: ${err}`);
51
+ console.error('');
52
+ console.error('Make sure your config file:');
53
+ console.error(' 1. Is a valid TypeScript/JavaScript file');
54
+ console.error(' 2. Uses export default or named exports');
55
+ console.error(' 3. Has all required theme properties');
56
+ process.exit(1);
57
+ }
58
+
59
+ // Validate config
60
+ if (!config.themes || !config.themes.light || !config.themes.dark) {
61
+ console.error('❌ Invalid config: themes.light and themes.dark are required');
62
+ process.exit(1);
63
+ }
64
+
65
+ // Import generator
66
+ const { generateStyles } = await import('./generator');
67
+
68
+ // Generate styles
69
+ console.log('⚙️ Generating styles...');
70
+ const files = generateStyles(config);
71
+
72
+ // Ensure output directory exists
73
+ if (!fs.existsSync(resolvedOutputDir)) {
74
+ fs.mkdirSync(resolvedOutputDir, { recursive: true });
75
+ }
76
+
77
+ // Write files
78
+ for (const [filename, content] of Object.entries(files)) {
79
+ const filePath = path.join(resolvedOutputDir, filename);
80
+ fs.writeFileSync(filePath, content, 'utf-8');
81
+ console.log(` ✓ ${filename}`);
82
+ }
83
+
84
+ console.log('');
85
+ console.log(`✅ Generated ${Object.keys(files).length} files in ${outputDir}`);
86
+ console.log('');
87
+ console.log('Next steps:');
88
+ console.log(' 1. Import the generated unistyles.generated.ts in your app entry');
89
+ console.log(' 2. Update components to import from generated style files');
90
+ }
91
+
92
+ main().catch((err) => {
93
+ console.error('Fatal error:', err);
94
+ process.exit(1);
95
+ });