A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Windows: port the full file-drop choreography
Louis Raillefc4c6717cfd9
diff --git a/windows/README.md b/windows/README.mdindex 36157e97..82b3083c 100644--- a/windows/README.md+++ b/windows/README.md@@ -97,6 +97,11 @@ npm run tauri dev # live-reloading development buildnpm run pack # builds the installer and drops it in windows/release/```+`npm run dev` alone serves the front end in an ordinary browser, which is enough+to work on the island's looks. It also serves `dev/upload-preview.html`, which+replays the whole file-drop choreography on a loop — the one part of the UI that+otherwise needs a real drag from Explorer to see. Neither page ships in the app.+`npm run pack` leaves two files in `windows/release/`, the same names the releaseworkflow publishes:diff --git a/windows/dev/upload-preview.html b/windows/dev/upload-preview.htmlnew file mode 100644index 00000000..597697e2--- /dev/null+++ b/windows/dev/upload-preview.html@@ -0,0 +1,17 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <title>Coucou — upload sequence preview</title>+ <style>+ body { margin: 0; background: #1b1b1f; font: 12px system-ui; color: #ddd; }+ #stage { position: relative; width: 640px; height: 176px; margin: 24px auto; border-radius: 22px; overflow: hidden; }+ #clock { text-align: center; font: 600 14px ui-monospace, monospace; }+ </style>+ </head>+ <body>+ <div id="stage"></div>+ <div id="clock">–</div>+ <script type="module" src="./upload-preview.ts"></script>+ </body>+</html>diff --git a/windows/dev/upload-preview.ts b/windows/dev/upload-preview.tsnew file mode 100644index 00000000..89520772--- /dev/null+++ b/windows/dev/upload-preview.ts@@ -0,0 +1,50 @@+// Dev harness: plays the whole drop sequence in a plain browser so the+// choreography can be watched without an OLE drag. Not part of the app bundle.++import { UploadCanvas } from "../src/upload/canvas";+import { UploadSeq } from "../src/upload/sequence";+import { State } from "../src/core/state";++State.droppedFile = { name: "rapport-q3.pdf", path: "C:/tmp/rapport-q3.pdf" };++const stage = document.getElementById("stage")!;+const clock = document.getElementById("clock")!;++const canvas = new UploadCanvas({+ ask: () => (clock.textContent = "ASK clicked"),+ cancel: () => (clock.textContent = "CANCEL clicked"),+});+canvas.el.classList.add("on");+canvas.el.style.position = "absolute";+canvas.el.style.left = "0";+stage.append(canvas.el);++// The cursor walks in from the right, settles over the box, then drops.+// The whole thing restarts every 12 s so it can be watched (and screenshotted)+// without reloading the page.+const CYCLE = 12;+let start = performance.now();+let dropped = false;+UploadSeq.enterZone(520, 96);++function loop(now: number) {+ let t = (now - start) / 1000;+ if (t >= CYCLE) {+ start = now;+ t = 0;+ dropped = false;+ UploadSeq.enterZone(520, 96);+ }+ if (!dropped) {+ const x = 520 - Math.min(1, t / 0.9) * 260;+ UploadSeq.updateCursor(x, 96);+ if (t >= 1.2) {+ dropped = true;+ UploadSeq.performDrop(2.4);+ }+ }+ canvas.draw(UploadSeq.frame(), now / 1000);+ clock.textContent = `t = ${t.toFixed(2)} s${dropped ? " (dropped)" : " (dragging)"}`;+ requestAnimationFrame(loop);+}+requestAnimationFrame(loop);diff --git a/windows/src/core/layout.ts b/windows/src/core/layout.tsindex 2b5876cb..6f70eea4 100644--- a/windows/src/core/layout.ts+++ b/windows/src/core/layout.ts@@ -88,23 +88,9 @@ export const VIEW_LAYOUTS: Record<IslandViewName, ViewLayout> = {greeting: { height: 150, botX: 320, botY: 90, botDiameter: 0, agentMode: "none" },};-/**- * Progress curve of the upload bar — `usProgressCurve` from- * UploadSequenceEngine.swift: quick to 60 %, an unhurried middle, then a last- * push. A plain ease-out reads as a different animation entirely.- */-export function uploadProgressCurve(u: number): number {- const eOut = (t: number) => 1 - Math.pow(1 - t, 3);- const eIn = (t: number) => t * t * t;- const eInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);- if (u < 0.4) return 0.6 * eOut(u / 0.4);- if (u < 0.85) return 0.6 + 0.32 * eInOut((u - 0.4) / 0.45);- return 0.92 + 0.08 * eIn((u - 0.85) / 0.15);-}--/** While a file hovers the box, Mochi slides along under the cursor. */-export const UPLOAD_FOLLOW_MIN = 60;-export const UPLOAD_FOLLOW_MAX = 580;+// The upload views above are only the fallback geometry. Once a file is actually+// dropped the whole sequence — Mochi included — is drawn by src/upload, which+// owns its own constants (USC) straight from UploadSequenceEngine.swift./** Chat view grows with the conversation — IslandContainer.chatPromptHeight. */export function chatPromptHeight(messageCount: number): number {diff --git a/windows/src/core/state.ts b/windows/src/core/state.tsindex 99e50e48..d628f27e 100644--- a/windows/src/core/state.ts+++ b/windows/src/core/state.ts@@ -128,7 +128,6 @@ class AppState {paused = false;uploadProgress = 0;- uploadStartMs: number | null = null;uploadDuration = 2.4;fileDragOver = false;diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 01695f6f..5eeaf81d 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -6,7 +6,7 @@ import { Bridge, IS_TAURI, onDragDrop } from "../core/bridge";import {EXPANDED_CORNER, EXPANDED_W, NOTCH_W, PANEL_H, PANEL_W,ROUNDED_CORNER, VIEW_LAYOUTS, botGlowColor, botGlowOpacity, botPosition, chatPromptHeight,- islandSize, uploadProgressCurve, UPLOAD_FOLLOW_MIN, UPLOAD_FOLLOW_MAX,+ islandSize,type IslandMode, type IslandViewName,} from "../core/layout";import { Sound } from "../core/sound";@@ -14,6 +14,8 @@ import { State } from "../core/state";import { BotEngine, hexToRGB } from "../mochi/engine";import { Greeting } from "../mochi/greeting";import { createMiniBot, pruneMiniBots, syncMiniBotStates, tickMiniBots } from "../mochi/minibots";+import { UploadCanvas } from "../upload/canvas";+import { USC, UploadSeq } from "../upload/sequence";import { buildHeader, buildViews, type ViewActions, type ViewHost } from "../views/views";import { h } from "../views/dom";import { IslandStateMachine } from "./fsm";@@ -22,6 +24,12 @@ const BOT_OVERHANG = 40;/** Same margin as the Rust hit test (src-tauri/src/island.rs). */const HIT_MARGIN = 14;+/** The three views the drop sequence owns; leaving them stops the engine. */+const UPLOAD_VIEWS: ReadonlySet<IslandViewName> = new Set(["upload", "uploading", "choose"]);++/** Seconds between the drop and the moment the progress bar starts filling. */+const PRE_PROGRESS = USC.T_PROG_START - USC.T_DROP;+const modeOrder = (m: IslandMode) => (m === "hidden" ? 0 : m === "compact" ? 1 : 2);export class Island {@@ -41,6 +49,7 @@ export class Island {private header!: ViewHost;private views!: Map<IslandViewName, ViewHost>;+ private uploadCanvas!: UploadCanvas;private width = new Tracked(NOTCH_W);private height = new Tracked(0);@@ -74,7 +83,10 @@ export class Island {private confusedRecovery: number | null = null;private prevViewBeforeConfused: IslandViewName = "overview";private lastSyncedView: IslandViewName | null = null;- private lastTick = -1;++ /** Drop sequence bookkeeping: last tick played, and whether the ✓ has fired. */+ private uploadTens = 0;+ private uploadDone = false;constructor(root: HTMLElement) {this.root = root;@@ -171,7 +183,25 @@ export class Island {for (const v of this.views.values()) this.viewsEl.append(v.el);this.contentEl = h("div", { id: "content" }, this.header.el, this.viewsEl);- this.clipEl = h("div", { id: "island-clip" }, this.greetingCanvas, this.contentEl);+ // The drop sequence draws the card, the bar and its own Mochi. It sits under+ // the header, which stays visible on top of it exactly as on macOS.+ this.uploadCanvas = new UploadCanvas({+ ask: () => {+ State.promptContext = State.droppedFile+ ? { kind: "file", name: State.droppedFile.name, path: State.droppedFile.path }+ : null;+ this.setView("prompt");+ },+ cancel: () => this.setView(State.defaultView()),+ });++ this.clipEl = h(+ "div",+ { id: "island-clip" },+ this.greetingCanvas,+ this.uploadCanvas.el,+ this.contentEl,+ );this.islandEl = h("div",{ id: "island" },@@ -237,13 +267,30 @@ export class Island {State.isPinned = false;void Bridge.focusWindow(false);}- if (mode !== "expanded") this.engine.resetMorph();+ if (mode !== "expanded") {+ this.engine.resetMorph();+ // Nothing can be seen of the sequence once the island is shut, and leaving+ // it running would keep the frame loop awake — the island must cost+ // nothing while hidden.+ UploadSeq.deactivate();+ }this.updateWindowCollapsed();this.animateGeometry(modeOrder(mode) < modeOrder(prev));State.notify();}+ /** True while the drop sequence owns the island body. */+ private get uploadActive(): boolean {+ return State.mode === "expanded" && UploadSeq.isActive && UPLOAD_VIEWS.has(State.view);+ }++ /** Navigating out of the drop flow ends the sequence, as on macOS. */+ private stopSequenceIfLeaving(view: IslandViewName) {+ if (UploadSeq.isActive && !UPLOAD_VIEWS.has(view)) UploadSeq.deactivate();+ }+expand(view: IslandViewName) {+ this.stopSequenceIfLeaving(view);State.view = view;if (State.mode !== "expanded") this.setMode("expanded");else this.animateGeometry(false);@@ -253,6 +300,7 @@ export class Island {}setView(view: IslandViewName) {+ this.stopSequenceIfLeaving(view);if (State.mode !== "expanded") {this.fsm.forceHome();State.view = view;@@ -303,6 +351,9 @@ export class Island {if (State.fileDragOver) return;State.fileDragOver = true;this.engine.animateMorph(1);+ // enterZone must run before the island expands, so the sequence is+ // already active by the time the view becomes `upload`.+ UploadSeq.enterZone(State.mouseInIsland.x, State.mouseInIsland.y);this.alert("upload");break;}@@ -310,7 +361,8 @@ export class Island {if (!State.fileDragOver) return;State.fileDragOver = false;this.engine.animateMorph(0);- if (State.view === "upload") this.setView(State.defaultView());+ // The island deliberately stays open: the drag session is still alive.+ UploadSeq.exitZone();State.notify();break;}@@ -322,59 +374,77 @@ export class Island {this.setView(State.defaultView());return;}- void this.swallow(path);+ this.swallow(path);break;}}}- /** Mochi eats the file, then the progress bar runs and `choose` appears. */- private async swallow(path: string) {- try {- const file = await Bridge.ingestFile(path);- State.droppedFile = { name: file.name, path: file.path };- State.chatHistory = [];- void Bridge.chatReset();- } catch (err) {- State.noteMessage = String(err).replace(/^Error:\s*/, "");- this.engine.animateMorph(0);- this.setView("note");- Sound.play("error");- window.setTimeout(() => this.setView(State.defaultView()), 2400);- return;- }+ /**+ * Mochi eats the file. Nothing here waits on the file system: the copy into+ * the inbox runs in the background and swaps the path in when it lands, so a+ * slow disk can never stall the animation — same as FileDropHandler on macOS.+ */+ private swallow(path: string) {+ const name = path.split(/[\\/]/).pop() || "file";+ State.droppedFile = { name, path };+ State.promptContext = { kind: "file", name, path };+ State.chatHistory = [];+ void Bridge.chatReset();++ UploadSeq.performDrop(State.uploadDuration);+ this.uploadTens = 0;+ this.uploadDone = false;this.engine.gulp();- Sound.play("gulp");+ Sound.play("approve");this.engine.triggerEmote("happy");- window.setTimeout(() => this.engine.animateMorph(0), 950);+ this.engine.animateMorph(0);State.uploadProgress = 0;- State.uploadStartMs = performance.now();- this.lastTick = -1;this.setView("uploading");this.ensureRunning();- }- /** Time-based progress, `tick` every 10 %, then `choose`. */- private stepUpload(nowMs: number) {- if (State.uploadStartMs == null) return;- const t = Math.min(1, (nowMs - State.uploadStartMs) / 1000 / State.uploadDuration);- State.uploadProgress = uploadProgressCurve(t);- const tick = Math.floor(State.uploadProgress * 10);- if (tick !== this.lastTick && tick < 10) {- this.lastTick = tick;+ void Bridge.ingestFile(path)+ .then((file) => {+ State.droppedFile = { name: file.name, path: file.path };+ State.promptContext = { kind: "file", name: file.name, path: file.path };+ State.notify();+ })+ .catch((err) => {+ UploadSeq.deactivate();+ State.noteMessage = String(err).replace(/^Error:\s*/, "");+ this.engine.animateMorph(0);+ this.setView("note");+ Sound.play("error");+ window.setTimeout(() => this.setView(State.defaultView()), 2400);+ });+ }++ /**+ * Sounds and view changes hung off the canvas timeline: a `tick` every 10 %,+ * the ✓ chime when the bar completes, then `choose` once Mochi has grown back.+ */+ private stepSequence() {+ const since = UploadSeq.sinceDrop();+ if (since == null) return;+ const dur = State.uploadDuration;+ const p = Math.max(0, Math.min(1, (since - PRE_PROGRESS) / dur));++ const tens = Math.floor(p * 10);+ if (tens > this.uploadTens && tens < 10) {+ this.uploadTens = tens;Sound.play("tick");}- this.views.get("uploading")?.sync();- if (t >= 1) {- State.uploadStartMs = null;- State.uploadProgress = 1;- this.views.get("uploading")?.sync();++ if (!this.uploadDone && since >= PRE_PROGRESS + dur) {+ this.uploadDone = true;Sound.play("approve");- window.setTimeout(() => {- if (State.view === "uploading") this.setView("choose");- }, 600);+ this.engine.triggerEmote("happy");+ }+ // The extra second is the grow-back, after which the choose card is up.+ if (since >= PRE_PROGRESS + dur + 1 && State.view === "uploading") {+ this.setView("choose");}}@@ -413,6 +483,7 @@ export class Island {this.miniGrid.style.left = `${w - 40 - 14.5}px`;this.miniGrid.style.top = `${hh / 2 - 14.5}px`;this.greetingCanvas.style.left = `${(w - EXPANDED_W) / 2}px`;+ this.uploadCanvas.el.style.left = `${(w - EXPANDED_W) / 2}px`;const rect = { x: (PANEL_W - w) / 2, y: 0, w, h: hh };const p = this.pushedRect;@@ -494,6 +565,12 @@ export class Island {const rect = this.islandRect();State.mouseInIsland = { x: x - rect.x, y: y - rect.y };+ // Windows sends no cursor position with an OLE drag, so the drop sequence is+ // fed from the Win32 cursor poll instead — it runs throughout the drag.+ if (UploadSeq.isActive && !UploadSeq.dropped) {+ UploadSeq.updateCursor(State.mouseInIsland.x, State.mouseInIsland.y);+ }+const inIsland =x >= rect.x - HIT_MARGIN && x <= rect.x + rect.w + HIT_MARGIN &&y >= rect.y - HIT_MARGIN && y <= rect.y + rect.h + HIT_MARGIN;@@ -619,19 +696,26 @@ export class Island {this.greeting.draw(gctx);}} else {+ // Kept running even while the drop canvas is up, so the island's own Mochi+ // is already in the right place the moment the canvas fades out.this.drawBot(dt);}+ const uploadActive = this.uploadActive;+ if (uploadActive) this.uploadCanvas.draw(UploadSeq.frame(), nowMs / 1000);+ this.uploadCanvas.el.classList.toggle("on", uploadActive);+ this.viewsEl.classList.toggle("hidden-by-upload", uploadActive);+tickMiniBots(dt);this.views.get(State.view)?.tick?.(nowMs);- if (State.view === "uploading") this.stepUpload(nowMs);+ if (UploadSeq.isActive) this.stepSequence();this.updateCountdown(nowMs);const busy =this.width.animating || this.height.animating || this.radius.animating ||!this.botCx.settled || !this.botCy.settled || !this.botSize.settled ||greetingActive || this.engine.busy || State.mode !== "hidden" ||- State.uploadStartMs != null;+ UploadSeq.isActive;if (busy) {requestAnimationFrame(this.frame);@@ -646,22 +730,12 @@ export class Island {this.botCy.target = p.cy;this.botSize.target = p.diameter / 0.6;- // While uploading, Mochi *is* the bar's cursor: a spring would always trail- // the fill. Follow the progress exactly, like the macOS TimelineView does.- if (State.view === "uploading" && State.uploadStartMs != null) {- this.botCx.set(p.cx);- }-- // With a file hovering the box, Mochi slides along under the cursor.- if (State.view === "upload" && State.fileDragOver) {- this.botCx.target = clamp(State.mouseInIsland.x, UPLOAD_FOLLOW_MIN, UPLOAD_FOLLOW_MAX);- }-const greetingActive = State.mode === "expanded" && State.view === "greeting";- const visible = p.opacity > 0 && !greetingActive;+ // The drop canvas draws its own Mochi; two of them would overlap.+ const visible = p.opacity > 0 && !greetingActive && !this.uploadActive;this.botCanvas.style.opacity = visible ? "1" : "0";- if (State.mode === "expanded" && State.view !== "uploading" && !greetingActive) {+ if (State.mode === "expanded" && State.view !== "uploading" && !greetingActive && !this.uploadActive) {const d = p.diameter;const color = botGlowColor(State.effectiveState);this.botGlow.style.display = "block";diff --git a/windows/src/style.css b/windows/src/style.cssindex 444d248d..1da05cf9 100644--- a/windows/src/style.css+++ b/windows/src/style.css@@ -88,6 +88,51 @@ body {pointer-events: none;}+/* The drop sequence. Sits under the header and takes over the island body; it+ cross-fades in and out, so the last frame stays up while the views return. */+#upload-layer {+ position: absolute;+ top: 0;+ width: 640px;+ height: 176px;+ opacity: 0;+ pointer-events: none;+ transition: opacity 0.22s ease-in-out;+}++#upload-layer.on {+ opacity: 1;+}++#upload-canvas {+ position: absolute;+ inset: 0;+}++#upload-overlay {+ position: absolute;+ inset: 0;+ display: none;+}++/* Invisible hit areas over the buttons the canvas paints. */+.upload-hit {+ position: absolute;+ padding: 0;+ border: 0;+ border-radius: 13px;+ background: none;+ pointer-events: auto;+ cursor: pointer;+}++/* The ordinary views step aside while the sequence owns the body. */+#views.hidden-by-upload {+ opacity: 0;+ pointer-events: none;+ transition: opacity 0.22s ease-in-out;+}+#bot-glow {position: absolute;pointer-events: none;diff --git a/windows/src/upload/canvas.ts b/windows/src/upload/canvas.tsnew file mode 100644index 00000000..64b54f65--- /dev/null+++ b/windows/src/upload/canvas.ts@@ -0,0 +1,533 @@+// The upload canvas — port of UploadCanvasView.swift.+//+// While the sequence engine is active this canvas draws the whole island body:+// card, dashed drop frame, drop text, progress bar, the choose card, Mochi and+// the file being sucked in. The island's own Mochi is hidden for the duration,+// exactly as on macOS, because this canvas draws its own.++import { State } from "../core/state";+import {+ USC, eIn, eInOut, eOut, lerp, progressAt,+ type UploadEyeShape, type UploadFrame,+} from "./sequence";++const FONT = 'system-ui, "Segoe UI Variable Text", "Segoe UI", sans-serif';++/** Mirrors the reference `rr()`: a rounded rect, radius clamped to the box. */+function rr(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) {+ const rad = Math.max(0, Math.min(r, w / 2, h / 2));+ ctx.beginPath();+ ctx.roundRect(x, y, w, h, rad);+}++/** Superellipse body — port of usBodyPath(m, R). */+function bodyPath(ctx: CanvasRenderingContext2D, m: number, R: number): { rx: number; ry: number } {+ const mc = Math.max(0, Math.min(m, 1));+ const n = 2.15 + (5.5 - 2.15) * mc;+ const rx = R * (1.04 - 0.04 * mc);+ const ry = R * (0.97 - 0.03 * mc);+ ctx.beginPath();+ for (let i = 0; i <= 96; i++) {+ const a = (i / 96) * Math.PI * 2;+ const ca = Math.cos(a);+ const sa = Math.sin(a);+ const px = rx * Math.sign(ca) * Math.pow(Math.abs(ca), 2 / n);+ const py = ry * Math.sign(sa) * Math.pow(Math.abs(sa), 2 / n);+ if (i === 0) ctx.moveTo(px, py);+ else ctx.lineTo(px, py);+ }+ ctx.closePath();+ return { rx, ry };+}++function text(+ ctx: CanvasRenderingContext2D,+ s: string,+ x: number,+ y: number,+ font: string,+ color: string,+ align: CanvasTextAlign = "left",+) {+ ctx.font = font;+ ctx.fillStyle = color;+ ctx.textAlign = align;+ // SwiftUI's .leading / .center / .trailing anchors are vertically centred.+ ctx.textBaseline = "middle";+ ctx.fillText(s, x, y);+}++export interface UploadCanvasActions {+ /** Primary button — hand the file to the chat. */+ ask(): void;+ /** Secondary button. */+ cancel(): void;+}++export class UploadCanvas {+ /** Wrapper holding the canvas and the two invisible choose buttons. */+ readonly el: HTMLElement;++ private canvas: HTMLCanvasElement;+ private ctx: CanvasRenderingContext2D | null;+ private overlay: HTMLElement;+ private sizedFor = 0;++ constructor(actions: UploadCanvasActions) {+ this.canvas = document.createElement("canvas");+ this.canvas.id = "upload-canvas";++ // Invisible hit areas at the reference button positions. The labels are+ // painted on the canvas; these only catch the click.+ const mk = (x: number, w: number, onclick: () => void) => {+ const b = document.createElement("button");+ b.className = "upload-hit";+ b.style.left = `${x}px`;+ b.style.top = "113px";+ b.style.width = `${w}px`;+ b.style.height = "26px";+ b.addEventListener("click", onclick);+ return b;+ };+ this.overlay = document.createElement("div");+ this.overlay.id = "upload-overlay";+ this.overlay.append(mk(114, 168, actions.ask), mk(290, 120, actions.cancel));++ this.el = document.createElement("div");+ this.el.id = "upload-layer";+ this.el.append(this.canvas, this.overlay);++ this.ctx = this.canvas.getContext("2d");+ }++ /** `wallTime` in seconds drives the marching dashes, like the macOS timeline. */+ draw(f: UploadFrame, wallTime: number) {+ const dpr = Math.min(2, window.devicePixelRatio || 1);+ if (this.sizedFor !== dpr) {+ this.sizedFor = dpr;+ this.canvas.width = Math.round(USC.W * dpr);+ this.canvas.height = Math.round(USC.ISL_H * dpr);+ this.canvas.style.width = `${USC.W}px`;+ this.canvas.style.height = `${USC.ISL_H}px`;+ }+ const ctx = this.ctx;+ if (!ctx) return;+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);+ ctx.clearRect(0, 0, USC.W, USC.ISL_H);++ this.drawScene(ctx, f, wallTime);++ // The buttons only exist once the choose card has faded in.+ this.overlay.style.display = f.chooseAlpha > 0.5 ? "block" : "none";+ }++ // ── Scene ─────────────────────────────────────────────────────────────────++ private drawScene(ctx: CanvasRenderingContext2D, f: UploadFrame, wallTime: number) {+ // Island background.+ ctx.fillStyle = "#000000";+ ctx.fillRect(0, 0, USC.W, USC.ISL_H);++ // Card.+ ctx.save();+ rr(ctx, USC.CARD_X, USC.CARD_Y, USC.CARD_W, USC.CARD_H, USC.CARD_R);+ ctx.clip();+ ctx.fillStyle = "#0D0E10";+ ctx.fillRect(USC.CARD_X, USC.CARD_Y, USC.CARD_W, USC.CARD_H);++ // Green glow, fanning up from the bottom edge of the card.+ if (f.greenWash > 0) {+ const gx = USC.CARD_X + USC.CARD_W / 2;+ const gy = USC.CARD_Y + USC.CARD_H;+ const g = ctx.createRadialGradient(gx, gy, 0, gx, gy, USC.CARD_H * 1.5);+ g.addColorStop(0, `rgba(40,212,130,${f.greenWash * 0.9})`);+ g.addColorStop(0.55, `rgba(40,212,130,${f.greenWash * 0.3})`);+ g.addColorStop(1, "rgba(40,212,130,0)");+ ctx.fillStyle = g;+ ctx.fillRect(USC.CARD_X, USC.CARD_Y, USC.CARD_W, USC.CARD_H);+ }+ ctx.restore();++ // Dashed border, marching left to right at ~20 pt/s.+ if (f.zoneAlpha > 0) {+ ctx.save();+ ctx.globalAlpha = f.zoneAlpha;+ ctx.strokeStyle = f.zoneOver ? "rgba(52,212,153,0.55)" : "rgba(255,255,255,0.14)";+ ctx.lineWidth = 1.5;+ ctx.setLineDash([6, 5]);+ ctx.lineDashOffset = -wallTime * 20;+ rr(ctx, USC.CARD_X + 0.75, USC.CARD_Y + 0.75, USC.CARD_W - 1.5, USC.CARD_H - 1.5, USC.CARD_R - 0.5);+ ctx.stroke();+ ctx.restore();+ }++ if (f.zoneAlpha > 0 && f.textAlpha > 0) this.drawDropText(ctx, f);+ if (f.barAlpha > 0 || f.barReveal > 0) this.drawProgressBar(ctx, f);+ if (f.chooseAlpha > 0) this.drawChoose(ctx, f);++ this.drawMochi(ctx, f);+ if (f.fileVisible) this.drawFile(ctx, f);+ }++ // ── Drop zone text and chips ──────────────────────────────────────────────++ private drawDropText(ctx: CanvasRenderingContext2D, f: UploadFrame) {+ ctx.save();+ ctx.globalAlpha = f.textAlpha;+ text(ctx, "Drop your files here", USC.TEXT_X, USC.TEXT_Y - 4, `500 13px ${FONT}`, "#D5D7DB");++ let cx = USC.TEXT_X;+ for (const chip of ["PDF", "Images", "Code", "Docs"]) {+ // The macOS port measures chips the same rough way, so the row lines up.+ const w = chip.length * 6.5 + 16;+ ctx.fillStyle = "rgba(255,255,255,0.07)";+ rr(ctx, cx, USC.TEXT_Y + 9, w, 18, 9);+ ctx.fill();+ text(ctx, chip, cx + 8, USC.TEXT_Y + 18, `500 11px ${FONT}`, "#B9BDC4");+ cx += w + 6;+ }+ ctx.restore();+ }++ // ── Progress bar ──────────────────────────────────────────────────────────++ private drawProgressBar(ctx: CanvasRenderingContext2D, f: UploadFrame) {+ ctx.save();+ ctx.globalAlpha = Math.max(f.barAlpha, 0.001);++ const x0 = USC.BAR_X0;+ const x1 = USC.BAR_X1;+ const by = USC.BAR_Y;+ const barLen = (x1 - x0) * f.barReveal;++ const name = State.droppedFile?.name ?? "file";+ text(ctx, `Uploading ${name}`, x0, by - 30, `500 12.5px ${FONT}`, "#A9ADB5");++ if (f.check > 0) {+ ctx.save();+ ctx.translate(x1 - 8, by - 30);+ ctx.scale(f.check, f.check);+ ctx.beginPath();+ ctx.arc(0, 0, 8, 0, Math.PI * 2);+ ctx.fillStyle = "#34D399";+ ctx.fill();+ ctx.beginPath();+ ctx.moveTo(-3.6, 0.2);+ ctx.lineTo(-1, 2.8);+ ctx.lineTo(3.8, -2.6);+ ctx.strokeStyle = "#07130E";+ ctx.lineWidth = 2;+ ctx.lineCap = "round";+ ctx.lineJoin = "round";+ ctx.stroke();+ ctx.restore();+ } else {+ text(ctx, `${Math.round(f.progress * 100)} %`, x1, by - 30, `500 12.5px ${FONT}`, "#A9ADB5", "right");+ }++ // Track.+ if (barLen > 0) {+ ctx.fillStyle = "rgba(255,255,255,0.08)";+ rr(ctx, x0, by - 3, barLen, 6, 3);+ ctx.fill();+ }++ // Fill.+ const fx = lerp(x0, x1, f.progress);+ if (fx > x0 + 1) {+ const flashGreen = `rgb(${Math.round(lerp(52, 110, f.flash))},${Math.round(+ lerp(211, 231, f.flash),+ )},${Math.round(lerp(153, 183, f.flash))})`;+ const g = ctx.createLinearGradient(x0, 0, fx, 0);+ g.addColorStop(0, "#1FA87A");+ g.addColorStop(1, flashGreen);+ ctx.fillStyle = g;+ rr(ctx, x0, by - 3, fx - x0, 6, 3);+ ctx.fill();+ }++ // Glow trail, its length driven by how fast the bar is moving.+ if (f.progress > 0.01 && f.progress < 1) {+ const v =+ (progressAt(f.t + 0.01, USC.T_PROG_START, f.progEnd) -+ progressAt(f.t, USC.T_PROG_START, f.progEnd)) / 0.01;+ const tl = Math.max(8, Math.min(34, 8 + v * 40));+ const g = ctx.createLinearGradient(fx - tl, 0, fx, 0);+ g.addColorStop(0, "rgba(52,212,153,0)");+ g.addColorStop(1, "rgba(110,231,183,0.6)");+ ctx.save();+ ctx.filter = "blur(3px)";+ ctx.fillStyle = g;+ rr(ctx, fx - tl, by - 4, tl, 8, 4);+ ctx.fill();+ ctx.restore();+ }+ ctx.restore();+ }++ // ── Choose card ───────────────────────────────────────────────────────────++ private drawChoose(ctx: CanvasRenderingContext2D, f: UploadFrame) {+ ctx.save();+ ctx.globalAlpha = f.chooseAlpha;+ ctx.translate(0, (1 - f.chooseAlpha) * 4);++ const name = State.droppedFile?.name ?? "file";+ text(ctx, `${name} is ready.`, 114, 80, `600 14px ${FONT}`, "#F5F6F8");+ text(ctx, "What do you want to do with it?", 114, 100, `400 12.5px ${FONT}`, "#9398A1");++ ctx.fillStyle = "#F5F6F8";+ rr(ctx, 114, 113, 168, 26, 13);+ ctx.fill();+ text(ctx, "Ask a question about it", 198, 126, `500 12.5px ${FONT}`, "#0B0C0E", "center");++ ctx.fillStyle = "rgba(255,255,255,0.09)";+ rr(ctx, 290, 113, 120, 26, 13);+ ctx.fill();+ text(ctx, "Cancel", 350, 126, `500 12.5px ${FONT}`, "#F1F2F4", "center");+ ctx.restore();+ }++ // ── Mochi ─────────────────────────────────────────────────────────────────++ private drawMochi(ctx: CanvasRenderingContext2D, f: UploadFrame) {+ const R = f.d / 2 / 1.04;+ const mc = Math.max(0, Math.min(f.morph, 1));++ ctx.save();+ ctx.translate(f.x, f.y + f.hop);+ ctx.rotate(f.tilt);+ ctx.scale(f.sx, f.sy);++ const { rx, ry } = bodyPath(ctx, f.morph, R);++ // Body.+ const bg = ctx.createLinearGradient(rx * 0.7, -ry * 0.9, -rx * 0.8, ry * 0.9);+ bg.addColorStop(0, "#EDEDEF");+ bg.addColorStop(1, "#C4C5CA");+ ctx.fillStyle = bg;+ ctx.fill();++ // Edge shadow.+ const sg = ctx.createRadialGradient(0, 0, R * 0.2, 0, 0, R * 1.3);+ sg.addColorStop(0, "rgba(0,0,0,0)");+ sg.addColorStop(0.62, "rgba(0,0,0,0)");+ sg.addColorStop(1, "rgba(0,0,0,0.12)");+ ctx.fillStyle = sg;+ ctx.fill();++ // The body path is reused as a clip for everything drawn inside it.+ ctx.save();+ bodyPath(ctx, f.morph, R);+ ctx.clip();++ // Top rim, once Mochi is box-shaped enough to have one.+ if (mc > 0.3) {+ const a = Math.max(0, Math.min(1, (mc - 0.3) / 0.7));+ ctx.beginPath();+ ctx.moveTo(-rx * 0.72, -ry + 0.9);+ ctx.lineTo(rx * 0.72, -ry + 0.9);+ ctx.strokeStyle = `rgba(255,255,255,${0.6 * a})`;+ ctx.lineWidth = 1.2;+ ctx.lineCap = "round";+ ctx.stroke();+ }++ // Mouth hole.+ const mh = f.mouth * R * mc;+ if (mh > 0.3) {+ const mw = 2 * rx - 0.24 * R;+ const mx = -mw / 2;+ const my = -ry + 0.1 * R;+ const g = ctx.createLinearGradient(0, my, 0, my + mh);+ g.addColorStop(0, "#030304");+ g.addColorStop(1, "#101114");+ ctx.fillStyle = g;+ rr(ctx, mx, my, mw, mh, Math.min(mw / 2, mh / 2));+ ctx.fill();+ if (mh > 4) {+ const r = Math.min(mw / 2, mh / 2);+ ctx.beginPath();+ ctx.moveTo(mx + r, my + mh + 0.5);+ ctx.lineTo(mx + mw - r, my + mh + 0.5);+ ctx.strokeStyle = "rgba(255,255,255,0.55)";+ ctx.lineWidth = 1;+ ctx.lineCap = "round";+ ctx.stroke();+ }+ }++ // Eyes.+ const ew = R * 0.25;+ const eh = R * (0.62 - 0.16 * mc);+ const ey = R * (0.02 + 0.28 * mc);+ const sp = R * 0.3;+ const lx = f.lookX * R * (0.34 - 0.08 * mc);+ const ly = f.lookY * R * (0.16 - 0.09 * mc);+ for (const sd of [-1, 1]) {+ ctx.save();+ ctx.translate(sd * sp + lx, ey + ly);+ drawEye(ctx, f.eye, ew, eh);+ ctx.restore();+ }++ ctx.restore(); // body clip+ ctx.restore(); // transform+ }++ // ── The file, and the suction ─────────────────────────────────────────────++ private drawFile(ctx: CanvasRenderingContext2D, f: UploadFrame) {+ const cx = f.cursorX;+ const cy = f.cursorY + 14;++ if (f.suck <= 0) {+ ctx.save();+ ctx.globalAlpha = 0.92;+ drawDoc(ctx, cx, cy, 1, 1);+ ctx.restore();+ return;+ }++ const m = f.mouthRect;+ const W0 = 34;+ const H0 = 42;+ const p = eIn(f.suck);+ const topY = lerp(cy - H0 / 2, m.y - 2, eInOut(f.suck));+ const hs = lerp(1.08, 0.55, eInOut(f.suck));+ const Hh = H0 * hs;+ const sc = lerp(1, 0.55, p);+ const q = eOut(f.suck);+ const fCx = lerp(cx, m.x + m.w / 2, eOut(f.suck));+ const wob = Math.sin(f.suck * Math.PI * 2) * 0.1 * (1 - p);+ const clipY = m.y + m.h * 0.5;++ // The sheet is drawn as 28 horizontal strips, each narrowed towards the+ // mouth, so the page appears to funnel in. Everything below the mouth line+ // is clipped away — that is what makes it look swallowed.+ ctx.save();+ ctx.beginPath();+ ctx.rect(0, 0, USC.W, clipY);+ ctx.clip();++ for (let i = 0; i < 28; i++) {+ const v0 = i / 28;+ const wsc = lerp(1, lerp(0.92, (0.22 * m.w) / W0, Math.pow(v0, 1.2)), q) * sc;+ const yy = topY + v0 * Hh;+ const hh = Hh / 28 + 0.6;++ ctx.save();+ ctx.translate(fCx, yy);+ ctx.rotate(wob);+ ctx.beginPath();+ ctx.rect((-W0 * wsc) / 2, 0, W0 * wsc, hh);+ ctx.clip();+ ctx.translate(-fCx, -yy);+ drawDoc(ctx, fCx, topY + Hh / 2, wsc, hs);+ ctx.restore();+ }+ ctx.restore();++ // Green crumbs pulled in with the file.+ for (let i = 0; i < 4; i++) {+ const a = (i / 4) * Math.PI * 2 + 0.6;+ const k = Math.max(0, Math.min(1, (f.suck - i * 0.08) / 0.7));+ if (k <= 0 || k >= 1) continue;+ const sx0 = cx + Math.cos(a) * 24;+ const sy0 = cy + Math.sin(a) * 24;+ const ex = m.x + m.w / 2;+ const ey = m.y + m.h * 0.3;+ const kk = Math.pow(k, 0.7);+ const px = lerp(sx0, ex, kk);+ const py = lerp(sy0, ey, kk) - Math.sin(Math.PI * k) * 6;+ const rad = 2.2 * (1 - k * 0.5);+ ctx.beginPath();+ ctx.arc(px, py, rad, 0, Math.PI * 2);+ ctx.fillStyle = `rgba(52,212,153,${1 - k})`;+ ctx.fill();+ }+ }+}++// ── Eye shapes ──────────────────────────────────────────────────────────────++const INK = "#0E0F12";++function drawEye(ctx: CanvasRenderingContext2D, shape: UploadEyeShape, w: number, h: number) {+ switch (shape) {+ case "pill":+ ctx.fillStyle = INK;+ rr(ctx, -w / 2, -h / 2, w, h, w / 2);+ ctx.fill();+ break;++ case "cup": {+ // Flat top, semicircular bottom.+ const hh = h * 0.55;+ ctx.beginPath();+ ctx.moveTo(-w / 2, -hh / 2);+ ctx.lineTo(w / 2, -hh / 2);+ ctx.lineTo(w / 2, hh / 2 - w / 2);+ ctx.arc(0, hh / 2 - w / 2, w / 2, 0, Math.PI, false);+ ctx.closePath();+ ctx.fillStyle = INK;+ ctx.fill();+ break;+ }++ case "content":+ ctx.beginPath();+ ctx.arc(0, -h * 0.12, w * 0.85, Math.PI * 0.15, Math.PI * 0.85, false);+ ctx.strokeStyle = INK;+ ctx.lineWidth = w * 0.5;+ ctx.lineCap = "round";+ ctx.stroke();+ break;+ }+}++// ── Document icon ───────────────────────────────────────────────────────────++/**+ * The generic sheet with a folded corner. macOS swaps in the real file icon from+ * NSWorkspace; Windows has no equivalent reachable from the webview, so this is+ * the shape in every case — it is the same fallback the Swift draws.+ */+function drawDoc(ctx: CanvasRenderingContext2D, cx: number, cy: number, wsc: number, hsc: number) {+ const w = 34 * wsc;+ const h = 42 * hsc;+ const x = cx - w / 2;+ const y = cy - h / 2;+ const fold = 8 * Math.min(wsc, hsc);++ ctx.save();+ ctx.shadowColor = "rgba(0,0,0,0.45)";+ ctx.shadowBlur = 8;+ ctx.shadowOffsetY = 3;+ ctx.beginPath();+ ctx.moveTo(x + 2, y);+ ctx.lineTo(x + w - fold, y);+ ctx.lineTo(x + w, y + fold);+ ctx.lineTo(x + w, y + h - 2);+ ctx.quadraticCurveTo(x + w, y + h, x + w - 2, y + h);+ ctx.lineTo(x + 2, y + h);+ ctx.quadraticCurveTo(x, y + h, x, y + h - 2);+ ctx.lineTo(x, y + 2);+ ctx.quadraticCurveTo(x, y, x + 2, y);+ ctx.closePath();+ ctx.fillStyle = "#F4F4F6";+ ctx.fill();+ ctx.restore();++ ctx.beginPath();+ ctx.moveTo(x + w - fold, y);+ ctx.lineTo(x + w - fold, y + fold);+ ctx.lineTo(x + w, y + fold);+ ctx.closePath();+ ctx.fillStyle = "#D5D6DB";+ ctx.fill();++ ctx.fillStyle = "#3B82F5";+ rr(ctx, x + w * 0.18, y + h * 0.58, w * 0.64, h * 0.16, 2);+ ctx.fill();+}diff --git a/windows/src/upload/sequence.ts b/windows/src/upload/sequence.tsnew file mode 100644index 00000000..1374c849--- /dev/null+++ b/windows/src/upload/sequence.ts@@ -0,0 +1,528 @@+// The drop choreography — port of UploadSequenceEngine.swift, itself a port of+// design/prototype/upload-sequence.html.+//+// The engine is pure arithmetic: it owns no DOM and draws nothing. It takes the+// cursor and a drop time, and hands `frame()` back everything the canvas needs+// for one frame. All coordinates are island points (the island is 640 × 176),+// so every constant below is the macOS constant unchanged.++/** Constants — exact mirror of USC in UploadSequenceEngine.swift. */+export const USC = {+ W: 640,+ ISL_H: 176,+ CARD_X: 10,+ CARD_Y: 42,+ CARD_W: 620,+ CARD_H: 124,+ CARD_R: 20,+ REST_X: 140,+ REST_Y: 104,+ D_BOX: 62,+ FOLLOW_MIN: 60, // CARD_X + 50+ FOLLOW_MAX: 580, // CARD_X + CARD_W - 50+ TEXT_X: 196,+ TEXT_Y: 94,+ BAR_X0: 46,+ BAR_X1: 520,+ BAR_Y: 118,+ CHOOSE_X: 60,+ CHOOSE_Y: 101,+ CHOOSE_D: 62,+ LOCK_IN: 60,+ LOCK_OUT: 90,+ MOUTH_AJAR: 0.2,+ MOUTH_OPEN: 0.42,+ MOUTH_MAX: 0.5,+ // Phase timestamps, in seconds on the reference timeline (drop = 1.95).+ T_DROP: 1.95,+ T_SUCK_START: 2.03,+ T_SUCK_END: 2.33,+ T_CLOSE_END: 2.42,+ T_CHEW1: 2.6,+ T_CHEW_END: 2.88,+ T_SHRINK_END: 3.23,+ T_BAR_IN: 3.0,+ T_PROG_START: 3.25,+ DT: 1 / 240,+ /** Entry offset: gives 0.40 s of following before the drop. */+ ENTRY_T_REF: 1.95 - 0.4,+} as const;++// ── Easing ──────────────────────────────────────────────────────────────────++export const eOut = (t: number) => 1 - Math.pow(1 - t, 3);+export const eIn = (t: number) => t * t * t;+export const eInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);+export const eBack = (t: number) => {+ const c1 = 1.70158;+ const c3 = c1 + 1;+ return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);+};++export const seg = (t: number, a: number, b: number) => Math.max(0, Math.min(1, (t - a) / (b - a)));+export const lerp = (a: number, b: number, t: number) => a + (b - a) * t;++/** Squeeze keyframes for the suckEnd → chew1 phase. */+function squeezeY(t: number): number {+ const t0 = USC.T_SUCK_END, t1 = t0 + 0.07, t2 = t0 + 0.2, t3 = USC.T_CHEW1;+ if (t <= t0) return 1.06;+ if (t <= t1) return lerp(1.06, 0.82, eOut(seg(t, t0, t1)));+ if (t <= t2) return lerp(0.82, 1.1, eOut(seg(t, t1, t2)));+ if (t <= t3) return lerp(1.1, 1.0, eInOut(seg(t, t2, t3)));+ return 1.0;+}++function squeezeX(t: number): number {+ const t0 = USC.T_SUCK_END, t1 = t0 + 0.07, t2 = t0 + 0.2, t3 = USC.T_CHEW1;+ if (t <= t0) return 0.97;+ if (t <= t1) return lerp(0.97, 1.14, eOut(seg(t, t0, t1)));+ if (t <= t2) return lerp(1.14, 0.95, eOut(seg(t, t1, t2)));+ if (t <= t3) return lerp(0.95, 1.0, eInOut(seg(t, t2, t3)));+ return 1.0;+}++/**+ * Progress curve of the upload bar: quick to 60 %, an unhurried middle, then a+ * last push. A plain ease-out reads as a different animation entirely.+ */+export function uploadProgressCurve(u: number): number {+ if (u < 0.4) return 0.6 * eOut(u / 0.4);+ if (u < 0.85) return 0.6 + 0.32 * eInOut((u - 0.4) / 0.45);+ return 0.92 + 0.08 * eIn((u - 0.85) / 0.15);+}++export function progressAt(t: number, progStart: number, progEnd: number): number {+ return t < progStart ? 0 : uploadProgressCurve(seg(t, progStart, progEnd));+}++// ── Spring ──────────────────────────────────────────────────────────────────++/** The reference `spring(s, target, response, damping, dt)`, integrated by hand. */+class USSpring {+ vel = 0;+ constructor(public v: number) {}++ step(target: number, response: number, damping: number, dt: number) {+ const k = Math.pow((2 * Math.PI) / response, 2);+ const c = 2 * damping * Math.sqrt(k);+ const a = k * (target - this.v) - c * this.vel;+ this.vel += a * dt;+ this.v += this.vel * dt;+ }+}++// ── Frame ───────────────────────────────────────────────────────────────────++export type UploadEyeShape = "pill" | "cup" | "content";++export interface MouthRect {+ x: number;+ y: number;+ w: number;+ h: number;+}++export interface UploadFrame {+ t: number;+ cursorX: number;+ cursorY: number;+ morph: number;+ x: number;+ y: number;+ d: number;+ sx: number;+ sy: number;+ tilt: number;+ hop: number;+ mouth: number;+ mouthRect: MouthRect;+ eye: UploadEyeShape;+ lookX: number;+ lookY: number;+ fileVisible: boolean;+ suck: number;+ zoneOver: boolean;+ zoneAlpha: number;+ textAlpha: number;+ barReveal: number;+ barAlpha: number;+ progress: number;+ flash: number;+ check: number;+ greenWash: number;+ chooseAlpha: number;+ progEnd: number;+ growStart: number;+ growEnd: number;+}++function restFrame(): UploadFrame {+ return {+ t: 0,+ cursorX: 600,+ cursorY: 280,+ morph: 0,+ x: USC.REST_X,+ y: USC.REST_Y,+ d: USC.D_BOX,+ sx: 1,+ sy: 1,+ tilt: 0,+ hop: 0,+ mouth: 0,+ mouthRect: { x: 0, y: 0, w: 0, h: 0 },+ eye: "pill",+ lookX: 0,+ lookY: 0,+ fileVisible: true,+ suck: 0,+ zoneOver: false,+ zoneAlpha: 1,+ textAlpha: 1,+ barReveal: 0,+ barAlpha: 0,+ progress: 0,+ flash: 0,+ check: 0,+ greenWash: 0,+ chooseAlpha: 0,+ progEnd: USC.T_PROG_START + 2.4,+ growStart: USC.T_PROG_START + 2.4 + 0.25,+ growEnd: USC.T_PROG_START + 2.4 + 0.7,+ };+}++// ── Engine ──────────────────────────────────────────────────────────────────++class UploadSequence {+ uploadDuration = 2.4;++ get progEnd() {+ return USC.T_PROG_START + this.uploadDuration;+ }+ get growStart() {+ return this.progEnd + 0.25;+ }+ get growEnd() {+ return this.progEnd + 0.7;+ }++ isActive = false;++ cursorX = 600;+ cursorY = 280;++ private entryWall = 0;+ private dropWall: number | null = null;++ private t = 0;+ private bx = new USSpring(USC.REST_X);+ private by = new USSpring(USC.REST_Y);+ private tilt = 0;+ private mouth = new USSpring(0);+ private locked = false;+ private lockAt = -9;+ private entered = -9;++ private prevX = 600;+ private prevY = 280;+ private prevT = 0;+ private speed = 0;++ private now(): number {+ return performance.now() / 1000;+ }++ // ── Session lifecycle ─────────────────────────────────────────────────────++ /** A file entered the island. Coordinates are island points. */+ enterZone(x: number, y: number) {+ const now = this.now();+ this.cursorX = x;+ this.cursorY = y;+ this.prevX = x;+ this.prevY = y;+ this.prevT = now;+ this.speed = 0;++ this.t = USC.ENTRY_T_REF;+ this.entered = USC.ENTRY_T_REF;+ this.bx = new USSpring(USC.REST_X);+ this.by = new USSpring(USC.REST_Y);+ this.tilt = 0;+ this.mouth = new USSpring(0);+ this.locked = false;+ this.lockAt = -9;++ this.entryWall = now;+ this.dropWall = null;+ this.isActive = true;+ }++ updateCursor(x: number, y: number) {+ const now = this.now();+ const dt = now - this.prevT;+ if (dt > 0.001) {+ this.speed = Math.hypot(x - this.prevX, y - this.prevY) / dt;+ }+ this.prevX = x;+ this.prevY = y;+ this.prevT = now;+ this.cursorX = x;+ this.cursorY = y;+ }++ /** The island stays open per the spec, so leaving the zone changes nothing. */+ exitZone() {}++ performDrop(uploadDuration: number) {+ this.uploadDuration = uploadDuration;+ this.dropWall = this.now();+ // Restart the canonical post-drop timeline however long the user hovered.+ // Spring state (position and velocity) is deliberately preserved.+ this.t = USC.T_DROP;+ }++ deactivate() {+ this.isActive = false;+ this.dropWall = null;+ }++ // ── Reference time from the wall clock ────────────────────────────────────++ private tRef(): number {+ if (!this.isActive) return 0;+ const now = this.now();+ if (this.dropWall != null) return USC.T_DROP + Math.max(0, now - this.dropWall);+ // No cap: the springs keep stepping as long as the user hovers. computeFrame+ // clamps every phase-sensitive output back to the pre-drop state.+ return USC.ENTRY_T_REF + Math.max(0, now - this.entryWall);+ }++ /** True once the file has been dropped (the post-drop timeline is running). */+ get dropped(): boolean {+ return this.dropWall != null;+ }++ /** Seconds since the drop, or null while still dragging. */+ sinceDrop(): number | null {+ return this.dropWall == null ? null : this.now() - this.dropWall;+ }++ // ── Public entry point ────────────────────────────────────────────────────++ frame(): UploadFrame {+ if (!this.isActive) return restFrame();+ const t = this.tRef();+ this.simulateTo(t);+ return this.computeFrame(t);+ }++ // ── Simulation ────────────────────────────────────────────────────────────++ private simulateTo(target: number) {+ // A long stall (a background tab, a dragged window) must not spin here.+ if (target - this.t > 2) this.t = target - 2;+ while (this.t < target - 1e-10) {+ const dt = Math.min(USC.DT, target - this.t);+ this.stepOnce(dt);+ this.t += dt;+ }+ }++ private stepOnce(dt: number) {+ const isDragging = this.dropWall == null;++ // Horizontal follow and lock, only while dragging inside the zone.+ if (isDragging && this.entered >= 0) {+ const dist = Math.hypot(this.cursorX - this.bx.v, this.cursorY + 14 - this.by.v);+ if (!this.locked && dist < USC.LOCK_IN && this.speed < 180) {+ this.locked = true;+ this.lockAt = this.t;+ }+ if (this.locked && dist > USC.LOCK_OUT) this.locked = false;+ const tx = Math.max(USC.FOLLOW_MIN, Math.min(USC.FOLLOW_MAX, this.cursorX));+ const response = this.locked ? 0.18 : 0.35;+ const damping = this.locked ? 0.75 : 0.7;+ this.bx.step(tx, response, damping, dt);+ this.by.step(USC.REST_Y, response, damping, dt);+ }++ // Tilt follows how fast Mochi is sliding.+ const tiltTarget = isDragging ? Math.max(-0.18, Math.min(0.18, this.bx.vel * 0.0015)) : 0;+ this.tilt = lerp(this.tilt, tiltTarget, 1 - Math.pow(0.0005, dt));++ // Mouth. The post-drop close only runs once the drop has actually happened.+ const t = this.t;+ if (!isDragging && t >= USC.T_SUCK_END) {+ this.mouth.v = Math.max(0, lerp(USC.MOUTH_MAX, 0, eIn(seg(t, USC.T_SUCK_END, USC.T_CLOSE_END))));+ } else {+ let mt = 0;+ if (this.entered >= 0) mt = this.locked || !isDragging ? USC.MOUTH_OPEN : USC.MOUTH_AJAR;+ if (!isDragging && t < USC.T_SUCK_END) mt = USC.MOUTH_MAX;+ this.mouth.step(mt, 0.25, 0.6, dt);+ if (this.mouth.v < 0) this.mouth.v = 0;+ }+ }++ // ── Frame computation ─────────────────────────────────────────────────────++ private computeFrame(t: number): UploadFrame {+ const f = restFrame();+ f.t = t;+ f.cursorX = this.cursorX;+ f.cursorY = this.cursorY;+ const progEnd = this.progEnd;+ const growStart = this.growStart;+ const growEnd = this.growEnd;+ f.progEnd = progEnd;+ f.growStart = growStart;+ f.growEnd = growEnd;++ const entered = this.entered >= 0 ? this.entered : 1e9;+ const isDragging = this.dropWall == null;+ // Clamp the phase clock to just before the drop while still dragging, so a+ // long hover never trips the post-drop visuals.+ const pt = isDragging ? Math.min(t, USC.T_DROP - USC.DT) : t;++ // Morph: 0→1 on entry, 1→0 shrinking to a ball, 0→1 growing back at choose.+ let morph: number;+ if (pt < USC.T_CHEW_END) morph = eBack(seg(pt, entered, entered + 0.38));+ else if (pt < growStart) morph = 1 - eOut(seg(pt, USC.T_CHEW_END, USC.T_SHRINK_END));+ else morph = eBack(seg(pt, growStart, growEnd));+ f.morph = Math.max(0, Math.min(morph, 1.08));++ // Position and diameter.+ let x = this.bx.v;+ let y = this.by.v;+ let d: number = USC.D_BOX;+ if (pt >= USC.T_CHEW_END && pt < USC.T_PROG_START) {+ const k = eInOut(seg(pt, USC.T_CHEW_END, USC.T_SHRINK_END));+ x = lerp(this.bx.v, USC.BAR_X0, k);+ y = lerp(this.by.v, USC.BAR_Y, k);+ d = lerp(USC.D_BOX, 14, k);+ }+ if (pt >= USC.T_PROG_START) {+ const p = progressAt(pt, USC.T_PROG_START, progEnd);+ x = lerp(USC.BAR_X0, USC.BAR_X1, p);+ y = USC.BAR_Y;+ d = 14;+ }+ if (pt >= progEnd) {+ x = USC.BAR_X1;+ y = USC.BAR_Y - 8 * Math.sin(Math.PI * seg(pt, progEnd, progEnd + 0.2));+ }+ if (pt >= growStart) {+ const k = eInOut(seg(pt, growStart, growEnd));+ x = lerp(USC.BAR_X1, USC.CHOOSE_X, k);+ y = lerp(USC.BAR_Y, USC.CHOOSE_Y, k);+ d = lerp(14, USC.CHOOSE_D, eBack(seg(pt, growStart, growEnd)));+ }+ f.x = x;+ f.y = y;+ f.d = d;++ // Squeeze.+ let sx = 1;+ let sy = 1;+ if (pt >= USC.T_DROP && pt < USC.T_SUCK_START) {+ const k = eOut(seg(pt, USC.T_DROP, USC.T_SUCK_START));+ sy = lerp(1, 0.92, k);+ sx = lerp(1, 1.06, k);+ }+ if (pt >= USC.T_SUCK_START && pt < USC.T_SUCK_END) {+ const k = eInOut(seg(pt, USC.T_SUCK_START, USC.T_SUCK_END));+ sy = lerp(0.92, 1.06, k);+ sx = lerp(1.06, 0.97, k);+ }+ if (pt >= USC.T_SUCK_END && pt < USC.T_CHEW1) {+ sy = squeezeY(pt);+ sx = squeezeX(pt);+ }+ if (pt >= USC.T_CHEW1 && pt < USC.T_CHEW_END) {+ const k = ((pt - USC.T_CHEW1) % 0.14) / 0.14;+ sy = 1 - 0.05 * Math.sin(Math.PI * k);+ sx = 1 + 0.03 * Math.sin(Math.PI * k);+ }+ if (pt >= USC.T_CHEW_END && pt < USC.T_SHRINK_END) {+ const k = seg(pt, USC.T_CHEW_END, USC.T_SHRINK_END);+ sy = 1 + 0.12 * Math.sin(Math.PI * k);+ sx = 1 - 0.06 * Math.sin(Math.PI * k);+ }+ if (pt >= USC.T_PROG_START && pt < progEnd) {+ const v =+ (progressAt(pt + 0.01, USC.T_PROG_START, progEnd) -+ progressAt(pt, USC.T_PROG_START, progEnd)) / 0.01;+ const st = Math.max(0, Math.min(1, v * 0.18));+ sx = 1 + 0.25 * st;+ sy = 1 - 0.15 * st;+ }+ if (pt >= growStart && pt < growEnd) {+ sy = 1 + 0.06 * Math.sin(Math.PI * seg(pt, growStart, growEnd));+ }+ f.sx = sx;+ f.sy = sy;+ f.tilt = this.tilt;+ f.hop =+ this.lockAt > 0 && isDragging+ ? -5 * Math.sin(Math.PI * seg(pt, this.lockAt, this.lockAt + 0.15))+ : 0;++ f.mouth = this.mouth.v;++ // Eyes.+ let eye: UploadEyeShape = "pill";+ if (this.locked && pt < USC.T_SUCK_END) eye = "cup";+ if (pt >= USC.T_SUCK_END && pt < USC.T_CHEW_END + 0.1) eye = "content";+ if (pt >= progEnd && pt < growEnd + 0.3) eye = "content";+ f.eye = eye;++ const lkx = pt < USC.T_SUCK_END ? this.cursorX - x : pt < USC.T_PROG_START ? 0 : 40;+ const lky = pt < USC.T_SUCK_END ? this.cursorY + 10 - y : 0;+ f.lookX = Math.max(-1, Math.min(1, lkx / 200));+ f.lookY = Math.max(-1, Math.min(1, lky / 150));++ f.fileVisible = pt < USC.T_SUCK_END;+ f.suck = seg(pt, USC.T_SUCK_START, USC.T_SUCK_END);++ // Content alphas.+ f.zoneOver = this.entered >= 0 && pt < USC.T_CHEW_END;+ f.zoneAlpha = 1 - seg(pt, USC.T_CHEW_END, USC.T_CHEW_END + 0.2);+ f.textAlpha = f.zoneAlpha * (x > USC.TEXT_X - 40 && isDragging ? 0.25 : 1);+ f.barReveal =+ eOut(seg(pt, USC.T_BAR_IN, USC.T_BAR_IN + 0.25)) * (1 - seg(pt, growStart, growStart + 0.2));+ f.barAlpha =+ seg(pt, USC.T_BAR_IN + 0.05, USC.T_BAR_IN + 0.25) * (1 - seg(pt, growStart, growStart + 0.2));+ f.progress = progressAt(pt, USC.T_PROG_START, progEnd);+ f.flash = pt >= progEnd ? Math.sin(Math.PI * seg(pt, progEnd, progEnd + 0.3)) : 0;+ f.check = pt >= progEnd ? eBack(seg(pt, progEnd, progEnd + 0.25)) : 0;++ const hoverGreen = f.zoneOver ? 0.22 : 0;+ let uploadGreen = 0;+ if (pt >= USC.T_PROG_START) {+ const baseGreen = f.progress * 0.5;+ const flashExtra = pt >= progEnd ? 0.2 * Math.sin(Math.PI * seg(pt, progEnd, progEnd + 0.4)) : 0;+ const fadeOut = 1 - seg(pt, growEnd, growEnd + 0.6);+ uploadGreen = (baseGreen + flashExtra) * fadeOut;+ }+ f.greenWash = Math.max(hoverGreen, uploadGreen);+ f.chooseAlpha = seg(pt, growStart + 0.15, growEnd);++ // Mouth rect in island coordinates — the file is clipped against it.+ const R = f.d / 2 / 1.04;+ const mc = Math.max(0, Math.min(f.morph, 1));+ const rx = R * (1.04 - 0.04 * mc);+ const ry = R * (0.97 - 0.03 * mc);+ const mh = f.mouth * R * mc;+ const mw = 2 * rx - 0.24 * R;+ f.mouthRect = {+ x: x + (-mw / 2) * sx,+ y: y + f.hop + (-ry + 0.1 * R) * sy,+ w: mw * sx,+ h: mh * sy,+ };+ return f;+ }+}++export const UploadSeq = new UploadSequence();