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

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.
@@ -63,10 +63,69 @@
63
63
  )
64
64
  }
65
65
 
66
+ function isConvincelyDomain(url: URL): boolean {
67
+ try {
68
+ return url.hostname.endsWith('.convincely.io')
69
+ } catch {
70
+ return false
71
+ }
72
+ }
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 {
86
+ 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)
100
+ }
101
+ return url.toString()
102
+ }
103
+
104
+ return imageSrc
105
+ } catch {
106
+ return imageSrc
107
+ }
108
+ }
109
+
66
110
  function getOptimizedImageUrl(imageSrc: string, targetWidth: number): string {
67
111
  const width = findClosestSize(targetWidth)
68
- const imgSrc = loader ? loader({ src: imageSrc, width }) : undefined
69
- return imgSrc || getImgUrl(imageSrc)
112
+
113
+ try {
114
+ 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
120
+ }
121
+ } catch {
122
+ // If URL parsing fails, continue with default behavior
123
+ }
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`
70
129
  }
71
130
 
72
131
  function getImgUrl(imageSrc: string): string {
@@ -78,6 +137,9 @@
78
137
  return imageSrc.startsWith('http') ? imageSrc : `${baseUrl}${imageSrc}`
79
138
  }
80
139
 
140
+ // Add dpl param to src if it's a Convincely domain
141
+ const processedSrc = $derived(addDplParamIfNeeded(src))
142
+
81
143
  function handleLoad() {
82
144
  isLoaded = true
83
145
  }
@@ -122,10 +184,10 @@
122
184
  })
123
185
 
124
186
  const srcSet = $derived.by(() =>
125
- widthCandidates.map((w) => `${getOptimizedImageUrl(src, w)} ${w}w`).join(', '),
187
+ widthCandidates.map((w) => `${getOptimizedImageUrl(processedSrc, w)} ${w}w`).join(', '),
126
188
  )
127
189
 
128
- const fallbackSrc = $derived.by(() => getOptimizedImageUrl(src, widthCandidates[0]))
190
+ const fallbackSrc = $derived.by(() => getOptimizedImageUrl(processedSrc, widthCandidates[0]))
129
191
 
130
192
  const fadeClasses = $derived.by(() => {
131
193
  if (loading === 'eager') return ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/svelte",
3
- "version": "0.0.1-dev.1765907257168",
3
+ "version": "0.0.1-dev.1765971320697",
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.1765907257168",
78
+ "@picked/client": "0.0.1-dev.1765971320697",
79
79
  "effector": "^23.3.0",
80
80
  "svelte": "^5.34.3"
81
81
  },