@umituz/react-native-image 1.3.5 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-image",
3
- "version": "1.3.5",
3
+ "version": "1.3.8",
4
4
  "description": "Image manipulation and viewing for React Native apps - resize, crop, rotate, flip, compress, gallery viewer",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -33,8 +33,7 @@
33
33
  "expo-image-manipulator": ">=12.0.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@umituz/react-native-animation": "latest",
37
- "@umituz/react-native-design-system": "^2.1.0",
36
+ "@umituz/react-native-design-system": "latest",
38
37
  "expo-image": ">=1.0.0",
39
38
  "expo-media-library": ">=15.0.0",
40
39
  "expo-sharing": ">=12.0.0",
@@ -44,8 +43,7 @@
44
43
  "react-native-reanimated": ">=3.0.0"
45
44
  },
46
45
  "devDependencies": {
47
- "@umituz/react-native-animation": "latest",
48
- "@umituz/react-native-design-system": "^2.1.0",
46
+ "@umituz/react-native-design-system": "latest",
49
47
  "expo-image": "~2.0.0",
50
48
  "expo-image-manipulator": "~13.0.0",
51
49
  "expo-media-library": "~17.0.0",
@@ -65,4 +63,4 @@
65
63
  "README.md",
66
64
  "LICENSE"
67
65
  ]
68
- }
66
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Image Template Types
3
+ */
4
+
5
+ export interface ImageTemplate {
6
+ id: string;
7
+ name: string;
8
+ url: string;
9
+ }
10
+
11
+ export interface MemeTemplateOptions {
12
+ templateKey: string;
13
+ topText?: string;
14
+ bottomText?: string;
15
+ style?: string; // e.g. 'black' for black text, or custom style
16
+ width?: number;
17
+ height?: number;
18
+ }
package/src/index.ts CHANGED
@@ -26,6 +26,11 @@ export type {
26
26
  ImageFlipOptions,
27
27
  } from './domain/entities/ImageTypes';
28
28
 
29
+ export type {
30
+ ImageTemplate,
31
+ MemeTemplateOptions,
32
+ } from './domain/entities/ImageTemplateTypes';
33
+
29
34
  export {
30
35
  ImageFormat,
31
36
  ImageOrientation,
@@ -68,6 +73,7 @@ export { ImageAIEnhancementService, type AutoEnhancementOptions, type Enhancemen
68
73
  export { ImageMetadataService, type ImageMetadataExtractionOptions } from './infrastructure/services/ImageMetadataService';
69
74
  export { ImageQualityPresetService, type QualityPreset, type QualityPresets, IMAGE_QUALITY_PRESETS } from './infrastructure/utils/ImageQualityPresets';
70
75
  export { ImageSpecializedEnhancementService } from './infrastructure/services/ImageSpecializedEnhancementService';
76
+ export { ImageTemplateService } from './infrastructure/services/ImageTemplateService';
71
77
 
72
78
  // =============================================================================
73
79
  // PRESENTATION LAYER - React Native Components & Hooks
@@ -0,0 +1,60 @@
1
+ import { MemeTemplateOptions } from '../../domain/entities/ImageTemplateTypes';
2
+
3
+ /**
4
+ * ImageTemplateService
5
+ *
6
+ * Provides utilities for generating image template URLs (e.g. Memegen.link)
7
+ */
8
+ export class ImageTemplateService {
9
+ /**
10
+ * Generates a Memegen.link URL for a given template and texts
11
+ *
12
+ * @param options Meme configuration (templateKey, topText, bottomText)
13
+ * @returns Formatted memegen.link URL
14
+ */
15
+ static generateMemeUrl(options: MemeTemplateOptions): string {
16
+ const { templateKey, topText = '', bottomText = '', style, width, height } = options;
17
+
18
+ // Internal helper for memegen-specific encoding
19
+ const encodeMemeText = (text: string) => {
20
+ const sanitized = text.trim();
21
+ if (!sanitized) return "_";
22
+
23
+ return encodeURIComponent(
24
+ sanitized
25
+ .replace(/ /g, "_")
26
+ .replace(/\?/g, "~q")
27
+ .replace(/#/g, "~h")
28
+ .replace(/\//g, "~s")
29
+ );
30
+ };
31
+
32
+ const top = encodeMemeText(topText);
33
+ const bottom = encodeMemeText(bottomText);
34
+
35
+ let url = `https://api.memegen.link/images/${templateKey}/${top}/${bottom}.png`;
36
+
37
+ const params: string[] = [];
38
+ if (style) params.push(`style=${style}`);
39
+ if (width) params.push(`width=${width}`);
40
+ if (height) params.push(`height=${height}`);
41
+
42
+ if (params.length > 0) {
43
+ url += `?${params.join('&')}`;
44
+ }
45
+
46
+ return url;
47
+ }
48
+
49
+ /**
50
+ * Extracts template key from a memegen.link URL or filename
51
+ */
52
+ static extractTemplateKey(url: string): string {
53
+ if (!url) return 'custom';
54
+
55
+ // Example: https://api.memegen.link/images/distracted.png -> distracted
56
+ const parts = url.split('/');
57
+ const lastPart = parts[parts.length - 1] || '';
58
+ return lastPart.split('.')[0] || 'custom';
59
+ }
60
+ }