@uxf/ui 1.0.0-beta.88 → 1.0.0-beta.89

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/ui",
3
- "version": "1.0.0-beta.88",
3
+ "version": "1.0.0-beta.89",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,5 +1,6 @@
1
- import { ImageSource } from "@uxf/core/utils/resizer";
1
+ import { ImageSource, ResizerImageProps } from "@uxf/core/utils/resizer";
2
2
  import { FC, ImgHTMLAttributes, ReactNode } from "react";
3
+ import { Quality } from "../utils/image";
3
4
  declare type ImgProps = ImgHTMLAttributes<HTMLImageElement>;
4
5
  declare type Props = {
5
6
  alt: string;
@@ -10,6 +11,8 @@ declare type Props = {
10
11
  loading?: ImgProps["loading"];
11
12
  mode?: "contain" | "cover" | "responsive";
12
13
  noImageContent?: ReactNode;
14
+ options?: Omit<ResizerImageProps, "quality" | "toFormat">;
15
+ quality?: Quality;
13
16
  role?: ImgProps["role"];
14
17
  src: ImageSource | null | undefined;
15
18
  widths?: number[];
@@ -10,7 +10,7 @@ const react_1 = __importDefault(require("react"));
10
10
  const context_1 = require("../context");
11
11
  const image_1 = require("../utils/image");
12
12
  const RasterImage = (props) => {
13
- var _a, _b, _c, _d, _e, _f, _g;
13
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14
14
  const componentContext = (0, context_1.useComponentContext)("rasterImage");
15
15
  const className = [
16
16
  props.mode === "contain" && "uxf-raster-image--contain",
@@ -18,17 +18,18 @@ const RasterImage = (props) => {
18
18
  props.className,
19
19
  ];
20
20
  const breakpoints = ["0em", ...Object.values((_a = props.breakpoints) !== null && _a !== void 0 ? _a : componentContext.breakpoints)];
21
- const resizerSrc = (0, resizer_1.resizerImageUrl)(props.src, (_b = props.width) !== null && _b !== void 0 ? _b : "auto", (_c = props.height) !== null && _c !== void 0 ? _c : "auto");
21
+ const resizerSrc = (0, resizer_1.resizerImageUrl)(props.src, (_b = props.width) !== null && _b !== void 0 ? _b : "auto", (_c = props.height) !== null && _c !== void 0 ? _c : "auto", {
22
+ ...((_d = props.options) !== null && _d !== void 0 ? _d : {}),
23
+ quality: (0, image_1.getImgQuality)(props.quality, "original"),
24
+ });
22
25
  if (!resizerSrc) {
23
26
  return (react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-raster-image uxf-raster-image--no-image", ...className) }, props.noImageContent));
24
27
  }
25
- return (react_1.default.createElement("picture", { className: (0, cx_1.cx)("uxf-raster-image", ...className) }, (_e = (_d = props.widths) === null || _d === void 0 ? void 0 : _d.map((w, i) => i < breakpoints.length && (react_1.default.createElement(image_1.ImgSources, { breakpointIndex: i, breakpoints: breakpoints, height: props.heights && props.heights[i]
28
+ return (react_1.default.createElement("picture", { className: (0, cx_1.cx)("uxf-raster-image", ...className) }, (_f = (_e = props.widths) === null || _e === void 0 ? void 0 : _e.map((w, i) => i < breakpoints.length && (react_1.default.createElement(image_1.ImgSources, { breakpointIndex: i, breakpoints: breakpoints, height: props.heights && props.heights[i]
26
29
  ? props.heights[i]
27
30
  : props.width && props.height
28
31
  ? Math.ceil((props.height / props.width) * w)
29
- : "auto", key: w, src: props.src, width: w }))).reverse()) !== null && _e !== void 0 ? _e : (
30
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
31
- react_1.default.createElement(image_1.ImgSources, { height: (_f = props.height) !== null && _f !== void 0 ? _f : "auto", src: props.src, width: (_g = props.width) !== null && _g !== void 0 ? _g : "auto" })),
32
+ : "auto", key: w, options: props.options, quality: props.quality, src: props.src, width: w }))).reverse()) !== null && _f !== void 0 ? _f : (react_1.default.createElement(image_1.ImgSources, { height: (_g = props.height) !== null && _g !== void 0 ? _g : "auto", options: props.options, quality: props.quality, src: props.src, width: (_h = props.width) !== null && _h !== void 0 ? _h : "auto" })),
32
33
  react_1.default.createElement("img", { alt: props.alt, className: (0, cx_1.cx)("uxf-raster-image__img", props.mode === "contain" && "uxf-raster-image__img--contain", props.mode === "cover" && "uxf-raster-image__img--cover", props.imgClassName), height: props.height, loading: props.loading, src: resizerSrc, width: props.width })));
33
34
  };
34
35
  exports.RasterImage = RasterImage;
@@ -10,6 +10,8 @@ declare const _default: {
10
10
  loading?: "eager" | "lazy" | undefined;
11
11
  mode?: "contain" | "cover" | "responsive" | undefined;
12
12
  noImageContent?: React.ReactNode;
13
+ options?: Omit<import("@uxf/core/utils/resizer").ResizerImageProps, "quality" | "toFormat"> | undefined;
14
+ quality?: import("../utils/image").Quality | undefined;
13
15
  role?: React.AriaRole | undefined;
14
16
  src: import("@uxf/core/utils/resizer").ImageSource | null | undefined;
15
17
  widths?: number[] | undefined;
package/utils/image.d.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  import { ImageSource, ResizerImageProps } from "@uxf/core/utils/resizer";
2
2
  import { FC } from "react";
3
3
  export declare type Dimension = number | "auto";
4
+ export declare type Format = "avif" | "webp" | "original";
5
+ export declare type Quality = number | Record<Format, number>;
6
+ export declare function getImgQuality(quality: Quality | undefined, format: Format): number | undefined;
4
7
  export declare function getImgUniqueIdentifier(src: ImageSource): string | undefined;
5
8
  export declare function getImgSrcSet(src?: ImageSource, width?: Dimension, height?: Dimension, options?: ResizerImageProps): string | undefined;
6
9
  interface ImageSourcesProps {
7
10
  breakpointIndex?: number;
8
11
  breakpoints?: string[];
9
12
  height: Dimension;
13
+ options?: Omit<ResizerImageProps, "quality" | "toFormat">;
14
+ quality?: Quality;
10
15
  src: ImageSource;
11
16
  width: Dimension;
12
17
  }
package/utils/image.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ImgSources = exports.getImgSrcSet = exports.getImgUniqueIdentifier = void 0;
6
+ exports.ImgSources = exports.getImgSrcSet = exports.getImgUniqueIdentifier = exports.getImgQuality = void 0;
7
7
  const resizer_1 = require("@uxf/core/utils/resizer");
8
8
  const react_1 = __importDefault(require("react"));
9
9
  function toFileResponse(src) {
@@ -16,6 +16,10 @@ function getImgExtension(src) {
16
16
  const ext = src.slice(src.lastIndexOf(".") + 1);
17
17
  return ext.length > 1 ? ext : undefined;
18
18
  }
19
+ function getImgQuality(quality, format) {
20
+ return typeof quality === "number" ? quality : quality ? quality[format] : undefined;
21
+ }
22
+ exports.getImgQuality = getImgQuality;
19
23
  function getImgUniqueIdentifier(src) {
20
24
  var _a;
21
25
  const fileResponse = toFileResponse(src);
@@ -28,7 +32,7 @@ function getImgSrcSet(src, width, height, options = {}) {
28
32
  if (!src) {
29
33
  return undefined;
30
34
  }
31
- let f;
35
+ let toFormat;
32
36
  let h = height !== null && height !== void 0 ? height : "auto";
33
37
  let w = width !== null && width !== void 0 ? width : "auto";
34
38
  if (typeof src === "string") {
@@ -36,14 +40,14 @@ function getImgSrcSet(src, width, height, options = {}) {
36
40
  if (extension === "svg") {
37
41
  return undefined;
38
42
  }
39
- f = extension;
43
+ toFormat = extension;
40
44
  }
41
45
  const fileResponse = toFileResponse(src);
42
46
  if (fileResponse) {
43
47
  if (!fileResponse.uuid || fileResponse.extension === "svg") {
44
48
  return undefined;
45
49
  }
46
- f = fileResponse.extension;
50
+ toFormat = fileResponse.extension;
47
51
  }
48
52
  const staticImageData = toStaticImageData(src);
49
53
  if (staticImageData) {
@@ -51,11 +55,10 @@ function getImgSrcSet(src, width, height, options = {}) {
51
55
  if (!staticImageData.src || extension === "svg") {
52
56
  return undefined;
53
57
  }
54
- f = extension;
58
+ toFormat = extension;
55
59
  h = h || staticImageData.height;
56
60
  w = w || staticImageData.width;
57
61
  }
58
- const toFormat = f !== null && f !== void 0 ? f : "png";
59
62
  if (typeof h === "number" || typeof w === "number") {
60
63
  return HIDPI_SIZES.map((size) => (0, resizer_1.resizerImageUrl)(src, w * size, h * size, {
61
64
  toFormat,
@@ -65,8 +68,8 @@ function getImgSrcSet(src, width, height, options = {}) {
65
68
  return (0, resizer_1.resizerImageUrl)(src, w, h, { toFormat, ...options });
66
69
  }
67
70
  exports.getImgSrcSet = getImgSrcSet;
68
- const EXTENSIONS = ["avif", "webp", undefined];
69
71
  const ImgSources = (props) => {
72
+ var _a, _b, _c;
70
73
  if (!props.src || (typeof props.src === "string" && getImgExtension(props.src) === "svg")) {
71
74
  return null;
72
75
  }
@@ -83,7 +86,19 @@ const ImgSources = (props) => {
83
86
  media = `(min-width: ${props.breakpoints[props.breakpointIndex]})`;
84
87
  }
85
88
  return (react_1.default.createElement(react_1.default.Fragment, null,
86
- EXTENSIONS.map((type) => (react_1.default.createElement("source", { key: type, media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, { toFormat: type }), type: `image/${type}` }))),
87
- react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {}) })));
89
+ react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
90
+ ...((_a = props.options) !== null && _a !== void 0 ? _a : {}),
91
+ quality: getImgQuality(props.quality, "avif"),
92
+ toFormat: "avif",
93
+ }), type: "image/avif" }),
94
+ react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
95
+ ...((_b = props.options) !== null && _b !== void 0 ? _b : {}),
96
+ quality: getImgQuality(props.quality, "webp"),
97
+ toFormat: "webp",
98
+ }), type: "image/webp" }),
99
+ react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
100
+ ...((_c = props.options) !== null && _c !== void 0 ? _c : {}),
101
+ quality: getImgQuality(props.quality, "original"),
102
+ }) })));
88
103
  };
89
104
  exports.ImgSources = ImgSources;