Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/cursor/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
// the nub path is covered by tests/cursor.test.ts).

import { Text, View } from "@pocketjs/framework/components";
import { createSignal } from "solid-js";
import { enableCursor } from "@pocketjs/framework/input";
import { createSignal, onCleanup } from "solid-js";

const ROWS = ["REPLAY TAPE", "OPEN MEMORY STICK", "LAUNCH SHELL"] as const;

export default function CursorDemo() {
// Keep the feature opt-in with the editable component so the Playground
// exercises the same cursor path as the packaged entry. Disposing the demo
// restores classic d-pad focus before another Playground app mounts.
onCleanup(enableCursor({ dpadSpeed: 60 }));
const [status, setStatus] = createSignal("hover a row, press CIRCLE");
return (
<View class="w-full h-full flex-col items-center justify-center gap-[10] bg-[#008080]">
Expand Down
6 changes: 0 additions & 6 deletions apps/cursor/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// @title PocketJS: Cursor
import CursorDemo from "./app.tsx";
import { mount } from "@pocketjs/framework";
import { enableCursor } from "@pocketjs/framework/input";

// Opt in to the virtual cursor (input.cursor). Safe before mount — the
// sprite uploads lazily on the first frame. dpadSpeed keeps the golden tape
// button-only (1 px/frame); the nub steers at the default 240 px/s.
enableCursor({ dpadSpeed: 60 });

mount(() => <CursorDemo />);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"dev": "bun tools/dev.ts",
"wasm": "bun tools/wasm.ts",
"site:build": "bun tools/site-build.ts",
"site:verify-playground": "bun run site:build && bun site/verify-playground.ts",
"gba:imagegen": "bun imagegen",
"vapor": "bun vapor/compiler/cli.ts vapor/examples/todo/todo.tsx",
"vapor:play": "bun vapor/scripts/play.ts",
Expand Down
277 changes: 230 additions & 47 deletions site/build.ts

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions site/playground/compiler-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { transformAsync, type PluginObj } from "@babel/core";
import solidPreset from "babel-preset-solid";
import tsPreset from "@babel/preset-typescript";
import { transformVueJsxVapor } from "vue-jsx-vapor/api";
import { compile as octaneCompile } from "octane/compiler";
import { parse as parseFont, type Font } from "opentype.js";

import { compileClasses, fontSlotInfo } from "../../framework/compiler/tailwind.ts";
Expand Down Expand Up @@ -176,9 +175,10 @@ function collectorPlugin(out: Collected, framework: PlaygroundFramework): Plugin

/** Run the exact build transform in the browser. Throws with a code frame on
* lint/syntax errors (message carries the frame). */
async function transform(
export async function transformAppSource(
source: string,
framework: PlaygroundFramework,
baseUrl = typeof location === "undefined" ? "https://pocketjs.dev/" : location.href,
): Promise<{ code: string; collected: Collected }> {
const collected: Collected = { classStrings: [], codepoints: new Set() };
let res;
Expand All @@ -197,7 +197,7 @@ async function transform(
"app.tsx",
{
compiler: {
runtimeModuleName: new URL("/pg/vue-jsx-vapor/vapor.js", location.href).href,
runtimeModuleName: new URL("/pg/vue-jsx-vapor/vapor.js", baseUrl).href,
},
},
false,
Expand All @@ -222,7 +222,11 @@ async function transform(
configFile: false,
sourceMaps: false,
});
res = octaneCompile(source, "app.tsx", { mode: "client", renderer: OCTANE_RENDERER }) as {
// Load this branch lazily. Octane marks its package side-effect free; a
// static import from 0.1.26 was pruned by Bun while its call site survived,
// leaving every Octane demo with an undefined minified binding.
const { compile } = await import("octane/compiler");
res = compile(source, "app.tsx", { mode: "client", renderer: OCTANE_RENDERER }) as {
code: string;
};
} else {
Expand Down Expand Up @@ -340,7 +344,7 @@ export async function compileApp(
} = {},
): Promise<CompileResult> {
const framework = opts.framework ?? "solid";
const { code, collected } = await transform(source, framework);
const { code, collected } = await transformAppSource(source, framework);

const styles = compileClasses(collected.classStrings);
const atlases = await bakeAtlases(collected.codepoints, styles.usedFontSlots, opts.extraChars ?? "");
Expand Down
13 changes: 11 additions & 2 deletions site/playground/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function loadCompiler() {
const $ = (sel) => document.querySelector(sel);

async function main() {
const query = new URLSearchParams(location.search);
const verifyMode = query.get("verify") === "1";
const canvas = $("#pg-canvas");
const statusEl = $("#pg-status");
const errorEl = $("#pg-error");
Expand All @@ -49,10 +51,13 @@ async function main() {

// --- host -----------------------------------------------------------------
const host = new PocketHost();
if (verifyMode) globalThis.__pgHost = host;
await host.mount(canvas, {
wasmUrl: PG + "pocketjs.wasm",
onError: (e) => showError(String(e && e.stack ? e.stack : e)),
onLog: () => {},
showHud: !verifyMode,
idleAfterMs: verifyMode ? 0 : Infinity,
});

// --- editor ---------------------------------------------------------------
Expand Down Expand Up @@ -172,6 +177,10 @@ async function main() {
try {
await import(/* @vite-ignore */ bootUrl);
host.begin();
// Browser regression mode advances exact virtual frames itself. Stop
// the RAF after begin()'s single initial frame so ambient animation or
// HUD timing cannot masquerade as an input result.
if (verifyMode) host.stop();
const ms = Math.round(performance.now() - t0);
const fwLabel = { "vue-vapor": "Vue Vapor", octane: "Octane" }[activeFramework] || "Solid";
setStatus(
Expand Down Expand Up @@ -232,8 +241,8 @@ async function main() {
canvas.addEventListener("click", () => canvas.focus());

// boot with the first demo (or a fallback), honoring ?demo=
const boot = new URLSearchParams(location.search).get("demo");
const bootFramework = new URLSearchParams(location.search).get("framework");
const boot = query.get("demo");
const bootFramework = query.get("framework");
if (boot && demos.some((d) => d.name === boot)) demoSel.value = boot;
if (
(bootFramework === "vue-vapor" || bootFramework === "octane") &&
Expand Down
16 changes: 14 additions & 2 deletions site/playground/runtime-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// a bare `export *` would hit, e.g. app-`render` vs universal-`render`).

// ---- public app surface -----------------------------------------------------
export { frameworkName, mount, render } from "../../framework/src/index.ts";
export { frameworkName, mount, registerTexture, render } from "../../framework/src/index.ts";
export {
View,
Text,
Expand All @@ -37,7 +37,13 @@ export {
Lazy,
Gallery,
} from "../../framework/src/components.ts";
export { animate, spring, cancelAnim } from "../../framework/src/animation.ts";
export {
animate,
spring,
cancelAnim,
jump,
createJumpBatch,
} from "../../framework/src/animation.ts";
export {
onFrame,
onButtonPress,
Expand All @@ -46,11 +52,17 @@ export {
} from "../../framework/src/lifecycle.ts";
export {
BTN,
enableCursor,
focusNode,
getFocused,
pushFocusGrid,
pushFocusScope,
touches,
} from "../../framework/src/input-api.ts";
export { createWavPlayer } from "../../framework/src/audio-api.ts";
export { ticksPerFrame } from "../../framework/src/clock.ts";
export { getOps, hostViewport } from "../../framework/src/host.ts";
export { appTable, frozenShot, launchApp } from "../../framework/src/launcher.ts";

// ---- universal-renderer surface (what babel-preset-solid imports from the
// `moduleName` specifier — must exist under this one module) ------------------
Expand Down
10 changes: 8 additions & 2 deletions site/playground/runtime-octane-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

export * from "../../framework/src/renderer-octane.ts";

export { frameworkName, mount, render } from "../../framework/src/index-octane.ts";
export {
frameworkName,
mount,
render,
setTextContent,
} from "../../framework/src/index-octane.ts";
export {
View,
Text,
Expand All @@ -24,7 +29,7 @@ export {
Lazy,
Gallery,
} from "../../framework/src/components-octane.tsx";
export { animate, spring, cancelAnim } from "../../framework/src/animation.ts";
export { animate, spring, cancelAnim, jump } from "../../framework/src/animation.ts";
export {
useFrame,
useButtonPress,
Expand All @@ -38,6 +43,7 @@ export {
pushFocusGrid,
pushFocusScope,
} from "../../framework/src/input-api.ts";
export { createWavPlayer } from "../../framework/src/audio-api.ts";

import {
resetRendererState,
Expand Down
1 change: 1 addition & 0 deletions site/playground/runtime-vue-vapor-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export {
pushFocusGrid,
pushFocusScope,
} from "../../framework/src/input-api.ts";
export { createWavPlayer } from "../../framework/src/audio-api.ts";

import {
resetRendererState,
Expand Down
Loading