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.
@@ -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
- if (hsl.lightness < 0.1 || hsl.lightness > 0.94 || hsl.saturation < 0.12) continue;
1787
- const key = `${Math.round(red / 24)},${Math.round(green / 24)},${Math.round(blue / 24)}`;
1788
- const bucket = colorBuckets.get(key) || {
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
- colorBuckets.set(key, bucket);
1804
+ buckets.set(key, bucket);
1798
1805
  }
1799
1806
 
1800
- let selectedColor = { red: 85, green: 70, blue: 232 };
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 = bucket.count * (0.55 + saturation * 1.8)
1806
- * (1 - Math.abs(lightness - 0.55) * 0.7);
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((sourceHsl.hue + (seed % 25) - 12 + 360) % 360);
1819
- const secondaryHue = (hue + [38, 56, 142, 205][seed % 4]) % 360;
1820
- const saturation = Math.max(58, Math.min(82, Math.round(sourceHsl.saturation * 100)));
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} 70% 54%)`,
1827
- secondarySoft: `hsla(${secondaryHue} 72% 58% / 0.18)`,
1828
- backgroundStart: `hsl(${hue} 68% 97%)`,
1829
- backgroundMiddle: `hsl(${(hue + 14) % 360} 58% 93%)`,
1830
- backgroundEnd: `hsl(${secondaryHue} 62% 88%)`,
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.7.4",
3
+ "version": "4.7.5",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",