dsh-notify-tray 0.1.11 → 0.1.13
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/README.en.md +9 -9
- package/README.md +9 -9
- package/README.zh-CN.md +9 -9
- package/assets/mascot-peeking.prompt.txt +6 -6
- package/assets/notify-icon.png +0 -0
- package/assets/tray-darwin.js +283 -283
- package/cordis.patch.yml +6 -6
- package/lib/ToastActivator.cs +33 -0
- package/lib/catalog.js +448 -448
- package/lib/client.js +65 -132
- package/lib/format.js +284 -284
- package/lib/host/context.js +11 -3
- package/lib/host/notify.js +26 -21
- package/lib/host/routes.js +9 -42
- package/lib/host/spend.js +190 -190
- package/lib/host/tray.js +120 -120
- package/lib/icon.js +159 -159
- package/lib/index.js +2 -7
- package/lib/ledger.js +285 -285
- package/lib/models-dev.json +2684 -2684
- package/lib/notices.js +3 -4
- package/lib/pricing.js +302 -302
- package/lib/quota.js +290 -290
- package/lib/system.js +11 -22
- package/lib/tracker.js +250 -250
- package/lib/tray/index.js +142 -142
- package/lib/tray/linux.js +393 -393
- package/lib/voice.js +76 -76
- package/lib/whale.js +396 -396
- package/lib/windows-toast.js +92 -0
- package/locale/en.json +7 -7
- package/locale/zh.json +7 -7
- package/package.json +2 -1
package/lib/whale.js
CHANGED
|
@@ -1,396 +1,396 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The whale: the plugin's one icon, drawn from code on every platform.
|
|
3
|
-
*
|
|
4
|
-
* It is the DeepSeek Harness whale: a whale curled into a ring, nose to the
|
|
5
|
-
* right, tail sweeping up behind its head, a small dorsal fin on the back,
|
|
6
|
-
* the white sweep of its belly line and a comma-shaped eye cut out of the
|
|
7
|
-
* body. The outline was traced by hand from the app icon's silhouette and
|
|
8
|
-
* smoothed into cubic curves; no bitmap is involved anywhere.
|
|
9
|
-
*
|
|
10
|
-
* State variants add a floating glyph in front of the nose instead of
|
|
11
|
-
* changing the colour, so the icon works as a monochrome macOS template image
|
|
12
|
-
* and as a tinted bitmap on Windows / Linux alike:
|
|
13
|
-
*
|
|
14
|
-
* idle the whale
|
|
15
|
-
* running the whale swimming and blowing bubbles (12-frame loop)
|
|
16
|
-
* attention the whale + "!"
|
|
17
|
-
* error the whale + "×"
|
|
18
|
-
*
|
|
19
|
-
* Geometry lives in a 100-wide box, y down. Paths use nonzero winding:
|
|
20
|
-
* clockwise subpaths add, counter-clockwise subpaths cut holes.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export const BOX = 100
|
|
24
|
-
/** Tight bounds of every variant inside the box (helpers crop to this). */
|
|
25
|
-
export const BOUNDS = { x: 0, y: -6.5, w: 104, h: 80.5 }
|
|
26
|
-
|
|
27
|
-
/** Tint used where the icon is a coloured bitmap (Windows / Linux / SVG). */
|
|
28
|
-
export const STATE_RGB = {
|
|
29
|
-
idle: [59, 83, 170], // deep dress blue
|
|
30
|
-
running: [77, 107, 254], // DeepSeek blue
|
|
31
|
-
attention: [245, 158, 11], // amber
|
|
32
|
-
error: [224, 49, 49], // red
|
|
33
|
-
done: [46, 160, 90], // green, just for the few seconds after a finish
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const K = 0.5523 // cubic approximation of a quarter circle
|
|
37
|
-
|
|
38
|
-
/** Circle as four cubics. Clockwise (y down) adds; ccw cuts. */
|
|
39
|
-
function circle(cx, cy, r, { hole = false } = {}) {
|
|
40
|
-
const k = K * r
|
|
41
|
-
const cw = [
|
|
42
|
-
['M', cx, cy - r],
|
|
43
|
-
['C', cx + k, cy - r, cx + r, cy - k, cx + r, cy],
|
|
44
|
-
['C', cx + r, cy + k, cx + k, cy + r, cx, cy + r],
|
|
45
|
-
['C', cx - k, cy + r, cx - r, cy + k, cx - r, cy],
|
|
46
|
-
['C', cx - r, cy - k, cx - k, cy - r, cx, cy - r],
|
|
47
|
-
['Z'],
|
|
48
|
-
]
|
|
49
|
-
return hole ? reverse(cw) : cw
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Ellipse (axis-aligned) as four cubics, clockwise. */
|
|
53
|
-
function ellipse(cx, cy, rx, ry) {
|
|
54
|
-
const kx = K * rx
|
|
55
|
-
const ky = K * ry
|
|
56
|
-
return [
|
|
57
|
-
['M', cx, cy - ry],
|
|
58
|
-
['C', cx + kx, cy - ry, cx + rx, cy - ky, cx + rx, cy],
|
|
59
|
-
['C', cx + rx, cy + ky, cx + kx, cy + ry, cx, cy + ry],
|
|
60
|
-
['C', cx - kx, cy + ry, cx - rx, cy + ky, cx - rx, cy],
|
|
61
|
-
['C', cx - rx, cy - ky, cx - kx, cy - ry, cx, cy - ry],
|
|
62
|
-
['Z'],
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Rounded rectangle centred at (cx, cy), rotated by `deg`, clockwise. */
|
|
67
|
-
function pill(cx, cy, w, h, r, deg = 0) {
|
|
68
|
-
const rad = (deg * Math.PI) / 180
|
|
69
|
-
const cos = Math.cos(rad)
|
|
70
|
-
const sin = Math.sin(rad)
|
|
71
|
-
const t = (x, y) => [cx + x * cos - y * sin, cy + x * sin + y * cos]
|
|
72
|
-
const hw = w / 2
|
|
73
|
-
const hh = h / 2
|
|
74
|
-
const k = K * r
|
|
75
|
-
const seg = (...pts) => pts.flatMap(([x, y]) => t(x, y))
|
|
76
|
-
return [
|
|
77
|
-
['M', ...t(-hw + r, -hh)],
|
|
78
|
-
['L', ...t(hw - r, -hh)],
|
|
79
|
-
['C', ...seg([hw - r + k, -hh], [hw, -hh + r - k], [hw, -hh + r])],
|
|
80
|
-
['L', ...t(hw, hh - r)],
|
|
81
|
-
['C', ...seg([hw, hh - r + k], [hw - r + k, hh], [hw - r, hh])],
|
|
82
|
-
['L', ...t(-hw + r, hh)],
|
|
83
|
-
['C', ...seg([-hw + r - k, hh], [-hw, hh - r + k], [-hw, hh - r])],
|
|
84
|
-
['L', ...t(-hw, -hh + r)],
|
|
85
|
-
['C', ...seg([-hw, -hh + r - k], [-hw + r - k, -hh], [-hw + r, -hh])],
|
|
86
|
-
['Z'],
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Reverse a closed subpath's direction (turns an additive shape into a hole). */
|
|
91
|
-
function reverse(sub) {
|
|
92
|
-
const pts = []
|
|
93
|
-
let cur
|
|
94
|
-
for (const cmd of sub) {
|
|
95
|
-
if (cmd[0] === 'M') cur = [cmd[1], cmd[2]]
|
|
96
|
-
else if (cmd[0] === 'L') { pts.push({ from: cur, to: [cmd[1], cmd[2]] }); cur = [cmd[1], cmd[2]] }
|
|
97
|
-
else if (cmd[0] === 'C') {
|
|
98
|
-
pts.push({ from: cur, c1: [cmd[1], cmd[2]], c2: [cmd[3], cmd[4]], to: [cmd[5], cmd[6]] })
|
|
99
|
-
cur = [cmd[5], cmd[6]]
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const out = [['M', ...pts[pts.length - 1].to]]
|
|
103
|
-
for (let i = pts.length - 1; i >= 0; i -= 1) {
|
|
104
|
-
const s = pts[i]
|
|
105
|
-
if (s.c1) out.push(['C', ...s.c2, ...s.c1, ...s.from])
|
|
106
|
-
else out.push(['L', ...s.from])
|
|
107
|
-
}
|
|
108
|
-
out.push(['Z'])
|
|
109
|
-
return out
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ---- the whale ------------------------------------------------------------
|
|
113
|
-
|
|
114
|
-
/** The icon's silhouette is 0.735 as tall as it is wide; points below are traced in percent of each. */
|
|
115
|
-
const ASPECT = 0.735
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Closed Catmull-Rom spline through traced points → cubic bezier commands.
|
|
119
|
-
* A point written as [x, y, 1] is a corner (no smoothing through it).
|
|
120
|
-
*/
|
|
121
|
-
function spline(points, { hole = false } = {}) {
|
|
122
|
-
const pts = points.map(([x, y, corner]) => [x, y * ASPECT, corner === 1])
|
|
123
|
-
const n = pts.length
|
|
124
|
-
const out = [['M', pts[0][0], pts[0][1]]]
|
|
125
|
-
for (let i = 0; i < n; i += 1) {
|
|
126
|
-
const p0 = pts[(i - 1 + n) % n]
|
|
127
|
-
const p1 = pts[i]
|
|
128
|
-
const p2 = pts[(i + 1) % n]
|
|
129
|
-
const p3 = pts[(i + 2) % n]
|
|
130
|
-
const c1 = p1[2] ? [p1[0], p1[1]] : [p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6]
|
|
131
|
-
const c2 = p2[2] ? [p2[0], p2[1]] : [p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6]
|
|
132
|
-
out.push(['C', c1[0], c1[1], c2[0], c2[1], p2[0], p2[1]])
|
|
133
|
-
}
|
|
134
|
-
out.push(['Z'])
|
|
135
|
-
return hole ? reverse(out) : out
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Outer silhouette, clockwise: back, dorsal fin, forehead, nose, face, chin,
|
|
140
|
-
* then up the belly-line sweep (which opens out at the mouth corner, so it is
|
|
141
|
-
* a deep bay rather than a hole), round the pectoral fin, and back along the
|
|
142
|
-
* tail stock round the ring.
|
|
143
|
-
*/
|
|
144
|
-
const BODY = spline([
|
|
145
|
-
[22, 7], [31, 5.5], [43, 5], [49, 2, 1], [53, 4.5, 1], // back up to the little dorsal fin
|
|
146
|
-
[51, 8], [50, 12], [52, 16], [56, 20], [61, 26], // the fin's trailing notch, then the head rises
|
|
147
|
-
[65, 32], [70, 37], [77, 38.5], [84, 41, 1], // forehead to the nose
|
|
148
|
-
[84, 47], [82, 56], [79, 64], [75, 72], [72, 79], // down the face
|
|
149
|
-
[73, 84], [78, 87], [79, 90.5], [75, 93], [66, 93, 1], // chin and the jaw's underside
|
|
150
|
-
[62, 89.5], [58, 84], [53.5, 78], [49, 71], [45, 64], // up the sweep's right side (the belly band)
|
|
151
|
-
[41, 57], [36, 50], [29, 43], [19, 37], [8.5, 34.5, 1], // to the sweep's tip
|
|
152
|
-
[6.5, 40], [7, 46], [8, 52], [9, 58], [11, 64], // down its left side (inside the ring)
|
|
153
|
-
[14, 70], [18, 76], [23, 82], [28, 85.5], [32, 87.5, 1], // to the pectoral fin
|
|
154
|
-
[33, 81], [33, 74.5, 1], [39, 74.5, 1], [44, 80], [48, 85.5], // the fin
|
|
155
|
-
[51, 89, 1], [56, 91], [61, 93.5, 1], // along the tail stock to the mouth corner
|
|
156
|
-
[56, 96], [49, 98.5], [40, 99.5], [28, 97], // the ring's underside
|
|
157
|
-
[18, 92], [11, 84], [5, 73], [1.5, 60], [0.5, 46], // round the left of the ring
|
|
158
|
-
[2, 32], [7, 19], [14, 11], // and back up to the back
|
|
159
|
-
])
|
|
160
|
-
|
|
161
|
-
/** Comma-shaped eye (hole) with its pupil (added back). */
|
|
162
|
-
const EYE = spline([
|
|
163
|
-
[52, 39, 1], [57, 41.5], [62, 45], [66, 50], [67, 55], [64.5, 59.5], [61, 60.5], [58.5, 57], [56, 51], [53.5, 45],
|
|
164
|
-
], { hole: true })
|
|
165
|
-
const PUPIL = circle(55.2, 47.5 * ASPECT, 2.2)
|
|
166
|
-
|
|
167
|
-
/** Tail flukes, sweeping up behind the head. Overlaps the forehead (nonzero union). */
|
|
168
|
-
const TAIL = spline([
|
|
169
|
-
[70, 1, 1], [73, 5], [76, 10], [79, 14], [82.5, 17, 1], // left fluke's inner edge down to the notch
|
|
170
|
-
[87, 14], [93, 11], [100, 10, 1], // right fluke out to its tip
|
|
171
|
-
[99, 19], [97, 25], [93, 30], [87, 34], [84, 38], // its trailing edge down into the head
|
|
172
|
-
[80, 45], [74, 45], [74, 38], [74, 31], // inside the head, back up the stem
|
|
173
|
-
[71, 26], [68, 20], [67, 12], [68, 5], // the left fluke's leading edge
|
|
174
|
-
])
|
|
175
|
-
|
|
176
|
-
const Y = y => y * ASPECT
|
|
177
|
-
|
|
178
|
-
// ---- transforms (for animation frames) ---------------------------------------
|
|
179
|
-
|
|
180
|
-
/** Apply (x, y) => [x', y'] to every coordinate pair of every command. */
|
|
181
|
-
function mapPoints(paths, fn) {
|
|
182
|
-
return paths.map(sub => sub.map(cmd => {
|
|
183
|
-
if (cmd.length < 3) return cmd
|
|
184
|
-
const out = [cmd[0]]
|
|
185
|
-
for (let i = 1; i < cmd.length; i += 2) out.push(...fn(cmd[i], cmd[i + 1]))
|
|
186
|
-
return out
|
|
187
|
-
}))
|
|
188
|
-
}
|
|
189
|
-
const translate = (paths, dx, dy) => mapPoints(paths, (x, y) => [x + dx, y + dy])
|
|
190
|
-
/** Rotate about (cx, cy) by `deg`, clockwise on screen (y down). */
|
|
191
|
-
function rotate(paths, cx, cy, deg) {
|
|
192
|
-
const rad = (deg * Math.PI) / 180
|
|
193
|
-
const cos = Math.cos(rad)
|
|
194
|
-
const sin = Math.sin(rad)
|
|
195
|
-
return mapPoints(paths, (x, y) => [cx + (x - cx) * cos - (y - cy) * sin, cy + (x - cx) * sin + (y - cy) * cos])
|
|
196
|
-
}
|
|
197
|
-
/** Four-point sparkle ✦ centred at (cx, cy), outer radius r. */
|
|
198
|
-
function sparkle(cx, cy, r) {
|
|
199
|
-
const k = r * 0.22
|
|
200
|
-
const q = (x1, y1, x, y, from) => ['C', from[0] + (2 / 3) * (x1 - from[0]), from[1] + (2 / 3) * (y1 - from[1]), x + (2 / 3) * (x1 - x), y + (2 / 3) * (y1 - y), x, y]
|
|
201
|
-
const p0 = [cx, cy - r]
|
|
202
|
-
const p1 = [cx + r, cy]
|
|
203
|
-
const p2 = [cx, cy + r]
|
|
204
|
-
const p3 = [cx - r, cy]
|
|
205
|
-
return [['M', ...p0], q(cx + k, cy - k, ...p1, p0), q(cx + k, cy + k, ...p2, p1), q(cx - k, cy + k, ...p3, p2), q(cx - k, cy - k, ...p0, p3), ['Z']]
|
|
206
|
-
}
|
|
207
|
-
/** Sweat drop 💧: a teardrop with its point up. */
|
|
208
|
-
function drop(cx, cy, r) {
|
|
209
|
-
return spline([[cx, cy - r * 2.2, 1], [cx + r, cy - r * 0.2], [cx + r * 0.9, cy + r * 0.8], [cx, cy + r * 1.3], [cx - r * 0.9, cy + r * 0.8], [cx - r, cy - r * 0.2]].map(([x, y, c]) => [x, y / ASPECT, c]))
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const BODY_PARTS = [BODY, EYE, PUPIL]
|
|
213
|
-
/** Eye shut: a thin slit instead of the comma (for blinks). */
|
|
214
|
-
const EYE_SHUT = spline([[53, 52, 1], [59, 51], [65, 53.5, 1], [59, 54.5]], { hole: true })
|
|
215
|
-
/** Tail pivot: where the stem meets the head. */
|
|
216
|
-
const TAIL_PIVOT = [76, Y(42)]
|
|
217
|
-
/** Whole-whale pivot for tilts. */
|
|
218
|
-
const CENTER = [48, Y(52)]
|
|
219
|
-
|
|
220
|
-
/** The whale with its tail swung by `deg` and the whole body shifted / tilted. */
|
|
221
|
-
function whale({ tail = 0, dx = 0, dy = 0, tilt = 0, blink = false } = {}) {
|
|
222
|
-
const body = blink ? [BODY, EYE_SHUT] : BODY_PARTS
|
|
223
|
-
// Transforms take a list of subpaths; TAIL alone is one subpath.
|
|
224
|
-
let parts = [...body, ...rotate([TAIL], TAIL_PIVOT[0], TAIL_PIVOT[1], tail)]
|
|
225
|
-
if (tilt) parts = rotate(parts, CENTER[0], CENTER[1], tilt)
|
|
226
|
-
if (dx || dy) parts = translate(parts, dx, dy)
|
|
227
|
-
return parts
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const bang = (dy = 0) => [pill(93, Y(52) + dy, 6, 12 * ASPECT, 3), circle(93, Y(67) + dy, 3)]
|
|
231
|
-
const cross = (dx = 0) => [pill(93 + dx, Y(58), 15, 5.5, 2.7, 45), pill(93 + dx, Y(58), 15, 5.5, 2.7, -45)]
|
|
232
|
-
/** Three bubbles in front of the nose, `t` in [0, 1) is how far they have risen. */
|
|
233
|
-
function bubbles(t) {
|
|
234
|
-
const rise = 20
|
|
235
|
-
const b = (x, y0, r, phase) => {
|
|
236
|
-
const u = (t + phase) % 1
|
|
237
|
-
return circle(x + Math.sin(u * Math.PI * 2) * 1.2, Y(y0 - u * rise), r * (0.6 + 0.4 * (1 - u)))
|
|
238
|
-
}
|
|
239
|
-
return [b(90, 66, 2.2, 0), b(95.5, 62, 3, 0.4), b(91, 58, 1.8, 0.7)]
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Per-state animation: a list of frames, how fast to play them, and whether
|
|
244
|
-
* to loop (false = play once and hold the last frame).
|
|
245
|
-
*/
|
|
246
|
-
const ANIM = {
|
|
247
|
-
idle: () => ({ fps: 1, loop: false, frames: [whale()] }),
|
|
248
|
-
// Swimming hard: tail wags, body bobs, bubbles stream out of the nose.
|
|
249
|
-
running: () => {
|
|
250
|
-
const n = 12
|
|
251
|
-
return {
|
|
252
|
-
fps: 8,
|
|
253
|
-
loop: true,
|
|
254
|
-
frames: Array.from({ length: n }, (_, i) => {
|
|
255
|
-
const ph = (i / n) * Math.PI * 2
|
|
256
|
-
return [...whale({ tail: Math.sin(ph) * 9, dy: Math.sin(ph * 2) * 0.7 }), ...bubbles(i / n)]
|
|
257
|
-
}),
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
// Waiting for you: the "!" hops, the whale tilts its head and blinks now and then.
|
|
261
|
-
attention: () => {
|
|
262
|
-
const n = 16
|
|
263
|
-
return {
|
|
264
|
-
fps: 8,
|
|
265
|
-
loop: true,
|
|
266
|
-
frames: Array.from({ length: n }, (_, i) => {
|
|
267
|
-
const ph = (i / n) * Math.PI * 2
|
|
268
|
-
const hop = -Math.abs(Math.sin(ph)) * 3
|
|
269
|
-
return [...whale({ tilt: Math.sin(ph) * 2.5, blink: i === 11, tail: Math.sin(ph) * 3 }), ...bang(hop)]
|
|
270
|
-
}),
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
// Something went wrong: the "×" shakes, a sweat drop slides down, then it all holds still.
|
|
274
|
-
error: () => {
|
|
275
|
-
const shake = [0, -3, 3, -2.5, 2.5, -1.5, 1.5, -0.5, 0.5, 0]
|
|
276
|
-
return {
|
|
277
|
-
fps: 10,
|
|
278
|
-
loop: false,
|
|
279
|
-
// The drop sits in the notch behind the dorsal fin and slides down a little.
|
|
280
|
-
frames: shake.map((dx, i) => [...whale({ tilt: -dx * 0.6, tail: -4 }), ...cross(dx), drop(60, Y(9) + Math.min(i, 5) * 1.1, 2.6)]),
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
// Just finished: a little leap with sparkles, then it settles back down.
|
|
284
|
-
done: () => {
|
|
285
|
-
const n = 14
|
|
286
|
-
const lift = [0, -2, -4.5, -6.5, -7.5, -7.5, -6.5, -4.5, -2.5, -1, 0, 0, 0, 0]
|
|
287
|
-
return {
|
|
288
|
-
fps: 10,
|
|
289
|
-
loop: false,
|
|
290
|
-
frames: lift.map((dy, i) => {
|
|
291
|
-
const k = i >= 2 && i <= 10 ? (i - 2) / 8 : -1
|
|
292
|
-
const stars = k < 0 ? [] : [
|
|
293
|
-
sparkle(93, Y(36), 7.5 * Math.sin(k * Math.PI)),
|
|
294
|
-
sparkle(58, Y(12), 5.5 * Math.sin(Math.min(1, k * 1.4) * Math.PI)),
|
|
295
|
-
sparkle(96, Y(66), 4.5 * Math.sin(Math.max(0, k - 0.2) * Math.PI)),
|
|
296
|
-
sparkle(10, Y(26), 4 * Math.sin(Math.max(0, k - 0.1) * Math.PI)),
|
|
297
|
-
]
|
|
298
|
-
return [...whale({ dy, tilt: -dy * 0.5, tail: Math.sin((i / n) * Math.PI * 4) * 8 }), ...stars]
|
|
299
|
-
}),
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export const STATES = Object.keys(ANIM)
|
|
305
|
-
const cache = new Map()
|
|
306
|
-
function animation(state) {
|
|
307
|
-
const key = ANIM[state] ? state : 'idle'
|
|
308
|
-
if (!cache.has(key)) cache.set(key, ANIM[key]())
|
|
309
|
-
return cache.get(key)
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* @param {'idle'|'running'|'attention'|'error'|'done'} state
|
|
314
|
-
* @returns {Array<Array<any>>} subpaths for one frame (wraps around).
|
|
315
|
-
*/
|
|
316
|
-
export function whalePaths(state, frame = 0) {
|
|
317
|
-
const { frames } = animation(state)
|
|
318
|
-
return frames[((frame % frames.length) + frames.length) % frames.length]
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** Animation frames for a state (one frame unless it animates). */
|
|
322
|
-
export function whaleFrames(state) {
|
|
323
|
-
return animation(state).frames
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/** Everything a helper needs to draw every state, written once to icon.json. */
|
|
327
|
-
export function iconSpec() {
|
|
328
|
-
const round = v => (typeof v === 'number' ? Number(v.toFixed(2)) : v)
|
|
329
|
-
return {
|
|
330
|
-
box: BOX,
|
|
331
|
-
bounds: BOUNDS,
|
|
332
|
-
rgb: STATE_RGB,
|
|
333
|
-
frames: Object.fromEntries(STATES.map(s => [s, whaleFrames(s).map(frame => frame.map(sub => sub.map(cmd => cmd.map(round))))])),
|
|
334
|
-
anim: Object.fromEntries(STATES.map(s => [s, { fps: animation(s).fps, loop: animation(s).loop }])),
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// ---- exporters --------------------------------------------------------------
|
|
339
|
-
|
|
340
|
-
const num = v => Number(v.toFixed(2))
|
|
341
|
-
|
|
342
|
-
export function toSvgPath(paths) {
|
|
343
|
-
return paths.map(sub => sub.map(cmd => `${cmd[0]}${cmd.slice(1).map(num).join(' ')}`).join(' ')).join(' ')
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Standalone SVG of one state, cropped to BOUNDS. `fill` defaults to the
|
|
348
|
-
* state tint; `background` adds a rounded tile the whale is centred on
|
|
349
|
-
* (used for the plugin icon), with `padding` box units around it.
|
|
350
|
-
*/
|
|
351
|
-
export function whaleSvg({ state = 'idle', frame = 0, size = 64, fill, background, padding = 0 } = {}) {
|
|
352
|
-
const [r, g, b] = STATE_RGB[state] ?? STATE_RGB.idle
|
|
353
|
-
const color = fill ?? `rgb(${r},${g},${b})`
|
|
354
|
-
const d = toSvgPath(whalePaths(state, frame))
|
|
355
|
-
if (!background) {
|
|
356
|
-
const height = Math.round(size * (BOUNDS.h / BOUNDS.w))
|
|
357
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${BOUNDS.x} ${BOUNDS.y} ${BOUNDS.w} ${BOUNDS.h}" width="${size}" height="${height}">`
|
|
358
|
-
+ `<path d="${d}" fill="${color}" fill-rule="nonzero"/></svg>`
|
|
359
|
-
}
|
|
360
|
-
const tile = BOX
|
|
361
|
-
const inner = tile - padding * 2
|
|
362
|
-
const scale = Math.min(inner / BOUNDS.w, inner / BOUNDS.h)
|
|
363
|
-
const tx = (tile - BOUNDS.w * scale) / 2 - BOUNDS.x * scale
|
|
364
|
-
const ty = (tile - BOUNDS.h * scale) / 2 - BOUNDS.y * scale
|
|
365
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${tile} ${tile}" width="${size}" height="${size}">`
|
|
366
|
-
+ `<rect width="${tile}" height="${tile}" rx="22" fill="${background}"/>`
|
|
367
|
-
+ `<path d="${d}" fill="${color}" fill-rule="nonzero" transform="translate(${tx.toFixed(2)} ${ty.toFixed(2)}) scale(${scale.toFixed(4)})"/></svg>`
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/** Flatten cubics into closed polygons (for the Linux software rasterizer). */
|
|
371
|
-
export function flatten(paths, steps = 10) {
|
|
372
|
-
const polys = []
|
|
373
|
-
for (const sub of paths) {
|
|
374
|
-
let poly = []
|
|
375
|
-
let cur = [0, 0]
|
|
376
|
-
for (const cmd of sub) {
|
|
377
|
-
if (cmd[0] === 'M') { cur = [cmd[1], cmd[2]]; poly = [cur] }
|
|
378
|
-
else if (cmd[0] === 'L') { cur = [cmd[1], cmd[2]]; poly.push(cur) }
|
|
379
|
-
else if (cmd[0] === 'C') {
|
|
380
|
-
const [x0, y0] = cur
|
|
381
|
-
const [, x1, y1, x2, y2, x3, y3] = cmd
|
|
382
|
-
for (let i = 1; i <= steps; i += 1) {
|
|
383
|
-
const t = i / steps
|
|
384
|
-
const u = 1 - t
|
|
385
|
-
poly.push([
|
|
386
|
-
u * u * u * x0 + 3 * u * u * t * x1 + 3 * u * t * t * x2 + t * t * t * x3,
|
|
387
|
-
u * u * u * y0 + 3 * u * u * t * y1 + 3 * u * t * t * y2 + t * t * t * y3,
|
|
388
|
-
])
|
|
389
|
-
}
|
|
390
|
-
cur = [x3, y3]
|
|
391
|
-
} else if (cmd[0] === 'Z') { if (poly.length > 2) polys.push(poly); poly = [] }
|
|
392
|
-
}
|
|
393
|
-
if (poly.length > 2) polys.push(poly)
|
|
394
|
-
}
|
|
395
|
-
return polys
|
|
396
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* The whale: the plugin's one icon, drawn from code on every platform.
|
|
3
|
+
*
|
|
4
|
+
* It is the DeepSeek Harness whale: a whale curled into a ring, nose to the
|
|
5
|
+
* right, tail sweeping up behind its head, a small dorsal fin on the back,
|
|
6
|
+
* the white sweep of its belly line and a comma-shaped eye cut out of the
|
|
7
|
+
* body. The outline was traced by hand from the app icon's silhouette and
|
|
8
|
+
* smoothed into cubic curves; no bitmap is involved anywhere.
|
|
9
|
+
*
|
|
10
|
+
* State variants add a floating glyph in front of the nose instead of
|
|
11
|
+
* changing the colour, so the icon works as a monochrome macOS template image
|
|
12
|
+
* and as a tinted bitmap on Windows / Linux alike:
|
|
13
|
+
*
|
|
14
|
+
* idle the whale
|
|
15
|
+
* running the whale swimming and blowing bubbles (12-frame loop)
|
|
16
|
+
* attention the whale + "!"
|
|
17
|
+
* error the whale + "×"
|
|
18
|
+
*
|
|
19
|
+
* Geometry lives in a 100-wide box, y down. Paths use nonzero winding:
|
|
20
|
+
* clockwise subpaths add, counter-clockwise subpaths cut holes.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const BOX = 100
|
|
24
|
+
/** Tight bounds of every variant inside the box (helpers crop to this). */
|
|
25
|
+
export const BOUNDS = { x: 0, y: -6.5, w: 104, h: 80.5 }
|
|
26
|
+
|
|
27
|
+
/** Tint used where the icon is a coloured bitmap (Windows / Linux / SVG). */
|
|
28
|
+
export const STATE_RGB = {
|
|
29
|
+
idle: [59, 83, 170], // deep dress blue
|
|
30
|
+
running: [77, 107, 254], // DeepSeek blue
|
|
31
|
+
attention: [245, 158, 11], // amber
|
|
32
|
+
error: [224, 49, 49], // red
|
|
33
|
+
done: [46, 160, 90], // green, just for the few seconds after a finish
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const K = 0.5523 // cubic approximation of a quarter circle
|
|
37
|
+
|
|
38
|
+
/** Circle as four cubics. Clockwise (y down) adds; ccw cuts. */
|
|
39
|
+
function circle(cx, cy, r, { hole = false } = {}) {
|
|
40
|
+
const k = K * r
|
|
41
|
+
const cw = [
|
|
42
|
+
['M', cx, cy - r],
|
|
43
|
+
['C', cx + k, cy - r, cx + r, cy - k, cx + r, cy],
|
|
44
|
+
['C', cx + r, cy + k, cx + k, cy + r, cx, cy + r],
|
|
45
|
+
['C', cx - k, cy + r, cx - r, cy + k, cx - r, cy],
|
|
46
|
+
['C', cx - r, cy - k, cx - k, cy - r, cx, cy - r],
|
|
47
|
+
['Z'],
|
|
48
|
+
]
|
|
49
|
+
return hole ? reverse(cw) : cw
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Ellipse (axis-aligned) as four cubics, clockwise. */
|
|
53
|
+
function ellipse(cx, cy, rx, ry) {
|
|
54
|
+
const kx = K * rx
|
|
55
|
+
const ky = K * ry
|
|
56
|
+
return [
|
|
57
|
+
['M', cx, cy - ry],
|
|
58
|
+
['C', cx + kx, cy - ry, cx + rx, cy - ky, cx + rx, cy],
|
|
59
|
+
['C', cx + rx, cy + ky, cx + kx, cy + ry, cx, cy + ry],
|
|
60
|
+
['C', cx - kx, cy + ry, cx - rx, cy + ky, cx - rx, cy],
|
|
61
|
+
['C', cx - rx, cy - ky, cx - kx, cy - ry, cx, cy - ry],
|
|
62
|
+
['Z'],
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Rounded rectangle centred at (cx, cy), rotated by `deg`, clockwise. */
|
|
67
|
+
function pill(cx, cy, w, h, r, deg = 0) {
|
|
68
|
+
const rad = (deg * Math.PI) / 180
|
|
69
|
+
const cos = Math.cos(rad)
|
|
70
|
+
const sin = Math.sin(rad)
|
|
71
|
+
const t = (x, y) => [cx + x * cos - y * sin, cy + x * sin + y * cos]
|
|
72
|
+
const hw = w / 2
|
|
73
|
+
const hh = h / 2
|
|
74
|
+
const k = K * r
|
|
75
|
+
const seg = (...pts) => pts.flatMap(([x, y]) => t(x, y))
|
|
76
|
+
return [
|
|
77
|
+
['M', ...t(-hw + r, -hh)],
|
|
78
|
+
['L', ...t(hw - r, -hh)],
|
|
79
|
+
['C', ...seg([hw - r + k, -hh], [hw, -hh + r - k], [hw, -hh + r])],
|
|
80
|
+
['L', ...t(hw, hh - r)],
|
|
81
|
+
['C', ...seg([hw, hh - r + k], [hw - r + k, hh], [hw - r, hh])],
|
|
82
|
+
['L', ...t(-hw + r, hh)],
|
|
83
|
+
['C', ...seg([-hw + r - k, hh], [-hw, hh - r + k], [-hw, hh - r])],
|
|
84
|
+
['L', ...t(-hw, -hh + r)],
|
|
85
|
+
['C', ...seg([-hw, -hh + r - k], [-hw + r - k, -hh], [-hw + r, -hh])],
|
|
86
|
+
['Z'],
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Reverse a closed subpath's direction (turns an additive shape into a hole). */
|
|
91
|
+
function reverse(sub) {
|
|
92
|
+
const pts = []
|
|
93
|
+
let cur
|
|
94
|
+
for (const cmd of sub) {
|
|
95
|
+
if (cmd[0] === 'M') cur = [cmd[1], cmd[2]]
|
|
96
|
+
else if (cmd[0] === 'L') { pts.push({ from: cur, to: [cmd[1], cmd[2]] }); cur = [cmd[1], cmd[2]] }
|
|
97
|
+
else if (cmd[0] === 'C') {
|
|
98
|
+
pts.push({ from: cur, c1: [cmd[1], cmd[2]], c2: [cmd[3], cmd[4]], to: [cmd[5], cmd[6]] })
|
|
99
|
+
cur = [cmd[5], cmd[6]]
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const out = [['M', ...pts[pts.length - 1].to]]
|
|
103
|
+
for (let i = pts.length - 1; i >= 0; i -= 1) {
|
|
104
|
+
const s = pts[i]
|
|
105
|
+
if (s.c1) out.push(['C', ...s.c2, ...s.c1, ...s.from])
|
|
106
|
+
else out.push(['L', ...s.from])
|
|
107
|
+
}
|
|
108
|
+
out.push(['Z'])
|
|
109
|
+
return out
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---- the whale ------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
/** The icon's silhouette is 0.735 as tall as it is wide; points below are traced in percent of each. */
|
|
115
|
+
const ASPECT = 0.735
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Closed Catmull-Rom spline through traced points → cubic bezier commands.
|
|
119
|
+
* A point written as [x, y, 1] is a corner (no smoothing through it).
|
|
120
|
+
*/
|
|
121
|
+
function spline(points, { hole = false } = {}) {
|
|
122
|
+
const pts = points.map(([x, y, corner]) => [x, y * ASPECT, corner === 1])
|
|
123
|
+
const n = pts.length
|
|
124
|
+
const out = [['M', pts[0][0], pts[0][1]]]
|
|
125
|
+
for (let i = 0; i < n; i += 1) {
|
|
126
|
+
const p0 = pts[(i - 1 + n) % n]
|
|
127
|
+
const p1 = pts[i]
|
|
128
|
+
const p2 = pts[(i + 1) % n]
|
|
129
|
+
const p3 = pts[(i + 2) % n]
|
|
130
|
+
const c1 = p1[2] ? [p1[0], p1[1]] : [p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6]
|
|
131
|
+
const c2 = p2[2] ? [p2[0], p2[1]] : [p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6]
|
|
132
|
+
out.push(['C', c1[0], c1[1], c2[0], c2[1], p2[0], p2[1]])
|
|
133
|
+
}
|
|
134
|
+
out.push(['Z'])
|
|
135
|
+
return hole ? reverse(out) : out
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Outer silhouette, clockwise: back, dorsal fin, forehead, nose, face, chin,
|
|
140
|
+
* then up the belly-line sweep (which opens out at the mouth corner, so it is
|
|
141
|
+
* a deep bay rather than a hole), round the pectoral fin, and back along the
|
|
142
|
+
* tail stock round the ring.
|
|
143
|
+
*/
|
|
144
|
+
const BODY = spline([
|
|
145
|
+
[22, 7], [31, 5.5], [43, 5], [49, 2, 1], [53, 4.5, 1], // back up to the little dorsal fin
|
|
146
|
+
[51, 8], [50, 12], [52, 16], [56, 20], [61, 26], // the fin's trailing notch, then the head rises
|
|
147
|
+
[65, 32], [70, 37], [77, 38.5], [84, 41, 1], // forehead to the nose
|
|
148
|
+
[84, 47], [82, 56], [79, 64], [75, 72], [72, 79], // down the face
|
|
149
|
+
[73, 84], [78, 87], [79, 90.5], [75, 93], [66, 93, 1], // chin and the jaw's underside
|
|
150
|
+
[62, 89.5], [58, 84], [53.5, 78], [49, 71], [45, 64], // up the sweep's right side (the belly band)
|
|
151
|
+
[41, 57], [36, 50], [29, 43], [19, 37], [8.5, 34.5, 1], // to the sweep's tip
|
|
152
|
+
[6.5, 40], [7, 46], [8, 52], [9, 58], [11, 64], // down its left side (inside the ring)
|
|
153
|
+
[14, 70], [18, 76], [23, 82], [28, 85.5], [32, 87.5, 1], // to the pectoral fin
|
|
154
|
+
[33, 81], [33, 74.5, 1], [39, 74.5, 1], [44, 80], [48, 85.5], // the fin
|
|
155
|
+
[51, 89, 1], [56, 91], [61, 93.5, 1], // along the tail stock to the mouth corner
|
|
156
|
+
[56, 96], [49, 98.5], [40, 99.5], [28, 97], // the ring's underside
|
|
157
|
+
[18, 92], [11, 84], [5, 73], [1.5, 60], [0.5, 46], // round the left of the ring
|
|
158
|
+
[2, 32], [7, 19], [14, 11], // and back up to the back
|
|
159
|
+
])
|
|
160
|
+
|
|
161
|
+
/** Comma-shaped eye (hole) with its pupil (added back). */
|
|
162
|
+
const EYE = spline([
|
|
163
|
+
[52, 39, 1], [57, 41.5], [62, 45], [66, 50], [67, 55], [64.5, 59.5], [61, 60.5], [58.5, 57], [56, 51], [53.5, 45],
|
|
164
|
+
], { hole: true })
|
|
165
|
+
const PUPIL = circle(55.2, 47.5 * ASPECT, 2.2)
|
|
166
|
+
|
|
167
|
+
/** Tail flukes, sweeping up behind the head. Overlaps the forehead (nonzero union). */
|
|
168
|
+
const TAIL = spline([
|
|
169
|
+
[70, 1, 1], [73, 5], [76, 10], [79, 14], [82.5, 17, 1], // left fluke's inner edge down to the notch
|
|
170
|
+
[87, 14], [93, 11], [100, 10, 1], // right fluke out to its tip
|
|
171
|
+
[99, 19], [97, 25], [93, 30], [87, 34], [84, 38], // its trailing edge down into the head
|
|
172
|
+
[80, 45], [74, 45], [74, 38], [74, 31], // inside the head, back up the stem
|
|
173
|
+
[71, 26], [68, 20], [67, 12], [68, 5], // the left fluke's leading edge
|
|
174
|
+
])
|
|
175
|
+
|
|
176
|
+
const Y = y => y * ASPECT
|
|
177
|
+
|
|
178
|
+
// ---- transforms (for animation frames) ---------------------------------------
|
|
179
|
+
|
|
180
|
+
/** Apply (x, y) => [x', y'] to every coordinate pair of every command. */
|
|
181
|
+
function mapPoints(paths, fn) {
|
|
182
|
+
return paths.map(sub => sub.map(cmd => {
|
|
183
|
+
if (cmd.length < 3) return cmd
|
|
184
|
+
const out = [cmd[0]]
|
|
185
|
+
for (let i = 1; i < cmd.length; i += 2) out.push(...fn(cmd[i], cmd[i + 1]))
|
|
186
|
+
return out
|
|
187
|
+
}))
|
|
188
|
+
}
|
|
189
|
+
const translate = (paths, dx, dy) => mapPoints(paths, (x, y) => [x + dx, y + dy])
|
|
190
|
+
/** Rotate about (cx, cy) by `deg`, clockwise on screen (y down). */
|
|
191
|
+
function rotate(paths, cx, cy, deg) {
|
|
192
|
+
const rad = (deg * Math.PI) / 180
|
|
193
|
+
const cos = Math.cos(rad)
|
|
194
|
+
const sin = Math.sin(rad)
|
|
195
|
+
return mapPoints(paths, (x, y) => [cx + (x - cx) * cos - (y - cy) * sin, cy + (x - cx) * sin + (y - cy) * cos])
|
|
196
|
+
}
|
|
197
|
+
/** Four-point sparkle ✦ centred at (cx, cy), outer radius r. */
|
|
198
|
+
function sparkle(cx, cy, r) {
|
|
199
|
+
const k = r * 0.22
|
|
200
|
+
const q = (x1, y1, x, y, from) => ['C', from[0] + (2 / 3) * (x1 - from[0]), from[1] + (2 / 3) * (y1 - from[1]), x + (2 / 3) * (x1 - x), y + (2 / 3) * (y1 - y), x, y]
|
|
201
|
+
const p0 = [cx, cy - r]
|
|
202
|
+
const p1 = [cx + r, cy]
|
|
203
|
+
const p2 = [cx, cy + r]
|
|
204
|
+
const p3 = [cx - r, cy]
|
|
205
|
+
return [['M', ...p0], q(cx + k, cy - k, ...p1, p0), q(cx + k, cy + k, ...p2, p1), q(cx - k, cy + k, ...p3, p2), q(cx - k, cy - k, ...p0, p3), ['Z']]
|
|
206
|
+
}
|
|
207
|
+
/** Sweat drop 💧: a teardrop with its point up. */
|
|
208
|
+
function drop(cx, cy, r) {
|
|
209
|
+
return spline([[cx, cy - r * 2.2, 1], [cx + r, cy - r * 0.2], [cx + r * 0.9, cy + r * 0.8], [cx, cy + r * 1.3], [cx - r * 0.9, cy + r * 0.8], [cx - r, cy - r * 0.2]].map(([x, y, c]) => [x, y / ASPECT, c]))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const BODY_PARTS = [BODY, EYE, PUPIL]
|
|
213
|
+
/** Eye shut: a thin slit instead of the comma (for blinks). */
|
|
214
|
+
const EYE_SHUT = spline([[53, 52, 1], [59, 51], [65, 53.5, 1], [59, 54.5]], { hole: true })
|
|
215
|
+
/** Tail pivot: where the stem meets the head. */
|
|
216
|
+
const TAIL_PIVOT = [76, Y(42)]
|
|
217
|
+
/** Whole-whale pivot for tilts. */
|
|
218
|
+
const CENTER = [48, Y(52)]
|
|
219
|
+
|
|
220
|
+
/** The whale with its tail swung by `deg` and the whole body shifted / tilted. */
|
|
221
|
+
function whale({ tail = 0, dx = 0, dy = 0, tilt = 0, blink = false } = {}) {
|
|
222
|
+
const body = blink ? [BODY, EYE_SHUT] : BODY_PARTS
|
|
223
|
+
// Transforms take a list of subpaths; TAIL alone is one subpath.
|
|
224
|
+
let parts = [...body, ...rotate([TAIL], TAIL_PIVOT[0], TAIL_PIVOT[1], tail)]
|
|
225
|
+
if (tilt) parts = rotate(parts, CENTER[0], CENTER[1], tilt)
|
|
226
|
+
if (dx || dy) parts = translate(parts, dx, dy)
|
|
227
|
+
return parts
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const bang = (dy = 0) => [pill(93, Y(52) + dy, 6, 12 * ASPECT, 3), circle(93, Y(67) + dy, 3)]
|
|
231
|
+
const cross = (dx = 0) => [pill(93 + dx, Y(58), 15, 5.5, 2.7, 45), pill(93 + dx, Y(58), 15, 5.5, 2.7, -45)]
|
|
232
|
+
/** Three bubbles in front of the nose, `t` in [0, 1) is how far they have risen. */
|
|
233
|
+
function bubbles(t) {
|
|
234
|
+
const rise = 20
|
|
235
|
+
const b = (x, y0, r, phase) => {
|
|
236
|
+
const u = (t + phase) % 1
|
|
237
|
+
return circle(x + Math.sin(u * Math.PI * 2) * 1.2, Y(y0 - u * rise), r * (0.6 + 0.4 * (1 - u)))
|
|
238
|
+
}
|
|
239
|
+
return [b(90, 66, 2.2, 0), b(95.5, 62, 3, 0.4), b(91, 58, 1.8, 0.7)]
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Per-state animation: a list of frames, how fast to play them, and whether
|
|
244
|
+
* to loop (false = play once and hold the last frame).
|
|
245
|
+
*/
|
|
246
|
+
const ANIM = {
|
|
247
|
+
idle: () => ({ fps: 1, loop: false, frames: [whale()] }),
|
|
248
|
+
// Swimming hard: tail wags, body bobs, bubbles stream out of the nose.
|
|
249
|
+
running: () => {
|
|
250
|
+
const n = 12
|
|
251
|
+
return {
|
|
252
|
+
fps: 8,
|
|
253
|
+
loop: true,
|
|
254
|
+
frames: Array.from({ length: n }, (_, i) => {
|
|
255
|
+
const ph = (i / n) * Math.PI * 2
|
|
256
|
+
return [...whale({ tail: Math.sin(ph) * 9, dy: Math.sin(ph * 2) * 0.7 }), ...bubbles(i / n)]
|
|
257
|
+
}),
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
// Waiting for you: the "!" hops, the whale tilts its head and blinks now and then.
|
|
261
|
+
attention: () => {
|
|
262
|
+
const n = 16
|
|
263
|
+
return {
|
|
264
|
+
fps: 8,
|
|
265
|
+
loop: true,
|
|
266
|
+
frames: Array.from({ length: n }, (_, i) => {
|
|
267
|
+
const ph = (i / n) * Math.PI * 2
|
|
268
|
+
const hop = -Math.abs(Math.sin(ph)) * 3
|
|
269
|
+
return [...whale({ tilt: Math.sin(ph) * 2.5, blink: i === 11, tail: Math.sin(ph) * 3 }), ...bang(hop)]
|
|
270
|
+
}),
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
// Something went wrong: the "×" shakes, a sweat drop slides down, then it all holds still.
|
|
274
|
+
error: () => {
|
|
275
|
+
const shake = [0, -3, 3, -2.5, 2.5, -1.5, 1.5, -0.5, 0.5, 0]
|
|
276
|
+
return {
|
|
277
|
+
fps: 10,
|
|
278
|
+
loop: false,
|
|
279
|
+
// The drop sits in the notch behind the dorsal fin and slides down a little.
|
|
280
|
+
frames: shake.map((dx, i) => [...whale({ tilt: -dx * 0.6, tail: -4 }), ...cross(dx), drop(60, Y(9) + Math.min(i, 5) * 1.1, 2.6)]),
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
// Just finished: a little leap with sparkles, then it settles back down.
|
|
284
|
+
done: () => {
|
|
285
|
+
const n = 14
|
|
286
|
+
const lift = [0, -2, -4.5, -6.5, -7.5, -7.5, -6.5, -4.5, -2.5, -1, 0, 0, 0, 0]
|
|
287
|
+
return {
|
|
288
|
+
fps: 10,
|
|
289
|
+
loop: false,
|
|
290
|
+
frames: lift.map((dy, i) => {
|
|
291
|
+
const k = i >= 2 && i <= 10 ? (i - 2) / 8 : -1
|
|
292
|
+
const stars = k < 0 ? [] : [
|
|
293
|
+
sparkle(93, Y(36), 7.5 * Math.sin(k * Math.PI)),
|
|
294
|
+
sparkle(58, Y(12), 5.5 * Math.sin(Math.min(1, k * 1.4) * Math.PI)),
|
|
295
|
+
sparkle(96, Y(66), 4.5 * Math.sin(Math.max(0, k - 0.2) * Math.PI)),
|
|
296
|
+
sparkle(10, Y(26), 4 * Math.sin(Math.max(0, k - 0.1) * Math.PI)),
|
|
297
|
+
]
|
|
298
|
+
return [...whale({ dy, tilt: -dy * 0.5, tail: Math.sin((i / n) * Math.PI * 4) * 8 }), ...stars]
|
|
299
|
+
}),
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export const STATES = Object.keys(ANIM)
|
|
305
|
+
const cache = new Map()
|
|
306
|
+
function animation(state) {
|
|
307
|
+
const key = ANIM[state] ? state : 'idle'
|
|
308
|
+
if (!cache.has(key)) cache.set(key, ANIM[key]())
|
|
309
|
+
return cache.get(key)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @param {'idle'|'running'|'attention'|'error'|'done'} state
|
|
314
|
+
* @returns {Array<Array<any>>} subpaths for one frame (wraps around).
|
|
315
|
+
*/
|
|
316
|
+
export function whalePaths(state, frame = 0) {
|
|
317
|
+
const { frames } = animation(state)
|
|
318
|
+
return frames[((frame % frames.length) + frames.length) % frames.length]
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Animation frames for a state (one frame unless it animates). */
|
|
322
|
+
export function whaleFrames(state) {
|
|
323
|
+
return animation(state).frames
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Everything a helper needs to draw every state, written once to icon.json. */
|
|
327
|
+
export function iconSpec() {
|
|
328
|
+
const round = v => (typeof v === 'number' ? Number(v.toFixed(2)) : v)
|
|
329
|
+
return {
|
|
330
|
+
box: BOX,
|
|
331
|
+
bounds: BOUNDS,
|
|
332
|
+
rgb: STATE_RGB,
|
|
333
|
+
frames: Object.fromEntries(STATES.map(s => [s, whaleFrames(s).map(frame => frame.map(sub => sub.map(cmd => cmd.map(round))))])),
|
|
334
|
+
anim: Object.fromEntries(STATES.map(s => [s, { fps: animation(s).fps, loop: animation(s).loop }])),
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ---- exporters --------------------------------------------------------------
|
|
339
|
+
|
|
340
|
+
const num = v => Number(v.toFixed(2))
|
|
341
|
+
|
|
342
|
+
export function toSvgPath(paths) {
|
|
343
|
+
return paths.map(sub => sub.map(cmd => `${cmd[0]}${cmd.slice(1).map(num).join(' ')}`).join(' ')).join(' ')
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Standalone SVG of one state, cropped to BOUNDS. `fill` defaults to the
|
|
348
|
+
* state tint; `background` adds a rounded tile the whale is centred on
|
|
349
|
+
* (used for the plugin icon), with `padding` box units around it.
|
|
350
|
+
*/
|
|
351
|
+
export function whaleSvg({ state = 'idle', frame = 0, size = 64, fill, background, padding = 0 } = {}) {
|
|
352
|
+
const [r, g, b] = STATE_RGB[state] ?? STATE_RGB.idle
|
|
353
|
+
const color = fill ?? `rgb(${r},${g},${b})`
|
|
354
|
+
const d = toSvgPath(whalePaths(state, frame))
|
|
355
|
+
if (!background) {
|
|
356
|
+
const height = Math.round(size * (BOUNDS.h / BOUNDS.w))
|
|
357
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${BOUNDS.x} ${BOUNDS.y} ${BOUNDS.w} ${BOUNDS.h}" width="${size}" height="${height}">`
|
|
358
|
+
+ `<path d="${d}" fill="${color}" fill-rule="nonzero"/></svg>`
|
|
359
|
+
}
|
|
360
|
+
const tile = BOX
|
|
361
|
+
const inner = tile - padding * 2
|
|
362
|
+
const scale = Math.min(inner / BOUNDS.w, inner / BOUNDS.h)
|
|
363
|
+
const tx = (tile - BOUNDS.w * scale) / 2 - BOUNDS.x * scale
|
|
364
|
+
const ty = (tile - BOUNDS.h * scale) / 2 - BOUNDS.y * scale
|
|
365
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${tile} ${tile}" width="${size}" height="${size}">`
|
|
366
|
+
+ `<rect width="${tile}" height="${tile}" rx="22" fill="${background}"/>`
|
|
367
|
+
+ `<path d="${d}" fill="${color}" fill-rule="nonzero" transform="translate(${tx.toFixed(2)} ${ty.toFixed(2)}) scale(${scale.toFixed(4)})"/></svg>`
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** Flatten cubics into closed polygons (for the Linux software rasterizer). */
|
|
371
|
+
export function flatten(paths, steps = 10) {
|
|
372
|
+
const polys = []
|
|
373
|
+
for (const sub of paths) {
|
|
374
|
+
let poly = []
|
|
375
|
+
let cur = [0, 0]
|
|
376
|
+
for (const cmd of sub) {
|
|
377
|
+
if (cmd[0] === 'M') { cur = [cmd[1], cmd[2]]; poly = [cur] }
|
|
378
|
+
else if (cmd[0] === 'L') { cur = [cmd[1], cmd[2]]; poly.push(cur) }
|
|
379
|
+
else if (cmd[0] === 'C') {
|
|
380
|
+
const [x0, y0] = cur
|
|
381
|
+
const [, x1, y1, x2, y2, x3, y3] = cmd
|
|
382
|
+
for (let i = 1; i <= steps; i += 1) {
|
|
383
|
+
const t = i / steps
|
|
384
|
+
const u = 1 - t
|
|
385
|
+
poly.push([
|
|
386
|
+
u * u * u * x0 + 3 * u * u * t * x1 + 3 * u * t * t * x2 + t * t * t * x3,
|
|
387
|
+
u * u * u * y0 + 3 * u * u * t * y1 + 3 * u * t * t * y2 + t * t * t * y3,
|
|
388
|
+
])
|
|
389
|
+
}
|
|
390
|
+
cur = [x3, y3]
|
|
391
|
+
} else if (cmd[0] === 'Z') { if (poly.length > 2) polys.push(poly); poly = [] }
|
|
392
|
+
}
|
|
393
|
+
if (poly.length > 2) polys.push(poly)
|
|
394
|
+
}
|
|
395
|
+
return polys
|
|
396
|
+
}
|