@uxf/core 10.10.1 → 11.10.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "10.10.1",
3
+ "version": "11.10.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -26,7 +26,7 @@
26
26
  "react": ">=18.2.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/react": "18.2.27",
29
+ "@types/react": "18.2.57",
30
30
  "react": "18.2.0"
31
31
  },
32
32
  "gitHead": "a2dee6aa67621f6eda17e63e88d0edf14f88455a"
package/utils/image.d.ts CHANGED
@@ -8,12 +8,19 @@ export declare function getImgQuality(quality: Quality | undefined, format: Form
8
8
  export declare function getImgUniqueIdentifier(src: ImageSource): string | undefined;
9
9
  export declare function getImgElementHeight(src: ImageSource, width: number | undefined, height: number | undefined): number | undefined;
10
10
  export declare function getImgElementWidth(src: ImageSource, width: number | undefined, height: number | undefined): number | undefined;
11
- export declare function getImgSrcSet(src?: ImageSource, width?: Dimension, height?: Dimension, options?: ResizerImageProps): string | undefined;
11
+ export type GetImgSrcSetOptions = ResizerImageProps & {
12
+ maxHiDpi?: 3 | 2 | 1;
13
+ };
14
+ export declare function getImgSrcSet(src?: ImageSource, width?: Dimension, height?: Dimension, options?: GetImgSrcSetOptions): string | undefined;
15
+ export type ImageSourcesOptions = Omit<GetImgSrcSetOptions, "quality" | "toFormat"> & {
16
+ isAvifDisabled?: boolean;
17
+ isWebPDisabled?: boolean;
18
+ };
12
19
  interface ImageSourcesProps {
13
20
  breakpointIndex?: number;
14
21
  breakpoints?: string[];
15
22
  height: Dimension;
16
- options?: Omit<ResizerImageProps, "quality" | "toFormat">;
23
+ options?: ImageSourcesOptions;
17
24
  quality?: Quality;
18
25
  src: ImageSource;
19
26
  width: Dimension;
package/utils/image.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ImgSources = exports.getImgSrcSet = exports.getImgElementWidth = exports.getImgElementHeight = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
+ const hide_1 = require("../components/hide");
8
9
  const file_1 = require("./file");
9
10
  const resizer_1 = require("./resizer");
10
11
  function toImageResponse(src) {
@@ -85,17 +86,20 @@ function getImgSrcSet(src, width, height, options = {}) {
85
86
  h = h || staticImageData.height;
86
87
  w = w || staticImageData.width;
87
88
  }
89
+ const { maxHiDpi, ...restOptions } = options;
88
90
  if (typeof h === "number" || typeof w === "number") {
89
- return HIDPI_SIZES.map((size) => (0, resizer_1.resizerImageUrl)(src, typeof w === "number" ? w * size : "auto", typeof h === "number" ? h * size : "auto", {
91
+ return (maxHiDpi ? HIDPI_SIZES.slice(-maxHiDpi) : HIDPI_SIZES)
92
+ .map((size) => (0, resizer_1.resizerImageUrl)(src, typeof w === "number" ? w * size : "auto", typeof h === "number" ? h * size : "auto", {
90
93
  toFormat,
91
- ...options,
92
- }) + (size > 1 ? ` ${size}x` : "")).join(", ");
94
+ ...restOptions,
95
+ }) + (size > 1 ? ` ${size}x` : ""))
96
+ .join(", ");
93
97
  }
94
- return (0, resizer_1.resizerImageUrl)(src, w, h, { toFormat, ...options });
98
+ return (0, resizer_1.resizerImageUrl)(src, w, h, { toFormat, ...restOptions });
95
99
  }
96
100
  exports.getImgSrcSet = getImgSrcSet;
97
101
  const ImgSources = (props) => {
98
- var _a, _b, _c;
102
+ var _a, _b, _c, _d, _e;
99
103
  if (!props.src) {
100
104
  return null;
101
105
  }
@@ -112,18 +116,20 @@ const ImgSources = (props) => {
112
116
  media = `(min-width: ${props.breakpoints[props.breakpointIndex]})`;
113
117
  }
114
118
  return (react_1.default.createElement(react_1.default.Fragment, null,
119
+ react_1.default.createElement(hide_1.Hide, { when: Boolean((_a = props.options) === null || _a === void 0 ? void 0 : _a.isAvifDisabled) },
120
+ react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
121
+ ...((_b = props.options) !== null && _b !== void 0 ? _b : {}),
122
+ quality: getImgQuality(props.quality, "avif"),
123
+ toFormat: "avif",
124
+ }), type: "image/avif" })),
125
+ react_1.default.createElement(hide_1.Hide, { when: Boolean((_c = props.options) === null || _c === void 0 ? void 0 : _c.isWebPDisabled) },
126
+ react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
127
+ ...((_d = props.options) !== null && _d !== void 0 ? _d : {}),
128
+ quality: getImgQuality(props.quality, "webp"),
129
+ toFormat: "webp",
130
+ }), type: "image/webp" })),
115
131
  react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
116
- ...((_a = props.options) !== null && _a !== void 0 ? _a : {}),
117
- quality: getImgQuality(props.quality, "avif"),
118
- toFormat: "avif",
119
- }), type: "image/avif" }),
120
- react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
121
- ...((_b = props.options) !== null && _b !== void 0 ? _b : {}),
122
- quality: getImgQuality(props.quality, "webp"),
123
- toFormat: "webp",
124
- }), type: "image/webp" }),
125
- react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
126
- ...((_c = props.options) !== null && _c !== void 0 ? _c : {}),
132
+ ...((_e = props.options) !== null && _e !== void 0 ? _e : {}),
127
133
  quality: getImgQuality(props.quality, "original"),
128
134
  }) })));
129
135
  };