moi-computer 0.0.1

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.
Files changed (106) hide show
  1. package/LICENSE +95 -0
  2. package/README.md +71 -0
  3. package/bin/moi.mjs +25 -0
  4. package/bunfig.toml +3 -0
  5. package/client/CLAUDE.md +12 -0
  6. package/client/api/workspaces.ts +158 -0
  7. package/client/assets/claude.svg +3 -0
  8. package/client/assets/favicon.png +0 -0
  9. package/client/assets/hermes-nous.png +0 -0
  10. package/client/assets/mcp/.gitkeep +0 -0
  11. package/client/assets/mcp/atlassian.png +0 -0
  12. package/client/assets/mcp/discord.png +0 -0
  13. package/client/assets/mcp/figma.png +0 -0
  14. package/client/assets/mcp/github.png +0 -0
  15. package/client/assets/mcp/gitlab.png +0 -0
  16. package/client/assets/mcp/granola.png +0 -0
  17. package/client/assets/mcp/hubspot.png +0 -0
  18. package/client/assets/mcp/linear.png +0 -0
  19. package/client/assets/mcp/neon.png +0 -0
  20. package/client/assets/mcp/notion.png +0 -0
  21. package/client/assets/mcp/sentry.png +0 -0
  22. package/client/assets/mcp/slack.png +0 -0
  23. package/client/assets/mcp/stripe.png +0 -0
  24. package/client/assets/mcp/supabase.png +0 -0
  25. package/client/assets/mcp/vercel.png +0 -0
  26. package/client/assets/moi-logo.svg +11 -0
  27. package/client/assets/openclaw.svg +22 -0
  28. package/client/components/App.tsx +35 -0
  29. package/client/components/BottomPanel.tsx +33 -0
  30. package/client/components/ChatInput.tsx +62 -0
  31. package/client/components/ChatPanel.tsx +206 -0
  32. package/client/components/ChatPopup.tsx +60 -0
  33. package/client/components/CustomizePanel.tsx +117 -0
  34. package/client/components/HiddenPanel.tsx +79 -0
  35. package/client/components/HomePage.tsx +17 -0
  36. package/client/components/MarkdownContent.tsx +41 -0
  37. package/client/components/ThreadSelector.tsx +88 -0
  38. package/client/components/TurnView.tsx +618 -0
  39. package/client/components/WidgetErrorBoundary.tsx +46 -0
  40. package/client/components/WidgetFrame.tsx +66 -0
  41. package/client/components/WidgetGrid.tsx +113 -0
  42. package/client/components/WidgetShell.tsx +44 -0
  43. package/client/components/Widgets.tsx +132 -0
  44. package/client/components/WorkspacePreview.tsx +48 -0
  45. package/client/components/WorkspacesPage.tsx +237 -0
  46. package/client/components/layout/SidebarLayout.tsx +260 -0
  47. package/client/components/playground/LedLogo.tsx +181 -0
  48. package/client/components/playground/PixelPainter.tsx +105 -0
  49. package/client/components/playground/PlaygroundPage.tsx +71 -0
  50. package/client/components/routes/workspace/[id].tsx +282 -0
  51. package/client/components/ui/button.tsx +48 -0
  52. package/client/components/ui/dropdown-menu.tsx +257 -0
  53. package/client/components/ui/input.tsx +21 -0
  54. package/client/components/ui/popover.tsx +79 -0
  55. package/client/components/ui/textarea.tsx +18 -0
  56. package/client/externalize-react.ts +29 -0
  57. package/client/hooks/useChat.ts +88 -0
  58. package/client/hooks/useFitsSidebar.ts +34 -0
  59. package/client/hooks/useGridReconcile.ts +73 -0
  60. package/client/hooks/useMeiEvents.ts +66 -0
  61. package/client/hooks/useScrollFade.ts +38 -0
  62. package/client/hooks/useWidget.ts +72 -0
  63. package/client/hooks/useWidgetList.ts +30 -0
  64. package/client/hooks/useWorkspaceTheme.ts +76 -0
  65. package/client/index.css +182 -0
  66. package/client/index.html +43 -0
  67. package/client/index.tsx +19 -0
  68. package/client/lib/WorkspaceContext.tsx +24 -0
  69. package/client/lib/WorkspaceLayoutContext.tsx +92 -0
  70. package/client/lib/cn.ts +6 -0
  71. package/client/lib/grid-pack.ts +35 -0
  72. package/client/lib/group-turns.ts +44 -0
  73. package/client/lib/mcp-icons.ts +53 -0
  74. package/client/lib/ws.ts +129 -0
  75. package/client/main.tsx +23 -0
  76. package/client/store/chat.tsx +162 -0
  77. package/client/store/ui.ts +21 -0
  78. package/client/theme.css +66 -0
  79. package/lib/claude-adapter.ts +602 -0
  80. package/lib/format.ts +212 -0
  81. package/lib/themes.ts +89 -0
  82. package/lib/types.ts +144 -0
  83. package/package.json +117 -0
  84. package/server/CLAUDE.md +6 -0
  85. package/server/agent.ts +132 -0
  86. package/server/build-widget.ts +343 -0
  87. package/server/cli.ts +632 -0
  88. package/server/constants.ts +3 -0
  89. package/server/control.ts +98 -0
  90. package/server/functions-worker.ts +89 -0
  91. package/server/functions.ts +171 -0
  92. package/server/layout.ts +83 -0
  93. package/server/openclaw-adapter.ts +242 -0
  94. package/server/openclaw-gateway.ts +255 -0
  95. package/server/openclaw-session.ts +485 -0
  96. package/server/openclaw-strip.ts +134 -0
  97. package/server/openclaw.ts +206 -0
  98. package/server/registry.ts +150 -0
  99. package/server/skills-template.ts +21 -0
  100. package/server/state.ts +87 -0
  101. package/server/theme.ts +55 -0
  102. package/server/web.ts +321 -0
  103. package/server/widgets.ts +254 -0
  104. package/tsconfig.json +21 -0
  105. package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
  106. package/workspace/.claude/skills/widgets/SKILL.md +176 -0
