@umituz/react-native-design-system 2.9.49 → 2.9.50

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-design-system",
3
- "version": "2.9.49",
3
+ "version": "2.9.50",
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, onboarding, and loading utilities",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -81,6 +81,11 @@ export {
81
81
  export {
82
82
  getMediaDuration,
83
83
  generateThumbnail,
84
+ isBase64DataUrl,
85
+ isRawBase64,
86
+ toDataUrl,
87
+ saveBase64ToFile,
88
+ downloadMediaToFile,
84
89
  } from "./infrastructure/utils/file-media-utils";
85
90
 
86
91
  // Multimedia Flashcard Support
@@ -1,3 +1,10 @@
1
+ /**
2
+ * File Media Utilities
3
+ * Utilities for handling media files (base64, downloads, file operations)
4
+ */
5
+
6
+ import { File, Paths } from "expo-file-system/next";
7
+
1
8
  interface FileWithType {
2
9
  readonly type: string;
3
10
  }
@@ -15,3 +22,66 @@ export function generateThumbnail(file: FileWithType): string | undefined {
15
22
  }
16
23
  return undefined;
17
24
  }
25
+
26
+ /**
27
+ * Check if a string is a base64 data URL
28
+ */
29
+ export const isBase64DataUrl = (str: string): boolean => {
30
+ return str.startsWith("data:image/");
31
+ };
32
+
33
+ /**
34
+ * Check if a string is raw base64 (not a URL and not a data URL)
35
+ */
36
+ export const isRawBase64 = (str: string): boolean => {
37
+ return !str.startsWith("http") && !str.startsWith("data:image/") && !str.startsWith("file://");
38
+ };
39
+
40
+ /**
41
+ * Convert raw base64 to data URL format
42
+ */
43
+ export const toDataUrl = (str: string): string => {
44
+ if (isBase64DataUrl(str)) return str;
45
+ if (isRawBase64(str)) return `data:image/jpeg;base64,${str}`;
46
+ return str;
47
+ };
48
+
49
+ /**
50
+ * Save base64 image to file system
51
+ */
52
+ export const saveBase64ToFile = async (base64Data: string): Promise<string> => {
53
+ const timestamp = Date.now();
54
+ const filename = `media_${timestamp}.jpg`;
55
+ const file = new File(Paths.cache, filename);
56
+
57
+ const pureBase64 = base64Data.replace(/^data:image\/\w+;base64,/, "");
58
+ const binaryString = atob(pureBase64);
59
+ const bytes = new Uint8Array(binaryString.length);
60
+ for (let i = 0; i < binaryString.length; i++) {
61
+ bytes[i] = binaryString.charCodeAt(i);
62
+ }
63
+
64
+ file.write(bytes);
65
+ return file.uri;
66
+ };
67
+
68
+ /**
69
+ * Download media from URL to local file
70
+ */
71
+ export const downloadMediaToFile = async (url: string, isVideo: boolean): Promise<string> => {
72
+ const timestamp = Date.now();
73
+ const extension = isVideo ? "mp4" : "jpg";
74
+ const filename = `media_${timestamp}.${extension}`;
75
+ const file = new File(Paths.cache, filename);
76
+
77
+ const response = await fetch(url);
78
+ if (!response.ok) {
79
+ throw new Error(`Failed to download media: ${response.statusText}`);
80
+ }
81
+
82
+ const arrayBuffer = await response.arrayBuffer();
83
+ const bytes = new Uint8Array(arrayBuffer);
84
+ file.write(bytes);
85
+
86
+ return file.uri;
87
+ };