@uncarved/jade 0.3.0 → 0.4.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.
Files changed (207) hide show
  1. package/README.md +1 -0
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/host.d.ts +2 -0
  5. package/dist/host.js +39 -5
  6. package/dist/host.js.map +1 -1
  7. package/dist/remote.js +5 -0
  8. package/dist/remote.js.map +1 -1
  9. package/dist/session.d.ts +7 -0
  10. package/dist/session.js +482 -27
  11. package/dist/session.js.map +1 -1
  12. package/package.json +4 -4
  13. package/plugins/approval/index.ts +49 -24
  14. package/plugins/approval/policy.ts +48 -25
  15. package/plugins/approval/review.ts +9 -5
  16. package/plugins/checks/checks.ts +10 -7
  17. package/plugins/checks/index.ts +13 -13
  18. package/plugins/checks/plugin.json +1 -1
  19. package/plugins/checks/project.ts +37 -38
  20. package/plugins/commands/index.ts +27 -3
  21. package/plugins/compact/compact.ts +13 -5
  22. package/plugins/compact/index.ts +20 -3
  23. package/plugins/compact/style.ts +13 -14
  24. package/plugins/completions/index.ts +35 -0
  25. package/plugins/completions/plugin.json +7 -0
  26. package/plugins/copy/index.ts +46 -0
  27. package/plugins/copy/plugin.json +7 -0
  28. package/plugins/editor/index.ts +10 -4
  29. package/plugins/fs/diff.ts +7 -6
  30. package/plugins/fs/fs.ts +8 -4
  31. package/plugins/fs/grep.ts +55 -12
  32. package/plugins/fs/index.ts +2 -7
  33. package/plugins/fs/plugin.json +1 -1
  34. package/plugins/fs/renderers.ts +16 -15
  35. package/plugins/fs/style.ts +16 -15
  36. package/plugins/hooks/index.ts +3 -2
  37. package/plugins/keys/index.ts +5 -1
  38. package/plugins/mcp/index.ts +197 -78
  39. package/plugins/mcp/install.ts +5 -3
  40. package/plugins/mcp/mcp.ts +163 -11
  41. package/plugins/mcp/plugin.json +2 -1
  42. package/plugins/mcp/project.ts +47 -50
  43. package/plugins/memory/index.ts +4 -4
  44. package/plugins/memory/style.ts +13 -14
  45. package/plugins/mentions/candidates.ts +67 -0
  46. package/plugins/mentions/index.ts +12 -5
  47. package/plugins/mentions/plugin.json +1 -1
  48. package/plugins/mentions/style.ts +13 -14
  49. package/plugins/models/configure.ts +10 -9
  50. package/plugins/models/index.ts +31 -4
  51. package/plugins/models/provider.ts +12 -1
  52. package/plugins/modes/index.ts +13 -2
  53. package/plugins/print/index.ts +7 -4
  54. package/plugins/prompts/index.ts +0 -0
  55. package/plugins/renderers/index.ts +10 -5
  56. package/plugins/repeats/index.ts +39 -9
  57. package/plugins/schedule/index.ts +2 -0
  58. package/plugins/screenshot/browser.ts +231 -0
  59. package/plugins/screenshot/index.ts +3 -2
  60. package/plugins/screenshot/tool.ts +27 -51
  61. package/plugins/sessions/index.ts +48 -2
  62. package/plugins/shell/index.ts +75 -22
  63. package/plugins/shell/plugin.json +1 -2
  64. package/plugins/shell/renderers.ts +9 -7
  65. package/plugins/shell/shell.ts +93 -34
  66. package/plugins/skills/index.ts +28 -19
  67. package/plugins/skills/project.ts +12 -7
  68. package/plugins/steer/index.ts +5 -4
  69. package/plugins/task/index.ts +81 -81
  70. package/plugins/task/plugin.json +5 -2
  71. package/plugins/task/style.ts +13 -14
  72. package/plugins/task/subagent.ts +67 -184
  73. package/plugins/todo/index.ts +39 -9
  74. package/plugins/tools/index.ts +57 -0
  75. package/plugins/tools/plugin.json +7 -0
  76. package/plugins/tui/frontend.ts +161 -87
  77. package/plugins/tui/index.ts +2 -3
  78. package/plugins/tui/mascot.ts +8 -7
  79. package/plugins/tui/mentions.ts +11 -80
  80. package/plugins/tui/plugin.json +1 -1
  81. package/plugins/tui/screen.ts +55 -5
  82. package/plugins/tui/transcript.ts +17 -7
  83. package/plugins/tui/tui.ts +356 -104
  84. package/plugins/tui/vendor.ts +1 -1
  85. package/plugins/undo/checkpoint.ts +5 -3
  86. package/plugins/undo/index.ts +43 -14
  87. package/plugins/undo/style.ts +13 -14
  88. package/plugins/web/index.ts +7 -18
  89. package/plugins/web/plugin.json +1 -1
  90. package/plugins-dist/approval/index.js +363 -414
  91. package/plugins-dist/approval/policy.js +395 -497
  92. package/plugins-dist/approval/review.js +132 -158
  93. package/plugins-dist/approval/schema.js +50 -55
  94. package/plugins-dist/ask/index.js +115 -129
  95. package/plugins-dist/budget/index.js +27 -31
  96. package/plugins-dist/checks/checks.js +293 -329
  97. package/plugins-dist/checks/index.js +119 -139
  98. package/plugins-dist/checks/plugin.json +2 -1
  99. package/plugins-dist/checks/project.js +57 -65
  100. package/plugins-dist/commands/index.js +47 -29
  101. package/plugins-dist/compact/compact.js +233 -249
  102. package/plugins-dist/compact/index.js +98 -95
  103. package/plugins-dist/compact/style.js +9 -14
  104. package/plugins-dist/completions/index.js +30 -0
  105. package/plugins-dist/completions/plugin.json +9 -0
  106. package/plugins-dist/continue/index.js +40 -52
  107. package/plugins-dist/copy/index.js +40 -0
  108. package/plugins-dist/copy/plugin.json +9 -0
  109. package/plugins-dist/cost/index.js +98 -115
  110. package/plugins-dist/custom-commands/index.js +55 -72
  111. package/plugins-dist/editor/index.js +64 -72
  112. package/plugins-dist/fs/diff.js +111 -124
  113. package/plugins-dist/fs/fs.js +426 -469
  114. package/plugins-dist/fs/grep.js +262 -244
  115. package/plugins-dist/fs/index.js +20 -34
  116. package/plugins-dist/fs/plugin.json +1 -2
  117. package/plugins-dist/fs/renderers.js +100 -112
  118. package/plugins-dist/fs/style.js +11 -15
  119. package/plugins-dist/fs/sys.js +31 -43
  120. package/plugins-dist/hooks/index.js +107 -127
  121. package/plugins-dist/keys/index.js +27 -31
  122. package/plugins-dist/mcp/index.js +271 -199
  123. package/plugins-dist/mcp/install.js +123 -137
  124. package/plugins-dist/mcp/mcp.js +638 -577
  125. package/plugins-dist/mcp/plugin.json +3 -1
  126. package/plugins-dist/mcp/project.js +98 -115
  127. package/plugins-dist/memory/index.js +83 -88
  128. package/plugins-dist/memory/memory.js +111 -128
  129. package/plugins-dist/memory/style.js +9 -14
  130. package/plugins-dist/mentions/attach.js +91 -99
  131. package/plugins-dist/mentions/candidates.js +49 -0
  132. package/plugins-dist/mentions/index.js +71 -81
  133. package/plugins-dist/mentions/plugin.json +2 -1
  134. package/plugins-dist/mentions/style.js +9 -14
  135. package/plugins-dist/models/config.js +29 -43
  136. package/plugins-dist/models/configure.js +392 -473
  137. package/plugins-dist/models/context.js +14 -22
  138. package/plugins-dist/models/index.js +182 -188
  139. package/plugins-dist/models/provider.js +243 -295
  140. package/plugins-dist/models/saved.js +59 -71
  141. package/plugins-dist/modes/index.js +138 -165
  142. package/plugins-dist/plugins/index.js +34 -34
  143. package/plugins-dist/print/index.js +192 -175
  144. package/plugins-dist/prompts/index.js +81 -89
  145. package/plugins-dist/prompts/notes.js +31 -37
  146. package/plugins-dist/prompts/prompts.js +155 -193
  147. package/plugins-dist/prompts/results.js +40 -53
  148. package/plugins-dist/prompts/sys.js +39 -50
  149. package/plugins-dist/renderers/index.js +32 -32
  150. package/plugins-dist/repeats/index.js +134 -151
  151. package/plugins-dist/schedule/cron.js +49 -56
  152. package/plugins-dist/schedule/index.js +229 -247
  153. package/plugins-dist/schedule/store.js +93 -109
  154. package/plugins-dist/scratch/index.js +12 -18
  155. package/plugins-dist/screenshot/browser.js +169 -0
  156. package/plugins-dist/screenshot/index.js +37 -45
  157. package/plugins-dist/screenshot/sys.js +53 -65
  158. package/plugins-dist/screenshot/tool.js +101 -151
  159. package/plugins-dist/sessions/index.js +149 -117
  160. package/plugins-dist/shell/index.js +117 -74
  161. package/plugins-dist/shell/plugin.json +1 -2
  162. package/plugins-dist/shell/renderers.js +28 -33
  163. package/plugins-dist/shell/service.js +17 -23
  164. package/plugins-dist/shell/shell.js +317 -320
  165. package/plugins-dist/shell/sys.js +64 -79
  166. package/plugins-dist/skills/index.js +193 -211
  167. package/plugins-dist/skills/install.js +122 -149
  168. package/plugins-dist/skills/project.js +65 -73
  169. package/plugins-dist/skills/skills.js +135 -171
  170. package/plugins-dist/steer/index.js +108 -125
  171. package/plugins-dist/suggest/index.js +235 -259
  172. package/plugins-dist/task/index.js +130 -148
  173. package/plugins-dist/task/plugin.json +5 -4
  174. package/plugins-dist/task/style.js +9 -14
  175. package/plugins-dist/task/subagent.js +156 -279
  176. package/plugins-dist/todo/index.js +79 -63
  177. package/plugins-dist/tools/index.js +43 -0
  178. package/plugins-dist/tools/plugin.json +9 -0
  179. package/plugins-dist/tui/editor.js +145 -160
  180. package/plugins-dist/tui/frontend.js +641 -655
  181. package/plugins-dist/tui/history.js +34 -37
  182. package/plugins-dist/tui/index.js +16 -18
  183. package/plugins-dist/tui/markdown.js +203 -247
  184. package/plugins-dist/tui/mascot.js +266 -353
  185. package/plugins-dist/tui/mentions.js +67 -144
  186. package/plugins-dist/tui/plugin.json +1 -2
  187. package/plugins-dist/tui/render.js +35 -45
  188. package/plugins-dist/tui/screen.js +197 -180
  189. package/plugins-dist/tui/transcript.js +436 -468
  190. package/plugins-dist/tui/tui.js +1554 -1645
  191. package/plugins-dist/tui/vendor.js +1388 -1088
  192. package/plugins-dist/undo/checkpoint.js +95 -118
  193. package/plugins-dist/undo/index.js +185 -192
  194. package/plugins-dist/undo/snapshot.js +83 -99
  195. package/plugins-dist/undo/style.js +9 -14
  196. package/plugins-dist/update/index.js +26 -28
  197. package/plugins-dist/web/env.js +55 -68
  198. package/plugins-dist/web/index.js +80 -110
  199. package/plugins-dist/web/plugin.json +1 -2
  200. package/plugins-dist/web/renderers.js +4 -5
  201. package/plugins-dist/web/web.js +514 -593
  202. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  203. package/sdk/python/jade_plugin.py +9 -2
  204. package/src/api.ts +1 -1
  205. package/src/host.ts +39 -4
  206. package/src/remote.ts +6 -1
  207. package/src/session.ts +489 -34