@@ -0,0 +1,260 @@
1
+ import { type ReactNode, useEffect, useState } from 'react'
2
+
3
+ import { AnimatePresence, motion } from 'motion/react'
4
+
5
+ import {
6
+ IconHome,
7
+ IconLayoutSidebar,
8
+ IconLayoutSidebarLeftCollapse,
9
+ IconLayoutSidebarLeftExpand,
10
+ IconPlus,
11
+ IconSettings
12
+ } from '@tabler/icons-react'
13
+ import { Link } from 'wouter'
14
+
15
+ import { useWorkspaces } from '@/client/api/workspaces'
16
+ import claudeIcon from '@/client/assets/claude.svg'
17
+ import hermesIcon from '@/client/assets/hermes-nous.png'
18
+ import openclawIcon from '@/client/assets/openclaw.svg'
19
+ import { type Effect, LedLogo } from '@/client/components/playground/LedLogo'
20
+ import { cn } from '@/client/lib/cn'
21
+ import { useUiStore } from '@/client/store/ui'
22
+ import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
23
+
24
+ const PROVIDER_ICON: Record<WorkspaceType, string> = {
25
+ 'claude-code': claudeIcon,
26
+ openclaw: openclawIcon,
27
+ hermes: hermesIcon
28
+ }
29
+
30
+ // Display name: explicit name → OpenClaw agentId → path basename.
31
+ function workspaceLabel(ws: WorkspaceEntry): string {
32
+ if (ws.name) return ws.name
33
+ if (ws.type === 'openclaw') return ws.agentId ?? 'OpenClaw agent'
34
+ return ws.path.split('/').pop() || ws.path
35
+ }
36
+
37
+ const EXPANDED_WIDTH = 240
38
+ const COLLAPSED_WIDTH = 54
39
+
40
+ type SidebarLayoutProps = {
41
+ // Full panel content — the page supplies its own header (compose it with
42
+ // <PanelHeader> + <SidebarToggle>) and body.
43
+ children?: ReactNode
44
+ }
45
+
46
+ // App shell: a sidebar beside an elevated white content panel. Owns the
47
+ // collapse state (persisted `ui` store) and the sidebar; the page owns the
48
+ // panel's header and body.
49
+ export function SidebarLayout({ children }: SidebarLayoutProps) {
50
+ const collapsed = useUiStore(s => s.sidebarCollapsed)
51
+ // Loaded once at this stable boundary — this component does NOT remount on
52
+ // toggle (only the keyed <Sidebar> inside AnimatePresence does). The rows are
53
+ // passed down ready, so they don't re-subscribe/refetch or flicker on collapse.
54
+ const { data: workspaces } = useWorkspaces()
55
+
56
+ // Boot-up: on mount the logo runs the noise effect for 0.75s, then settles to
57
+ // the sprite. Kept here (not in the remounting Sidebar) so it fires once.
58
+ const [booting, setBooting] = useState(true)
59
+ useEffect(() => {
60
+ const id = setTimeout(() => setBooting(false), 750)
61
+ return () => clearTimeout(id)
62
+ }, [])
63
+
64
+ return (
65
+ <div className="flex h-dvh bg-[#f6f7f8]">
66
+ {/* Width animates; the Sidebar crossfades on collapse via AnimatePresence.
67
+ The two instances are absolutely positioned so they overlap. */}
68
+ <motion.div
69
+ className="relative shrink-0 overflow-hidden"
70
+ initial={false}
71
+ animate={{ width: collapsed ? COLLAPSED_WIDTH : EXPANDED_WIDTH }}
72
+ transition={{ type: 'spring', visualDuration: 0.2, bounce: 0 }}
73
+ >
74
+ <AnimatePresence initial={false}>
75
+ <motion.div
76
+ key={collapsed ? 'collapsed' : 'expanded'}
77
+ className="absolute inset-y-0 left-0"
78
+ // Per-version timing (each instance keeps its own props through exit):
79
+ // collapse: mini = instant, full = fade out (no delay)
80
+ // expand: full = fade in (no delay), mini = hold then fade out
81
+ // So one layer is always fully opaque over the shared icons → no dip.
82
+ initial={collapsed ? false : { opacity: 0 }}
83
+ animate={{ opacity: 1, transition: { duration: 0.15, ease: 'easeOut' } }}
84
+ exit={{
85
+ opacity: 0,
86
+ transition: collapsed
87
+ ? { delay: 0.15, duration: 0.2, ease: 'easeIn' }
88
+ : { duration: 0.2, ease: 'easeIn' }
89
+ }}
90
+ >
91
+ <Sidebar
92
+ collapsed={collapsed}
93
+ workspaces={workspaces ?? []}
94
+ logoEffect={booting ? 'chaos' : undefined}
95
+ />
96
+ </motion.div>
97
+ </AnimatePresence>
98
+ </motion.div>
99
+ <main className="bg-background flex min-w-0 flex-1 flex-col overflow-hidden rounded-l-md border-l border-gray-200 shadow-[1px_0px_3px_0px_rgba(0,0,0,0.1)]">
100
+ {children}
101
+ </main>
102
+ </div>
103
+ )
104
+ }
105
+
106
+ // Styling-only header bar. Pages compose their header inside it, typically
107
+ // starting with <SidebarToggle />.
108
+ type PanelHeaderProps = {
109
+ children?: ReactNode
110
+ }
111
+
112
+ export function PanelHeader({ children }: PanelHeaderProps) {
113
+ return (
114
+ <header className="border-border flex h-12 shrink-0 items-center gap-2.5 border-b px-3">
115
+ {children}
116
+ </header>
117
+ )
118
+ }
119
+
120
+ // The sidebar collapse/expand button — self-wired to the ui store. The one
121
+ // header piece shared across pages.
122
+ export function SidebarToggle() {
123
+ const collapsed = useUiStore(s => s.sidebarCollapsed)
124
+ const toggle = useUiStore(s => s.toggleSidebar)
125
+ const ToggleIcon = collapsed ? IconLayoutSidebarLeftExpand : IconLayoutSidebarLeftCollapse
126
+
127
+ return (
128
+ <button
129
+ type="button"
130
+ aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
131
+ title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
132
+ onClick={toggle}
133
+ className={cn(
134
+ 'text-muted-foreground hover:bg-muted hover:text-foreground flex size-7 items-center justify-center rounded-sm',
135
+ collapsed ? 'cursor-e-resize' : 'cursor-w-resize'
136
+ )}
137
+ >
138
+ <ToggleIcon size={20} strokeWidth={1.5} />
139
+ </button>
140
+ )
141
+ }
142
+
143
+ type SidebarProps = {
144
+ // Collapsed keeps the sidebar's width: content is hidden in place (logo +
145
+ // workspaces header stay invisible but occupy space) and rows drop their text.
146
+ collapsed?: boolean
147
+ workspaces: WorkspaceEntry[]
148
+ logoEffect?: Effect
149
+ }
150
+
151
+ function Sidebar({ collapsed, workspaces, logoEffect }: SidebarProps) {
152
+ return (
153
+ <aside className={cn('flex h-full shrink-0 flex-col px-2.5', collapsed ? 'w-[54px]' : 'w-60')}>
154
+ {/* Logo */}
155
+ <div className="mb-3.5 flex h-12 items-center px-2">
156
+ <LedLogo
157
+ pixelSize={3}
158
+ gap={0.5}
159
+ sprite={collapsed ? 'moi' : 'moi-full'}
160
+ effect={logoEffect}
161
+ />
162
+ </div>
163
+
164
+ {/* Home */}
165
+ <nav className="flex flex-col gap-0.5">
166
+ <NavRow
167
+ href="/"
168
+ icon={<IconHome size={18} className="text-foreground shrink-0" />}
169
+ label="Home"
170
+ collapsed={collapsed}
171
+ />
172
+ </nav>
173
+
174
+ {/* Workspaces */}
175
+ <div className="mt-5 flex flex-col gap-2">
176
+ <div className={cn('flex items-center justify-between pl-2', collapsed && 'invisible')}>
177
+ <span className="text-muted-foreground text-[13px] font-medium">Workspaces</span>
178
+ <Link
179
+ href="/"
180
+ aria-label="Add workspace"
181
+ className="border-border bg-background text-foreground/60 hover:bg-muted hover:text-foreground flex size-6 items-center justify-center rounded-[6px] border"
182
+ >
183
+ <IconPlus size={16} />
184
+ </Link>
185
+ </div>
186
+
187
+ <nav className="flex flex-col gap-0.5">
188
+ {workspaces.map(ws => (
189
+ <NavRow
190
+ key={ws.id}
191
+ href={`/workspace/${ws.id}`}
192
+ icon={
193
+ <img
194
+ src={PROVIDER_ICON[ws.type ?? 'claude-code']}
195
+ alt=""
196
+ className="size-[18px] shrink-0"
197
+ />
198
+ }
199
+ label={workspaceLabel(ws)}
200
+ collapsed={collapsed}
201
+ />
202
+ ))}
203
+ </nav>
204
+ </div>
205
+
206
+ <div className="flex-1" />
207
+
208
+ {/* Footer */}
209
+ <div className="flex items-center justify-between gap-2 py-3">
210
+ <button
211
+ type="button"
212
+ className={cn(
213
+ 'hover:bg-foreground/[0.05] hover:text-foreground text-foreground flex h-8 items-center gap-2 rounded-sm pl-1.5 text-sm',
214
+ collapsed ? 'pr-1.5' : 'pr-2.5'
215
+ )}
216
+ >
217
+ <IconSettings size={18} className="shrink-0" />
218
+ {!collapsed && <span>Settings</span>}
219
+ </button>
220
+ {/* Temporarily hidden */}
221
+ <button
222
+ type="button"
223
+ aria-label="Toggle sidebar"
224
+ className="text-foreground/45 hover:bg-foreground/[0.06] hover:text-foreground/80 hidden size-7 items-center justify-center rounded-[6px]"
225
+ >
226
+ <IconLayoutSidebar size={16} />
227
+ </button>
228
+ </div>
229
+ </aside>
230
+ )
231
+ }
232
+
233
+ type NavRowProps = {
234
+ href: string
235
+ icon: ReactNode
236
+ label: string
237
+ collapsed?: boolean
238
+ }
239
+
240
+ function NavRow({ href, icon, label, collapsed }: NavRowProps) {
241
+ // wouter resolves `active` by matching `href` against the current location
242
+ // (exact match — a workspace row lights up only on its own route).
243
+ return (
244
+ <Link
245
+ href={href}
246
+ aria-label={label}
247
+ className={active =>
248
+ cn(
249
+ 'flex h-8 items-center gap-2.5 rounded-sm px-2 text-sm font-medium',
250
+ active
251
+ ? 'bg-foreground/[0.07] text-foreground'
252
+ : 'text-foreground/65 hover:bg-foreground/[0.04] hover:text-foreground'
253
+ )
254
+ }
255
+ >
256
+ {icon}
257
+ {!collapsed && <span className="truncate">{label}</span>}
258
+ </Link>
259
+ )
260
+ }
@@ -0,0 +1,181 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+
5
+ // A sprite is a glyph (and sets the grid dimensions). An effect is an optional
6
+ // animation rendered at the sprite's dimensions.
7
+ export type Sprite = 'moi' | 'moi-full'
8
+ export type Effect = 'wave' | 'chaos'
9
+
10
+ const parse = (rows: string[]): number[][] =>
11
+ rows.map(row => [...row].map(ch => (ch === '#' ? 1 : 0)))
12
+
13
+ // "moi" glyphs — 5×5 each, hand-painted in the playground.
14
+ const M_ROWS = ['####.', '#.#.#', '#.#.#', '#.#.#', '#.#.#']
15
+ const PART2_ROWS = ['###.#', '#.#.#', '#.#.#', '#.#.#', '###.#']
16
+
17
+ // Small standalone M (sits a row lower).
18
+ const M = parse(['.....', '####.', '#.#.#', '#.#.#', '#.#.#'])
19
+ // Full mark: M + a 1-column gap + the second glyph.
20
+ const MOI_FULL = parse(M_ROWS.map((row, i) => `${row}.${PART2_ROWS[i]}`))
21
+
22
+ const SPRITES: Record<Sprite, number[][]> = {
23
+ moi: M,
24
+ 'moi-full': MOI_FULL
25
+ }
26
+
27
+ // ---- frame generators (sized to the sprite's W×H) --------------------------
28
+
29
+ function makeGrid(w: number, h: number, fn: (c: number, r: number) => number): number[][] {
30
+ const grid: number[][] = []
31
+ for (let r = 0; r < h; r++) {
32
+ const row: number[] = []
33
+ for (let c = 0; c < w; c++) row.push(fn(c, r))
34
+ grid.push(row)
35
+ }
36
+ return grid
37
+ }
38
+
39
+ // Deterministic per-cell pseudo-random in [0,1) — lets effects run at any
40
+ // sprite dimension without a fixed-size parameter table.
41
+ function hash(c: number, r: number, seed: number): number {
42
+ const x = Math.sin(c * 12.9898 + r * 78.233 + seed * 37.719) * 43758.5453
43
+ return x - Math.floor(x)
44
+ }
45
+
46
+ // Smooth twinkle: each pixel breathes on its own slow cycle (fairy lights),
47
+ // squared so peaks pop bright while most sit dim.
48
+ function chaosFrame(t: number, w: number, h: number): number[][] {
49
+ return makeGrid(w, h, (c, r) => {
50
+ const phase = hash(c, r, 0) * Math.PI * 2
51
+ const speed = 5 + hash(c, r, 1) * 6
52
+ const v = 0.5 + 0.5 * Math.sin(t * speed + phase)
53
+ return v * v
54
+ })
55
+ }
56
+
57
+ // Smooth diagonal travelling wave.
58
+ function waveFrame(t: number, w: number, h: number): number[][] {
59
+ const speed = 6.5
60
+ return makeGrid(w, h, (c, r) => 0.5 + 0.5 * Math.sin(c * 0.5 + r * 0.32 - t * speed))
61
+ }
62
+
63
+ // A sprite sliding up from below into place, then static.
64
+ const SLIDE_SECONDS = 0.55
65
+ function spriteSlide(pattern: number[][], t: number): number[][] {
66
+ const h = pattern.length
67
+ const w = pattern.reduce((m, row) => Math.max(m, row.length), 0)
68
+ const p = Math.min(t / SLIDE_SECONDS, 1)
69
+ const eased = 1 - Math.pow(1 - p, 3) // easeOutCubic
70
+ const drop = Math.round((1 - eased) * h) // h → 0
71
+ const out: number[][] = []
72
+ for (let r = 0; r < h; r++) {
73
+ const row: number[] = []
74
+ for (let c = 0; c < w; c++) row.push(pattern[r - drop]?.[c] ?? 0)
75
+ out.push(row)
76
+ }
77
+ return out
78
+ }
79
+
80
+ function frameFor(sprite: Sprite, effect: Effect | undefined, t: number): number[][] {
81
+ const base = SPRITES[sprite]
82
+ if (effect === undefined) return spriteSlide(base, t)
83
+ const h = base.length
84
+ const w = base[0]?.length ?? 0
85
+ return effect === 'wave' ? waveFrame(t, w, h) : chaosFrame(t, w, h)
86
+ }
87
+
88
+ // Default target frame rate; overridable via the `fps` prop.
89
+ const DEFAULT_FPS = 24
90
+
91
+ // ---- animation hook: owns the rAF lifecycle --------------------------------
92
+
93
+ function useLedFrames(sprite: Sprite, effect: Effect | undefined, fps: number): number[][] {
94
+ const [grid, setGrid] = useState<number[][]>(() => frameFor(sprite, effect, 0))
95
+
96
+ useEffect(() => {
97
+ let raf = 0
98
+ let start: number | null = null
99
+ let last = 0
100
+ const interval = 1000 / fps
101
+
102
+ const loop = (now: number) => {
103
+ if (start === null) start = now
104
+ const t = (now - start) / 1000
105
+ if (now - last >= interval) {
106
+ last = now
107
+ setGrid(frameFor(sprite, effect, t))
108
+ // A static sprite (no effect) stops once it has slid into place.
109
+ if (effect === undefined && t >= SLIDE_SECONDS) return
110
+ }
111
+ raf = requestAnimationFrame(loop)
112
+ }
113
+
114
+ raf = requestAnimationFrame(loop)
115
+ return () => cancelAnimationFrame(raf)
116
+ }, [sprite, effect, fps])
117
+
118
+ return grid
119
+ }
120
+
121
+ // Brightness [0,1] → ink color. Continuous so waves read as gradients while
122
+ // the off baseline keeps the matrix faintly visible.
123
+ function pixelColor(v: number): string {
124
+ const a = 0.1 + Math.max(0, Math.min(1, v)) * 0.9
125
+ return `rgba(23, 23, 23, ${a.toFixed(3)})`
126
+ }
127
+
128
+ type LedLogoProps = {
129
+ /** Which glyph to show; also sets the grid dimensions. Default 'moi'. */
130
+ sprite?: Sprite
131
+ /** Optional animation, sized to the sprite. Omit for the static sprite. */
132
+ effect?: Effect
133
+ /** Target frames per second. Default 24. */
134
+ fps?: number
135
+ /** Square pixel edge in px. Default 3. */
136
+ pixelSize?: number
137
+ /** Spacing between pixels in px. Default 1. */
138
+ gap?: number
139
+ className?: string
140
+ }
141
+
142
+ export function LedLogo({
143
+ sprite = 'moi',
144
+ effect,
145
+ fps = DEFAULT_FPS,
146
+ pixelSize = 3,
147
+ gap = 1,
148
+ className
149
+ }: LedLogoProps) {
150
+ const grid = useLedFrames(sprite, effect, fps)
151
+ const cols = grid[0]?.length ?? 0
152
+ // Effects glow; the static sprite stays crisp.
153
+ const bloom = effect !== undefined
154
+ return (
155
+ <div
156
+ className={cn('grid', className)}
157
+ style={{
158
+ gridTemplateColumns: `repeat(${cols}, ${pixelSize}px)`,
159
+ gap: `${gap}px`
160
+ }}
161
+ >
162
+ {grid.flatMap((row, r) =>
163
+ row.map((v, c) => (
164
+ <div
165
+ key={`${r}-${c}`}
166
+ className="rounded-[2px]"
167
+ style={{
168
+ width: pixelSize,
169
+ height: pixelSize,
170
+ background: pixelColor(v),
171
+ // Soft bloom that grows with brightness — bright pixels glow.
172
+ boxShadow: bloom
173
+ ? `0 0 ${(pixelSize * (0.4 + v)).toFixed(1)}px rgba(23, 23, 23, ${(v * 0.35).toFixed(3)})`
174
+ : undefined
175
+ }}
176
+ />
177
+ ))
178
+ )}
179
+ </div>
180
+ )
181
+ }
@@ -0,0 +1,105 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+
5
+ const COLS = 5
6
+ const ROWS = 5
7
+
8
+ // Seed with the current M.
9
+ const SEED = ['.....', '####.', '#.#.#', '#.#.#', '#.#.#']
10
+
11
+ function fromRows(rows: string[]): boolean[][] {
12
+ return rows.map(row => [...row].map(ch => ch === '#'))
13
+ }
14
+
15
+ function emptyGrid(): boolean[][] {
16
+ return Array.from({ length: ROWS }, () => Array.from({ length: COLS }, () => false))
17
+ }
18
+
19
+ // Simple 9×6 pixel painter: click or drag to toggle cells, then copy the
20
+ // `#`/`.` rows. Used to author the LED glyph by hand.
21
+ export function PixelPainter() {
22
+ const [grid, setGrid] = useState<boolean[][]>(() => fromRows(SEED))
23
+ const [painting, setPainting] = useState(false)
24
+ const paintValue = useRef(true)
25
+ const [copied, setCopied] = useState(false)
26
+
27
+ useEffect(() => {
28
+ const stop = () => setPainting(false)
29
+ window.addEventListener('mouseup', stop)
30
+ return () => window.removeEventListener('mouseup', stop)
31
+ }, [])
32
+
33
+ function setCell(r: number, c: number, value: boolean) {
34
+ setGrid(g => {
35
+ if (g[r][c] === value) return g
36
+ const next = g.map(row => row.slice())
37
+ next[r][c] = value
38
+ return next
39
+ })
40
+ }
41
+
42
+ function handleDown(r: number, c: number) {
43
+ const value = !grid[r][c]
44
+ paintValue.current = value
45
+ setPainting(true)
46
+ setCell(r, c, value)
47
+ }
48
+
49
+ function handleEnter(r: number, c: number) {
50
+ if (painting) setCell(r, c, paintValue.current)
51
+ }
52
+
53
+ const ascii = grid.map(row => row.map(on => (on ? '#' : '.')).join('')).join('\n')
54
+
55
+ async function copy() {
56
+ await navigator.clipboard.writeText(ascii)
57
+ setCopied(true)
58
+ setTimeout(() => setCopied(false), 1200)
59
+ }
60
+
61
+ return (
62
+ <div className="flex flex-col items-center gap-4">
63
+ <div className="grid w-fit select-none grid-cols-[repeat(5,28px)] gap-px bg-black/15 p-px">
64
+ {grid.map((row, r) =>
65
+ row.map((on, c) => (
66
+ <div
67
+ key={`${r}-${c}`}
68
+ onMouseDown={() => handleDown(r, c)}
69
+ onMouseEnter={() => handleEnter(r, c)}
70
+ className={cn('size-7 cursor-pointer', on ? 'bg-neutral-900' : 'bg-white')}
71
+ />
72
+ ))
73
+ )}
74
+ </div>
75
+
76
+ <pre className="border-border rounded-md border bg-white px-3 py-2 text-center font-mono text-sm leading-snug text-neutral-900">
77
+ {ascii}
78
+ </pre>
79
+
80
+ <div className="flex gap-2">
81
+ <button
82
+ type="button"
83
+ onClick={copy}
84
+ className="rounded-md bg-neutral-900 px-3 py-1 text-xs font-medium text-white"
85
+ >
86
+ {copied ? 'Copied!' : 'Copy'}
87
+ </button>
88
+ <button
89
+ type="button"
90
+ onClick={() => setGrid(emptyGrid())}
91
+ className="rounded-md bg-black/[0.06] px-3 py-1 text-xs font-medium text-black/60 hover:text-black/80"
92
+ >
93
+ Clear
94
+ </button>
95
+ <button
96
+ type="button"
97
+ onClick={() => setGrid(fromRows(SEED))}
98
+ className="rounded-md bg-black/[0.06] px-3 py-1 text-xs font-medium text-black/60 hover:text-black/80"
99
+ >
100
+ Reset
101
+ </button>
102
+ </div>
103
+ </div>
104
+ )
105
+ }
@@ -0,0 +1,71 @@
1
+ import { useState } from 'react'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+
5
+ import { type Effect, LedLogo, type Sprite } from './LedLogo'
6
+ import { PixelPainter } from './PixelPainter'
7
+
8
+ const SPRITES: { value: Sprite; label: string }[] = [
9
+ { value: 'moi', label: 'M' },
10
+ { value: 'moi-full', label: 'MOI' }
11
+ ]
12
+
13
+ const EFFECTS: { value: Effect | 'none'; label: string }[] = [
14
+ { value: 'none', label: 'None' },
15
+ { value: 'wave', label: 'Wave' },
16
+ { value: 'chaos', label: 'Random' }
17
+ ]
18
+
19
+ type SegmentedProps<T extends string | number> = {
20
+ options: { value: T; label: string }[]
21
+ value: T
22
+ onChange: (value: T) => void
23
+ }
24
+
25
+ function Segmented<T extends string | number>({ options, value, onChange }: SegmentedProps<T>) {
26
+ return (
27
+ <div className="flex gap-1 rounded-lg bg-black/[0.04] p-1">
28
+ {options.map(o => (
29
+ <button
30
+ key={String(o.value)}
31
+ type="button"
32
+ onClick={() => onChange(o.value)}
33
+ className={cn(
34
+ 'rounded-md px-3 py-1 text-xs transition-colors',
35
+ value === o.value ? 'bg-neutral-900 text-white' : 'text-black/50 hover:text-black/80'
36
+ )}
37
+ >
38
+ {o.label}
39
+ </button>
40
+ ))}
41
+ </div>
42
+ )
43
+ }
44
+
45
+ // Scratch route for UI experiments. Add new experiments here over time.
46
+ export function PlaygroundPage() {
47
+ const [sprite, setSprite] = useState<Sprite>('moi')
48
+ const [effect, setEffect] = useState<Effect | 'none'>('none')
49
+
50
+ return (
51
+ <div className="relative flex min-h-dvh flex-col items-center justify-center gap-8 bg-[#f2f1ee]">
52
+ <span className="absolute left-5 top-5 text-[11px] font-medium uppercase tracking-widest text-black/30">
53
+ Playground
54
+ </span>
55
+
56
+ <PixelPainter />
57
+
58
+ <LedLogo
59
+ sprite={sprite}
60
+ effect={effect === 'none' ? undefined : effect}
61
+ pixelSize={3}
62
+ gap={0.5}
63
+ />
64
+
65
+ <div className="flex flex-col items-center gap-2">
66
+ <Segmented options={SPRITES} value={sprite} onChange={setSprite} />
67
+ <Segmented options={EFFECTS} value={effect} onChange={setEffect} />
68
+ </div>
69
+ </div>
70
+ )
71
+ }