@umituz/react-native-design-system 2.8.8 → 2.8.9

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 (65) hide show
  1. package/package.json +6 -1
  2. package/src/exports/media.ts +1 -0
  3. package/src/index.ts +5 -0
  4. package/src/media/domain/entities/CardMultimedia.types.README.md +129 -0
  5. package/src/media/domain/entities/CardMultimedia.types.ts +105 -0
  6. package/src/media/domain/entities/Media.README.md +80 -0
  7. package/src/media/domain/entities/Media.ts +139 -0
  8. package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +144 -0
  9. package/src/media/domain/entities/MultimediaFlashcardTypes.ts +105 -0
  10. package/src/media/domain/utils/MediaUtils.README.md +178 -0
  11. package/src/media/domain/utils/MediaUtils.ts +82 -0
  12. package/src/media/index.ts +70 -0
  13. package/src/media/index.ts.README.md +191 -0
  14. package/src/media/infrastructure/services/CardMediaGenerationService.README.md +99 -0
  15. package/src/media/infrastructure/services/CardMediaGenerationService.ts +101 -0
  16. package/src/media/infrastructure/services/CardMediaOptimizerService.README.md +167 -0
  17. package/src/media/infrastructure/services/CardMediaOptimizerService.ts +36 -0
  18. package/src/media/infrastructure/services/CardMediaUploadService.README.md +123 -0
  19. package/src/media/infrastructure/services/CardMediaUploadService.ts +67 -0
  20. package/src/media/infrastructure/services/CardMediaValidationService.README.md +134 -0
  21. package/src/media/infrastructure/services/CardMediaValidationService.ts +81 -0
  22. package/src/media/infrastructure/services/CardMultimediaService.README.md +176 -0
  23. package/src/media/infrastructure/services/CardMultimediaService.ts +97 -0
  24. package/src/media/infrastructure/services/MediaGenerationService.README.md +142 -0
  25. package/src/media/infrastructure/services/MediaGenerationService.ts +80 -0
  26. package/src/media/infrastructure/services/MediaOptimizerService.README.md +145 -0
  27. package/src/media/infrastructure/services/MediaOptimizerService.ts +32 -0
  28. package/src/media/infrastructure/services/MediaPickerService.README.md +106 -0
  29. package/src/media/infrastructure/services/MediaPickerService.ts +173 -0
  30. package/src/media/infrastructure/services/MediaSaveService.README.md +120 -0
  31. package/src/media/infrastructure/services/MediaSaveService.ts +154 -0
  32. package/src/media/infrastructure/services/MediaUploadService.README.md +135 -0
  33. package/src/media/infrastructure/services/MediaUploadService.ts +62 -0
  34. package/src/media/infrastructure/services/MediaValidationService.README.md +135 -0
  35. package/src/media/infrastructure/services/MediaValidationService.ts +61 -0
  36. package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +142 -0
  37. package/src/media/infrastructure/services/MultimediaFlashcardService.ts +95 -0
  38. package/src/media/infrastructure/utils/mediaHelpers.README.md +96 -0
  39. package/src/media/infrastructure/utils/mediaHelpers.ts +82 -0
  40. package/src/media/infrastructure/utils/mediaPickerMappers.README.md +129 -0
  41. package/src/media/infrastructure/utils/mediaPickerMappers.ts +76 -0
  42. package/src/media/presentation/hooks/card-multimedia.types.README.md +177 -0
  43. package/src/media/presentation/hooks/card-multimedia.types.ts +51 -0
  44. package/src/media/presentation/hooks/multimedia.types.README.md +201 -0
  45. package/src/media/presentation/hooks/multimedia.types.ts +51 -0
  46. package/src/media/presentation/hooks/useCardMediaGeneration.README.md +164 -0
  47. package/src/media/presentation/hooks/useCardMediaGeneration.ts +124 -0
  48. package/src/media/presentation/hooks/useCardMediaUpload.README.md +153 -0
  49. package/src/media/presentation/hooks/useCardMediaUpload.ts +86 -0
  50. package/src/media/presentation/hooks/useCardMediaValidation.README.md +176 -0
  51. package/src/media/presentation/hooks/useCardMediaValidation.ts +101 -0
  52. package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +158 -0
  53. package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +104 -0
  54. package/src/media/presentation/hooks/useMedia.README.md +94 -0
  55. package/src/media/presentation/hooks/useMedia.ts +186 -0
  56. package/src/media/presentation/hooks/useMediaGeneration.README.md +118 -0
  57. package/src/media/presentation/hooks/useMediaGeneration.ts +101 -0
  58. package/src/media/presentation/hooks/useMediaUpload.README.md +108 -0
  59. package/src/media/presentation/hooks/useMediaUpload.ts +86 -0
  60. package/src/media/presentation/hooks/useMediaValidation.README.md +134 -0
  61. package/src/media/presentation/hooks/useMediaValidation.ts +93 -0
  62. package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +141 -0
  63. package/src/media/presentation/hooks/useMultimediaFlashcard.ts +103 -0
  64. package/src/storage/infrastructure/repositories/__tests__/AsyncStorageRepository.test.ts +1 -1
  65. package/src/storage/infrastructure/repositories/__tests__/BaseStorageOperations.test.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-design-system",
