@umituz/react-native-design-system 2.8.7 → 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.
- package/package.json +10 -6
- package/src/device/infrastructure/repositories/LegacyDeviceIdRepository.ts +1 -1
- package/src/device/infrastructure/services/DeviceFeatureService.ts +1 -1
- package/src/exception/infrastructure/services/ExceptionLogger.ts +1 -1
- package/src/exception/infrastructure/storage/ExceptionStore.ts +1 -1
- package/src/exports/filesystem.ts +1 -0
- package/src/exports/media.ts +1 -0
- package/src/exports/storage.ts +1 -0
- package/src/filesystem/domain/constants/FileConstants.ts +20 -0
- package/src/filesystem/domain/entities/File.ts +20 -0
- package/src/filesystem/domain/types/FileTypes.ts +43 -0
- package/src/filesystem/domain/utils/FileUtils.ts +86 -0
- package/src/filesystem/index.ts +23 -0
- package/src/filesystem/infrastructure/services/FileSystemService.ts +45 -0
- package/src/filesystem/infrastructure/services/cache.service.ts +48 -0
- package/src/filesystem/infrastructure/services/directory.service.ts +66 -0
- package/src/filesystem/infrastructure/services/download.constants.ts +6 -0
- package/src/filesystem/infrastructure/services/download.service.ts +74 -0
- package/src/filesystem/infrastructure/services/download.types.ts +7 -0
- package/src/filesystem/infrastructure/services/encoding.service.ts +25 -0
- package/src/filesystem/infrastructure/services/file-info.service.ts +52 -0
- package/src/filesystem/infrastructure/services/file-manager.service.ts +81 -0
- package/src/filesystem/infrastructure/services/file-path.service.ts +22 -0
- package/src/filesystem/infrastructure/services/file-reader.service.ts +52 -0
- package/src/filesystem/infrastructure/services/file-writer.service.ts +32 -0
- package/src/filesystem/infrastructure/utils/blob.utils.ts +20 -0
- package/src/image/infrastructure/services/ImageStorageService.ts +1 -1
- package/src/index.ts +14 -0
- package/src/media/domain/entities/CardMultimedia.types.README.md +129 -0
- package/src/media/domain/entities/CardMultimedia.types.ts +105 -0
- package/src/media/domain/entities/Media.README.md +80 -0
- package/src/media/domain/entities/Media.ts +139 -0
- package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +144 -0
- package/src/media/domain/entities/MultimediaFlashcardTypes.ts +105 -0
- package/src/media/domain/utils/MediaUtils.README.md +178 -0
- package/src/media/domain/utils/MediaUtils.ts +82 -0
- package/src/media/index.ts +70 -0
- package/src/media/index.ts.README.md +191 -0
- package/src/media/infrastructure/services/CardMediaGenerationService.README.md +99 -0
- package/src/media/infrastructure/services/CardMediaGenerationService.ts +101 -0
- package/src/media/infrastructure/services/CardMediaOptimizerService.README.md +167 -0
- package/src/media/infrastructure/services/CardMediaOptimizerService.ts +36 -0
- package/src/media/infrastructure/services/CardMediaUploadService.README.md +123 -0
- package/src/media/infrastructure/services/CardMediaUploadService.ts +67 -0
- package/src/media/infrastructure/services/CardMediaValidationService.README.md +134 -0
- package/src/media/infrastructure/services/CardMediaValidationService.ts +81 -0
- package/src/media/infrastructure/services/CardMultimediaService.README.md +176 -0
- package/src/media/infrastructure/services/CardMultimediaService.ts +97 -0
- package/src/media/infrastructure/services/MediaGenerationService.README.md +142 -0
- package/src/media/infrastructure/services/MediaGenerationService.ts +80 -0
- package/src/media/infrastructure/services/MediaOptimizerService.README.md +145 -0
- package/src/media/infrastructure/services/MediaOptimizerService.ts +32 -0
- package/src/media/infrastructure/services/MediaPickerService.README.md +106 -0
- package/src/media/infrastructure/services/MediaPickerService.ts +173 -0
- package/src/media/infrastructure/services/MediaSaveService.README.md +120 -0
- package/src/media/infrastructure/services/MediaSaveService.ts +154 -0
- package/src/media/infrastructure/services/MediaUploadService.README.md +135 -0
- package/src/media/infrastructure/services/MediaUploadService.ts +62 -0
- package/src/media/infrastructure/services/MediaValidationService.README.md +135 -0
- package/src/media/infrastructure/services/MediaValidationService.ts +61 -0
- package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +142 -0
- package/src/media/infrastructure/services/MultimediaFlashcardService.ts +95 -0
- package/src/media/infrastructure/utils/mediaHelpers.README.md +96 -0
- package/src/media/infrastructure/utils/mediaHelpers.ts +82 -0
- package/src/media/infrastructure/utils/mediaPickerMappers.README.md +129 -0
- package/src/media/infrastructure/utils/mediaPickerMappers.ts +76 -0
- package/src/media/presentation/hooks/card-multimedia.types.README.md +177 -0
- package/src/media/presentation/hooks/card-multimedia.types.ts +51 -0
- package/src/media/presentation/hooks/multimedia.types.README.md +201 -0
- package/src/media/presentation/hooks/multimedia.types.ts +51 -0
- package/src/media/presentation/hooks/useCardMediaGeneration.README.md +164 -0
- package/src/media/presentation/hooks/useCardMediaGeneration.ts +124 -0
- package/src/media/presentation/hooks/useCardMediaUpload.README.md +153 -0
- package/src/media/presentation/hooks/useCardMediaUpload.ts +86 -0
- package/src/media/presentation/hooks/useCardMediaValidation.README.md +176 -0
- package/src/media/presentation/hooks/useCardMediaValidation.ts +101 -0
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +158 -0
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +104 -0
- package/src/media/presentation/hooks/useMedia.README.md +94 -0
- package/src/media/presentation/hooks/useMedia.ts +186 -0
- package/src/media/presentation/hooks/useMediaGeneration.README.md +118 -0
- package/src/media/presentation/hooks/useMediaGeneration.ts +101 -0
- package/src/media/presentation/hooks/useMediaUpload.README.md +108 -0
- package/src/media/presentation/hooks/useMediaUpload.ts +86 -0
- package/src/media/presentation/hooks/useMediaValidation.README.md +134 -0
- package/src/media/presentation/hooks/useMediaValidation.ts +93 -0
- package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +141 -0
- package/src/media/presentation/hooks/useMultimediaFlashcard.ts +103 -0
- package/src/molecules/alerts/AlertStore.ts +1 -1
- package/src/molecules/calendar/infrastructure/storage/EventActions.ts +1 -1
- package/src/molecules/calendar/infrastructure/stores/storageAdapter.ts +1 -1
- package/src/offline/infrastructure/storage/OfflineStore.ts +1 -1
- package/src/onboarding/infrastructure/storage/OnboardingStore.ts +2 -2
- package/src/onboarding/infrastructure/storage/__tests__/OnboardingStore.test.ts +1 -1
- package/src/onboarding/infrastructure/storage/actions/answerActions.ts +1 -1
- package/src/onboarding/infrastructure/storage/actions/storageHelpers.ts +1 -1
- package/src/storage/README.md +185 -0
- package/src/storage/__tests__/integration.test.ts +391 -0
- package/src/storage/__tests__/mocks/asyncStorage.mock.ts +52 -0
- package/src/storage/__tests__/performance.test.tsx +352 -0
- package/src/storage/__tests__/setup.ts +63 -0
- package/src/storage/application/README.md +158 -0
- package/src/storage/application/ports/IStorageRepository.ts +61 -0
- package/src/storage/application/ports/README.md +127 -0
- package/src/storage/cache/README.md +154 -0
- package/src/storage/cache/__tests__/PerformanceAndMemory.test.ts +387 -0
- package/src/storage/cache/__tests__/setup.ts +19 -0
- package/src/storage/cache/domain/Cache.ts +146 -0
- package/src/storage/cache/domain/CacheManager.md +83 -0
- package/src/storage/cache/domain/CacheManager.ts +48 -0
- package/src/storage/cache/domain/CacheStatsTracker.md +169 -0
- package/src/storage/cache/domain/CacheStatsTracker.ts +49 -0
- package/src/storage/cache/domain/CachedValue.md +97 -0
- package/src/storage/cache/domain/ErrorHandler.md +99 -0
- package/src/storage/cache/domain/ErrorHandler.ts +42 -0
- package/src/storage/cache/domain/PatternMatcher.md +122 -0
- package/src/storage/cache/domain/PatternMatcher.ts +30 -0
- package/src/storage/cache/domain/README.md +118 -0
- package/src/storage/cache/domain/__tests__/Cache.test.ts +293 -0
- package/src/storage/cache/domain/__tests__/CacheManager.test.ts +276 -0
- package/src/storage/cache/domain/__tests__/ErrorHandler.test.ts +303 -0
- package/src/storage/cache/domain/__tests__/PatternMatcher.test.ts +261 -0
- package/src/storage/cache/domain/strategies/EvictionStrategy.ts +9 -0
- package/src/storage/cache/domain/strategies/FIFOStrategy.ts +12 -0
- package/src/storage/cache/domain/strategies/LFUStrategy.ts +22 -0
- package/src/storage/cache/domain/strategies/LRUStrategy.ts +22 -0
- package/src/storage/cache/domain/strategies/README.md +117 -0
- package/src/storage/cache/domain/strategies/TTLStrategy.ts +23 -0
- package/src/storage/cache/domain/strategies/__tests__/EvictionStrategies.test.ts +293 -0
- package/src/storage/cache/domain/types/Cache.ts +28 -0
- package/src/storage/cache/domain/types/README.md +107 -0
- package/src/storage/cache/index.ts +28 -0
- package/src/storage/cache/infrastructure/README.md +126 -0
- package/src/storage/cache/infrastructure/TTLCache.ts +103 -0
- package/src/storage/cache/infrastructure/__tests__/TTLCache.test.ts +303 -0
- package/src/storage/cache/presentation/README.md +123 -0
- package/src/storage/cache/presentation/__tests__/ReactHooks.test.ts +514 -0
- package/src/storage/cache/presentation/useCache.ts +76 -0
- package/src/storage/cache/presentation/useCachedValue.ts +88 -0
- package/src/storage/cache/types.d.ts +3 -0
- package/src/storage/domain/README.md +128 -0
- package/src/storage/domain/constants/CacheDefaults.ts +64 -0
- package/src/storage/domain/constants/README.md +105 -0
- package/src/storage/domain/entities/CachedValue.ts +86 -0
- package/src/storage/domain/entities/README.md +109 -0
- package/src/storage/domain/entities/StorageResult.ts +75 -0
- package/src/storage/domain/entities/__tests__/CachedValue.test.ts +149 -0
- package/src/storage/domain/entities/__tests__/StorageResult.test.ts +122 -0
- package/src/storage/domain/errors/README.md +126 -0
- package/src/storage/domain/errors/StorageError.ts +81 -0
- package/src/storage/domain/errors/__tests__/StorageError.test.ts +127 -0
- package/src/storage/domain/factories/README.md +138 -0
- package/src/storage/domain/factories/StoreFactory.ts +59 -0
- package/src/storage/domain/types/README.md +522 -0
- package/src/storage/domain/types/Store.ts +44 -0
- package/src/storage/domain/utils/CacheKeyGenerator.ts +66 -0
- package/src/storage/domain/utils/README.md +127 -0
- package/src/storage/domain/utils/__tests__/devUtils.test.ts +97 -0
- package/src/storage/domain/utils/devUtils.ts +37 -0
- package/src/storage/domain/value-objects/README.md +120 -0
- package/src/storage/domain/value-objects/StorageKey.ts +60 -0
- package/src/storage/index.ts +175 -0
- package/src/storage/infrastructure/README.md +165 -0
- package/src/storage/infrastructure/adapters/README.md +175 -0
- package/src/storage/infrastructure/adapters/StorageService.md +103 -0
- package/src/storage/infrastructure/adapters/StorageService.ts +49 -0
- package/src/storage/infrastructure/repositories/AsyncStorageRepository.ts +98 -0
- package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +100 -0
- package/src/storage/infrastructure/repositories/BatchStorageOperations.ts +42 -0
- package/src/storage/infrastructure/repositories/README.md +121 -0
- package/src/storage/infrastructure/repositories/StringStorageOperations.ts +44 -0
- package/src/storage/infrastructure/repositories/__tests__/AsyncStorageRepository.test.ts +170 -0
- package/src/storage/infrastructure/repositories/__tests__/BaseStorageOperations.test.ts +201 -0
- package/src/storage/presentation/README.md +181 -0
- package/src/storage/presentation/hooks/CacheStorageOperations.ts +94 -0
- package/src/storage/presentation/hooks/README.md +128 -0
- package/src/storage/presentation/hooks/__tests__/usePersistentCache.test.ts +405 -0
- package/src/storage/presentation/hooks/__tests__/useStorage.test.ts +247 -0
- package/src/storage/presentation/hooks/__tests__/useStorageState.test.ts +293 -0
- package/src/storage/presentation/hooks/useCacheState.ts +53 -0
- package/src/storage/presentation/hooks/usePersistentCache.ts +154 -0
- package/src/storage/presentation/hooks/useStorage.ts +102 -0
- package/src/storage/presentation/hooks/useStorageState.ts +71 -0
- package/src/storage/presentation/hooks/useStore.ts +15 -0
- package/src/storage/types/README.md +103 -0
- package/src/theme/infrastructure/globalThemeStore.ts +1 -1
- package/src/theme/infrastructure/storage/ThemeStorage.ts +1 -1
- package/src/theme/infrastructure/stores/themeStore.ts +1 -1
- package/src/utilities/sharing/infrastructure/services/SharingService.ts +1 -1
|
@@ -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
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multimedia Flashcard Types
|
|
3
|
+
* Extended media types for flashcard support
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type MediaType = "image" | "audio" | "video";
|
|
7
|
+
export type MediaPosition = "front" | "back" | "both";
|
|
8
|
+
|
|
9
|
+
export interface MediaAttachment {
|
|
10
|
+
id: string;
|
|
11
|
+
type: MediaType;
|
|
12
|
+
position: MediaPosition;
|
|
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 MultimediaFlashcard {
|
|
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: MediaAttachment[];
|
|
35
|
+
hasMedia: boolean; // Computed property
|
|
36
|
+
mediaType: MediaType[]; // Array of media types present
|
|
37
|
+
isDownloaded: boolean; // All media downloaded?
|
|
38
|
+
estimatedSize: number; // Total size in bytes
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface MediaGenerationRequest {
|
|
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 MediaGenerationResult {
|
|
58
|
+
success: boolean;
|
|
59
|
+
attachments: MediaAttachment[];
|
|
60
|
+
creditsUsed: number;
|
|
61
|
+
processingTime: number;
|
|
62
|
+
error?: string;
|
|
63
|
+
requestId: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface MediaUploadProgress {
|
|
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 MediaCompressionOptions {
|
|
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 MediaValidation {
|
|
83
|
+
isValid: boolean;
|
|
84
|
+
errors: string[];
|
|
85
|
+
warnings: string[];
|
|
86
|
+
recommendations: string[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface MultimediaFlashcardService {
|
|
90
|
+
uploadMedia(
|
|
91
|
+
file: any,
|
|
92
|
+
options?: MediaCompressionOptions,
|
|
93
|
+
): Promise<MediaAttachment>;
|
|
94
|
+
generateMedia(
|
|
95
|
+
request: MediaGenerationRequest,
|
|
96
|
+
): Promise<MediaGenerationResult>;
|
|
97
|
+
validateMedia(file: any): Promise<MediaValidation>;
|
|
98
|
+
optimizeMedia(
|
|
99
|
+
attachment: MediaAttachment,
|
|
100
|
+
options: MediaCompressionOptions,
|
|
101
|
+
): Promise<MediaAttachment>;
|
|
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,178 @@
|
|
|
1
|
+
# MediaUtils
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Utility class containing helper functions for media operations, validation, and calculations. Provides static methods for file type detection, dimension calculations, format conversions, and media validation.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`src/domain/utils/MediaUtils.ts`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Provide framework-agnostic utility functions for media operations
|
|
11
|
+
- Enable consistent media type detection and validation
|
|
12
|
+
- Support dimension calculations and scaling operations
|
|
13
|
+
- Facilitate format conversions and MIME type mappings
|
|
14
|
+
- Maintain aspect ratio preservation during transformations
|
|
15
|
+
- Validate media constraints (dimensions, file types, sizes)
|
|
16
|
+
- Provide helper functions for common media operations
|
|
17
|
+
|
|
18
|
+
## Forbidden
|
|
19
|
+
- **DO NOT** import external libraries (expo-image-picker, react-native) in utility functions
|
|
20
|
+
- **DO NOT** include business logic or application-specific rules
|
|
21
|
+
- **DO NOT** create instance methods - all methods must be static
|
|
22
|
+
- **DO NOT** store state or maintain mutable properties
|
|
23
|
+
- **DO NOT** make network calls or async operations in utility methods
|
|
24
|
+
- **DO NOT** hardcode platform-specific behavior
|
|
25
|
+
- **DO NOT** include UI-related logic or formatting for display
|
|
26
|
+
- **DO NOT** modify input parameters - always return new objects/values
|
|
27
|
+
- **DO NOT** throw exceptions for validation failures - return boolean results
|
|
28
|
+
- **DO NOT** assume specific file systems or storage mechanisms
|
|
29
|
+
|
|
30
|
+
## Rules
|
|
31
|
+
1. All methods must be static and stateless
|
|
32
|
+
2. All methods must be synchronous and pure functions
|
|
33
|
+
3. Input validation must not throw exceptions
|
|
34
|
+
4. Dimension calculations must preserve aspect ratios
|
|
35
|
+
5. MIME type mappings must use standard MIME types
|
|
36
|
+
6. Maximum dimension limit is 8192x8192 pixels
|
|
37
|
+
7. Minimum dimension limit is 1x1 pixels
|
|
38
|
+
8. File type detection must use extension checking
|
|
39
|
+
9. Scale calculations must return integer values
|
|
40
|
+
10. Aspect ratio must be calculated as width/height
|
|
41
|
+
11. Unknown MIME types must map to MediaType.ALL
|
|
42
|
+
12. Format validation must use supported format lists
|
|
43
|
+
13. All methods must handle edge cases (zero, negative values)
|
|
44
|
+
14. Return types must be consistent (boolean for validation, numbers for calculations)
|
|
45
|
+
|
|
46
|
+
## AI Agent Guidelines
|
|
47
|
+
|
|
48
|
+
When working with MediaUtils:
|
|
49
|
+
|
|
50
|
+
1. **Static Usage**: Always call methods on the class, never create instances
|
|
51
|
+
2. **Type Detection**: Use isImage() and isVideo() before processing files
|
|
52
|
+
3. **Validation**: Always validate dimensions before scaling operations
|
|
53
|
+
4. **Aspect Ratios**: Preserve aspect ratios when calculating scaled dimensions
|
|
54
|
+
5. **MIME Types**: Use getImageMimeType() for format-to-MIME conversion
|
|
55
|
+
6. **Media Type Parsing**: Use parseMediaType() to convert MIME to MediaType enum
|
|
56
|
+
7. **Error Handling**: Check boolean return values for validation failures
|
|
57
|
+
8. **Edge Cases**: Handle zero and negative dimensions appropriately
|
|
58
|
+
9. **Performance**: Utility methods are lightweight and can be called frequently
|
|
59
|
+
|
|
60
|
+
### Key Methods Reference
|
|
61
|
+
|
|
62
|
+
- **isImage(uri: string)**: boolean - Check if file is an image by extension
|
|
63
|
+
- **isVideo(uri: string)**: boolean - Check if file is a video by extension
|
|
64
|
+
- **getImageMimeType(format: ImageFormat)**: string - Get MIME type for image format
|
|
65
|
+
- **calculateAspectRatio(width, height)**: number - Calculate width/height ratio
|
|
66
|
+
- **getScaledDimensions(width, height, maxWidth, maxHeight)**: object - Calculate scaled dimensions preserving aspect ratio
|
|
67
|
+
- **isValidDimensions(width, height)**: boolean - Validate dimensions are within allowed range
|
|
68
|
+
- **parseMediaType(mimeType: string)**: MediaType - Convert MIME type to MediaType enum
|
|
69
|
+
|
|
70
|
+
### Method Usage Guidelines
|
|
71
|
+
|
|
72
|
+
**File Type Detection:**
|
|
73
|
+
1. Use isImage() to validate image files before processing
|
|
74
|
+
2. Use isVideo() to validate video files before processing
|
|
75
|
+
3. Both methods check file extensions (jpg, png, mp4, mov, etc.)
|
|
76
|
+
4. Returns false for unknown or unsupported formats
|
|
77
|
+
|
|
78
|
+
**Dimension Calculations:**
|
|
79
|
+
1. Always validate dimensions with isValidDimensions() before processing
|
|
80
|
+
2. Use calculateAspectRatio() to understand image proportions
|
|
81
|
+
3. Use getScaledDimensions() to resize while preserving aspect ratio
|
|
82
|
+
4. Scaled dimensions will never exceed maxWidth or maxHeight
|
|
83
|
+
5. Aspect ratio is maintained even when only one dimension exceeds limits
|
|
84
|
+
|
|
85
|
+
**Format Conversions:**
|
|
86
|
+
1. Use getImageMimeType() to get standard MIME type from format enum
|
|
87
|
+
2. Use parseMediaType() to convert MIME strings to MediaType enum
|
|
88
|
+
3. Unknown MIME types return MediaType.ALL
|
|
89
|
+
4. MIME type mappings are constant and cannot be modified
|
|
90
|
+
|
|
91
|
+
### Validation Rules
|
|
92
|
+
|
|
93
|
+
1. **isValidDimensions**:
|
|
94
|
+
- Width and height must be positive integers
|
|
95
|
+
- Maximum allowed dimension is 8192 pixels
|
|
96
|
+
- Minimum allowed dimension is 1 pixel
|
|
97
|
+
- Returns false for zero or negative values
|
|
98
|
+
- Returns false for values exceeding 8192
|
|
99
|
+
|
|
100
|
+
2. **Aspect Ratio Calculations**:
|
|
101
|
+
- Must preserve original ratio in scaled dimensions
|
|
102
|
+
- Calculated as width divided by height
|
|
103
|
+
- Square images (1:1) return ratio of 1.0
|
|
104
|
+
- Widescreen (16:9) returns ratio of approximately 1.78
|
|
105
|
+
- Portrait (9:16) returns ratio of approximately 0.56
|
|
106
|
+
|
|
107
|
+
3. **Scaling Operations**:
|
|
108
|
+
- Input dimensions can be any positive integers
|
|
109
|
+
- Output dimensions never exceed maxWidth or maxHeight
|
|
110
|
+
- Aspect ratio is always preserved
|
|
111
|
+
- Returns integer dimensions (not floating point)
|
|
112
|
+
- If both dimensions are within limits, returns original dimensions
|
|
113
|
+
- If only one dimension exceeds limit, scales proportionally
|
|
114
|
+
|
|
115
|
+
### MIME Type Handling
|
|
116
|
+
|
|
117
|
+
**Supported Image MIME Types:**
|
|
118
|
+
- PNG: "image/png"
|
|
119
|
+
- JPEG: "image/jpeg"
|
|
120
|
+
- WEBP: "image/webp"
|
|
121
|
+
|
|
122
|
+
**MediaType Mapping:**
|
|
123
|
+
- "image/*" formats return MediaType.IMAGE
|
|
124
|
+
- "video/*" formats return MediaType.VIDEO
|
|
125
|
+
- Unknown formats return MediaType.ALL
|
|
126
|
+
- Mapping is based on MIME type prefix
|
|
127
|
+
|
|
128
|
+
### Constants Reference
|
|
129
|
+
|
|
130
|
+
- **IMAGE_MIME_TYPES**: Readonly object mapping image formats to MIME types
|
|
131
|
+
- Keys: "png", "jpeg", "webp"
|
|
132
|
+
- Values: Standard MIME type strings
|
|
133
|
+
- Used by getImageMimeType() method
|
|
134
|
+
|
|
135
|
+
### Common Use Cases
|
|
136
|
+
|
|
137
|
+
**Image Validation Pipeline:**
|
|
138
|
+
1. Check file type with isImage()
|
|
139
|
+
2. Validate dimensions with isValidDimensions()
|
|
140
|
+
3. Calculate aspect ratio with calculateAspectRatio()
|
|
141
|
+
4. Get MIME type with getImageMimeType()
|
|
142
|
+
5. Scale if needed with getScaledDimensions()
|
|
143
|
+
|
|
144
|
+
**Video Validation Pipeline:**
|
|
145
|
+
1. Check file type with isVideo()
|
|
146
|
+
2. Validate dimensions with isValidDimensions()
|
|
147
|
+
3. Parse media type with parseMediaType()
|
|
148
|
+
4. Scale if needed with getScaledDimensions()
|
|
149
|
+
|
|
150
|
+
**Format Conversion:**
|
|
151
|
+
1. Convert format enum to MIME type using getImageMimeType()
|
|
152
|
+
2. Convert MIME type to MediaType using parseMediaType()
|
|
153
|
+
3. Use MediaType for filtering and type checking
|
|
154
|
+
|
|
155
|
+
### Edge Case Handling
|
|
156
|
+
|
|
157
|
+
1. **Zero dimensions**: isValidDimensions() returns false
|
|
158
|
+
2. **Negative dimensions**: isValidDimensions() returns false
|
|
159
|
+
3. **Oversized dimensions**: isValidDimensions() returns false if > 8192
|
|
160
|
+
4. **Unknown file extensions**: isImage() and isVideo() return false
|
|
161
|
+
5. **Unknown MIME types**: parseMediaType() returns MediaType.ALL
|
|
162
|
+
6. **Equal aspect ratios**: getScaledDimensions() returns original if within limits
|
|
163
|
+
|
|
164
|
+
### Performance Considerations
|
|
165
|
+
|
|
166
|
+
1. All methods are synchronous and execute in O(1) time
|
|
167
|
+
2. No network calls or I/O operations
|
|
168
|
+
3. No side effects or state mutations
|
|
169
|
+
4. Safe to call frequently in loops or render cycles
|
|
170
|
+
5. No memory allocation beyond return values
|
|
171
|
+
|
|
172
|
+
## Dependencies
|
|
173
|
+
|
|
174
|
+
- No external dependencies
|
|
175
|
+
- References ImageFormat enum from domain types
|
|
176
|
+
- References MediaType enum from domain types
|
|
177
|
+
- Pure utility functions with no side effects
|
|
178
|
+
- Can be used by any layer without additional dependencies
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media Utilities
|
|
3
|
+
* Utility functions for media operations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ImageFormat, MEDIA_CONSTANTS, MediaType } from "../entities/Media";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Image MIME type mappings
|
|
10
|
+
*/
|
|
11
|
+
export const IMAGE_MIME_TYPES = {
|
|
12
|
+
[ImageFormat.PNG]: "image/png",
|
|
13
|
+
[ImageFormat.JPEG]: "image/jpeg",
|
|
14
|
+
[ImageFormat.WEBP]: "image/webp",
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Media utility class
|
|
19
|
+
*/
|
|
20
|
+
export class MediaUtils {
|
|
21
|
+
static isImage(uri: string): boolean {
|
|
22
|
+
const extension = uri.split(".").pop()?.toLowerCase();
|
|
23
|
+
return MEDIA_CONSTANTS.SUPPORTED_IMAGE_FORMATS.some(
|
|
24
|
+
(format) => format.replace(".", "") === extension
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static isVideo(uri: string): boolean {
|
|
29
|
+
const extension = uri.split(".").pop()?.toLowerCase();
|
|
30
|
+
return MEDIA_CONSTANTS.SUPPORTED_VIDEO_FORMATS.some(
|
|
31
|
+
(format) => format.replace(".", "") === extension
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static getImageMimeType(format: ImageFormat): string {
|
|
36
|
+
return IMAGE_MIME_TYPES[format];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static calculateAspectRatio(width: number, height: number): number {
|
|
40
|
+
return width / height;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getScaledDimensions(
|
|
44
|
+
originalWidth: number,
|
|
45
|
+
originalHeight: number,
|
|
46
|
+
maxWidth: number,
|
|
47
|
+
maxHeight: number
|
|
48
|
+
): { width: number; height: number } {
|
|
49
|
+
const aspectRatio = MediaUtils.calculateAspectRatio(
|
|
50
|
+
originalWidth,
|
|
51
|
+
originalHeight
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
let width = originalWidth;
|
|
55
|
+
let height = originalHeight;
|
|
56
|
+
|
|
57
|
+
if (width > maxWidth) {
|
|
58
|
+
width = maxWidth;
|
|
59
|
+
height = width / aspectRatio;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (height > maxHeight) {
|
|
63
|
+
height = maxHeight;
|
|
64
|
+
width = height * aspectRatio;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
width: Math.round(width),
|
|
69
|
+
height: Math.round(height),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static isValidDimensions(width: number, height: number): boolean {
|
|
74
|
+
return width > 0 && height > 0 && width <= 8192 && height <= 8192;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static parseMediaType(mimeType: string): MediaType {
|
|
78
|
+
if (mimeType.startsWith("image/")) return MediaType.IMAGE;
|
|
79
|
+
if (mimeType.startsWith("video/")) return MediaType.VIDEO;
|
|
80
|
+
return MediaType.ALL;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @umituz/react-native-media - Enhanced Public API
|
|
3
|
+
*
|
|
4
|
+
* Media picking capabilities for React Native apps
|
|
5
|
+
* Includes multimedia flashcard support
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import {
|
|
9
|
+
* useMedia,
|
|
10
|
+
* useMultimediaFlashcard,
|
|
11
|
+
* MultimediaFlashcardService,
|
|
12
|
+
* type MediaAttachment,
|
|
13
|
+
* type MultimediaFlashcard,
|
|
14
|
+
* } from '@umituz/react-native-media';
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Domain Layer - Original Media Entities
|
|
18
|
+
export {
|
|
19
|
+
MediaType,
|
|
20
|
+
ImageFormat as MediaImageFormat,
|
|
21
|
+
MediaQuality,
|
|
22
|
+
MediaLibraryPermission,
|
|
23
|
+
MEDIA_CONSTANTS,
|
|
24
|
+
} from "./domain/entities/Media";
|
|
25
|
+
|
|
26
|
+
export { IMAGE_MIME_TYPES as MEDIA_IMAGE_MIME_TYPES, MediaUtils } from "./domain/utils/MediaUtils";
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
MediaAsset,
|
|
30
|
+
MediaPickerResult,
|
|
31
|
+
MediaPickerOptions,
|
|
32
|
+
CameraOptions,
|
|
33
|
+
ImageDimensions as MediaImageDimensions,
|
|
34
|
+
ImageManipulationActions,
|
|
35
|
+
ImageSaveOptions as MediaImageSaveOptions,
|
|
36
|
+
} from "./domain/entities/Media";
|
|
37
|
+
|
|
38
|
+
// Infrastructure Layer - Original Media Services
|
|
39
|
+
export { MediaPickerService } from "./infrastructure/services/MediaPickerService";
|
|
40
|
+
export { MediaSaveService } from "./infrastructure/services/MediaSaveService";
|
|
41
|
+
export type { SaveResult, SaveOptions } from "./infrastructure/services/MediaSaveService";
|
|
42
|
+
|
|
43
|
+
// Presentation Layer - Original Media Hooks
|
|
44
|
+
export { useMedia } from "./presentation/hooks/useMedia";
|
|
45
|
+
|
|
46
|
+
// Multimedia Flashcard Support
|
|
47
|
+
export type {
|
|
48
|
+
CardMediaType,
|
|
49
|
+
CardMediaPosition,
|
|
50
|
+
CardMediaAttachment,
|
|
51
|
+
CardMultimediaFlashcard,
|
|
52
|
+
CardMediaGenerationRequest,
|
|
53
|
+
CardMediaGenerationResult,
|
|
54
|
+
CardMediaUploadProgress,
|
|
55
|
+
CardMediaCompressionOptions,
|
|
56
|
+
CardMediaValidation,
|
|
57
|
+
} from "./domain/entities/CardMultimedia.types";
|
|
58
|
+
|
|
59
|
+
export { CardMultimediaFlashcardService } from "./infrastructure/services/CardMultimediaService";
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
useCardMediaUpload,
|
|
63
|
+
useCardMediaGeneration,
|
|
64
|
+
useCardMediaValidation,
|
|
65
|
+
useCardMultimediaFlashcard,
|
|
66
|
+
type UseCardMediaUploadResult,
|
|
67
|
+
type UseCardMediaGenerationResult,
|
|
68
|
+
type UseCardMediaValidationResult,
|
|
69
|
+
type UseCardMultimediaFlashcardResult,
|
|
70
|
+
} from "./presentation/hooks/useCardMultimediaFlashcard";
|