@blocklet/images 1.16.33-beta-20241108-105022-266cd380 → 1.16.33-beta-20241112-051238-c5de53cb

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.
@@ -9,9 +9,11 @@ const path_1 = __importDefault(require("path"));
9
9
  const image_size_1 = __importDefault(require("image-size"));
10
10
  const image_type_1 = __importDefault(require("image-type"));
11
11
  const is_svg_1 = __importDefault(require("is-svg"));
12
+ const ASPECT_RATIO = 1 / 1;
13
+ const ASPECT_RATIO_THRESHOLD = 0.01;
12
14
  const validateLogo = (logoName, options) => {
13
15
  const { extractedFilepath, maxSize = 1024, minWidth = 256 } = options;
14
- const logoType = options.logoType || ['png', 'jpg', 'webp'];
16
+ const logoType = options.logoType || ['png', 'jpg', 'webp', 'svg'];
15
17
  const logoPath = path_1.default.join(extractedFilepath, logoName);
16
18
  const preLogoMessage = `The logo(${logoName})`;
17
19
  const errorMessages = [];
@@ -27,17 +29,23 @@ const validateLogo = (logoName, options) => {
27
29
  if (maxSize && logoStats.size > maxSize * 1024) {
28
30
  errorMessages.push(`${preLogoMessage} size exceeds ${maxSize} KB, but got ${(logoStats.size / 1024).toFixed(2)} KB.`);
29
31
  }
30
- const imgType = (0, image_type_1.default)(fs_1.default.readFileSync(logoPath));
31
32
  const isSvgFile = (0, is_svg_1.default)(fs_1.default.readFileSync(logoPath));
32
- if (isSvgFile || !logoType.includes(imgType.ext)) {
33
- errorMessages.push(`${preLogoMessage} format is not supported, expected: [${logoType}].`);
34
- }
35
- const imageMeta = (0, image_size_1.default)(logoPath);
36
- if (imageMeta.width < minWidth || imageMeta.height < minWidth) {
37
- errorMessages.push(`${preLogoMessage} minimum size must be ${minWidth}x${minWidth}, but got ${imageMeta.width}x${imageMeta.height}.`);
38
- }
39
- if (imageMeta.height !== imageMeta.width) {
40
- errorMessages.push(`${preLogoMessage} aspect ratio must be 1:1, but got 1:${parseFloat((imageMeta.height / imageMeta.width).toFixed(2))}.`);
33
+ if (!isSvgFile) {
34
+ const imgType = (0, image_type_1.default)(fs_1.default.readFileSync(logoPath));
35
+ if (!imgType || !logoType.includes(imgType.ext)) {
36
+ errorMessages.push(`${preLogoMessage} format is not supported, expected: [${logoType}].`);
37
+ }
38
+ if (`.${imgType?.ext}` !== path_1.default.extname(logoPath)) {
39
+ errorMessages.push(`${preLogoMessage} extension is not match the real file extension [.${imgType?.ext}].`);
40
+ }
41
+ const logoMeta = (0, image_size_1.default)(logoPath);
42
+ const aspectRatio = logoMeta.width / logoMeta.height;
43
+ if (logoMeta.width < minWidth || logoMeta.height < minWidth) {
44
+ errorMessages.push(`${preLogoMessage} minimum size must be ${minWidth}x${minWidth}, but got ${logoMeta.width}x${logoMeta.height}.`);
45
+ }
46
+ if (Math.abs(aspectRatio - ASPECT_RATIO) > ASPECT_RATIO_THRESHOLD) {
47
+ errorMessages.push(`${preLogoMessage} aspect ratio must be approximately 1:1, but got 1:${parseFloat((logoMeta.height / logoMeta.width).toFixed(2))} (${logoMeta.width}x${logoMeta.height}).`);
48
+ }
41
49
  }
42
50
  return errorMessages;
43
51
  };
@@ -10,7 +10,7 @@ const image_size_1 = __importDefault(require("image-size"));
10
10
  const image_type_1 = __importDefault(require("image-type"));
11
11
  const is_svg_1 = __importDefault(require("is-svg"));
12
12
  const ordinal_suffix_1 = require("./ordinal-suffix");
13
- const ASPECT_RATIO_16_10 = 16 / 10;
13
+ const ASPECT_RATIO = 16 / 9;
14
14
  const ASPECT_RATIO_THRESHOLD = 0.05;
15
15
  const validateScreenshots = (screenshots, options) => {
16
16
  const { extractedFilepath, minCount, maxCount, maxSize, minWidth, minHeight } = options;
@@ -43,21 +43,25 @@ const validateScreenshots = (screenshots, options) => {
43
43
  if (maxSize && screenshotsStats.size > maxSize * 1024 * 1024) {
44
44
  asyncErrors[screenshot].push(`${preMessage} size exceeds ${maxSize} MB, but got ${(screenshotsStats.size / 1024 / 1024).toFixed(2)} MB.`);
45
45
  }
46
- const imgType = (0, image_type_1.default)(fs_1.default.readFileSync(screenshotsPath));
47
46
  const isSvgFile = (0, is_svg_1.default)(fs_1.default.readFileSync(screenshotsPath));
48
- if (!isSvgFile && !imgType) {
49
- asyncErrors[screenshot].push(`${preMessage} is not a valid image file.`);
50
- }
51
47
  if (!isSvgFile) {
48
+ const imgType = (0, image_type_1.default)(fs_1.default.readFileSync(screenshotsPath));
49
+ if (!imgType) {
50
+ asyncErrors[screenshot].push(`${preMessage} is not a valid image file.`);
51
+ return;
52
+ }
53
+ if (`.${imgType.ext}` !== path_1.default.extname(screenshotsPath)) {
54
+ asyncErrors[screenshot].push(`${preMessage} extension is not match the real file extension [.${imgType.ext}].`);
55
+ }
52
56
  const imageMeta = (0, image_size_1.default)(screenshotsPath);
53
57
  const aspectRatio = imageMeta.width / imageMeta.height;
54
- const width = minWidth || (minHeight && minHeight * ASPECT_RATIO_16_10);
55
- const height = minHeight || (width && width / ASPECT_RATIO_16_10);
58
+ const width = minWidth || (minHeight && Math.round(minHeight * ASPECT_RATIO));
59
+ const height = minHeight || (width && Math.round(width / ASPECT_RATIO));
56
60
  if (imageMeta.width < width || imageMeta.height < height) {
57
61
  asyncErrors[screenshot].push(`${preMessage} minimum size must be ${width}x${height}, but got ${imageMeta.width}x${imageMeta.height}.`);
58
62
  }
59
- if (Math.abs(aspectRatio - ASPECT_RATIO_16_10) > ASPECT_RATIO_THRESHOLD) {
60
- asyncErrors[screenshot].push(`${preMessage} aspect ratio must be approximately 16:10, but got 16:${parseFloat((imageMeta.height / (imageMeta.width / 16)).toFixed(2))} (${imageMeta.width}x${imageMeta.height}).`);
63
+ if (Math.abs(aspectRatio - ASPECT_RATIO) > ASPECT_RATIO_THRESHOLD) {
64
+ asyncErrors[screenshot].push(`${preMessage} aspect ratio must be approximately 16:9, but got 16:${parseFloat((imageMeta.height / (imageMeta.width / 16)).toFixed(2))} (${imageMeta.width}x${imageMeta.height}).`);
61
65
  }
62
66
  }
63
67
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/images",
3
- "version": "1.16.33-beta-20241108-105022-266cd380",
3
+ "version": "1.16.33-beta-20241112-051238-c5de53cb",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "MIT",
@@ -51,5 +51,5 @@
51
51
  "ts-node": "^10.9.1",
52
52
  "typescript": "^5.6.3"
53
53
  },
54
- "gitHead": "804206007f31a5875d11f0f099b3bc87a4357b83"
54
+ "gitHead": "a2b9b5f89cab401cb2fe0622a14ed72334b1c2b8"
55
55
  }