3
- "version": "2.8.8",
3
+ "version": "2.8.9",
4
4
  "description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, and onboarding utilities",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -25,6 +25,7 @@
25
25
  "./onboarding": "./src/onboarding/index.ts",
26
26
  "./storage": "./src/storage/index.ts",
27
27
  "./filesystem": "./src/filesystem/index.ts",
28
+ "./media": "./src/media/index.ts",
28
29
  "./package.json": "./package.json"
29
30
  },
30
31
  "scripts": {
@@ -75,6 +76,8 @@
75
76
  "expo-font": ">=12.0.0",
76
77
  "expo-image": ">=3.0.0",
77
78
  "expo-image-manipulator": ">=12.0.0",
79
+ "expo-image-picker": ">=14.0.0",
80
+ "expo-media-library": ">=15.0.0",
78
81
  "expo-network": ">=8.0.0",
79
82
  "expo-secure-store": ">=14.0.0",
80
83
  "expo-sharing": ">=12.0.0",
@@ -129,6 +132,8 @@
129
132
  "expo-video": "~3.0.0",
130
133
  "expo-haptics": "~14.0.0",
131
134
  "expo-image-manipulator": "~13.0.0",
135
+ "expo-image-picker": "~16.0.0",
136
+ "expo-media-library": "~17.0.0",
132
137
  "expo-image": "~3.0.11",
133
138
  "expo-localization": "~16.0.1",
134
139
  "expo-secure-store": "~14.0.0",
@@ -0,0 +1 @@
1
+ export * from "../media";
package/src/index.ts CHANGED
@@ -115,3 +115,8 @@ export * from './exports/onboarding';
115
115
  // FILESYSTEM EXPORTS
116
116
  // =============================================================================
117
117
  export * from './exports/filesystem';
118
+
119
+ // =============================================================================
120
+ // MEDIA EXPORTS
121
+ // =============================================================================
122
+ export * from './exports/media';
@@ -0,0 +1,129 @@
1
+ # CardMultimedia Types
2
+
3
+ ## Purpose
4
+ Type definitions for flashcard-specific media operations. These types define the contract for media attachment, generation, and management within the card-based learning system.
5
+
6
+ ## File Location
7
+ `src/domain/entities/CardMultimedia.types.ts`
8
+
9
+ ## Strategy
10
+ - Define the contract for card-specific media operations
11
+ - Provide type-safe interfaces for flashcard media attachments
12
+ - Support AI-powered media generation for educational content
13
+ - Enable comprehensive media validation and optimization
14
+ - Maintain clear separation between card media and general media types
15
+ - Support upload progress tracking and compression
16
+ - Facilitate media download management for offline learning
17
+
18
+ ## Forbidden
19
+ - **DO NOT** use these types for general-purpose media operations (use Multimedia types instead)
20
+ - **DO NOT** include UI components or presentation logic in type definitions
21
+ - **DO NOT** add business logic or implementation details to interfaces
22
+ - **DO NOT** create circular dependencies with other domain types
23
+ - **DO NOT** use `any` type or loose type definitions
24
+ - **DO NOT** modify existing type properties - extend interfaces for new features
25
+ - **DO NOT** assume specific storage backend or cloud provider
26
+ - **DO NOT** hardcode validation limits in type definitions
27
+ - **DO NOT** mix card media types with general multimedia types
28
+
29
+ ## Rules
30
+ 1. All card media types must be exported from this file
31
+ 2. Type definitions must be framework-agnostic
32
+ 3. Card media IDs must use "card_media_" prefix for uniqueness
33
+ 4. Position types must explicitly define front/back/both placement
34
+ 5. File size fields must use bytes as unit
35
+ 6. Duration fields must use seconds as unit
36
+ 7. Date fields must use ISO 8601 format
37
+ 8. All generation requests must include input validation
38
+ 9. Compression quality must be between 0.1 and 1.0
39
+ 10. Upload progress must be tracked from 0-100
40
+ 11. Validation results must separate errors, warnings, and recommendations
41
+ 12. Service interfaces must return Promises for all async operations
42
+ 13. Media type arrays must be automatically calculated, not manually set
43
+ 14. Download status must be tracked per attachment
44
+ 15. Estimated size must represent total of all attachments
45
+
46
+ ## AI Agent Guidelines
47
+
48
+ When working with CardMultimedia types:
49
+
50
+ 1. **Type Selection**: Use CardMediaAttachment for flashcard-specific media operations
51
+ 2. **Generation Requests**: Always specify input parameters and options explicitly
52
+ 3. **Validation**: Validate media files before upload and after generation
53
+ 4. **Progress Tracking**: Monitor upload progress for user feedback
54
+ 5. **Compression**: Apply compression options before upload to reduce bandwidth
55
+ 6. **Download Management**: Check isDownloaded status before displaying media
56
+ 7. **Position Logic**: Respect position field for front/back/both placement
57
+ 8. **Size Estimation**: Calculate total size for all media before batch operations
58
+ 9. **Error Handling**: Parse validation errors and warnings for user feedback
59
+ 10. **Cost Tracking**: Monitor creditsUsed for AI generation operations
60
+
61
+ ### Key Types Reference
62
+
63
+ - **CardMediaType**: "image" | "audio" | "video" - Media type classification for cards
64
+ - **CardMediaPosition**: "front" | "back" | "both" - Display placement on card faces
65
+ - **CardMediaAttachment**: Core interface for individual media items with metadata
66
+ - **CardMultimediaFlashcard**: Card entity with computed media properties
67
+ - **CardMediaGenerationRequest**: Input specification for AI media generation
68
+ - **CardMediaGenerationResult**: Output with cost tracking and performance metrics
69
+ - **CardMediaUploadProgress**: Real-time upload status tracking
70
+ - **CardMediaCompressionOptions**: Quality and size optimization settings
71
+ - **CardMediaValidation**: Comprehensive validation with recommendations
72
+ - **CardMultimediaFlashcardService**: Service interface for media operations
73
+
74
+ ### Type Usage Patterns
75
+
76
+ 1. **CardMediaAttachment**: Individual media item with position, URL, and metadata
77
+ 2. **CardMultimediaFlashcard**: Card with computed properties (hasMedia, mediaType, isDownloaded)
78
+ 3. **CardMediaGenerationRequest**: Three generation types (text_to_image, text_to_audio, image_search)
79
+ 4. **CardMediaValidation**: Separate errors (blocking) from warnings and recommendations
80
+
81
+ ### Validation Rules
82
+
83
+ 1. Validate file size against upload limits before processing
84
+ 2. Check MIME type matches CardMediaType
85
+ 3. Ensure dimensions are within supported ranges
86
+ 4. Verify URIs are properly formatted and accessible
87
+ 5. Validate duration for audio/video files
88
+ 6. Check compression quality is within 0.1-1.0 range
89
+ 7. Ensure generation prompts are non-empty strings
90
+ 8. Validate language codes for audio generation (e.g., "tr-TR", "en-US")
91
+
92
+ ### Service Interface Guidelines
93
+
94
+ When implementing CardMultimediaFlashcardService:
95
+
96
+ 1. **uploadMedia**: Accept file with optional compression, return attachment with URL
97
+ 2. **generateMedia**: Process AI generation request, track credits and timing
98
+ 3. **validateMedia**: Return comprehensive validation with errors, warnings, recommendations
99
+ 4. **optimizeMedia**: Apply compression to existing attachment, preserve metadata
100
+ 5. **deleteMedia**: Remove attachment and update card associations
101
+ 6. **getMediaUrl**: Return accessible URL for downloaded or remote media
102
+ 7. **downloadMedia**: Fetch remote media to local storage, update isDownloaded status
103
+
104
+ ### Generation Type Specifics
105
+
106
+ 1. **text_to_image**: Requires prompt, style (realistic/cartoon/artistic), quality, format
107
+ 2. **text_to_audio**: Requires text, language, voice (male/female/neutral), format
108
+ 3. **image_search**: Requires prompt, maxResults (no quality/format options)
109
+
110
+ ### Position Logic
111
+
112
+ 1. **front**: Media displayed only on card front face
113
+ 2. **back**: Media displayed only on card back face
114
+ 3. **both**: Media displayed on both card faces (e.g., background image)
115
+
116
+ ### Download Management
117
+
118
+ 1. Check isDownloaded before displaying media offline
119
+ 2. Use localPath for offline access when available
120
+ 3. Fall back to URL when media not downloaded
121
+ 4. Track estimatedSize for storage management
122
+ 5. Implement downloadMedia for offline caching
123
+
124
+ ## Dependencies
125
+
126
+ - No external dependencies
127
+ - References domain types from Media.ts for base media concepts
128
+ - Must be usable by infrastructure and presentation layers without additional dependencies
129
+ - Service interfaces require async operation support
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Card Multimedia Types
3
+ * Multimedia support for flashcard functionality
4
+ */
5
+
6
+ export type CardMediaType = "image" | "audio" | "video";
7
+ export type CardMediaPosition = "front" | "back" | "both";
8
+
9
+ export interface CardMediaAttachment {
10
+ id: string;
11
+ type: CardMediaType;
12
+ position: CardMediaPosition;
13
+ url: string;
14
+ localPath?: string;
15
+ filename: string;
16
+ fileSize: number;
17
+ mimeType: string;
18
+ duration?: number; // For audio/video in seconds
19
+ thumbnailUrl?: string; // For videos
20
+ caption?: string;
21
+ isDownloaded: boolean;
22
+ createdAt: string;
23
+ }
24
+
25
+ export interface CardMultimediaFlashcard {
26
+ id: string;
27
+ front: string;
28
+ back: string;
29
+ difficulty: "easy" | "medium" | "hard";
30
+ tags: string[];
31
+ createdAt?: string;
32
+ updatedAt?: string;
33
+ // Extended properties for multimedia support
34
+ media: CardMediaAttachment[];
35
+ hasMedia: boolean; // Computed property
36
+ mediaType: CardMediaType[]; // Array of media types present
37
+ isDownloaded: boolean; // All media downloaded?
38
+ estimatedSize: number; // Total size in bytes
39
+ }
40
+
41
+ export interface CardMediaGenerationRequest {
42
+ type: "text_to_image" | "text_to_audio" | "image_search";
43
+ input: {
44
+ text?: string;
45
+ prompt?: string;
46
+ language?: string;
47
+ voice?: "male" | "female" | "neutral";
48
+ style?: "realistic" | "cartoon" | "artistic";
49
+ };
50
+ options: {
51
+ maxResults?: number;
52
+ quality?: "low" | "medium" | "high";
53
+ format?: "jpeg" | "png" | "mp3" | "wav";
54
+ };
55
+ }
56
+
57
+ export interface CardMediaGenerationResult {
58
+ success: boolean;
59
+ attachments: CardMediaAttachment[];
60
+ creditsUsed: number;
61
+ processingTime: number;
62
+ error?: string;
63
+ requestId: string;
64
+ }
65
+
66
+ export interface CardMediaUploadProgress {
67
+ fileId: string;
68
+ progress: number; // 0-100
69
+ status: "uploading" | "processing" | "completed" | "error";
70
+ error?: string;
71
+ url?: string;
72
+ }
73
+
74
+ export interface CardMediaCompressionOptions {
75
+ quality: number; // 0.1 - 1.0
76
+ maxWidth?: number;
77
+ maxHeight?: number;
78
+ maxFileSize?: number; // bytes
79
+ format?: "jpeg" | "png" | "webp";
80
+ }
81
+
82
+ export interface CardMediaValidation {
83
+ isValid: boolean;
84
+ errors: string[];
85
+ warnings: string[];
86
+ recommendations: string[];
87
+ }
88
+
89
+ export interface CardMultimediaFlashcardService {
90
+ uploadMedia(
91
+ file: any,
92
+ options?: CardMediaCompressionOptions,
93
+ ): Promise<CardMediaAttachment>;
94
+ generateMedia(
95
+ request: CardMediaGenerationRequest,
96
+ ): Promise<CardMediaGenerationResult>;
97
+ validateMedia(file: any): Promise<CardMediaValidation>;
98
+ optimizeMedia(
99
+ attachment: CardMediaAttachment,
100
+ options: CardMediaCompressionOptions,
101
+ ): Promise<CardMediaAttachment>;
102
+ deleteMedia(attachmentId: string): Promise<void>;
103
+ getMediaUrl(attachmentId: string): Promise<string>;
104
+ downloadMedia(attachmentId: string): Promise<string>; // Returns local path
105
+ }
@@ -0,0 +1,80 @@
1
+ # Media Types and Interfaces
2
+
3
+ ## Purpose
4
+ Core type definitions and interfaces for media handling throughout the application.
5
+
6
+ ## File Location
7
+ `src/domain/entities/Media.ts`
8
+
9
+ ## Strategy
10
+ - Define the contract for media operations across all layers
11
+ - Provide type-safe interfaces for media assets, picker options, and operations
12
+ - Serve as the single source of truth for media-related types
13
+ - Enable compile-time validation of media operations
14
+ - Maintain separation between domain logic and implementation
15
+
16
+ ## Forbidden
17
+ - **DO NOT** import external libraries (expo, react-native) in domain types
18
+ - **DO NOT** include implementation details in type definitions
19
+ - **DO NOT** add business logic to type definitions
20
+ - **DO NOT** create circular dependencies between types
21
+ - **DO NOT** export types that are not used by other layers
22
+ - **DO NOT** use `any` type or loose type definitions
23
+ - **DO NOT** modify existing types - extend them instead
24
+
25
+ ## Rules
26
+ 1. All media types must be exported from this file
27
+ 2. Type definitions must be framework-agnostic
28
+ 3. Enums must have explicit string values
29
+ 4. Interfaces must extend appropriate base types
30
+ 5. Optional fields must be clearly marked with `?`
31
+ 6. File size fields must use bytes as unit
32
+ 7. Dimensions must be in pixels
33
+ 8. MIME type validation must use standard MIME types
34
+ 9. All new properties must be added with backward compatibility in mind
35
+ 10. Type exports must be re-exported from main index
36
+
37
+ ## AI Agent Guidelines
38
+
39
+ When working with Media types:
40
+
41
+ 1. **Type Import**: Always import types from `@umituz/react-native-media` domain layer
42
+ 2. **Type Safety**: Use provided types instead of `any` or loose types
43
+ 3. **Validation**: Validate media assets against these types before processing
44
+ 4. **Extensibility**: Extend interfaces when adding new properties, don't modify core types
45
+ 5. **Consistency**: Maintain naming conventions (PascalCase for types, camelCase for properties)
46
+
47
+ ### Key Enums Reference
48
+
49
+ - `MediaType`: IMAGE, VIDEO, ALL - Use for media type filtering
50
+ - `ImageFormat`: PNG, JPEG, WEBP - Use for format specification
51
+ - `MediaQuality`: LOW (0.3), MEDIUM (0.7), HIGH (1.0) - Use for compression quality
52
+ - `MediaLibraryPermission`: GRANTED, DENIED, LIMITED - Use for permission states
53
+
54
+ ### Type Usage Guidelines
55
+
56
+ 1. **MediaAsset**: Primary type for all media files with uri, dimensions, type, size
57
+ 2. **MediaPickerResult**: Return type for all picker operations with canceled flag
58
+ 3. **MediaPickerOptions**: Configuration for library picker with mediaTypes, quality, limits
59
+ 4. **CameraOptions**: Configuration for camera operations with quality, duration, editing
60
+
61
+ ### Validation Rules
62
+
63
+ 1. Check file size against `MediaAsset.fileSize` (in bytes)
64
+ 2. Validate dimensions using `width` and `height` properties (in pixels)
65
+ 3. Verify MIME type matches expected `MediaType`
66
+ 4. Ensure URIs are properly formatted strings
67
+ 5. Validate aspect ratio format as [width, height] tuple
68
+
69
+ ### Constants Reference
70
+
71
+ Use `MEDIA_CONSTANTS` for:
72
+ - Maximum file sizes (MAX_IMAGE_SIZE, MAX_VIDEO_SIZE)
73
+ - Default values (DEFAULT_QUALITY, DEFAULT_FORMAT, DEFAULT_ASPECT_RATIO)
74
+ - Supported format lists (SUPPORTED_IMAGE_FORMATS, SUPPORTED_VIDEO_FORMATS)
75
+
76
+ ## Dependencies
77
+
78
+ - No external dependencies
79
+ - May reference other domain types within the domain layer
80
+ - Must be usable by infrastructure and presentation layers without additional dependencies
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Media Domain - Core Entities
3
+ *
4
+ * Core types and interfaces for media operations.
5
+ * Handles images, videos, and media library interactions.
6
+ */
7
+
8
+
9
+ /**
10
+ * Media type enumeration
11
+ */
12
+ export enum MediaType {
13
+ IMAGE = "image",
14
+ VIDEO = "video",
15
+ ALL = "all",
16
+ }
17
+
18
+ /**
19
+ * Image format enumeration
20
+ */
21
+ export enum ImageFormat {
22
+ PNG = "png",
23
+ JPEG = "jpeg",
24
+ WEBP = "webp",
25
+ }
26
+
27
+ /**
28
+ * Media quality enumeration
29
+ */
30
+ export enum MediaQuality {
31
+ LOW = 0.3,
32
+ MEDIUM = 0.7,
33
+ HIGH = 1.0,
34
+ }
35
+
36
+ /**
37
+ * Media library permissions
38
+ */
39
+ export enum MediaLibraryPermission {
40
+ GRANTED = "granted",
41
+ DENIED = "denied",
42
+ LIMITED = "limited",
43
+ }
44
+
45
+ /**
46
+ * Image dimensions interface
47
+ */
48
+ export interface ImageDimensions {
49
+ width: number;
50
+ height: number;
51
+ }
52
+
53
+ /**
54
+ * Image manipulation actions
55
+ */
56
+ export interface ImageManipulationActions {
57
+ resize?: ImageDimensions;
58
+ crop?: {
59
+ originX: number;
60
+ originY: number;
61
+ width: number;
62
+ height: number;
63
+ };
64
+ rotate?: number;
65
+ flip?: {
66
+ horizontal?: boolean;
67
+ vertical?: boolean;
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Image save options
73
+ */
74
+ export interface ImageSaveOptions {
75
+ quality?: MediaQuality;
76
+ format?: ImageFormat;
77
+ base64?: boolean;
78
+ }
79
+
80
+ /**
81
+ * Media picker options
82
+ */
83
+ export interface MediaPickerOptions {
84
+ mediaTypes?: MediaType;
85
+ allowsEditing?: boolean;
86
+ allowsMultipleSelection?: boolean;
87
+ aspect?: [number, number];
88
+ quality?: MediaQuality;
89
+ selectionLimit?: number;
90
+ base64?: boolean;
91
+ }
92
+
93
+ /**
94
+ * Media asset interface
95
+ */
96
+ export interface MediaAsset {
97
+ uri: string;
98
+ width: number;
99
+ height: number;
100
+ type: MediaType;
101
+ fileSize?: number;
102
+ fileName?: string;
103
+ duration?: number;
104
+ base64?: string;
105
+ mimeType?: string;
106
+ }
107
+
108
+ /**
109
+ * Media picker result
110
+ */
111
+ export interface MediaPickerResult {
112
+ canceled: boolean;
113
+ assets?: MediaAsset[];
114
+ }
115
+
116
+ /**
117
+ * Camera options
118
+ */
119
+ export interface CameraOptions {
120
+ quality?: MediaQuality;
121
+ allowsEditing?: boolean;
122
+ aspect?: [number, number];
123
+ base64?: boolean;
124
+ videoMaxDuration?: number;
125
+ }
126
+
127
+ /**
128
+ * Media constants
129
+ */
130
+ export const MEDIA_CONSTANTS = {
131
+ MAX_IMAGE_SIZE: 10 * 1024 * 1024,
132
+ MAX_VIDEO_SIZE: 100 * 1024 * 1024,
133
+ DEFAULT_QUALITY: MediaQuality.HIGH,
134
+ DEFAULT_FORMAT: ImageFormat.JPEG,
135
+ DEFAULT_ASPECT_RATIO: [4, 3] as [number, number],
136
+ DEFAULT_SELECTION_LIMIT: 10,
137
+ SUPPORTED_IMAGE_FORMATS: [".jpg", ".jpeg", ".png", ".gif", ".webp"],
138
+ SUPPORTED_VIDEO_FORMATS: [".mp4", ".mov"],
139
+ } as const;
@@ -0,0 +1,144 @@
1
+ # MultimediaFlashcard Types
2
+
3
+ ## Purpose
4
+ Type definitions for general-purpose media operations in flashcard applications. These types define the contract for media attachment, generation, and management across various multimedia use cases.
5
+
6
+ ## File Location
7
+ `src/domain/entities/MultimediaFlashcardTypes.ts`
8
+
9
+ ## Strategy
10
+ - Define the contract for general multimedia operations in flashcards
11
+ - Provide type-safe interfaces for media attachments and generation
12
+ - Support AI-powered media generation for educational content
13
+ - Enable comprehensive media validation and optimization
14
+ - Maintain clear separation between general media and card-specific media types
15
+ - Support upload progress tracking and compression
16
+ - Facilitate media download management for offline learning
17
+
18
+ ## Forbidden
19
+ - **DO NOT** use these types for card-specific operations with special requirements (use CardMultimedia types instead)
20
+ - **DO NOT** include UI components or presentation logic in type definitions
21
+ - **DO NOT** add business logic or implementation details to interfaces
22
+ - **DO NOT** create circular dependencies with other domain types
23
+ - **DO NOT** use `any` type or loose type definitions
24
+ - **DO NOT** modify existing type properties - extend interfaces for new features
25
+ - **DO NOT** assume specific storage backend or cloud provider
26
+ - **DO NOT** hardcode validation limits in type definitions
27
+ - **DO NOT** mix general multimedia types with card-specific types
28
+ - **DO NOT** use image_search generation type (only available in CardMultimedia)
29
+
30
+ ## Rules
31
+ 1. All multimedia types must be exported from this file
32
+ 2. Type definitions must be framework-agnostic
33
+ 3. Media IDs must use "media_" prefix for uniqueness
34
+ 4. Position types must explicitly define front/back/both placement
35
+ 5. File size fields must use bytes as unit
36
+ 6. Duration fields must use seconds as unit
37
+ 7. Date fields must use ISO 8601 format
38
+ 8. All generation requests must include input validation
39
+ 9. Compression quality must be between 0.1 and 1.0
40
+ 10. Upload progress must be tracked from 0-100
41
+ 11. Validation results must separate errors, warnings, and recommendations
42
+ 12. Service interfaces must return Promises for all async operations
43
+ 13. Media type arrays must be automatically calculated, not manually set
44
+ 14. Download status must be tracked per attachment
45
+ 15. Estimated size must represent total of all attachments
46
+
47
+ ## AI Agent Guidelines
48
+
49
+ When working with MultimediaFlashcard types:
50
+
51
+ 1. **Type Selection**: Use MediaAttachment for general-purpose media operations
52
+ 2. **Generation Requests**: Always specify input parameters and options explicitly
53
+ 3. **Validation**: Validate media files before upload and after generation
54
+ 4. **Progress Tracking**: Monitor upload progress for user feedback
55
+ 5. **Compression**: Apply compression options before upload to reduce bandwidth
56
+ 6. **Download Management**: Check isDownloaded status before displaying media
57
+ 7. **Position Logic**: Respect position field for front/back/both placement
58
+ 8. **Size Estimation**: Calculate total size for all media before batch operations
59
+ 9. **Error Handling**: Parse validation errors and warnings for user feedback
60
+ 10. **Cost Tracking**: Monitor creditsUsed for AI generation operations
61
+
62
+ ### Key Types Reference
63
+
64
+ - **MediaType**: "image" | "audio" | "video" - Media type classification
65
+ - **MediaPosition**: "front" | "back" | "both" - Display placement on card faces
66
+ - **MediaAttachment**: Core interface for individual media items with metadata
67
+ - **MultimediaFlashcard**: Card entity with computed media properties
68
+ - **MediaGenerationRequest**: Input specification for AI media generation
69
+ - **MediaGenerationResult**: Output with cost tracking and performance metrics
70
+ - **MediaUploadProgress**: Real-time upload status tracking
71
+ - **MediaCompressionOptions**: Quality and size optimization settings
72
+ - **MediaValidation**: Comprehensive validation with recommendations
73
+ - **MultimediaFlashcardService**: Service interface for media operations
74
+
75
+ ### Type Usage Patterns
76
+
77
+ 1. **MediaAttachment**: Individual media item with position, URL, and metadata
78
+ 2. **MultimediaFlashcard**: Card with computed properties (hasMedia, mediaType, isDownloaded)
79
+ 3. **MediaGenerationRequest**: Two generation types (text_to_image, text_to_audio) - no image_search
80
+ 4. **MediaValidation**: Separate errors (blocking) from warnings and recommendations
81
+
82
+ ### Validation Rules
83
+
84
+ 1. Validate file size against upload limits before processing
85
+ 2. Check MIME type matches MediaType
86
+ 3. Ensure dimensions are within supported ranges
87
+ 4. Verify URIs are properly formatted and accessible
88
+ 5. Validate duration for audio/video files
89
+ 6. Check compression quality is within 0.1-1.0 range
90
+ 7. Ensure generation prompts are non-empty strings
91
+ 8. Validate language codes for audio generation (e.g., "en-US", "es-ES")
92
+
93
+ ### Service Interface Guidelines
94
+
95
+ When implementing MultimediaFlashcardService:
96
+
97
+ 1. **uploadMedia**: Accept file with optional compression, return attachment with URL
98
+ 2. **generateMedia**: Process AI generation request, track credits and timing
99
+ 3. **validateMedia**: Return comprehensive validation with errors, warnings, recommendations
100
+ 4. **optimizeMedia**: Apply compression to existing attachment, preserve metadata
101
+ 5. **deleteMedia**: Remove attachment and update card associations
102
+ 6. **getMediaUrl**: Return accessible URL for downloaded or remote media
103
+ 7. **downloadMedia**: Fetch remote media to local storage, update isDownloaded status
104
+
105
+ ### Generation Type Specifics
106
+
107
+ 1. **text_to_image**: Requires prompt, style (realistic/cartoon/artistic), quality, format
108
+ 2. **text_to_audio**: Requires text, language, voice (male/female/neutral), format
109
+ 3. **image_search**: NOT supported in general multimedia types (use CardMultimedia instead)
110
+
111
+ ### Position Logic
112
+
113
+ 1. **front**: Media displayed only on card front face
114
+ 2. **back**: Media displayed only on card back face
115
+ 3. **both**: Media displayed on both card faces (e.g., background image)
116
+
117
+ ### Download Management
118
+
119
+ 1. Check isDownloaded before displaying media offline
120
+ 2. Use localPath for offline access when available
121
+ 3. Fall back to URL when media not downloaded
122
+ 4. Track estimatedSize for storage management
123
+ 5. Implement downloadMedia for offline caching
124
+
125
+ ### CardMultimedia vs Multimedia Selection
126
+
127
+ Use **CardMultimedia types** when:
128
+ - Working with flashcard-specific features
129
+ - Need image_search generation capability
130
+ - Using card-specific ID prefixes (card_media_)
131
+ - Integrating with card-specific services
132
+
133
+ Use **Multimedia types** when:
134
+ - Building general-purpose media features
135
+ - Only need text_to_image and text_to_audio generation
136
+ - Using general media ID prefixes (media_)
137
+ - Building reusable media components
138
+
139
+ ## Dependencies
140
+
141
+ - No external dependencies
142
+ - References domain types from Media.ts for base media concepts
143
+ - Must be usable by infrastructure and presentation layers without additional dependencies
144
+ - Service interfaces require async operation support