@eldrajs/sdk 0.5.1 → 0.5.2

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 CHANGED
@@ -9,6 +9,10 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - **A 3840 px image variant, `uhd`.** A full-width image on a high-density screen wants about 3840 px, and
13
+ `full` stops at 2560. `imageSrcset` now lists `…/uhd 3840w` after `full`, `imageVariantFor` falls back to
14
+ `uhd` instead of `full`, and the original is listed only when it is wider than 3840 px.
15
+ `ELDRA_IMAGE_VARIANT_WIDTHS` and `EldraImageVariant` carry it. It needs the media host that serves `uhd`.
12
16
  - **Removed: the checkout summary types.** `EldraOrderPreview`, `EldraOrderPreviewGiftCard` and
13
17
  `EldraOrderPreviewDiscountCode` are no longer exported. They typed `POST /order/v1/preview`, which the SDK
14
18
  never had a method for: delivery choice, the order summary, order creation and payment belong to the hosted
package/dist/index.d.ts CHANGED
@@ -158,7 +158,7 @@ interface EldraTrackerScript {
158
158
  */
159
159
  export declare function analyticsTrackerScript(options?: EldraTrackerScriptOptions): EldraTrackerScript | undefined;
160
160
  /** A size the media host serves by path suffix; `original` is the uploaded file, untransformed. */
161
- type EldraImageVariant = 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'original';
161
+ type EldraImageVariant = 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'uhd' | 'original';
162
162
  /** The variants the media host resizes, narrowest first. */
163
163
  type EldraSizedImageVariant = Exclude<EldraImageVariant, 'original'>;
164
164
  /**
@@ -186,14 +186,14 @@ export declare function isEldraImage(source: EldraImageSource): boolean;
186
186
  export declare function imageUrl(source: string, variant: EldraImageVariant): string;
187
187
  export declare function imageUrl(source: EldraImageSource, variant: EldraImageVariant): string | undefined;
188
188
  /**
189
- * The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `full`
189
+ * The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `uhd`
190
190
  * when nothing is that wide.
191
191
  */
192
192
  export declare function imageVariantFor(width: number, density?: number): EldraSizedImageVariant;
193
193
  interface EldraImageSrcsetOptions {
194
194
  /**
195
195
  * The original's width in pixels, by default the source's `width`. Wider variants are dropped and
196
- * the last is described at its true width; an original wider than `full` is listed itself, last.
196
+ * the last is described at its true width; an original wider than `uhd` is listed itself, last.
197
197
  */
198
198
  originalWidth?: number;
199
199
  }
package/dist/index.js CHANGED
@@ -156,11 +156,13 @@ const ELDRA_IMAGE_VARIANT_WIDTHS = {
156
156
  md: 800,
157
157
  lg: 1200,
158
158
  xl: 1920,
159
- full: 2560
159
+ full: 2560,
160
+ uhd: 3840
160
161
  };
161
162
  const SIZED_VARIANTS = Object.keys(ELDRA_IMAGE_VARIANT_WIDTHS);
163
+ const WIDEST = "uhd";
162
164
  const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
163
- const ELDRA_ASSET_URL = new RegExp(`^((?:(?:https?:)?//[^/\\s,?#]+)?(?:/[^\\s,?#]*)?/public/${UUID}/assets/${UUID})(?:/(?:sm|md|lg|xl|full|original))?/?$`, "i");
165
+ const ELDRA_ASSET_URL = new RegExp(`^((?:(?:https?:)?//[^/\\s,?#]+)?(?:/[^\\s,?#]*)?/public/${UUID}/assets/${UUID})(?:/(?:sm|md|lg|xl|full|uhd|original))?/?$`, "i");
164
166
  const RESIZABLE_CONTENT_TYPES = /* @__PURE__ */ new Set([
165
167
  "image/jpeg",
166
168
  "image/png",
@@ -198,13 +200,13 @@ function imageUrl(source, variant) {
198
200
  return base ? `${base}/${variant}` : sourceUrl(source);
199
201
  }
200
202
  /**
201
- * The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `full`
203
+ * The narrowest variant at least `width` CSS pixels wide at the given pixel density, or `uhd`
202
204
  * when nothing is that wide.
203
205
  */
204
206
  function imageVariantFor(width, density = 1) {
205
207
  const needed = width * density;
206
208
  if (!Number.isFinite(needed) || needed <= 0) throw new RangeError(`imageVariantFor needs a positive width, got ${width} at ${density}x`);
207
- return SIZED_VARIANTS.find((variant) => ELDRA_IMAGE_VARIANT_WIDTHS[variant] >= needed) ?? "full";
209
+ return SIZED_VARIANTS.find((variant) => ELDRA_IMAGE_VARIANT_WIDTHS[variant] >= needed) ?? WIDEST;
208
210
  }
209
211
  function originalDisplays(source) {
210
212
  const contentType = typeof source === "object" ? source?.contentType?.toLowerCase() : void 0;
@@ -227,7 +229,7 @@ function imageSrcset(source, options = {}) {
227
229
  }
228
230
  candidates.push(`${base}/${variant} ${width}w`);
229
231
  }
230
- if (isSide(originalWidth) && Math.round(originalWidth) > ELDRA_IMAGE_VARIANT_WIDTHS.full && originalDisplays(source)) candidates.push(`${base}/original ${Math.round(originalWidth)}w`);
232
+ if (isSide(originalWidth) && Math.round(originalWidth) > ELDRA_IMAGE_VARIANT_WIDTHS[WIDEST] && originalDisplays(source)) candidates.push(`${base}/original ${Math.round(originalWidth)}w`);
231
233
  return candidates.join(", ");
232
234
  }
233
235
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/sdk",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Framework-free client for the Eldra Web Studio public storefront API: CMS, catalog, cart, checkout handoff, orders, inventory. Types generated from your gateway's OpenAPI document and CMS schemas at build time.",
5
5
  "keywords": [
6
6
  "cms",