@vibes.diy/prompts 14.3.234 → 14.3.235

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,8 @@ The play area is the controller: the whole game surface carries `select-none tou
11
11
 
12
12
  The game fills the screen: the play surface is a `relative h-dvh w-full` root, never a card on a scrolling page — scores, records and leaderboards go behind the menu button, not below the game.
13
13
 
14
+ The game wears the app's look: once the canvas fills the screen it is most of what the person sees, so the world is painted in the look's colours and the HUD over it is the kit's own components (see _The look reaches the play area_ below).
15
+
14
16
  Three things make that true, and each has one home:
15
17
 
16
18
  1. **The surface belongs to the finger.** `select-none touch-none` on the full-screen container
@@ -75,9 +77,8 @@ export default function App() {
75
77
  pull starts.
76
78
  - **One line of hint text** names the gestures in the HUD; that line is the whole tutorial.
77
79
  - **HUD ink contrasts with what the canvas paints.** A neon game painted near-black needs light
78
- HUD text: either paint the canvas from the theme (`bg-background`, ink read from the root's
79
- computed `color`, as the worked example does) or give the HUD a `Card` / `bg-background/80`
80
- backing so the score reads on any frame.
80
+ HUD text: paint the canvas from the theme (`readLook`, below, as both worked examples do) and
81
+ give the HUD a `Card` backing so the score reads on any frame.
81
82
  - **Start on the first touch.** The touch that starts a run only starts it (it does not also
82
83
  jump or dash); a tap restarts after game over, after a short grace period so a frantic swipe
83
84
  at the moment of the crash does not skip the score screen.
@@ -212,6 +213,7 @@ import React from "react";
212
213
  import * as THREE from "three";
213
214
  import { useWorldControls } from "use-vibes";
214
215
  import { Button, Card, Heading, IconButton, Stack, Text } from "@vibes.diy/ui";
216
+ import { readLook, watchLook } from "./look.js";
215
217
 
216
218
  const VIEWS = ["Free cam", "First person", "Shoulder view"];
217
219
  const HINT = {
@@ -230,7 +232,7 @@ export default function App() {
230
232
  const [howTo, setHowTo] = React.useState(false);
231
233
  const [full, setFull] = React.useState(false);
232
234
  const me = React.useRef({ pos: new THREE.Vector3(0, 0, 12), yaw: 0, pitch: 0, move: [0, 0], vy: 0, zoom: 34 });
233
- const world = React.useRef({ hedges: [] });
235
+ const world = React.useRef({ hedges: [], colors: null });
234
236
 
235
237
  const turn = (yaw, pitch) => {
236
238
  me.current.yaw += yaw;
@@ -243,6 +245,11 @@ export default function App() {
243
245
  ray.setFromCamera(new THREE.Vector2(((x - r.left) / r.width) * 2 - 1, 1 - ((y - r.top) / r.height) * 2), camera);
244
246
  return ray.intersectObjects(world.current.hedges)[0]?.object;
245
247
  };
248
+ const bloom = (hedge, on) => {
249
+ if (!hedge) return;
250
+ hedge.userData.bloom = on;
251
+ hedge.material.color.set(on ? world.current.colors.accent : world.current.colors.lead);
252
+ };
246
253
  const { isTouch, locked, requestLock, tick } = useWorldControls(rootRef, {
247
254
  mode: view === "Free cam" ? "free" : "player",
248
255
  camera,
@@ -250,8 +257,8 @@ export default function App() {
250
257
  onLook: look,
251
258
  onTurn: look,
252
259
  onPinch: (factor) => (me.current.zoom = Math.max(8, Math.min(60, me.current.zoom * factor))),
253
- onTap: (x, y) => hedgeAt(x, y)?.material.color.set(0xff6fb1),
254
- onHold: (x, y) => hedgeAt(x, y)?.material.color.set(0x2f7a3a),
260
+ onTap: (x, y) => bloom(hedgeAt(x, y), true),
261
+ onHold: (x, y) => bloom(hedgeAt(x, y), false),
255
262
  onFlick: (dir) => dir === "up" && me.current.pos.y === 0 && (me.current.vy = 7),
256
263
  });
257
264
  const live = React.useRef({});
@@ -264,20 +271,35 @@ export default function App() {
264
271
  const size = new ResizeObserver(() => renderer.setSize(root.clientWidth, root.clientHeight, false));
265
272
  size.observe(root);
266
273
  const scene = new THREE.Scene();
267
- scene.background = new THREE.Color(0x9fe3ff);
268
- scene.add(new THREE.HemisphereLight(0xffffff, 0x3b5d2a, 1.4));
274
+ scene.fog = new THREE.Fog(0x000000, 30, 90);
275
+ const light = new THREE.HemisphereLight(0xffffff, 0xffffff, 1.4);
276
+ scene.add(light);
269
277
  const groundGeo = new THREE.PlaneGeometry(60, 60);
270
- const ground = new THREE.Mesh(groundGeo, new THREE.MeshLambertMaterial({ color: 0x6fcf5b }));
278
+ const ground = new THREE.Mesh(groundGeo, new THREE.MeshLambertMaterial());
271
279
  ground.rotation.x = -Math.PI / 2;
272
280
  scene.add(ground);
273
281
  const hedgeGeo = new THREE.BoxGeometry(5, 2, 1);
274
282
  for (let i = 0; i < 10; i++) {
275
- const hedge = new THREE.Mesh(hedgeGeo, new THREE.MeshLambertMaterial({ color: 0x2f7a3a }));
283
+ const hedge = new THREE.Mesh(hedgeGeo, new THREE.MeshLambertMaterial());
276
284
  hedge.position.set(Math.cos(i * 0.63) * 18, 1, Math.sin(i * 0.63) * 18);
277
285
  hedge.lookAt(0, 1, 0);
278
286
  scene.add(hedge);
279
287
  world.current.hedges.push(hedge);
280
288
  }
289
+ // The garden wears the app's look: sky, light, ground and hedges all come from its tokens, and
290
+ // a restyle repaints them in place while the player keeps walking.
291
+ const paint = (colors) => {
292
+ world.current.colors = colors;
293
+ const sky = new THREE.Color(colors.backdrop).lerp(new THREE.Color(colors.lead), 0.2);
294
+ scene.background = sky;
295
+ scene.fog.color.copy(sky);
296
+ light.color.set(colors.surface);
297
+ light.groundColor.set(colors.lead);
298
+ ground.material.color.set(colors.surface);
299
+ for (const hedge of world.current.hedges) hedge.material.color.set(hedge.userData.bloom ? colors.accent : colors.lead);
300
+ };
301
+ paint(readLook(root));
302
+ const unwatch = watchLook(root, paint);
281
303
 
282
304
  let raf = 0;
283
305
  let last = performance.now();
@@ -310,6 +332,7 @@ export default function App() {
310
332
 
311
333
  return () => {
312
334
  cancelAnimationFrame(raf);
335
+ unwatch();
313
336
  size.disconnect();
314
337
  world.current.hedges.forEach((hedge) => hedge.material.dispose());
315
338
  world.current.hedges = [];
@@ -421,6 +444,99 @@ the controls without a tutorial.
421
444
  `navigator.vibrate?.(10)` where the phone supports it, and WebAudio beeps created on the first
422
445
  gesture (audio can only start from a user gesture).
423
446
 
447
+ ## The look reaches the play area
448
+
449
+ The look reaches the play area: the canvas paints with the app's own tokens, and the HUD over it is the kit's components on the look's surfaces.
450
+
451
+ A full-screen game is judged by its first screenshot, and that screenshot is mostly canvas. The
452
+ world, the overlays, the hotbar and the buttons all speak the look, so the game reads as the
453
+ same crafted app as everything else the person made.
454
+
455
+ **The world takes the look's colours.** Resolve the theme tokens to concrete colours once per
456
+ mount and paint every large area from them: the sky or backdrop from `--background` leaned toward
457
+ `--primary`, fog from the same colour so the horizon melts into it, the light from `--primary`
458
+ over `--surface`, the player and the thing to chase in `--primary` and `--accent`, guides and lane
459
+ lines in `--border`, and text drawn on the canvas in `--text-primary`. A game's own materials (a
460
+ voxel world's block table, a racer's track paint) keep their names and colours; the look owns
461
+ everything around them.
462
+
463
+ ```js
464
+ // look.js — the look's tokens as colours a 2D canvas or a Three.js scene can paint with.
465
+ // A computed colour can come back as oklch(), color-mix() or a translucent rgba(); filling one pixel
466
+ // over `under` turns any of them into the opaque hex the eye sees, which THREE.Color and
467
+ // ctx.fillStyle both read.
468
+ export function cssColor(host, token, fallback, under = "#ffffff") {
469
+ const probe = document.createElement("span");
470
+ probe.style.display = "none";
471
+ probe.style.color = `var(${token}, ${fallback})`;
472
+ host.appendChild(probe);
473
+ const value = getComputedStyle(probe).color;
474
+ probe.remove();
475
+ const ctx = document.createElement("canvas").getContext("2d");
476
+ ctx.fillStyle = under;
477
+ ctx.fillRect(0, 0, 1, 1);
478
+ ctx.fillStyle = fallback;
479
+ ctx.fillStyle = value; // a value the canvas cannot parse leaves the fallback in place
480
+ ctx.fillRect(0, 0, 1, 1);
481
+ const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
482
+ return `#${[r, g, b].map((n) => n.toString(16).padStart(2, "0")).join("")}`;
483
+ }
484
+
485
+ // A look may give its surface or border as a tint over the background (a dark look's surface
486
+ // can be rgba(255,255,255,0.04)), so every other token lands on the resolved backdrop.
487
+ export function readLook(host) {
488
+ const backdrop = cssColor(host, "--background", "#f7f3ea");
489
+ return {
490
+ backdrop,
491
+ surface: cssColor(host, "--surface", "#ffffff", backdrop),
492
+ lead: cssColor(host, "--primary", "#5b4bff", backdrop),
493
+ accent: cssColor(host, "--accent", "#ff7a59", backdrop),
494
+ ink: cssColor(host, "--text-primary", "#1a1325", backdrop),
495
+ line: cssColor(host, "--border", "#d9d2c3", backdrop),
496
+ };
497
+ }
498
+
499
+ // The Style tab restyles a running app by rewriting a <style> in the document head, with no
500
+ // remount, so the canvas is told: onChange gets a fresh look and repaints without a restart.
501
+ export function watchLook(host, onChange) {
502
+ const observer = new MutationObserver(() => onChange(readLook(host)));
503
+ observer.observe(document.head, { childList: true, subtree: true, characterData: true });
504
+ return () => observer.disconnect();
505
+ }
506
+ ```
507
+
508
+ Read the look inside the effect that builds the scene, and call `watchLook` in the same effect
509
+ with its cleanup, so a restyle recolours the world in place (the Walk + look garden above keeps
510
+ its sky, light and materials in one `paint(colors)` it runs at mount and on every change):
511
+
512
+ ```js
513
+ const look = readLook(containerRef.current);
514
+ const sky = new THREE.Color(look.backdrop).lerp(new THREE.Color(look.lead), 0.2);
515
+ scene.background = sky;
516
+ scene.fog = new THREE.Fog(sky, 40, 120);
517
+ scene.add(new THREE.HemisphereLight(look.lead, look.surface, 0.9));
518
+ const sun = new THREE.DirectionalLight(look.surface, 1.4);
519
+ ```
520
+
521
+ A day/night cycle blends between two look colours (`backdrop` toward `lead` by day, toward `ink`
522
+ by night), so every hour of the day still belongs to the app.
523
+
524
+ **The HUD is the kit, on the look's surfaces.** Everything drawn over the world is a component
525
+ from `@vibes.diy/ui`, so it brings the look's type, radius, border and weight with it:
526
+
527
+ - The title sits in a `Heading` on a `Card` (or a `Row` on `bg-surface`) at full ink, so it reads
528
+ over a bright sky or a dark cave alike.
529
+ - Score and best are `Metric`s on a `Card`; a timer or lap count is one more `Metric`.
530
+ - The hotbar is a `Row` of `IconButton`s on a `Card`: the selected slot carries `tint` with the
531
+ active colour and `aria-pressed`, the rest stay `variant="quiet"`.
532
+ - Start, pause and game-over screens are a `Card` or `Dialog` with a `Heading`, one lead `Button`
533
+ and a quiet second action.
534
+ - Overlay text keeps the look's own foreground and muted tones at full opacity; a scrim behind it
535
+ comes from `bg-background` or `bg-surface`.
536
+
537
+ Read the first screenshot before you finish: the sky, the ground, the HUD and the title should
538
+ look like they came from the app's palette and type, the way its list pages do.
539
+
424
540
  ## The engine around it
425
541
 
426
542
  One `useEffect(() => {…}, [])` owns the loop, the listeners and the cleanup; the loop is one
@@ -432,14 +548,16 @@ tuned in one place.
432
548
 
433
549
  ## Worked example: a three-lane dodge, start to finish
434
550
 
435
- The whole shape in one file: the surface, the mid-move swipe recogniser, a keyboard twin, a
436
- finger trail, and an engine that cleans up after itself. Grow it into a runner, a racer or a
551
+ The whole shape in one file beside `look.js` from the section above: the surface, the mid-move
552
+ swipe recogniser, a keyboard twin, a finger trail, a world painted in the look's colours, and an
553
+ engine that cleans up after itself. Grow it into a runner, a racer or a
437
554
  snake by changing what `move()` does.
438
555
 
439
556
  ### `App.jsx`
440
557
  ```jsx
