@umituz/react-native-image 1.3.5 → 1.3.6

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.6",
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",
@@ -0,0 +1,15 @@
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
+ }
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,50 @@
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 = '' } = 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
+ // Additional memegen.link requirements if needed
30
+ );
31
+ };
32
+
33
+ const top = encodeMemeText(topText);
34
+ const bottom = encodeMemeText(bottomText);
35
+
36
+ return `https://api.memegen.link/images/${templateKey}/${top}/${bottom}.png`;
37
+ }
38
+
39
+ /**
40
+ * Extracts template key from a memegen.link URL or filename
41
+ */
42
+ static extractTemplateKey(url: string): string {
43
+ if (!url) return 'custom';
44
+
45
+ // Example: https://api.memegen.link/images/distracted.png -> distracted
46
+ const parts = url.split('/');
47
+ const lastPart = parts[parts.length - 1] || '';
48
+ return lastPart.split('.')[0] || 'custom';
49
+ }
50
+ }