@massimo-cassandro/minimo 1.14.3 → 1.14.4
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/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { classnames } from './classnames.js';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {Object} PictureSizeEntry
|
|
7
|
-
* @property {number} [from] -
|
|
7
|
+
* @property {number} [from] - Breakpoint (px) the size applies from (`width >=` media condition); omitted in the (single) mobile-first default entry.
|
|
8
8
|
* @property {number | [number, number]} size - Rendered width (px, height computed with `ratio`) or explicit `[width, height]` pair (px).
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -17,7 +17,7 @@ import { classnames } from './classnames.js';
|
|
|
17
17
|
* of `sizes`, a candidate is generated for every integer density from 1 to `dpr`.
|
|
18
18
|
* The `sizes` attribute is built mobile-first: the entry without `from` is the
|
|
19
19
|
* default, and every other entry applies from its `from` breakpoint up, as a
|
|
20
|
-
* `(
|
|
20
|
+
* `(width >= …)` media condition (range syntax).
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* // fixed-width thumb (250px, 16:9 ratio, 1x and 2x candidates)
|
|
@@ -32,7 +32,7 @@ import { classnames } from './classnames.js';
|
|
|
32
32
|
* baseSrc,
|
|
33
33
|
* sizes: [250, { from: 576, size: 500 }, { from: 992, size: 800 }],
|
|
34
34
|
* });
|
|
35
|
-
* // sizes="(
|
|
35
|
+
* // sizes="(width >= 992px) 800px, (width >= 576px) 500px, 250px"
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* // custom ratio for numeric sizes and candidates up to 3x
|
|
@@ -65,6 +65,7 @@ import { classnames } from './classnames.js';
|
|
|
65
65
|
* @param {boolean} [args.devMode=false] - When true, `avif` is excluded from `formats` (not supported by the local dev environment).
|
|
66
66
|
* @param {boolean} [args.lazy=true] - When true, the `img` element gets `loading="lazy"`.
|
|
67
67
|
* @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
|
|
68
|
+
* @param {boolean} [args.legacyMediaSyntax=false] - When true, the `sizes` media conditions use `(min-width: …)` instead of the range syntax `(width >= …)`, for older browsers (pre Chrome/Edge 104, Firefox 102, Safari 16.4).
|
|
68
69
|
* @param {string|null} [args.pictureExtraClass=null] - Extra class(es) for the `picture` element.
|
|
69
70
|
* @param {Object<string, *>} [args.pictureExtraAttrs={}] - Extra attributes for the `picture` element.
|
|
70
71
|
* @param {string|null} [args.imgExtraClass=null] - Extra class(es) for the `img` element.
|
|
@@ -82,6 +83,7 @@ export function buildPictureTag({
|
|
|
82
83
|
devMode = false,
|
|
83
84
|
lazy = true,
|
|
84
85
|
condition = true,
|
|
86
|
+
legacyMediaSyntax = false,
|
|
85
87
|
pictureExtraClass = null,
|
|
86
88
|
pictureExtraAttrs = {},
|
|
87
89
|
imgExtraClass = null,
|
|
@@ -138,7 +140,10 @@ export function buildPictureTag({
|
|
|
138
140
|
// attributo `sizes` (mobile-first): le entry con breakpoint in ordine decrescente
|
|
139
141
|
// (vince la prima condizione che matcha), il default per ultimo
|
|
140
142
|
,sizesAttr = brkEntries
|
|
141
|
-
.map(({from, width}) =>
|
|
143
|
+
.map(({from, width}) => legacyMediaSyntax
|
|
144
|
+
? `(min-width: ${from}px) ${width}px`
|
|
145
|
+
: `(width >= ${from}px) ${width}px`
|
|
146
|
+
)
|
|
142
147
|
.reverse()
|
|
143
148
|
.concat(`${defaultEntry.width}px`)
|
|
144
149
|
.join(', ')
|