|
|
|
@@ -17,6 +17,7 @@ export interface State {
|
|
|
|
interface SrcSetInfo {
|
|
|
|
interface SrcSetInfo {
|
|
|
|
jpeg: string;
|
|
|
|
jpeg: string;
|
|
|
|
webp: string;
|
|
|
|
webp: string;
|
|
|
|
|
|
|
|
avif: string;
|
|
|
|
bestSrc: string;
|
|
|
|
bestSrc: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -45,6 +46,10 @@ export class Picture extends React.PureComponent<Props, State> {
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<picture>
|
|
|
|
<picture>
|
|
|
|
|
|
|
|
{ srcSet.avif !== ""
|
|
|
|
|
|
|
|
? <source srcSet={srcSet.avif} type="image/avif" media="(dynamic-range: high)" />
|
|
|
|
|
|
|
|
: null
|
|
|
|
|
|
|
|
}
|
|
|
|
<source srcSet={srcSet.webp} type="image/webp" />
|
|
|
|
<source srcSet={srcSet.webp} type="image/webp" />
|
|
|
|
<source srcSet={srcSet.jpeg} type="image/jpeg" />
|
|
|
|
<source srcSet={srcSet.jpeg} type="image/jpeg" />
|
|
|
|
<img
|
|
|
|
<img
|
|
|
|
@@ -61,6 +66,7 @@ export class Picture extends React.PureComponent<Props, State> {
|
|
|
|
private _srcset = (): SrcSetInfo => {
|
|
|
|
private _srcset = (): SrcSetInfo => {
|
|
|
|
const jpegSrcSet: string[] = [];
|
|
|
|
const jpegSrcSet: string[] = [];
|
|
|
|
const webpSrcSet: string[] = [];
|
|
|
|
const webpSrcSet: string[] = [];
|
|
|
|
|
|
|
|
const avifSrcSet: string[] = [];
|
|
|
|
let bestSize = 800;
|
|
|
|
let bestSize = 800;
|
|
|
|
let bestScale = Infinity;
|
|
|
|
let bestScale = Infinity;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -75,8 +81,12 @@ export class Picture extends React.PureComponent<Props, State> {
|
|
|
|
if (scale >= 1 || size === 2400) {
|
|
|
|
if (scale >= 1 || size === 2400) {
|
|
|
|
const jpeg = `img/${size}/${this.props.image.src}`;
|
|
|
|
const jpeg = `img/${size}/${this.props.image.src}`;
|
|
|
|
const webp = jpeg.replace("jpg", "webp");
|
|
|
|
const webp = jpeg.replace("jpg", "webp");
|
|
|
|
|
|
|
|
const avif = jpeg.replace("jpg", "avif");
|
|
|
|
jpegSrcSet.push(`${jpeg} ${scale}x`);
|
|
|
|
jpegSrcSet.push(`${jpeg} ${scale}x`);
|
|
|
|
webpSrcSet.push(`${webp} ${scale}x`);
|
|
|
|
webpSrcSet.push(`${webp} ${scale}x`);
|
|
|
|
|
|
|
|
if (this.props.image.hdr) {
|
|
|
|
|
|
|
|
avifSrcSet.push(`${avif} ${scale}x`);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (scale < bestScale) {
|
|
|
|
if (scale < bestScale) {
|
|
|
|
bestSize = size;
|
|
|
|
bestSize = size;
|
|
|
|
bestScale = scale;
|
|
|
|
bestScale = scale;
|
|
|
|
@@ -87,6 +97,7 @@ export class Picture extends React.PureComponent<Props, State> {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
jpeg: jpegSrcSet.join(","),
|
|
|
|
jpeg: jpegSrcSet.join(","),
|
|
|
|
webp: webpSrcSet.join(","),
|
|
|
|
webp: webpSrcSet.join(","),
|
|
|
|
|
|
|
|
avif: avifSrcSet.join(","),
|
|
|
|
bestSrc: `img/${bestSize}/${this.props.image.src}`,
|
|
|
|
bestSrc: `img/${bestSize}/${this.props.image.src}`,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|