Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

Video 0.11: the phone shots in Kokon's phone layout

Gabriele Lozupone5aef9f3a180c
diff --git a/marketing/video/loaders/phone-composer.cjs b/marketing/video/loaders/phone-composer.cjs
new file mode 100644
index 0000000..edb4d54
--- /dev/null
+++ b/marketing/video/loaders/phone-composer.cjs
@@ -0,0 +1,7 @@
+// The phone's writing screen opens when the prompt is tapped (Composer.tsx keeps that in its own
+// state, which a video can't tap): a window's state with `writing: true` opens it too.
+module.exports = function (source) {
+ const from = "const expanded = !phone || opened || reviewing;";
+ if (!source.includes(from)) throw new Error("phone-composer.cjs: Composer.tsx changed, update the loader");
+ return source.replace(from, "const expanded = !phone || opened || reviewing || useStore((s) => !!(s as { writing?: boolean }).writing);");
+};
diff --git a/marketing/video/loaders/phone-container.cjs b/marketing/video/loaders/phone-container.cjs
index aecd1d5..0a89b5b 100644
--- a/marketing/video/loaders/phone-container.cjs
+++ b/marketing/video/loaders/phone-container.cjs
@@ -1,11 +1,27 @@
-// Two things the device shots need from the app's styles.css, the rules themselves unchanged:
+// What the device shots need from the app's styles.css and phone.css, the rules themselves unchanged:
// - the phone layout (`@media (max-width: 720px)`) as a container query, so a window rendered
// phone-sized inside the 1920-px video gets it (AppWindow `phone`), while desktop windows keep
-// the desktop layout;
-// - the light theme's tokens (the first `:root` block) also on `.kokon-light`, so a window can be
-// light while the video's document is dark (AppWindow `light`).
+// the desktop layout; phone.css's own width query (3-column library) the same way;
+// - the light theme's tokens (the first `:root` block of styles.css) also on `.kokon-light`, so a
+// window can be light while the video's document is dark (AppWindow `light`);
+// - phone.css: its phone tokens (`:root` inside the phone query) on the window's `.app`, the dark
+// ones only in a dark window; the home-screen app's rules (`display-mode: standalone`) for a
+// window named `kokon-standalone` (AppWindow `standalone`); the keyboard (`html.keyboard`) on a
+// window with `.keyboard`; the home bar's inset (0 in the render) from `--sab`.
module.exports = function (source) {
+ const phone = /phone\.css$/.test(this.resourcePath);
+ let out = source.replace(/@media \(max-width: 720px\)/g, "@container (max-width: 720px)");
+ if (phone) {
+ return out
+ .replace(/:root\[data-theme="dark"\] \{/g, ':root[data-theme="dark"] .kokon-window:not(.kokon-light) > .app {')
+ .replace(/:root \{/g, ".kokon-window > .app {")
+ .replace(/@media \(min-width: 540px\)/g, "@container (min-width: 540px)")
+ .replace(/@media \(display-mode: standalone\)/g, "@container kokon-standalone (min-width: 0px)")
+ .replace(/html\.keyboard /g, ".kokon-window.keyboard ")
+ .replace(/html:not\(\.keyboard\) /g, ".kokon-window:not(.keyboard) ")
+ .replace(/env\(safe-area-inset-bottom\)/g, "var(--sab, 0px)");
+ }
const root = source.match(/:root \{([\s\S]*?)\n\}/);
const light = root ? `\n.kokon-window.kokon-light {${root[1]}\n}\n` : "";
- return source.replace(/@media \(max-width: 720px\)/g, "@container (max-width: 720px)") + light;
+ return out + light;
};
diff --git a/marketing/video/public/img/beach-sunset.jpg b/marketing/video/public/img/beach-sunset.jpg
new file mode 100644
index 0000000..68c6d7a
Binary files /dev/null and b/marketing/video/public/img/beach-sunset.jpg differ
diff --git a/marketing/video/public/thumb/beach-sunset.jpg b/marketing/video/public/thumb/beach-sunset.jpg
new file mode 100644
index 0000000..2e9d05d
Binary files /dev/null and b/marketing/video/public/thumb/beach-sunset.jpg differ
diff --git a/marketing/video/remotion.config.ts b/marketing/video/remotion.config.ts
index 437257c..28c038f 100644
--- a/marketing/video/remotion.config.ts
+++ b/marketing/video/remotion.config.ts
@@ -30,7 +30,8 @@ Config.overrideWebpackConfig((c) => {
...(c.module?.rules ?? []).map((r) => (r && typeof r === "object" && r.type === "asset/resource" ? { ...r, resourceQuery: { not: [/raw/] } } : r)),
{ resourceQuery: /raw/, type: "asset/source" },
{ test: /\.tsx?$/, include: app, enforce: "pre" as const, use: path.resolve(root, "loaders/vite-glob.cjs") },
- { test: /styles\.css$/, include: app, enforce: "pre" as const, use: path.resolve(root, "loaders/phone-container.cjs") },
+ { test: /(styles|phone)\.css$/, include: app, enforce: "pre" as const, use: path.resolve(root, "loaders/phone-container.cjs") },
+ { test: /Composer\.tsx$/, include: app, enforce: "pre" as const, use: path.resolve(root, "loaders/phone-composer.cjs") },
],
},
resolve: {
@@ -58,6 +59,7 @@ Config.overrideWebpackConfig((c) => {
swap(/^(\.\.?\/)+(lib\/)?platform$/, "platform.ts"),
swap(/^\.\/Compare$/, "Compare.tsx"),
swap(/^\.\/Cocoon$/, "Cocoon.tsx"),
+ swap(/^\.\/Develop$/, "Develop.tsx"),
swap(/^\.\/jobMotion$/, "jobMotion.ts"),
],
};
diff --git a/marketing/video/src/app/AppWindow.tsx b/marketing/video/src/app/AppWindow.tsx
index 16b7c0b..34862ed 100644
--- a/marketing/video/src/app/AppWindow.tsx
+++ b/marketing/video/src/app/AppWindow.tsx
@@ -5,13 +5,16 @@ import type { CSSProperties, ReactNode } from "react";
import { useEffect, useState } from "react";
import { continueRender, delayRender, useCurrentFrame } from "remotion";
import { Composer } from "../../../../src/components/Composer";
+import { PhoneApp } from "../../../../src/components/PhoneApp";
import { Settings } from "../../../../src/components/Settings";
import { Sidebar } from "../../../../src/components/Sidebar";
import { Stage } from "../../../../src/components/Stage";
import { TopBar } from "../../../../src/components/TopBar";
import "../../../../src/styles.css";
+import "../../../../src/phone.css";
import { CardMotionContext, type CardMotion } from "../mocks/card";
import { CompareSplitContext } from "../mocks/Compare";
+import { type Develop, DevelopContext } from "../mocks/Develop";
import { setWordPace } from "../mocks/jobMotion";
import { setPlatform } from "../mocks/platform";
import { FrameStateContext, setFrameState, type State } from "../mocks/store";
@@ -25,8 +28,13 @@ if (typeof document !== "undefined") document.documentElement.dataset.theme = "d
* job card in the stage (cocoon, Prompt+ text, hatching); `className` "silk" shows the thread
* that runs round the composer while you write (app/theme.css). `phone`: Kokon in a phone's
* browser (the app's phone layout, loaders/phone-container.cjs); otherwise the desktop app.
- * `light`: the app's light theme (the document stays dark). `waitFor`: what Settings must show before the frame is taken (default: the dialog itself). */
-export function AppWindow({ state, width, height, overlay, hideComposer, split = 0.5, card, className, phone = false, light = false, waitFor = ".modal" }: { state: State; width: number; height: number; overlay?: ReactNode; hideComposer?: boolean; split?: number; card?: CardMotion; className?: string; phone?: boolean; light?: boolean; waitFor?: string }) {
+ * `light`: the app's light theme (the document stays dark). `waitFor`: what Settings must show before the frame is taken (default: the dialog itself).
+ * A phone window shows the app's phone layout (components/PhoneApp.tsx): `standalone` as added to
+ * the home screen (its corners, the home bar's inset), `keyboard` with the keyboard up (the scene
+ * draws it under the window), `develop` the image developing into view (mocks/Develop.tsx), and
+ * `vars` CSS variables for the phone's motion on the scene's clock (video011.css: `--t-screen`,
+ * `--t-page` seconds into an entrance, `--swipe-dx`/`--swipe-o` a finger on the picture). */
+export function AppWindow({ state, width, height, overlay, hideComposer, split = 0.5, card, className, phone = false, light = false, waitFor = ".modal", standalone = false, keyboard = false, develop = null, vars }: { state: State; width: number; height: number; overlay?: ReactNode; hideComposer?: boolean; split?: number; card?: CardMotion; className?: string; phone?: boolean; light?: boolean; waitFor?: string; standalone?: boolean; keyboard?: boolean; develop?: Develop | null; vars?: Record<string, string | number> }) {
const f = useCurrentFrame();
setFrameState(state);
setPlatform(phone, phone);
@@ -34,29 +42,53 @@ export function AppWindow({ state, width, height, overlay, hideComposer, split =
// CSS loops (the status capsule's silk, shimmer, caret) run on the frame clock; entrances
// have long finished (app/theme.css).
const vt = { "--vt": (100 + f / FPS).toFixed(3) } as CSSProperties;
+ // A phone: the window is the screen (the app's height follows the visible part, PhoneApp.tsx).
+ const screen = phone
+ ? ({
+ containerType: "inline-size",
+ // .phone-app is position: fixed: the window, not the phone's frame, holds it.
+ contain: "layout",
+ containerName: standalone ? "kokon-standalone" : undefined,
+ "--vv-h": `${height}px`,
+ "--vv-top": "0px",
+ "--sab": standalone && !keyboard ? "34px" : "0px",
+ ...vars,
+ } as CSSProperties)
+ : {};
+ const desktop = (
+ <div className="app">
+ {state.sidebar && <Sidebar />}
+ <div className="workspace">
+ <TopBar />
+ <div className="main">
+ <Stage />
+ {overlay}
+ </div>
+ {!hideComposer && <Composer />}
+ </div>
+ {state.overlay === "settings" && (
+ <>
+ <Settings />
+ <WaitFor selector={waitFor} />
+ </>
+ )}
+ </div>
+ );
return (
<FrameStateContext.Provider value={state}>
<CompareSplitContext.Provider value={split}>
<CardMotionContext.Provider value={card ?? null}>
- <div className={["kokon-window", className, light && "kokon-light"].filter(Boolean).join(" ")} style={{ width, height, ...vt, ...(phone ? { containerType: "inline-size" } : {}) }}>
- <div className="app">
- {state.sidebar && <Sidebar />}
- <div className="workspace">
- <TopBar />
- <div className="main">
- <Stage />
- {overlay}
+ <DevelopContext.Provider value={develop}>
+ <div className={["kokon-window", className, light && "kokon-light", keyboard && "keyboard"].filter(Boolean).join(" ")} style={{ width, height, ...vt, ...screen }}>
+ {phone ? (
+ <div className="app phone">
+ <PhoneApp />
</div>
- {!hideComposer && <Composer />}
- </div>
- {state.overlay === "settings" && (
- <>
- <Settings />
- <WaitFor selector={waitFor} />
- </>
+ ) : (
+ desktop
)}
</div>
- </div>
+ </DevelopContext.Provider>
</CardMotionContext.Provider>
</CompareSplitContext.Provider>
</FrameStateContext.Provider>
diff --git a/marketing/video/src/app/fixtures.ts b/marketing/video/src/app/fixtures.ts
index d045212..3654f2f 100644
--- a/marketing/video/src/app/fixtures.ts
+++ b/marketing/video/src/app/fixtures.ts
@@ -24,6 +24,8 @@ export const SIZES: Record<string, [number, number]> = {
// The 0.11 video: a beach photo and the edit that puts him on a flamingo (use-case set, 2K).
beach: [1760, 2368],
"beach-flamingo": [1760, 2368],
+ // ...and a sunset version of the beach photo (the project has two versions before the flamingo).
+ "beach-sunset": [1760, 2368],
};
export const PROMPTS = {
@@ -177,6 +179,8 @@ export function appState(patch: Partial<State> = {}): State {
privateMode: false,
redo: [],
update: null,
+ // The phone's writing screen, opened by a scene (loaders/phone-composer.cjs): never carried over.
+ ...({ writing: false } as Partial<State>),
...patch,
};
}
diff --git a/marketing/video/src/app/timeline011.ts b/marketing/video/src/app/timeline011.ts
index b99161c..77b270b 100644
--- a/marketing/video/src/app/timeline011.ts
+++ b/marketing/video/src/app/timeline011.ts
@@ -65,13 +65,19 @@ const cueOf = (n: number, i: number) => CUES_011.find((c) => c.line === n && c.f
export const said = (n: number, i: number) => sentenceAt(cueOf(n, i), i);
export const saidEnd = (n: number, i: number) => said(n, i) + Math.round((span(n, i)[1] - span(n, i)[0]) * FPS);
-/** The phone in use (shot `use`): + tapped on "Pick a photo", the prompt typed from "describe", Send; the photo
- * travels to the computer, the job runs there, the result travels back, Download. */
+/** The phone in use (shot `use`): the library, Beach day tapped (it opens on its sunset version);
+ * on "Pick a photo" a swipe back to the beach photo; the prompt tapped (the writing screen, the
+ * keyboard) before "describe", typed from it, Send; the photo travels to the computer, the job
+ * runs there, the result travels back and develops into view; the actions row slid to Save, Download. */
export const PROMPT_011 = "Put him on a pink flamingo, surfing a wave";
const U = SHOT.use;
export const USE = {
- plus: U + 20,
- photo: U + 30,
+ open: U + 10,
+ /** The finger on the picture, dragging it right, let go: the beach slides in from the left. */
+ swipe: U + 28,
+ drag: 10,
+ swiped: U + 44,
+ prompt: 0,
type: said(4, 1),
cps: 26,
send: 0,
@@ -80,12 +86,16 @@ export const USE = {
job: 0,
back: 0,
result: 0,
+ /** The actions row slid left by a finger, so Save is in reach. */
+ row: 0,
download: 0,
};
+USE.prompt = USE.type - 6;
USE.send = USE.type + Math.ceil((PROMPT_011.length * FPS) / USE.cps) + 10;
USE.out = USE.send + 2;
USE.job = USE.out + 22;
USE.back = USE.job + 110;
USE.result = USE.back + 22;
USE.download = Math.min(USE.result + 40, SHOT.safe - 16);
+USE.row = USE.download - 18;
CUES_011[7].at = USE.out + 4;
diff --git a/marketing/video/src/app/video011.css b/marketing/video/src/app/video011.css
index a45ac3f..4fd7f7b 100644
--- a/marketing/video/src/app/video011.css
+++ b/marketing/video/src/app/video011.css
@@ -2,3 +2,12 @@
.kokon-window.in-phone { border-radius: 0; box-shadow: none; }
/* The sign-in page, as kokon-service serves it before the app (Login.tsx): centred on the page. */
.kokon-window.login-page { align-items: center; justify-content: center; padding-bottom: 120px; }
+/* The phone layout's one-off entrances on the scene's clocks (AppWindow `clocks`), not the film's:
+ the project sliding in from the library (--t-screen), the version swiped to (--t-page, with
+ .page-enter-left/right), an image developing (--t-develop, mocks/Develop.tsx). */
+.kokon-window .phone-screen { animation-delay: calc(var(--t-screen, 100) * -1s) !important; }
+.kokon-window.page-enter-left .swipe-page { animation: page-left 0.46s var(--ease) both; animation-delay: calc(var(--t-page, 100) * -1s) !important; }
+.kokon-window.page-enter-right .swipe-page { animation: page-right 0.46s var(--ease) both; animation-delay: calc(var(--t-page, 100) * -1s) !important; }
+.kokon-window img.develop-in { animation-delay: calc(var(--t-develop, 100) * -1s) !important; }
+/* a finger dragging the picture sideways (Swipe in PhoneStage.tsx moves .swipe-track the same way) */
+.kokon-window .swipe-track { transform: translateX(var(--swipe-dx, 0px)); opacity: var(--swipe-o, 1); }
diff --git a/marketing/video/src/mocks/Compare.tsx b/marketing/video/src/mocks/Compare.tsx
index 53f501d..2e7c0df 100644
--- a/marketing/video/src/mocks/Compare.tsx
+++ b/marketing/video/src/mocks/Compare.tsx
@@ -1,12 +1,15 @@
// The app's CompareFrame (src/components/Compare.tsx) with the slider position taken from the
// frame clock (`CompareSplitContext`, provided by <AppWindow>) instead of the pointer. Markup and
-// classes are unchanged.
+// classes are unchanged; a phone gets the app's one glass button for the views (PhoneCompare).
+import { ChevronDown, SquareSplitHorizontal } from "lucide-react";
import { createContext, useContext } from "react";
import { compareBase as _cb, type CompareBase, type CompareMode } from "../../../../src/lib/logic";
import type { GenerationRecord } from "../../../../src/lib/types";
import { Seg, useFit } from "../../../../src/components/ui";
import { FullscreenButton } from "../../../../src/components/Viewer";
import { urls } from "./api";
+import { DevelopImg } from "./Develop";
+import { useNarrow } from "./platform";
import { useStore } from "./store";
void _cb;
@@ -21,6 +24,7 @@ export const CompareSplitContext = createContext(0.5);
export function CompareFrame({ g, base, fullscreen = false }: { g: GenerationRecord; base: CompareBase; fullscreen?: boolean }) {
const mode = useStore((s) => s.compare);
+ const phone = useNarrow();
const split = Math.min(1, Math.max(0, useContext(CompareSplitContext)));
const { ref, box } = useFit(g.width / g.height);
const after = urls.gen(g.id);
@@ -30,7 +34,7 @@ export function CompareFrame({ g, base, fullscreen = false }: { g: GenerationRec
return (
<div className={fullscreen ? "viewer-frame" : "stage-frame"} ref={ref}>
<div className={`compare-box ${mode === "slider" ? "slider" : ""}`} style={{ width: box.w, height: box.h }}>
- <img className="compare-img" src={after} alt={g.prompt} draggable={false} />
+ <DevelopImg className="compare-img" src={after} placeholder={urls.genThumb(g.id)} alt={g.prompt} />
<div className="compare-before" style={{ visibility: mode === "slider" ? "visible" : "hidden", clipPath: mode === "slider" ? `inset(0 ${pct(1 - split)} 0 0)` : undefined }}>
<img src={before} alt="Original" draggable={false} style={{ left: pct(x), top: pct(y), width: pct(w), height: pct(h) }} />
</div>
@@ -43,7 +47,8 @@ export function CompareFrame({ g, base, fullscreen = false }: { g: GenerationRec
<span className="compare-tag right">After</span>
</>
)}
- {!fullscreen && (
+ {!fullscreen && phone && <PhoneCompare />}
+ {!fullscreen && !phone && (
<div className="compare-overlay">
<CompareBar />
</div>
@@ -54,6 +59,20 @@ export function CompareFrame({ g, base, fullscreen = false }: { g: GenerationRec
);
}
+/** The phone's switch: one glass button on the picture naming the view (its sheet is not filmed). */
+function PhoneCompare() {
+ const mode = useStore((s) => s.compare);
+ return (
+ <div className="compare-pill-wrap">
+ <button className="compare-pill" title="Compare with the original">
+ <SquareSplitHorizontal size={15} />
+ {MODES.find((m) => m.value === mode)?.label}
+ <ChevronDown size={13} />
+ </button>
+ </div>
+ );
+}
+
export function CompareBar() {
const mode = useStore((s) => s.compare);
return (
diff --git a/marketing/video/src/mocks/Develop.tsx b/marketing/video/src/mocks/Develop.tsx
new file mode 100644
index 0000000..9ab8dce
--- /dev/null
+++ b/marketing/video/src/mocks/Develop.tsx
@@ -0,0 +1,34 @@
+// The app's DevelopImg (src/components/Develop.tsx) on the frame clock: the app starts the
+// entrance when the image has decoded, which a video can't wait for. <AppWindow develop={…}> names
+// the image developing and the seconds since it started (before 0: still loading, the blurred
+// thumbnail under the sheen); every other image is shown at once. Markup and classes are the app's.
+import { createContext, useContext, type CSSProperties } from "react";
+
+export interface Develop {
+ /** Part of the image's URL (e.g. "img/beach-flamingo"). */
+ match: string;
+ /** Seconds since it started to develop. */
+ t: number;
+}
+export const DevelopContext = createContext<Develop | null>(null);
+
+/** How long the placeholder takes to fade (styles.css .develop-ph transition). */
+const PH_FADE = 0.55;
+
+export function DevelopImg({ src, placeholder, className = "", alt = "" }: { src?: string; placeholder?: string; className?: string; alt?: string; lazy?: boolean }) {
+ const d = useContext(DevelopContext);
+ const t = d && src?.includes(d.match) ? d.t : null;
+ if (t === null || t >= 1) return <img className={className} src={src} alt={alt} draggable={false} />;
+ const waiting = t < 0;
+ const ph = waiting ? 1 : Math.max(0, 1 - t / PH_FADE);
+ return (
+ <>
+ {ph > 0 && (
+ <span className={`develop-ph ${waiting ? "" : "out"}`} aria-hidden style={{ opacity: ph }}>
+ {placeholder && <img className="on" src={placeholder} alt="" draggable={false} />}
+ </span>
+ )}
+ <img className={`${className} ${waiting ? "develop-wait" : "develop-in"}`} src={src} alt={alt} draggable={false} style={{ "--t-develop": t.toFixed(3) } as CSSProperties} />
+ </>
+ );
+}
diff --git a/marketing/video/src/mocks/api.ts b/marketing/video/src/mocks/api.ts
index b7446dc..84f16dc 100644
--- a/marketing/video/src/mocks/api.ts
+++ b/marketing/video/src/mocks/api.ts
@@ -24,6 +24,9 @@ export const urls = {
genThumb: (id: string) => staticFile(`thumb/${id}.jpg`),
source: (s: string) => staticFile(`img/${s.replace(/^(gen|input):/, "")}.jpg`),
sourceThumb: (s: string) => staticFile(`thumb/${s.replace(/^(gen|input):/, "")}.jpg`),
+ // A browser's screen-sized previews (the phone's stage): the same images.
+ sourcePreview: (s: string) => staticFile(`img/${s.replace(/^(gen|input):/, "")}.jpg`),
+ genOriginal: (id: string) => staticFile(`img/${id}.jpg`),
};
export function subscribe() {
return () => {};
diff --git a/marketing/video/src/mocks/platform.ts b/marketing/video/src/mocks/platform.ts
index aa619dc..674f583 100644
--- a/marketing/video/src/mocks/platform.ts
+++ b/marketing/video/src/mocks/platform.ts
@@ -1,11 +1,12 @@
// The app's platform checks, switched per window: the desktop app (Settings → Other devices) or
-// Kokon in a phone's browser (the drawer sidebar, bottom sheets). <AppWindow> sets them before
+// Kokon in a phone's browser (its own layout, components/PhoneApp.tsx). <AppWindow> sets them before
// its components render; the app reads `inBrowser` at use, so the live binding follows.
export * from "../../../../src/lib/platform";
export let inBrowser = false;
let narrow = false;
export const isNarrow = () => narrow;
+export const useNarrow = () => narrow;
export function setPlatform(browser: boolean, phone: boolean) {
inBrowser = browser;
narrow = phone;
diff --git a/marketing/video/src/scenes/Update011.tsx b/marketing/video/src/scenes/Update011.tsx
index ca864e9..5187854 100644
--- a/marketing/video/src/scenes/Update011.tsx
+++ b/marketing/video/src/scenes/Update011.tsx
@@ -6,14 +6,14 @@
// (app/timeline011.ts): no camera moves. The on-screen words carry every message, since Reddit
// plays muted.
import { Check, CloudOff, Compass, Lock, PlusSquare, Share, UserX, X } from "lucide-react";
-import { useLayoutEffect, useMemo, type CSSProperties, type ReactNode } from "react";
+import { useLayoutEffect, useMemo, type ComponentProps, type CSSProperties, type ReactNode } from "react";
import { AbsoluteFill, Img, spring, staticFile, useCurrentFrame, useVideoConfig } from "remotion";
import { siDocker, siLinux, siNvidia } from "simple-icons";
import { encode } from "uqr";
import { KokonMark } from "../../../../src/components/Welcome";
import { AppWindow } from "../app/AppWindow";
import { type Curve, fanAngle, HomeScene, IPhone, Link, NetPill, Packet, Pc, PHONE_SCREEN } from "../app/Devices011";
-import { appState, gen, genItem, jobItem, ref, settingsState } from "../app/fixtures";
+import { appState, gen, genItem, jobItem, PROJECTS, ref, settingsState } from "../app/fixtures";
import { Mark } from "../app/Mark";
import { Backdrop, Caption, inOut, prog, Pointer, typed, typingDone } from "../app/motion";
import { Music, Send, Sfx, Voice } from "../app/sound";
@@ -40,19 +40,24 @@ const Shot = ({ from, to, children }: { from: number; to: number; children: Reac
};
// ---------------------------------------------------------------------------------------------
-// The project on the phone: a beach photo, and the edit that puts him on a flamingo.
+// The project on the phone: a beach photo, a sunset version of it, and the edit that puts him on a
+// flamingo (made from the photo).
// ---------------------------------------------------------------------------------------------
const BEACH = gen("beach", "generate", "A man on the beach, arms open");
+const SUNSET = gen("beach-sunset", "edit", "Make it sunset, with golden light on the water", "beach");
const FLAMINGO = gen("beach-flamingo", "edit", PROMPT_011, "beach");
-const BEACH_DAY = { projects: [{ id: "current", title: "Beach day", updatedAt: Date.now() - 60_000, cover: "gen:beach-flamingo", count: 2 }], projectId: "current", sidebar: false };
-/** A photo picked on the phone: an upload, so an input, not a result. */
-const PICKED = { key: "ref-photo", source: "input:beach", width: 1760, height: 2368, name: "IMG_2048.jpg" };
+/** Beach day in the library: before the flamingo (two images, the sunset its cover), and after. */
+const beachDay = (done: boolean) => ({ id: "current", title: "Beach day", updatedAt: Date.now() - (done ? 60_000 : 40 * 60_000), cover: done ? "gen:beach-flamingo" : "gen:beach-sunset", count: done ? 3 : 2 });
+const BEACH_DAY = { projects: [beachDay(true), ...PROJECTS], projectId: "current", sidebar: false };
+/** The phone's home: the projects the computer keeps, Beach day first. */
+const LIBRARY = { projects: [beachDay(false), ...PROJECTS], projectId: "current", sidebar: true };
const resultState = (patch: Partial<State> = {}) =>
- appState({ ...BEACH_DAY, session: [genItem(BEACH), genItem(FLAMINGO)], selected: "beach-flamingo", composer: { ...appState().composer, refs: [ref("beach-flamingo")] }, ...patch });
+ appState({ ...BEACH_DAY, session: [genItem(BEACH), genItem(SUNSET), genItem(FLAMINGO)], selected: "beach-flamingo", composer: { ...appState().composer, refs: [ref("beach-flamingo")] }, ...patch });
-/** Kokon in the phone's browser (390×776 under the status bar), light as on the site. */
-const PhoneApp = ({ state, card, split, height = PHONE_SCREEN.h }: { state: State; card?: CardMotion; split?: number; height?: number }) => (
- <AppWindow state={state} width={PHONE_SCREEN.w} height={height} phone light className="in-phone" card={card} split={split} />
+/** Kokon on the phone (390×776 under the status bar), light as on the site: as added to the home
+ * screen (`standalone`), or in Safari over its toolbar. */
+const PhoneApp = ({ state, height = PHONE_SCREEN.h, standalone = true, className, ...rest }: { state: State; height?: number; standalone?: boolean } & Omit<ComponentProps<typeof AppWindow>, "state" | "width" | "height" | "phone" | "light">) => (
+ <AppWindow state={state} width={PHONE_SCREEN.w} height={height} phone light standalone={standalone} className={["in-phone", className].filter(Boolean).join(" ")} {...rest} />
);
/** The computer's settings: Other devices, before and after the password (mocks/api.ts answers
@@ -344,7 +349,7 @@ function SignIn() {
<AbsoluteFill>
<Backdrop glow={0.7} />
<IPhone x={PHONE_AT.x} y={PHONE_AT.y} scale={PHONE_AT.s}>
- {f < LOGIN.open ? <LoginPage chars={chars} /> : <PhoneApp state={appState({ ...BEACH_DAY, projects: [] })} height={PHONE_SCREEN.h - SAFARI_BAR} />}
+ {f < LOGIN.open ? <LoginPage chars={chars} /> : <PhoneApp state={appState(LIBRARY)} height={PHONE_SCREEN.h - SAFARI_BAR} standalone={false} />}
<SafariBar />
<Touch x={LOGIN_BUTTON[0]} y={LOGIN_BUTTON[1]} at={LOGIN.tap} />
</IPhone>
@@ -426,7 +431,7 @@ function AddHome() {
<IPhone x={PHONE_AT.x} y={PHONE_AT.y} scale={PHONE_AT.s} dark={onHome} full={onHome ? <HomeScreen f={f} /> : undefined}>
{!onHome && (
<>
- <PhoneApp state={appState({ ...BEACH_DAY, projects: [] })} height={PHONE_SCREEN.h - SAFARI_BAR} />
+ <PhoneApp state={appState(LIBRARY)} height={PHONE_SCREEN.h - SAFARI_BAR} standalone={false} />
<SafariBar />
<ShareSheet p={prog(f, HOME.sheet, 10)} />
{/* the sheet's second row from the bottom: Add to Home Screen (rows 48 px, the sheet 8 px up) */}
@@ -445,17 +450,26 @@ function AddHome() {
}
// ---------------------------------------------------------------------------------------------
-// 4. Using it: + a photo, the prompt, Send. The photo runs along the link to the computer (its
-// fans speed up, the GPU glows), the result runs back, Download.
+// 4. Using it: the library, Beach day, a swipe back to the photo, the prompt written and sent. The
+// photo runs along the link to the computer (its fans speed up, the GPU glows), the result runs
+// back and develops into view, Download.
// ---------------------------------------------------------------------------------------------
const USE_PHONE = { x: 200, y: 96, s: 1.02 };
const USE_PC = { x: 1440, y: 250, s: 1.5 };
/** The link from the phone's side to the computer's (frame px). */
const USE_LINK: Curve = [660, 470, 900, 300, 1180, 330, 1428, 560];
-/** The composer's + and Send, and Download under the result (phone px, Probe011). */
-const ADD: [number, number] = [39, 742];
-const SEND: [number, number] = [354, 742];
-const DOWNLOAD: [number, number] = [256, 462];
+/** Where the finger goes (phone px under the status bar, measured on stills): Beach day's card in
+ * the library, the picture it drags, the closed prompt, Send over the keyboard, Save in the row
+ * once it has slid, and how far the row slides. */
+const CARD: [number, number] = [102, 214];
+const PICTURE: [number, number] = [150, 300];
+const PROMPT_CARD: [number, number] = [170, 690];
+const SEND: [number, number] = [352, 440];
+const SAVE: [number, number] = [281, 476];
+const ROW_SLIDE = 150;
+/** The keyboard's height over the screen's foot (the app shrinks above it, as on an iPhone). */
+const KB_H = 300;
+
/** What the phone shows once Download is tapped: a banner with the photo, as for any download. */
function Downloaded({ f }: { f: number }) {
const p = prog(f, USE.download + 4, 10);
@@ -474,27 +488,115 @@ function Downloaded({ f }: { f: number }) {
);
}
+/** The iPhone's keyboard (light), rising at `at`; the key of the letter just typed pressed. */
+const KEY_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
+function Keyboard({ f, at, text }: { f: number; at: number; text: string }) {
+ const up = prog(f, at, 8, inOut);
+ const last = text.slice(-1).toLowerCase();
+ const face = (on: boolean, fn = false): CSSProperties => ({ height: 42, borderRadius: 6, background: on ? "#aeb3bc" : fn ? "#abb0ba" : "#fff", boxShadow: "0 1px 0 rgba(0,0,0,0.3)", display: "flex", alignItems: "center", justifyContent: "center", color: "#000" });
+ const key = (c: string) => (
+ <span key={c} style={{ ...face(c === last), width: 33, font: `400 23px/1 -apple-system, ${font}` }}>
+ {c}
+ </span>
+ );
+ const fn = (label: string, w: number) => <span style={{ ...face(false, true), width: w, font: `400 16px/1 -apple-system, ${font}` }}>{label}</span>;
+ const row = (children: ReactNode, pad = 3) => <div style={{ display: "flex", justifyContent: "center", gap: 6, padding: `0 ${pad}px` }}>{children}</div>;
+ const bar = <span style={{ width: 1, height: 24, background: "#b5b9c0" }} />;
+ return (
+ <div style={{ position: "absolute", left: 0, right: 0, top: PHONE_SCREEN.h - KB_H, height: KB_H + 60, zIndex: 30, background: "#d1d4da", transform: `translateY(${(1 - up) * (KB_H + 60)}px)`, display: "flex", flexDirection: "column", gap: 11, paddingTop: 8 }}>
+ <div style={{ height: 36, display: "flex", alignItems: "center", justifyContent: "space-around", font: `400 16px/1 -apple-system, ${font}`, color: "#222" }}>
+ <span>“wave”</span>
+ {bar}
+ <span>waves</span>
+ {bar}
+ <span>wavy</span>
+ </div>
+ {row(KEY_ROWS[0].split("").map(key))}
+ {row(KEY_ROWS[1].split("").map(key), 22)}
+ {row(
+ <>
+ {fn("⇧", 44)}
+ <span style={{ width: 8 }} />
+ {KEY_ROWS[2].split("").map(key)}
+ <span style={{ width: 8 }} />
+ {fn("⌫", 44)}
+ </>,
+ )}
+ {row(
+ <>
+ {fn("123", 88)}
+ <span style={{ ...face(last === " "), flex: 1, font: `400 16px/1 -apple-system, ${font}` }}>space</span>
+ {fn("return", 88)}
+ </>,
+ )}
+ </div>
+ );
+}
+
+/** Slides the phone's actions row to `px` (the app's own scroll, which a video can't swipe). */
+function ScrollRow({ px }: { px: number }) {
+ useLayoutEffect(() => {
+ const row = document.querySelector<HTMLElement>(".in-phone .phone-actions");
+ if (row) row.scrollLeft = px;
+ });
+ return null;
+}
+
/** The computer's work: 0 idle, 1 busy (fans fast, warm glow). */
const busy = (i: number) => prog(i, USE.job - 8, 20, inOut) * (1 - prog(i, USE.back, 30, inOut));
function UsePhone() {
const f = useCurrentFrame();
- const base = appState({ ...BEACH_DAY, projects: [{ ...BEACH_DAY.projects[0], title: "Beach day" }] });
+ const composer = appState().composer;
+ const before = [genItem(BEACH), genItem(SUNSET)];
+ const opened = { ...LIBRARY, sidebar: false };
+ // Send is pressed on the writing screen; it closes a moment later.
+ const sent = USE.send + 4;
+ const writing = f >= USE.prompt + 2 && f < sent;
let state: State;
let card: CardMotion | undefined;
- if (f < USE.photo) state = base;
- else if (f < USE.send) state = appState({ ...BEACH_DAY, composer: { ...base.composer, refs: [PICKED], prompt: f < USE.type ? "" : typed(PROMPT_011, f, USE.type, USE.cps) } });
- else if (f < USE.result) {
- const j = jobItem("j-phone", "edit", PROMPT_011, "beach-flamingo", undefined, Math.min(8, Math.floor((f - USE.job) / 12)));
- state = appState({ ...BEACH_DAY, session: [j.item], selected: "j-phone", jobs: { "j-phone": j.job } });
+ // The project slides in from the tap on (before it, the library has long been there).
+ let vars: Record<string, string | number> = f >= USE.open ? { "--t-screen": ((f - USE.open) / FPS).toFixed(3) } : {};
+ // Each phase is a window of its own: the composer keeps "open" in its own state once focused.
+ const phase = f < USE.open ? "library" : f < USE.swiped ? "swipe" : writing ? "writing" : f < sent ? "photo" : f < USE.result ? "job" : "result";
+ let page: string | undefined;
+ const dragEnd = USE.swipe + USE.drag;
+ if (f < USE.open) state = appState(LIBRARY);
+ else if (f < USE.swiped) {
+ // Beach day opens on its last version; the finger drags it right and lets go, it slides off.
+ state = appState({ ...opened, session: before, selected: "beach-sunset", composer: { ...composer, refs: [ref("beach-sunset")] } });
+ const drag = prog(f, USE.swipe, USE.drag, inOut);
+ const away = prog(f, dragEnd, USE.swiped - dragEnd);
+ const dx = f < dragEnd ? 120 * drag : 120 - 30 * away;
+ const o = f < dragEnd ? 1 - dx / 600 : 0.8 * (1 - away);
+ vars = { ...vars, "--swipe-dx": `${dx.toFixed(1)}px`, "--swipe-o": o.toFixed(3) };
+ } else if (f < sent) {
+ const prompt = f < USE.type ? "" : typed(PROMPT_011, f, USE.type, USE.cps);
+ state = appState({ ...opened, session: before, selected: "beach", composer: { ...composer, refs: [ref("beach")], prompt }, ...(writing ? { writing: true } : {}) } as Partial<State>);
+ vars = { ...vars, "--t-page": ((f - USE.swiped) / FPS).toFixed(3) };
+ page = "page-enter-left";
+ } else if (f < USE.result) {
+ const j = jobItem("j-phone", "edit", PROMPT_011, "beach-flamingo", "beach", Math.min(8, Math.floor((f - USE.job) / 12)));
+ state = appState({ ...opened, session: [...before, j.item], selected: "j-phone", jobs: { "j-phone": j.job }, composer: { ...composer, refs: [ref("beach")] } });
card = { t: Math.max(0, (f - USE.send) / FPS), pctAt: (t) => Math.min(99, Math.max(0, (t - 0.7) / 3.2) * 100) };
- } else state = appState({ ...BEACH_DAY, session: [genItem(FLAMINGO)], selected: "beach-flamingo", composer: { ...base.composer, refs: [ref("beach-flamingo")] } });
+ } else state = resultState();
+ const develop = f >= USE.result ? { match: "img/beach-flamingo", t: (f - USE.result) / FPS } : null;
+ const typedNow = f >= USE.type && f < sent ? typed(PROMPT_011, f, USE.type, USE.cps) : "";
+ // The finger on the picture follows the drag.
+ const swipeX = PICTURE[0] + 120 * prog(f, USE.swipe, USE.drag, inOut);
+ const slide = prog(f, USE.row, 10, inOut);
return (
<>
- <PhoneApp state={state} card={card} />
- <Touch x={ADD[0]} y={ADD[1]} at={USE.plus} />
+ <PhoneApp key={phase} state={state} card={card} vars={vars} className={page} develop={develop} keyboard={writing} height={writing ? PHONE_SCREEN.h - KB_H : PHONE_SCREEN.h} />
+ {f >= USE.result && <ScrollRow px={ROW_SLIDE * slide} />}
+ {writing && <Keyboard f={f} at={USE.prompt + 2} text={typedNow} />}
+ <Touch x={CARD[0]} y={CARD[1]} at={USE.open} />
+ {f < USE.swiped && <Touch x={swipeX} y={PICTURE[1]} at={USE.swipe} from={USE.swipe - 6} />}
+ <Touch x={PROMPT_CARD[0]} y={PROMPT_CARD[1]} at={USE.prompt} />
<Touch x={SEND[0]} y={SEND[1]} at={USE.send} />
- <Touch x={DOWNLOAD[0]} y={DOWNLOAD[1]} at={USE.download} />
+ {/* the row slid left by a finger, then Save */}
+ {f < USE.row + 16 && <Touch x={SAVE[0] + ROW_SLIDE * (1 - slide)} y={SAVE[1]} at={USE.row} from={USE.row - 6} />}
+ <Touch x={SAVE[0]} y={SAVE[1]} at={USE.download} />
<Downloaded f={f} />
</>
);
@@ -822,8 +924,9 @@ function Sounds() {
<Sfx name="pop" at={HOME.icon} />
<Sfx name="click" at={HOME.open} gain={0.7} />
{/* using it */}
- <Sfx name="click" at={USE.plus} gain={0.7} />
- <Sfx name="pop" at={USE.photo} gain={0.7} />
+ <Sfx name="click" at={USE.open} gain={0.7} />
+ <Sfx name="swipe" at={USE.swipe + USE.drag} gain={0.5} />
+ <Sfx name="click" at={USE.prompt} gain={0.7} />
<Sfx name="typing" at={USE.type} dur={typeEnd - USE.type} gain={0.8} />
<Send at={USE.send} />
<Sfx name="travel" at={USE.out} />