@picked/svelte 0.0.1-dev.1765971320697 → 0.0.1-dev.1765991816856

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.
@@ -71,64 +71,35 @@
71
71
  }
72
72
  }
73
73
 
74
- function isShopifyDomain(url: URL): boolean {
75
- try {
76
- return url.hostname === 'cdn.shopify.com'
77
- } catch {
78
- return false
79
- }
80
- }
81
-
82
- /**
83
- * Add dpl param to Convincely domain URLs for deployment-specific routing.
84
- */
85
- function addDplParamIfNeeded(imageSrc: string): string {
74
+ function getOptimizedImageUrl(imageSrc: string, targetWidth: number): string {
86
75
  try {
87
- const url = new URL(imageSrc, import.meta.url)
88
-
89
- if (isConvincelyDomain(url)) {
90
- // Check for Vercel deployment ID (works in both browser and server contexts)
91
- const vercelDeploymentId = typeof import.meta.env !== 'undefined'
92
- ? import.meta.env.VERCEL_DEPLOYMENT_ID
93
- : undefined
94
- const vercelSkewProtection = typeof import.meta.env !== 'undefined'
95
- ? import.meta.env.VERCEL_SKEW_PROTECTION_ENABLED
96
- : undefined
97
-
98
- if (vercelDeploymentId && vercelSkewProtection === '1') {
99
- url.searchParams.set('dpl', vercelDeploymentId)
76
+ // If a custom loader is provided, use it first
77
+ if (loader) {
78
+ const result = loader({ src: imageSrc, width: targetWidth })
79
+ if (result !== undefined) {
80
+ return result
100
81
  }
101
- return url.toString()
102
82
  }
103
-
104
- return imageSrc
105
- } catch {
106
- return imageSrc
107
- }
108
- }
109
83
 
110
- function getOptimizedImageUrl(imageSrc: string, targetWidth: number): string {
111
- const width = findClosestSize(targetWidth)
112
-
113
- try {
114
84
  const url = new URL(imageSrc, import.meta.url)
115
-
116
- // If it's a Shopify domain and a custom loader is provided, use the loader
117
- if (isShopifyDomain(url) && loader) {
118
- const customUrl = loader({ src: imageSrc, width })
119
- if (customUrl) return customUrl
85
+
86
+ // Handle Convincely domain optimization through the image optimization service
87
+ if (isConvincelyDomain(url)) {
88
+ const encodedUrl = encodeURIComponent(url.toString())
89
+ const optimizedSize = findClosestSize(targetWidth)
90
+ return `https://img.convincely.io/_next/image?url=${encodedUrl}&w=${optimizedSize}&q=75`
120
91
  }
92
+
93
+ // For other domains, return the original URL
94
+ return getImgUrl(imageSrc)
121
95
  } catch {
122
- // If URL parsing fails, continue with default behavior
96
+ // If URL parsing fails, fall back to original behavior
97
+ return getImgUrl(imageSrc)
123
98
  }
124
-
125
- // Default optimization: use img.convincely.io for all images
126
- const imgUrl = getImgUrl(imageSrc)
127
- const encodedUrl = encodeURIComponent(imgUrl)
128
- return `https://img.convincely.io/_next/image?url=${encodedUrl}&w=${width}&q=75`
129
99
  }
130
100
 
131
101
  function getImgUrl(imageSrc: string): string {
102
+ // Skip base64 images
132
103
  if (imageSrc.startsWith('data:')) {
133
104
  return imageSrc
134
105
  }
@@ -137,9 +108,6 @@
137
108
  return imageSrc.startsWith('http') ? imageSrc : `${baseUrl}${imageSrc}`
138
109
  }
139
110
 
140
- // Add dpl param to src if it's a Convincely domain
141
- const processedSrc = $derived(addDplParamIfNeeded(src))
142
-
143
111
  function handleLoad() {
144
112
  isLoaded = true
145
113
  }
@@ -161,6 +129,7 @@
161
129
  rootMargin: '50px',
162
130
  },
163
131
  )
132
+
164
133
  observer.observe(elementToObserve)
165
134
 
166
135
  return () => {
@@ -184,11 +153,12 @@
184
153
  })
185
154
 
186
155
  const srcSet = $derived.by(() =>
187
- widthCandidates.map((w) => `${getOptimizedImageUrl(processedSrc, w)} ${w}w`).join(', '),
156
+ widthCandidates.map((w) => `${getOptimizedImageUrl(src, w)} ${w}w`).join(', '),
188
157
  )
189
158
 
190
- const fallbackSrc = $derived.by(() => getOptimizedImageUrl(processedSrc, widthCandidates[0]))
159
+ const fallbackSrc = $derived.by(() => getOptimizedImageUrl(src, widthCandidates[0]))
191
160
 
161
+ // Only apply fade-in when loading is not eager
192
162
  const fadeClasses = $derived.by(() => {
193
163
  if (loading === 'eager') return ''
194
164
  return `transition-opacity duration-300 ${isLoaded ? 'opacity-100' : 'opacity-0'}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/svelte",
3
- "version": "0.0.1-dev.1765971320697",
3
+ "version": "0.0.1-dev.1765991816856",
4
4
  "dependencies": {
5
5
  "d3": "^7.9.0"
6
6
  },
@@ -75,7 +75,7 @@
75
75
  ],
76
76
  "module": "./dist/index.js",
77
77
  "peerDependencies": {
78
- "@picked/client": "0.0.1-dev.1765971320697",
78
+ "@picked/client": "0.0.1-dev.1765991816856",
79
79
  "effector": "^23.3.0",
80
80
  "svelte": "^5.34.3"
81
81
  },