@@ -73,61 +73,6 @@ export function currency(amount?: string, currency?: string): string {
7373 }
7474}
7575
76- /**
77- * Optimizes a Shopify image URL by requesting a specific size
78- * This significantly reduces bandwidth and improves loading times
79- *
80- * @param url - Original Shopify CDN image URL
81- * @param size - Desired image dimensions
82- * @param scale - Pixel density multiplier (default: 2 for retina displays)
83- * @returns Optimized image URL with size parameters
84- *
85- * @example For product thumbnails
86- * getOptimizedImageUrl(imageUrl, {width: 150, height: 150})
87- *
88- * @example For product detail images
89- * getOptimizedImageUrl(imageUrl, {width: 400, height: 400})
90- *
91- * @example For cart item thumbnails
92- * getOptimizedImageUrl(imageUrl, {width: 80, height: 80})
93- */
94- export function getOptimizedImageUrl (
95- url : string | undefined ,
96- size : { width : number ; height : number } ,
97- scale : number = 2 ,
98- ) : string | undefined {
99- if ( ! url ) {
100- return undefined ;
101- }
102-
103- try {
104- // Calculate actual dimensions for device pixel density
105- const width = size . width * scale ;
106- const height = size . height * scale ;
107-
108- // Shopify CDN image transformation pattern:
109- // Original: https://cdn.shopify.com/s/files/1/0001/0002/products/image.jpg
110- // Resized: https://cdn.shopify.com/s/files/1/0001/0002/products/image_600x600.jpg
111-
112- if ( url . includes ( 'cdn.shopify.com' ) ) {
113- // Remove any existing size parameters
114- const cleanUrl = url . replace ( / _ \d + x \d + ( \. \w + ) / , '$1' ) ;
115-
116- // Insert new size parameters before file extension
117- const lastDot = cleanUrl . lastIndexOf ( '.' ) ;
118- if ( lastDot > - 1 ) {
119- return `${ cleanUrl . slice ( 0 , lastDot ) } _${ width } x${ height } ${ cleanUrl . slice ( lastDot ) } ` ;
120- }
121- }
122-
123- // Return original URL if not a Shopify CDN image
124- return url ;
125- } catch {
126- // Return original URL if transformation fails
127- return url ;
128- }
129- }
130-
13176export function debugLog ( message : string , data ?: any ) {
13277 if ( __DEV__ ) {
13378 console . log ( message , data || '' ) ;
0 commit comments