@uxf/core 10.10.1 → 11.9.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 +1 -1
- package/utils/image.d.ts +9 -2
- package/utils/image.js +22 -16
package/package.json
CHANGED
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
|
|
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?:
|
|
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
|
|
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
|
-
...
|
|
92
|
-
}) + (size > 1 ? ` ${size}x` : ""))
|
|
94
|
+
...restOptions,
|
|
95
|
+
}) + (size > 1 ? ` ${size}x` : ""))
|
|
96
|
+
.join(", ");
|
|
93
97
|
}
|
|
94
|
-
return (0, resizer_1.resizerImageUrl)(src, w, h, { toFormat, ...
|
|
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
|
-
...((
|
|
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
|
};
|