@yusho/server 0.0.0-stage → 0.1.17

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 (115) hide show
  1. package/README.md +135 -2
  2. package/app/appguide.mjs +33 -0
  3. package/app/asr.mjs +82 -0
  4. package/app/assets/agents/claude-192.webp +0 -0
  5. package/app/assets/agents/claude-96.webp +0 -0
  6. package/app/assets/agents/codex-192.webp +0 -0
  7. package/app/assets/agents/codex-96.webp +0 -0
  8. package/app/assets/agents/default-192.webp +0 -0
  9. package/app/assets/agents/default-96.webp +0 -0
  10. package/app/assets/agents/dsh-192.webp +0 -0
  11. package/app/assets/agents/dsh-96.webp +0 -0
  12. package/app/assets/brand/logo.webp +0 -0
  13. package/app/assets/lib/THIRD-PARTY.txt +1 -0
  14. package/app/assets/lib/jsqr.js +10102 -0
  15. package/app/assets/linux/alpine-arm64.tar.gz +0 -0
  16. package/app/assets/linux/alpine-x64.tar.gz +0 -0
  17. package/app/assets/live/claude.livliv +0 -0
  18. package/app/assets/live/dafeiyu.livliv +0 -0
  19. package/app/assets/live/gpt.livliv +0 -0
  20. package/app/assets/live/sho.livliv +0 -0
  21. package/app/assets/live//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
  22. package/app/assets/livliv/LICENSE +202 -0
  23. package/app/assets/livliv/NOTICE +7 -0
  24. package/app/assets/livliv/player.mjs +15 -0
  25. package/app/assets/looks/claude.webp +0 -0
  26. package/app/assets/looks/dafeiyu.webp +0 -0
  27. package/app/assets/looks/gpt.webp +0 -0
  28. package/app/assets/looks//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
  29. package/app/assets/sho/avatar.webp +0 -0
  30. package/app/assets/sho/done.webp +0 -0
  31. package/app/assets/sho/eat.webp +0 -0
  32. package/app/assets/sho/idle-blink.webp +0 -0
  33. package/app/assets/sho/idle.webp +0 -0
  34. package/app/assets/sho/listen.webp +0 -0
  35. package/app/assets/sho/need.webp +0 -0
  36. package/app/assets/sho/work.webp +0 -0
  37. package/app/companion.mjs +519 -0
  38. package/app/diag.mjs +51 -0
  39. package/app/index.html +497 -0
  40. package/app/judge.mjs +103 -0
  41. package/app/lanxfer.mjs +157 -0
  42. package/app/launcher.mjs +2715 -0
  43. package/app/linux.mjs +97 -0
  44. package/app/livliv-pack.mjs +12 -0
  45. package/app/memory.mjs +53 -0
  46. package/app/net.mjs +717 -0
  47. package/app/office.mjs +172 -0
  48. package/app/p2plink.mjs +134 -0
  49. package/app/pcupdate.mjs +55 -0
  50. package/app/plans.mjs +126 -0
  51. package/app/plugins.mjs +79 -0
  52. package/app/realtime.mjs +67 -0
  53. package/app/skills/app-icon/SKILL.md +31 -0
  54. package/app/skills/daily-brief/SKILL.md +29 -0
  55. package/app/skills/expense-review/SKILL.md +28 -0
  56. package/app/skills/make-app/SKILL.md +92 -0
  57. package/app/skills/make-skin/SKILL.md +51 -0
  58. package/app/skills/meeting-notes/SKILL.md +23 -0
  59. package/app/skills/reading-notes/SKILL.md +25 -0
  60. package/app/skills/sho-stickers/SKILL.md +34 -0
  61. package/app/skills/sho-stickers/stickers/eat.webp +0 -0
  62. package/app/skills/sho-stickers/stickers/got-it.webp +0 -0
  63. package/app/skills/sho-stickers/stickers/hi.webp +0 -0
  64. package/app/skills/sho-stickers/stickers/huh.webp +0 -0
  65. package/app/skills/sho-stickers/stickers/on-it.webp +0 -0
  66. package/app/skills/sho-stickers/stickers/yay.webp +0 -0
  67. package/app/skills/sho-stickers/stickers.json +12 -0
  68. package/app/skills/study-plan/SKILL.md +30 -0
  69. package/app/skills/trip-planner/SKILL.md +29 -0
  70. package/app/skills/weekly-report/SKILL.md +30 -0
  71. package/app/skills/workout-plan/SKILL.md +30 -0
  72. package/app/skills/writing-polish/SKILL.md +33 -0
  73. package/app/skills.mjs +173 -0
  74. package/app/skins.mjs +40 -0
  75. package/app/social.mjs +1067 -0
  76. package/app/storage.mjs +143 -0
  77. package/app/tts.mjs +68 -0
  78. package/app/ttslocal.mjs +77 -0
  79. package/app/voices.mjs +102 -0
  80. package/backup.mjs +109 -0
  81. package/bin/yusho.mjs +141 -0
  82. package/connector/lib/api.mjs +14 -0
  83. package/connector/lib/autostart.mjs +40 -0
  84. package/connector/lib/client.js +165 -0
  85. package/connector/lib/connector.mjs +468 -0
  86. package/connector/lib/dsh-acp.mjs +129 -0
  87. package/connector/lib/dsh-headless.patch.yml +4 -0
  88. package/connector/lib/dsh-plugin.mjs +80 -0
  89. package/connector/lib/lanfile.mjs +151 -0
  90. package/connector/lib/nostr.mjs +53 -0
  91. package/connector/lib/page.html +121 -0
  92. package/connector/lib/qr.mjs +4 -0
  93. package/connector/lib/service.mjs +54 -0
  94. package/node_modules/@local/shoal-mobile/lib/index.js +485 -0
  95. package/node_modules/@local/shoal-mobile/lib/polyfill.js +82 -0
  96. package/node_modules/@local/shoal-mobile/lib/session-context.js +34 -0
  97. package/node_modules/@local/shoal-mobile/lib/shell.js +60 -0
  98. package/node_modules/@local/shoal-mobile/lib/web-startup.js +33 -0
  99. package/node_modules/@local/shoal-mobile/package.json +24 -0
  100. package/node_modules/@local/yusho-pc/lib/client.js +9100 -0
  101. package/node_modules/@local/yusho-pc/lib/index.js +3 -0
  102. package/node_modules/@local/yusho-pc/package.json +28 -0
  103. package/node_modules/@local/yusho-web-login/brand/icon-192.webp +0 -0
  104. package/node_modules/@local/yusho-web-login/brand/logo-dark.svg +25 -0
  105. package/node_modules/@local/yusho-web-login/brand.mjs +8 -0
  106. package/node_modules/@local/yusho-web-login/dsh-web-login.mjs +974 -0
  107. package/node_modules/@local/yusho-web-login/lib/client.js +607 -0
  108. package/node_modules/@local/yusho-web-login/login-page.mjs +609 -0
  109. package/node_modules/@local/yusho-web-login/login-store.mjs +708 -0
  110. package/node_modules/@local/yusho-web-login/package.json +25 -0
  111. package/node_modules/@local/yusho-web-login/whale-scene.mjs +509 -0
  112. package/node_modules/@local/yusho-web-login/yusho-scene.mjs +227 -0
  113. package/package.json +38 -4
  114. package/pc.patch.yml +83 -0
  115. package/run.mjs +138 -0
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@local/yusho-web-login",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "鱼Sho 官方插件「登录与安全」:网页版放到公网时的访问密码、登录页、IP 封禁和访问记录(服务器版用;电脑上不用开)",
7
+ "license": "MIT",
8
+ "exports": {
9
+ ".": {
10
+ "default": "./dsh-web-login.mjs"
11
+ },
12
+ "./store": {
13
+ "default": "./login-store.mjs"
14
+ },
15
+ "./client": {
16
+ "default": "./lib/client.js"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "dsh": {
21
+ "client": {
22
+ "platform": "web"
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,509 @@
1
+ /**
2
+ * 「鲸灵」— the flagship login animation.
3
+ *
4
+ * A WebGL particle field. Thousands of glowing motes drift in a curl-noise
5
+ * current, then school together into the DeepSeek whale, which swims with a
6
+ * body wave; later they re-form into the page title and (when one is uploaded)
7
+ * the operator's logo. The scene listens to the login form:
8
+ * focus the current shape holds while you type
9
+ * input each keystroke sends a ripple out from the password field
10
+ * error a red shockwave scatters the shape
11
+ * success everything implodes into the card, flashes, and bursts outward
12
+ *
13
+ * The browser half is the `scene` function below. It is serialized with
14
+ * Function.prototype.toString, so it must stay self-contained: no imports, no
15
+ * closures over module scope. Node parses it like any other code, which keeps
16
+ * syntax errors out of the served page.
17
+ *
18
+ * Budget: positions update on the CPU in typed arrays (≈2–4 ms for 9k motes on
19
+ * a laptop); drawing is one points call with additive blending. Falls back to
20
+ * the 2D「深海鲸游」scene without WebGL, renders one still frame under
21
+ * prefers-reduced-motion, pauses while the tab is hidden.
22
+ */
23
+
24
+ import { FISH_LOGO_PATH, FISH_LOGO_VIEWBOX } from './brand.mjs'
25
+
26
+ /* eslint-disable no-var */
27
+ function scene(cfg) {
28
+ var canvas = document.getElementById('bg-gl')
29
+ if (!canvas) return
30
+ var fallback = function () {
31
+ canvas.hidden = true
32
+ if (typeof window.__startDeepsea === 'function') window.__startDeepsea()
33
+ }
34
+ var gl = canvas.getContext('webgl', { alpha: false, antialias: false, premultipliedAlpha: false, powerPreference: 'high-performance' })
35
+ if (!gl) { fallback(); return }
36
+
37
+ var reduce = matchMedia('(prefers-reduced-motion: reduce)').matches
38
+ var css = getComputedStyle(document.body)
39
+ var accentRGB = (css.getPropertyValue('--accent-rgb').trim() || '99,102,241').split(',').map(function (v) { return Number(v) / 255 })
40
+ var DPR = Math.min(window.devicePixelRatio || 1, 2)
41
+ var W = 0, H = 0
42
+
43
+ // ---------------------------------------------------------------- shaders
44
+ function compile(type, src) {
45
+ var s = gl.createShader(type)
46
+ gl.shaderSource(s, src)
47
+ gl.compileShader(s)
48
+ if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s) || 'shader')
49
+ return s
50
+ }
51
+ function program(vs, fs) {
52
+ var p = gl.createProgram()
53
+ gl.attachShader(p, compile(gl.VERTEX_SHADER, vs))
54
+ gl.attachShader(p, compile(gl.FRAGMENT_SHADER, fs))
55
+ gl.linkProgram(p)
56
+ if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p) || 'link')
57
+ return p
58
+ }
59
+
60
+ var bgProg, ptProg
61
+ try {
62
+ bgProg = program(
63
+ 'attribute vec2 p; varying vec2 v; void main(){ v = p * 0.5 + 0.5; gl_Position = vec4(p, 0.0, 1.0); }',
64
+ [
65
+ 'precision mediump float;',
66
+ 'varying vec2 v; uniform float t; uniform vec2 res; uniform vec3 acc; uniform float flash; uniform float alarm;',
67
+ 'float h(vec2 q){ return fract(sin(dot(q, vec2(127.1, 311.7))) * 43758.5453); }',
68
+ 'float n(vec2 q){ vec2 i = floor(q), f = fract(q); f = f * f * (3.0 - 2.0 * f);',
69
+ ' return mix(mix(h(i), h(i + vec2(1, 0)), f.x), mix(h(i + vec2(0, 1)), h(i + vec2(1, 1)), f.x), f.y); }',
70
+ 'void main(){',
71
+ ' vec2 uv = v; float asp = res.x / res.y;',
72
+ ' vec3 deep = vec3(0.006, 0.014, 0.04); vec3 mid = vec3(0.02, 0.07, 0.15);',
73
+ ' vec3 col = mix(deep, mid, smoothstep(0.0, 1.1, uv.y));',
74
+ ' col += acc * 0.06 * smoothstep(0.5, 1.0, uv.y);',
75
+ // God rays: a few slanted bands breathing with low-frequency noise.
76
+ ' float x = (uv.x - 0.5) * asp + (1.0 - uv.y) * 0.32;',
77
+ ' float rays = 0.0;',
78
+ ' for (int k = 0; k < 4; k++) { float fk = float(k);',
79
+ ' float c = (fk - 1.5) * 0.42 + sin(t * 0.05 + fk * 1.9) * 0.08;',
80
+ ' float w = 0.05 + 0.03 * sin(t * 0.07 + fk);',
81
+ ' rays += smoothstep(w, 0.0, abs(x - c)) * (0.5 + 0.5 * n(vec2(fk * 3.1, uv.y * 3.0 - t * 0.12))); }',
82
+ ' col += vec3(0.30, 0.55, 0.85) * rays * 0.085 * smoothstep(0.05, 1.0, uv.y);',
83
+ // Caustic shimmer near the surface.
84
+ ' float c1 = n(vec2(uv.x * asp * 7.0 + t * 0.15, uv.y * 7.0 - t * 0.1));',
85
+ ' float c2 = n(vec2(uv.x * asp * 11.0 - t * 0.12, uv.y * 11.0 + t * 0.08));',
86
+ ' col += vec3(0.2, 0.45, 0.7) * pow(c1 * c2, 3.0) * 0.5 * smoothstep(0.55, 1.0, uv.y);',
87
+ ' col = mix(col, vec3(0.32, 0.03, 0.05), alarm * 0.45 * (1.0 - uv.y * 0.5));',
88
+ ' col += vec3(0.85, 0.92, 1.0) * flash;',
89
+ ' float vig = smoothstep(1.25, 0.25, length((uv - 0.5) * vec2(asp, 1.0)));',
90
+ ' col *= mix(0.55, 1.0, vig);',
91
+ ' col += (h(uv * res + t) - 0.5) / 255.0;',
92
+ ' gl_FragColor = vec4(col, 1.0);',
93
+ '}',
94
+ ].join('\n'))
95
+ ptProg = program(
96
+ [
97
+ 'attribute vec2 pos; attribute float size; attribute vec4 col;',
98
+ 'uniform vec2 res; uniform float dpr; varying vec4 vc;',
99
+ 'void main(){ vc = col; gl_PointSize = size * dpr;',
100
+ ' gl_Position = vec4(pos / res * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0); }',
101
+ ].join('\n'),
102
+ [
103
+ 'precision mediump float; varying vec4 vc;',
104
+ 'void main(){ vec2 d = gl_PointCoord - 0.5; float r = length(d) * 2.0;',
105
+ ' if (r > 1.0) discard;',
106
+ ' float core = exp(-r * r * 14.0); float halo = exp(-r * r * 3.2) * 0.28;',
107
+ ' gl_FragColor = vec4(vc.rgb * (core + halo), vc.a * (core + halo)); }',
108
+ ].join('\n'))
109
+ } catch (e) { fallback(); return }
110
+
111
+ var quad = gl.createBuffer()
112
+ gl.bindBuffer(gl.ARRAY_BUFFER, quad)
113
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW)
114
+ var bgLoc = { p: gl.getAttribLocation(bgProg, 'p'), t: gl.getUniformLocation(bgProg, 't'), res: gl.getUniformLocation(bgProg, 'res'), acc: gl.getUniformLocation(bgProg, 'acc'), flash: gl.getUniformLocation(bgProg, 'flash'), alarm: gl.getUniformLocation(bgProg, 'alarm') }
115
+ var ptLoc = { pos: gl.getAttribLocation(ptProg, 'pos'), size: gl.getAttribLocation(ptProg, 'size'), col: gl.getAttribLocation(ptProg, 'col'), res: gl.getUniformLocation(ptProg, 'res'), dpr: gl.getUniformLocation(ptProg, 'dpr') }
116
+
117
+ // -------------------------------------------------------------- particles
118
+ var N = 0, px, py, vx, vy, seed, edge, tx, ty, slot, buf, vbo = gl.createBuffer()
119
+ var STRIDE = 7 // x, y, size, r, g, b, a
120
+
121
+ function alloc() {
122
+ var area = W * H
123
+ var mobile = Math.min(W, H) < 600
124
+ N = Math.round(Math.max(3200, Math.min(mobile ? 4800 : 9000, area / 115)))
125
+ px = new Float32Array(N); py = new Float32Array(N); vx = new Float32Array(N); vy = new Float32Array(N)
126
+ seed = new Float32Array(N); edge = new Float32Array(N); tx = new Float32Array(N); ty = new Float32Array(N)
127
+ slot = new Uint32Array(N); buf = new Float32Array(N * STRIDE)
128
+ for (var i = 0; i < N; i++) {
129
+ px[i] = Math.random() * W; py[i] = Math.random() * H
130
+ seed[i] = Math.random(); slot[i] = (Math.random() * 1e9) >>> 0
131
+ }
132
+ }
133
+
134
+ // ----------------------------------------------------------------- shapes
135
+ // A shape is a set of sample points normalized to [0,1]² plus its aspect.
136
+ var shapes = []
137
+ function sample(draw, cw, ch, opaqueTest) {
138
+ var c = document.createElement('canvas')
139
+ c.width = cw; c.height = ch
140
+ var g = c.getContext('2d', { willReadFrequently: true })
141
+ draw(g, cw, ch)
142
+ var d
143
+ try { d = g.getImageData(0, 0, cw, ch).data } catch (e) { return null }
144
+ var test = opaqueTest || function (k) { return d[k + 3] > 128 }
145
+ var inside = [], border = []
146
+ var step = 2
147
+ for (var y = step; y < ch - step; y += step) {
148
+ for (var x = step; x < cw - step; x += step) {
149
+ var k = (y * cw + x) * 4
150
+ if (!test(k, d)) continue
151
+ var isEdge = !test(k - step * 4, d) || !test(k + step * 4, d) || !test(k - step * cw * 4, d) || !test(k + step * cw * 4, d)
152
+ ;(isEdge ? border : inside).push(x / cw, y / ch)
153
+ }
154
+ }
155
+ if (inside.length + border.length < 40) return null
156
+ return { inside: new Float32Array(inside), border: new Float32Array(border), aspect: cw / ch }
157
+ }
158
+
159
+ function addWhale() {
160
+ var fish = new Path2D(cfg.fish)
161
+ var cw = 460, ch = Math.round(460 * cfg.fh / cfg.fw)
162
+ var s = sample(function (g) { g.scale(cw / cfg.fw, ch / cfg.fh); g.fill(fish) }, cw, ch)
163
+ if (s) { s.kind = 'whale'; shapes.push(s) }
164
+ }
165
+ function addTitle() {
166
+ var text = String(cfg.title || '').slice(0, 24)
167
+ if (!text) return
168
+ var font = '700 120px -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif'
169
+ var probe = document.createElement('canvas').getContext('2d')
170
+ probe.font = font
171
+ var tw = Math.ceil(probe.measureText(text).width) + 40
172
+ var s = sample(function (g, w, h) { g.font = font; g.textAlign = 'center'; g.textBaseline = 'middle'; g.fillStyle = '#fff'; g.fillText(text, w / 2, h / 2 + 6) }, tw, 160)
173
+ if (s) { s.kind = 'text'; shapes.push(s) }
174
+ }
175
+ function addLogo() {
176
+ if (!cfg.logo) return
177
+ var img = new Image()
178
+ img.onload = function () {
179
+ var ar = img.naturalWidth / Math.max(1, img.naturalHeight) || 1
180
+ var cw = ar >= 1 ? 240 : Math.round(240 * ar), ch = ar >= 1 ? Math.round(240 / ar) : 240
181
+ var s = sample(function (g, w, h) { g.drawImage(img, 0, 0, w, h) }, cw, ch, function (k, d) {
182
+ // Opaque logos: compare against the corner colour instead of alpha.
183
+ if (d[3] > 200 && d[k + 3] > 200) return Math.abs(d[k] - d[0]) + Math.abs(d[k + 1] - d[1]) + Math.abs(d[k + 2] - d[2]) > 90
184
+ return d[k + 3] > 128
185
+ })
186
+ if (s) { s.kind = 'logo'; shapes.push(s) }
187
+ }
188
+ img.src = cfg.logo
189
+ }
190
+
191
+ // Free rectangles around the login card; each shape takes the one where it
192
+ // can be drawn largest.
193
+ function freeRects() {
194
+ var card = document.getElementById('login-form')
195
+ var r = card ? card.getBoundingClientRect() : { left: W / 2, right: W / 2, top: H / 2, bottom: H / 2 }
196
+ var m = Math.min(W, H) * 0.05
197
+ return [
198
+ { x: m, y: m, w: r.left - 2 * m, h: H - 2 * m },
199
+ { x: r.right + m, y: m, w: W - r.right - 2 * m, h: H - 2 * m },
200
+ { x: m, y: m, w: W - 2 * m, h: r.top - 2 * m },
201
+ { x: m, y: r.bottom + m, w: W - 2 * m, h: H - r.bottom - 2 * m },
202
+ ].filter(function (q) { return q.w > 60 && q.h > 40 })
203
+ }
204
+ function placeFor(shape, prefer) {
205
+ var rects = freeRects()
206
+ var best = null
207
+ for (var i = 0; i < rects.length; i++) {
208
+ var q = rects[i]
209
+ var cap = shape.kind === 'text' ? 0.92 : 0.86
210
+ var w = Math.min(q.w * cap, q.h * cap * shape.aspect, shape.kind === 'text' ? W * 0.7 : Math.max(W, H) * 0.42)
211
+ var score = w * (i === prefer ? 1.15 : 1)
212
+ if (!best || score > best.score) best = { score: score, w: w, cx: q.x + q.w / 2, cy: q.y + q.h / 2 }
213
+ }
214
+ if (!best || best.w < 120) {
215
+ // Nowhere roomy enough: swim behind the frosted card.
216
+ var w2 = Math.min(W * 0.9, H * 0.7 * shape.aspect)
217
+ best = { w: w2, cx: W / 2, cy: H * 0.42 }
218
+ }
219
+ return { cx: best.cx, cy: best.cy, w: best.w, h: best.w / shape.aspect }
220
+ }
221
+
222
+ // ------------------------------------------------------------------ state
223
+ var phase = 'flow' // flow | form | burst
224
+ var current = null, place = null, shapeIndex = -1, side = 0
225
+ var phaseAt = 0, holdUntil = 0, focused = false
226
+ var pulses = [] // {x, y, t0, strength, red}
227
+ var flash = 0, alarm = 0, fade = 0
228
+ var mouse = { x: -1e5, y: -1e5, active: false }
229
+
230
+ function assignTargets() {
231
+ var pts = current.inside, edgePts = current.border
232
+ var ni = pts.length / 2, ne = edgePts.length / 2
233
+ for (var i = 0; i < N; i++) {
234
+ // ~30% of motes trace the outline, which gives the shape a crisp rim.
235
+ var onEdge = ne > 0 && (seed[i] < 0.3 || ni === 0)
236
+ var arr = onEdge ? edgePts : pts
237
+ var n = onEdge ? ne : ni
238
+ var j = (slot[i] % n) * 2
239
+ tx[i] = arr[j]; ty[i] = arr[j + 1]
240
+ edge[i] = onEdge ? 1 : 0
241
+ }
242
+ }
243
+ function startForm(now) {
244
+ if (shapes.length === 0) return
245
+ shapeIndex = (shapeIndex + 1) % shapes.length
246
+ current = shapes[shapeIndex]
247
+ side = 1 - side
248
+ place = placeFor(current, current.kind === 'text' ? 2 : side)
249
+ assignTargets()
250
+ phase = 'form'; phaseAt = now
251
+ holdUntil = now + (current.kind === 'text' ? 9000 : 12000)
252
+ }
253
+ function startFlow(now, kick) {
254
+ phase = 'flow'; phaseAt = now
255
+ for (var i = 0; i < N; i++) {
256
+ var a = seed[i] * 6.2832 + now * 0.001
257
+ vx[i] += Math.cos(a) * kick; vy[i] += Math.sin(a) * kick
258
+ }
259
+ }
260
+
261
+ // ------------------------------------------------------------------- noise
262
+ // Cheap divergence-free-ish flow: rotate a smooth angle field.
263
+ function flowAngle(x, y, t) {
264
+ return Math.sin(x * 0.0032 + t * 0.00011) * 1.7 + Math.cos(y * 0.0041 - t * 0.00009) * 1.6 + Math.sin((x + y) * 0.0017 + t * 0.00007) * 1.2
265
+ }
266
+
267
+ // ---------------------------------------------------------------- physics
268
+ function step(now, dt) {
269
+ var k = dt / 16.67
270
+ var forming = phase === 'form'
271
+ var swim = forming && current.kind === 'whale'
272
+ var formAge = now - phaseAt
273
+ var pull = forming ? Math.min(1, formAge / 1600) : 0
274
+ var driftX = 0, driftY = 0
275
+ if (forming) {
276
+ driftX = Math.sin(now * 0.00023) * place.w * 0.05
277
+ driftY = Math.sin(now * 0.00031 + 1.3) * place.h * 0.06
278
+ }
279
+ var mx = mouse.x, my = mouse.y, mr = 170, mr2 = mr * mr
280
+ var npulse = pulses.length
281
+ for (var i = 0; i < N; i++) {
282
+ var x = px[i], y = py[i], ax = 0, ay = 0
283
+ if (forming) {
284
+ var u = tx[i], v = ty[i]
285
+ var gx = place.cx - place.w / 2 + u * place.w + driftX
286
+ var gy = place.cy - place.h / 2 + v * place.h + driftY
287
+ if (swim) {
288
+ // Body wave: the tail (right side of the mark, u→1) swings most.
289
+ var amp = Math.pow(u, 2.2) * place.h * 0.085
290
+ gy += Math.sin(now * 0.0034 - u * 4.2) * amp
291
+ gx += Math.cos(now * 0.0034 - u * 4.2) * amp * 0.25
292
+ } else {
293
+ gy += Math.sin(now * 0.0021 + u * 7.0) * place.h * 0.025
294
+ }
295
+ // Each mote breathes around its slot so the shape shimmers, not freezes.
296
+ gx += Math.sin(now * 0.0017 + seed[i] * 40.0) * 2.2
297
+ gy += Math.cos(now * 0.0013 + seed[i] * 53.0) * 2.2
298
+ var spring = (0.0045 + seed[i] * 0.004) * pull
299
+ ax += (gx - x) * spring
300
+ ay += (gy - y) * spring
301
+ }
302
+ var ang = flowAngle(x, y, now)
303
+ var fs = forming ? 0.006 * (1 - pull * 0.85) : 0.028
304
+ ax += Math.cos(ang) * fs; ay += Math.sin(ang) * fs - (forming ? 0 : 0.004)
305
+ // Pointer vortex: swirl around the cursor, with a little push.
306
+ var dx = x - mx, dy = y - my, d2 = dx * dx + dy * dy
307
+ if (d2 < mr2) {
308
+ var d = Math.sqrt(d2) + 0.001, f = (1 - d / mr)
309
+ ax += (-dy / d * 0.55 + dx / d * 0.22) * f
310
+ ay += (dx / d * 0.55 + dy / d * 0.22) * f
311
+ }
312
+ for (var p = 0; p < npulse; p++) {
313
+ var P = pulses[p]
314
+ var age = (now - P.t0) / 1000
315
+ var radius = age * P.speed
316
+ var ddx = x - P.x, ddy = y - P.y
317
+ var dd = Math.sqrt(ddx * ddx + ddy * ddy) + 0.001
318
+ var band = Math.abs(dd - radius)
319
+ if (band < 70) {
320
+ var s = (1 - band / 70) * P.strength * Math.max(0, 1 - age / P.life)
321
+ ax += ddx / dd * s; ay += ddy / dd * s
322
+ }
323
+ }
324
+ var damp = forming ? 0.9 : 0.955
325
+ var nvx = (vx[i] + ax * k) * Math.pow(damp, k)
326
+ var nvy = (vy[i] + ay * k) * Math.pow(damp, k)
327
+ vx[i] = nvx; vy[i] = nvy
328
+ x += nvx * k; y += nvy * k
329
+ if (!forming) {
330
+ if (x < -30) x = W + 30; else if (x > W + 30) x = -30
331
+ if (y < -30) y = H + 30; else if (y > H + 30) y = -30
332
+ }
333
+ px[i] = x; py[i] = y
334
+ }
335
+ for (var q = pulses.length - 1; q >= 0; q--) if ((now - pulses[q].t0) / 1000 > pulses[q].life) pulses.splice(q, 1)
336
+ }
337
+
338
+ function writeBuffer(now) {
339
+ var ar = accentRGB[0], ag = accentRGB[1], ab = accentRGB[2]
340
+ var forming = phase === 'form'
341
+ var pull = forming ? Math.min(1, (now - phaseAt) / 1600) : 0
342
+ var red = alarm, white = flash
343
+ for (var i = 0; i < N; i++) {
344
+ var s = seed[i]
345
+ var sp = Math.min(1, Math.sqrt(vx[i] * vx[i] + vy[i] * vy[i]) * 0.35)
346
+ // Palette: accent → cyan → white, by seed; speed brightens.
347
+ var mixC = s < 0.55 ? s / 0.55 : 1
348
+ var r = ar + (0.35 - ar) * mixC * 0.7, g = ag + (0.85 - ag) * mixC * 0.7, b = ab + (1.0 - ab) * mixC * 0.7
349
+ if (s > 0.9) { r = 0.9; g = 0.97; b = 1.0 }
350
+ var tw = 0.65 + 0.35 * Math.sin(now * 0.003 + s * 90.0)
351
+ var lum = (0.48 + sp * 0.6) * tw
352
+ if (forming) lum += (edge[i] > 0 ? 0.75 : 0.18) * pull
353
+ r += (1.0 - r) * red * 0.2; g *= 1 - red * 0.75; b *= 1 - red * 0.8
354
+ r += (1.0 - r) * white; g += (1.0 - g) * white; b += (1.0 - b) * white
355
+ var size = (s > 0.93 ? 7.5 : 3.2 + s * 3.4) * (forming && edge[i] > 0 ? 1.2 : 1)
356
+ var o = i * STRIDE
357
+ buf[o] = px[i]; buf[o + 1] = py[i]; buf[o + 2] = size
358
+ buf[o + 3] = r * lum; buf[o + 4] = g * lum; buf[o + 5] = b * lum; buf[o + 6] = fade
359
+ }
360
+ }
361
+
362
+ function draw(now) {
363
+ gl.viewport(0, 0, canvas.width, canvas.height)
364
+ gl.disable(gl.BLEND)
365
+ gl.useProgram(bgProg)
366
+ gl.bindBuffer(gl.ARRAY_BUFFER, quad)
367
+ gl.enableVertexAttribArray(bgLoc.p)
368
+ gl.vertexAttribPointer(bgLoc.p, 2, gl.FLOAT, false, 0, 0)
369
+ gl.uniform1f(bgLoc.t, now / 1000)
370
+ gl.uniform2f(bgLoc.res, canvas.width, canvas.height)
371
+ gl.uniform3f(bgLoc.acc, accentRGB[0], accentRGB[1], accentRGB[2])
372
+ gl.uniform1f(bgLoc.flash, flash * 0.35)
373
+ gl.uniform1f(bgLoc.alarm, alarm)
374
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)
375
+ gl.disableVertexAttribArray(bgLoc.p)
376
+
377
+ writeBuffer(now)
378
+ gl.enable(gl.BLEND)
379
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE)
380
+ gl.useProgram(ptProg)
381
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo)
382
+ gl.bufferData(gl.ARRAY_BUFFER, buf, gl.DYNAMIC_DRAW)
383
+ var B = 4 * STRIDE
384
+ gl.enableVertexAttribArray(ptLoc.pos); gl.vertexAttribPointer(ptLoc.pos, 2, gl.FLOAT, false, B, 0)
385
+ gl.enableVertexAttribArray(ptLoc.size); gl.vertexAttribPointer(ptLoc.size, 1, gl.FLOAT, false, B, 8)
386
+ gl.enableVertexAttribArray(ptLoc.col); gl.vertexAttribPointer(ptLoc.col, 4, gl.FLOAT, false, B, 12)
387
+ gl.uniform2f(ptLoc.res, W, H)
388
+ gl.uniform1f(ptLoc.dpr, DPR)
389
+ gl.drawArrays(gl.POINTS, 0, N)
390
+ }
391
+
392
+ // ------------------------------------------------------------- lifecycle
393
+ // The scene runs on its own clock in fixed sub-steps, so a slow device
394
+ // (or a software renderer) sees the same motion at a lower frame rate
395
+ // instead of everything moving in slow motion.
396
+ var clock = 0, last = 0, raf = 0, stats = { frames: 0, stepMs: 0 }
397
+ function advance(dt) {
398
+ clock += dt
399
+ fade = Math.min(1, clock / 1400)
400
+ flash *= Math.pow(0.9, dt / 16.67)
401
+ alarm *= Math.pow(0.955, dt / 16.67)
402
+ if (phase === 'flow' && clock > 1100 && clock - phaseAt > (shapeIndex < 0 ? 0 : 6500)) startForm(clock)
403
+ else if (phase === 'form' && !focused && clock > holdUntil) startFlow(clock, 1.6)
404
+ step(clock, dt)
405
+ }
406
+ function tick(now) {
407
+ var raw = last === 0 ? 16.67 : Math.min(100, now - last)
408
+ last = now
409
+ var n = Math.min(4, Math.max(1, Math.round(raw / 16.67)))
410
+ var a = performance.now()
411
+ for (var i = 0; i < n; i++) advance(raw / n)
412
+ stats.stepMs = stats.stepMs * 0.95 + (performance.now() - a) / n * 0.05
413
+ stats.frames++
414
+ draw(clock)
415
+ raf = requestAnimationFrame(tick)
416
+ }
417
+
418
+ function resize() {
419
+ W = window.innerWidth; H = window.innerHeight
420
+ canvas.width = Math.round(W * DPR); canvas.height = Math.round(H * DPR)
421
+ canvas.style.width = W + 'px'; canvas.style.height = H + 'px'
422
+ if (!px) alloc()
423
+ if (current) place = placeFor(current, current.kind === 'text' ? 2 : side)
424
+ }
425
+
426
+ // ------------------------------------------------------------------ events
427
+ addEventListener('pointermove', function (e) { mouse.x = e.clientX; mouse.y = e.clientY }, { passive: true })
428
+ document.addEventListener('pointerleave', function () { mouse.x = mouse.y = -1e5 })
429
+ var fieldCenter = function () {
430
+ var el = document.getElementById('password')
431
+ var r = el ? el.getBoundingClientRect() : { left: W / 2, width: 0, top: H / 2, height: 0 }
432
+ return { x: r.left + r.width * 0.5, y: r.top + r.height * 0.5 }
433
+ }
434
+ addEventListener('dsh-login', function (e) {
435
+ var now = clock
436
+ var kind = e.detail && e.detail.type
437
+ if (kind === 'focus') { focused = true; if (phase === 'form') holdUntil = Math.max(holdUntil, now + 4000) }
438
+ else if (kind === 'blur') { focused = false; holdUntil = Math.max(holdUntil, now + 3000) }
439
+ else if (kind === 'input') {
440
+ var c = fieldCenter()
441
+ pulses.push({ x: c.x + (Math.random() - 0.5) * 40, y: c.y, t0: now, speed: 520, strength: 0.6, life: 1.4 })
442
+ if (pulses.length > 6) pulses.shift()
443
+ } else if (kind === 'error') {
444
+ var c2 = fieldCenter()
445
+ alarm = 1
446
+ pulses.push({ x: c2.x, y: c2.y, t0: now, speed: 900, strength: 3.2, life: 1.6 })
447
+ if (phase === 'form') { holdUntil = now + 2600 }
448
+ for (var i = 0; i < N; i++) { vx[i] += (Math.random() - 0.5) * 6; vy[i] += (Math.random() - 0.5) * 6 }
449
+ } else if (kind === 'success') {
450
+ // Implode into the card, flash, then burst outward.
451
+ var card = document.getElementById('login-form').getBoundingClientRect()
452
+ current = { kind: 'core', inside: new Float32Array([0.5, 0.5]), border: new Float32Array(0), aspect: 1 }
453
+ place = { cx: card.left + card.width / 2, cy: card.top + card.height / 2, w: 6, h: 6 }
454
+ assignTargets(); phase = 'form'; phaseAt = now - 1200; holdUntil = now + 1e6
455
+ setTimeout(function () {
456
+ flash = 1
457
+ var n2 = clock
458
+ pulses.push({ x: place.cx, y: place.cy, t0: n2, speed: 1400, strength: 9, life: 1.2 })
459
+ phase = 'burst'
460
+ for (var j = 0; j < N; j++) { var aa = seed[j] * 6.2832 * 7; var sp = 8 + seed[j] * 18; vx[j] = Math.cos(aa) * sp; vy[j] = Math.sin(aa) * sp }
461
+ }, 380)
462
+ }
463
+ })
464
+
465
+ canvas.addEventListener('webglcontextlost', function (e) { e.preventDefault(); cancelAnimationFrame(raf); fallback() })
466
+
467
+ addWhale(); addTitle(); addLogo()
468
+ resize()
469
+ var resizeTimer
470
+ addEventListener('resize', function () { clearTimeout(resizeTimer); resizeTimer = setTimeout(resize, 120) })
471
+
472
+ // Test/preview hooks (harmless in production: no state leaves the page).
473
+ window.__whale = {
474
+ stats: stats,
475
+ form: function (kind) { for (var i = 0; i < shapes.length; i++) if (shapes[i].kind === kind) { shapeIndex = i - 1; startForm(clock); return true } return false },
476
+ // Fast-forward the simulation (inspection / screenshots).
477
+ advance: function (ms) { for (var t = 0; t < ms; t += 16.67) advance(16.67); draw(clock); return Math.round(clock) },
478
+ phase: function () { return phase + ':' + (current ? current.kind : '-') },
479
+ }
480
+
481
+ if (reduce) {
482
+ // One composed still: the whale, fully formed.
483
+ if (shapes.length) { shapeIndex = -1; startForm(0) }
484
+ holdUntil = 1e12
485
+ for (var it = 0; it < 240; it++) advance(16.67)
486
+ fade = 1
487
+ draw(clock)
488
+ return
489
+ }
490
+ document.addEventListener('visibilitychange', function () {
491
+ if (document.hidden) { cancelAnimationFrame(raf); raf = 0 } else if (raf === 0) { last = 0; raf = requestAnimationFrame(tick) }
492
+ })
493
+ raf = requestAnimationFrame(tick)
494
+ }
495
+ /* eslint-enable no-var */
496
+
497
+ /**
498
+ * The inline script for the whale scene.
499
+ * @param {{title: string, logo?: string}} options - page-specific inputs.
500
+ * @returns {string} script source (without the <script> tag).
501
+ */
502
+ export function whaleScript({ title, logo }) {
503
+ const cfg = { fish: FISH_LOGO_PATH, fw: FISH_LOGO_VIEWBOX.width, fh: FISH_LOGO_VIEWBOX.height, title, logo: logo ?? null }
504
+ // JSON in a script element: escape '<' so a title can never close the tag.
505
+ const json = JSON.stringify(cfg).replace(/</gu, '\\u003c').replace(/\u2028/gu, '\\u2028').replace(/\u2029/gu, '\\u2029')
506
+ // Leading ';' — this is concatenated after another IIFE, and without it
507
+ // `})()\n(function…)` parses as a call of the previous expression's result.
508
+ return `;(${scene.toString()})(${json});`
509
+ }