@@ -1,42 +1,29 @@
1
- // 标题左边的吉祥物:一个玉做的团子,按当前在做的事换表情、带一点动画;还有终端标签页标题上的 jade 标志。
2
- // 不碰 Ink:动画由 App 统一重画推动(见 tui.ts 的 tick),这里每次按时间算出这一帧。
3
- //
4
- // 画布 15×6 个像素,每格字符上下两个像素(▀ 前景是上面、背景是下面),6 个像素高正好三行,和右边三行文字并排。
5
- // 左边 9 列是身体,空一列,右边 5 列放表情以外的小东西(思考的三个点、工具的转圈、提问的感叹号、做完的 ✓……都用像素画)。画布宽度不随表情变,标题右边的文字不会跟着左右跳。
6
- //
7
- // 精度只有这么多,细节靠颜色:身体按光照着色(左上亮、边缘暗、一点高光),眼睛是深色的形状,
8
- // 每个像素按 4×4 次采样算出眼睛盖住了多少、和身体的颜色混合,所以眼睛可以不按整格移动、眨眼也有中间的几帧。
9
- // 身体外面是终端背景,颜色未知、没法混合,所以轮廓只按整格变(只有做完后蹦那一下会变)、混色只在身体里面做。
10
- // 视线、睁眼的程度、颜色在状态之间缓动(Mascot),不会一下跳过去。
11
1
  export const JADE = "#00a86b";
