@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.
Files changed (52) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/USAGE.md +286 -4
  3. package/dist/abandoned-checkout.d.ts +45 -0
  4. package/dist/abandoned-checkout.js +81 -3
  5. package/dist/answer-readers.d.ts +11 -4
  6. package/dist/answer-readers.js +114 -0
  7. package/dist/astro.d.ts +2 -0
  8. package/dist/astro.js +1 -0
  9. package/dist/basket.d.ts +11 -1
  10. package/dist/basket.js +17 -0
  11. package/dist/catalog.d.ts +18 -0
  12. package/dist/catalog.js +27 -0
  13. package/dist/client/orders.d.ts +10 -1
  14. package/dist/client/orders.js +8 -1
  15. package/dist/client/products.d.ts +13 -3
  16. package/dist/client/products.js +35 -12
  17. package/dist/coupon.d.ts +16 -1
  18. package/dist/coupon.js +37 -0
  19. package/dist/endpoints/storefront-routes.d.ts +8 -2
  20. package/dist/endpoints/storefront-routes.js +12 -2
  21. package/dist/index.d.ts +15 -7
  22. package/dist/index.js +9 -4
  23. package/dist/operations.d.ts +4 -0
  24. package/dist/operations.js +4 -0
  25. package/dist/order-number.d.ts +9 -0
  26. package/dist/order-number.js +11 -0
  27. package/dist/product-view.d.ts +8 -0
  28. package/dist/product-view.js +26 -4
  29. package/dist/quote.d.ts +27 -0
  30. package/dist/quote.js +43 -0
  31. package/dist/review-capture.d.ts +77 -0
  32. package/dist/review-capture.js +172 -0
  33. package/dist/review-media.d.ts +8 -75
  34. package/dist/review-media.js +7 -170
  35. package/dist/review-session.d.ts +97 -0
  36. package/dist/review-session.js +157 -0
  37. package/dist/reviews.d.ts +33 -0
  38. package/dist/reviews.js +41 -0
  39. package/dist/schemas.d.ts +98 -0
  40. package/dist/schemas.js +31 -0
  41. package/dist/seo.d.ts +47 -0
  42. package/dist/seo.js +87 -0
  43. package/dist/server.d.ts +1 -0
  44. package/dist/server.js +1 -0
  45. package/dist/sitemap.d.ts +22 -0
  46. package/dist/sitemap.js +51 -0
  47. package/dist/store-request.d.ts +96 -0
  48. package/dist/store-request.js +102 -0
  49. package/dist/types.d.ts +50 -2
  50. package/dist/utils/image.d.ts +48 -0
  51. package/dist/utils/image.js +51 -0
  52. package/package.json +1 -1
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocart/storefront",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "Typed, validated SDK for Wocart cash-on-delivery storefronts: catalog reads, basket, checkout, OTP and order tracking, with Astro adapters.",
5
5
  "keywords": [
6
6
  "wocart",