Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(brand): loop neutral logo from complete state (#849)

Generbb0d0c299136
diff --git a/src/desktop/src-tauri/src/commands.rs b/src/desktop/src-tauri/src/commands.rs
index 9df203cf9..64a5d77d6 100644
--- a/src/desktop/src-tauri/src/commands.rs
+++ b/src/desktop/src-tauri/src/commands.rs
@@ -402,7 +402,8 @@ fn should_close_splash(frontend_ready: bool, min_elapsed: bool, max_wait_elapsed
#[cfg(desktop)]
pub fn splash_html() -> String {
let logo = include_str!("../../../../assets/alook.svg");
- let mut html = String::with_capacity(logo.len() + 6_144);
+ let motion = include_str!("../../../web/src/components/brand/alook-loading/motion.js");
+ let mut html = String::with_capacity(logo.len() + motion.len() + 5_120);
html.push_str(
r#"<!doctype html><html><head><meta charset="utf-8"><style>
*{margin:0;padding:0;box-sizing:border-box}
@@ -417,9 +418,10 @@ html,body{width:100%;height:100%;overflow:hidden;background:transparent;display:
</style></head><body><div id="stage" role="status" aria-label="Loading"><div id="canvas"><div id="clip"><div id="orbit"></div></div></div></div><template id="source">"#,
);
html.push_str(logo);
+ html.push_str(r##"</template><script type="module">"##);
+ html.push_str(motion);
html.push_str(
- r##"</template><script>
-const DURATION=540;
+ r##"
const bots=[
{face:"red",x:-100,y:-45,scale:.8,tilt:8},
{face:"purple",x:-20,y:-55,scale:.78,tilt:-9},
@@ -448,21 +450,6 @@ const faces=bots.map((bot,index)=>{
(index<4?orbitElement:clip).appendChild(wrapper);
return {wrapper,art,expressions:[...group.querySelectorAll('[data-part="expression"]')],pupils};
});
-function smooth(value){const t=Math.max(0,Math.min(1,value));return t*t*t*(t*(t*6-15)+10)}
-function motionAt(frame){
- const merge=smooth(frame/144);
- const split=smooth((frame-204)/144);
- const joined=merge-split;
- const times=[348,384,414,450,486,510];
- const values=[0,-1,-1,1,1,0];
- let look=0;
- for(let index=0;index<times.length-1;index+=1){
- if(frame>=times[index]&&frame<times[index+1]){
- look=values[index]+(values[index+1]-values[index])*smooth((frame-times[index])/(times[index+1]-times[index]));
- }
- }
- return {joined,orbit:((merge+split)*1080)%360,look};
-}
function apply(frame){
const {joined,orbit,look}=motionAt(frame);
clip.style.clipPath=`inset(${-300*(1-joined)}px round ${152.109375*joined}px)`;
@@ -491,8 +478,11 @@ function tick(now){
function sync(){
cancelAnimationFrame(request);
last=undefined;
- if(media.matches)apply(180);
- else if(!document.hidden)request=requestAnimationFrame(tick);
+ if(media.matches)apply(REDUCED_MOTION_FRAME);
+ else{
+ apply(0);
+ if(!document.hidden)request=requestAnimationFrame(tick);
+ }
}
media.addEventListener("change",sync);
document.addEventListener("visibilitychange",sync);
@@ -986,28 +976,56 @@ mod tests {
fn desktop_splash_matches_the_main_unknown_neutral_motion() {
let html = splash_html();
let canonical = include_str!("../../../../assets/alook.svg");
- let web_motion = include_str!("../../../web/src/components/brand/alook-loading/motion.ts");
+ let web_motion = include_str!("../../../web/src/components/brand/alook-loading/motion.js");
let web_frame =
include_str!("../../../web/src/components/brand/alook-loading/LoadingFrame.tsx");
assert!(html.contains(canonical));
assert!(html.contains("#stage{position:relative;width:192px;height:192px"));
- assert!(html.contains("const DURATION=540"));
- assert!(html.contains("const times=[348,384,414,450,486,510]"));
- assert!(html.contains("const values=[0,-1,-1,1,1,0]"));
- assert!(html.contains("orbit:((merge+split)*1080)%360"));
+ assert!(html.contains("<script type=\"module\">"));
+ assert_eq!(html.match_indices(web_motion).count(), 1);
+ assert_eq!(html.matches("export const DURATION = 540").count(), 1);
+ assert_eq!(html.matches("export const motionAt").count(), 1);
+ assert!(!html.contains("const DURATION=540"));
+ assert!(!html.contains("function motionAt("));
+ assert!(!html.contains("function smooth("));
assert!(html.contains("expressionOpacity=index===4?1:1-smooth((joined-.45)/.55)"));
- assert!(html.contains("apply(180)"));
+ assert!(html.contains("apply(REDUCED_MOTION_FRAME)"));
assert!(html.contains("prefers-reduced-motion: reduce"));
assert!(!html.contains("data:image/png"));
- assert!(web_motion.contains("export const DURATION = 540"));
- assert!(web_motion.contains("const times = [348, 384, 414, 450, 486, 510]"));
+ assert!(web_motion.contains("export const REDUCED_MOTION_FRAME = 0"));
+ assert!(web_motion.contains("const times = [204, 240, 270, 306, 342, 366]"));
assert!(web_motion.contains("const values = [0, -1, -1, 1, 1, 0]"));
assert!(web_frame.contains("width: 660"));
assert!(web_frame.contains("height: 660"));
assert!(web_frame.contains("rotate: `${orbit}deg`"));
}
+ #[test]
+ fn desktop_splash_applies_complete_frame_before_the_first_animation_request() {
+ let html = splash_html();
+ let sync_start = html.find("function sync(){").unwrap();
+ let sync_end = html[sync_start..]
+ .find("media.addEventListener")
+ .map(|offset| sync_start + offset)
+ .unwrap();
+ let sync = &html[sync_start..sync_end];
+ let complete_frame = sync.find("apply(0);").unwrap();
+ let first_request = sync.find("request=requestAnimationFrame(tick);").unwrap();
+
+ assert!(complete_frame < first_request);
+ assert!(html.contains(
+ "clip.style.clipPath=`inset(${-300*(1-joined)}px round ${152.109375*joined}px)`"
+ ));
+ assert!(html.contains(
+ "face.wrapper.style.translate=`${bot.x*.96*(1-joined)}px ${bot.y*.96*(1-joined)}px`"
+ ));
+ assert!(html.contains("face.wrapper.style.scale=String(bot.scale+(1-bot.scale)*joined)"));
+ assert!(html.contains("face.art.style.rotate=`${look*bot.tilt}deg`"));
+ assert!(html.contains("const expressionOpacity=index===4?1:1-smooth((joined-.45)/.55)"));
+ assert!(html.contains("expression.style.opacity=String(expressionOpacity)"));
+ }
+
#[test]
fn login_shell_path_accepts_only_one_line_of_absolute_entries() {
let root = std::env::current_dir().unwrap();
diff --git a/src/web/src/components/brand/alook-loading/AlookLoading.dom.test.ts b/src/web/src/components/brand/alook-loading/AlookLoading.dom.test.ts
index adb76c076..22fb42d30 100644
--- a/src/web/src/components/brand/alook-loading/AlookLoading.dom.test.ts
+++ b/src/web/src/components/brand/alook-loading/AlookLoading.dom.test.ts
@@ -60,15 +60,18 @@ describe("AlookLoading playback lifecycle", () => {
document.dispatchEvent(new Event("visibilitychange"))
})
- it("advances the shared artwork and wraps exactly at nine seconds", () => {
+ it("first paints the completed logo, advances, and wraps to that exact frame", () => {
const view = render(React.createElement(AlookLoading))
const initial = view.container.innerHTML
expect(observe).toHaveBeenCalledWith(view.getByRole("status"))
expect(view.getByRole("status")).toHaveAttribute("aria-label", "Loading")
+ expect(initial).toContain("round 152.109375px")
+ expect(initial.match(/translate: 0px 0px/g)).toHaveLength(5)
tick(0)
+ expect(view.container.innerHTML).toBe(initial)
tick(2500)
expect(view.container.innerHTML).not.toBe(initial)
- expect(view.container.innerHTML).toContain("round 152.109375px")
+ expect(view.container.innerHTML).not.toContain("round 152.109375px")
tick(6500)
expect(view.container.innerHTML).not.toBe(initial)
tick(7500)
@@ -108,7 +111,7 @@ describe("AlookLoading playback lifecycle", () => {
intersect(true)
tick(3000)
expect(view.container.innerHTML).toBe(before)
- tick(3200)
+ tick(3700)
expect(view.container.innerHTML).not.toBe(before)
visibility(true)
const hiddenFrame = view.container.innerHTML
@@ -125,6 +128,7 @@ describe("AlookLoading playback lifecycle", () => {
media.matches = true
const remove = vi.spyOn(document, "removeEventListener")
const view = render(React.createElement(AlookLoading))
+ const completed = view.container.innerHTML
expect(frames.size).toBe(0)
expect(view.container.innerHTML).toContain("round 152.109375px")
reduce(false)
@@ -133,7 +137,7 @@ describe("AlookLoading playback lifecycle", () => {
tick(100)
reduce(true)
expect(frames.size).toBe(0)
- expect(view.container.innerHTML).toContain("round 152.109375px")
+ expect(view.container.innerHTML).toBe(completed)
reduce(false)
expect(frames.size).toBe(1)
view.unmount()
diff --git a/src/web/src/components/brand/alook-loading/AlookLoading.tsx b/src/web/src/components/brand/alook-loading/AlookLoading.tsx
index 057d83a12..0368c2551 100644
--- a/src/web/src/components/brand/alook-loading/AlookLoading.tsx
+++ b/src/web/src/components/brand/alook-loading/AlookLoading.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useRef, useState } from "react";
import { LoadingFrame } from "./LoadingFrame";
-import { DURATION } from "./motion";
+import { DURATION, REDUCED_MOTION_FRAME } from "./motion";
export type AlookLoadingProps = {
size?: number;
paused?: boolean;
@@ -31,7 +31,7 @@ export const AlookLoading = ({
const sync = () => {
cancelAnimationFrame(request);
last = undefined;
- if (media.matches) setFrame(180);
+ if (media.matches) setFrame(REDUCED_MOTION_FRAME);
else if (!paused && visible && !document.hidden)
request = requestAnimationFrame(tick);
};
diff --git a/src/web/src/components/brand/alook-loading/LoadingFrame.test.ts b/src/web/src/components/brand/alook-loading/LoadingFrame.test.ts
new file mode 100644
index 000000000..4f33e1500
--- /dev/null
+++ b/src/web/src/components/brand/alook-loading/LoadingFrame.test.ts
@@ -0,0 +1,18 @@
+import { createElement } from "react"
+import { renderToStaticMarkup } from "react-dom/server"
+import { describe, expect, it } from "vitest"
+import { LoadingFrame } from "./LoadingFrame"
+import { DURATION } from "./motion"
+
+describe("LoadingFrame loop boundary", () => {
+ it("renders the same completed geometry, transforms, and opacity at both ends", () => {
+ const first = renderToStaticMarkup(createElement(LoadingFrame, { frame: 0 }))
+ const final = renderToStaticMarkup(createElement(LoadingFrame, { frame: DURATION - 1 }))
+
+ expect(final).toBe(first)
+ expect(first).toContain("clip-path:inset(0px round 152.109375px)")
+ expect(first.match(/translate:0px 0px/g)).toHaveLength(5)
+ expect(first.match(/scale:1/g)).toHaveLength(5)
+ expect(first.match(/opacity=\"0\"/g)).toHaveLength(4)
+ })
+})
diff --git a/src/web/src/components/brand/alook-loading/motion.ts b/src/web/src/components/brand/alook-loading/motion.js
similarity index 51%
rename from src/web/src/components/brand/alook-loading/motion.ts
rename to src/web/src/components/brand/alook-loading/motion.js
index e3e6f87b9..182e67955 100644
--- a/src/web/src/components/brand/alook-loading/motion.ts
+++ b/src/web/src/components/brand/alook-loading/motion.js
@@ -1,13 +1,18 @@
export const DURATION = 540;
-export const smooth = (value: number) => {
+export const REDUCED_MOTION_FRAME = 0;
+
+/** @param {number} value */
+export const smooth = (value) => {
const t = Math.max(0, Math.min(1, value));
return t * t * t * (t * (t * 6 - 15) + 10);
};
-export const motionAt = (frame: number) => {
- const merge = smooth(frame / 144);
- const split = smooth((frame - 204) / 144);
- const joined = merge - split;
- const times = [348, 384, 414, 450, 486, 510];
+
+/** @param {number} frame */
+export const motionAt = (frame) => {
+ const split = smooth((frame - 60) / 144);
+ const merge = smooth((frame - 366) / 144);
+ const joined = 1 - split + merge;
+ const times = [204, 240, 270, 306, 342, 366];
const values = [0, -1, -1, 1, 1, 0];
let look = 0;
for (let i = 0; i < times.length - 1; i++) {
@@ -18,5 +23,5 @@ export const motionAt = (frame: number) => {
smooth((frame - times[i]) / (times[i + 1] - times[i]));
}
}
- return { joined, orbit: ((merge + split) * 1080) % 360, look };
+ return { joined, orbit: ((split + merge) * 1080) % 360, look };
};
diff --git a/src/web/src/components/brand/alook-loading/motion.test.ts b/src/web/src/components/brand/alook-loading/motion.test.ts
index f34908d14..d5f14df1e 100644
--- a/src/web/src/components/brand/alook-loading/motion.test.ts
+++ b/src/web/src/components/brand/alook-loading/motion.test.ts
@@ -2,21 +2,21 @@ import { describe, expect, it } from "vitest"
import { DURATION, motionAt } from "./motion"
describe("Alook loading loop", () => {
- it("joins the final and first frames without a state jump", () => {
- expect(motionAt(DURATION - 1)).toEqual(motionAt(0))
- expect(motionAt(1).joined).toBeLessThan(0.00001)
+ it("starts and ends on the same completed logo", () => {
+ const completed = { joined: 1, orbit: 0, look: 0 }
+ expect(motionAt(0)).toEqual(completed)
+ expect(motionAt(DURATION - 1)).toEqual(completed)
})
- it("holds the completed logo before continuing into separation", () => {
- for (const frame of [144, 180, 204]) {
- expect(motionAt(frame)).toEqual({ joined: 1, orbit: 0, look: 0 })
- }
- expect(motionAt(205).joined).toBeLessThan(1)
- expect(motionAt(205).orbit).toBeGreaterThan(0)
- expect(motionAt(348)).toEqual({ joined: 0, orbit: 0, look: 0 })
+ it("separates only in the middle of the loop", () => {
+ expect(motionAt(60)).toEqual({ joined: 1, orbit: 0, look: 0 })
+ expect(motionAt(61).joined).toBeLessThan(1)
+ expect(motionAt(61).orbit).toBeGreaterThan(0)
+ expect(motionAt(204)).toEqual({ joined: 0, orbit: 0, look: 0 })
+ expect(motionAt(510)).toEqual({ joined: 1, orbit: 0, look: 0 })
})
it("looks both ways and returns to center before the next merge", () => {
- expect(motionAt(384).look).toBe(-1)
- expect(motionAt(450).look).toBe(1)
- expect(motionAt(510).look).toBe(0)
+ expect(motionAt(240).look).toBe(-1)
+ expect(motionAt(306).look).toBe(1)
+ expect(motionAt(366).look).toBe(0)
})
})