gantri-components 2.251.1 → 2.252.1

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.
@@ -3,3 +3,4 @@ export * from './build-cloudinary-url';
3
3
  export * from './build-srcset';
4
4
  export * from './build-placeholder';
5
5
  export * from './normalize-resolution-aware';
6
+ export * from './infer-sizes-from-width';
@@ -0,0 +1,21 @@
1
+ import { NormalizedResolutionAware } from './normalize-resolution-aware';
2
+ /**
3
+ * Build a `sizes` attribute string from a normalized `width` map so
4
+ * `<Picture width={...} />` doesn't need a hand-written `sizes`. The
5
+ * browser uses `sizes` together with each `<source>`'s `srcset` to pick
6
+ * a single variant per DPR — without an accurate value it defaults to
7
+ * `100vw` and over-fetches on small containers (e.g. a 400-px desktop
8
+ * card pulling the 1200w variant instead of 800w).
9
+ *
10
+ * width=400 → "400px"
11
+ * width={{ lg: 400, sm: 720 }} → "(max-width: 720px) 720px, 400px"
12
+ * width={{ lg: 400, md: 600, sm: 720 }} →
13
+ * "(max-width: 720px) 720px, (max-width: 1024px) 600px, 400px"
14
+ * width=undefined → undefined (caller should fall
15
+ * back to the default `100vw`)
16
+ *
17
+ * When a breakpoint has no explicit width, we substitute `100vw` for
18
+ * that segment so the inferred string never silently invents a desktop
19
+ * size from a sm-only spec.
20
+ */
21
+ export declare const inferSizesFromWidth: (widths: NormalizedResolutionAware<number>) => string | undefined;
@@ -29,6 +29,12 @@ export interface PictureProps extends PicturePassThroughProps {
29
29
  alt: string;
30
30
  /** Override auto-detection of how to render the asset. */
31
31
  as?: PictureAs;
32
+ /**
33
+ * Target render width in px. Drives **both** the container CSS width
34
+ * AND the Cloudinary srcset (DPR multipliers `1x / 2x / 3x` of this
35
+ * value). Use it alongside `fill` to keep the parent-driven layout
36
+ * while still capping the source bytes the browser fetches.
37
+ */
32
38
  width?: ResolutionAwareProp<number>;
33
39
  height?: ResolutionAwareProp<number>;
34
40
  /** e.g. "16:9", "1:1". Drives both CSS aspect-ratio and Cloudinary ar_ transformation. */
@@ -41,7 +47,19 @@ export interface PictureProps extends PicturePassThroughProps {
41
47
  minWidth?: ResolutionAwareProp<Property.MinWidth>;
42
48
  /** CSS min-height on the container. */
43
49
  minHeight?: ResolutionAwareProp<Property.MinHeight>;
44
- /** Image fills its (position: relative) parent. Mutually exclusive with width/height. */
50
+ /**
51
+ * Image fills its (`position: relative`) parent — CSS-wise the container
52
+ * becomes `position: absolute; inset: 0; width/height: 100%`, so the
53
+ * configured `width` / `height` props are ignored for layout.
54
+ *
55
+ * `width` is still honored as a **render hint for srcset**: when set
56
+ * alongside `fill`, the srcset is built from DPR multipliers
57
+ * `[width × 1, width × 2, width × 3]` instead of the default
58
+ * `[320, 640, 1024, 1600, 2400]`. Pair `<Picture fill width={400} />`
59
+ * (with `sizes="400px"` for accuracy) on a 400-px container so the
60
+ * browser fetches an 800-px source on Retina instead of the 1024 it
61
+ * would pick from the default set.
62
+ */
45
63
  fill?: boolean;
46
64
  /** Native sizes attribute. Default: "100vw". Tells the browser how wide the image renders. */
47
65
  sizes?: string;