441
558
  import React from "react";
442
- import { Card, Heading, IconButton, Stack, Text } from "@vibes.diy/ui";
559
+ import { Card, Heading, IconButton, Metric, Stack, Text } from "@vibes.diy/ui";
560
+ import { readLook, watchLook } from "./look.js";
443
561
 
444
562
  const TUNE = {
445
563
  swipePx: 26, // travel from the anchor before a swipe fires (raise to 30–34 if a resting thumb misfires)
@@ -522,7 +640,8 @@ export default function App() {
522
640
  const root = rootRef.current;
523
641
  const canvas = canvasRef.current;
524
642
  const ctx = canvas.getContext("2d");
525
- const ink = getComputedStyle(root).color; // text-foreground, so the drawing follows the theme
643
+ let look = readLook(root); // the look paints the world, so the game wears the app's colours
644
+ const unwatch = watchLook(root, (next) => (look = next)); // a restyle repaints on the next frame
526
645
  const s = { lane: 1, x: 1, rocks: [], t: 0, spawn: 0, dead: false, trail: [] };
527
646
  let w = 0;
528
647
  let h = 0;
@@ -586,16 +705,17 @@ export default function App() {
586
705
  }
587
706
  setScore(Math.floor(s.t * 10));
588
707
  }
589
- ctx.clearRect(0, 0, w, h);
590
- ctx.strokeStyle = ink;
591
- ctx.fillStyle = ink;
592
- ctx.globalAlpha = 0.15;
708
+ ctx.fillStyle = look.backdrop;
709
+ ctx.fillRect(0, 0, w, h);
710
+ ctx.fillStyle = look.line;
593
711
  for (let i = 1; i < 3; i++) ctx.fillRect(laneW * i - 1, 0, 2, h);
594
- ctx.globalAlpha = 1;
712
+ ctx.fillStyle = look.accent;
595
713
  for (const r of s.rocks) ctx.fillRect(laneW * r.lane + laneW / 2 - 18, r.y - 18, 36, 36);
714
+ ctx.fillStyle = look.lead;
596
715
  ctx.beginPath();
597
716
  ctx.arc(laneW * s.x + laneW / 2, h * 0.78, 20, 0, Math.PI * 2);
598
717
  ctx.fill();
718
+ ctx.fillStyle = look.ink;
599
719
  s.trail = s.trail.filter((p) => now - p.t < TUNE.trailMs);
600
720
  s.trail.forEach((p, i) => {
601
721
  ctx.globalAlpha = 1 - (now - p.t) / TUNE.trailMs;
@@ -610,6 +730,7 @@ export default function App() {
610
730
 
611
731
  return () => {
612
732
  cancelAnimationFrame(raf);
733
+ unwatch();
613
734
  detach();
614
735
  window.removeEventListener("keydown", keys);
615
736
  window.removeEventListener("resize", resize);
@@ -624,10 +745,14 @@ export default function App() {
624
745
  >
625
746
  <canvas ref={canvasRef} className="absolute inset-0 block w-full h-full select-none touch-none" />
626
747
  <div className="absolute top-3 left-3 pointer-events-none">
627
- <p className="text-2xl font-bold">{score}</p>
628
- <p className="text-sm text-muted-foreground">
629
- {over ? "tap to run again" : "swipe ← → to switch lanes"}
630
- </p>
748
+ <Card>
749
+ <Stack gap={1}>
750
+ <Metric label="Score" value={String(score)} />
751
+ <Text size="sm" muted>
752
+ {over ? "tap to run again" : "swipe ← → to switch lanes"}
753
+ </Text>
754
+ </Stack>
755
+ </Card>
631
756
  </div>
632
757
  {/* One button holds everything that is not play; pointerdown stops here so a tap on it never steers. */}
633
758
  <div className="absolute top-3 right-3" onPointerDown={(e) => e.stopPropagation()}>
package/llms/voxel.md CHANGED
@@ -138,7 +138,10 @@ const BLOCK_TYPES = {
138
138
  Use the Blocktopia voxel palette in every voxel app. Keep the game-specific
139
139
  colors in one named table, shared by material swatches and HUD controls. Add
140
140
  game-specific materials to that table; preserve these colors for matching
141
- materials. The surrounding app retains its supplied theme's surfaces and text.
141
+ materials. The surrounding app retains its supplied theme's surfaces and text, and the world
142
+ around the blocks wears the look too: the sky, fog and light come from the theme tokens through
143
+ `readLook` (the `touch-games` skill, _The look reaches the play area_), and the title, hotbar and
144
+ panels are kit components on the look's surfaces. This table colours the blocks and the accent.
142
145
 
143
146
  ```js
144
147
  export const VOXEL_PALETTE = {
@@ -1032,7 +1035,7 @@ timestamp. For several worlds, scope these IDs and queries by world as well
1032
1035
  None of this needs persistence — keep it purely visual and client-side:
1033
1036
 
1034
1037
  - **Day/night cycle.** Advance a `dayTime` 0..1, drive the sun/moon position and
1035
- a blended sky/fog color, and fade light intensity. A full day every few
1038
+ a sky/fog color blended between two look colours (from `readLook`), and fade light intensity. A full day every few
1036
1039
  minutes feels right.
1037
1040
  - **Mobs.** Spawn a small capped population near the player: animals that wander
1038
1041
  by day, zombies that shuffle toward the player at night. Build each from a few
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibes.diy/prompts",
3
- "version": "14.3.234",
3
+ "version": "14.3.235",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "exports": {
@@ -39,10 +39,10 @@
39
39
  "license": "Apache-2.0",
40
40
  "dependencies": {
41
41
  "@adviser/cement": "~0.5.34",
42
- "@vibes.diy/api-types": "14.3.234",
43
- "@vibes.diy/call-ai-v2": "14.3.234",
44
- "@vibes.diy/identity": "14.3.234",
45
- "@vibes.diy/use-vibes-types": "14.3.234",
42
+ "@vibes.diy/api-types": "14.3.235",
43
+ "@vibes.diy/call-ai-v2": "14.3.235",
44
+ "@vibes.diy/identity": "14.3.235",
45
+ "@vibes.diy/use-vibes-types": "14.3.235",
46
46
  "arktype": "~2.2.8",
47
47
  "json-schema-faker": "~0.6.3"
48
48
  },