12
- /** 做完后笑多久 */
13
2
  export const HAPPY_MS = 4000;
14
3
  export function moodOf(s, now) {
15
- if (s.asking)
16
- return "asking";
17
- const b = s.busy;
18
- if (b === undefined)
19
- return s.doneAt !== undefined && now - s.doneAt < HAPPY_MS ? "happy" : "idle";
20
- if (b === "Interrupting")
21
- return "stopping";
22
- if (b === "Thinking")
23
- return "thinking";
24
- if (b.startsWith("Writing"))
25
- return "writing";
26
- if (b.startsWith("Running "))
27
- return "tool";
28
- return "waiting";
4
+ if (s.asking)
5
+ return "asking";
6
+ const b = s.busy;
7
+ if (b === undefined)
8
+ return s.doneAt !== undefined && now - s.doneAt < HAPPY_MS ? "happy" : "idle";
9
+ if (b === "Interrupting")
10
+ return "stopping";
11
+ if (b === "Thinking")
12
+ return "thinking";
13
+ if (b.startsWith("Writing"))
14
+ return "writing";
15
+ if (b.startsWith("Running "))
16
+ return "tool";
17
+ return "waiting";
29
18
  }
30
19
  const rgb = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
31
20
  const hex = (c) => `#${c.map((v) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0")).join("")}`;
32
21
  const mix = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
33
- /** 按 t(0–1)在一串颜色之间插值 */
34
22
  const ramp = (stops, t) => {
35
- const x = Math.max(0, Math.min(1, t)) * (stops.length - 1);
36
- const i = Math.min(stops.length - 2, Math.floor(x));
37
- return mix(stops[i], stops[i + 1], x - i);
23
+ const x = Math.max(0, Math.min(1, t)) * (stops.length - 1);
24
+ const i = Math.min(stops.length - 2, Math.floor(x));
25
+ return mix(stops[i], stops[i + 1], x - i);
38
26
  };
39
- /** 从暗到亮的玉色;中断时换成琥珀色那一套 */
40
27
  const JADE_RAMP = ["#004a33", "#00744c", JADE, "#2ccc8a", "#8eeec0"].map(rgb);
41
28
  const AMBER_RAMP = ["#5a3a00", "#9a6500", "#e0a526", "#f4c75a", "#fde4a0"].map(rgb);
42
29
  const SPECULAR = rgb("#effff6");
@@ -45,395 +32,321 @@ const PALE = rgb("#b6f2d4");
45
32
  const DEEP = rgb("#00744c");
46
33
  const BANG = [rgb("#f5c518"), rgb("#fff1a8")];
47
34
  const SWEAT = rgb("#8fd3ff");
48
- /** 蹦起来时地上的影子:身体外面没法和终端背景混合,用一个暗的玉色 */
49
35
  const SHADOW = mix(DEEP, EYE, 0.55);
50
- // ---------- 形状 ----------
51
36
  const W = 15;
52
- /** 右边小东西的第一列:和身体之间空一列,不贴着 */
53
37
  const SIDE = 10;
54
38
  const H = 6;
55
- /** 身体的轮廓(9 列),轮廓外是终端背景 */
56
39
  const MASK = ["..#####..", ".#######.", "#########", "#########", "#########", ".#######."];
57
40
  const CX = 4.5;
58
41
  const SHAPES = {
59
- rest: { mask: MASK, top: 0, bottom: 6, dy: 0 },
60
- crouch: { mask: [".........", ".#######.", "#########", "#########", "#########", ".#######."], top: 1, bottom: 6, dy: 1 },
61
- air: { mask: ["..#####..", ".#######.", "#########", "#########", ".#######.", "........."], top: 0, bottom: 5, dy: -1 },
42
+ rest: { mask: MASK, top: 0, bottom: 6, dy: 0 },
43
+ crouch: { mask: [".........", ".#######.", "#########", "#########", "#########", ".#######."], top: 1, bottom: 6, dy: 1 },
44
+ air: { mask: ["..#####..", ".#######.", "#########", "#########", ".#######.", "........."], top: 0, bottom: 5, dy: -1 }
62
45
  };
63
- /** 做完后的一跳:蹲下蓄力 → 跳起 → 落地压扁一下 → 站好(t 是进入 happy 之后的毫秒) */
64
46
  const HOP = { crouch: 90, air: 380, land: 470 };
65
47
  function shapeAt(mood, t) {
66
- if (mood !== "happy" || t >= HOP.land)
67
- return SHAPES.rest;
68
- return t < HOP.crouch || t >= HOP.air ? SHAPES.crouch : SHAPES.air;
48
+ if (mood !== "happy" || t >= HOP.land)
49
+ return SHAPES.rest;
50
+ return t < HOP.crouch || t >= HOP.air ? SHAPES.crouch : SHAPES.air;
69
51
  }
70
- /**
71
- * 两只眼睛:中心的 x、下沿的 y(像素坐标,像素 (x, y) 覆盖 [x, x+1)×[y, y+1)),宽 1、高 2 个像素。
72
- * 停住的位置都正好对齐像素,眼睛是清楚的两块;只有移动、眨眼的中间几帧才会混出过渡色
73
- */
74
52
  const EYES_X = [2.5, 6.5];
75
53
  const EYE_BOTTOM = 4;
76
54
  const EYE_H = 2;
77
55
  const smooth = (t) => {
78
- const x = Math.max(0, Math.min(1, t));
79
- return x * x * (3 - 2 * x);
56
+ const x = Math.max(0, Math.min(1, t));
57
+ return x * x * (3 - 2 * x);
80
58
  };
81
59
  const gauss = (dx, dy, s) => Math.exp(-(dx * dx + dy * dy) / (2 * s * s));
82
60
  const REST = { gx: 0, gy: 0, open: 1, happy: 0, wink: 0, tint: 0, glow: 0 };
