The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Live edit: the demo shows eleven changes on one portrait
Adarshfb6484f02a96
diff --git a/public/previews/live-edit/512/step-00.webp b/public/previews/live-edit/512/step-00.webpnew file mode 100644index 00000000..732b5394Binary files /dev/null and b/public/previews/live-edit/512/step-00.webp differdiff --git a/public/previews/live-edit/512/step-01.webp b/public/previews/live-edit/512/step-01.webpnew file mode 100644index 00000000..34658c72Binary files /dev/null and b/public/previews/live-edit/512/step-01.webp differdiff --git a/public/previews/live-edit/512/step-02.webp b/public/previews/live-edit/512/step-02.webpnew file mode 100644index 00000000..f564927eBinary files /dev/null and b/public/previews/live-edit/512/step-02.webp differdiff --git a/public/previews/live-edit/512/step-03.webp b/public/previews/live-edit/512/step-03.webpnew file mode 100644index 00000000..1ac08776Binary files /dev/null and b/public/previews/live-edit/512/step-03.webp differdiff --git a/public/previews/live-edit/512/step-04.webp b/public/previews/live-edit/512/step-04.webpnew file mode 100644index 00000000..8bb2d3e9Binary files /dev/null and b/public/previews/live-edit/512/step-04.webp differdiff --git a/public/previews/live-edit/512/step-05.webp b/public/previews/live-edit/512/step-05.webpnew file mode 100644index 00000000..d52b60ebBinary files /dev/null and b/public/previews/live-edit/512/step-05.webp differdiff --git a/public/previews/live-edit/512/step-06.webp b/public/previews/live-edit/512/step-06.webpnew file mode 100644index 00000000..95e36cf1Binary files /dev/null and b/public/previews/live-edit/512/step-06.webp differdiff --git a/public/previews/live-edit/512/step-07.webp b/public/previews/live-edit/512/step-07.webpnew file mode 100644index 00000000..6d839b30Binary files /dev/null and b/public/previews/live-edit/512/step-07.webp differdiff --git a/public/previews/live-edit/512/step-08.webp b/public/previews/live-edit/512/step-08.webpnew file mode 100644index 00000000..b45003b4Binary files /dev/null and b/public/previews/live-edit/512/step-08.webp differdiff --git a/public/previews/live-edit/512/step-09.webp b/public/previews/live-edit/512/step-09.webpnew file mode 100644index 00000000..234c86fcBinary files /dev/null and b/public/previews/live-edit/512/step-09.webp differdiff --git a/public/previews/live-edit/512/step-10.webp b/public/previews/live-edit/512/step-10.webpnew file mode 100644index 00000000..f26614baBinary files /dev/null and b/public/previews/live-edit/512/step-10.webp differdiff --git a/public/previews/live-edit/512/step-11.webp b/public/previews/live-edit/512/step-11.webpnew file mode 100644index 00000000..e78fd40eBinary files /dev/null and b/public/previews/live-edit/512/step-11.webp differdiff --git a/public/previews/live-edit/960/step-00.webp b/public/previews/live-edit/960/step-00.webpnew file mode 100644index 00000000..cbee6068Binary files /dev/null and b/public/previews/live-edit/960/step-00.webp differdiff --git a/public/previews/live-edit/960/step-01.webp b/public/previews/live-edit/960/step-01.webpnew file mode 100644index 00000000..2a5e728aBinary files /dev/null and b/public/previews/live-edit/960/step-01.webp differdiff --git a/public/previews/live-edit/960/step-02.webp b/public/previews/live-edit/960/step-02.webpnew file mode 100644index 00000000..ac8f32dbBinary files /dev/null and b/public/previews/live-edit/960/step-02.webp differdiff --git a/public/previews/live-edit/960/step-03.webp b/public/previews/live-edit/960/step-03.webpnew file mode 100644index 00000000..2318e16aBinary files /dev/null and b/public/previews/live-edit/960/step-03.webp differdiff --git a/public/previews/live-edit/960/step-04.webp b/public/previews/live-edit/960/step-04.webpnew file mode 100644index 00000000..faaa5986Binary files /dev/null and b/public/previews/live-edit/960/step-04.webp differdiff --git a/public/previews/live-edit/960/step-05.webp b/public/previews/live-edit/960/step-05.webpnew file mode 100644index 00000000..ed05c54dBinary files /dev/null and b/public/previews/live-edit/960/step-05.webp differdiff --git a/public/previews/live-edit/960/step-06.webp b/public/previews/live-edit/960/step-06.webpnew file mode 100644index 00000000..638e0a11Binary files /dev/null and b/public/previews/live-edit/960/step-06.webp differdiff --git a/public/previews/live-edit/960/step-07.webp b/public/previews/live-edit/960/step-07.webpnew file mode 100644index 00000000..bcc9a538Binary files /dev/null and b/public/previews/live-edit/960/step-07.webp differdiff --git a/public/previews/live-edit/960/step-08.webp b/public/previews/live-edit/960/step-08.webpnew file mode 100644index 00000000..e4dc997bBinary files /dev/null and b/public/previews/live-edit/960/step-08.webp differdiff --git a/public/previews/live-edit/960/step-09.webp b/public/previews/live-edit/960/step-09.webpnew file mode 100644index 00000000..ecec8367Binary files /dev/null and b/public/previews/live-edit/960/step-09.webp differdiff --git a/public/previews/live-edit/960/step-10.webp b/public/previews/live-edit/960/step-10.webpnew file mode 100644index 00000000..f92f9734Binary files /dev/null and b/public/previews/live-edit/960/step-10.webp differdiff --git a/public/previews/live-edit/960/step-11.webp b/public/previews/live-edit/960/step-11.webpnew file mode 100644index 00000000..70e12556Binary files /dev/null and b/public/previews/live-edit/960/step-11.webp differdiff --git a/public/previews/live-edit/demo.json b/public/previews/live-edit/demo.jsonindex 01a036bc..1514cf28 100644--- a/public/previews/live-edit/demo.json+++ b/public/previews/live-edit/demo.json@@ -1,16 +1,127 @@{- "v": 1,+ "v": 2,"size": [960, 720],"frames": {- "before": {"src": "/previews/presets/ba/960/app-makeup-studio-before.jpg", "small": "/previews/presets/ba/512/app-makeup-studio-before.jpg"},- "after": {"src": "/previews/presets/ba/960/app-makeup-studio-after.jpg", "small": "/previews/presets/ba/512/app-makeup-studio-after.jpg"}+ "s0": {"src": "/previews/live-edit/960/step-00.webp?v=9d4a860e", "small": "/previews/live-edit/512/step-00.webp?v=c47f82ab"},+ "s1a": {"src": "/previews/live-edit/live/step-01-1.webp?v=95f2d54d"},+ "s1b": {"src": "/previews/live-edit/live/step-01-2.webp?v=32e1b3e9"},+ "s1c": {"src": "/previews/live-edit/live/step-01-3.webp?v=841a6980"},+ "s1": {"src": "/previews/live-edit/960/step-01.webp?v=541106bb", "small": "/previews/live-edit/512/step-01.webp?v=dba8a40c"},+ "s2a": {"src": "/previews/live-edit/live/step-02-1.webp?v=5bb58562"},+ "s2b": {"src": "/previews/live-edit/live/step-02-2.webp?v=33be604d"},+ "s2c": {"src": "/previews/live-edit/live/step-02-3.webp?v=9ef90659"},+ "s2": {"src": "/previews/live-edit/960/step-02.webp?v=66d43685", "small": "/previews/live-edit/512/step-02.webp?v=76a29afa"},+ "s3a": {"src": "/previews/live-edit/live/step-03-1.webp?v=c800d544"},+ "s3b": {"src": "/previews/live-edit/live/step-03-2.webp?v=c3be087b"},+ "s3": {"src": "/previews/live-edit/960/step-03.webp?v=c6674bcc", "small": "/previews/live-edit/512/step-03.webp?v=ef5b6616"},+ "s4a": {"src": "/previews/live-edit/live/step-04-1.webp?v=0c1a6657"},+ "s4": {"src": "/previews/live-edit/960/step-04.webp?v=7ac28830", "small": "/previews/live-edit/512/step-04.webp?v=3232ef5d"},+ "s5a": {"src": "/previews/live-edit/live/step-05-1.webp?v=ade78628"},+ "s5b": {"src": "/previews/live-edit/live/step-05-2.webp?v=5e4aa500"},+ "s5": {"src": "/previews/live-edit/960/step-05.webp?v=8eb781f9", "small": "/previews/live-edit/512/step-05.webp?v=2eb522e9"},+ "s6a": {"src": "/previews/live-edit/live/step-06-1.webp?v=09c74831"},+ "s6b": {"src": "/previews/live-edit/live/step-06-2.webp?v=ee1062c1"},+ "s6": {"src": "/previews/live-edit/960/step-06.webp?v=a4c2f7f0", "small": "/previews/live-edit/512/step-06.webp?v=7c905df8"},+ "s7a": {"src": "/previews/live-edit/live/step-07-1.webp?v=3402d883"},+ "s7b": {"src": "/previews/live-edit/live/step-07-2.webp?v=78c2d107"},+ "s7": {"src": "/previews/live-edit/960/step-07.webp?v=4be10fc9", "small": "/previews/live-edit/512/step-07.webp?v=80192a89"},+ "s8a": {"src": "/previews/live-edit/live/step-08-1.webp?v=62ed261f"},+ "s8b": {"src": "/previews/live-edit/live/step-08-2.webp?v=4377c72d"},+ "s8": {"src": "/previews/live-edit/960/step-08.webp?v=4457e3e6", "small": "/previews/live-edit/512/step-08.webp?v=9c570756"},+ "s9a": {"src": "/previews/live-edit/live/step-09-1.webp?v=af96200f"},+ "s9b": {"src": "/previews/live-edit/live/step-09-2.webp?v=5be1d9b2"},+ "s9": {"src": "/previews/live-edit/960/step-09.webp?v=b9d1302c", "small": "/previews/live-edit/512/step-09.webp?v=b7bc4937"},+ "s10a": {"src": "/previews/live-edit/live/step-10-1.webp?v=2ced9938"},+ "s10b": {"src": "/previews/live-edit/live/step-10-2.webp?v=edf847f6"},+ "s10": {"src": "/previews/live-edit/960/step-10.webp?v=c0c1411a", "small": "/previews/live-edit/512/step-10.webp?v=231d06ef"},+ "s11a": {"src": "/previews/live-edit/live/step-11-1.webp?v=39d640d9"},+ "s11b": {"src": "/previews/live-edit/live/step-11-2.webp?v=669b291b"},+ "s11": {"src": "/previews/live-edit/960/step-11.webp?v=c15dc572", "small": "/previews/live-edit/512/step-11.webp?v=4d25f666"}},"script": [- {"type": "frame", "frame": "before", "ms": 900},- {"type": "type", "text": "evening makeup, deep red lips", "ms": 1900},- {"type": "frame", "frame": "after", "live": true, "ms": 1200},- {"type": "keep", "label": "evening makeup, deep red lips", "ms": 1300},- {"type": "compare", "ms": 2800},- {"type": "pause", "ms": 1400}+ {"type": "frame", "frame": "s0", "ms": 800},+ {"type": "zoom", "box": [0.42, 0.267, 0.577, 0.528], "ms": 150},+ {"type": "type", "text": "evening makeup", "ms": 628},+ {"type": "frame", "frame": "s1a", "live": true, "ms": 600},+ {"type": "type", "text": ", deep red", "ms": 500},+ {"type": "frame", "frame": "s1b", "live": true, "ms": 600},+ {"type": "type", "text": " lips", "ms": 250},+ {"type": "frame", "frame": "s1c", "live": true, "ms": 600},+ {"type": "zoom", "box": null, "ms": 0},+ {"type": "frame", "frame": "s1", "ms": 680},+ {"type": "keep", "label": "Evening makeup", "ms": 820},+ {"type": "type", "text": "hair down", "ms": 418},+ {"type": "frame", "frame": "s2a", "live": true, "ms": 600},+ {"type": "type", "text": ", side-swept", "ms": 544},+ {"type": "frame", "frame": "s2b", "live": true, "ms": 600},+ {"type": "type", "text": " waves", "ms": 292},+ {"type": "frame", "frame": "s2c", "live": true, "ms": 600},+ {"type": "frame", "frame": "s2", "ms": 680},+ {"type": "keep", "label": "Side-swept waves", "ms": 820},+ {"type": "zoom", "box": [0.376, 0.422, 0.619, 0.538], "ms": 230},+ {"type": "type", "text": "big gold hoop", "ms": 470},+ {"type": "frame", "frame": "s3a", "live": true, "ms": 540},+ {"type": "type", "text": " earrings", "ms": 310},+ {"type": "frame", "frame": "s3b", "live": true, "ms": 540},+ {"type": "zoom", "box": null, "ms": 0},+ {"type": "frame", "frame": "s3", "ms": 600},+ {"type": "keep", "label": "Gold hoops", "ms": 700},+ {"type": "zoom", "box": [0.312, 0.626, 0.61, 0.997], "ms": 150},+ {"type": "type", "text": "jet black velvet gown", "ms": 750},+ {"type": "frame", "frame": "s4a", "live": true, "ms": 540},+ {"type": "zoom", "box": null, "ms": 0},+ {"type": "frame", "frame": "s4", "ms": 600},+ {"type": "keep", "label": "Black velvet gown", "ms": 700},+ {"type": "zoom", "box": [0.4, 0.3, 0.64, 0.7], "ms": 240},+ {"type": "type", "text": "diamond choker", "ms": 460},+ {"type": "frame", "frame": "s5a", "live": true, "ms": 540},+ {"type": "type", "text": " necklace", "ms": 310},+ {"type": "frame", "frame": "s5b", "live": true, "ms": 540},+ {"type": "zoom", "box": null, "ms": 0},+ {"type": "frame", "frame": "s5", "ms": 600},+ {"type": "keep", "label": "Diamond choker", "ms": 700},+ {"type": "zoom", "box": [0.586, 0.164, 0.682, 0.366], "ms": 420},+ {"type": "type", "text": "red rose", "ms": 280},+ {"type": "frame", "frame": "s6a", "live": true, "ms": 540},+ {"type": "type", "text": " in her hair", "ms": 480},+ {"type": "frame", "frame": "s6b", "live": true, "ms": 540},+ {"type": "zoom", "box": null, "ms": 0},+ {"type": "frame", "frame": "s6", "ms": 600},+ {"type": "keep", "label": "Red rose", "ms": 700},+ {"type": "zoom", "box": [0.28, 0.626, 0.722, 0.996], "ms": 150},+ {"type": "type", "text": "sheer black lace", "ms": 560},+ {"type": "frame", "frame": "s7a", "live": true, "ms": 540},+ {"type": "type", "text": " sleeves", "ms": 280},+ {"type": "frame", "frame": "s7b", "live": true, "ms": 540},+ {"type": "zoom", "box": null, "ms": 0},+ {"type": "frame", "frame": "s7", "ms": 600},+ {"type": "keep", "label": "Black lace sleeves", "ms": 700},+ {"type": "type", "text": "candlelit", "ms": 270},+ {"type": "frame", "frame": "s8a", "live": true, "ms": 540},+ {"type": "type", "text": " ballroom background", "ms": 680},+ {"type": "frame", "frame": "s8b", "live": true, "ms": 540},+ {"type": "frame", "frame": "s8", "ms": 600},+ {"type": "keep", "label": "Candlelit ballroom", "ms": 700},+ {"type": "type", "text": "soft golden", "ms": 370},+ {"type": "frame", "frame": "s9a", "live": true, "ms": 540},+ {"type": "type", "text": " backlight", "ms": 340},+ {"type": "frame", "frame": "s9b", "live": true, "ms": 540},+ {"type": "frame", "frame": "s9", "ms": 600},+ {"type": "keep", "label": "Golden backlight", "ms": 700},+ {"type": "type", "text": "diamond tiara", "ms": 430},+ {"type": "frame", "frame": "s10a", "live": true, "ms": 540},+ {"type": "type", "text": " on top", "ms": 290},+ {"type": "frame", "frame": "s10b", "live": true, "ms": 540},+ {"type": "frame", "frame": "s10", "ms": 600},+ {"type": "keep", "label": "Diamond tiara", "ms": 700},+ {"type": "type", "text": "black and white photo", "ms": 666},+ {"type": "frame", "frame": "s11a", "live": true, "ms": 540},+ {"type": "type", "text": ", only the rose stays", "ms": 706},+ {"type": "frame", "frame": "s11b", "live": true, "ms": 540},+ {"type": "type", "text": " red", "ms": 144},+ {"type": "frame", "frame": "s11", "ms": 600},+ {"type": "keep", "label": "Black and white", "ms": 700},+ {"type": "compare", "ms": 2400},+ {"type": "pause", "ms": 900}]}diff --git a/public/previews/live-edit/live/step-01-1.webp b/public/previews/live-edit/live/step-01-1.webpnew file mode 100644index 00000000..eddf73d4Binary files /dev/null and b/public/previews/live-edit/live/step-01-1.webp differdiff --git a/public/previews/live-edit/live/step-01-2.webp b/public/previews/live-edit/live/step-01-2.webpnew file mode 100644index 00000000..e37201ceBinary files /dev/null and b/public/previews/live-edit/live/step-01-2.webp differdiff --git a/public/previews/live-edit/live/step-01-3.webp b/public/previews/live-edit/live/step-01-3.webpnew file mode 100644index 00000000..9374a5d7Binary files /dev/null and b/public/previews/live-edit/live/step-01-3.webp differdiff --git a/public/previews/live-edit/live/step-02-1.webp b/public/previews/live-edit/live/step-02-1.webpnew file mode 100644index 00000000..335b2873Binary files /dev/null and b/public/previews/live-edit/live/step-02-1.webp differdiff --git a/public/previews/live-edit/live/step-02-2.webp b/public/previews/live-edit/live/step-02-2.webpnew file mode 100644index 00000000..c5608769Binary files /dev/null and b/public/previews/live-edit/live/step-02-2.webp differdiff --git a/public/previews/live-edit/live/step-02-3.webp b/public/previews/live-edit/live/step-02-3.webpnew file mode 100644index 00000000..46e5ae5eBinary files /dev/null and b/public/previews/live-edit/live/step-02-3.webp differdiff --git a/public/previews/live-edit/live/step-03-1.webp b/public/previews/live-edit/live/step-03-1.webpnew file mode 100644index 00000000..241d4bdaBinary files /dev/null and b/public/previews/live-edit/live/step-03-1.webp differdiff --git a/public/previews/live-edit/live/step-03-2.webp b/public/previews/live-edit/live/step-03-2.webpnew file mode 100644index 00000000..f0baf9b1Binary files /dev/null and b/public/previews/live-edit/live/step-03-2.webp differdiff --git a/public/previews/live-edit/live/step-04-1.webp b/public/previews/live-edit/live/step-04-1.webpnew file mode 100644index 00000000..ce2b28bfBinary files /dev/null and b/public/previews/live-edit/live/step-04-1.webp differdiff --git a/public/previews/live-edit/live/step-05-1.webp b/public/previews/live-edit/live/step-05-1.webpnew file mode 100644index 00000000..6669291cBinary files /dev/null and b/public/previews/live-edit/live/step-05-1.webp differdiff --git a/public/previews/live-edit/live/step-05-2.webp b/public/previews/live-edit/live/step-05-2.webpnew file mode 100644index 00000000..0089e29aBinary files /dev/null and b/public/previews/live-edit/live/step-05-2.webp differdiff --git a/public/previews/live-edit/live/step-06-1.webp b/public/previews/live-edit/live/step-06-1.webpnew file mode 100644index 00000000..54b16fa1Binary files /dev/null and b/public/previews/live-edit/live/step-06-1.webp differdiff --git a/public/previews/live-edit/live/step-06-2.webp b/public/previews/live-edit/live/step-06-2.webpnew file mode 100644index 00000000..7266eea4Binary files /dev/null and b/public/previews/live-edit/live/step-06-2.webp differdiff --git a/public/previews/live-edit/live/step-07-1.webp b/public/previews/live-edit/live/step-07-1.webpnew file mode 100644index 00000000..37806a96Binary files /dev/null and b/public/previews/live-edit/live/step-07-1.webp differdiff --git a/public/previews/live-edit/live/step-07-2.webp b/public/previews/live-edit/live/step-07-2.webpnew file mode 100644index 00000000..a222254eBinary files /dev/null and b/public/previews/live-edit/live/step-07-2.webp differdiff --git a/public/previews/live-edit/live/step-08-1.webp b/public/previews/live-edit/live/step-08-1.webpnew file mode 100644index 00000000..f0d85914Binary files /dev/null and b/public/previews/live-edit/live/step-08-1.webp differdiff --git a/public/previews/live-edit/live/step-08-2.webp b/public/previews/live-edit/live/step-08-2.webpnew file mode 100644index 00000000..ed865904Binary files /dev/null and b/public/previews/live-edit/live/step-08-2.webp differdiff --git a/public/previews/live-edit/live/step-09-1.webp b/public/previews/live-edit/live/step-09-1.webpnew file mode 100644index 00000000..3fe4f200Binary files /dev/null and b/public/previews/live-edit/live/step-09-1.webp differdiff --git a/public/previews/live-edit/live/step-09-2.webp b/public/previews/live-edit/live/step-09-2.webpnew file mode 100644index 00000000..134924dbBinary files /dev/null and b/public/previews/live-edit/live/step-09-2.webp differdiff --git a/public/previews/live-edit/live/step-10-1.webp b/public/previews/live-edit/live/step-10-1.webpnew file mode 100644index 00000000..26b51c32Binary files /dev/null and b/public/previews/live-edit/live/step-10-1.webp differdiff --git a/public/previews/live-edit/live/step-10-2.webp b/public/previews/live-edit/live/step-10-2.webpnew file mode 100644index 00000000..d75bd3beBinary files /dev/null and b/public/previews/live-edit/live/step-10-2.webp differdiff --git a/public/previews/live-edit/live/step-11-1.webp b/public/previews/live-edit/live/step-11-1.webpnew file mode 100644index 00000000..23ae060cBinary files /dev/null and b/public/previews/live-edit/live/step-11-1.webp differdiff --git a/public/previews/live-edit/live/step-11-2.webp b/public/previews/live-edit/live/step-11-2.webpnew file mode 100644index 00000000..1face86cBinary files /dev/null and b/public/previews/live-edit/live/step-11-2.webp differdiff --git a/src/app/(studio)/live-edit/page.tsx b/src/app/(studio)/live-edit/page.tsxindex 4a8e2fe7..6dceadcb 100644--- a/src/app/(studio)/live-edit/page.tsx+++ b/src/app/(studio)/live-edit/page.tsx@@ -2,7 +2,7 @@ import type { Metadata } from "next";import { Suspense } from "react";import { LiveEditApp, LiveSkeleton } from "@/components/live/live-edit-app";-export const metadata: Metadata = { title: "Live edit", description: "Change a picture as you type, on your own GPU with Qwen-Image 2.1." };+export const metadata: Metadata = { title: "Live edit", description: "Change a picture as you type, on your own GPU." };export default function Page() {return (diff --git a/src/app/globals.css b/src/app/globals.cssindex 4867fe18..01656dd6 100644--- a/src/app/globals.css+++ b/src/app/globals.css@@ -668,6 +668,15 @@/* Live edit (src/components/live): a new frame fades in over the last; the demo dock's caret blinks. */@keyframes live-fade { from { opacity: 0; } to { opacity: 1; } }@keyframes live-caret { 50% { opacity: 0; } }+@keyframes live-chip { from { opacity: 0; translate: 6px 0; } to { opacity: 1; translate: 0 0; } }+/* A live frame is drawn across the picture: a soft edge travels left to right across the part the camera shows, and+ a faint line rides on it. The mask is 2.5 pictures wide; --sweep-from/--sweep-to and --scan-from/--scan-to come+ from sweepPath (src/lib/live/demo.ts). */+@keyframes live-sweep {+ from { -webkit-mask-image: linear-gradient(90deg, #000 46%, transparent 54%); mask-image: linear-gradient(90deg, #000 46%, transparent 54%); -webkit-mask-size: 250% 100%; mask-size: 250% 100%; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: var(--sweep-from, 100%) 0; mask-position: var(--sweep-from, 100%) 0; }+ to { -webkit-mask-image: linear-gradient(90deg, #000 46%, transparent 54%); mask-image: linear-gradient(90deg, #000 46%, transparent 54%); -webkit-mask-size: 250% 100%; mask-size: 250% 100%; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: var(--sweep-to, 0%) 0; mask-position: var(--sweep-to, 0%) 0; }+}+@keyframes live-scan { from { opacity: 1; transform: translateX(var(--scan-from, -10%)); } 85% { opacity: 1; } to { opacity: 0; transform: translateX(var(--scan-to, 110%)); } }@media (prefers-reduced-motion: reduce) {[data-live-stage] img, [data-live-demo] img { animation: none !important; transition: none !important; }}diff --git a/src/components/live/live-demo.tsx b/src/components/live/live-demo.tsxindex 679394c5..047805cd 100644--- a/src/components/live/live-demo.tsx+++ b/src/components/live/live-demo.tsx@@ -1,36 +1,70 @@"use client";import { Check, CornerDownLeft, Zap } from "lucide-react";-import { useEffect, useRef, useState } from "react";+import { type CSSProperties, useEffect, useLayoutEffect, useRef, useState } from "react";+import {+ cameraFor,+ type Demo,+ type DemoView,+ demoEnds,+ FADE_MS,+ frameOrder,+ KEEP_PULSE_MS,+ LIVE_DEMO,+ LIVE_DEMO_V,+ pillText,+ startView,+ stepsWord,+ SWEEP_MS,+ sweepPath,+ trailWindow,+ typeDelays,+ viewBefore,+ ZOOM_MAX,+ ZOOM_MS,+} from "@/lib/live/demo";import { cn } from "@/lib/utils";/**- * A recorded live edit session, played back: the text types itself into the dock, the picture follows, Keep pulses, a- * step joins the trail, and a compare sweep shows the before and after. It loops, pauses off screen and in a hidden- * tab, and under reduced motion it is a still before/after. No GPU, no requests: guests, Home and the Apps card see it.+ * A recorded live edit session, played back: the camera moves in on the area the step changes, the text types itself+ * into the dock, each live frame is drawn across the picture as it arrives, the full-quality picture settles, the+ * camera pulls back out, Keep pulses, a step joins the trail, and a compare sweep shows the original against the last+ * step. It loops, pauses off screen and+ * in a hidden tab and picks up where it stopped, and under reduced motion it is a still before/after. Frames load+ * only once the player is in view. No GPU, no requests beyond the files: guests, Home and the Apps card see it.*/-export const LIVE_DEMO = "/previews/live-edit/demo.json";--interface DemoFrame {- src: string;- small?: string;-}-type DemoStep =- /** live: a live frame (the pill says Live); the recording's real times join it once there are real-GPU numbers. */- | { type: "frame"; frame: string; live?: boolean; ms: number }- | { type: "type"; text: string; ms: number }- | { type: "keep"; label: string; ms: number }- | { type: "compare"; ms: number }- | { type: "pause"; ms: number };-interface Demo {- size: [number, number];- frames: Record<string, DemoFrame>;- script: DemoStep[];-}+export { LIVE_DEMO };let loaded: Promise<Demo | null> | null = null;-const loadDemo = () => (loaded ??= fetch(LIVE_DEMO).then((r) => (r.ok ? (r.json() as Promise<Demo>) : null)).catch(() => null));+// A failed fetch is not kept, so the next player tries again.+const loadDemo = () =>+ (loaded ??= fetch(`${LIVE_DEMO}?v=${LIVE_DEMO_V}`)+ .then((r) => (r.ok ? (r.json() as Promise<Demo>) : null))+ .catch(() => null)+ .then((d) => {+ if (!d) loaded = null;+ return d;+ }));++/** Each frame file is fetched and decoded once per page, however many players show it. */+const decoded = new Map<string, Promise<void>>();+function ready(url: string) {+ let p = decoded.get(url);+ if (!p) {+ const img = new Image();+ img.decoding = "async";+ img.src = url;+ // A failed decode is tried again the next time the frame is needed.+ p = img.decode().catch(() => {+ decoded.delete(url);+ });+ decoded.set(url, p);+ }+ return p;+}+/** A slow file never stalls the loop for long. */+const READY_CAP_MS = 1200;function useReducedMotion() {const [reduced, setReduced] = useState(false);@@ -44,23 +78,15 @@ function useReducedMotion() {return reduced;}-interface View {- frame: string;- /** The frame under it, fading out. */- under: string | null;- typed: string;- steps: string[];- keepPulse: boolean;- compare: number | null;- pill: string;-}-export function LiveDemo({ compact, className, onTypeAttempt }: { compact?: boolean; className?: string; onTypeAttempt?: () => void }) {const [demo, setDemo] = useState<Demo | null>(null);const reduced = useReducedMotion();const box = useRef<HTMLDivElement>(null);- const [visible, setVisible] = useState(true);- const [view, setView] = useState<View>({ frame: "before", under: null, typed: "", steps: [], keepPulse: false, compare: null, pill: "Live" });+ // Nothing plays or loads until the observer says the player is in view.+ const [visible, setVisible] = useState(false);+ const [view, setView] = useState<DemoView | null>(null);+ /** The script step to run next, kept across pauses so the loop picks up where it stopped. */+ const at = useRef(0);useEffect(() => {let alive = true;@@ -73,109 +99,221 @@ export function LiveDemo({ compact, className, onTypeAttempt }: { compact?: booluseEffect(() => {const el = box.current;if (!el) return;- const io = new IntersectionObserver(([e]) => setVisible(e.isIntersecting), { threshold: 0.15 });+ // One callback can carry several entries for the player; the newest is the one that counts.+ const io = new IntersectionObserver(+ (es) => {+ const e = es[es.length - 1];+ if (e) setVisible(e.isIntersecting && document.visibilityState === "visible");+ },+ { threshold: 0.15 },+ );io.observe(el);- const vis = () => setVisible((v) => v && document.visibilityState === "visible");- const back = () => document.visibilityState === "visible" && setVisible(el.getBoundingClientRect().bottom > 0);- document.addEventListener("visibilitychange", vis);- document.addEventListener("visibilitychange", back);+ const onVis = () => {+ if (document.visibilityState !== "visible") return setVisible(false);+ const r = el.getBoundingClientRect();+ setVisible(r.bottom > 0 && r.top < window.innerHeight);+ };+ document.addEventListener("visibilitychange", onVis);return () => {io.disconnect();- document.removeEventListener("visibilitychange", vis);- document.removeEventListener("visibilitychange", back);+ document.removeEventListener("visibilitychange", onVis);};}, []);+ const src = (id: string | null) => {+ const f = id ? demo?.frames[id] : undefined;+ return f ? (compact && f.small ? f.small : f.src) : "";+ };+// The player: one step at a time, each with its own small animation, then round again.useEffect(() => {if (!demo || reduced || !visible) return;let alive = true;const timers = new Set<ReturnType<typeof setTimeout>>();- const wait = (ms: number) => new Promise<void>((r) => timers.add(setTimeout(r, ms)));- const frameOf = (s: DemoStep) => (s.type === "frame" ? s.frame : null);- const first = demo.script.map(frameOf).find(Boolean) ?? Object.keys(demo.frames)[0];+ const wait = (ms: number) =>+ new Promise<void>((r) => {+ const t = setTimeout(() => {+ timers.delete(t);+ r();+ }, ms);+ timers.add(t);+ });+ const url = (id: string) => {+ const f = demo.frames[id];+ return f ? (compact && f.small ? f.small : f.src) : "";+ };+ const shown = (id: string) => Promise.race([ready(url(id)), wait(READY_CAP_MS)]);+ const order = frameOrder(demo);+ const { before, after } = demoEnds(demo);+ // Every frame starts loading now, in the order the script shows them.+ for (const id of order) void ready(url(id));void (async () => {+ await shown(order[0] ?? before);+ if (!alive) return;+ let i = at.current;+ let typed = "";+ if (i > 0) {+ const v = viewBefore(demo, i);+ typed = v.typed;+ setView(v);+ } else setView((v) => startView(before, v && v.frame !== before ? v.frame : null));while (alive) {- setView({ frame: first, under: null, typed: "", steps: [], keepPulse: false, compare: null, pill: "Live" });- let typed = "";- for (const s of demo.script) {+ for (; i < demo.script.length; i++) {if (!alive) return;+ at.current = i;+ const s = demo.script[i];if (s.type === "frame") {- setView((v) => ({ ...v, under: v.frame === s.frame ? v.under : v.frame, frame: s.frame, pill: s.live ? "Live" : v.pill }));+ await shown(s.frame);+ if (!alive) return;+ // The same frame again (the original at a new round) keeps its slower fade back.+ setView(+ (v) =>+ v && {+ ...v,+ under: v.frame === s.frame ? v.under : v.frame,+ frame: s.frame,+ fade: v.frame === s.frame ? v.fade : FADE_MS,+ sweep: !!s.live,+ ...(s.live ? { pill: "Live" as const } : {}),+ },+ );await wait(s.ms);+ } else if (s.type === "zoom") {+ setView((v) => v && { ...v, zoom: s.box });+ if (s.ms > 0) await wait(s.ms);} else if (s.type === "type") {- const per = Math.max(28, Math.floor(s.ms / Math.max(1, s.text.length)));- for (const ch of s.text) {+ const base = typed;+ const delays = typeDelays(s.text, s.ms);+ for (let c = 0; c < delays.length; c++) {if (!alive) return;- typed += ch;- const t = typed;- setView((v) => ({ ...v, typed: t }));- await wait(per + (ch === " " ? 40 : 0));+ const t = base + [...s.text].slice(0, c + 1).join("");+ setView((v) => v && { ...v, typed: t });+ await wait(delays[c]);}+ typed = base + s.text;} else if (s.type === "keep") {- setView((v) => ({ ...v, keepPulse: true }));- await wait(380);+ setView((v) => v && { ...v, keepPulse: true });+ await wait(KEEP_PULSE_MS);typed = "";- setView((v) => ({ ...v, keepPulse: false, typed: "", steps: [...v.steps, s.label], pill: "Kept ✓" }));- await wait(s.ms - 380);+ setView((v) => v && { ...v, keepPulse: false, typed: "", steps: [...v.steps, s.label], pill: "Kept ✓" });+ await wait(s.ms - KEEP_PULSE_MS);} else if (s.type === "compare") {const t0 = performance.now();while (alive && performance.now() - t0 < s.ms) {const p = (performance.now() - t0) / s.ms;- setView((v) => ({ ...v, compare: 50 + 42 * Math.sin(p * Math.PI * 2) }));+ setView((v) => v && { ...v, compare: 50 + 42 * Math.sin(p * Math.PI * 2) });await wait(33);}- setView((v) => ({ ...v, compare: null }));+ setView((v) => v && { ...v, compare: null });} else await wait(s.ms);}+ if (!alive) return;+ // Round again: the last picture fades back to the original.+ i = 0;+ at.current = 0;+ typed = "";+ setView((v) => startView(before, v ? (v.frame !== before ? v.frame : null) : after !== before ? after : null));}})();return () => {alive = false;for (const t of timers) clearTimeout(t);};- }, [demo, reduced, visible]);+ }, [demo, reduced, visible, compact]);- const src = (id: string | null) => {- const f = id ? demo?.frames[id] : undefined;- return f ? (compact && f.small ? f.small : f.src) : "";- };- const firstFrame = demo ? Object.keys(demo.frames)[0] : null;- const lastFrame = demo ? Object.keys(demo.frames).at(-1)! : null;+ const ends = demo ? demoEnds(demo) : null;+ // Under reduced motion the still compare shows, with nothing left over from a loop that was playing.+ const v = ends && (reduced || !view) ? startView(ends.before) : view;const ratio = demo ? `${demo.size[0]} / ${demo.size[1]}` : "4 / 3";+ const pill = v ? pillText(v, compact) : { main: "Live", count: null };+ const kept = v?.steps.length ?? 0;+ const showImages = visible || view !== null;+ // The small card keeps the whole picture: zoomed in, the typing bar would cover the change.+ const cam = cameraFor(v?.zoom ?? null, compact ? 1 : ZOOM_MAX);+ const sweep = sweepPath(cam);+ // The typed text fades on the left only once it is wider than the bar; short text shows whole.+ const typedOuter = useRef<HTMLSpanElement>(null);+ const typedInner = useRef<HTMLSpanElement>(null);+ const [clipped, setClipped] = useState(false);+ const typedNow = v?.typed ?? "";+ useLayoutEffect(() => {+ const o = typedOuter.current;+ const i = typedInner.current;+ setClipped(!!typedNow && !!o && !!i && i.offsetWidth > o.clientWidth + 1);+ }, [typedNow]);return (- <div ref={box} className={cn("relative isolate overflow-hidden rounded-2xl bg-media text-white", className)} style={{ aspectRatio: compact ? ratio : undefined }} data-live-demo>- {demo && (reduced ? (- <StillCompare before={src(firstFrame)} after={src(lastFrame)} />+ <div ref={box} className={cn("@container relative isolate overflow-hidden rounded-2xl bg-media text-white", className)} style={{ aspectRatio: compact ? ratio : undefined }} data-live-demo>+ {demo && ends && v && showImages && (reduced ? (+ <StillCompare before={src(ends.before)} after={src(ends.after)} steps={countKeeps(demo)} />) : (- <>- {/* eslint-disable-next-line @next/next/no-img-element */}- {view.under && <img key={`u-${view.under}`} src={src(view.under)} alt="" className="absolute inset-0 size-full object-cover" draggable={false} />}- {/* eslint-disable-next-line @next/next/no-img-element */}- <img key={`f-${view.frame}`} src={src(view.frame)} alt="A live edit of a portrait" className="absolute inset-0 size-full animate-[live-fade_140ms_ease-out] object-cover" draggable={false} />- {view.compare !== null && (+ // The camera: it glides in on the area a step changes while the live frames arrive, and back out to keep.+ <div+ className="absolute inset-0 origin-top-left"+ style={+ {+ transform: `translate(${cam.x * 100}%, ${cam.y * 100}%) scale(${cam.s})`,+ transition: `transform ${ZOOM_MS}ms cubic-bezier(.45,0,.2,1)`,+ "--sweep-from": `${sweep.from}%`,+ "--sweep-to": `${sweep.to}%`,+ "--scan-from": `${sweep.scanFrom}%`,+ "--scan-to": `${sweep.scanTo}%`,+ } as CSSProperties+ }+ data-live-camera={cam.s > 1 ? cam.s : undefined}+ >+ {/* Both pictures sit in one keyed list, so the frame that drops underneath keeps its painted image. */}+ {[v.under, v.frame]+ .filter((id): id is string => !!id)+ .map((id) => {+ const top = id === v.frame;+ return (+ // eslint-disable-next-line @next/next/no-img-element+ <img+ key={id}+ src={src(id)}+ alt={top ? "A live edit of a portrait" : ""}+ className="absolute inset-0 size-full object-cover"+ style={top ? { animation: v.sweep ? `live-sweep ${SWEEP_MS}ms cubic-bezier(.45,0,.55,1)` : v.fade ? `live-fade ${v.fade}ms ease-out` : "none" } : undefined}+ onError={+ top+ ? (e) => {+ e.currentTarget.style.visibility = "hidden";+ }+ : undefined+ }+ draggable={false}+ />+ );+ })}+ {/* The leading edge of a live frame as it is drawn across. */}+ {v.sweep && (+ <span key={`s-${v.frame}`} className="pointer-events-none absolute inset-0 opacity-0" style={{ animation: `live-scan ${SWEEP_MS}ms cubic-bezier(.45,0,.55,1)` }} aria-hidden>+ <span className="absolute inset-y-0 left-0 w-10 -translate-x-1/2 bg-gradient-to-r from-transparent via-white/25 to-transparent" />+ <span className="absolute inset-y-0 left-0 w-px -translate-x-1/2 bg-white/70 shadow-[0_0_10px_rgba(255,255,255,.6)]" />+ </span>+ )}+ {v.compare !== null && (<>{/* eslint-disable-next-line @next/next/no-img-element */}- <img src={src(firstFrame)} alt="" className="absolute inset-0 size-full object-cover" style={{ clipPath: `inset(0 ${100 - view.compare}% 0 0)` }} draggable={false} />- <span className="absolute inset-y-0 w-0.5 bg-white shadow-[0_0_8px_rgba(0,0,0,.5)]" style={{ left: `${view.compare}%` }} />+ <img src={src(ends.before)} alt="" className="absolute -inset-px object-cover" style={{ width: "calc(100% + 2px)", height: "calc(100% + 2px)", clipPath: `inset(-2px ${100 - v.compare}% -2px 0)` }} draggable={false} />+ <span className="absolute inset-y-0 w-0.5 bg-white shadow-[0_0_8px_rgba(0,0,0,.5)]" style={{ left: `${v.compare}%` }} /></>)}- </>+ </div>))}<div className="pointer-events-none absolute inset-0 bg-gradient-to-t from-black/70 via-black/0 to-black/10" />- <span className={cn("absolute inline-flex items-center gap-1.5 rounded-full bg-black/45 font-medium backdrop-blur", compact ? "top-1.5 left-1.5 px-2 py-0.5 text-[10.5px]" : "top-3 left-3 px-2.5 py-1 text-[11px]")} role="status" aria-live="off">- <span className="size-1.5 animate-pulse rounded-full bg-emerald-400" />- {view.pill}+ <span className={cn("absolute inline-flex items-center gap-1.5 rounded-full bg-black/45 font-medium whitespace-nowrap backdrop-blur", compact ? "top-1.5 left-1.5 px-2 py-0.5 text-[10.5px]" : "top-3 left-3 px-2.5 py-1 text-[11px]")} role="status" aria-live="off">+ <span className="size-1.5 rounded-full bg-emerald-400 motion-safe:animate-pulse" />+ {pill.main}+ {pill.count && <span className="text-white/75">· {pill.count}</span>}</span>- {!compact && view.steps.length > 0 && (- <div className="absolute top-3 right-3 flex max-w-[60%] items-center gap-1 overflow-hidden text-[11px]">+ {/* The compare sweep has its own labels; the trail steps aside while it plays. */}+ {!compact && v && <DemoTrail steps={v.steps} hidden={v.compare !== null} />}+ {v && v.compare !== null && (+ <div className={cn("pointer-events-none absolute inset-x-3 flex justify-between text-[11px] font-medium", compact ? "inset-x-2 bottom-12" : "bottom-16")} data-live-compare><span className="rounded-full bg-black/45 px-2 py-0.5 backdrop-blur">Original</span>- {view.steps.map((s, i) => (- <span key={i} className="truncate rounded-full bg-white/90 px-2 py-0.5 font-medium text-black">- {i + 1} · {s}- </span>- ))}+ <span className="rounded-full bg-white/90 px-2 py-0.5 text-black">{stepsWord(kept)}</span></div>)}<div className={cn("absolute inset-x-3 bottom-3 flex items-center gap-2", compact && "inset-x-2 bottom-2")}>@@ -187,12 +325,24 @@ export function LiveDemo({ compact, className, onTypeAttempt }: { compact?: boolaria-label="Type a change"><Zap className={cn("shrink-0 text-amber-300", compact ? "size-3" : "size-3.5")} />- {/* The end of the text stays in view as it grows. */}- <span className={cn("flex min-w-0 overflow-hidden whitespace-nowrap", view.typed && "justify-end")}>{view.typed || <span className="text-white/55">Type a change…</span>}</span>- <span className="-ml-1.5 h-4 w-px shrink-0 animate-[live-caret_1s_steps(1)_infinite] bg-white/80" />+ {/* The end of the text stays in view as it grows; text cut off on the left fades out rather than ending mid-letter. */}+ <span+ ref={typedOuter}+ className={cn("flex min-w-0 overflow-hidden whitespace-nowrap", v?.typed && "justify-end", v?.typed && clipped && "[mask-image:linear-gradient(90deg,transparent,#000_1.25rem)]")}+ data-live-typed-clipped={(v?.typed && clipped) || undefined}+ >+ {v?.typed ? (+ <span ref={typedInner} className="shrink-0" data-live-typed>+ {v.typed}+ </span>+ ) : (+ <span className="truncate text-white/55">Type a change…</span>+ )}+ </span>+ <span className="-ml-1.5 h-4 w-px shrink-0 bg-white/80 motion-safe:animate-[live-caret_1s_steps(1)_infinite]" /></button>- <span className={cn("inline-flex shrink-0 items-center justify-center gap-1 rounded-xl bg-white font-medium text-black transition-transform", compact ? "size-8" : "h-11 px-3.5 text-[13px]", view.keepPulse && "scale-95 ring-4 ring-primary/60")} aria-label={compact ? "Keep" : undefined}>- {view.steps.length && !view.typed ? <Check className="size-3.5" /> : <CornerDownLeft className="size-3.5" />}+ <span className={cn("inline-flex shrink-0 items-center justify-center gap-1 rounded-xl bg-white font-medium text-black transition-transform", compact ? "size-8" : "h-11 px-3.5 text-[13px]", v?.keepPulse && "scale-95 ring-4 ring-primary/60")} aria-label={compact ? "Keep" : undefined}>+ {kept && !v?.typed ? <Check className="size-3.5" /> : <CornerDownLeft className="size-3.5" />}{!compact && "Keep"}</span></div>@@ -200,7 +350,68 @@ export function LiveDemo({ compact, className, onTypeAttempt }: { compact?: bool);}-function StillCompare({ before, after }: { before: string; after: string }) {+const countKeeps = (d: Demo) => d.script.filter((s) => s.type === "keep").length;++/**+ * The kept steps, as the editor shows them: Original › +N › the newest step(s), the newest one whole and lit. One step+ * fits a phone-width player; three from a wider one. The player's own width decides (a container query), not the+ * window's, so Home's half-width player and a full-width phone each get the right count.+ */+export function DemoTrail({ steps, hidden }: { steps: readonly string[]; hidden?: boolean }) {+ if (!steps.length) return null;+ const wide = trailWindow(steps, 3);+ const narrow = trailWindow(steps, 1);+ const sep = <span className="shrink-0 text-white/70">›</span>;+ return (+ <div+ className={cn("pointer-events-none absolute top-3 right-3 flex max-w-[calc(100%-6.5rem)] min-w-0 items-center gap-1 text-[11px] transition-opacity duration-300", hidden && "opacity-0")}+ aria-hidden={hidden || undefined}+ data-live-trail+ >+ {/* On a narrow player, once earlier steps fold into a count, Original steps aside to keep the picture clear. */}+ <span className={cn("shrink-0 rounded-full bg-black/45 px-2 py-0.5 backdrop-blur", narrow.hidden > 0 && "@max-md:hidden")} data-live-original>+ Original+ </span>+ {narrow.hidden > 0 && (+ <span className="contents @md:hidden">+ <span className="shrink-0 rounded-full bg-black/45 px-1.5 py-0.5 tabular-nums backdrop-blur" title={`${stepsWord(narrow.hidden)} before`} data-live-more={narrow.hidden}>+ +{narrow.hidden}+ </span>+ </span>+ )}+ {wide.hidden > 0 && (+ <span className="contents @max-md:hidden">+ {sep}+ <span className="shrink-0 rounded-full bg-black/45 px-1.5 py-0.5 tabular-nums backdrop-blur" title={`${stepsWord(wide.hidden)} before`} data-live-more={wide.hidden}>+ +{wide.hidden}+ </span>+ </span>+ )}+ {wide.shown.map(({ n, label }) => {+ const newest = n === steps.length;+ return (+ <span key={n} className={cn("contents", !newest && "@max-md:hidden")}>+ {sep}+ <span+ className={cn(+ "min-w-0 truncate rounded-full px-2 py-0.5",+ newest ? "max-w-[12rem] bg-white/95 font-medium text-black ring-2 ring-primary/60 animate-[live-chip_260ms_ease-out]" : "max-w-[8rem] shrink-[3] bg-white/70 text-black/80",+ )}+ title={label}+ data-live-chip={n}+ data-newest={newest || undefined}+ aria-current={newest ? "step" : undefined}+ >+ {n} · {label}+ </span>+ </span>+ );+ })}+ </div>+ );+}++function StillCompare({ before, after, steps }: { before: string; after: string; steps: number }) {const [pos, setPos] = useState(50);return (<div className="absolute inset-0">@@ -210,6 +421,12 @@ function StillCompare({ before, after }: { before: string; after: string }) {<img src={before} alt="Before" className="absolute inset-0 size-full object-cover" style={{ clipPath: `inset(0 ${100 - pos}% 0 0)` }} /><input type="range" min={0} max={100} value={pos} onChange={(e) => setPos(Number(e.target.value))} aria-label="Compare before and after" className="absolute inset-x-6 top-1/2 opacity-0" /><span className="pointer-events-none absolute inset-y-0 w-0.5 bg-white" style={{ left: `${pos}%` }} />+ {steps > 0 && (+ <div className="pointer-events-none absolute inset-x-3 top-12 flex justify-between text-[11px] font-medium">+ <span className="rounded-full bg-black/45 px-2 py-0.5 backdrop-blur">Original</span>+ <span className="rounded-full bg-white/90 px-2 py-0.5 text-black">{stepsWord(steps)}</span>+ </div>+ )}</div>);}diff --git a/src/components/live/live-edit-app.tsx b/src/components/live/live-edit-app.tsxindex 2074760d..e9d4a708 100644--- a/src/components/live/live-edit-app.tsx+++ b/src/components/live/live-edit-app.tsx@@ -77,11 +77,11 @@ export function LiveEditPanel({ image, text, onUse, onClose }: { image?: string;const live = useLiveTransport();if (live.s === "ready") return <LiveEditor variant="embedded" transport={live.transport} image={fileParam(image ?? null)} text={text} from="edit" canSave={live.owner} onUse={onUse} onClose={onClose} />;return (- <div className="grid h-full place-items-center rounded-2xl border p-4" data-live-panel>+ <div className="grid h-full place-items-center rounded-2xl border p-2 sm:p-4" data-live-panel>{live.s === "loading" ? (<span className="text-[13px] text-muted-foreground">Starting Live edit…</span>) : (- <div className="grid w-full max-w-3xl items-center gap-5 md:grid-cols-[1.3fr_1fr]">+ <div className="grid w-full max-w-5xl items-center gap-5 md:grid-cols-[1.3fr_1fr]"><LiveDemo className="aspect-[4/3] w-full" /><div><p className="font-heading text-[24px] leading-tight">Change it as you type</p>@@ -142,7 +142,7 @@ function LiveShowcase({ kind }: { kind: "guest" | "connect" | "unsupported" }) {<div className="max-w-md"><p className="font-heading text-[34px] leading-[1.08] text-balance sm:text-[40px]">Change a picture as you type</p><p className="mt-3 text-[15px] leading-relaxed text-muted-foreground text-pretty">- Type a change and the picture follows in under a second. Press Enter to keep it, then type the next. Every kept step is a lossless full-size master, so nothing blurs, however many changes you stack.+ Type a change and watch the picture follow. Press Enter to keep it, then type the next. Every kept step is a lossless full-size master, so nothing blurs, however many changes you stack.</p><ul className="mt-4 space-y-1.5 text-[13.5px]">{["Live frames as you type, on your own GPU", "Keep, undo and redo every step", "Paint a region to change only that", "Compare with the step before or the original"].map((t) => (@@ -186,7 +186,7 @@ function LiveShowcase({ kind }: { kind: "guest" | "connect" | "unsupported" }) {)}</div><p className="mt-4 text-[12px] text-muted-foreground">- Qwen-Image 2.1 with the DMD2 2-step LoRA · non-commercial weights ·{" "}+ Runs on your own GPU ·{" "}<Link href="/settings/about" className="underline-offset-2 hover:underline">licence</Link>diff --git a/src/lib/home-showcase.ts b/src/lib/home-showcase.tsindex 39a58431..2d3b4b8a 100644--- a/src/lib/home-showcase.ts+++ b/src/lib/home-showcase.ts@@ -113,7 +113,7 @@ export const HOME_OWN_SECTIONS = ["/assist", "/motions", "/effects", "/apps", "/export const HOME_LIVE = {href: "/live-edit?from=home",title: "Change it as you type",- line: "Type a change and watch the picture follow in under a second. Keep what you like; nothing blurs, however many changes you stack.",+ line: "Type a change and watch the picture follow. Keep what you like; nothing blurs, however many changes you stack.",};/** Assist's starter skills, as its empty chat lists them first (assist-view.tsx). */diff --git a/src/lib/live/demo.ts b/src/lib/live/demo.tsnew file mode 100644index 00000000..b6495517--- /dev/null+++ b/src/lib/live/demo.ts@@ -0,0 +1,238 @@+/**+ * The recorded live edit session that guests, Home and the Apps card see (public/previews/live-edit/demo.json), and+ * the pure parts of its player: how long each step takes, where a paused loop picks up again, which frames are the+ * before and after, where the camera sits when it zooms in on a change, and which kept steps the trail shows. The+ * player itself is src/components/live/live-demo.tsx.+ */++export const LIVE_DEMO = "/previews/live-edit/demo.json";+/**+ * The file's content version: the first 8 hex digits of the SHA-256 of demo.json (line endings as \n). The player+ * fetches the file with it (?v=), so a new session reaches returning visitors at once; a test keeps it in step.+ */+export const LIVE_DEMO_V = "61b6e096";++/** A trail chip's label stays readable on a phone: the longer instruction is the typed text. */+export const CHIP_MAX = 18;+/** The Keep button's pulse, before the step joins the trail. */+export const KEEP_PULSE_MS = 380;+/** A typed character never goes faster than this. */+export const TYPE_MIN_CHAR_MS = 28;+/** A space waits a little longer, the way people type. */+export const TYPE_SPACE_MS = 40;+/** The picture fades in over the last one; at the loop's restart it fades back to the original more slowly. */+export const FADE_MS = 140;+export const REWIND_MS = 320;+/** One full round stays short enough to watch to the end. */+export const LOOP_MAX_MS = 45_000;+/** A live frame is drawn across the picture, left to right, in this long. */+export const SWEEP_MS = 520;+/** The camera glides in on the area a step changes, and back out, in this long. */+export const ZOOM_MS = 700;+/** It never comes closer than this, so a live frame stays crisp enough to read. */+export const ZOOM_MAX = 1.7;+/** Room left around the changed area, as a share of its size on each side. */+export const ZOOM_PAD = 0.12;++export interface DemoFrame {+ /** 960 px wide. It may end in ?v= and the first 8 hex digits of the file's SHA-256, so a new file is never served from cache. */+ src: string;+ /** 512 px wide, for the small card. */+ small?: string;+}++/** An area of the picture, as shares of its width and height: [left, top, right, bottom]. */+export type Box = [number, number, number, number];++export type DemoStep =+ /** live: a live frame (the pill says Live); it is drawn across the picture rather than faded in. */+ | { type: "frame"; frame: string; live?: boolean; ms: number }+ | { type: "type"; text: string; ms: number }+ | { type: "keep"; label: string; ms: number }+ /** from/to: the frames to compare (the script's first and last frames when left out). */+ | { type: "compare"; ms: number; from?: string; to?: string }+ | { type: "pause"; ms: number }+ /**+ * The camera glides in on the area the step changes (box), or back out to the whole picture (null). The glide takes+ * ZOOM_MS whatever `ms` is; `ms` is how long the script waits before its next step (0 lets the next one start at once).+ */+ | { type: "zoom"; box: Box | null; ms: number };++export interface Demo {+ v?: number;+ size: [number, number];+ frames: Record<string, DemoFrame>;+ script: DemoStep[];+}++/** Each character's wait, so a type step takes its `ms` (or longer, when that would mean typing too fast). */+export function typeDelays(text: string, ms: number): number[] {+ const chars = [...text];+ if (!chars.length) return [];+ const spaces = chars.filter((c) => c === " ").length;+ const per = Math.max(TYPE_MIN_CHAR_MS, Math.floor((ms - spaces * TYPE_SPACE_MS) / chars.length));+ return chars.map((c) => per + (c === " " ? TYPE_SPACE_MS : 0));+}++export function stepMs(s: DemoStep): number {+ if (s.type === "type") return typeDelays(s.text, s.ms).reduce((a, b) => a + b, 0);+ if (s.type === "keep") return Math.max(KEEP_PULSE_MS, s.ms);+ return s.ms;+}++/** One round of the loop. */+export const loopMs = (d: Pick<Demo, "script">) => d.script.reduce((a, s) => a + stepMs(s), 0);++/** The original and the final picture: the compare step's, or the script's first and last frames. */+export function demoEnds(d: Demo): { before: string; after: string } {+ const shown = d.script.flatMap((s) => (s.type === "frame" ? [s.frame] : []));+ const keys = Object.keys(d.frames);+ const cmp = d.script.find((s) => s.type === "compare");+ return {+ before: (cmp?.type === "compare" && cmp.from) || shown[0] || keys[0],+ after: (cmp?.type === "compare" && cmp.to) || shown.at(-1) || keys.at(-1) || keys[0],+ };+}++/** The frame ids in the order the script shows them, each once. */+export const frameOrder = (d: Pick<Demo, "script">) => [...new Set(d.script.flatMap((s) => (s.type === "frame" ? [s.frame] : [])))];++export interface DemoView {+ frame: string;+ /** The frame under it, fading out. */+ under: string | null;+ /** How long the frame on top fades in; 0 shows it at once (a loop picking up again). */+ fade: number;+ /** The frame on top is drawn across the picture (a live frame) rather than faded in. */+ sweep: boolean;+ typed: string;+ steps: string[];+ keepPulse: boolean;+ compare: number | null;+ pill: "Live" | "Kept ✓";+ /** The area the camera is on; null is the whole picture. */+ zoom: Box | null;+}++export const startView = (frame: string, under: string | null = null): DemoView => ({+ frame,+ under,+ fade: under ? REWIND_MS : FADE_MS,+ sweep: false,+ typed: "",+ steps: [],+ keepPulse: false,+ compare: null,+ pill: "Live",+ zoom: null,+});++/**+ * The view just before script step `at` runs: where a loop paused off screen picks up again. Its picture is shown at+ * once, with no fade from the dark background behind it.+ */+export function viewBefore(d: Demo, at: number): DemoView {+ const v = { ...startView(demoEnds(d).before), fade: 0 };+ for (const s of d.script.slice(0, at)) {+ if (s.type === "frame") Object.assign(v, { frame: s.frame, sweep: false, ...(s.live ? { pill: "Live" } : {}) });+ else if (s.type === "type") v.typed += s.text;+ else if (s.type === "keep") Object.assign(v, { typed: "", steps: [...v.steps, s.label], pill: "Kept ✓" });+ else if (s.type === "zoom") v.zoom = s.box;+ }+ return v;+}++/**+ * Where the camera sits to show `box` large: a scale and a shift, both as shares of the picture, for+ * `translate(x, y) scale(s)` from the top-left corner. The area is centred where it can be; the picture always fills+ * the frame, and the camera never comes closer than ZOOM_MAX. An area that already fills most of the picture keeps+ * the whole picture.+ */+export function cameraFor(box: Box | null, max = ZOOM_MAX): { s: number; x: number; y: number } {+ if (!box) return { s: 1, x: 0, y: 0 };+ const [l, t, r, b] = box;+ const w = (r - l) * (1 + 2 * ZOOM_PAD);+ const h = (b - t) * (1 + 2 * ZOOM_PAD);+ const fit = Math.min(max, 1 / Math.max(w, 1e-3), 1 / Math.max(h, 1e-3));+ if (fit < 1.15) return { s: 1, x: 0, y: 0 };+ const s = Math.round(fit * 100) / 100;+ const shift = (c: number) => Math.min(0, Math.max(1 - s, 0.5 - s * c));+ return { s, x: shift((l + r) / 2), y: shift((t + b) / 2) };+}++/**+ * Where a live frame's sweep starts and ends, so its soft edge crosses exactly the part of the picture the camera+ * shows. The new frame is masked by a gradient 2.5 picture-widths wide (opaque to 46 %, clear from 54 %, see+ * live-sweep in globals.css); `from`/`to` are its mask-position (%), and `scanFrom`/`scanTo` where the bright line+ * riding the edge goes (% of the picture's width). The edge starts just left of the view and ends just right of it.+ */+export function sweepPath(cam: { s: number; x: number }) {+ const M = 2.5;+ const half = ((0.54 - 0.46) / 2) * M;+ const centre = 0.5 * M;+ const left = -cam.x / cam.s - half;+ const right = (1 - cam.x) / cam.s + half;+ const pos = (c: number) => Math.round(((centre - c) / (M - 1)) * 1000) / 10;+ const pct = (c: number) => Math.round(c * 1000) / 10;+ return { from: pos(left), to: pos(right), scanFrom: pct(left), scanTo: pct(right) };+}++const isBox = (b: unknown): b is Box =>+ Array.isArray(b) && b.length === 4 && b.every((n) => typeof n === "number" && n >= 0 && n <= 1) && b[0] < b[2] && b[1] < b[3];++/** The pill's words: compact cards add the step count after a keep. */+export function pillText(v: Pick<DemoView, "pill" | "steps">, compact = false) {+ const count = compact && v.pill === "Kept ✓" && v.steps.length > 1 ? String(v.steps.length) : null;+ return { main: v.pill, count };+}++/** A frame's file, without the ?v= content version. */+export const framePath = (src: string) => src.split("?")[0];++/** The trail: Original, how many earlier steps are folded away, then the newest `keep` steps (numbered from 1). */+export function trailWindow(steps: readonly string[], keep: number) {+ const from = Math.max(0, steps.length - keep);+ return { hidden: from, shown: steps.slice(from).map((label, i) => ({ n: from + i + 1, label })) };+}++export const stepsWord = (n: number) => `${n} ${n === 1 ? "step" : "steps"}`;++/** What is wrong with a demo file, in words; empty when it plays. `exists` checks that a frame's file is there. */+export function demoProblems(d: Demo, exists?: (src: string) => boolean): string[] {+ const out: string[] = [];+ if (!Array.isArray(d.size) || d.size.length !== 2 || d.size.some((n) => !(n > 0))) out.push("size must be [width, height]");+ const ids = Object.keys(d.frames ?? {});+ if (!ids.length) out.push("no frames");+ for (const [id, f] of Object.entries(d.frames ?? {})) {+ for (const src of [f.src, f.small].filter(Boolean) as string[]) {+ if (!src.startsWith("/previews/")) out.push(`frame ${id}: ${src} is not under /previews/`);+ else if (exists && !exists(framePath(src))) out.push(`frame ${id}: ${src} is missing`);+ }+ }+ if (!d.script?.length) return [...out, "no script"];+ if (d.script[0].type !== "frame") out.push("the script must start with a frame");+ const used = new Set<string>();+ d.script.forEach((s, i) => {+ if (s.type === "zoom") {+ if (!(Number.isFinite(s.ms) && s.ms >= 0)) out.push(`step ${i}: ms must be 0 or more`);+ if (s.box !== null && !isBox(s.box)) out.push(`step ${i}: a zoom box is [left, top, right, bottom], each 0 to 1`);+ return;+ }+ if (!(Number.isFinite(s.ms) && s.ms > 0)) out.push(`step ${i}: ms must be positive`);+ if (s.type === "frame") {+ if (s.live && s.ms < SWEEP_MS) out.push(`step ${i}: a live frame shows for at least ${SWEEP_MS} ms`);+ used.add(s.frame);+ if (!d.frames[s.frame]) out.push(`step ${i}: no frame ${s.frame}`);+ } else if (s.type === "type") {+ if (!s.text) out.push(`step ${i}: nothing to type`);+ } else if (s.type === "keep") {+ if (!s.label || s.label.length > CHIP_MAX) out.push(`step ${i}: a keep label is 1 to ${CHIP_MAX} characters`);+ if (s.ms < KEEP_PULSE_MS) out.push(`step ${i}: a keep lasts at least ${KEEP_PULSE_MS} ms`);+ } else if (s.type === "compare") {+ for (const f of [s.from, s.to]) if (f && !d.frames[f]) out.push(`step ${i}: no frame ${f}`);+ } else if (s.type !== "pause") out.push(`step ${i}: unknown step`);+ });+ for (const id of ids) if (!used.has(id)) out.push(`frame ${id} is never shown`);+ if (loopMs(d) > LOOP_MAX_MS) out.push(`one round takes ${loopMs(d)} ms, over ${LOOP_MAX_MS}`);+ return out;+}diff --git a/tests/live-demo.test.ts b/tests/live-demo.test.tsnew file mode 100644index 00000000..d0bc4b00--- /dev/null+++ b/tests/live-demo.test.ts@@ -0,0 +1,318 @@+import { createHash } from "node:crypto";+import fs from "node:fs";+import path from "node:path";+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it } from "vitest";+import { DemoTrail } from "@/components/live/live-demo";+import {+ type Box,+ cameraFor,+ CHIP_MAX,+ type Demo,+ type DemoStep,+ demoEnds,+ demoProblems,+ frameOrder,+ framePath,+ KEEP_PULSE_MS,+ LIVE_DEMO,+ LIVE_DEMO_V,+ LOOP_MAX_MS,+ loopMs,+ pillText,+ stepMs,+ SWEEP_MS,+ sweepPath,+ trailWindow,+ typeDelays,+ viewBefore,+ ZOOM_MAX,+ ZOOM_MS,+} from "@/lib/live/demo";++/*+ * The recorded live edit session (public/previews/live-edit/demo.json) and its player (src/lib/live/demo.ts,+ * src/components/live/live-demo.tsx): the file plays, every frame is there, one round stays short, and a long session+ * keeps its trail readable.+ */++const PUBLIC = path.join(__dirname, "..", "public");+const exists = (src: string) => fs.existsSync(path.join(PUBLIC, src));+const shippedText = fs.readFileSync(path.join(PUBLIC, LIVE_DEMO), "utf8").replace(/\r\n/g, "\n");+const shipped = JSON.parse(shippedText) as Demo;++/**+ * An eleven-step session in the shape of the shipped one: the camera moves in on the changed area, partial live frames+ * arrive while typing, the camera pulls back out as the settled one arrives, then the keep. The two big changes keep+ * the whole picture.+ */+const LABELS = ["Red lips", "Hair down", "Gold hoops", "Velvet gown", "Diamond choker", "Red rose", "Fur stole", "Ballroom", "Spotlight", "Soft smile", "Cinematic grade"];+function longSession(): Demo {+ const frames: Demo["frames"] = { s0: { src: "/previews/x/960/step-00.jpg", small: "/previews/x/512/step-00.jpg" } };+ const script: DemoStep[] = [{ type: "frame", frame: "s0", ms: 800 }];+ LABELS.forEach((label, i) => {+ const n = String(i + 1).padStart(2, "0");+ const early = i < 2;+ frames[`s${i + 1}a`] = { src: `/previews/x/960/step-${n}a.jpg` };+ frames[`s${i + 1}`] = { src: `/previews/x/960/step-${n}.jpg` };+ const box: Box | null = label === "Ballroom" || label === "Spotlight" ? null : [0.4, 0.3, 0.6, 0.6];+ if (box) script.push({ type: "zoom", box, ms: 200 });+ script.push(+ { type: "type", text: label.toLowerCase(), ms: early ? 700 : 450 },+ { type: "frame", frame: `s${i + 1}a`, live: true, ms: early ? 600 : 540 },+ { type: "type", text: " please", ms: early ? 500 : 300 },+ );+ if (box) script.push({ type: "zoom", box: null, ms: 0 });+ script.push({ type: "frame", frame: `s${i + 1}`, ms: early ? 700 : 560 }, { type: "keep", label, ms: early ? 900 : 700 });+ });+ script.push({ type: "compare", ms: 3400 }, { type: "pause", ms: 1200 });+ return { v: 2, size: [960, 720], frames, script };+}++describe("the shipped demo", () => {+ it("plays: every frame file is there, every step is valid, one round is short", () => {+ expect(demoProblems(shipped, exists)).toEqual([]);+ expect(loopMs(shipped)).toBeLessThanOrEqual(LOOP_MAX_MS);+ });++ it("is one session of eleven kept steps, each settled picture shown before its keep", () => {+ const keeps = shipped.script.flatMap((s, i) => (s.type === "keep" ? [i] : []));+ expect(keeps).toHaveLength(11);+ for (const [k, i] of keeps.entries()) {+ const prev = shipped.script[i - 1];+ expect(prev).toMatchObject({ type: "frame", frame: `s${k + 1}` });+ expect(prev.type === "frame" && prev.live).toBeFalsy();+ }+ expect(shipped.script.at(-2)?.type).toBe("compare");+ expect(Object.keys(shipped.frames)[0]).toBe("s0");+ for (const id of Object.keys(shipped.frames)) expect(id).not.toMatch(/^\d+$/);+ });++ it("is fetched at its content version, and so is every frame", () => {+ const sha8 = (b: Buffer | string) => createHash("sha256").update(b).digest("hex").slice(0, 8);+ expect(sha8(shippedText)).toBe(LIVE_DEMO_V);+ for (const f of Object.values(shipped.frames)) {+ for (const src of [f.src, f.small].filter(Boolean) as string[]) {+ expect(src).toMatch(/\?v=[0-9a-f]{8}$/);+ expect(src.split("?v=")[1]).toBe(sha8(fs.readFileSync(path.join(PUBLIC, framePath(src)))));+ }+ }+ });++ it("compares the original with the last picture, whatever order the frames are listed in", () => {+ const ends = demoEnds(shipped);+ const order = frameOrder(shipped);+ expect(ends).toEqual({ before: order[0], after: order.at(-1) });+ const shuffled: Demo = { ...shipped, frames: Object.fromEntries(Object.entries(shipped.frames).reverse()) };+ expect(demoEnds(shuffled)).toEqual(ends);+ });++ it("zooms in on every small change, and back out before the settled picture", () => {+ let zoom: Box | null = null;+ let zoomed = 0;+ for (const s of shipped.script) {+ if (s.type === "zoom") {+ zoom = s.box;+ // A zoom that would keep the whole picture is left out.+ if (s.box) expect(cameraFor(s.box).s).toBeGreaterThan(1);+ if (s.box) zoomed++;+ }+ if (s.type === "keep" || s.type === "compare" || (s.type === "frame" && !s.live)) expect(zoom).toBeNull();+ }+ expect(zoomed).toBeGreaterThanOrEqual(4);+ });++ it("starts each step's first live frame once the camera has finished moving in", () => {+ shipped.script.forEach((s, i) => {+ if (s.type !== "zoom" || !s.box) return;+ let ms = s.ms;+ for (const n of shipped.script.slice(i + 1)) {+ if (n.type === "frame") break;+ ms += stepMs(n);+ }+ expect(ms).toBeGreaterThanOrEqual(ZOOM_MS);+ });+ });++ it("shows each live frame long enough to be drawn across and seen", () => {+ for (const s of shipped.script) if (s.type === "frame" && s.live) expect(s.ms).toBeGreaterThanOrEqual(SWEEP_MS);+ });++ it("shows no timings: the pill says Live or Kept, nothing more", () => {+ expect(shippedText).not.toMatch(/Ms"\s*:/);+ });+});++describe("timing", () => {+ it("types in the time the script gives, spaces a little slower", () => {+ const d = typeDelays("deep red lips", 1300);+ expect(d.reduce((a, b) => a + b, 0)).toBeLessThanOrEqual(1300);+ expect(d.reduce((a, b) => a + b, 0)).toBeGreaterThan(1300 - 13);+ expect(d[4] - d[3]).toBe(40);+ });++ it("never types faster than a person can read", () => {+ expect(Math.min(...typeDelays("a very long instruction typed in no time at all", 100))).toBeGreaterThanOrEqual(28);+ });++ it("holds a keep for at least its pulse", () => {+ expect(stepMs({ type: "keep", label: "x", ms: 100 })).toBe(KEEP_PULSE_MS);+ });+});++describe("an eleven-step session", () => {+ const d = longSession();+ const without = (src: string) => !src.includes("/x/");++ it("is valid apart from its stand-in files, and one round takes about half a minute", () => {+ expect(demoProblems(d)).toEqual([]);+ expect(demoProblems(d, without).every((p) => p.endsWith("is missing"))).toBe(true);+ expect(loopMs(d)).toBeGreaterThan(28_000);+ expect(loopMs(d)).toBeLessThanOrEqual(LOOP_MAX_MS);+ });++ it("compares the original with the eleventh step", () => {+ expect(demoEnds(d)).toEqual({ before: "s0", after: "s11" });+ });++ it("picks up where it paused, with the kept steps and the typed text", () => {+ const keep7 = d.script.findIndex((s) => s.type === "keep" && s.label === LABELS[6]);+ const v = viewBefore(d, keep7 + 2);+ expect(v.steps).toEqual(LABELS.slice(0, 7));+ expect(v.frame).toBe("s7");+ expect(v.typed).toBe(LABELS[7].toLowerCase());+ expect(v.pill).toBe("Kept ✓");+ expect(v.zoom).toBeNull();+ // The picture is there at once, not faded in from the dark behind it.+ expect(v).toMatchObject({ fade: 0, sweep: false, under: null });+ const mid = viewBefore(d, keep7 + 3);+ expect(mid).toMatchObject({ frame: "s8a", pill: "Live" });+ const keep2 = d.script.findIndex((s) => s.type === "keep" && s.label === LABELS[1]);+ expect(viewBefore(d, keep2 + 4)).toMatchObject({ frame: "s3a", zoom: [0.4, 0.3, 0.6, 0.6] });+ expect(viewBefore(d, keep2).zoom).toBeNull();+ });++ it("shows the count on the small card after a keep", () => {+ expect(pillText({ pill: "Live", steps: [] })).toEqual({ main: "Live", count: null });+ expect(pillText({ pill: "Kept ✓", steps: LABELS.slice(0, 7) }, true).count).toBe("7");+ expect(pillText({ pill: "Kept ✓", steps: LABELS.slice(0, 7) }).count).toBeNull();+ });++ it("refuses chip labels too long for a phone, keeps too short for the pulse, and a round over the limit", () => {+ const bad: Demo = { ...d, script: d.script.map((s) => (s.type === "keep" ? { ...s, label: "x".repeat(CHIP_MAX + 1), ms: 200 } : s)) };+ const p = demoProblems(bad);+ expect(p.some((x) => x.includes("label"))).toBe(true);+ expect(p.some((x) => x.includes(`${KEEP_PULSE_MS} ms`))).toBe(true);+ const slow: Demo = { ...d, script: [...d.script, { type: "pause", ms: LOOP_MAX_MS }] };+ expect(demoProblems(slow).some((x) => x.startsWith("one round"))).toBe(true);+ });+});++describe("the camera", () => {+ /** Where a point of the picture lands in the frame, as shares of its width and height. */+ const at = (c: ReturnType<typeof cameraFor>, px: number, py: number) => [c.x + c.s * px, c.y + c.s * py];++ it("stays on the whole picture with no area, or one that already fills most of it", () => {+ expect(cameraFor(null)).toEqual({ s: 1, x: 0, y: 0 });+ expect(cameraFor([0.01, 0.01, 0.99, 0.99])).toEqual({ s: 1, x: 0, y: 0 });+ expect(cameraFor([0.27, 0.11, 0.68, 0.89])).toEqual({ s: 1, x: 0, y: 0 });+ });++ it("moves in on a small change, centred, no closer than the limit", () => {+ const c = cameraFor([0.45, 0.45, 0.55, 0.55]);+ expect(c.s).toBe(ZOOM_MAX);+ const [x, y] = at(c, 0.5, 0.5);+ expect(x).toBeCloseTo(0.5);+ expect(y).toBeCloseTo(0.5);+ });++ it("frames a mid-size change whole, with room around it", () => {+ const box: Box = [0.2, 0.25, 0.75, 0.7];+ const c = cameraFor(box);+ expect(c.s).toBeGreaterThan(1.15);+ expect(c.s).toBeLessThan(ZOOM_MAX);+ const [l, t0] = at(c, box[0], box[1]);+ const [r, b] = at(c, box[2], box[3]);+ for (const v of [l, t0]) expect(v).toBeGreaterThan(0);+ for (const v of [r, b]) expect(v).toBeLessThan(1);+ });++ it("never shows past the picture's edge, even for a change in a corner", () => {+ for (const box of [[0, 0, 0.1, 0.1], [0.9, 0.85, 1, 1], [0.6, 0.15, 0.68, 0.36], [0.31, 0.63, 0.61, 1]] as Box[]) {+ const c = cameraFor(box);+ expect(c.x).toBeLessThanOrEqual(0);+ expect(c.y).toBeLessThanOrEqual(0);+ expect(c.x + c.s).toBeGreaterThanOrEqual(1);+ expect(c.y + c.s).toBeGreaterThanOrEqual(1);+ }+ });++ it("draws a live frame across exactly the part of the picture in view", () => {+ // The edge's centre, in shares of the picture's width, for a mask-position (see sweepPath).+ const centre = (pos: number) => 1.25 - 1.5 * (pos / 100);+ const whole = sweepPath(cameraFor(null));+ expect(whole).toEqual({ from: 90, to: 10, scanFrom: -10, scanTo: 110 });+ for (const box of [null, [0.42, 0.26, 0.65, 0.71], [0.58, 0.16, 0.68, 0.36], [0.31, 0.63, 0.61, 1]] as (Box | null)[]) {+ const cam = cameraFor(box);+ const p = sweepPath(cam);+ const [l, r] = [-cam.x / cam.s, (1 - cam.x) / cam.s];+ // It starts with the whole edge just left of the view and ends just right of it; the line rides the edge.+ expect(centre(p.from) + 0.1).toBeCloseTo(l, 2);+ expect(centre(p.to) - 0.1).toBeCloseTo(r, 2);+ expect(p.scanFrom / 100).toBeCloseTo(centre(p.from), 2);+ expect(p.scanTo / 100).toBeCloseTo(centre(p.to), 2);+ }+ });++ it("refuses a zoom box outside the picture", () => {+ const d = longSession();+ const bad: Demo = { ...d, script: d.script.map((s) => (s.type === "zoom" && s.box ? { ...s, box: [0.5, 0.2, 0.4, 1.2] as Box } : s)) };+ expect(demoProblems(bad).some((x) => x.includes("zoom box"))).toBe(true);+ });+});++describe("the trail", () => {+ it("folds older steps into a count and keeps the newest", () => {+ expect(trailWindow(LABELS.slice(0, 7), 1)).toEqual({ hidden: 6, shown: [{ n: 7, label: "Fur stole" }] });+ expect(trailWindow(LABELS.slice(0, 7), 3).hidden).toBe(4);+ expect(trailWindow(LABELS.slice(0, 2), 3)).toEqual({ hidden: 0, shown: [{ n: 1, label: "Red lips" }, { n: 2, label: "Hair down" }] });+ });++ it("renders Original, the folded count for each width, and at most three chips, the newest lit", () => {+ const html = renderToStaticMarkup(createElement(DemoTrail, { steps: LABELS }));+ expect(html).toContain(">Original<");+ expect(html.match(/data-live-chip="/g)).toHaveLength(3);+ expect(html).toContain('data-live-chip="11"');+ expect(html).not.toContain('data-live-chip="8"');+ expect(html).toContain('data-live-more="10"');+ expect(html).toContain('data-live-more="8"');+ expect(html.match(/data-newest="true"/g)).toHaveLength(1);+ expect(html).toMatch(/data-live-chip="11"[^>]*aria-current="step"|aria-current="step"[^>]*data-live-chip="11"/);+ // Phones see only the newest chip and the count of the rest.+ expect(html).toMatch(/class="contents @max-md:hidden"><span[^>]*>›<\/span><span[^>]*data-live-chip="10"/);+ });++ it("lets Original step aside on narrow players once earlier steps fold into a count", () => {+ const folded = renderToStaticMarkup(createElement(DemoTrail, { steps: LABELS }));+ expect(folded).toMatch(/<span class="[^"]*@max-md:hidden[^"]*"[^>]*data-live-original/);+ // The narrow count then leads the trail, with no separator before it.+ expect(folded).toMatch(/class="contents @md:hidden"><span[^>]*data-live-more="10"/);+ const first = renderToStaticMarkup(createElement(DemoTrail, { steps: LABELS.slice(0, 1) }));+ expect(first).toMatch(/data-live-original/);+ expect(first).not.toMatch(/<span class="[^"]*@max-md:hidden[^"]*"[^>]*data-live-original/);+ });++ it("has no wide count before a fourth step while the narrow one folds the earlier ones; nothing before the first keep", () => {+ const html = renderToStaticMarkup(createElement(DemoTrail, { steps: LABELS.slice(0, 3) }));+ expect(html).toContain('data-live-more="2"');+ expect(html).not.toContain('data-live-more="0"');+ expect(html.match(/data-live-chip="/g)).toHaveLength(3);+ expect(renderToStaticMarkup(createElement(DemoTrail, { steps: [] }))).toBe("");+ });++ it("keeps every chip on one line, cut short rather than wrapped", () => {+ const html = renderToStaticMarkup(createElement(DemoTrail, { steps: LABELS }));+ for (const chip of html.match(/<span class="[^"]*"[^>]*data-live-chip="\d+"/g) ?? []) expect(chip).toMatch(/truncate/);+ });+});