@wocart/storefront 1.19.0 → 1.20.0
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/CHANGELOG.md +65 -0
- package/USAGE.md +286 -4
- package/dist/abandoned-checkout.d.ts +45 -0
- package/dist/abandoned-checkout.js +81 -3
- package/dist/answer-readers.d.ts +11 -4
- package/dist/answer-readers.js +114 -0
- package/dist/astro.d.ts +2 -0
- package/dist/astro.js +1 -0
- package/dist/basket.d.ts +11 -1
- package/dist/basket.js +17 -0
- package/dist/catalog.d.ts +18 -0
- package/dist/catalog.js +27 -0
- package/dist/client/orders.d.ts +10 -1
- package/dist/client/orders.js +8 -1
- package/dist/client/products.d.ts +13 -3
- package/dist/client/products.js +35 -12
- package/dist/coupon.d.ts +16 -1
- package/dist/coupon.js +37 -0
- package/dist/endpoints/storefront-routes.d.ts +8 -2
- package/dist/endpoints/storefront-routes.js +12 -2
- package/dist/index.d.ts +15 -7
- package/dist/index.js +9 -4
- package/dist/operations.d.ts +4 -0
- package/dist/operations.js +4 -0
- package/dist/order-number.d.ts +9 -0
- package/dist/order-number.js +11 -0
- package/dist/product-view.d.ts +8 -0
- package/dist/product-view.js +26 -4
- package/dist/quote.d.ts +27 -0
- package/dist/quote.js +43 -0
- package/dist/review-capture.d.ts +77 -0
- package/dist/review-capture.js +172 -0
- package/dist/review-media.d.ts +8 -75
- package/dist/review-media.js +7 -170
- package/dist/review-session.d.ts +97 -0
- package/dist/review-session.js +157 -0
- package/dist/reviews.d.ts +33 -0
- package/dist/reviews.js +41 -0
- package/dist/schemas.d.ts +98 -0
- package/dist/schemas.js +31 -0
- package/dist/seo.d.ts +47 -0
- package/dist/seo.js +87 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +1 -0
- package/dist/sitemap.d.ts +22 -0
- package/dist/sitemap.js +51 -0
- package/dist/store-request.d.ts +96 -0
- package/dist/store-request.js +102 -0
- package/dist/types.d.ts +50 -2
- package/dist/utils/image.d.ts +48 -0
- package/dist/utils/image.js +51 -0
- package/package.json +1 -1
package/dist/utils/image.js
CHANGED
|
@@ -93,6 +93,57 @@ export function mediaUrl(key, mediaDomain) {
|
|
|
93
93
|
const origin = mediaOriginOf(mediaDomain);
|
|
94
94
|
return origin === null ? null : `${origin}/${segments.map(encodeURIComponent).join("/")}`;
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The same photo at several widths, with width descriptors
|
|
98
|
+
* (`… 360w, … 720w`), for an `<img>` whose `sizes` says how wide it shows —
|
|
99
|
+
* a phone then downloads a phone-sized file. Each size is converted to the
|
|
100
|
+
* best format the browser takes (`format=auto`).
|
|
101
|
+
*
|
|
102
|
+
* @returns `null` when there is no media domain, the URL is not on it, or no
|
|
103
|
+
* width is a positive whole number.
|
|
104
|
+
*/
|
|
105
|
+
export function mediaImageSrcset(src, widths, options = {}) {
|
|
106
|
+
const sizes = [...new Set(widths.filter((width) => Number.isInteger(width) && width > 0))].sort((a, b) => a - b);
|
|
107
|
+
if (sizes.length === 0)
|
|
108
|
+
return null;
|
|
109
|
+
const { ratio, quality, mediaDomain } = options;
|
|
110
|
+
const cropped = ratio !== undefined && Number.isFinite(ratio) && ratio > 0;
|
|
111
|
+
const encoding = quality === undefined ? {} : { quality };
|
|
112
|
+
const entries = [];
|
|
113
|
+
for (const width of sizes) {
|
|
114
|
+
const url = mediaImageUrl(src, cropped
|
|
115
|
+
? { width, height: Math.max(1, Math.round(width * ratio)), fit: "cover", format: "auto", ...encoding }
|
|
116
|
+
: { width, fit: "scale-down", format: "auto", ...encoding }, mediaDomain);
|
|
117
|
+
if (url === null)
|
|
118
|
+
return null;
|
|
119
|
+
entries.push(`${url} ${width}w`);
|
|
120
|
+
}
|
|
121
|
+
return entries.join(", ");
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A picked image as a theme draws it: its URL on the store's media domain,
|
|
125
|
+
* its alt text (empty when the merchant wrote none), its size, and its focal
|
|
126
|
+
* point as `object-position`, so a cropped photo keeps what matters in view.
|
|
127
|
+
*
|
|
128
|
+
* @returns `null` when no image is picked, the key cannot name an object, or
|
|
129
|
+
* the store has no media domain.
|
|
130
|
+
*/
|
|
131
|
+
export function pictureOf(image, mediaDomain) {
|
|
132
|
+
if (!image)
|
|
133
|
+
return null;
|
|
134
|
+
const src = mediaUrl(image.key, mediaDomain);
|
|
135
|
+
if (src === null)
|
|
136
|
+
return null;
|
|
137
|
+
const percent = (value) => `${Math.round(Math.min(1, Math.max(0, value)) * 100)}%`;
|
|
138
|
+
const focal = image.focal;
|
|
139
|
+
return {
|
|
140
|
+
src,
|
|
141
|
+
alt: image.alt ?? "",
|
|
142
|
+
width: image.width,
|
|
143
|
+
height: image.height,
|
|
144
|
+
position: focal && Number.isFinite(focal.x) && Number.isFinite(focal.y) ? `${percent(focal.x)} ${percent(focal.y)}` : undefined,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
96
147
|
/**
|
|
97
148
|
* Predefined image sizes for common use cases
|
|
98
149
|
*/
|
package/package.json
CHANGED