@dilemmagx/palette 0.2.1 → 0.2.2
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/dist/cli.js +9 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10226,7 +10226,11 @@ async function extractDominantPalette(buffer, count) {
|
|
|
10226
10226
|
count: population
|
|
10227
10227
|
}));
|
|
10228
10228
|
if (entries.length === 0) return [];
|
|
10229
|
-
entries.sort((a, b) =>
|
|
10229
|
+
entries.sort((a, b) => {
|
|
10230
|
+
const countDelta = b.count - a.count;
|
|
10231
|
+
if (countDelta !== 0) return countDelta;
|
|
10232
|
+
return rgbKey(a.rgb) - rgbKey(b.rgb);
|
|
10233
|
+
});
|
|
10230
10234
|
const totalCount = entries.reduce((sum, entry) => sum + entry.count, 0);
|
|
10231
10235
|
const coverageTarget = 0.95;
|
|
10232
10236
|
const candidateEntries = [];
|
|
@@ -10261,7 +10265,7 @@ async function extractDominantPalette(buffer, count) {
|
|
|
10261
10265
|
}
|
|
10262
10266
|
const weight = entry.count / maxCount;
|
|
10263
10267
|
const score = minDist * (0.2 + Math.sqrt(weight));
|
|
10264
|
-
if (score > bestScore) {
|
|
10268
|
+
if (score > bestScore + 1e-9 || Math.abs(score - bestScore) <= 1e-9 && best !== null && rgbKey(entry.rgb) < rgbKey(best.rgb)) {
|
|
10265
10269
|
bestScore = score;
|
|
10266
10270
|
best = entry;
|
|
10267
10271
|
}
|
|
@@ -10378,6 +10382,9 @@ function rgbDistanceSq(a, b) {
|
|
|
10378
10382
|
const db = a.b - b.b;
|
|
10379
10383
|
return dr * dr + dg * dg + db * db;
|
|
10380
10384
|
}
|
|
10385
|
+
function rgbKey(color) {
|
|
10386
|
+
return (color.r << 16) + (color.g << 8) + color.b;
|
|
10387
|
+
}
|
|
10381
10388
|
function argbToRgb(argb) {
|
|
10382
10389
|
return {
|
|
10383
10390
|
r: argb >>> 16 & 255,
|