Prompt specification
Build or customize the Three.js 3D scene "Community Skill Exchange Board" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Community Skill Exchange Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-skill-exchange-board-x3255
Scene Description Prompt:
Create one HTML file using Three.js from cdnjs: a voxel neighborhood board tracking fictional repair, cooking, and tutoring exchanges and outstanding commitments.
Working Three.js Starter (community-skill-exchange-board-x3255):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#173f38">
<title>Common Ground — Voxel Neighborhood Board</title>
<style>
:root {
--ink: #20352f;
--muted: #71827c;
--paper: #fffdf8;
--paper-2: #f3f1e9;
--line: #dde2da;
--forest: #173f38;
--repair: #5377d9;
--cooking: #e98546;
--tutoring: #36a273;
--danger: #c75c56;
--shadow: 0 16px 45px rgba(37, 61, 52, 0.12);
--radius: 18px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: #e9eee8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input,
select,
textarea {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(83, 119, 217, 0.35);
outline-offset: 2px;
}
.app {
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
height: 100vh;
}
.topbar {
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
background: var(--paper);
border-bottom: 1px solid var(--line);
box-shadow: 0 4px 18px rgba(31, 54, 46, 0.05);
}
.brand {
display: flex;
align-items: center;
min-width: 250px;
}
.brand-mark {
position: relative;
display: grid;
place-items: center;
width: 42px;
height: 42px;
margin-right: 12px;
border-radius: 13px;
background: var(--forest);
box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: #f7f0d7;
}
.brand-mark::before {
width: 18px;
height: 18px;
transform: rotate(45deg);
border-radius: 3px;
}
.brand-mark::after {
width: 8px;
height: 8px;
background: #f0a34a;
border-radius: 2px;
transform: translate(4px, -5px);
}
.brand h1 {
margin: 0;
font-size: 18px;
letter-spacing: -0.03em;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.top-stats {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
flex: 1;
}
.stat {
min-width: 108px;
padding: 8px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: #fbfaf5;
}
.stat strong,
.stat span {
display: block;
}
.stat strong {
font-size: 17px;
line-height: 1.1;
}
.stat span {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 8px;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 39px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--paper);
cursor: pointer;
font-size: 13px;
font-weight: 750;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
.button:hover {
transform: translateY(-1px);
border-color: #b9c5bb;
background: #fff;
}
.button.primary {
color: #fff;
border-color: var(--forest);
background: var(--forest);
box-shadow: 0 7px 18px rgba(23, 63, 56, 0.17);
}
.button.primary:hover {
background: #22574d;
}
.button.icon {
width: 39px;
padding: 0;
}
.workspace {
display: grid;
grid-template-columns: 318px minmax(420px, 1fr) 338px;
min-height: 0;
}
.panel {
z-index: 4;
min-height: 0;
background: var(--paper);
}
.sidebar {
display: flex;
flex-direction: column;
border-right: 1px solid var(--line);
}
.details {
overflow-y: auto;
border-left: 1px solid var(--line);
}
.panel-header {
padding: 20px 20px 14px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 6px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.panel-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.panel-title-row h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.035em;
}
.small-count {
min-width: 29px;
height: 29px;
display: grid;
place-items: center;
padding: 0 8px;
border-radius: 10px;
color: var(--muted);
background: var(--paper-2);
font-size: 12px;
font-weight: 800;
}
.tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
margin-top: 16px;
padding: 4px;
border-radius: 12px;
background: var(--paper-2);
}
.tab {
min-height: 34px;
border: 0;
border-radius: 9px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 800;
}
.tab.active {
color: var(--ink);
background: var(--paper);
box-shadow: 0 3px 10px rgba(40, 65, 56, 0.08);
}
.filter-area {
padding: 14px 16px 12px;
border-bottom: 1px solid var(--line);
}
.search-box {
position: relative;
}
.search-box::before {
content: "";
position: absolute;
left: 13px;
top: 50%;
width: 12px;
height: 12px;
border: 2px solid #82918b;
border-radius: 50%;
transform: translateY(-58%);
pointer-events: none;
}
.search-box::after {
content: "";
position: absolute;
left: 24px;
top: 66%;
width: 6px;
height: 2px;
border-radius: 2px;
background: #82918b;
transform: rotate(45deg);
pointer-events: none;
}
.search-box input {
width: 100%;
height: 40px;
padding: 0 12px 0 36px;
border: 1px solid var(--line);
border-radius: 11px;
outline: 0;
background: #faf9f4;
color: var(--ink);
font-size: 13px;
}
.search-box input:focus {
border-color: #9baa9f;
background: #fff;
}
.filters {
display: flex;
gap: 6px;
margin-top: 10px;
overflow-x: auto;
scrollbar-width: none;
}
.filters::-webkit-scrollbar {
display: none;
}
.filter {
flex: 0 0 auto;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 800;
}
.filter.active {
color: #fff;
border-color: var(--forest);
background: var(--forest);
}
.filter[data-filter="repair"].active {
background: var(--repair);
border-color: var(--repair);
}
.filter[data-filter="cooking"].active {
background: var(--cooking);
border-color: var(--cooking);
}
.filter[data-filter="tutoring"].active {
background: var(--tutoring);
border-color: var(--tutoring);
}
.records {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 14px;
}
.record-card {
position: relative;
margin-bottom: 10px;
padding: 14px 14px 13px 17px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 14px;
background: #fffefa;
cursor: pointer;
transition:
border-color 140ms ease,
transform 140ms ease,
box-shadow 140ms ease;
}
.record-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--category, #8a9a92);
}
.record-card:hover {
transform: translateY(-1px);
border-color: #bdc9c0;
box-shadow: 0 8px 20px rgba(40, 65, 56, 0.07);
}
.record-card.selected {
border-color: var(--category, var(--forest));
box-shadow: 0 0 0 2px color-mix(in srgb, var(--category, var(--forest)) 15%, transparent);
}
.record-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.category-label {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--category, var(--muted));
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.category-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: currentColor;
}
.status {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 4px 7px;
border-radius: 999px;
color: #6e7d76;
background: #eff1ec;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.status::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: currentColor;
}
.status.scheduled {
color: #4b68b5;
background: #e9eefb;
}
.status.open {
color: #a86627;
background: #fff0df;
}
.status.completed,
.status.done {
color: #348160;
background: #e4f3eb;
}
.record-card h3 {
margin: 0 0 8px;
font-size: 14px;
line-height: 1.35;
letter-spacing: -0.015em;
}
.people-line {
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.people-line strong {
color: #52645d;
font-weight: 750;
}
.record-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid #edf0e9;
color: var(--muted);
font-size: 10px;
}
.record-meta span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.commitment-check {
display: inline-grid;
place-items: center;
width: 21px;
height: 21px;
flex: 0 0 auto;
margin-right: 8px;
border: 1.5px solid #b9c4bd;
border-radius: 7px;
color: #fff;
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 900;
vertical-align: middle;
}
.commitment-check.done {
border-color: var(--tutoring);
background: var(--tutoring);
}
.empty-state {
display: grid;
place-items: center;
min-height: 220px;
padding: 28px;
color: var(--muted);
text-align: center;
font-size: 13px;
line-height: 1.6;
}
.empty-state strong {
display: block;
margin-bottom: 4px;
color: var(--ink);
font-size: 15px;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e7ede7;
}
#canvasWrap {
position: absolute;
inset: 0;
}
#canvasWrap canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#canvasWrap canvas.dragging {
cursor: grabbing;
}
.scene-heading {
position: absolute;
z-index: 2;
top: 22px;
left: 24px;
pointer-events: none;
}
.scene-heading .eyebrow {
margin-bottom: 5px;
}
.scene-heading h2 {
margin: 0;
font-size: clamp(21px, 2.2vw, 31px);
letter-spacing: -0.055em;
}
.scene-heading p {
margin: 7px 0 0;
color: #64766e;
font-size: 12px;
}
.scene-badge {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 12px;
padding: 6px 9px;
border: 1px solid rgba(56, 88, 76, 0.16);
border-radius: 999px;
color: #49635a;
background: rgba(255, 253, 248, 0.72);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.scene-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: #e1a34e;
box-shadow: 0 0 0 3px rgba(225, 163, 78, 0.17);
}
.scene-controls {
position: absolute;
z-index: 3;
right: 18px;
bottom: 18px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(92, 112, 102, 0.18);
border-radius: 14px;
background: rgba(255, 253, 248, 0.88);
box-shadow: 0 10px 30px rgba(41, 66, 57, 0.12);
backdrop-filter: blur(12px);
}
.scene-controls button {
width: 35px;
height: 35px;
border: 0;
border-radius: 9px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 17px;
font-weight: 800;
}
.scene-controls button:hover {
background: #e9eee7;
}
.scene-legend {
position: absolute;
z-index: 2;
left: 24px;
bottom: 18px;
display: flex;
gap: 7px;
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 7px 9px;
border: 1px solid rgba(92, 112, 102, 0.15);
border-radius: 9px;
color: #5d7068;
background: rgba(255, 253, 248, 0.8);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.legend-item i {
width: 7px;
height: 7px;
border-radius: 2px;
}
.scene-help {
position: absolute;
z-index: 2;
right: 18px;
top: 18px;
padding: 8px 10px;
border: 1px solid rgba(92, 112, 102, 0.14);
border-radius: 10px;
color: #71817b;
background: rgba(255, 253, 248, 0.72);
backdrop-filter: blur(8px);
font-size: 10px;
pointer-events: none;
}
.scene-tooltip {
position: absolute;
z-index: 8;
max-width: 220px;
padding: 9px 11px;
border-radius: 9px;
color: #fff;
background: rgba(24, 48, 41, 0.93);
box-shadow: 0 9px 25px rgba(22, 45, 38, 0.2);
font-size: 11px;
line-height: 1.4;
pointer-events: none;
transform: translate(12px, 12px);
}
.scene-tooltip[hidden] {
display: none;
}
.details-inner {
padding: 20px;
}
.details-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.detail-icon {
display: grid;
place-items: center;
width: 44px;
height: 44px;
flex: 0 0 auto;
border-radius: 13px;
color: #fff;
background: var(--category, var(--forest));
box-shadow: 0 8px 18px color-mix(in srgb, var(--category, var(--forest)) 24%, transparent);
font-size: 20px;
}
.detail-title h2 {
margin: 0 0 7px;
font-size: 20px;
line-height: 1.25;
letter-spacing: -0.035em;
}
.detail-title .category-label {
font-size: 9px;
}
.detail-section {
padding: 17px 0;
border-top: 1px solid var(--line);
}
.detail-section:first-of-type {
border-top: 0;
padding-top: 0;
}
.detail-section h3 {
margin: 0 0 11px;
color: #75847e;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.exchange-route {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 8px;
}
.route-person {
min-width: 0;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: #faf9f4;
}
.route-person span,
.route-person strong {
display: block;
}
.route-person span {
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
}
.route-person strong {
overflow: hidden;
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
.route-arrow {
color: #9ba8a2;
font-size: 18px;
}
.info-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.info-cell {
min-width: 0;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: #faf9f4;
}
.info-cell span,
.info-cell strong {
display: block;
}
.info-cell span {
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
}
.info-cell strong {
overflow: hidden;
font-size: 11px;
line-height: 1.4;
text-overflow: ellipsis;
}
.commitment-item {
display: flex;
align-items: flex-start;
gap: 9px;
padding: 10px 0;
border-bottom: 1px solid #edf0e9;
}
.commitment-item:last-child {
border-bottom: 0;
}
.commitment-copy {
flex: 1;
min-width: 0;
}
.commitment-copy strong {
display: block;
margin-bottom: 4px;
font-size: 11px;
line-height: 1.4;
}
.commitment-copy span {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.commitment-item.done .commitment-copy strong {
color: #829089;
text-decoration: line-through;
}
.detail-actions {
display: flex;
gap: 8px;
margin-top: 13px;
}
.detail-actions .button {
flex: 1;
}
.note-area {
width: 100%;
min-height: 75px;
resize: vertical;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
outline: 0;
color: var(--ink);
background: #faf9f4;
font-size: 11px;
line-height: 1.5;
}
.note-area:focus {
border-color: #9baa9f;
background: #fff;
}
.note-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 8px;
}
.note-row span {
color: var(--muted);
font-size: 9px;
}
.progress-track {
height: 7px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: #e9ede7;
}
.progress-fill {
height: 100%;
border-radius: inherit;
background: var(--category, var(--tutoring));
transition: width 260ms ease;
}
.progress-caption {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
}
dialog {
width: min(520px, calc(100vw - 32px));
padding: 0;
overflow: hidden;
border: 0;
border-radius: 20px;
color: var(--ink);
background: var(--paper);
box-shadow: 0 28px 90px rgba(17, 44, 35, 0.28);
}
dialog::backdrop {
background: rgba(21, 45, 37, 0.48);
backdrop-filter: blur(5px);
}
.dialog-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 22px 16px;
border-bottom: 1px solid var(--line);
}
.dialog-header h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.035em;
}
.dialog-close {
width: 33px;
height: 33px;
border: 0;
border-radius: 9px;
background: var(--paper-2);
cursor: pointer;
font-size: 19px;
}
.dialog-body {
display: grid;
gap: 14px;
padding: 20px 22px;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.field {
display: grid;
gap: 6px;
}
.field label {
color: #65766f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.field input,
.field select,
.field textarea {
width: 100%;
min-height: 42px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 11px;
outline: 0;
color: var(--ink);
background: #faf9f4;
font-size: 13px;
}
.field textarea {
min-height: 78px;
resize: vertical;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
border-color: #91a499;
background: #fff;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 8px;
padding: 16px 22px 20px;
border-top: 1px solid var(--line);
}
.toast {
position: fixed;
z-index: 50;
left: 50%;
bottom: 28px;
min-width: 230px;
padding: 12px 16px;
border-radius: 11px;
color: #fff;
background: rgba(23, 63, 56, 0.95);
box-shadow: 0 14px 35px rgba(18, 45, 36, 0.25);
font-size: 12px;
font-weight: 700;
text-align: center;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 15px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 999px;
background: #cbd3cc;
background-clip: padding-box;
}
@media (max-width: 1180px) {
.workspace {
grid-template-columns: 280px minmax(380px, 1fr) 300px;
}
.top-stats .stat {
min-width: 88px;
padding-inline: 10px;
}
.brand {
min-width: 210px;
}
.reset-label {
display: none;
}
}
@media (max-width: 930px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
grid-template-rows: auto 1fr;
}
.topbar {
flex-wrap: wrap;
gap: 12px;
padding: 14px 16px;
}
.top-stats {
order: 3;
width: 100%;
justify-content: stretch;
}
.top-stats .stat {
flex: 1;
}
.top-actions {
margin-left: auto;
}
.workspace {
grid-template-columns: 1fr;
}
.viewport {
grid-row: 1;
height: 62vh;
min-height: 470px;
}
.sidebar {
grid-row: 2;
max-height: 620px;
border-right: 0;
border-top: 1px solid var(--line);
}
.details {
grid-row: 3;
border-top: 1px solid var(--line);
border-left: 0;
}
.records {
max-height: 470px;
}
}
@media (max-width: 540px) {
.brand p,
.scene-help,
.scene-legend {
display: none;
}
.brand {
min-width: 0;
}
.brand h1 {
font-size: 16px;
}
.topbar {
align-items: center;
}
.top-actions .button.primary {
padding-inline: 10px;
}
.top-actions .button.primary span {
display: none;
}
.scene-heading {
top: 18px;
left: 18px;
}
.scene-controls {
right: 12px;
bottom: 12px;
}
.form-row,
.info-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Common Ground</h1>
<p>Block 08 neighborhood board</p>
</div>
</div>
<div class="top-stats" aria-label="Neighborhood summary">
<div class="stat">
<strong id="activeExchanges">0</strong>
<span>Active exchanges</span>
</div>
<div class="stat">
<strong id="openCommitments">0</strong>
<span>Open promises</span>
</div>
<div class="stat">
<strong id="completionRate">0%</strong>
<span>Completed</span>
</div>
</div>
<div class="top-actions">
<button class="button" id="resetDemo" title="Restore the original fictional records">
<span aria-hidden="true">↻</span>
<span class="reset-label">Reset demo</span>
</button>
<button class="button primary" id="openExchangeDialog">
<span aria-hidden="true">+</span>
<span>Add exchange</span>
</button>
</div>
</header>
<main class="workspace">
<aside class="panel sidebar">
<div class="panel-header">
<p class="eyebrow">Neighborhood ledger</p>
<div class="panel-title-row">
<h2>Exchange board</h2>
<span class="small-count" id="recordCount">0</span>
</div>
<div class="tabs" role="tablist" aria-label="Record type">
<button class="tab active" id="exchangesTab" data-view="exchanges" role="tab">
Exchanges
</button>
<button class="tab" id="commitmentsTab" data-view="commitments" role="tab">
Commitments
</button>
</div>
</div>
<div class="filter-area">
<div class="search-box">
<input
id="searchInput"
type="search"
placeholder="Search neighbors or requests"
aria-label="Search exchanges and commitments"
>
</div>
<div class="filters" aria-label="Category filters">
<button class="filter active" data-filter="all">All</button>
<button class="filter" data-filter="repair">Repair</button>
<button class="filter" data-filter="cooking">Cooking</button>
<button class="filter" data-filter="tutoring">Tutoring</button>
</div>
</div>
<div class="records" id="records" aria-live="polite"></div>
</aside>
<section class="viewport" id="viewport" aria-label="Interactive voxel neighborhood">
<div id="canvasWrap"></div>
<div class="scene-heading">
<p class="eyebrow">A small place for useful favors</p>
<h2>Maple & Ninth</h2>
<p>Drag to orbit · Scroll to zoom · Select a card or building</p>
<span class="scene-badge">Entirely fictional neighborhood</span>
</div>
<div class="scene-help">Hold Shift + drag to pan</div>
<div class="scene-legend">
<span class="legend-item">
<i style="background: var(--repair)"></i> Repair
</span>
<span class="legend-item">
<i style="background: var(--cooking)"></i> Cooking
</span>
<span class="legend-item">
<i style="background: var(--tutoring)"></i> Tutoring
</span>
</div>
<div class="scene-controls" aria-label="Camera controls">
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="resetCamera" title="Reset camera" aria-label="Reset camera">⌂</button>
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
</div>
<div class="scene-tooltip" id="sceneTooltip" hidden></div>
</section>
<aside class="panel details" id="detailsPanel">
<div class="details-inner" id="detailContent"></div>
</aside>
</main>
</div>
<dialog id="exchangeDialog">
<form id="exchangeForm">
<div class="dialog-header">
<h2>Post an exchange</h2>
<button class="dialog-close" type="button" data-close="exchangeDialog" aria-label="Close">×</button>
</div>
<div class="dialog-body">
<div class="form-row">
<div class="field">
<label for="exchangeCategory">Category</label>
<select id="exchangeCategory" required>
<option value="repair">Repair & fix</option>
<option value="cooking">Cook & share</option>
<option value="tutoring">Tutor & learn</option>
</select>
</div>
<div class="field">
<label for="exchangeDue">When</label>
<input id="exchangeDue" type="text" value="Saturday · 10:00 AM" required>
</div>
</div>
<div class="field">
<label for="exchangeTitle">What is needed</label>
<input
id="exchangeTitle"
type="text"
placeholder="Example: Tighten the loose garden gate"
required
>
</div>
<div class="form-row">
<div class="field">
<label for="exchangeRequester">Requester</label>
<input id="exchangeRequester" type="text" placeholder="Neighbor name" required>
</div>
<div class="field">
<label for="exchangeHelper">Helper</label>
<input id="exchangeHelper" type="text" placeholder="Neighbor name" required>
</div>
</div>
<div class="field">
<label for="exchangeLocation">Meeting place</label>
<input id="exchangeLocation" type="text" placeholder="Front porch, kitchen, library steps..." required>
</div>
<div class="field">
<label for="exchangeCommitment">First commitment</label>
<textarea
id="exchangeCommitment"
placeholder="Who will bring, return, prepare, or practice what?"
></textarea>
</div>
</div>
<div class="dialog-footer">
<button class="button" type="button" data-close="exchangeDialog">Cancel</button>
<button class="button primary" type="submit">Post exchange</button>
</div>
</form>
</dialog>
<dialog id="commitmentDialog">
<form id="commitmentForm">
<div class="dialog-header">
<h2>Add a commitment</h2>
<button class="dialog-close" type="button" data-close="commitmentDialog" aria-label="Close">×</button>
</div>
<div class="dialog-body">
<div class="field">
<label for="commitmentExchange">Linked exchange</label>
<select id="commitmentExchange" required></select>
</div>
<div class="form-row">
<div class="field">
<label for="commitmentOwner">Owner</label>
<input id="commitmentOwner" type="text" placeholder="Neighbor name" required>
</div>
<div class="field">
<label for="commitmentDue">Due</label>
<input id="commitmentDue" type="text" placeholder="Today · 6:00 PM" required>
</div>
</div>
<div class="field">
<label for="commitmentText">Promise</label>
<textarea
id="commitmentText"
placeholder="Describe the concrete next action"
required
></textarea>
</div>
</div>
<div class="dialog-footer">
<button class="button" type="button" data-close="commitmentDialog">Cancel</button>
<button class="button primary" type="submit">Add commitment</button>
</div>
</form>
</dialog>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const clone = (value) => JSON.parse(JSON.stringify(value));
const STORAGE_KEY = "common-ground-voxel-board-v1";
const categories = {
repair: {
label: "Repair & fix",
shortLabel: "Repair",
boardLabel: "FIX / BUILD",
color: 0x5377d9,
css: "#5377d9",
icon: "⚒"
},
cooking: {
label: "Cook & share",
shortLabel: "Cooking",
boardLabel: "COOK / SHARE",
color: 0xe98546,
css: "#e98546",
icon: "♨"
},
tutoring: {
label: "Tutor & learn",
shortLabel: "Tutoring",
boardLabel: "LEARN / HELP",
color: 0x36a273,
css: "#36a273",
icon: "✦"
}
};
const seedExchanges = [
{
id: "R-101",
category: "repair",
title: "Tighten the loose brake on my blue bicycle",
requester: "Maya Chen",
helper: "Theo Brooks",
location: "Maya’s porch · North Lane",
due: "Today · 5:00 PM",
status: "scheduled",
building: "theo",
note: "Maya has a crescent wrench and a new brake cable."
},
{
id: "R-102",
category: "repair",
title: "Re-seat the humming kitchen drawer",
requester: "Ana Ruiz",
helper: "Theo Brooks",
location: "Ana’s kitchen · Rowan House",
due: "Tomorrow · 10:00 AM",
status: "open",
building: "theo",
note: "The drawer sticks halfway open."
},
{
id: "R-103",
category: "repair",
title: "Patch three cracked step tiles",
requester: "Milo Park",
helper: "Sam Okafor",
location: "West steps · Common Hall",
due: "Completed Friday",
status: "completed",
building: "hall",
note: "Spare blue tiles are under the hall bench."
},
{
id: "C-201",
category: "cooking",
title: "Trade lentil soup for a jar of tomato jam",
requester: "Nia Patel",
helper: "Omar Reed",
location: "Nia’s kitchen · Garden House",
due: "Wednesday · 6:00 PM",
status: "scheduled",
building: "nia",
note: "Nia will make two jars; one is vegetarian."
},
{
id: "C-202",
category: "cooking",
title: "Teach me to fold herb dumplings for six",
requester: "Luca Moretti",
helper: "Priya Shah",
location: "Library teaching kitchen",
due: "Thursday · 4:00 PM",
status: "open",
building: "nia",
note: "Priya prefers a simple spinach and ricotta filling."
},
{
id: "C-203",
category: "cooking",
title: "Swap saffron rice for peach preserves",
requester: "Bea Lawson",
helper: "Omar Reed",
location: "Bea’s front gate",
due: "Completed Tuesday",
status: "completed",
building: "nia",
note: "The jars were labeled with ingredients."
},
{
id: "T-301",
category: "tutoring",
title: "Practice algebra fractions on the west steps",
requester: "Jo Ellis",
helper: "Mina Park",
location: "West steps · Common Hall",
due: "Tuesday · 4:00 PM",
status: "scheduled",
building: "jo",
note: "Mina will bring three worked examples."
},
{
id: "T-302",
category: "tutoring",
title: "Read a chapter from The Lantern Fox",
requester: "Eli Stone",
helper: "Jo Ellis",
location: "Corner reading bench",
due: "Thursday · 5:00 PM",
status: "open",
building: "jo",
note: "Eli would like to stop before chapter seven."
},
{
id: "T-303",
category: "tutoring",
title: "Practice Spanish greetings with Mara",
requester: "Niko Bell",
helper: "Mina Park",
location: "Community hall porch",
due: "Completed Saturday",
status: "completed",
building: "jo",
note: "They practiced greetings, farewells, and names."
}
];
const seedCommitments = [
{
id: "K-01",
exchangeId: "R-101",
owner: "Theo",
text: "Check the brake cable and return the blue bike",
due: "Today · 5:00 PM",
done: false
},
{
id: "K-02",
exchangeId: "R-101",
owner: "Maya",
text: "Return Theo’s crescent wrench to the workshop",
due: "Today · 7:00 PM",
done: false
},
{
id: "K-03",
exchangeId: "R-102",
owner: "Theo",
text: "Bring wood runners and re-seat the drawer",
due: "Tomorrow · 10:00 AM",
done: false
},
{
id: "K-04",
exchangeId: "C-201",
owner: "Omar",
text: "Bring one sealed jar of tomato jam",
due: "Wednesday · 6:00 PM",
done: false
},
{
id: "K-05",
exchangeId: "C-202",
owner: "Priya",
text: "Bring wrappers, spinach, and a folding demonstration",
due: "Thursday · 4:00 PM",
done: false
},
{
id: "K-06",
exchangeId: "T-301",
owner: "Mina",
text: "Print the fraction practice sheet",
due: "Tuesday · 3:30 PM",
done: false
},
{
id: "K-07",
exchangeId: "T-302",
owner: "Jo",
text: "Mark the stopping point on chapter six",
due: "Thursday · 4:30 PM",
done: false
},
{
id: "K-08",
exchangeId: "R-103",
owner: "Sam",
text: "Carry the repair kit to the west steps",
due: "Friday · 9:00 AM",
done: true
},
{
id: "K-09",
exchangeId: "C-203",
owner: "Bea",
text: "Label the peach preserve jar",
due: "Tuesday · 5:00 PM",
done: true
},
{
id: "K-10",
exchangeId: "T-303",
owner: "Niko",
text: "Practice the farewell phrase at home",
due: "Saturday · 9:00 AM",
done: true
}
];
let exchanges = clone(seedExchanges);
let commitments = clone(seedCommitments);
try {
const saved = JSON.parse(localStorage.getItem(STORAGE_KEY));
if (
saved &&
Array.isArray(saved.exchanges) &&
Array.isArray(saved.commitments)
) {
exchanges = saved.exchanges;
commitments = saved.commitments;
}
} catch (error) {
console.warn("Local board data could not be loaded.", error);
}
const state = {
view: "exchanges",
filter: "all",
search: "",
selectedId: exchanges[0]?.id ?? null
};
function persist() {
try {
localStorage.setItem(
STORAGE_KEY,
JSON.stringify({ exchanges, commitments })
);
} catch (error) {
console.warn("Local board data could not be saved.", error);
}
}
function escapeHTML(value = "") {
return String(value)
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function statusName(status) {
return {
scheduled: "Scheduled",
open: "Open",
completed: "Completed",
done: "Done"
}[status] || status;
}
function categoryFor(exchangeId) {
return exchanges.find((exchange) => exchange.id === exchangeId)?.category ?? "repair";
}
// ----- Three.js scene -----------------------------------------------------
const viewport = $("#viewport");
const canvasWrap = $("#canvasWrap");
const tooltip = $("#sceneTooltip");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ede7);
scene.fog = new THREE.Fog(0xe7ede7, 33, 62);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
canvasWrap.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "Voxel neighborhood. Drag to orbit and scroll to zoom.");
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraState = {
azimuth: 0.72,
polar: 0.72,
zoom: 1,
target: new THREE.Vector3(0, 0.85, 0.2)
};
const desiredCamera = {
azimuth: cameraState.azimuth,
polar: cameraState.polar,
zoom: cameraState.zoom,
target: cameraState.target.clone()
};
const hemisphere = new THREE.HemisphereLight(0xf8fbff, 0x8b9d82, 2.35);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff3d4, 3.5);
sunlight.position.set(-9, 18, 11);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -18;
sunlight.shadow.camera.right = 18;
sunlight.shadow.camera.top = 18;
sunlight.shadow.camera.bottom = -18;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 50;
sunlight.shadow.bias = -0.00035;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0xbad4ff, 0.7);
fillLight.position.set(10, 8, -10);
scene.add(fillLight);
const world = new THREE.Group();
scene.add(world);
const palette = {
ground: 0xcbd7bc,
groundAlt: 0xd3ddc7,
grass: 0x9fbd8d,
cream: 0xf6edda,
roof: 0x587468,
wood: 0x9a6e49,
darkWood: 0x654c39,
road: 0x64706c,
curb: 0xe7e2d2,
window: 0xaed9e2,
windowLit: 0xffdf8a,
leaf: 0x668d65,
leafLight: 0x7da676,
skin: [
0xe8b48e,
0xb87d5d,
0x8e5e45,
0xf0c8a8,
0x6f4937
]
};
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.85,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.rotationY) {
mesh.rotation.y = options.rotationY;
}
parent.add(mesh);
return mesh;
}
function makeTextTexture(text, options = {}) {
const {
background = null,
foreground = "#ffffff",
width = 1024,
height = 256,
fontSize = 92,
fontWeight = 800
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
if (background) {
context.fillStyle = background;
context.fillRect(0, 0, width, height);
}
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `${fontWeight} ${fontSize}px system-ui, sans-serif`;
const maxWidth = width - 70;
let displayText = text;
while (context.measureText(displayText).width > maxWidth && displayText.length > 4) {
displayText = displayText.slice(0, -2);
}
if (displayText !== text) {
displayText = `${displayText.slice(0, -1)}…`;
}
context.fillText(displayText, width / 2, height / 2 + 4);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeTextPlane(
text,
width,
height,
options = {}
) {
const texture = makeTextTexture(text, options);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
mesh.renderOrder = 3;
return mesh;
}
const pickables = [];
const buildingGroups = new Map();
const buildingRoofMaterials = new Map();
const animatedPeople = [];
let boardRoot;
let markerRoot;
const markerMeshes = new Map();
const markerMaterials = new Map();
const markerTitleMaterials = new Map();
const buildingDefs = {
theo: {
id: "theo",
label: "Theo’s Workshop",
category: "repair",
position: [-7.1, 0, -4.0],
body: 0xe4d8bd,
roof: categories.repair.color
},
nia: {
id: "nia",
label: "Nia’s Kitchen",
category: "cooking",
position: [-2.45, 0, -4.15],
body: 0xf0dfbd,
roof: categories.cooking.color
},
jo: {
id: "jo",
label: "Jo & Mina",
category: "tutoring",
position: [2.35, 0, -3.95],
body: 0xdce8dd,
roof: categories.tutoring.color
},
hall: {
id: "hall",
label: "Common Hall",
category: "all",
position: [7.0, 0, -4.15],
body: 0xe8e1cf,
roof: 0x728477
}
};
function buildGround() {
const groundMaterial = standardMaterial(palette.ground);
const groundAltMaterial = standardMaterial(palette.groundAlt);
addBox(world, [24, 0.9, 17], [0, -0.48, 0], groundMaterial);
for (let x = 0; x < 12; x++) {
for (let z = 0; z < 8; z++) {
const xPos = -11.25 + x * 2.05;
const zPos = -7.25 + z * 2.05;
if (Math.abs(zPos - 0.4) < 1.6) {
continue;
}
const material = (x + z) % 3 === 0 ? groundAltMaterial : groundMaterial;
addBox(
world,
[2.01, 0.055, 2.01],
[xPos, 0.025, zPos],
material,
{ castShadow: false }
);
}
}
const roadMaterial = standardMaterial(palette.road);
addBox(world, [22.8, 0.12, 2.25], [0, 0.06, 0.35], roadMaterial, {
castShadow: false
});
const curbMaterial = standardMaterial(palette.curb);
addBox(world, [22.8, 0.18, 0.35], [0, 0.09, -0.9], curbMaterial);
addBox(world, [22.8, 0.18, 0.35], [0, 0.09, 1.6], curbMaterial);
const markingMaterial = standardMaterial(0xe8dfbb);
for (let x = -9; x <= 9; x += 3) {
addBox(world, [1.3, 0.025, 0.09], [x, 0.135, 0.35], markingMaterial, {
castShadow: false
});
}
const crossingMaterial = standardMaterial(0xf0ead7);
for (let x = -0.85; x <= 0.85; x += 0.45) {
addBox(world, [0.26, 0.025, 2.15], [x, 0.14, 0.35], crossingMaterial, {
castShadow: false
});
}
}
function buildBuilding(def) {
const group = new THREE.Group();
group.position.set(...def.position);
world.add(group);
const bodyMaterial = standardMaterial(def.body);
const roofMaterial = standardMaterial(def.roof, {
transparent: true,
opacity: 1
});
const trimMaterial = standardMaterial(palette.darkWood);
const windowMaterial = standardMaterial(palette.window, {
emissive: 0x254b57,
emissiveIntensity: 0.18
});
const litWindowMaterial = standardMaterial(palette.windowLit, {
emissive: 0xd79e39,
emissiveIntensity: 0.4
});
addBox(group, [3.35, 0.2, 3.15], [0, 0.1, 0], standardMaterial(0xb5b9a9));
addBox(group, [3.0, 2.35, 2.55], [0, 1.3, 0], bodyMaterial);
// Stepped voxel roof.
addBox(group, [3.45, 0.34, 3.0], [0, 2.62, -0.05], roofMaterial);
addBox(group, [2.9, 0.34, 2.65], [0, 2.95, -0.1], roofMaterial);
addBox(group, [2.25, 0.34, 2.25], [0, 3.28, -0.15], roofMaterial);
// Door.
addBox(group, [0.76, 1.5, 0.16], [0, 0.88, 1.33], trimMaterial);
addBox(group, [0.55, 0.45, 0.08], [0, 1.68, 1.43], windowMaterial);
// Front windows.
addBox(group, [0.92, 0.78, 0.13], [-1.02, 1.45, 1.33], trimMaterial);
addBox(group, [0.72, 0.58, 0.08], [-1.02, 1.45, 1.42], litWindowMaterial);
addBox(group, [0.92, 0.78, 0.13], [1.02, 1.45, 1.33], trimMaterial);
addBox(group, [0.72, 0.58, 0.08], [1.02, 1.45, 1.42], windowMaterial);
// Side window.
addBox(group, [0.13, 0.78, 0.92], [1.56, 1.45, 0], trimMaterial);
addBox(group, [0.08, 0.58, 0.72], [1.65, 1.45, 0], windowMaterial);
// Chimney and door step.
addBox(group, [0.46, 0.75, 0.5], [0.8, 3.48, -0.65], standardMaterial(0x8a6250));
addBox(group, [1.05, 0.16, 0.55], [0, 0.18, 1.55], standardMaterial(0xd8cfba));
// Tiny plant.
addBox(group, [0.45, 0.38, 0.45], [-1.65, 0.43, 1.48], standardMaterial(0xb96f4e));
addBox(group, [0.56, 0.55, 0.56], [-1.65, 0.82, 1.48], standardMaterial(0x719866));
const sign = makeTextPlane(def.label.toUpperCase(), 2.55, 0.43, {
background: "#fffdf5",
foreground: "#33473f",
fontSize: 64
});
sign.position.set(0, 3.55, 1.25);
group.add(sign);
group.traverse((object) => {
if (object.isMesh) {
object.userData.buildingId = def.id;
object.userData.buildingCategory = def.category;
pickables.push(object);
}
});
buildingGroups.set(def.id, group);
buildingRoofMaterials.set(def.id, roofMaterial);
}
function buildTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
addBox(group, [0.42, 2.0, 0.42], [0, 1.0, 0], standardMaterial(palette.wood));
addBox(group, [1.9, 1.35, 1.9], [0, 2.45, 0], standardMaterial(palette.leaf));
addBox(group, [1.45, 1.1, 1.45], [0.25, 3.15, -0.15], standardMaterial(palette.leafLight));
addBox(group, [0.85, 0.85, 0.85], [-0.45, 3.62, 0.08], standardMaterial(palette.leaf));
}
function buildLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
const post = standardMaterial(0x3f514b);
addBox(group, [0.16, 3.6, 0.16], [0, 1.8, 0], post);
addBox(group, [0.75, 0.16, 0.75], [0, 3.52, 0], post);
addBox(group, [0.48, 0.58, 0.48], [0, 3.15, 0], standardMaterial(0xffdf94, {
emissive: 0xe7aa3b,
emissiveIntensity: 0.45
}));
}
function buildBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
const wood = standardMaterial(0x9c704c);
addBox(group, [2.15, 0.18, 0.62], [0, 0.65, 0], wood);
addBox(group, [2.15, 0.62, 0.16], [0, 1.02, -0.27], wood);
addBox(group, [0.18, 0.65, 0.55], [-0.76, 0.33, 0], standardMaterial(0x5a5146));
addBox(group, [0.18, 0.65, 0.55], [0.76, 0.33, 0], standardMaterial(0x5a5146));
}
function buildPerson(x, z, shirtColor, phase = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
const shirt = standardMaterial(shirtColor);
const pants = standardMaterial(0x44534f);
const skin = standardMaterial(palette.skin[Math.abs(Math.round(phase * 10)) % palette.skin.length]);
addBox(group, [0.22, 0.62, 0.25], [-0.15, 0.32, 0], pants);
addBox(group, [0.22, 0.62, 0.25], [0.15, 0.32, 0], pants);
addBox(group, [0.62, 0.7, 0.38], [0, 0.93, 0], shirt);
addBox(group, [0.42, 0.42, 0.4], [0, 1.49, 0], skin);
addBox(group, [0.44, 0.18, 0.42], [0, 1.67, 0], standardMaterial(0x4c382d));
group.userData.phase = phase;
animatedPeople.push(group);
}
function buildBoard() {
boardRoot = new THREE.Group();
boardRoot.position.set(0, 0, 4.35);
world.add(boardRoot);
const boardMaterial = standardMaterial(0xf4e8cd);
const frameMaterial = standardMaterial(0x6f533d);
const postMaterial = standardMaterial(0x74563f);
addBox(boardRoot, [0.36, 2.6, 0.36], [-5.25, 1.3, 0], postMaterial);
addBox(boardRoot, [0.36, 2.6, 0.36], [5.25, 1.3, 0], postMaterial);
addBox(boardRoot, [13.5, 4.65, 0.42], [0, 2.52, 0], boardMaterial);
addBox(boardRoot, [13.85, 0.24, 0.58], [0, 4.91, 0], frameMaterial);
addBox(boardRoot, [13.85, 0.24, 0.58], [0, 0.15, 0], frameMaterial);
const title = makeTextPlane("COMMON GROUND", 5.7, 0.72, {
background: "#173f38",
foreground: "#fff8e8",
fontSize: 96
});
title.position.set(0, 5.38, 0.31);
boardRoot.add(title);
const columnXs = [-4.3, 0, 4.3];
Object.entries(categories).forEach(([key, category], index) => {
const x = columnXs[index];
addBox(
boardRoot,
[3.75, 0.72, 0.18],
[x, 4.12, 0.27],
standardMaterial(category.color)
);
const label = makeTextPlane(category.boardLabel, 3.35, 0.48, {
background: `#${category.color.toString(16).padStart(6, "0")}`,
foreground: "#ffffff",
fontSize: 64
});
label.position.set(x, 4.12, 0.38);
boardRoot.add(label);
// Small category pegs.
for (let peg = 0; peg < 2; peg++) {
addBox(
boardRoot,
[0.16, 0.16, 0.12],
[x - 1.45 + peg * 2.9, 4.12, 0.43],
standardMaterial(0xfff8df)
);
}
});
markerRoot = new THREE.Group();
boardRoot.add(markerRoot);
}
function disposeMarker(marker) {
marker.traverse((object) => {
if (!object.isMesh) return;
object.geometry?.dispose();
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material?.map?.dispose();
object.material?.dispose();
}
});
}
function rebuildMarkers() {
markerMeshes.clear();
markerMaterials.clear();
markerTitleMaterials.clear();
while (markerRoot.children.length) {
const child = markerRoot.children.pop();
disposeMarker(child);
}
const columnXs = {
repair: -4.3,
cooking: 0,
tutoring: 4.3
};
Object.entries(categories).forEach(([categoryKey, category]) => {
const records = exchanges
.filter((exchange) => exchange.category === categoryKey)
.slice(0, 6);
records.forEach((exchange, index) => {
const group = new THREE.Group();
group.position.set(columnXs[categoryKey], 3.48 - index * 0.58, 0.48);
const material = standardMaterial(category.color, {
transparent: true,
opacity: 0.96,
emissive: 0x000000
});
const card = addBox(group, [3.25, 0.43, 0.16], [0, 0, 0], material);
card.userData.exchangeId = exchange.id;
const title = makeTextPlane(exchange.title, 2.8, 0.25, {
background: `#${category.color.toString(16).padStart(6, "0")}`,
foreground: "#ffffff",
fontSize: 52,
height: 128,
width: 1024
});
title.position.set(0, 0, 0.095);
group.add(title);
const pin = addBox(
group,
[0.15, 0.15, 0.08],
[-1.48, 0.13, 0.13],
standardMaterial(0xfff6d8)
);
pin.userData.exchangeId = exchange.id;
markerRoot.add(group);
markerMeshes.set(exchange.id, card);
markerMaterials.set(exchange.id, material);
markerTitleMaterials.set(exchange.id, title.material);
pickables.push(card, pin);
});
});
updateSceneHighlights();
}
const selectedFrame = new THREE.Group();
const selectedFrameMaterial = new THREE.MeshBasicMaterial({
color: 0x173f38,
transparent: true,
opacity: 0.9
});
addBox(selectedFrame, [4.4, 0.06, 0.09], [0, 0.07, -2.2], selectedFrameMaterial);
addBox(selectedFrame, [4.4, 0.06, 0.09], [0, 0.07, 2.2], selectedFrameMaterial);
addBox(selectedFrame, [0.09, 0.06, 4.4], [-2.2, 0.07, 0], selectedFrameMaterial);
addBox(selectedFrame, [0.09, 0.06, 4.4], [2.2, 0.07, 0], selectedFrameMaterial);
world.add(selectedFrame);
function buildNeighborhood() {
buildGround();
Object.values(buildingDefs).forEach(buildBuilding);
buildTree(-10.2, -6.2, 1.1);
buildTree(10.0, -6.1, 1.0);
buildTree(-9.5, 2.3, 0.85);
buildTree(9.8, 2.4, 0.9);
buildTree(-5.9, -6.6, 0.7);
buildTree(5.0, -6.6, 0.72);
buildLamp(-8.7, -0.95);
buildLamp(8.7, -0.95);
buildLamp(-3.5, 1.95);
buildLamp(3.5, 1.95);
buildBench(-7.3, 2.0, Math.PI / 2);
buildBench(6.8, 2.0, -Math.PI / 2);
buildBench(0.5, -1.75, 0);
buildPerson(-4.8, 5.7, 0xe98546, 0.2);
buildPerson(-4.35, 5.75, 0x5377d9, 1.1);
buildPerson(3.9, 5.75, 0x36a273, 2.3);
buildPerson(-7.4, -1.7, 0xd28b53, 3.1);
buildPerson(3.0, -1.55, 0x6885c5, 4.4);
buildBoard();
rebuildMarkers();
}
function updateSceneHighlights() {
const selected = exchanges.find((exchange) => exchange.id === state.selectedId);
const selectedBuilding = selected?.building ?? "hall";
const building = buildingGroups.get(selectedBuilding);
if (building) {
selectedFrame.position.set(building.position.x, 0, building.position.z);
selectedFrame.visible = true;
const color = categories[selected?.category ?? "repair"].color;
selectedFrameMaterial.color.setHex(color);
}
markerMeshes.forEach((card, id) => {
const markerMaterial = markerMaterials.get(id);
const titleMaterial = markerTitleMaterials.get(id);
const categoryKey = categoryFor(id);
const matchesFilter = state.filter === "all" || state.filter === categoryKey;
const isSelected = id === state.selectedId;
markerMaterial.opacity = matchesFilter ? 0.96 : 0.22;
markerMaterial.emissive.setHex(isSelected ? 0xffffff : 0x000000);
markerMaterial.emissiveIntensity = isSelected ? 0.24 : 0;
if (titleMaterial) {
titleMaterial.opacity = matchesFilter ? 1 : 0.22;
}
});
buildingGroups.forEach((group, id) => {
const roofMaterial = buildingRoofMaterials.get(id);
const definition = buildingDefs[id];
const matchesFilter =
state.filter === "all" ||
definition.category === "all" ||
definition.category === state.filter;
roofMaterial.opacity = matchesFilter ? 1 : 0.32;
roofMaterial.emissive.setHex(
id === selectedBuilding
? categories[selected?.category ?? "repair"].color
: 0x000000
);
roofMaterial.emissiveIntensity = id === selectedBuilding ? 0.16 : 0;
});
}
buildNeighborhood();
// ----- Camera controls ----------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: 0,
x: 0,
y: 0,
lastX: 0,
lastY: 0,
shift: false
};
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function hitTest(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(pickables, false)[0] ?? null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerState.down = true;
pointerState.moved = 0;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
pointerState.shift = event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
tooltip.hidden = true;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerState.down) {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.moved += Math.abs(dx) + Math.abs(dy);
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
if (pointerState.shift || event.shiftKey) {
const scale = 0.025 / cameraState.zoom;
desiredCamera.target.x -= dx * scale;
desiredCamera.target.z -= dy * scale;
desiredCamera.target.x = THREE.MathUtils.clamp(desiredCamera.target.x, -9, 9);
desiredCamera.target.z = THREE.MathUtils.clamp(desiredCamera.target.z, -7, 7);
} else {
desiredCamera.azimuth -= dx * 0.006;
desiredCamera.polar = THREE.MathUtils.clamp(
desiredCamera.polar - dy * 0.0045,
0.38,
1.13
);
}
return;
}
const hit = hitTest(event);
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
if (!hit) {
tooltip.hidden = true;
return;
}
const data = hit.object.userData;
let text = "";
if (data.exchangeId) {
const exchange = exchanges.find((item) => item.id === data.exchangeId);
if (exchange) {
text = `${exchange.title} · ${exchange.due}`;
}
} else if (data.buildingId) {
const definition = buildingDefs[data.buildingId];
const count = exchanges.filter((exchange) => exchange.building === data.buildingId).length;
text = `${definition.label} · ${count} exchange${count === 1 ? "" : "s"}`;
}
if (!text) {
tooltip.hidden = true;
return;
}
const rect = viewport.getBoundingClientRect();
tooltip.textContent = text;
tooltip.style.left = `${event.clientX - rect.left}px`;
tooltip.style.top = `${event.clientY - rect.top}px`;
tooltip.hidden = false;
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick = pointerState.moved < 6;
pointerState.down = false;
renderer.domElement.classList.remove("dragging");
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!wasClick) return;
const hit = hitTest(event);
if (!hit) return;
const data = hit.object.userData;
if (data.exchangeId) {
selectExchange(data.exchangeId);
} else if (data.buildingId) {
const candidates = exchanges.filter(
(exchange) =>
exchange.building === data.buildingId &&
(state.filter === "all" || exchange.category === state.filter)
);
const fallback = exchanges.filter(
(exchange) => exchange.building === data.buildingId
);
const exchange = candidates[0] ?? fallback[0];
if (exchange) selectExchange(exchange.id);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerState.down) tooltip.hidden = true;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.zoom = THREE.MathUtils.clamp(
desiredCamera.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.1
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") desiredCamera.azimuth += step;
else if (event.key === "ArrowRight") desiredCamera.azimuth -= step;
else if (event.key === "ArrowUp") {
desiredCamera.polar = THREE.MathUtils.clamp(desiredCamera.polar - step, 0.38, 1.13);
} else if (event.key === "ArrowDown") {
desiredCamera.polar = THREE.MathUtils.clamp(desiredCamera.polar + step, 0.38, 1.13);
} else if (event.key === "+" || event.key === "=") {
desiredCamera.zoom = Math.min(2.1, desiredCamera.zoom + 0.1);
} else if (event.key === "-") {
desiredCamera.zoom = Math.max(0.68, desiredCamera.zoom - 0.1);
} else {
return;
}
event.preventDefault();
});
function resetCamera() {
desiredCamera.azimuth = 0.72;
desiredCamera.polar = 0.72;
desiredCamera.zoom = 1;
desiredCamera.target.set(0, 0.85, 0.2);
}
function focusBuilding(buildingId) {
const building = buildingGroups.get(buildingId);
if (!building) return;
desiredCamera.target.set(building.position.x, 0.75, building.position.z);
desiredCamera.zoom = 1.38;
}
$("#resetCamera").addEventListener("click", resetCamera);
$("#zoomIn").addEventListener("click", () => {
desiredCamera.zoom = Math.min(2.1, desiredCamera.zoom + 0.13);
});
$("#zoomOut").addEventListener("click", () => {
desiredCamera.zoom = Math.max(0.68, desiredCamera.zoom - 0.13);
});
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const viewHeight = 17.8;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resizeRenderer).observe(viewport);
resizeRenderer();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const damping = 1 - Math.exp(-dt * 8);
cameraState.azimuth = THREE.MathUtils.lerp(
cameraState.azimuth,
desiredCamera.azimuth,
damping
);
cameraState.polar = THREE.MathUtils.lerp(
cameraState.polar,
desiredCamera.polar,
damping
);
cameraState.zoom = THREE.MathUtils.lerp(
cameraState.zoom,
desiredCamera.zoom,
damping
);
cameraState.target.lerp(desiredCamera.target, damping);
const radius = 29;
camera.position.set(
cameraState.target.x + radius * Math.sin(cameraState.polar) * Math.sin(cameraState.azimuth),
cameraState.target.y + radius * Math.cos(cameraState.polar),
cameraState.target.z + radius * Math.sin(cameraState.polar) * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
animatedPeople.forEach((person) => {
person.position.y = Math.sin(elapsed * 1.8 + person.userData.phase) * 0.025;
});
selectedFrameMaterial.opacity = 0.72 + Math.sin(elapsed * 2.4) * 0.16;
renderer.render(scene, camera);
}
animate();
// ----- UI rendering -------------------------------------------------------
function matchingExchanges() {
const query = state.search.trim().toLowerCase();
return exchanges.filter((exchange) => {
const categoryMatches =
state.filter === "all" || exchange.category === state.filter;
const text = [
exchange.title,
exchange.requester,
exchange.helper,
exchange.location,
categories[exchange.category].label
]
.join(" ")
.toLowerCase();
return categoryMatches && (!query || text.includes(query));
});
}
function matchingCommitments() {
const query = state.search.trim().toLowerCase();
return commitments.filter((commitment) => {
const exchange = exchanges.find(
(item) => item.id === commitment.exchangeId
);
if (!exchange) return false;
const categoryMatches =
state.filter === "all" || exchange.category === state.filter;
const text = [
commitment.text,
commitment.owner,
commitment.due,
exchange.title
]
.join(" ")
.toLowerCase();
return categoryMatches && (!query || text.includes(query));
});
}
function renderStats() {
const active = exchanges.filter((exchange) => exchange.status !== "completed").length;
const open = commitments.filter((commitment) => !commitment.done).length;
const completed = commitments.filter((commitment) => commitment.done).length;
const total = commitments.length;
const percent = total ? Math.round((completed / total) * 100) : 0;
$("#activeExchanges").textContent = active;
$("#openCommitments").textContent = open;
$("#completionRate").textContent = `${percent}%`;
}
function renderTabs() {
$$(".tab").forEach((tab) => {
tab.classList.toggle("active", tab.dataset.view === state.view);
tab.setAttribute("aria-selected", String(tab.dataset.view === state.view));
});
$$(".filter").forEach((filter) => {
filter.classList.toggle("active", filter.dataset.filter === state.filter);
});
}
function exchangeCard(exchange) {
const category = categories[exchange.category];
const selected = exchange.id === state.selectedId;
return `
<article
class="record-card ${selected ? "selected" : ""}"
data-exchange-id="${escapeHTML(exchange.id)}"
style="--category:${category.css}"
tabindex="0"
>
<div class="record-top">
<span class="category-label">
<i class="category-dot"></i>${escapeHTML(category.label)}
</span>
<span class="status ${escapeHTML(exchange.status)}">
${escapeHTML(statusName(exchange.status))}
</span>
</div>
<h3>${escapeHTML(exchange.title)}</h3>
<div class="people-line">
<strong>${escapeHTML(exchange.requester)}</strong>
<span> → </span>
<strong>${escapeHTML(exchange.helper)}</strong>
</div>
<div class="record-meta">
<span>⌖ ${escapeHTML(exchange.location)}</span>
<span>◷ ${escapeHTML(exchange.due)}</span>
</div>
</article>
`;
}
function commitmentCard(commitment) {
const exchange = exchanges.find(
(item) => item.id === commitment.exchangeId
);
if (!exchange) return "";
const category = categories[exchange.category];
const selected = exchange.id === state.selectedId;
return `
<article
class="record-card ${selected ? "selected" : ""}"
data-exchange-id="${escapeHTML(exchange.id)}"
style="--category:${category.css}"
tabindex="0"
>
<div class="record-top">
<span class="category-label">
<i class="category-dot"></i>${escapeHTML(category.shortLabel)}
</span>
<span class="status ${commitment.done ? "done" : "open"}">
${commitment.done ? "Done" : "Open"}
</span>
</div>
<h3>
<button
class="commitment-check ${commitment.done ? "done" : ""}"
data-toggle-commitment="${escapeHTML(commitment.id)}"
aria-label="${commitment.done ? "Mark open" : "Mark complete"}"
>${commitment.done ? "✓" : ""}</button>
${escapeHTML(commitment.text)}
</h3>
<div class="people-line">
Owner: <strong>${escapeHTML(commitment.owner)}</strong>
</div>
<div class="record-meta">
<span>${escapeHTML(exchange.title)}</span>
<span>◷ ${escapeHTML(commitment.due)}</span>
</div>
</article>
`;
}
function renderRecords() {
const records =
state.view === "exchanges"
? matchingExchanges()
: matchingCommitments();
$("#recordCount").textContent = records.length;
if (!records.length) {
$("#records").innerHTML = `
<div class="empty-state">
<div>
<strong>No matching records</strong>
Try another category or search phrase.
</div>
</div>
`;
return;
}
$("#records").innerHTML = records
.map((record) =>
state.view === "exchanges"
? exchangeCard(record)
: commitmentCard(record)
)
.join("");
}
function renderDetail() {
const exchange = exchanges.find(
(item) => item.id === state.selectedId
);
if (!exchange) {
$("#detailContent").innerHTML = `
<div class="empty-state">
<div>
<strong>Select an exchange</strong>
Choose a card, board tile, or neighborhood building.
</div>
</div>
`;
return;
}
const category = categories[exchange.category];
const related = commitments.filter(
(commitment) => commitment.exchangeId === exchange.id
);
const completed = related.filter((commitment) => commitment.done).length;
const progress = related.length
? Math.round((completed / related.length) * 100)
: 0;
$("#detailContent").innerHTML = `
<div class="details-top" style="--category:${category.css}">
<div class="detail-icon" aria-hidden="true">${category.icon}</div>
<div class="detail-title">
<h2>${escapeHTML(exchange.title)}</h2>
<span class="category-label">
<i class="category-dot"></i>${escapeHTML(category.label)}
<span class="status ${escapeHTML(exchange.status)}">
${escapeHTML(statusName(exchange.status))}
</span>
</span>
</div>
</div>
<section class="detail-section">
<h3>Neighbors</h3>
<div class="exchange-route">
<div class="route-person">
<span>Requesting</span>
<strong>${escapeHTML(exchange.requester)}</strong>
</div>
<div class="route-arrow" aria-hidden="true">→</div>
<div class="route-person">
<span>Helping</span>
<strong>${escapeHTML(exchange.helper)}</strong>
</div>
</div>
</section>
<section class="detail-section">
<h3>Exchange details</h3>
<div class="info-grid">
<div class="info-cell">
<span>Meet at</span>
<strong>${escapeHTML(exchange.location)}</strong>
</div>
<div class="info-cell">
<span>Timing</span>
<strong>${escapeHTML(exchange.due)}</strong>
</div>
</div>
</section>
<section class="detail-section" style="--category:${category.css}">
<h3>Outstanding commitments</h3>
${
related.length
? related
.map(
(commitment) => `
<div class="commitment-item ${commitment.done ? "done" : ""}">
<button
class="commitment-check ${commitment.done ? "done" : ""}"
data-toggle-detail="${escapeHTML(commitment.id)}"
aria-label="${commitment.done ? "Mark commitment open" : "Mark commitment complete"}"
>${commitment.done ? "✓" : ""}</button>
<div class="commitment-copy">
<strong>${escapeHTML(commitment.text)}</strong>
<span>${escapeHTML(commitment.owner)} · ${escapeHTML(commitment.due)}</span>
</div>
</div>
`
)
.join("")
: `<div class="empty-state" style="min-height:80px;padding:12px 0">No promises recorded yet.</div>`
}
<div class="progress-track">
<div class="progress-fill" style="width:${progress}%"></div>
</div>
<div class="progress-caption">
<span>${completed} of ${related.length} complete</span>
<span>${progress}%</span>
</div>
<div class="detail-actions">
<button class="button" id="addCommitment">+ Commitment</button>
<button class="button" id="focusExchange">⌖ Focus</button>
</div>
</section>
<section class="detail-section">
<h3>Neighbor notes</h3>
<textarea
id="detailNote"
class="note-area"
placeholder="Add a useful detail for this exchange…"
>${escapeHTML(exchange.note ?? "")}</textarea>
<div class="note-row">
<span>Saved only in this browser</span>
<button class="button" id="saveNote">Save note</button>
</div>
</section>
`;
}
function renderAll() {
renderStats();
renderTabs();
renderRecords();
renderDetail();
updateSceneHighlights();
}
function selectExchange(id) {
if (!exchanges.some((exchange) => exchange.id === id)) return;
state.selectedId = id;
renderRecords();
renderDetail();
updateSceneHighlights();
}
function syncExchangeStatus(exchangeId) {
const exchange = exchanges.find((item) => item.id === exchangeId);
if (!exchange) return;
const related = commitments.filter(
(commitment) => commitment.exchangeId === exchangeId
);
if (related.length && related.every((commitment) => commitment.done)) {
exchange.status = "completed";
} else if (exchange.status === "completed") {
exchange.status = "scheduled";
}
}
function toggleCommitment(id) {
const commitment = commitments.find((item) => item.id === id);
if (!commitment) return;
commitment.done = !commitment.done;
syncExchangeStatus(commitment.exchangeId);
persist();
renderAll();
}
function openCommitmentDialog() {
const select = $("#commitmentExchange");
select.innerHTML = exchanges
.map(
(exchange) =>
`<option value="${escapeHTML(exchange.id)}" ${
exchange.id === state.selectedId ? "selected" : ""
}>${escapeHTML(exchange.title)}</option>`
)
.join("");
const selectedExchange = exchanges.find(
(exchange) => exchange.id === state.selectedId
);
$("#commitmentOwner").value =
selectedExchange?.helper?.split(" ")[0] ?? "";
$("#commitmentDue").value = "Saturday · 10:00 AM";
$("#commitmentText").value = "";
$("#commitmentDialog").showModal();
setTimeout(() => $("#commitmentText").focus(), 50);
}
let toastTimer;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2300);
}
// ----- UI events ----------------------------------------------------------
$$(".tab").forEach((tab) => {
tab.addEventListener("click", () => {
state.view = tab.dataset.view;
renderAll();
});
});
$$(".filter").forEach((filter) => {
filter.addEventListener("click", () => {
state.filter = filter.dataset.filter;
const matching =
state.view === "exchanges"
? matchingExchanges()
: matchingCommitments();
if (matching.length && !matching.some((record) => record.id === state.selectedId)) {
const first = matching[0];
state.selectedId =
state.view === "exchanges" ? first.id : first.exchangeId;
}
renderAll();
});
});
$("#searchInput").addEventListener("input", (event) => {
state.search = event.target.value;
renderRecords();
});
$("#records").addEventListener("click", (event) => {
const toggle = event.target.closest("[data-toggle-commitment]");
if (toggle) {
event.stopPropagation();
toggleCommitment(toggle.dataset.toggleCommitment);
return;
}
const card = event.target.closest("[data-exchange-id]");
if (card) selectExchange(card.dataset.exchangeId);
});
$("#records").addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
const card = event.target.closest("[data-exchange-id]");
if (!card) return;
event.preventDefault();
selectExchange(card.dataset.exchangeId);
});
$("#detailContent").addEventListener("click", (event) => {
const toggle = event.target.closest("[data-toggle-detail]");
if (toggle) {
toggleCommitment(toggle.dataset.toggleDetail);
return;
}
if (event.target.closest("#addCommitment")) {
openCommitmentDialog();
return;
}
if (event.target.closest("#focusExchange")) {
const exchange = exchanges.find(
(item) => item.id === state.selectedId
);
if (exchange) focusBuilding(exchange.building);
return;
}
if (event.target.closest("#saveNote")) {
const exchange = exchanges.find(
(item) => item.id === state.selectedId
);
const note = $("#detailNote")?.value ?? "";
if (exchange) {
exchange.note = note;
persist();
showToast("Neighbor note saved");
}
}
});
$("#openExchangeDialog").addEventListener("click", () => {
$("#exchangeCategory").value =
state.filter === "all" ? "repair" : state.filter;
$("#exchangeForm").reset();
$("#exchangeCategory").value =
state.filter === "all" ? "repair" : state.filter;
$("#exchangeDue").value = "Saturday · 10:00 AM";
$("#exchangeDialog").showModal();
setTimeout(() => $("#exchangeTitle").focus(), 50);
});
$("#exchangeForm").addEventListener("submit", (event) => {
event.preventDefault();
const category = $("#exchangeCategory").value;
const prefix = {
repair: "R",
cooking: "C",
tutoring: "T"
}[category];
const id = `${prefix}-${Date.now().toString().slice(-5)}`;
const exchange = {
id,
category,
title: $("#exchangeTitle").value.trim(),
requester: $("#exchangeRequester").value.trim(),
helper: $("#exchangeHelper").value.trim(),
location: $("#exchangeLocation").value.trim(),
due: $("#exchangeDue").value.trim(),
status: "scheduled",
building:
category === "repair"
? "theo"
: category === "cooking"
? "nia"
: "jo",
note: ""
};
exchanges.unshift(exchange);
const commitmentText = $("#exchangeCommitment").value.trim();
if (commitmentText) {
commitments.unshift({
id: `K-${Date.now().toString().slice(-5)}`,
exchangeId: id,
owner: exchange.helper.split(" ")[0],
text: commitmentText,
due: exchange.due,
done: false
});
}
state.selectedId = id;
state.view = "exchanges";
persist();
rebuildMarkers();
renderAll();
$("#exchangeDialog").close();
showToast("Exchange posted to the neighborhood board");
});
$("#commitmentForm").addEventListener("submit", (event) => {
event.preventDefault();
const exchangeId = $("#commitmentExchange").value;
const owner = $("#commitmentOwner").value.trim();
const text = $("#commitmentText").value.trim();
const due = $("#commitmentDue").value.trim();
if (!exchangeId || !owner || !text || !due) return;
commitments.unshift({
id: `K-${Date.now().toString().slice(-5)}`,
exchangeId,
owner,
text,
due,
done: false
});
state.selectedId = exchangeId;
persist();
renderAll();
$("#commitmentDialog").close();
showToast("Commitment added");
});
$$('[data-close]').forEach((button) => {
button.addEventListener("click", () => {
document.getElementById(button.dataset.close).close();
});
});
$$("dialog").forEach((dialog) => {
dialog.addEventListener("click", (event) => {
const rect = dialog.getBoundingClientRect();
const inside =
event.clientX >= rect.left &&
event.clientX <= rect.right &&
event.clientY >= rect.top &&
event.clientY <= rect.bottom;
if (!inside) dialog.close();
});
});
$("#resetDemo").addEventListener("click", () => {
const confirmed = window.confirm(
"Restore the original fictional neighborhood records? Your local additions will be removed."
);
if (!confirmed) return;
exchanges = clone(seedExchanges);
commitments = clone(seedCommitments);
state.selectedId = exchanges[0].id;
state.view = "exchanges";
state.filter = "all";
state.search = "";
$("#searchInput").value = "";
persist();
rebuildMarkers();
renderAll();
resetCamera();
showToast("Demo neighborhood restored");
});
renderAll();
</script>
</body>
</html>
```