diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 57cf4b2..d61e50b 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -31,7 +31,7 @@ jobs: working-directory: client # Project Pages live at jonocodes.github.io/deckd/: the homepage - # (site/) at the root, the client at /deckd/app/, Ladle at + # (site/) at the root, the client at /deckd/demo/client/, Ladle at # /deckd/ladle/. The same script backs `just pages`, so a local # preview is exactly what deploys; it type-checks the client first, # so a type error fails the deploy before a broken bundle ships. diff --git a/Justfile b/Justfile index 1e6df46..b6c4954 100644 --- a/Justfile +++ b/Justfile @@ -205,7 +205,7 @@ build-client: cd client && npm run build # Assemble the GitHub Pages site exactly as the deploy workflow does: the -# homepage at the root, the client under app/, Ladle under ladle/. +# homepage at the root, the client under demo/client/, Ladle under ladle/. # Output: _site/deckd/. `just pages` builds and serves it. build-pages: scripts/build_pages.sh _site/deckd @@ -221,14 +221,17 @@ screenshots: cd client && node screenshots.mjs # Build the GitHub Pages site exactly as CI deploys it (homepage at /deckd/, -# client at /deckd/app/, Ladle at /deckd/ladle/) and serve it on :5290. -# SKIP_LADLE=1 just pages skips the slow Ladle build. +# client at /deckd/demo/client/, Ladle at /deckd/ladle/) and serve it on :5290. +# SKIP_LADLE=1 just pages skips the slow Ladle build; PAGES_HOST=0.0.0.0 +# serves it to other devices too (e.g. over Tailscale). pages: #!/usr/bin/env bash set -euo pipefail scripts/build_pages.sh _site/deckd - echo "Pages preview: http://127.0.0.1:5290/deckd/" - node scripts/serve_pages.mjs _site 5290 + host="${PAGES_HOST:-127.0.0.1}" + [ "$host" = 0.0.0.0 ] && shown="$(hostname)" || shown="$host" + echo "Pages preview: http://$shown:5290/deckd/ (demo: /deckd/demo/)" + node scripts/serve_pages.mjs _site 5290 "$host" # Preview the homepage mockups (docs/mockups/homepage) over http. The client's # Vite dev server on :5288 serves the demo decks the pages embed; a static diff --git a/README.md b/README.md index 603c7f0..77d38c5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # deckd -**[jonocodes.github.io/deckd](https://jonocodes.github.io/deckd/)** — homepage, with the client running live in demo mode. +**[jonocodes.github.io/deckd](https://jonocodes.github.io/deckd/)** — homepage · **[live demo](https://jonocodes.github.io/deckd/demo/)**: pick an app, see its deck. App-aware touch control surface for your desktop. A Stream Deck-like deck of buttons, sliders, scroll strips, and a manual control mode (a single combined trackpad + keyboard passthrough), rendered in any browser on any touchscreen device, driven by a local daemon that watches the focused application and swaps decks automatically. diff --git a/client/src/Gallery.tsx b/client/src/Gallery.tsx index ad02f9d..08644e9 100644 --- a/client/src/Gallery.tsx +++ b/client/src/Gallery.tsx @@ -16,9 +16,7 @@ type Device = { label: string; w: number; h: number }; // Portrait base dimensions (CSS px); landscape swaps w/h. const DEVICES: Device[] = [ - { label: "Phone", w: 390, h: 844 }, { label: "Large phone", w: 430, h: 932 }, - { label: '7" tablet', w: 600, h: 1024 }, { label: '10" tablet', w: 834, h: 1194 }, ]; @@ -29,7 +27,8 @@ const MAX_H = 360; type Orientation = "landscape" | "portrait"; -const DEMO_LABELS: Record = { mpris: "Media" }; +// ``media`` is the showcase now-playing deck; ``mpris`` is the test fixture. +const DEMO_LABELS: Record = { mpris: "MPRIS" }; function Frame({ device, diff --git a/client/src/demo-landing.test.ts b/client/src/demo-landing.test.ts new file mode 100644 index 0000000..f23e596 --- /dev/null +++ b/client/src/demo-landing.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from "vitest"; +import { demoLanding } from "./demo-landing"; + +describe("demo landing (GitHub Pages build)", () => { + const target = "/deckd/demo/"; + + it("forwards a visit with nothing to show to the demo page", () => { + expect(demoLanding("", target)).toBe(target); + }); + + it("leaves demo, playground and pinned-deck links alone", () => { + expect(demoLanding("?demo=firefox", target)).toBeNull(); + expect(demoLanding("?playground", target)).toBeNull(); + expect(demoLanding("?deck=youtube", target)).toBeNull(); + }); + + it("does nothing outside the Pages build (no target configured)", () => { + expect(demoLanding("", undefined)).toBeNull(); + expect(demoLanding("", "")).toBeNull(); + }); +}); diff --git a/client/src/demo-landing.ts b/client/src/demo-landing.ts new file mode 100644 index 0000000..ebbbef7 --- /dev/null +++ b/client/src/demo-landing.ts @@ -0,0 +1,11 @@ +/** On GitHub Pages there's no daemon, so the client with nothing to show + * (no ``?demo=`` / ``?playground`` / ``?deck=``) just says "Reconnecting…". + * The Pages build sets ``VITE_DEMO_PAGE`` (scripts/build_pages.sh) and such a + * visit forwards there instead. The client is also the site's 404.html, so a + * mistyped site link lands on the demo too. Unset everywhere else, so a + * daemon-served client never redirects. */ +export function demoLanding(search: string, target: string | undefined): string | null { + if (!target) return null; + const params = new URLSearchParams(search); + return params.has("demo") || params.has("playground") || params.has("deck") ? null : target; +} diff --git a/client/src/main.tsx b/client/src/main.tsx index 7f051ac..8ce60d5 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -1,12 +1,18 @@ import React from "react"; import ReactDOM from "react-dom/client"; import { App } from "./App"; +import { demoLanding } from "./demo-landing"; import "./fonts"; import "./style.css"; import "./help.css"; -ReactDOM.createRoot(document.getElementById("root")!).render( - - - , -); +const landing = demoLanding(window.location.search, import.meta.env.VITE_DEMO_PAGE); +if (landing) { + window.location.replace(landing); +} else { + ReactDOM.createRoot(document.getElementById("root")!).render( + + + , + ); +} diff --git a/client/src/view-routing.test.ts b/client/src/view-routing.test.ts index 0f7932c..3a18641 100644 --- a/client/src/view-routing.test.ts +++ b/client/src/view-routing.test.ts @@ -19,23 +19,23 @@ describe("view routing", () => { expect(viewFromPath("/not-a-page")).toBe("deck"); }); - // Served under a sub-path (GitHub Pages: /deckd/app/), every view lives + // Served under a sub-path (GitHub Pages: /deckd/demo/client/), every view lives // beneath the base, and paths outside it aren't views. describe("under a base path", () => { - const base = "/deckd/app/"; + const base = "/deckd/demo/client/"; it.each([ - ["/deckd/app/", "deck"], - ["/deckd/app/trackpad", "trackpad"], - ["/deckd/app/now-playing", "nowplaying"], - ["/deckd/app/help", "help"], + ["/deckd/demo/client/", "deck"], + ["/deckd/demo/client/trackpad", "trackpad"], + ["/deckd/demo/client/now-playing", "nowplaying"], + ["/deckd/demo/client/help", "help"], ] as const)("maps %s to %s", (path, view) => { expect(viewFromPath(path, base)).toBe(view); expect(pathForView(view, base)).toBe(path); }); it("treats the base without its trailing slash as the deck", () => { - expect(viewFromPath("/deckd/app", base)).toBe("deck"); + expect(viewFromPath("/deckd/demo/client", base)).toBe("deck"); }); it("doesn't read a root-level path as a view", () => { diff --git a/client/src/view-routing.ts b/client/src/view-routing.ts index fd0afe0..3f93846 100644 --- a/client/src/view-routing.ts +++ b/client/src/view-routing.ts @@ -24,7 +24,7 @@ const VIEW_BY_PATH: Record = Object.fromEntries( ) as Record; // Views live under the app's base path: "/" when the daemon serves the -// client, "/deckd/app/" on GitHub Pages (Vite's ``base``, from +// client, "/deckd/demo/client/" on GitHub Pages (Vite's ``base``, from // VITE_BASE_PATH). The trailing slash is dropped so "/" joins as "". const prefix = (base: string) => base.replace(/\/+$/, ""); diff --git a/client/src/vite-env.d.ts b/client/src/vite-env.d.ts index 11f02fe..6a27224 100644 --- a/client/src/vite-env.d.ts +++ b/client/src/vite-env.d.ts @@ -1 +1,6 @@ /// + +interface ImportMetaEnv { + /** Pages build only: where a visit with no demo to show is sent. */ + readonly VITE_DEMO_PAGE?: string; +} diff --git a/client/vite.config.ts b/client/vite.config.ts index 7dca870..93cb9d1 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -22,9 +22,9 @@ const daemonUpstream = process.env.DECKD_UPSTREAM ?? "http://127.0.0.1:8865"; const https = readTlsConfig(); export default defineConfig({ - // On Pages the client lives at jonocodes.github.io/deckd/app/ (the + // On Pages the client lives at jonocodes.github.io/deckd/demo/client/ (the // homepage has /deckd/): scripts/build_pages.sh sets - // ``VITE_BASE_PATH=/deckd/app/``. Local dev and the daemon-served build + // ``VITE_BASE_PATH=/deckd/demo/client/``. Local dev and the daemon-served build // leave ``base`` at the default ``/``. base: process.env.VITE_BASE_PATH ?? "/", plugins: [react()], diff --git a/docs/GUIDE.md b/docs/GUIDE.md index e01d49a..fa85593 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -220,13 +220,14 @@ The client can be viewed and design-iterated without a running daemon: Every push to `main` builds the homepage, the client and Ladle and publishes them to GitHub Pages, so the previews above can be browsed with no daemon and no local checkout. `scripts/build_pages.sh` assembles the site, and `just pages` builds and serves the same thing locally on :5290. -- **Homepage** — `https://jonocodes.github.io/deckd/`. Source in `site/`; its phones embed the client's showcase demo decks (`?demo=home`, `gmail`, `meet`, `media`, …). -- **Live client (demo mode)** — `https://jonocodes.github.io/deckd/app/?demo=showcase` (also `?demo=firefox`, `?demo=home`). Without `?demo=` the client loads and shows "disconnected" since there's no daemon behind the Pages site; the param lets the fixture deck run. Deep links to a view (`app/trackpad`) work too: the site's `404.html` is the client. -- **Responsive gallery** — `https://jonocodes.github.io/deckd/app/gallery.html`. -- **Layout help** — `https://jonocodes.github.io/deckd/app/help.html`. The standalone build of the in-app explainer (below); no daemon, no icons. -- **Ladle stories** — `https://jonocodes.github.io/deckd/ladle/`. - -Source: `.github/workflows/deploy-pages.yml`. The client builds with `VITE_BASE_PATH=/deckd/app/` and Ladle with `--base /deckd/ladle/` so the Project-Pages sub-paths resolve; local dev keeps base `/`. `just build-pages` assembles the same tree into `_site/deckd/`; `just pages` builds and serves it. +- **Homepage** — [jonocodes.github.io/deckd/](https://jonocodes.github.io/deckd/). Source in `site/`; its phones embed the client's showcase demo decks (`?demo=home`, `gmail`, `meet`, `media`, …). +- **Live demo** — [jonocodes.github.io/deckd/demo/](https://jonocodes.github.io/deckd/demo/). Pick an app on a pretend desktop and the client (below) switches to its deck. Source in `site/demo/`. +- **Demo client** — `demo/client/` is the real client running on pretend data. It's there only for the homepage and the demo page to embed (`demo/client/?demo=gmail`, …), so nothing links to it; a visit without `?demo=` (or `?playground`) forwards to the demo page (`VITE_DEMO_PAGE`, set by `scripts/build_pages.sh`). A daemon-served client never redirects. Deep links to a view (`demo/client/trackpad?demo=firefox`) work because the site's `404.html` is the client. +- **Responsive gallery** — [jonocodes.github.io/deckd/demo/client/gallery.html](https://jonocodes.github.io/deckd/demo/client/gallery.html). +- **Layout help** — [jonocodes.github.io/deckd/demo/client/help.html](https://jonocodes.github.io/deckd/demo/client/help.html). The standalone build of the in-app explainer (below); no daemon, no icons. +- **Ladle stories** — [jonocodes.github.io/deckd/ladle/](https://jonocodes.github.io/deckd/ladle/). + +Source: `.github/workflows/deploy-pages.yml`. The client builds with `VITE_BASE_PATH=/deckd/demo/client/` and Ladle with `--base /deckd/ladle/` so the Project-Pages sub-paths resolve; local dev keeps base `/`. `just build-pages` assembles the same tree into `_site/deckd/`; `just pages` builds and serves it (`PAGES_HOST=0.0.0.0 just pages` to reach it from another device, e.g. over Tailscale). ### PWA install over HTTPS (Tailscale) diff --git a/docs/ONBOARDING.md b/docs/ONBOARDING.md index afeee8e..b0c8bb5 100644 --- a/docs/ONBOARDING.md +++ b/docs/ONBOARDING.md @@ -82,7 +82,7 @@ This document is the primary navigation map for AI agents (and human developers) │ ├── kwin-script/ # KWin focus script (KDE Plasma Wayland) │ └── gnome-shell/ # GNOME Shell focus extension ├── scripts/ # Diagnostic and testing utilities; build_pages.sh assembles the Pages site -├── site/ # GitHub Pages homepage (jonocodes.github.io/deckd/); the client deploys under app/ +├── site/ # GitHub Pages homepage (jonocodes.github.io/deckd/); the client deploys under demo/client/ (embedded by the homepage and demo page) ├── tests/ # Python test suite (pytest + pytest-asyncio) └── docs/ # Documentation (see below) ├── GUIDE.md # User & setup guide: install, per-platform setup, config walkthrough, client features, dev loop diff --git a/docs/mockups/homepage/README.md b/docs/mockups/homepage/README.md index a887769..241531d 100644 --- a/docs/mockups/homepage/README.md +++ b/docs/mockups/homepage/README.md @@ -27,7 +27,7 @@ just mockups # → http://127.0.0.1:5289/docs/mockups/homepage/a-notebook.html (and c-press.html) # → http://127.0.0.1:5289/site/index.html?app=http://127.0.0.1:5288/ (B, live dev client) just pages -# → http://127.0.0.1:5290/deckd/ (B exactly as deployed: built site, client at app/) +# → http://127.0.0.1:5290/deckd/ (B exactly as deployed: built site, client at demo/client/) ``` The phones show the showcase demo decks (`?demo=home`, `gmail`, `meet`, @@ -38,6 +38,6 @@ directly: a `file://` page can't frame localhost in current browsers, so the phones stay blank. `?app=` points the phones at another client. The homepage defaults to the -client beside it (`app/`); A and C fall back to the public build at -`https://jonocodes.github.io/deckd/app/`. Add `?eager` to load every phone +client beside it (`demo/client/`); A and C fall back to the public build at +`https://jonocodes.github.io/deckd/demo/client/`. Add `?eager` to load every phone up front (for full-page screenshots). diff --git a/scripts/build_pages.sh b/scripts/build_pages.sh index 32d62d2..c9c6beb 100755 --- a/scripts/build_pages.sh +++ b/scripts/build_pages.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Assemble the GitHub Pages site: the homepage (site/) at the root, the client -# under app/, Ladle under ladle/. CI (.github/workflows/deploy-pages.yml) and +# under demo/client/ (it only exists to be embedded by the homepage and the +# demo page), Ladle under ladle/. CI (.github/workflows/deploy-pages.yml) and # `just pages` both run this, so a local preview is exactly what deploys. # # Usage: scripts/build_pages.sh [OUT_DIR] (default: _site) @@ -20,12 +21,14 @@ cp -rL "$root/site/." "$out/" cd "$root/client" # `npm run build` type-checks first, so a type error fails the deploy. -VITE_BASE_PATH="${base}app/" npm run build -- --outDir "$out/app" --emptyOutDir +# VITE_DEMO_PAGE: with no daemon here, a visit with no demo to show forwards to +# the demo page (client/src/demo-landing.ts) instead of "Reconnecting…". +VITE_BASE_PATH="${base}demo/client/" VITE_DEMO_PAGE="${base}demo/" npm run build -- --outDir "$out/demo/client" --emptyOutDir # Pages serves the site's 404.html for any unknown path. Make it the client, -# so a deep link like app/trackpad boots the app (its asset URLs are +# so a deep link like demo/client/trackpad boots the app (its asset URLs are # absolute, so they resolve from any path) instead of a bare 404. -cp "$out/app/index.html" "$out/404.html" +cp "$out/demo/client/index.html" "$out/404.html" if [ -z "${SKIP_LADLE:-}" ]; then # Ladle won't create its outDir, and joins even an absolute --outDir onto diff --git a/scripts/serve_pages.mjs b/scripts/serve_pages.mjs index 4b99ed0..0ec270e 100644 --- a/scripts/serve_pages.mjs +++ b/scripts/serve_pages.mjs @@ -2,7 +2,8 @@ // static files, `dir/` → `dir/index.html`, and the site's 404.html (with a // 404 status) for anything else — which is what makes app deep links work. // -// Usage: node scripts/serve_pages.mjs [port] (default port 5290) +// Usage: node scripts/serve_pages.mjs [port] [host] +// (default port 5290, host 127.0.0.1; 0.0.0.0 to reach it from another device) // is the directory holding the site under its base, e.g. _site for // _site/deckd/. import { createServer } from "node:http"; @@ -11,6 +12,7 @@ import { extname, join, normalize, resolve } from "node:path"; const root = resolve(process.argv[2] ?? "_site"); const port = Number(process.argv[3] ?? 5290); +const host = process.argv[4] ?? "127.0.0.1"; const TYPES = { ".html": "text/html; charset=utf-8", ".js": "text/javascript", ".mjs": "text/javascript", ".css": "text/css", ".json": "application/json", ".svg": "image/svg+xml", ".png": "image/png", @@ -40,4 +42,4 @@ createServer(async (req, res) => { if (!path) return res.writeHead(404).end("not found"); res.writeHead(status, { "content-type": TYPES[extname(path)] ?? "application/octet-stream" }); res.end(await readFile(path)); -}).listen(port, "127.0.0.1", () => console.log(`serving ${root} on http://127.0.0.1:${port}/`)); +}).listen(port, host, () => console.log(`serving ${root} on http://${host}:${port}/`)); diff --git a/site/demo/index.html b/site/demo/index.html new file mode 100644 index 0000000..31200bd --- /dev/null +++ b/site/demo/index.html @@ -0,0 +1,130 @@ + + + + + +deckd — demo + + + + + + + + + + + + +
+
+ deckd + +
+ +
+
Live demo
+

