@basiclines/rampa 1.1.0 → 1.1.3
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/index.js +58 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9897,6 +9897,52 @@ function formatCss2(ramps) {
|
|
|
9897
9897
|
`);
|
|
9898
9898
|
}
|
|
9899
9899
|
|
|
9900
|
+
// src/utils/terminal-colors.ts
|
|
9901
|
+
function supportsTruecolor() {
|
|
9902
|
+
const colorterm = process.env.COLORTERM?.toLowerCase() || "";
|
|
9903
|
+
if (colorterm === "truecolor" || colorterm === "24bit") {
|
|
9904
|
+
return true;
|
|
9905
|
+
}
|
|
9906
|
+
const term = process.env.TERM?.toLowerCase() || "";
|
|
9907
|
+
if (term.includes("truecolor") || term.includes("24bit") || term.includes("direct")) {
|
|
9908
|
+
return true;
|
|
9909
|
+
}
|
|
9910
|
+
return false;
|
|
9911
|
+
}
|
|
9912
|
+
function hasLimitedColorSupport() {
|
|
9913
|
+
return !supportsTruecolor();
|
|
9914
|
+
}
|
|
9915
|
+
function rgbTo256(r4, g3, b2) {
|
|
9916
|
+
if (r4 === g3 && g3 === b2) {
|
|
9917
|
+
if (r4 < 8)
|
|
9918
|
+
return 16;
|
|
9919
|
+
if (r4 > 248)
|
|
9920
|
+
return 231;
|
|
9921
|
+
return Math.round((r4 - 8) / 10) + 232;
|
|
9922
|
+
}
|
|
9923
|
+
const rIndex = Math.round(r4 / 255 * 5);
|
|
9924
|
+
const gIndex = Math.round(g3 / 255 * 5);
|
|
9925
|
+
const bIndex = Math.round(b2 / 255 * 5);
|
|
9926
|
+
return 16 + 36 * rIndex + 6 * gIndex + bIndex;
|
|
9927
|
+
}
|
|
9928
|
+
function coloredSquare(r4, g3, b2) {
|
|
9929
|
+
if (hasLimitedColorSupport()) {
|
|
9930
|
+
const colorCode = rgbTo256(r4, g3, b2);
|
|
9931
|
+
return `\x1B[38;5;${colorCode}m■\x1B[0m`;
|
|
9932
|
+
}
|
|
9933
|
+
return `\x1B[38;2;${r4};${g3};${b2}m■\x1B[0m`;
|
|
9934
|
+
}
|
|
9935
|
+
function getColorLimitationNote() {
|
|
9936
|
+
if (hasLimitedColorSupport()) {
|
|
9937
|
+
const dim = "\x1B[2m";
|
|
9938
|
+
const yellow = "\x1B[33m";
|
|
9939
|
+
const reset = "\x1B[0m";
|
|
9940
|
+
return `${yellow}Note:${reset} ${dim}Using 256-color mode. Terminal does not advertise truecolor support.${reset}
|
|
9941
|
+
${dim}For accurate color previews, use a terminal with COLORTERM=truecolor.${reset}`;
|
|
9942
|
+
}
|
|
9943
|
+
return null;
|
|
9944
|
+
}
|
|
9945
|
+
|
|
9900
9946
|
// src/index.ts
|
|
9901
9947
|
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
9902
9948
|
showHelp();
|
|
@@ -9906,7 +9952,7 @@ function showHelp() {
|
|
|
9906
9952
|
const dim = "\x1B[2m";
|
|
9907
9953
|
const reset = "\x1B[0m";
|
|
9908
9954
|
const help = `
|
|
9909
|
-
rampa v1.1.
|
|
9955
|
+
rampa v1.1.3
|
|
9910
9956
|
Generate mathematically accurate color palettes from a base color
|
|
9911
9957
|
|
|
9912
9958
|
USAGE
|
|
@@ -10144,7 +10190,7 @@ var validFormats = ["hex", "hsl", "rgb", "oklch"];
|
|
|
10144
10190
|
var main = defineCommand({
|
|
10145
10191
|
meta: {
|
|
10146
10192
|
name: "rampa",
|
|
10147
|
-
version: "1.1.
|
|
10193
|
+
version: "1.1.3",
|
|
10148
10194
|
description: "Generate mathematically accurate color palettes from a base color"
|
|
10149
10195
|
},
|
|
10150
10196
|
args: {
|
|
@@ -10469,6 +10515,14 @@ var main = defineCommand({
|
|
|
10469
10515
|
} else if (outputType === "css") {
|
|
10470
10516
|
console.log(formatCss2(ramps));
|
|
10471
10517
|
} else {
|
|
10518
|
+
const canShowPreview = args.preview && supportsTruecolor();
|
|
10519
|
+
if (args.preview && !canShowPreview) {
|
|
10520
|
+
const limitationNote = getColorLimitationNote();
|
|
10521
|
+
if (limitationNote) {
|
|
10522
|
+
console.log(limitationNote);
|
|
10523
|
+
console.log("");
|
|
10524
|
+
}
|
|
10525
|
+
}
|
|
10472
10526
|
ramps.forEach((ramp, rampIndex) => {
|
|
10473
10527
|
if (rampIndex > 0 || ramps.length > 1) {
|
|
10474
10528
|
if (rampIndex > 0)
|
|
@@ -10476,10 +10530,10 @@ var main = defineCommand({
|
|
|
10476
10530
|
console.log(`# ${ramp.name}`);
|
|
10477
10531
|
}
|
|
10478
10532
|
ramp.colors.forEach((color) => {
|
|
10479
|
-
if (
|
|
10533
|
+
if (canShowPreview) {
|
|
10480
10534
|
const c4 = chroma_js_default(color);
|
|
10481
10535
|
const [r4, g3, b2] = c4.rgb();
|
|
10482
|
-
const square =
|
|
10536
|
+
const square = coloredSquare(r4, g3, b2);
|
|
10483
10537
|
console.log(`${square} ${color}`);
|
|
10484
10538
|
} else {
|
|
10485
10539
|
console.log(color);
|