83
- // ---------- 时间轴 ----------
84
61
  const ease = (now, keys, period) => {
85
- // keys:[时刻, 值],时刻在 [0, period) 里递增;相邻两个之间平滑过渡,最后一个过渡回第一个
86
- const t = now % period;
87
- for (let i = 0; i < keys.length; i++) {
88
- const [t0, v0] = keys[i];
89
- const [t1raw, v1] = keys[(i + 1) % keys.length];
90
- const t1 = i + 1 < keys.length ? t1raw : t1raw + period;
91
- if (t >= t0 && t < t1)
92
- return v0 + (v1 - v0) * smooth((t - t0) / (t1 - t0));
93
- }
94
- return keys[0][1];
62
+ const t = now % period;
63
+ for (let i = 0;i < keys.length; i++) {
64
+ const [t0, v0] = keys[i];
65
+ const [t1raw, v1] = keys[(i + 1) % keys.length];
66
+ const t1 = i + 1 < keys.length ? t1raw : t1raw + period;
67
+ if (t >= t0 && t < t1)
68
+ return v0 + (v1 - v0) * smooth((t - t0) / (t1 - t0));
69
+ }
70
+ return keys[0][1];
95
71
  };
96
- /** 关键帧之间停一会儿再动:每个值先停 hold 毫秒,再用 move 毫秒移到下一个 */
97
72
  const steps = (values, hold, move) => {
98
- const keys = [];
99
- values.forEach((v, i) => {
100
- keys.push([i * (hold + move), v], [i * (hold + move) + hold, v]);
101
- });
102
- return [keys, values.length * (hold + move)];
73
+ const keys = [];
74
+ values.forEach((v, i) => {
75
+ keys.push([i * (hold + move), v], [i * (hold + move) + hold, v]);
76
+ });
77
+ return [keys, values.length * (hold + move)];
103
78
  };
104
- /** 每隔多久眨一次眼,眨一下多久 */
105
79
  const BLINK_EVERY = 4200;
106
80
  const BLINK_MS = 220;
107
- /** 空闲时每隔多久往旁边瞟一眼,从什么时候到什么时候 */
108
- const GLANCE_EVERY = 11_000;
81
+ const GLANCE_EVERY = 11000;
109
82
  const GLANCE = [7000, 8600];
110
- /** 眨眼:返回睁眼程度的系数。每第三次连眨两下 */
111
83
  function blink(now) {
112
- const n = Math.floor(now / BLINK_EVERY);
113
- const t = now % BLINK_EVERY;
114
- const one = (t0) => (t >= t0 && t < t0 + BLINK_MS ? 1 - Math.sin((Math.PI * (t - t0)) / BLINK_MS) : 1);
115
- return Math.min(one(0), n % 3 === 2 ? one(BLINK_MS + 90) : 1);
84
+ const n = Math.floor(now / BLINK_EVERY);
85
+ const t = now % BLINK_EVERY;
86
+ const one = (t0) => t >= t0 && t < t0 + BLINK_MS ? 1 - Math.sin(Math.PI * (t - t0) / BLINK_MS) : 1;
87
+ return Math.min(one(0), n % 3 === 2 ? one(BLINK_MS + 90) : 1);
116
88
  }
117
- /** 做完后什么时候回过头眨眼(落地后先看着 ✓ 画出来) */
118
89
  const WINK_AT = 1500;
