@usequeek/theme-kit 0.5.5 → 0.5.7
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/components/cart/default-cart-shell.tsx +1 -1
- package/package.json +1 -1
- package/stores/cart-store.ts +6 -1
- package/types/cart.ts +8 -0
- package/types/vendor.ts +2 -0
- package/utils/image-srcset.ts +10 -3
- package/utils/product-media.ts +14 -1
|
@@ -123,7 +123,7 @@ export function DefaultCartShell({
|
|
|
123
123
|
return (
|
|
124
124
|
<li key={`${item.shop_id}-${item.id}`} className="core-cart-page__item">
|
|
125
125
|
{item.image ? (
|
|
126
|
-
<Image src={item.image} alt={item.title} className="core-cart-page__item-img" />
|
|
126
|
+
<Image src={item.image} variants={item.image_variants} intent="card" sizes="150px" alt={item.title} className="core-cart-page__item-img" />
|
|
127
127
|
) : (
|
|
128
128
|
<div className="core-cart-page__item-img core-cart-page__item-img--placeholder" />
|
|
129
129
|
)}
|
package/package.json
CHANGED
package/stores/cart-store.ts
CHANGED
|
@@ -187,7 +187,11 @@ export const useCartStore = create<CartState>()(
|
|
|
187
187
|
// A variant's own price/stock override the base product's — the same
|
|
188
188
|
// precedence the quick-add flow uses.
|
|
189
189
|
const unitPrice = (variant?.pricing.sale_amount ?? product.pricing.sale_amount) + addonTotal;
|
|
190
|
-
const
|
|
190
|
+
const itemMedia = [variant?.media, product.media].find((media) => media && (media.thumbnail ?? media.image) != null);
|
|
191
|
+
const itemImage = itemMedia ? (itemMedia.thumbnail ?? itemMedia.image) : null;
|
|
192
|
+
// The tier map belongs to `media.image`: when the picked url IS that image (the API's thumbnail falls back to it) the line can
|
|
193
|
+
// render a small copy; a separate thumbnail file is small already.
|
|
194
|
+
const itemImageVariants = itemMedia && itemImage === itemMedia.image ? (itemMedia.image_variants ?? null) : null;
|
|
191
195
|
|
|
192
196
|
// Confirm the add with a global toast (works across every theme) —
|
|
193
197
|
// except on QR, which has its own persistent cart bar (QrCartBar)
|
|
@@ -235,6 +239,7 @@ export const useCartStore = create<CartState>()(
|
|
|
235
239
|
title: product.title,
|
|
236
240
|
slug: product.slug,
|
|
237
241
|
image: itemImage,
|
|
242
|
+
...(itemImageVariants ? { image_variants: itemImageVariants } : {}),
|
|
238
243
|
unit_price: unitPrice,
|
|
239
244
|
quantity: Math.max(1, quantity),
|
|
240
245
|
addons,
|
package/types/cart.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ImageVariants } from './media';
|
|
2
|
+
|
|
1
3
|
export interface CartAddon {
|
|
2
4
|
addon_id: string;
|
|
3
5
|
item_id: string;
|
|
@@ -12,6 +14,12 @@ export interface CartItem {
|
|
|
12
14
|
title: string;
|
|
13
15
|
slug?: string | null;
|
|
14
16
|
image: string | null;
|
|
17
|
+
/**
|
|
18
|
+
* The tier map of `image` (the API's `image_variants`), kept so a cart thumbnail renders a small WebP copy: the line's `image` is
|
|
19
|
+
* the product's thumbnail, which the API sets to the full image unless the merchant chose another. Null when `image` is a separate,
|
|
20
|
+
* explicit thumbnail file (already small) or is not Media-backed; absent on a line saved before the kit kept it.
|
|
21
|
+
*/
|
|
22
|
+
image_variants?: ImageVariants | null;
|
|
15
23
|
unit_price: number;
|
|
16
24
|
quantity: number;
|
|
17
25
|
addons: CartAddon[];
|
package/types/vendor.ts
CHANGED
|
@@ -209,6 +209,8 @@ export interface StorefrontConfig {
|
|
|
209
209
|
default_variants?: Record<string, string>;
|
|
210
210
|
pages?: Record<string, {
|
|
211
211
|
banner?: string;
|
|
212
|
+
/** The tier map of `banner` (the API's `image_variants` contract); null when the banner is not Media-backed, absent without a banner. */
|
|
213
|
+
banner_variants?: ImageVariants | null;
|
|
212
214
|
title?: string;
|
|
213
215
|
subtitle?: string;
|
|
214
216
|
/** QR-only header overrides, each falling back to the vendor's own
|
package/utils/image-srcset.ts
CHANGED
|
@@ -201,12 +201,19 @@ export function resolveImageSources(
|
|
|
201
201
|
* (a 2048 px JPG of 139 KB is a 38 KB WebP). Never a smaller tier: a wide wordmark
|
|
202
202
|
* on a 3x phone would come out softer than the upload it replaces. The raw `url`
|
|
203
203
|
* when there is no `view` copy, no copies at all (an SVG, an off-host file) or
|
|
204
|
-
* copies of a different file
|
|
204
|
+
* copies of a different file, and when the upload is already a WebP no wider than
|
|
205
|
+
* `view`: the copy is then the same picture re-encoded, and often heavier (an 8 KB
|
|
206
|
+
* wordmark's `view` is 9.6 KB).
|
|
205
207
|
*/
|
|
206
208
|
export function logoSrc(url: string | null | undefined, variants: ImageVariants | null | undefined): string | null {
|
|
207
209
|
if (!url) {
|
|
208
210
|
return null;
|
|
209
211
|
}
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
+
const original = variants?.original;
|
|
213
|
+
const view = variants && original?.url === url ? variants.view : null;
|
|
214
|
+
if (!usableTier(view)) {
|
|
215
|
+
return url;
|
|
216
|
+
}
|
|
217
|
+
const samePixels = typeof view.w === 'number' && typeof original?.w === 'number' && view.w >= original.w;
|
|
218
|
+
return samePixels && /\.webp(?:[?#]|$)/i.test(url) ? url : view.url;
|
|
212
219
|
}
|
package/utils/product-media.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ImageVariants } from '../types/media';
|
|
2
|
-
import type { Product, ProductImage } from '../types/product';
|
|
2
|
+
import type { Product, ProductImage, ProductMedia } from '../types/product';
|
|
3
3
|
|
|
4
4
|
export interface MediaFrame {
|
|
5
5
|
id: string;
|
|
@@ -37,6 +37,19 @@ export function getSlideshowImages(product: Product): ProductImage[] {
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The tier map to pass to `<Image variants>` for a product picture: `media.image_variants` only when `src` IS the main image.
|
|
42
|
+
* A card or thumb often renders `media.thumbnail ?? media.image`; the API sets the thumbnail to the main image unless the merchant chose
|
|
43
|
+
* a separate thumbnail file, and `<Image>` renders the variants' url ahead of `src`, so the main photo's copies would replace the
|
|
44
|
+
* merchant's own thumbnail. Null for any other src (the thumbnail file is small already), for no src and for no media.
|
|
45
|
+
*/
|
|
46
|
+
export function mainImageVariants(
|
|
47
|
+
src: string | null | undefined,
|
|
48
|
+
media: Pick<ProductMedia, 'image' | 'image_variants'> | null | undefined,
|
|
49
|
+
): ImageVariants | null {
|
|
50
|
+
return src && media && media.image === src ? (media.image_variants ?? null) : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
/**
|
|
41
54
|
* The card hover-swap source: the second ordered image. Null unless the
|
|
42
55
|
* product carries at least two images — callers render the primary alone.
|