@massimo-cassandro/minimo 1.14.4 → 1.14.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.14.4",
3
+ "version": "1.14.5",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -64,6 +64,7 @@ import { classnames } from './classnames.js';
64
64
  * @param {string[]} [args.formats=['avif','webp','pjpg']] - Image formats: the last one is used for the `img` fallback element, the others for the `source` elements.
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
+ * @param {((img: HTMLImageElement) => void) | null} [args.onLoad=null] - Called once the image has finished loading, receiving the `img` element (called immediately if the image is already complete).
67
68
  * @param {boolean} [args.condition=true] - When false, the function returns `null` without building anything.
68
69
  * @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).
69
70
  * @param {string|null} [args.pictureExtraClass=null] - Extra class(es) for the `picture` element.
@@ -82,6 +83,7 @@ export function buildPictureTag({
82
83
  formats = ['avif', 'webp', 'pjpg'],
83
84
  devMode = false,
84
85
  lazy = true,
86
+ onLoad = null,
85
87
  condition = true,
86
88
  legacyMediaSyntax = false,
87
89
  pictureExtraClass = null,
@@ -204,6 +206,14 @@ export function buildPictureTag({
204
206
  loading: lazy? 'lazy' : null,
205
207
  ...imgExtraAttrs
206
208
  },
209
+ callback: onLoad == null? undefined : el => {
210
+ const img = /** @type {HTMLImageElement} */ (el);
211
+ if(img.complete) {
212
+ onLoad(img);
213
+ } else {
214
+ img.addEventListener('load', () => onLoad(img), {once: true});
215
+ }
216
+ },
207
217
  // TODO classe popover, se attivato
208
218
  // callback: options.addPopover
209
219
  // ? el => el.addEventListener('click', () => zoomPopoverEl.togglePopover())