119
- /** 这个状态此刻想要的样子(Mascot 往这里缓动);t 是进入这个状态之后的毫秒,只有 happy 用 */
120
90
  export function goal(mood, now, t = HAPPY_MS / 2) {
121
- switch (mood) {
122
- case "idle": {
123
- const t = now % GLANCE_EVERY;
124
- const look = t >= GLANCE[0] && t < GLANCE[1] ? -1 : 0;
125
- return { ...REST, gx: look, open: blink(now) };
126
- }
127
- case "waiting": {
128
- const [keys, period] = steps([0, -1, 0, 1], 600, 350);
129
- return { ...REST, gx: ease(now, keys, period), open: blink(now) };
130
- }
131
- case "thinking": {
132
- // 琢磨:眯起眼往左上方望,身体一点点亮起来(在攒想法);
133
- // 想到了:睁开眼转向右上角,看着三个点一个个冒出来,攒的亮光随着点冒出来慢慢退掉
134
- const gx = ease(now, [[0, -1], [THINK.ponder - 350, -1], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
135
- const open = ease(now, [[0, 0.5], [THINK.ponder - 350, 0.5], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
136
- const glow = ease(now, [[0, 0], [THINK.ponder, 0.75], [THINK.dot(2), 0]], THINK.period);
137
- return { ...REST, gx, gy: -1, open: open * blink(now + 1700), glow };
138
- }
139
- case "writing": {
140
- // 读着刚写的字:一行里从左往右扫,到头回来
141
- const [keys, period] = steps([-1, 0, 1], 260, 140);
142
- return { ...REST, gx: ease(now, keys, period), gy: 1, open: 0.5 + 0.5 * blink(now + 600) };
143
- }
144
- case "tool":
145
- return { ...REST, gx: 1, open: blink(now + 900) };
146
- case "asking":
147
- return { ...REST, open: 1.5 * blink(now + 2500) };
148
- case "stopping":
149
- return { ...REST, open: 0, tint: 1 };
150
- case "happy": {
151
- // 只有眼睛,不加嘴和脸红:别的表情都只靠眼睛,加了反而不像同一个。
152
- // 蹦的时候 ^ ^;落地那一下身体一亮,睁眼看右边的 ✓ 画出来;然后回过头,左眼 ^ 冲你眨一下
153
- const glow = t >= HOP.air ? Math.exp(-(t - HOP.air) / 260) : 0;
154
- if (t < HOP.land)
155
- return { ...REST, happy: 1, glow };
156
- if (t < WINK_AT)
157
- return { ...REST, gx: 1, glow };
158
- return { ...REST, wink: 1 };
159
- }
91
+ switch (mood) {
92
+ case "idle": {
93
+ const t = now % GLANCE_EVERY;
94
+ const look = t >= GLANCE[0] && t < GLANCE[1] ? -1 : 0;
95
+ return { ...REST, gx: look, open: blink(now) };
96
+ }
97
+ case "waiting": {
98
+ const [keys, period] = steps([0, -1, 0, 1], 600, 350);
99
+ return { ...REST, gx: ease(now, keys, period), open: blink(now) };
160
100
  }
101
+ case "thinking": {
102
+ const gx = ease(now, [[0, -1], [THINK.ponder - 350, -1], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
103
+ const open = ease(now, [[0, 0.5], [THINK.ponder - 350, 0.5], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
104
+ const glow = ease(now, [[0, 0], [THINK.ponder, 0.75], [THINK.dot(2), 0]], THINK.period);
105
+ return { ...REST, gx, gy: -1, open: open * blink(now + 1700), glow };
106
+ }
107
+ case "writing": {
108
+ const [keys, period] = steps([-1, 0, 1], 260, 140);
109
+ return { ...REST, gx: ease(now, keys, period), gy: 1, open: 0.5 + 0.5 * blink(now + 600) };
110
+ }
111
+ case "tool":
112
+ return { ...REST, gx: 1, open: blink(now + 900) };
113
+ case "asking":
114
+ return { ...REST, open: 1.5 * blink(now + 2500) };
115
+ case "stopping":
116
+ return { ...REST, open: 0, tint: 1 };
117
+ case "happy": {
118
+ const glow = t >= HOP.air ? Math.exp(-(t - HOP.air) / 260) : 0;
119
+ if (t < HOP.land)
120
+ return { ...REST, happy: 1, glow };
121
+ if (t < WINK_AT)
122
+ return { ...REST, gx: 1, glow };
123
+ return { ...REST, wink: 1 };
124
+ }
125
+ }
161
126
  }
162
- /** 画一帧:返回 6 行、每行 15 个颜色("#rrggbb"),undefined 是透明(终端背景);t 同 goal */
163
127
  export function paint(p, mood, now, t = HAPPY_MS / 2) {
164
- const shape = shapeAt(mood, t);
165
- const cy = (shape.top + shape.bottom) / 2;
166
- const half = (shape.bottom - shape.top) / 2;
167
- const ramp_ = (t) => mix(ramp(JADE_RAMP, t), ramp(AMBER_RAMP, t), p.tint);
168
- const grid = Array.from({ length: H }, () => Array(W).fill(undefined));
169
- // 工具运行时,一道光从左往右扫过身体
170
- const sweep = mood === "tool" ? ((now % 1400) / 1400) * 16 - 4 : undefined;
171
- for (let y = 0; y < H; y++)
172
- for (let x = 0; x < 9; x++) {
173
- if (shape.mask[y]?.[x] !== "#")
174
- continue;
175
- const nx = (x + 0.5 - CX) / 4.5;
176
- const ny = (y + 0.5 - cy) / half;
177
- const r = Math.max(Math.abs(nx), Math.abs(ny) * 0.9, Math.hypot(nx, ny) * 0.82);
178
- let light = 0.62 - 0.3 * ny - 0.14 * nx - 0.32 * smooth((r - 0.55) / 0.45) + 0.18 * p.glow;
179
- if (sweep !== undefined)
180
- light += 0.22 * Math.exp(-(((x - y * 0.5 - sweep) / 0.8) ** 2));
181
- let c = ramp_(light);
182
- // 高光:左上角一个像素,旁边一圈淡淡的
183
- c = mix(c, SPECULAR, 0.9 * gauss(x - 2, y - shape.top - 1, 0.45));
184
- // 眼睛:4×4 次采样,算出盖住了多少
185
- let cover = 0;
186
- for (let sy = 0; sy < 4; sy++)
187
- for (let sx = 0; sx < 4; sx++) {
188
- const px = x + (sx + 0.5) / 4;
189
- const py = y + (sy + 0.5) / 4;
190
- cover += eyeAt(p, px, py - shape.dy) / 16;
191
- }
192
- c = mix(c, mix(EYE, ramp_(0.05), p.tint * 0.4), Math.min(1, cover));
193
- grid[y][x] = c;
128
+ const shape = shapeAt(mood, t);
129
+ const cy = (shape.top + shape.bottom) / 2;
130
+ const half = (shape.bottom - shape.top) / 2;
131
+ const ramp_ = (t) => mix(ramp(JADE_RAMP, t), ramp(AMBER_RAMP, t), p.tint);
132
+ const grid = Array.from({ length: H }, () => Array(W).fill(undefined));
133
+ const sweep = mood === "tool" ? now % 1400 / 1400 * 16 - 4 : undefined;
134
+ for (let y = 0;y < H; y++)
135
+ for (let x = 0;x < 9; x++) {
136
+ if (shape.mask[y]?.[x] !== "#")
137
+ continue;
138
+ const nx = (x + 0.5 - CX) / 4.5;
139
+ const ny = (y + 0.5 - cy) / half;
140
+ const r = Math.max(Math.abs(nx), Math.abs(ny) * 0.9, Math.hypot(nx, ny) * 0.82);
141
+ let light = 0.62 - 0.3 * ny - 0.14 * nx - 0.32 * smooth((r - 0.55) / 0.45) + 0.18 * p.glow;
142
+ if (sweep !== undefined)
143
+ light += 0.22 * Math.exp(-(((x - y * 0.5 - sweep) / 0.8) ** 2));
144
+ let c = ramp_(light);
145
+ c = mix(c, SPECULAR, 0.9 * gauss(x - 2, y - shape.top - 1, 0.45));
146
+ let cover = 0;
147
+ for (let sy = 0;sy < 4; sy++)
148
+ for (let sx = 0;sx < 4; sx++) {
149
+ const px = x + (sx + 0.5) / 4;
150
+ const py = y + (sy + 0.5) / 4;
151
+ cover += eyeAt(p, px, py - shape.dy) / 16;
194
152
  }
195
- // 跳在空中时脚下一块影子
196
- if (shape === SHAPES.air)
197
- for (let x = 3; x < 6; x++)
198
- grid[5][x] = SHADOW;
199
- for (const [x, y, c] of extras(mood, now, t))
200
- grid[y][x] = c;
201
- return grid.map((row) => row.map((c) => (c ? hex(c) : undefined)));
153
+ c = mix(c, mix(EYE, ramp_(0.05), p.tint * 0.4), Math.min(1, cover));
154
+ grid[y][x] = c;
155
+ }
156
+ if (shape === SHAPES.air)
157
+ for (let x = 3;x < 6; x++)
158
+ grid[5][x] = SHADOW;
159
+ for (const [x, y, c] of extras(mood, now, t))
160
+ grid[y][x] = c;
161
+ return grid.map((row) => row.map((c) => c ? hex(c) : undefined));
202
162
  }
203
- /** 眼睛在 (px, py) 处的覆盖(0 或 1):普通的眼睛和 ^ 形的笑眼按 happy 混合(左眼还算上 wink) */
204
163
  function eyeAt(p, px, py) {
205
- let best = 0;
206
- for (const [i, bx] of EYES_X.entries()) {
207
- const happy = i === 0 ? Math.max(p.happy, p.wink) : p.happy;
208
- // 笑分两步:先是下眼皮往上推,眼睛压成上面一格的一条线(连续的);
209
- // 推到头之后一下子变成 ^(像素画按帧换形状,滑过去的中间几帧是糊的)
210
- const smile = happy > 0.6;
211
- // 两只都变成 ^ 时各往外一格:^ 有三格宽,不挪开的话两只里边的眼角只隔一格,连成一排锯齿;
212
- // 只眨一只眼时另一只是普通的眼睛,不会连起来,^ 留在原位
213
- // ^ 对齐整格:从别的表情缓过来时视线还没回正,不对齐的话 ^ 是糊的
214
- const out = p.happy > 0.6 ? (i === 0 ? -1 : 1) : 0;
215
- const ex = smile ? Math.round(bx + p.gx - 0.5) + 0.5 + out : bx + p.gx;
216
- const bottom = smile ? Math.round(EYE_BOTTOM + p.gy) : EYE_BOTTOM + p.gy;
217
- if (Math.abs(px - ex) < 0.5) {
218
- // 闭眼是上眼皮往下:下沿不动,高度变小,最少留 1 像素的一条线
219
- const lower = bottom - Math.min(1, happy / 0.6);
220
- const upper = Math.min(bottom - Math.max(1, EYE_H * p.open), lower - 1);
221
- if (py >= upper && py < lower)
222
- best = 1;
223
- }
224
- if (smile && Math.abs(Math.abs(px - ex) - 1) < 0.5 && py >= bottom - 1 && py < bottom)
225
- best = 1;
164
+ let best = 0;
165
+ for (const [i, bx] of EYES_X.entries()) {
166
+ const happy = i === 0 ? Math.max(p.happy, p.wink) : p.happy;
167
+ const smile = happy > 0.6;
168
+ const out = p.happy > 0.6 ? i === 0 ? -1 : 1 : 0;
169
+ const ex = smile ? Math.round(bx + p.gx - 0.5) + 0.5 + out : bx + p.gx;
170
+ const bottom = smile ? Math.round(EYE_BOTTOM + p.gy) : EYE_BOTTOM + p.gy;
171
+ if (Math.abs(px - ex) < 0.5) {
172
+ const lower = bottom - Math.min(1, happy / 0.6);
173
+ const upper = Math.min(bottom - Math.max(1, EYE_H * p.open), lower - 1);
174
+ if (py >= upper && py < lower)
175
+ best = 1;
226
176
  }
227
- return best;
177
+ if (smile && Math.abs(Math.abs(px - ex) - 1) < 0.5 && py >= bottom - 1 && py < bottom)
178
+ best = 1;
179
+ }
180
+ return best;
228
181
  }
229
- /** 右边的小东西:[列, 行, 颜色],列是 SIDE 起的 0–4 */
230
182
  function extras(mood, now, t) {
231
- return side(mood, now, t).map(([x, y, c]) => [SIDE + x, y, c]);
183
+ return side(mood, now, t).map(([x, y, c]) => [SIDE + x, y, c]);
232
184
  }
233
- /** ✓ 的五个像素,按笔画的顺序:短的一笔往右下,长的一笔往右上 */
234
185
  const CHECK = [
235
- [0, 3],
236
- [1, 4],
237
- [2, 3],
238
- [3, 2],
239
- [4, 1],
186
+ [0, 3],
187
+ [1, 4],
188
+ [2, 3],
189
+ [3, 2],
190
+ [4, 1]
240
191
  ];
241
- /** ✓ 落地后一笔画出来,每个像素隔多久;画完过一会儿一道光沿着笔画走一遍;最后按笔画的顺序暗下去消失 */
242
192
  const CHECK_STEP = 55;
243
193
  const CHECK_SHINE = 1900;
244
194
  const CHECK_FADE = HAPPY_MS - 600;
245
195
  function check(t) {
246
- const white = rgb("#ffffff");
247
- return CHECK.flatMap(([x, y], i) => {
248
- const age = t - (HOP.land + i * CHECK_STEP);
249
- if (age < 0)
250
- return [];
251
- // 刚画上的是白的笔尖,很快沉成淡玉色
252
- let c = mix(PALE, white, Math.exp(-age / 120));
253
- // 一道光:亮点沿着笔画走过去
254
- c = mix(c, white, 0.85 * Math.exp(-(((t - CHECK_SHINE) / 60 - i) ** 2)));
255
- // 消失:一个个暗下去再拿掉(外面是终端背景,没法渐隐)
256
- const out = (t - CHECK_FADE - i * 70) / 280;
257
- if (out >= 1)
258
- return [];
259
- if (out > 0)
260
- c = mix(c, DEEP, out);
261
- return [[x, y, c]];
262
- });
196
+ const white = rgb("#ffffff");
197
+ return CHECK.flatMap(([x, y], i) => {
198
+ const age = t - (HOP.land + i * CHECK_STEP);
199
+ if (age < 0)
200
+ return [];
201
+ let c = mix(PALE, white, Math.exp(-age / 120));
202
+ c = mix(c, white, 0.85 * Math.exp(-(((t - CHECK_SHINE) / 60 - i) ** 2)));
203
+ const out = (t - CHECK_FADE - i * 70) / 280;
204
+ if (out >= 1)
205
+ return [];
206
+ if (out > 0)
207
+ c = mix(c, DEEP, out);
208
+ return [[x, y, c]];
209
+ });
263
210
  }
264
211
  const fade = (t) => ramp([DEEP, rgb(JADE), PALE], t);
265
- /**
266
- * 思考的节奏(一圈的毫秒数):先琢磨 ponder,然后三个点隔 gap 一个个冒出来;
267
- * 三个都在了停一会儿,从 dim 起一起暗下去、拿掉,再接着琢磨
268
- */
269
212
  const THINK = {
270
- period: 4800,
271
- ponder: 1700,
272
- gap: 550,
273
- /** 第 i 个点冒出来的时刻 */
274
- dot: (i) => THINK.ponder + 250 + i * THINK.gap,
275
- dim: 4200,
276
- /** 暗下去用多久:之后拿掉(外面是终端背景,没法渐隐) */
277
- fade: 400,
213
+ period: 4800,
214
+ ponder: 1700,
215
+ gap: 550,
216
+ dot: (i) => THINK.ponder + 250 + i * THINK.gap,
217
+ dim: 4200,
218
+ fade: 400
278
219
  };
279
- /** 三个点:在右上方从左往右排成一排,和往右上看的眼睛同一高度附近,像省略号 */
280
220
  const DOTS = [
281
- [0, 1],
282
- [2, 1],
283
- [4, 1],
221
+ [0, 1],
222
+ [2, 1],
223
+ [4, 1]
284
224
  ];
285
225
  function dots(now) {
286
- const t = now % THINK.period;
287
- const out = (t - THINK.dim) / THINK.fade;
288
- if (out >= 1)
289
- return [];
290
- return DOTS.flatMap(([x, y], i) => {
291
- const age = t - THINK.dot(i);
292
- if (age < 0)
293
- return [];
294
- // 冒出来时白一下,很快沉成淡玉色
295
- let c = mix(fade(0.85), rgb("#ffffff"), Math.exp(-age / 140));
296
- if (out > 0)
297
- c = mix(c, DEEP, out);
298
- return [[x, y, c]];
299
- });
226
+ const t = now % THINK.period;
227
+ const out = (t - THINK.dim) / THINK.fade;
228
+ if (out >= 1)
229
+ return [];
230
+ return DOTS.flatMap(([x, y], i) => {
231
+ const age = t - THINK.dot(i);
232
+ if (age < 0)
233
+ return [];
234
+ let c = mix(fade(0.85), rgb("#ffffff"), Math.exp(-age / 140));
235
+ if (out > 0)
236
+ c = mix(c, DEEP, out);
237
+ return [[x, y, c]];
238
+ });
300
239
  }
301
240
  function side(mood, now, t) {
302
- switch (mood) {
303
- case "happy":
304
- return check(t);
305
- case "thinking":
306
- return dots(now);
307
- case "writing": {
308
- // 打字的点:一个个亮起来,亮过之后慢慢暗下去
309
- const t = (now % 1200) / 1200;
310
- return [0, 1, 2].flatMap((x) => {
311
- const age = t - x * 0.18;
312
- return age >= 0 && age < 0.75 ? [[x, 5, fade(1 - Math.max(0, age - 0.25) * 2)]] : [];
313
- });
314
- }
315
- case "tool": {
316
- // 彗星一样转圈:亮的头,后面跟着越来越暗的尾巴
317
- const ring = [
318
- [1, 1],
319
- [2, 2],
320
- [2, 3],
321
- [1, 4],
322
- [0, 3],
323
- [0, 2],
324
- ];
325
- const head = Math.floor(now / 90) % ring.length;
326
- return [0, 1, 2, 3].map((k) => {
327
- const [x, y] = ring[(head - k + ring.length) % ring.length];
328
- return [x, y, fade(1 - k / 3.2)];
329
- });
330
- }
331
- case "asking": {
332
- // 感叹号在两种黄之间呼吸
333
- const c = mix(BANG[0], BANG[1], 0.5 + 0.5 * Math.sin(now / 160));
334
- return [0, 1, 2, 4].map((y) => [1, y, c]);
335
- }
336
- case "stopping":
337
- // 汗珠挂在头的右上角,贴着身体
338
- return [
339
- [-1, 0, SWEAT],
340
- [-1, 1, mix(SWEAT, rgb("#ffffff"), 0.4)],
341
- ];
342
- default:
343
- return [];
241
+ switch (mood) {
242
+ case "happy":
243
+ return check(t);
244
+ case "thinking":
245
+ return dots(now);
246
+ case "writing": {
247
+ const t = now % 1200 / 1200;
248
+ return [0, 1, 2].flatMap((x) => {
249
+ const age = t - x * 0.18;
250
+ return age >= 0 && age < 0.75 ? [[x, 5, fade(1 - Math.max(0, age - 0.25) * 2)]] : [];
251
+ });
252
+ }
253
+ case "tool": {
254
+ const ring = [
255
+ [1, 1],
256
+ [2, 2],
257
+ [2, 3],
258
+ [1, 4],
259
+ [0, 3],
260
+ [0, 2]
261
+ ];
262
+ const head = Math.floor(now / 90) % ring.length;
263
+ return [0, 1, 2, 3].map((k) => {
264
+ const [x, y] = ring[(head - k + ring.length) % ring.length];
265
+ return [x, y, fade(1 - k / 3.2)];
266
+ });
267
+ }
268
+ case "asking": {
269
+ const c = mix(BANG[0], BANG[1], 0.5 + 0.5 * Math.sin(now / 160));
270
+ return [0, 1, 2, 4].map((y) => [1, y, c]);
344
271
  }
272
+ case "stopping": {
273
+ const row = Math.floor(now % 1000 / 200);
274
+ if (row > 3)
275
+ return [];
276
+ const head = [-1, row, mix(SWEAT, rgb("#ffffff"), 0.4)];
277
+ return row > 0 ? [[-1, row - 1, SWEAT], head] : [head];
278
+ }
279
+ default:
280
+ return [];
281
+ }
345
282
  }
346
- /**
347
- * 有状态的动画:每次 frame 把 Pose 往当前状态想要的样子缓动一点,所以换状态时眼睛是滑过去的。
348
- * 眨眼这种很快的动作直接用目标值,不缓动
349
- */
283
+
350
284
  export class Mascot {
351
- pose = { ...REST };
352
- #last;
353
- #mood;
354
- /** 进入当前状态的时刻:做完后那一套动作按它排时间 */
355
- #since = 0;
356
- frame(mood, now) {
357
- if (mood !== this.#mood) {
358
- this.#mood = mood;
359
- this.#since = now;
360
- }
361
- const t = now - this.#since;
362
- const want = goal(mood, now, t);
363
- const dt = this.#last === undefined ? 1e9 : Math.max(0, now - this.#last);
364
- this.#last = now;
365
- const k = 1 - Math.exp(-dt / 110);
366
- const p = this.pose;
367
- for (const key of ["gx", "gy", "happy", "wink", "tint"])
368
- p[key] += (want[key] - p[key]) * k;
369
- p.open = want.open < p.open ? want.open : p.open + (want.open - p.open) * (1 - Math.exp(-dt / 50));
370
- p.glow = want.glow;
371
- return paint(p, mood, now, t);
372
- }
373
- /** 还在往目标缓动(空闲时也要接着重画几帧) */
374
- moving(mood, now) {
375
- const want = goal(mood, now, mood === this.#mood ? now - this.#since : 0);
376
- const p = this.pose;
377
- return ["gx", "gy", "happy", "wink", "tint", "open"].some((k) => Math.abs(want[k] - p[k]) > 0.02);
285
+ pose = { ...REST };
286
+ #last;
287
+ #mood;
288
+ #since = 0;
289
+ frame(mood, now) {
290
+ if (mood !== this.#mood) {
291
+ this.#mood = mood;
292
+ this.#since = now;
378
293
  }
294
+ const t = now - this.#since;
295
+ const want = goal(mood, now, t);
296
+ const dt = this.#last === undefined ? 1e9 : Math.max(0, now - this.#last);
297
+ this.#last = now;
298
+ const k = 1 - Math.exp(-dt / 110);
299
+ const p = this.pose;
300
+ for (const key of ["gx", "gy", "happy", "wink", "tint"])
301
+ p[key] += (want[key] - p[key]) * k;
302
+ p.open = want.open < p.open ? want.open : p.open + (want.open - p.open) * (1 - Math.exp(-dt / 50));
303
+ p.glow = want.glow;
304
+ return paint(p, mood, now, t);
305
+ }
306
+ moving(mood, now) {
307
+ const want = goal(mood, now, mood === this.#mood ? now - this.#since : 0);
308
+ const p = this.pose;
309
+ return ["gx", "gy", "happy", "wink", "tint", "open"].some((k) => Math.abs(want[k] - p[k]) > 0.02);
310
+ }
379
311
  }
380
- /** 把像素合成半格字符,每一行是若干段同色的字符 */
381
312
  export function cells(grid) {
382
- const out = [];
383
- for (let y = 0; y < grid.length; y += 2) {
384
- const top = grid[y];
385
- const bottom = grid[y + 1] ?? [];
386
- const line = [];
387
- for (let x = 0; x < top.length; x++) {
388
- const t = top[x];
389
- const b = bottom[x];
390
- const cell = !t && !b ? { text: " " }
391
- : t === b ? { text: "█", fg: t }
392
- : !t ? { text: "▄", fg: b }
393
- : !b ? { text: "▀", fg: t }
394
- : { text: "▀", fg: t, bg: b };
395
- const last = line.at(-1);
396
- if (last && last.fg === cell.fg && last.bg === cell.bg)
397
- last.text += cell.text;
398
- else
399
- line.push(cell);
400
- }
401
- out.push(line);
313
+ const out = [];
314
+ for (let y = 0;y < grid.length; y += 2) {
315
+ const top = grid[y];
316
+ const bottom = grid[y + 1] ?? [];
317
+ const line = [];
318
+ for (let x = 0;x < top.length; x++) {
319
+ const t = top[x];
320
+ const b = bottom[x];
321
+ const cell = !t && !b ? { text: " " } : t === b ? { text: "█", fg: t } : !t ? { text: "▄", fg: b } : !b ? { text: "▀", fg: t } : { text: "▀", fg: t, bg: b };
322
+ const last = line.at(-1);
323
+ if (last && last.fg === cell.fg && last.bg === cell.bg)
324
+ last.text += cell.text;
325
+ else
326
+ line.push(cell);
402
327
  }
403
- return out;
328
+ out.push(line);
329
+ }
330
+ return out;
404
331
  }
405
- /** 动画帧之间隔多久 */
406
332
  export const FRAME_MS = 50;
407
- /**
408
- * 不在运行时,下一次需要重画还要多久(毫秒):缓动没结束、正在眨眼或瞟眼时按帧画,
409
- * 否则等到下一次眨眼、瞟眼或笑完。运行中由 App 定时重画,用不到这个
410
- */
411
333
  export function nextChange(mood, now, doneAt, moving = false) {
412
- if (moving)
413
- return FRAME_MS;
414
- if (mood === "asking" || mood === "happy") {
415
- const end = mood === "happy" && doneAt !== undefined ? doneAt + HAPPY_MS - now : Infinity;
416
- return Math.max(16, Math.min(FRAME_MS, end));
417
- }
418
- const tb = now % BLINK_EVERY;
419
- // 眨眼(含连眨的第二下)期间按帧画
420
- if (tb < 2 * BLINK_MS + 90)
421
- return FRAME_MS;
422
- const tg = now % GLANCE_EVERY;
423
- const toGlance = tg < GLANCE[0] ? GLANCE[0] - tg : tg < GLANCE[1] ? GLANCE[1] - tg : GLANCE_EVERY - tg + GLANCE[0];
424
- return Math.max(16, Math.min(BLINK_EVERY - tb, toGlance));
334
+ if (moving)
335
+ return FRAME_MS;
336
+ if (mood === "asking" || mood === "happy") {
337
+ const end = mood === "happy" && doneAt !== undefined ? doneAt + HAPPY_MS - now : 1 / 0;
338
+ return Math.max(16, Math.min(FRAME_MS, end));
339
+ }
340
+ const tb = now % BLINK_EVERY;
341
+ if (tb < 2 * BLINK_MS + 90)
342
+ return FRAME_MS;
343
+ const tg = now % GLANCE_EVERY;
344
+ const toGlance = tg < GLANCE[0] ? GLANCE[0] - tg : tg < GLANCE[1] ? GLANCE[1] - tg : GLANCE_EVERY - tg + GLANCE[0];
345
+ return Math.max(16, Math.min(BLINK_EVERY - tb, toGlance));
425
346
  }
426
- // ---------- 终端标题 ----------
427
- /** jade 的标志:一块玉 */
428
347
  export const LOGO = "◆";
429
348
  const SPIN = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
430
- /**
431
- * 终端标签页标题:空闲时是标志,运行中换成转圈,等用户时加感叹号,在别的标签页里也能看出 jade 在做什么。
432
- * dir 是当前目录的名字
433
- */
434
349
  export function title(mood, dir, now) {
435
- const mark = mood === "asking" ? `${LOGO}!`
436
- : mood === "idle" || mood === "happy" ? LOGO
437
- : SPIN[Math.floor(now / 250) % SPIN.length];
438
- return `${mark} jade · ${dir}`;
350
+ const mark = mood === "asking" ? `${LOGO}!` : mood === "idle" || mood === "happy" ? LOGO : SPIN[Math.floor(now / 250) % SPIN.length];
351
+ return `${mark} jade · ${dir}`;
439
352
  }