@redneckz/wildless-cms-uni-blocks 0.4.4 → 0.4.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/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +38 -11
- package/bundle/bundle.umd.min.js +1 -1
- package/dist/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/dist/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/dist/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/dist/content-page-repository/transformContentPage.js +9 -3
- package/dist/content-page-repository/transformContentPage.js.map +1 -1
- package/dist/content-page-repository/transformImg.d.ts +11 -0
- package/dist/content-page-repository/transformImg.js +100 -0
- package/dist/content-page-repository/transformImg.js.map +1 -0
- package/dist/content-page-repository/transformPicture.js +15 -40
- package/dist/content-page-repository/transformPicture.js.map +1 -1
- package/dist/content-page-repository/transformSrc.d.ts +3 -0
- package/dist/content-page-repository/transformSrc.js +20 -0
- package/dist/content-page-repository/transformSrc.js.map +1 -0
- package/dist/model/ImageSize.d.ts +6 -0
- package/dist/model/ImageSize.js +2 -0
- package/dist/model/ImageSize.js.map +1 -0
- package/dist/model/Picture.d.ts +19 -6
- package/dist/ui-kit/Img/ImgAsPicture.js +6 -2
- package/dist/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/dist/utils/isPictureSizeEmpty.d.ts +2 -0
- package/dist/utils/isPictureSizeEmpty.js +7 -0
- package/dist/utils/isPictureSizeEmpty.js.map +1 -0
- package/lib/common.css +1 -1
- package/lib/components/BenefitsBlock/BenefitsBlock.fixture.d.ts +2 -0
- package/lib/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/lib/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/lib/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/lib/content-page-repository/transformContentPage.js +9 -3
- package/lib/content-page-repository/transformContentPage.js.map +1 -1
- package/lib/content-page-repository/transformImg.d.ts +11 -0
- package/lib/content-page-repository/transformImg.js +94 -0
- package/lib/content-page-repository/transformImg.js.map +1 -0
- package/lib/content-page-repository/transformPicture.js +15 -40
- package/lib/content-page-repository/transformPicture.js.map +1 -1
- package/lib/content-page-repository/transformSrc.d.ts +3 -0
- package/lib/content-page-repository/transformSrc.js +14 -0
- package/lib/content-page-repository/transformSrc.js.map +1 -0
- package/lib/model/ImageSize.d.ts +6 -0
- package/lib/model/ImageSize.js +2 -0
- package/lib/model/ImageSize.js.map +1 -0
- package/lib/model/Picture.d.ts +19 -6
- package/lib/ui-kit/Img/ImgAsPicture.js +6 -2
- package/lib/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/lib/utils/isPictureSizeEmpty.d.ts +2 -0
- package/lib/utils/isPictureSizeEmpty.js +4 -0
- package/lib/utils/isPictureSizeEmpty.js.map +1 -0
- package/mobile/bundle/bundle.umd.js +6 -2
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/dist/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/mobile/dist/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/mobile/dist/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/mobile/dist/content-page-repository/transformContentPage.js +9 -3
- package/mobile/dist/content-page-repository/transformContentPage.js.map +1 -1
- package/mobile/dist/content-page-repository/transformImg.d.ts +11 -0
- package/mobile/dist/content-page-repository/transformImg.js +100 -0
- package/mobile/dist/content-page-repository/transformImg.js.map +1 -0
- package/mobile/dist/content-page-repository/transformPicture.js +15 -40
- package/mobile/dist/content-page-repository/transformPicture.js.map +1 -1
- package/mobile/dist/content-page-repository/transformSrc.d.ts +3 -0
- package/mobile/dist/content-page-repository/transformSrc.js +20 -0
- package/mobile/dist/content-page-repository/transformSrc.js.map +1 -0
- package/mobile/dist/model/ImageSize.d.ts +6 -0
- package/mobile/dist/model/ImageSize.js +2 -0
- package/mobile/dist/model/ImageSize.js.map +1 -0
- package/mobile/dist/model/Picture.d.ts +19 -6
- package/mobile/dist/ui-kit/Img/ImgAsPicture.js +6 -2
- package/mobile/dist/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/mobile/dist/utils/isPictureSizeEmpty.d.ts +2 -0
- package/mobile/dist/utils/isPictureSizeEmpty.js +7 -0
- package/mobile/dist/utils/isPictureSizeEmpty.js.map +1 -0
- package/mobile/lib/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/mobile/lib/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/mobile/lib/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/mobile/lib/content-page-repository/transformContentPage.js +9 -3
- package/mobile/lib/content-page-repository/transformContentPage.js.map +1 -1
- package/mobile/lib/content-page-repository/transformImg.d.ts +11 -0
- package/mobile/lib/content-page-repository/transformImg.js +94 -0
- package/mobile/lib/content-page-repository/transformImg.js.map +1 -0
- package/mobile/lib/content-page-repository/transformPicture.js +15 -40
- package/mobile/lib/content-page-repository/transformPicture.js.map +1 -1
- package/mobile/lib/content-page-repository/transformSrc.d.ts +3 -0
- package/mobile/lib/content-page-repository/transformSrc.js +14 -0
- package/mobile/lib/content-page-repository/transformSrc.js.map +1 -0
- package/mobile/lib/model/ImageSize.d.ts +6 -0
- package/mobile/lib/model/ImageSize.js +2 -0
- package/mobile/lib/model/ImageSize.js.map +1 -0
- package/mobile/lib/model/Picture.d.ts +19 -6
- package/mobile/lib/ui-kit/Img/ImgAsPicture.js +6 -2
- package/mobile/lib/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/mobile/lib/utils/isPictureSizeEmpty.d.ts +2 -0
- package/mobile/lib/utils/isPictureSizeEmpty.js +4 -0
- package/mobile/lib/utils/isPictureSizeEmpty.js.map +1 -0
- package/mobile/src/components/BenefitsBlock/BenefitsBlock.example.json +1 -0
- package/mobile/src/components/BenefitsBlock/BenefitsBlock.tsx +78 -28
- package/mobile/src/components/BenefitsBlock/BenefitsBlockContent.ts +10 -2
- package/mobile/src/components/ContentPage/ContentPage.page.json +1 -2
- package/mobile/src/components/__snapshots__/Blocks.spec.tsx.snap +1 -1
- package/mobile/src/content-page-repository/transformContentPage.ts +10 -3
- package/mobile/src/content-page-repository/transformImg.ts +157 -0
- package/mobile/src/content-page-repository/transformPicture.ts +24 -58
- package/mobile/src/content-page-repository/transformSrc.ts +21 -0
- package/mobile/src/model/ImageSize.ts +6 -0
- package/mobile/src/model/Picture.ts +29 -6
- package/mobile/src/ui-kit/Img/ImgAsPicture.tsx +8 -2
- package/mobile/src/utils/isPictureSizeEmpty.ts +5 -0
- package/package.json +2 -1
- package/src/components/BenefitsBlock/BenefitsBlock.example.json +1 -0
- package/src/components/BenefitsBlock/BenefitsBlock.fixture.tsx +94 -1
- package/src/components/BenefitsBlock/BenefitsBlock.tsx +78 -28
- package/src/components/BenefitsBlock/BenefitsBlockContent.ts +10 -2
- package/src/components/ContentPage/ContentPage.page.json +1 -2
- package/src/components/__snapshots__/Blocks.spec.tsx.snap +1 -1
- package/src/content-page-repository/transformContentPage.ts +10 -3
- package/src/content-page-repository/transformImg.ts +157 -0
- package/src/content-page-repository/transformPicture.ts +24 -58
- package/src/content-page-repository/transformSrc.ts +21 -0
- package/src/model/ImageSize.ts +6 -0
- package/src/model/Picture.ts +29 -6
- package/src/ui-kit/Img/ImgAsPicture.tsx +8 -2
- package/src/utils/isPictureSizeEmpty.ts +5 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import util from 'util';
|
|
4
|
+
import sharp from 'sharp';
|
|
5
|
+
import type { ResizeOptions, Sharp } from 'sharp';
|
|
6
|
+
import type { ImageSize } from '../model/ImageSize';
|
|
7
|
+
import type { TransformationOptions } from './TransformationOptions';
|
|
8
|
+
import type { ImgAlignment, ImgSource, Picture } from '../model/Picture';
|
|
9
|
+
import { transformSrc } from './transformSrc';
|
|
10
|
+
import { isPictureSizeEmpty } from '../utils/isPictureSizeEmpty';
|
|
11
|
+
|
|
12
|
+
const mkdir = util.promisify(fs.mkdir);
|
|
13
|
+
|
|
14
|
+
type TransformImgParams = {
|
|
15
|
+
pagePath: string;
|
|
16
|
+
src: string;
|
|
17
|
+
containerSize?: ImageSize;
|
|
18
|
+
transformationOptions: TransformationOptions & ImgSource;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function transformImg({
|
|
22
|
+
pagePath,
|
|
23
|
+
src,
|
|
24
|
+
containerSize,
|
|
25
|
+
transformationOptions,
|
|
26
|
+
}: TransformImgParams): Promise<string> {
|
|
27
|
+
if (!src) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { contentDir, publicDir, format, options, size, alignment } = transformationOptions;
|
|
32
|
+
|
|
33
|
+
const pageDir = path.dirname(pagePath);
|
|
34
|
+
const imgPath = `${pageDir}/${src}`;
|
|
35
|
+
let chain = sharp(imgPath);
|
|
36
|
+
|
|
37
|
+
const targetSize = getPictureSize(size, containerSize);
|
|
38
|
+
|
|
39
|
+
if (targetSize) {
|
|
40
|
+
chain = resizeImg(chain, targetSize, getResizeFit(targetSize));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (containerSize) {
|
|
44
|
+
chain = resizeImg(chain, containerSize);
|
|
45
|
+
|
|
46
|
+
// Save intermediate transform result to modify further
|
|
47
|
+
const { data } = await chain.toBuffer({ resolveWithObject: true });
|
|
48
|
+
|
|
49
|
+
chain = resizeImg(
|
|
50
|
+
sharp(data),
|
|
51
|
+
getCompositionResizeSize(containerSize, targetSize),
|
|
52
|
+
getResizeFit(targetSize),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
chain = await compositeImg({ chain, containerSize, alignment });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (format) {
|
|
59
|
+
chain = chain.toFormat(format, options);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const transformedSrc = transformSrc(src, transformationOptions);
|
|
63
|
+
const transformedImgPath = `${publicDir}/${path.relative(
|
|
64
|
+
contentDir,
|
|
65
|
+
`${path.dirname(pagePath)}/${transformedSrc}`,
|
|
66
|
+
)}`;
|
|
67
|
+
|
|
68
|
+
await mkdir(path.dirname(transformedImgPath), { recursive: true });
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
await chain.toFile(transformedImgPath);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error(e);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return transformedSrc;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function createBackgroundImageChain({ width, height }: ImageSize) {
|
|
80
|
+
const channels = 4;
|
|
81
|
+
const rgbaColor = 0x00000000;
|
|
82
|
+
|
|
83
|
+
const canvas = Buffer.alloc(width * height * channels, rgbaColor);
|
|
84
|
+
|
|
85
|
+
return sharp(canvas, { raw: { width, height, channels } });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function resizeImg(chain: Sharp, size: Picture['size'], options?: ResizeOptions) {
|
|
89
|
+
return chain.resize(size?.width, size?.height, {
|
|
90
|
+
fit: sharp.fit.fill,
|
|
91
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
|
92
|
+
...options,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type CompositeImgParams = {
|
|
97
|
+
chain: Sharp;
|
|
98
|
+
containerSize: ImageSize;
|
|
99
|
+
alignment?: ImgAlignment;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
async function compositeImg({
|
|
103
|
+
chain,
|
|
104
|
+
containerSize,
|
|
105
|
+
alignment,
|
|
106
|
+
}: CompositeImgParams): Promise<Sharp> {
|
|
107
|
+
const { data } = await chain.toBuffer({ resolveWithObject: true });
|
|
108
|
+
|
|
109
|
+
return createBackgroundImageChain(containerSize).composite([
|
|
110
|
+
{
|
|
111
|
+
input: data,
|
|
112
|
+
gravity: alignment,
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getPictureSize(size: Picture['size'], containerSize?: ImageSize) {
|
|
118
|
+
// If containerSize is undefined intrinsic dimensions of image will be used then.
|
|
119
|
+
return isPictureSizeEmpty(size) ? containerSize : size;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getCompositionResizeSize(
|
|
123
|
+
containerSize: ImageSize,
|
|
124
|
+
size: Picture['size'] = {},
|
|
125
|
+
): Picture['size'] {
|
|
126
|
+
const { width, height } = size;
|
|
127
|
+
const { width: containerWidth, height: containerHeight } = containerSize;
|
|
128
|
+
|
|
129
|
+
let widthRatio = 0;
|
|
130
|
+
let heightRatio = 0;
|
|
131
|
+
|
|
132
|
+
if (!(width || height)) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (width) {
|
|
137
|
+
widthRatio = containerWidth / width;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (height) {
|
|
141
|
+
heightRatio = containerHeight / height;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return widthRatio > heightRatio
|
|
145
|
+
? { width: Math.min(Number(width), containerWidth) }
|
|
146
|
+
: { height: Math.min(Number(height), containerHeight) };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getResizeFit(size: Picture['size']): ResizeOptions {
|
|
150
|
+
/*
|
|
151
|
+
Editor behaviour with one dimension present: resize by given dimension maintaining aspect ratio. (fit: contain)
|
|
152
|
+
With two dimensions present: resize trying to fill given dimensions (fit: fill)
|
|
153
|
+
*/
|
|
154
|
+
return {
|
|
155
|
+
fit: size?.width && size?.height ? sharp.fit.fill : sharp.fit.contain,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import sharp from 'sharp';
|
|
4
|
-
import
|
|
5
|
-
import type { ImgSource, Picture } from '../model/Picture';
|
|
3
|
+
import type { Picture } from '../model/Picture';
|
|
6
4
|
import type { TransformationOptions } from './TransformationOptions';
|
|
7
|
-
|
|
8
|
-
const mkdir = util.promisify(fs.mkdir);
|
|
5
|
+
import { transformImg } from './transformImg';
|
|
9
6
|
|
|
10
7
|
export async function transformPicture(
|
|
11
8
|
pagePath: string,
|
|
@@ -14,8 +11,27 @@ export async function transformPicture(
|
|
|
14
11
|
): Promise<Picture> {
|
|
15
12
|
const sources = picture.sources || [];
|
|
16
13
|
const src = picture?.src || '';
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
const transformedPicture = await transformImg({
|
|
16
|
+
pagePath,
|
|
17
|
+
src,
|
|
18
|
+
transformationOptions: { ...options, ...picture },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const { width, height } = await sharp(
|
|
22
|
+
path.resolve(options.publicDir, transformedPicture),
|
|
23
|
+
).metadata();
|
|
24
|
+
const containerSize = width && height ? { width, height } : undefined;
|
|
25
|
+
|
|
26
|
+
const transformedSources = await Promise.all(
|
|
27
|
+
sources.map((_) =>
|
|
28
|
+
transformImg({
|
|
29
|
+
pagePath,
|
|
30
|
+
src,
|
|
31
|
+
containerSize,
|
|
32
|
+
transformationOptions: { ...options, ..._ },
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
19
35
|
);
|
|
20
36
|
|
|
21
37
|
return {
|
|
@@ -24,57 +40,7 @@ export async function transformPicture(
|
|
|
24
40
|
sources: transformedSources.map((_, i) => ({
|
|
25
41
|
...sources[i],
|
|
26
42
|
src: _,
|
|
43
|
+
size: { width, height },
|
|
27
44
|
})),
|
|
28
45
|
};
|
|
29
46
|
}
|
|
30
|
-
|
|
31
|
-
async function transformImg(
|
|
32
|
-
pagePath: string,
|
|
33
|
-
src: string,
|
|
34
|
-
transformationOptions: TransformationOptions & ImgSource,
|
|
35
|
-
): Promise<string> {
|
|
36
|
-
const { contentDir, publicDir, format, options, size } = transformationOptions;
|
|
37
|
-
|
|
38
|
-
const pageDir = path.dirname(pagePath);
|
|
39
|
-
const imgPath = `${pageDir}/${src}`;
|
|
40
|
-
let chain = sharp(imgPath);
|
|
41
|
-
if (size) {
|
|
42
|
-
chain = chain.resize(size?.width, size?.height, {
|
|
43
|
-
fit: sharp.fit.contain,
|
|
44
|
-
background: [0, 0, 0, 0],
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (format) {
|
|
48
|
-
chain = chain.toFormat(format, options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const transformedSrc = transformSrc(src, transformationOptions);
|
|
52
|
-
const transformedImgPath = `${publicDir}/${path.relative(
|
|
53
|
-
contentDir,
|
|
54
|
-
`${path.dirname(pagePath)}/${transformedSrc}`,
|
|
55
|
-
)}`;
|
|
56
|
-
|
|
57
|
-
await mkdir(path.dirname(transformedImgPath), { recursive: true });
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
await chain.toFile(transformedImgPath);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
console.error(e);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return transformedSrc;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function transformSrc(src: string, { format, size }: TransformationOptions & ImgSource): string {
|
|
69
|
-
const noTransform = !format && !size;
|
|
70
|
-
if (noTransform) {
|
|
71
|
-
return src;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const fileName = path.basename(src, path.extname(src));
|
|
75
|
-
const fileSizes = [size?.width, size?.height].filter(Boolean);
|
|
76
|
-
const suffix = fileSizes.length ? `-${fileSizes.join('-')}` : '';
|
|
77
|
-
const ext = String(format) || path.extname(src);
|
|
78
|
-
|
|
79
|
-
return `${fileName}${suffix}.${ext}`;
|
|
80
|
-
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import type { ImgSource } from '../model/Picture';
|
|
3
|
+
import type { TransformationOptions } from './TransformationOptions';
|
|
4
|
+
import { isPictureSizeEmpty } from '../utils/isPictureSizeEmpty';
|
|
5
|
+
|
|
6
|
+
export function transformSrc(
|
|
7
|
+
src: string,
|
|
8
|
+
{ format, size }: TransformationOptions & ImgSource,
|
|
9
|
+
): string {
|
|
10
|
+
const noTransform = isPictureSizeEmpty(size) && !format;
|
|
11
|
+
if (noTransform) {
|
|
12
|
+
return src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const fileName = path.basename(src, path.extname(src));
|
|
16
|
+
const fileSizes = [size?.width, size?.height].filter(Boolean);
|
|
17
|
+
const suffix = fileSizes.length ? `-${fileSizes.join('-')}` : '';
|
|
18
|
+
const ext = format ? String(format) : 'webp';
|
|
19
|
+
|
|
20
|
+
return `${fileName}${suffix}.${ext}`;
|
|
21
|
+
}
|
package/src/model/Picture.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import type { IconName } from '../icons/IconName';
|
|
2
2
|
import type { IconVersion } from './IconVersion';
|
|
3
|
+
import { ImageSize } from './ImageSize';
|
|
3
4
|
|
|
4
5
|
export type ImgFormats = 'jpeg' | 'jpg' | 'png' | 'gif' | 'webp' | 'heif' | 'avif';
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @title Позиционирование
|
|
9
|
+
* @enumNames [
|
|
10
|
+
* "Сверху слева",
|
|
11
|
+
* "Сверху по центру",
|
|
12
|
+
* "Сверху справа",
|
|
13
|
+
* "Посередине слева",
|
|
14
|
+
* "Посередине по центру",
|
|
15
|
+
* "Посередине справа",
|
|
16
|
+
* "Снизу слева",
|
|
17
|
+
* "Снизу по центру",
|
|
18
|
+
* "Снизу справа"
|
|
19
|
+
* ]
|
|
20
|
+
* @default "center"
|
|
21
|
+
*/
|
|
22
|
+
export type ImgAlignment =
|
|
23
|
+
| 'northwest'
|
|
24
|
+
| 'north'
|
|
25
|
+
| 'northeast'
|
|
26
|
+
| 'west'
|
|
27
|
+
| 'center'
|
|
28
|
+
| 'east'
|
|
29
|
+
| 'southwest'
|
|
30
|
+
| 'south'
|
|
31
|
+
| 'southeast';
|
|
32
|
+
|
|
6
33
|
export interface Img {
|
|
7
34
|
/** @title Картинка */
|
|
8
35
|
src?: string;
|
|
@@ -19,6 +46,7 @@ export interface Img {
|
|
|
19
46
|
export type MediaQuery = 1919 | 1439 | 1279;
|
|
20
47
|
|
|
21
48
|
export interface ImgSource {
|
|
49
|
+
alignment?: ImgAlignment;
|
|
22
50
|
/** @title Иконка */
|
|
23
51
|
icon?: IconName;
|
|
24
52
|
iconVersion?: IconVersion;
|
|
@@ -30,12 +58,7 @@ export interface ImgSource {
|
|
|
30
58
|
options?: Record<string, any>;
|
|
31
59
|
media?: MediaQuery;
|
|
32
60
|
/** @title Размер изображения */
|
|
33
|
-
size?:
|
|
34
|
-
/** @title Ширина */
|
|
35
|
-
width?: number;
|
|
36
|
-
/** @title Высота */
|
|
37
|
-
height?: number;
|
|
38
|
-
};
|
|
61
|
+
size?: Partial<ImageSize>;
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
/** @title Изображение */
|
|
@@ -23,13 +23,13 @@ export const ImgAsPicture = JSX<ImageProps<Picture>>(
|
|
|
23
23
|
{image?.sources?.length
|
|
24
24
|
? image.sources
|
|
25
25
|
.sort(sourcesComparator)
|
|
26
|
-
.map(({ src, format, media
|
|
26
|
+
.map(({ src, format, media }, index) => (
|
|
27
27
|
<source
|
|
28
28
|
key={`${index}_${src}`}
|
|
29
29
|
srcSet={src}
|
|
30
30
|
type={formatToMimeType(format)}
|
|
31
31
|
media={media ? `(max-width: ${media}px)` : ''}
|
|
32
|
-
{...size}
|
|
32
|
+
{...image.size}
|
|
33
33
|
/>
|
|
34
34
|
))
|
|
35
35
|
: null}
|
|
@@ -40,6 +40,11 @@ export const ImgAsPicture = JSX<ImageProps<Picture>>(
|
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
const renderImg = (image: Picture, imageClassName = '', isMobile = false) => {
|
|
43
|
+
const style = {
|
|
44
|
+
width: image.size?.width ? `${image.size?.width}px` : '100%',
|
|
45
|
+
height: image.size?.height ? `${image.size?.height}px` : '100%',
|
|
46
|
+
};
|
|
47
|
+
|
|
43
48
|
const title = image.title || '';
|
|
44
49
|
const alt = image.alt || image.title;
|
|
45
50
|
const imgStyle = isMobile ? 'm-auto' : 'm-0';
|
|
@@ -50,6 +55,7 @@ const renderImg = (image: Picture, imageClassName = '', isMobile = false) => {
|
|
|
50
55
|
className={`${imgStyle} ${imageClassName}`}
|
|
51
56
|
alt={alt}
|
|
52
57
|
title={title}
|
|
58
|
+
style={style}
|
|
53
59
|
{...image.size}
|
|
54
60
|
/>
|
|
55
61
|
);
|