@floless/app 0.156.0 → 0.157.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-actions.mjs +21 -5
- package/dist/floless-server.cjs +70965 -43326
- package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
- package/dist/schemas/steel.model.v2.schema.json +25 -1
- package/dist/skills/floless-app-actions/SKILL.md +79 -17
- package/dist/skills/floless-app-knowledge/SKILL.md +21 -2
- package/dist/skills/floless-app-new-workflow/SKILL.md +23 -7
- package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
- package/dist/skills/floless-app-report-issue/SKILL.md +3 -3
- package/dist/skills/floless-app-rfi/SKILL.md +40 -6
- package/dist/skills/floless-app-routines/SKILL.md +9 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +1 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
- package/dist/skills/floless-app-workflows/SKILL.md +46 -10
- package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
- package/dist/web/agent-steps.js +864 -47
- package/dist/web/agents.js +28 -8
- package/dist/web/app.css +478 -3
- package/dist/web/app.js +110 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +685 -170
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +245 -1
- package/dist/web/chat.js +2466 -78
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +820 -3
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/connections.js +1 -0
- package/dist/web/drawing-check-editor.html +33 -5
- package/dist/web/drawing-check-editor.js +538 -22
- package/dist/web/drawing-check-overlay.js +13 -0
- package/dist/web/flo-avatar.js +28 -3
- package/dist/web/guide.js +7 -2
- package/dist/web/index.html +119 -6
- package/dist/web/instructor.js +3 -3
- package/dist/web/model-view-query.js +12 -2
- package/dist/web/pages.js +865 -34
- package/dist/web/panels.js +5 -2
- package/dist/web/parser-setup-recovery.js +12 -4
- package/dist/web/project-access.js +549 -0
- package/dist/web/report-files.js +50 -0
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +642 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/terminal-requests.js +59 -10
- package/dist/web/tool-updates.js +1 -0
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +1667 -63
- package/launch.mjs +9 -7
- package/package.json +3 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
// The chat's start screens (choose Claude or Codex, open a project, opening a conversation, ready when you are) show
|
|
2
|
+
// Flo building FloLess's three parts in the background, one after another, in each part's colour: it stacks a
|
|
3
|
+
// Workspace (the project's sheets), wires a Workflow (steps joined, a light running through them) and becomes an
|
|
4
|
+
// Agent (the hat goes on and it brings a question). Decorative: the card's own words say what to do, so the scene is
|
|
5
|
+
// aria-hidden and decides nothing. Colours are the theme's own tokens (chat.css --scene-*), read off the element, so
|
|
6
|
+
// both themes stay on the baseline. Under prefers-reduced-motion it is one still frame with all three parts built.
|
|
7
|
+
// It plays three cycles and then settles on that same still frame, so nothing moves beside the chat for good, and
|
|
8
|
+
// the first key press or click anywhere settles it at once: someone starting to work has stopped it (WCAG 2.2.2).
|
|
9
|
+
// Each caller names its screen; a different screen plays it again, a repaint of the same one does not.
|
|
10
|
+
//
|
|
11
|
+
// Behind the card the conversation area holds a hidden flow: a few dozen motes on a slow current, most in a neutral
|
|
12
|
+
// tone and a few in the three parts' colours. Nothing of it shows until the pointer is over the area; then, in a soft
|
|
13
|
+
// circle round the pointer, the motes appear, drifting with short trails as the current curls round it, like a hand
|
|
14
|
+
// in water. It moves only while the pointer is there (motion the person starts), and under reduced motion the motes
|
|
15
|
+
// it reveals stand still. The card's own area is left clear, so its words never sit on the flow.
|
|
16
|
+
//
|
|
17
|
+
// One requestAnimationFrame loop serves every scene, drawing at most 30 times a second, only while a scene is in the
|
|
18
|
+
// document, laid out and the window is visible; a scene whose node left the document (a feed repaint) is dropped.
|
|
19
|
+
(function () {
|
|
20
|
+
const FRAME_MS = 1000 / 30;
|
|
21
|
+
const PHASE_S = 3.6; // each part's turn
|
|
22
|
+
const CYCLE_S = PHASE_S * 3;
|
|
23
|
+
const HEIGHT = 84; // canvas CSS height
|
|
24
|
+
// It settles at the third cycle's still-frame moment (the Agent's turn, 85% through), so it ends on what it shows.
|
|
25
|
+
const STILL_U = 0.85;
|
|
26
|
+
const SETTLE_S = CYCLE_S * 2 + PHASE_S * (2 + STILL_U);
|
|
27
|
+
const EDGE = 20; // Flo's ring never goes nearer the canvas edge than this
|
|
28
|
+
// The flow behind the card: area per mote, most motes, drift speed (px/s), how far round the pointer it shows,
|
|
29
|
+
// how fast trails fade (per second), a mote's opacity right beside the pointer, the share of motes in a part's
|
|
30
|
+
// colour, and the margin kept clear round the card.
|
|
31
|
+
const FLOW = { area: 900, max: 220, speed: 14, reach: 90, fade: 2.6, lit: 0.9, coloured: 0.3, clear: 8 };
|
|
32
|
+
const COLOURED = ['ws', 'wf', 'ag'];
|
|
33
|
+
const PARTS = [
|
|
34
|
+
{ key: 'ws', label: 'Workspaces', note: 'hold the project' },
|
|
35
|
+
{ key: 'wf', label: 'Workflows', note: 'repeat the work' },
|
|
36
|
+
{ key: 'ag', label: 'Agents', note: 'look after it' },
|
|
37
|
+
];
|
|
38
|
+
const scenes = new Set();
|
|
39
|
+
const motion = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : null;
|
|
40
|
+
const reduced = () => Boolean(motion && motion.matches);
|
|
41
|
+
// The scene's clock starts when its screen does, so a new screen always opens on Workspaces' turn.
|
|
42
|
+
let origin = performance.now();
|
|
43
|
+
let frame = 0, last = -Infinity, played = 0, settled = false, screen = null;
|
|
44
|
+
|
|
45
|
+
const clamp = (v, a = 0, b = 1) => Math.max(a, Math.min(b, v));
|
|
46
|
+
const easeOut = (u) => 1 - Math.pow(1 - clamp(u), 3);
|
|
47
|
+
const easeInOut = (u) => { u = clamp(u); return u < 0.5 ? 4 * u * u * u : 1 - Math.pow(-2 * u + 2, 3) / 2; };
|
|
48
|
+
const bump = (u) => Math.sin(Math.PI * clamp(u));
|
|
49
|
+
|
|
50
|
+
function readColors(el) {
|
|
51
|
+
const cs = getComputedStyle(el);
|
|
52
|
+
const v = (n) => cs.getPropertyValue(n).trim();
|
|
53
|
+
return {
|
|
54
|
+
ws: v('--scene-ws'), wf: v('--scene-wf'), ag: v('--scene-ag'),
|
|
55
|
+
ground: v('--scene-ground'), soft: v('--scene-soft'), surface: v('--scene-surface'),
|
|
56
|
+
flo: { line: v('--scene-flo'), fill: 'transparent', hat: v('--scene-hat'), hatLine: v('--scene-hat-line'), pulse: v('--scene-flo') },
|
|
57
|
+
font: `700 10px ${v('--ui') || 'sans-serif'}`,
|
|
58
|
+
label: `600 10px ${v('--ui') || 'sans-serif'}`,
|
|
59
|
+
dot: v('--scene-dot'),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Where things are, from the time alone, so a repainted scene picks up exactly where the old one was.
|
|
64
|
+
function pose(t, W) {
|
|
65
|
+
const cyc = ((t % CYCLE_S) + CYCLE_S) % CYCLE_S;
|
|
66
|
+
const phase = Math.floor(cyc / PHASE_S), u = (cyc - phase * PHASE_S) / PHASE_S;
|
|
67
|
+
const slots = [W / 6, W / 2, (5 * W) / 6];
|
|
68
|
+
// Flo stands left of what it builds, except as the Agent, where it is the thing built.
|
|
69
|
+
const stand = (i) => (i === 2 ? slots[2] : Math.max(slots[i] - 26, EDGE));
|
|
70
|
+
const from = stand((phase + 2) % 3), to = stand(phase);
|
|
71
|
+
const hop = easeInOut(u / 0.18);
|
|
72
|
+
const floX = from + (to - from) * hop;
|
|
73
|
+
const lift = bump(u / 0.18) * (phase === 0 ? 22 : 14);
|
|
74
|
+
// Build progress per part: 1 once its turn is over, 0 before it; everything fades out at the cycle's end.
|
|
75
|
+
const build = [0, 1, 2].map((i) => (i < phase ? 1 : i > phase ? 0 : clamp((u - 0.2) / 0.62)));
|
|
76
|
+
const fade = phase === 2 ? 1 - clamp((u - 0.9) / 0.1) : phase === 0 && u < 0.2 ? 0 : 1;
|
|
77
|
+
return { phase, u, slots, floX, lift, hopping: u < 0.18, build, fade, t };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function stillPose(W) {
|
|
81
|
+
const p = pose(PHASE_S * (2 + STILL_U), W);
|
|
82
|
+
p.build = [1, 1, 1]; p.fade = 1; p.hopping = false; p.lift = 0;
|
|
83
|
+
return p;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function roundRect(c, x, y, w, h, r) { c.beginPath(); c.roundRect(x, y, w, h, r); }
|
|
87
|
+
|
|
88
|
+
// Workspace: three of the project's sheets drop and stack, a fold on the top one.
|
|
89
|
+
function drawWorkspace(c, x, ground, b, k) {
|
|
90
|
+
const sheets = [[-11, 0], [3, 0], [-4, 1]];
|
|
91
|
+
sheets.forEach(([dx, row], i) => {
|
|
92
|
+
const s = clamp(b * 3 - i);
|
|
93
|
+
if (!s) return;
|
|
94
|
+
const y = ground - 11 - row * 12 - (1 - easeOut(s)) * 30;
|
|
95
|
+
c.globalAlpha *= s;
|
|
96
|
+
roundRect(c, x + dx, y, 13, 11, 2);
|
|
97
|
+
c.fillStyle = k.soft; c.fill(); c.lineWidth = 1.6; c.strokeStyle = k.ws; c.stroke();
|
|
98
|
+
c.beginPath(); c.moveTo(x + dx + 3, y + 4); c.lineTo(x + dx + 10, y + 4); c.moveTo(x + dx + 3, y + 7); c.lineTo(x + dx + 8, y + 7);
|
|
99
|
+
c.lineWidth = 1; c.stroke();
|
|
100
|
+
c.globalAlpha /= s;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Workflow: three steps appear, joined in order; once joined, a light runs from the first to the last, again.
|
|
105
|
+
function drawWorkflow(c, x, ground, b, t, k) {
|
|
106
|
+
const nodes = [[x - 14, ground - 26], [x + 2, ground - 10], [x + 16, ground - 28]];
|
|
107
|
+
const link = clamp((b - 0.35) / 0.45);
|
|
108
|
+
c.lineWidth = 1.6; c.strokeStyle = k.wf;
|
|
109
|
+
for (let i = 0; i < 2; i++) {
|
|
110
|
+
const seg = clamp(link * 2 - i);
|
|
111
|
+
if (!seg) continue;
|
|
112
|
+
const [ax, ay] = nodes[i], [bx, by] = nodes[i + 1];
|
|
113
|
+
c.beginPath(); c.moveTo(ax, ay); c.lineTo(ax + (bx - ax) * seg, ay + (by - ay) * seg); c.stroke();
|
|
114
|
+
}
|
|
115
|
+
nodes.forEach(([nx, ny], i) => {
|
|
116
|
+
const s = easeOut(clamp(b * 3.2 - i * 0.6));
|
|
117
|
+
if (!s) return;
|
|
118
|
+
c.beginPath(); c.arc(nx, ny, 4.5 * s, 0, 2 * Math.PI);
|
|
119
|
+
c.fillStyle = k.surface; c.fill(); c.lineWidth = 1.8; c.strokeStyle = k.wf; c.stroke();
|
|
120
|
+
});
|
|
121
|
+
if (b >= 1) {
|
|
122
|
+
const run = (t % 1.4) / 1.4, at = run * 2, i = Math.min(1, Math.floor(at)), f = at - i;
|
|
123
|
+
const [ax, ay] = nodes[i], [bx, by] = nodes[i + 1];
|
|
124
|
+
c.beginPath(); c.arc(ax + (bx - ax) * f, ay + (by - ay) * f, 2.2, 0, 2 * Math.PI);
|
|
125
|
+
c.fillStyle = k.wf; c.fill();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Agent: a halo in the Agent colour closes round Flo, and a question pops up beside it (agents bring you the questions).
|
|
130
|
+
function drawAgentHalo(c, x, cy, r, b, t, k) {
|
|
131
|
+
const halo = clamp(b / 0.55);
|
|
132
|
+
if (halo) {
|
|
133
|
+
c.beginPath(); c.arc(x, cy, r + 5, -Math.PI / 2, -Math.PI / 2 + 2 * Math.PI * easeOut(halo));
|
|
134
|
+
c.lineWidth = 1.8; c.strokeStyle = k.ag; c.stroke();
|
|
135
|
+
}
|
|
136
|
+
const q = clamp((b - 0.6) / 0.3);
|
|
137
|
+
if (q) {
|
|
138
|
+
const bob = Math.sin(t * 2.4) * 1.2, s = easeOut(q), bx = x + r + 12, by = cy - r - 4 + bob;
|
|
139
|
+
c.save(); c.translate(bx, by); c.scale(s, s);
|
|
140
|
+
roundRect(c, -8, -8, 16, 14, 4); c.fillStyle = k.surface; c.fill(); c.lineWidth = 1.6; c.strokeStyle = k.ag; c.stroke();
|
|
141
|
+
c.beginPath(); c.moveTo(-4, 6); c.lineTo(-6, 10); c.lineTo(0, 6); c.fillStyle = k.ag; c.fill();
|
|
142
|
+
c.fillStyle = k.ag; c.font = k.font;
|
|
143
|
+
c.textAlign = 'center'; c.textBaseline = 'middle'; c.fillText('?', 0, -1);
|
|
144
|
+
c.restore();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// A stable pseudo-random number per (i, j), so the frame is the same on every repaint.
|
|
149
|
+
const hash = (i, j) => { const v = Math.sin(i * 12.9898 + j * 78.233) * 43758.5453; return v - Math.floor(v); };
|
|
150
|
+
|
|
151
|
+
// The motes, kept per screen so a repaint of the same screen carries on with the same flow.
|
|
152
|
+
let flow = null;
|
|
153
|
+
function motes(W, H) {
|
|
154
|
+
if (flow && flow.screen === screen && flow.W === W && flow.H === H) return flow.motes;
|
|
155
|
+
const n = Math.min(FLOW.max, Math.round((W * H) / FLOW.area)), list = [];
|
|
156
|
+
for (let i = 0; i < n; i++) {
|
|
157
|
+
const tone = hash(i, 3) < FLOW.coloured ? COLOURED[i % 3] : 'dot';
|
|
158
|
+
list.push({ x: hash(i, 1) * W, y: hash(i, 2) * H, r: 0.8 + 0.7 * hash(i, 4), tone, phase: hash(i, 5) * 6.28 });
|
|
159
|
+
}
|
|
160
|
+
flow = { screen, W, H, motes: list };
|
|
161
|
+
return list;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// The current at (x, y): a slow drift up and to the right, bent by two gentle waves that change over time.
|
|
165
|
+
function current(x, y, t) {
|
|
166
|
+
const a = -0.5 + 0.9 * Math.sin(x * 0.011 + t * 0.13) + 0.7 * Math.cos(y * 0.014 - t * 0.09);
|
|
167
|
+
return [Math.cos(a), Math.sin(a)];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// How near (x, y) is to the pointer: 1 under it, 0 out of its reach.
|
|
171
|
+
const near = (s, x, y) => (s.pointer ? clamp(1 - Math.hypot(x - s.pointer.x, y - s.pointer.y) / FLOW.reach) : 0);
|
|
172
|
+
|
|
173
|
+
function drawBackdrop(s, t, still, k) {
|
|
174
|
+
const { bw: W, bh: H, bctx: c } = s;
|
|
175
|
+
if (!W || !H) return;
|
|
176
|
+
const list = motes(W, H);
|
|
177
|
+
const flowing = !reduced() && Boolean(s.pointer);
|
|
178
|
+
const dt = flowing && s.flowAt ? Math.min(0.1, t - s.flowAt) : 0;
|
|
179
|
+
s.flowAt = t;
|
|
180
|
+
c.setTransform(s.bdpr, 0, 0, s.bdpr, 0, 0);
|
|
181
|
+
// Trails: what was drawn fades a little each frame; a still frame is drawn fresh.
|
|
182
|
+
c.globalCompositeOperation = 'destination-out';
|
|
183
|
+
c.globalAlpha = dt ? Math.min(1, FLOW.fade * dt) : 1;
|
|
184
|
+
c.fillRect(0, 0, W, H);
|
|
185
|
+
c.globalCompositeOperation = 'source-over';
|
|
186
|
+
for (const m of list) {
|
|
187
|
+
if (dt) {
|
|
188
|
+
let [vx, vy] = current(m.x, m.y, t);
|
|
189
|
+
// Beside the pointer the current curls round it.
|
|
190
|
+
const pull = near(s, m.x, m.y);
|
|
191
|
+
if (pull) {
|
|
192
|
+
const dx = m.x - s.pointer.x, dy = m.y - s.pointer.y, d = Math.hypot(dx, dy) || 1;
|
|
193
|
+
vx += (-dy / d) * 2.2 * pull; vy += (dx / d) * 2.2 * pull;
|
|
194
|
+
}
|
|
195
|
+
m.x += vx * FLOW.speed * dt; m.y += vy * FLOW.speed * dt;
|
|
196
|
+
// Off one edge, back in at the other.
|
|
197
|
+
if (m.x < -4) m.x += W + 8; else if (m.x > W + 4) m.x -= W + 8;
|
|
198
|
+
if (m.y < -4) m.y += H + 8; else if (m.y > H + 4) m.y -= H + 8;
|
|
199
|
+
}
|
|
200
|
+
const lit = Math.pow(near(s, m.x, m.y), 1.4);
|
|
201
|
+
if (!lit) continue; // away from the pointer the flow does not show
|
|
202
|
+
c.globalAlpha = FLOW.lit * lit;
|
|
203
|
+
c.fillStyle = k[m.tone];
|
|
204
|
+
c.beginPath(); c.arc(m.x, m.y, m.r + 0.6 * lit, 0, 2 * Math.PI); c.fill();
|
|
205
|
+
}
|
|
206
|
+
// The card's own area stays clear, so its words never sit on the flow.
|
|
207
|
+
c.globalAlpha = 1;
|
|
208
|
+
const g = FLOW.clear, card = s.card;
|
|
209
|
+
c.clearRect(card.x - g, card.y - g, card.w + 2 * g, card.h + 2 * g);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function draw(s, now) {
|
|
213
|
+
const W = s.w, H = HEIGHT, c = s.ctx;
|
|
214
|
+
if (!W) return;
|
|
215
|
+
const k = s.k || (s.k = readColors(s.root));
|
|
216
|
+
const t = (now - origin) / 1000;
|
|
217
|
+
// Settle once it has played long enough, at the moment the cycle matches the still frame, so nothing jumps.
|
|
218
|
+
if (!settled && played >= SETTLE_S) { const q = pose(t, W); if (q.phase === 2 && q.u >= STILL_U) settled = true; }
|
|
219
|
+
const still = reduced() || settled;
|
|
220
|
+
drawBackdrop(s, t, still, k);
|
|
221
|
+
// Settled, the strip's own clock stops too, so a redraw for the flow (or a theme change) cannot move it.
|
|
222
|
+
const ts = still ? STILL_U : t;
|
|
223
|
+
const p = still ? stillPose(W) : pose(t, W);
|
|
224
|
+
c.setTransform(s.dpr, 0, 0, s.dpr, 0, 0);
|
|
225
|
+
c.clearRect(0, 0, W, H);
|
|
226
|
+
const ground = H - 10;
|
|
227
|
+
// The ground, with the path Flo travels lighting up behind it in each finished part's colour.
|
|
228
|
+
c.lineCap = 'round';
|
|
229
|
+
c.beginPath(); c.moveTo(10, ground); c.lineTo(W - 10, ground);
|
|
230
|
+
c.lineWidth = 1; c.strokeStyle = k.ground; c.setLineDash([2, 4]); c.stroke(); c.setLineDash([]);
|
|
231
|
+
c.save(); c.globalAlpha = p.fade;
|
|
232
|
+
for (let i = 0; i < 2; i++) {
|
|
233
|
+
const done = clamp(p.build[i + 1] * 1.6);
|
|
234
|
+
if (!done) continue;
|
|
235
|
+
const a = p.slots[i] + 14, z = p.slots[i + 1] - 30;
|
|
236
|
+
c.beginPath(); c.moveTo(a, ground); c.lineTo(a + (z - a) * done, ground);
|
|
237
|
+
c.lineWidth = 1.6; c.strokeStyle = [k.wf, k.ag][i]; c.stroke();
|
|
238
|
+
}
|
|
239
|
+
drawWorkspace(c, p.slots[0] + 6, ground, p.build[0], k);
|
|
240
|
+
drawWorkflow(c, p.slots[1] + 4, ground, p.build[1], ts, k);
|
|
241
|
+
c.restore();
|
|
242
|
+
// Flo: working (its light in the colour of the part it builds), the hat dropping on in the Agent's turn.
|
|
243
|
+
const r = 12, cy = ground - r - 3 - p.lift;
|
|
244
|
+
const agentTurn = p.phase === 2 && !p.hopping;
|
|
245
|
+
const hatLift = agentTurn ? 1 - easeOut(clamp((p.u - 0.2) / 0.25)) : 1;
|
|
246
|
+
const colors = { ...k.flo, pulse: [k.ws, k.wf, k.ag][p.phase] };
|
|
247
|
+
if (agentTurn || still) { c.save(); c.globalAlpha = p.fade; drawAgentHalo(c, p.floX, cy, r, p.build[2], ts, k); c.restore(); }
|
|
248
|
+
const squash = p.hopping ? [1 + 0.12 * bump(p.u / 0.18), 1 - 0.12 * bump(p.u / 0.18)] : [1, 1];
|
|
249
|
+
if (typeof drawFlo === 'function') {
|
|
250
|
+
drawFlo(c, {
|
|
251
|
+
x: p.floX, y: cy, r, stroke: 0.29 * r, t: ts, colors,
|
|
252
|
+
mood: still ? 'idle' : p.hopping ? 'idle' : 'working',
|
|
253
|
+
hat: agentTurn || still, hatLift: still ? 0 : hatLift, squash,
|
|
254
|
+
look: p.hopping ? [p.phase === 0 ? -1 : 1, -0.3] : undefined,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
// The labels light in their part's colour while it is that part's turn.
|
|
258
|
+
const lit = still ? -1 : p.phase;
|
|
259
|
+
s.labels.forEach((el, i) => el.classList.toggle('is-active', i === lit));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const forget = (s) => { scenes.delete(s); s.resize?.disconnect(); };
|
|
263
|
+
const moving = () => !reduced() && !settled;
|
|
264
|
+
|
|
265
|
+
function tick(now) {
|
|
266
|
+
frame = 0;
|
|
267
|
+
if (document.hidden) return;
|
|
268
|
+
if (now - last >= FRAME_MS - 1) {
|
|
269
|
+
// Only time on screen counts toward settling (a long hidden gap is clamped).
|
|
270
|
+
if (moving() && last > -Infinity && [...scenes].some((s) => s.visible)) played += Math.min(0.25, (now - last) / 1000);
|
|
271
|
+
last = now;
|
|
272
|
+
for (const s of [...scenes]) {
|
|
273
|
+
if (!s.root.isConnected) { forget(s); continue; }
|
|
274
|
+
if (!s.visible || !(s.dirty || moving() || s.pointer)) continue;
|
|
275
|
+
try { draw(s, now); s.dirty = false; } catch { forget(s); }
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// Nothing on screen to move or redraw: the loop stops, and fit() restarts it when a scene shows again.
|
|
279
|
+
if ([...scenes].some((s) => s.visible && (s.dirty || moving() || (s.pointer && !reduced())))) schedule();
|
|
280
|
+
}
|
|
281
|
+
function schedule() { if (!frame && scenes.size) frame = requestAnimationFrame(tick); }
|
|
282
|
+
const redrawAll = (recolor) => { for (const s of scenes) { s.dirty = true; if (recolor) s.k = null; } schedule(); };
|
|
283
|
+
document.addEventListener('visibilitychange', () => { if (!document.hidden) redrawAll(false); });
|
|
284
|
+
motion?.addEventListener?.('change', () => redrawAll(false));
|
|
285
|
+
// The pointer stirs the flow: redrawn while it is over the area, settled or not (the person moved it).
|
|
286
|
+
document.addEventListener('pointermove', (e) => {
|
|
287
|
+
for (const s of [...scenes]) {
|
|
288
|
+
if (!s.root.isConnected) { forget(s); continue; }
|
|
289
|
+
// A hidden scene forgets the pointer: it must be found again over the area once the scene shows.
|
|
290
|
+
if (!s.visible) { s.pointer = null; continue; }
|
|
291
|
+
const r = s.backdrop.getBoundingClientRect();
|
|
292
|
+
const inside = e.clientX >= r.left && e.clientX < r.right && e.clientY >= r.top && e.clientY < r.bottom;
|
|
293
|
+
if (!inside && !s.pointer) continue;
|
|
294
|
+
s.pointer = inside ? { x: e.clientX - r.left, y: e.clientY - r.top } : null;
|
|
295
|
+
s.dirty = true;
|
|
296
|
+
}
|
|
297
|
+
schedule();
|
|
298
|
+
}, { passive: true });
|
|
299
|
+
// A key press or a click anywhere stops the scene on its still frame: the person has started, so it gets out of the way.
|
|
300
|
+
const stop = () => { if (!moving()) return; settled = true; redrawAll(false); };
|
|
301
|
+
document.addEventListener('keydown', stop, { capture: true, passive: true });
|
|
302
|
+
document.addEventListener('pointerdown', stop, { capture: true, passive: true });
|
|
303
|
+
// The pointer gone where this document no longer hears it (out of the window, into a frame, the window
|
|
304
|
+
// losing focus) leaves no pointer behind, or the flow would go on stirring with nobody there.
|
|
305
|
+
const letGo = () => { for (const s of scenes) if (s.pointer) { s.pointer = null; s.dirty = true; } schedule(); };
|
|
306
|
+
document.addEventListener('pointerout', (e) => { if (!e.relatedTarget || e.relatedTarget.tagName === 'IFRAME') letGo(); }, { passive: true });
|
|
307
|
+
window.addEventListener?.('blur', letGo);
|
|
308
|
+
// A theme switch changes the tokens; once settled (or under reduced motion) nothing else would redraw the frame.
|
|
309
|
+
new MutationObserver(() => redrawAll(true))
|
|
310
|
+
.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'class'] });
|
|
311
|
+
|
|
312
|
+
// chatLandingScene(host, key): prepends the scene to host (an .ai-chat-empty card) and returns its root. key names
|
|
313
|
+
// the screen (the chooser for a scope, a conversation...): the same key carries on, a new one plays from the start.
|
|
314
|
+
window.chatLandingScene = function chatLandingScene(host, key = null) {
|
|
315
|
+
const root = document.createElement('div');
|
|
316
|
+
root.className = 'chat-landing-scene';
|
|
317
|
+
root.setAttribute('aria-hidden', 'true');
|
|
318
|
+
const canvas = document.createElement('canvas');
|
|
319
|
+
canvas.style.height = `${HEIGHT}px`;
|
|
320
|
+
const legend = document.createElement('div');
|
|
321
|
+
legend.className = 'chat-landing-parts';
|
|
322
|
+
const labels = PARTS.map((part) => {
|
|
323
|
+
const el = document.createElement('span');
|
|
324
|
+
el.className = `chat-landing-part is-${part.key}`;
|
|
325
|
+
const name = document.createElement('b'); name.textContent = part.label;
|
|
326
|
+
const note = document.createElement('small'); note.textContent = part.note;
|
|
327
|
+
el.append(name, note);
|
|
328
|
+
legend.append(el);
|
|
329
|
+
return el;
|
|
330
|
+
});
|
|
331
|
+
// The flow behind the card covers the whole conversation area (chat.css positions it).
|
|
332
|
+
const backdrop = document.createElement('canvas');
|
|
333
|
+
backdrop.className = 'chat-landing-backdrop';
|
|
334
|
+
root.append(backdrop, canvas, legend);
|
|
335
|
+
host.prepend(root);
|
|
336
|
+
// Callers clear the feed before building the card, so a scene left behind is gone by now: drop it here, since
|
|
337
|
+
// the loop that would have dropped it may be stopped (settled, or hidden).
|
|
338
|
+
for (const other of [...scenes]) if (!other.root.isConnected) forget(other);
|
|
339
|
+
if (key === null || key !== screen) { played = 0; settled = false; origin = performance.now(); }
|
|
340
|
+
screen = key;
|
|
341
|
+
const s = {
|
|
342
|
+
root, canvas, labels, ctx: canvas.getContext('2d'), dpr: 0, w: 0, k: null, visible: false, dirty: true,
|
|
343
|
+
host, backdrop, bctx: backdrop.getContext('2d'), bw: 0, bh: 0, bdpr: 0, card: { x: 0, y: 0, w: 0, h: 0 }, flowAt: 0, pointer: null,
|
|
344
|
+
};
|
|
345
|
+
// Sized from its laid-out width; a scene hidden by the short-panel rule has none and is skipped until it shows.
|
|
346
|
+
const fit = () => {
|
|
347
|
+
const w = Math.round(canvas.getBoundingClientRect().width);
|
|
348
|
+
const dpr = Math.min(2, window.devicePixelRatio || 1);
|
|
349
|
+
const shown = w > 0 && !s.visible;
|
|
350
|
+
s.visible = w > 0;
|
|
351
|
+
if (!s.visible) s.pointer = null;
|
|
352
|
+
if (shown) { s.dirty = true; schedule(); }
|
|
353
|
+
if (!w) return;
|
|
354
|
+
// The backdrop covers the conversation area, with the card's place in it kept clear.
|
|
355
|
+
const area = backdrop.getBoundingClientRect(), box = host.getBoundingClientRect();
|
|
356
|
+
const bw = Math.round(area.width), bh = Math.round(area.height);
|
|
357
|
+
const card = { x: Math.round(box.left - area.left), y: Math.round(box.top - area.top), w: Math.round(box.width), h: Math.round(box.height) };
|
|
358
|
+
if (card.x !== s.card.x || card.y !== s.card.y || card.w !== s.card.w || card.h !== s.card.h) { s.card = card; s.dirty = true; schedule(); }
|
|
359
|
+
if (bw !== s.bw || bh !== s.bh || dpr !== s.bdpr) {
|
|
360
|
+
s.bw = bw; s.bh = bh; s.bdpr = dpr; backdrop.width = Math.round(bw * dpr); backdrop.height = Math.round(bh * dpr); s.dirty = true; schedule();
|
|
361
|
+
}
|
|
362
|
+
if (w === s.w && dpr === s.dpr) return;
|
|
363
|
+
s.w = w; s.dpr = dpr; canvas.width = Math.round(w * dpr); canvas.height = Math.round(HEIGHT * dpr); s.dirty = true; schedule();
|
|
364
|
+
};
|
|
365
|
+
if (window.ResizeObserver) { s.resize = new ResizeObserver(fit); for (const el of [canvas, backdrop, host]) s.resize.observe(el); }
|
|
366
|
+
requestAnimationFrame(fit);
|
|
367
|
+
scenes.add(s);
|
|
368
|
+
schedule();
|
|
369
|
+
return root;
|
|
370
|
+
};
|
|
371
|
+
window.chatLandingScene.live = () => scenes.size;
|
|
372
|
+
})();
|