Pick an app.

+

Click a window on the pretend desktop and the phone switches to that app's deck, the way deckd follows your focus. The phone is the real client: its bottom bar opens the trackpad, now playing and settings. With no computer attached, deck buttons don't send anything.

+
+ +
+
+
your desktopfocus →
+
    +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
+
orientation + + +
+
    +
  • ♫ in the bottom bar: now playing, from any deck
  • +
  • ✋: trackpad and keyboard
  • +
  • ⚙: per-device settings
  • +
+
+
+
+ + +
+ + diff --git a/site/index.html b/site/index.html index 0555fc2..47b00dc 100644 --- a/site/index.html +++ b/site/index.html @@ -1,11 +1,11 @@ - + deckd — your phone becomes the buttons for whatever's on screen @@ -41,10 +41,20 @@ header nav { margin-left: auto; display: flex; gap: 22px; color: var(--muted); } header nav a { text-decoration: none; } header nav a:hover { color: var(--text); } + /* narrow screens: drop the in-page jumps so the header stays on one line */ + @media (max-width: 560px) { header nav { gap: 16px; } header nav .wide { display: none; } } .hero { padding: 64px 0 40px; display: grid; grid-template-columns: 1fr; gap: 12px; } .label { font: 500 12px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--orange); } h1 { font-size: 52px; line-height: 1.05; font-weight: 600; letter-spacing: -0.02em; margin: 0; max-width: 13em; } + /* "Your phone / tablet / laptop becomes…": the words share one grid cell + and the box eases to the current word's width, so "becomes" follows it + without a gap. Without JS (or with reduced motion) it just says phone. */ + h1 .swap { display: inline-grid; color: var(--orange); transition: width .35s ease; } + h1 .swap > span { grid-area: 1 / 1; justify-self: start; opacity: 0; transform: translateY(.25em); transition: opacity .35s, transform .35s; } + h1 .swap:not(.js) > span:first-child, h1 .swap > span.on { opacity: 1; transform: none; } + h1 .swap > span.out { transform: translateY(-.25em); } + .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; } .hero p { color: var(--muted); font-size: 18px; max-width: 36em; margin: 8px 0 0; } /* The stage: a fake desktop window strip driving a live phone. */ @@ -109,6 +119,8 @@ .feature.stack .copy .label { grid-column: 1 / -1; } .feature.stack .copy h2 { margin-bottom: 0; } .feature.stack .copy p { max-width: 34em; margin: 0; } + .feature.stack .copy p + p { margin-top: 10px; } + .feature p b { color: var(--text); font-weight: 500; } @media (max-width: 860px) { .feature.stack .copy { grid-template-columns: 1fr; } .feature.stack .copy p { margin-top: 10px; } } .feature h2 { font-size: 30px; line-height: 1.15; letter-spacing: -0.015em; margin: 10px 0 12px; } .feature p { color: var(--muted); margin: 0 0 12px; } @@ -148,16 +160,17 @@ deckd
Context-aware controller
-

