@lokiyou/pi-nano-footer 0.9.0 → 0.11.0
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/index.ts +31 -13
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -46,6 +46,9 @@ const C = {
|
|
|
46
46
|
border: "#dfe6e9",
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
// ── ANSI 24-bit true color 正则(用于从 borderColor 函数提取颜色) ──
|
|
50
|
+
const ANSI_RE = /\x1b\[38;2;(\d+);(\d+);(\d+)m/;
|
|
51
|
+
|
|
49
52
|
// ── Rainbow 色表(high / xhigh 思考等级用) ──
|
|
50
53
|
const RAINBOW = [
|
|
51
54
|
"#b281d6", "#d787af", "#febc38", "#e4c00f",
|
|
@@ -59,8 +62,15 @@ const RAINBOW = [
|
|
|
59
62
|
let working = false;
|
|
60
63
|
let animInterval: ReturnType<typeof setInterval> | undefined;
|
|
61
64
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
65
|
+
/**
|
|
66
|
+
* 从 borderColor 函数采样字符,提取当前 RGB 色值
|
|
67
|
+
*/
|
|
68
|
+
function extractRGB(fn: (str: string) => string): [number, number, number] | null {
|
|
69
|
+
const sample = fn("─");
|
|
70
|
+
const m = sample.match(ANSI_RE);
|
|
71
|
+
if (!m) return null;
|
|
72
|
+
return [parseInt(m[1]), parseInt(m[2]), parseInt(m[3])];
|
|
73
|
+
}
|
|
64
74
|
|
|
65
75
|
/** 保存原始 render */
|
|
66
76
|
const origRender = Editor.prototype.render;
|
|
@@ -68,17 +78,25 @@ const origRender = Editor.prototype.render;
|
|
|
68
78
|
Editor.prototype.render = function (width: number): string[] {
|
|
69
79
|
if (working) {
|
|
70
80
|
const saved = this.borderColor;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const rgb = extractRGB(saved);
|
|
82
|
+
if (rgb) {
|
|
83
|
+
let [r, g, b] = rgb;
|
|
84
|
+
// 智能工作色:向暖橙 #ff9f1c 偏移 40%
|
|
85
|
+
// 这样冷色(紫/青)会变暖,暖色(橙/红)保持,过渡自然不突兀
|
|
86
|
+
const blend = 0.4;
|
|
87
|
+
r = Math.round(r + (0xff - r) * blend);
|
|
88
|
+
g = Math.round(g + (0x9f - g) * blend);
|
|
89
|
+
b = Math.round(b + (0x1c - b) * blend);
|
|
90
|
+
// 呼吸:周期 ~800ms,60fps
|
|
91
|
+
const t = 0.5 + 0.5 * Math.sin(performance.now() / 400);
|
|
92
|
+
const bright = 0.25 + 0.75 * t;
|
|
93
|
+
const glow = t * t * 0.35;
|
|
94
|
+
const nr = Math.round(Math.min(255, r * bright + (255 - r) * glow));
|
|
95
|
+
const ng = Math.round(Math.min(255, g * bright + (255 - g) * glow));
|
|
96
|
+
const nb = Math.round(Math.min(255, b * bright + (255 - b) * glow));
|
|
97
|
+
this.borderColor = (str: string) =>
|
|
98
|
+
`\x1b[38;2;${nr};${ng};${nb}m${str}\x1b[0m`;
|
|
99
|
+
}
|
|
82
100
|
try {
|
|
83
101
|
return origRender.call(this, width);
|
|
84
102
|
} finally {
|