@mindful-web/image 1.0.0 → 1.18.1
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": "@mindful-web/image",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Common image utilities for Mindful Web projects.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Jacob Bare <jacob@parameter1.com>",
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@mindful-web/html": "^1.0.0",
|
|
16
|
-
"@mindful-web/inflector": "^1.0.0"
|
|
16
|
+
"@mindful-web/inflector": "^1.0.0",
|
|
17
|
+
"@mindful-web/utils": "^1.11.9"
|
|
17
18
|
},
|
|
18
19
|
"publishConfig": {
|
|
19
20
|
"access": "public"
|
|
20
21
|
},
|
|
21
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "dfe29e096ca4eb8ab7c60453eddfa0477866b91f"
|
|
22
23
|
}
|
package/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const cropRectangle = require('./crop-rectangle');
|
|
|
6
6
|
const getRelativeAspectRatioHeight = require('./get-relative-aspect-ratio-height');
|
|
7
7
|
const getRelativeAspectRatioWidth = require('./get-relative-aspect-ratio-width');
|
|
8
8
|
const getRelativeCropRectangleHeight = require('./get-relative-crop-rectangle-height');
|
|
9
|
+
const parsePersistedImageSettings = require('./parse-persisted-image-settings');
|
|
9
10
|
|
|
10
11
|
module.exports = {
|
|
11
12
|
buildImgixUrl,
|
|
@@ -16,4 +17,5 @@ module.exports = {
|
|
|
16
17
|
getRelativeAspectRatioHeight,
|
|
17
18
|
getRelativeAspectRatioWidth,
|
|
18
19
|
getRelativeCropRectangleHeight,
|
|
20
|
+
parsePersistedImageSettings,
|
|
19
21
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const { round } = require('@mindful-web/utils');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {number} num
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
const toHex = (num) => {
|
|
8
|
+
const str = num.toString(16);
|
|
9
|
+
if (str.length === 1) return `0${str}`;
|
|
10
|
+
return str;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {{ r: number, g: number, b: number, a: number }} value
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
const formatColor = (value) => [
|
|
18
|
+
toHex(round(255 * value.a, 0)),
|
|
19
|
+
toHex(value.r),
|
|
20
|
+
toHex(value.g),
|
|
21
|
+
toHex(value.b),
|
|
22
|
+
].join('');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {{ settings: { json: string|undefined }|undefined }} image
|
|
26
|
+
* @returns {Record<string, any>}
|
|
27
|
+
*/
|
|
28
|
+
module.exports = (image) => {
|
|
29
|
+
try {
|
|
30
|
+
const settings = JSON.parse(image.settings.json) || {};
|
|
31
|
+
delete settings.auto; // remove auto values
|
|
32
|
+
if (settings.rect) {
|
|
33
|
+
settings.rect = `${settings.rect.x},${settings.rect.y},${settings.rect.width},${settings.rect.height}`;
|
|
34
|
+
}
|
|
35
|
+
['bg', 'fillColor'].forEach((key) => {
|
|
36
|
+
if (settings[key]) settings[key] = formatColor(settings[key]);
|
|
37
|
+
});
|
|
38
|
+
return settings;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
};
|