Your phone becomes the buttons for whatever's on screen.

+

Your phone, tablet or laptop becomes the buttons for whatever's on screen.

deckd watches which app — or website — is focused on your computer and hands the right buttons to any browser on your network.

@@ -178,6 +191,7 @@

Your phone becomes the buttons for whatever's on screen.

@@ -202,9 +216,10 @@

Every player, one list.

-
Trackpad
-

The phone is the mouse.

-

For whatever a deck doesn't cover: drag to move, tap to click, and a keyboard for typing a URL from the couch.

+
Trackpad and keyboard
+

The phone is the mouse. And the keyboard.

+

For whatever a deck doesn't cover: drag to move, tap to click. Type on your phone and the words land in whatever's focused on the computer as you go.

+

Or just talk. Tap the mic on your phone's keyboard and dictate a search, a message or a URL from the couch. Your phone does the voice typing; deckd types it out on your desktop.

@@ -271,5 +286,23 @@

Questions.

License

GPL-3.0No account, no cloud
+ diff --git a/site/shared/content.js b/site/shared/content.js index 3fc6d39..9389cab 100644 --- a/site/shared/content.js +++ b/site/shared/content.js @@ -73,10 +73,12 @@ const TODAY = [ "Password sign-in, network scope, lock awareness", "Keyboard, screen-reader, high-contrast and reduced-motion support", "Linux (GNOME, KDE, X11) and macOS, plus a Nix flake", + "Downloads: an AppImage for Linux, a DMG for macOS", ]; const NEXT = [ - ["Downloadable app for Linux and macOS", 168], ["A browser extension for exact website matching", 90], + ["Different decks on different devices", null], + ["Pick between several computers", 25], ["Windows", null], ]; function roadmap(root) { @@ -99,8 +101,6 @@ const FAQ = [ "With the editor in the app: pick widgets, set icons and colours, drag to reorder, save. Every screen updates as you go. Decks are plain text files too, if you'd rather."], ["What can a button do?", "Press a key combination, run a command, open a URL, start a terminal, call D-Bus — or chain several into a macro."], - ["Is it free?", - `Yes — open source under GPL-3.0. Issues and ideas are welcome on GitHub.`], ]; function faq(root) { root.append(el(`
${FAQ.map(([q, a]) => `
${q}

${a}

`).join("")}
`)); diff --git a/site/shared/scenes.js b/site/shared/scenes.js index 9c4f398..06b30c4 100644 --- a/site/shared/scenes.js +++ b/site/shared/scenes.js @@ -9,7 +9,7 @@ // Served locally (`just mockups`), default to the local client on :5288. const LOCAL = /^https?:$/.test(location.protocol) && ["127.0.0.1", "localhost"].includes(location.hostname); const APP = new URLSearchParams(location.search).get("app") || document.documentElement.dataset.app - || (LOCAL ? `${location.protocol}//${location.hostname}:5288/` : "https://jonocodes.github.io/deckd/app/"); + || (LOCAL ? `${location.protocol}//${location.hostname}:5288/` : "https://jonocodes.github.io/deckd/demo/client/"); const LANDSCAPE = [700, 390]; // a 4x2 deck fills this edge to edge const PORTRAIT = [390, 760]; const reduced = matchMedia("(prefers-reduced-motion: reduce)").matches; @@ -208,6 +208,49 @@ function webapps(root) { // ---------------------------------------------------------------- now playing function nowplaying(root) { root.append(phone("demo=media", { size: PORTRAIT }).el); } +// ---------------------------------------------------------------- picker +// The demo page: click a "window" ([data-q] buttons inside the mount) to +// focus it, and one large, tappable phone switches to that deck. The phone +// starts landscape and stays in whichever orientation a [data-orient-mode] +// button (landscape | portrait) last picked. One iframe per item, loaded up front and +// kept alive, so switching back keeps whatever view you'd opened there. +function picker(root) { + const items = [...root.querySelectorAll("[data-q]")]; + const modes = [...root.querySelectorAll("[data-orient-mode]")]; + const el = h('
'); + const screen = el.querySelector(".dk-screen"), stage = el.querySelector(".dk-stage"); + const frames = items.map((it) => { + const f = h(``); + f.hidden = true; + stage.append(f); + return f; + }); + let size = LANDSCAPE, current = 0; + const fit = () => { + stage.style.width = size[0] + "px"; + stage.style.height = size[1] + "px"; + screen.style.aspectRatio = `${size[0]} / ${size[1]}`; + el.classList.toggle("portrait", size[1] > size[0]); + stage.style.transform = `scale(${screen.clientWidth / size[0]})`; + }; + new ResizeObserver(fit).observe(screen); + const select = (k) => { + current = k; + items.forEach((it, j) => it.setAttribute("aria-pressed", j === k)); + frames.forEach((f, j) => (f.hidden = j !== k)); + fit(); + }; + items.forEach((it, k) => it.addEventListener("click", () => select(k))); + modes.forEach((b) => b.addEventListener("click", () => { + // The orientation sticks across apps until switched here. + size = b.dataset.orientMode === "portrait" ? PORTRAIT : LANDSCAPE; + modes.forEach((o) => o.setAttribute("aria-pressed", o === b)); + fit(); + })); + (root.querySelector(".dk-picker-phone") || root).append(el); + select(0); +} + // A single passive phone:
. function single(root) { root.append(phone(root.dataset.q).el); } @@ -264,7 +307,7 @@ addEventListener("scroll", () => { lastActive = a; lastY = scrollY; }, { passive: true }); -const MOUNTS = { cycle, trackpad, scroll, focus, webapps, nowplaying, install, phone: single, ...(window.DK_CONTENT || {}) }; +const MOUNTS = { cycle, trackpad, scroll, focus, webapps, nowplaying, install, picker, phone: single, ...(window.DK_CONTENT || {}) }; document.querySelectorAll("[data-dk]").forEach((el) => MOUNTS[el.dataset.dk]?.(el)); // For pages that mount scenes on demand (design C's readout).