codeplay-common 4.7.4 → 4.7.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/files/take-screen-image.js +30 -18
- package/package.json +1 -1
|
@@ -1773,19 +1773,26 @@ function rgbToHsl(red, green, blue) {
|
|
|
1773
1773
|
async function getPromotionalPalette(screenshotBuffer, screenshotFileName) {
|
|
1774
1774
|
const { data, info } = await sharp(screenshotBuffer)
|
|
1775
1775
|
.resize(36, 36, { fit: 'fill' })
|
|
1776
|
+
.toColourspace('srgb')
|
|
1776
1777
|
.removeAlpha()
|
|
1777
1778
|
.raw()
|
|
1778
1779
|
.toBuffer({ resolveWithObject: true });
|
|
1779
1780
|
const colorBuckets = new Map();
|
|
1781
|
+
const neutralBuckets = new Map();
|
|
1780
1782
|
|
|
1781
1783
|
for (let index = 0; index < data.length; index += info.channels) {
|
|
1782
1784
|
const red = data[index];
|
|
1783
1785
|
const green = data[index + 1];
|
|
1784
1786
|
const blue = data[index + 2];
|
|
1785
1787
|
const hsl = rgbToHsl(red, green, blue);
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
const
|
|
1788
|
+
const isColorful = hsl.lightness >= 0.1 && hsl.lightness <= 0.94
|
|
1789
|
+
&& hsl.saturation >= 0.12 && Math.max(red, green, blue) - Math.min(red, green, blue) >= 12;
|
|
1790
|
+
const buckets = isColorful ? colorBuckets : neutralBuckets;
|
|
1791
|
+
// Combine shades of the same hue so large tinted surfaces and their controls count together.
|
|
1792
|
+
const key = isColorful
|
|
1793
|
+
? Math.round(hsl.hue / 15) % 24
|
|
1794
|
+
: `${Math.round(red / 24)},${Math.round(green / 24)},${Math.round(blue / 24)}`;
|
|
1795
|
+
const bucket = buckets.get(key) || {
|
|
1789
1796
|
count: 0, red: 0, green: 0, blue: 0, saturation: 0, lightness: 0,
|
|
1790
1797
|
};
|
|
1791
1798
|
bucket.count += 1;
|
|
@@ -1794,16 +1801,18 @@ async function getPromotionalPalette(screenshotBuffer, screenshotFileName) {
|
|
|
1794
1801
|
bucket.blue += blue;
|
|
1795
1802
|
bucket.saturation += hsl.saturation;
|
|
1796
1803
|
bucket.lightness += hsl.lightness;
|
|
1797
|
-
|
|
1804
|
+
buckets.set(key, bucket);
|
|
1798
1805
|
}
|
|
1799
1806
|
|
|
1800
|
-
let selectedColor
|
|
1807
|
+
let selectedColor;
|
|
1801
1808
|
let selectedScore = -1;
|
|
1802
|
-
for (const bucket of colorBuckets.values()) {
|
|
1809
|
+
for (const bucket of (colorBuckets.size ? colorBuckets : neutralBuckets).values()) {
|
|
1803
1810
|
const saturation = bucket.saturation / bucket.count;
|
|
1804
1811
|
const lightness = bucket.lightness / bucket.count;
|
|
1805
|
-
const score =
|
|
1806
|
-
|
|
1812
|
+
const score = colorBuckets.size
|
|
1813
|
+
? bucket.count * (0.55 + saturation * 1.8)
|
|
1814
|
+
* (1 - Math.abs(lightness - 0.55) * 0.7)
|
|
1815
|
+
: bucket.count;
|
|
1807
1816
|
if (score <= selectedScore) continue;
|
|
1808
1817
|
selectedScore = score;
|
|
1809
1818
|
selectedColor = {
|
|
@@ -1815,21 +1824,24 @@ async function getPromotionalPalette(screenshotBuffer, screenshotFileName) {
|
|
|
1815
1824
|
|
|
1816
1825
|
const seed = getDecorationSeed(path.parse(screenshotFileName).name);
|
|
1817
1826
|
const sourceHsl = rgbToHsl(selectedColor.red, selectedColor.green, selectedColor.blue);
|
|
1818
|
-
const hue = Math.round(
|
|
1819
|
-
const secondaryHue = (hue +
|
|
1820
|
-
const saturation =
|
|
1827
|
+
const hue = Math.round(sourceHsl.hue) % 360;
|
|
1828
|
+
const secondaryHue = (hue + 18) % 360;
|
|
1829
|
+
const saturation = colorBuckets.size
|
|
1830
|
+
? Math.min(75, Math.round(sourceHsl.saturation * 100))
|
|
1831
|
+
: 0;
|
|
1832
|
+
const backgroundSaturation = Math.round(saturation * 0.75);
|
|
1821
1833
|
|
|
1822
1834
|
return {
|
|
1823
1835
|
seed,
|
|
1824
1836
|
accent: `hsl(${hue} ${saturation}% 46%)`,
|
|
1825
1837
|
accentSoft: `hsla(${hue} ${saturation}% 55% / 0.2)`,
|
|
1826
|
-
secondary: `hsl(${secondaryHue}
|
|
1827
|
-
secondarySoft: `hsla(${secondaryHue}
|
|
1828
|
-
backgroundStart: `hsl(${hue}
|
|
1829
|
-
backgroundMiddle: `hsl(${
|
|
1830
|
-
backgroundEnd: `hsl(${secondaryHue}
|
|
1831
|
-
text: `hsl(${hue} 35% 17%)`,
|
|
1832
|
-
mutedText: `hsl(${hue} 18% 38%)`,
|
|
1838
|
+
secondary: `hsl(${secondaryHue} ${saturation}% 54%)`,
|
|
1839
|
+
secondarySoft: `hsla(${secondaryHue} ${saturation}% 58% / 0.18)`,
|
|
1840
|
+
backgroundStart: `hsl(${hue} ${backgroundSaturation}% 97%)`,
|
|
1841
|
+
backgroundMiddle: `hsl(${hue} ${backgroundSaturation}% 93%)`,
|
|
1842
|
+
backgroundEnd: `hsl(${secondaryHue} ${backgroundSaturation}% 88%)`,
|
|
1843
|
+
text: `hsl(${hue} ${Math.min(35, saturation)}% 17%)`,
|
|
1844
|
+
mutedText: `hsl(${hue} ${Math.min(18, saturation)}% 38%)`,
|
|
1833
1845
|
};
|
|
1834
1846
|
}
|
|
1835
1847
|
|