@lokiyou/pi-nano-footer 0.7.0 → 0.8.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 +20 -7
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ const RAINBOW = [
|
|
|
60
60
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
61
61
|
|
|
62
62
|
let working = false;
|
|
63
|
+
let animInterval: ReturnType<typeof setInterval> | undefined;
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* 从 borderColor 函数采样一个字符,提取其中使用的 RGB 色值
|
|
@@ -81,12 +82,12 @@ Editor.prototype.render = function (width: number): string[] {
|
|
|
81
82
|
const rgb = extractRGB(saved);
|
|
82
83
|
if (rgb) {
|
|
83
84
|
const [r, g, b] = rgb;
|
|
84
|
-
// 呼吸发光:纯 sin
|
|
85
|
-
// - 暗处 ~
|
|
86
|
-
// 周期 ~
|
|
87
|
-
const t = 0.5 + 0.5 * Math.sin(performance.now() /
|
|
88
|
-
const bright = 0.
|
|
89
|
-
const glow = t * 0.
|
|
85
|
+
// 呼吸发光:纯 sin + 60fps 主动刷新
|
|
86
|
+
// - 暗处 ~25%,亮处 100% + 柔和白色辉光
|
|
87
|
+
// 周期 ~1.2s(从容的呼吸节奏)
|
|
88
|
+
const t = 0.5 + 0.5 * Math.sin(performance.now() / 600);
|
|
89
|
+
const bright = 0.25 + 0.75 * t; // 25%~100%
|
|
90
|
+
const glow = t * t * 0.35; // 0~0.35 白色 blend,t² 让辉光集中在峰值
|
|
90
91
|
const nr = Math.round(Math.min(255, r * bright + (255 - r) * glow));
|
|
91
92
|
const ng = Math.round(Math.min(255, g * bright + (255 - g) * glow));
|
|
92
93
|
const nb = Math.round(Math.min(255, b * bright + (255 - b) * glow));
|
|
@@ -166,13 +167,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
166
167
|
});
|
|
167
168
|
pi.on("model_select", () => refresh());
|
|
168
169
|
|
|
169
|
-
// 工作状态切换 →
|
|
170
|
+
// 工作状态切换 → 控制呼吸发光
|
|
170
171
|
pi.on("agent_start", () => {
|
|
171
172
|
working = true;
|
|
173
|
+
// 50ms 间隔主动刷新,保证呼吸动画 20fps 流畅
|
|
174
|
+
if (requestRender) {
|
|
175
|
+
animInterval = setInterval(requestRender, 50);
|
|
176
|
+
}
|
|
172
177
|
refresh();
|
|
173
178
|
});
|
|
174
179
|
pi.on("agent_end", () => {
|
|
175
180
|
working = false;
|
|
181
|
+
if (animInterval) {
|
|
182
|
+
clearInterval(animInterval);
|
|
183
|
+
animInterval = undefined;
|
|
184
|
+
}
|
|
176
185
|
refresh();
|
|
177
186
|
});
|
|
178
187
|
|
|
@@ -182,6 +191,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
182
191
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
183
192
|
ctx.ui.setFooter(undefined);
|
|
184
193
|
requestRender = undefined;
|
|
194
|
+
if (animInterval) {
|
|
195
|
+
clearInterval(animInterval);
|
|
196
|
+
animInterval = undefined;
|
|
197
|
+
}
|
|
185
198
|
});
|
|
186
199
|
}
|
|
187
200
|
|