Skip to content

Commit 8d8ddf1

Browse files
committed
feat: add pointer interaction
1 parent d020f3a commit 8d8ddf1

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

website/src/components/HdiLogo.astro

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
_____ _____ _____
77
||h |||d |||i ||
88
||___|||___|||___||
9-
|/___\|/___\|/___\|
10-
</pre>
9+
|/___\|/___\|/___\|</pre>
1110

1211
<script>
1312
// ── Logo key press animation ──────────────────────────────────────────
@@ -56,7 +55,7 @@
5655
row
5756
],
5857
);
59-
_logoPre.innerHTML = "\n" + rows.join("\n") + "\n";
58+
_logoPre.innerHTML = rows.join("\n");
6059
}
6160

6261
function _pressLogoKey(key: string) {
@@ -71,10 +70,13 @@
7170
}
7271

7372
_logoPre.addEventListener("mousedown", (e) => {
74-
const el = (e.target as HTMLElement).closest<HTMLElement>(
75-
".hero-logo-letter",
76-
);
77-
if (el?.dataset.key) _pressLogoKey(el.dataset.key);
73+
// Measure one character's width using the pre's own font
74+
const charWidth = _logoPre.getBoundingClientRect().width / 19; // logo is 19 chars wide
75+
const rect = _logoPre.getBoundingClientRect();
76+
const col = Math.floor((e.clientX - rect.left) / charWidth);
77+
// h: cols 0-5, d: cols 6-11, i: cols 12-17 (col 18 is trailing '|', ignore)
78+
const key = col < 6 ? "h" : col < 12 ? "d" : col < 18 ? "i" : null;
79+
if (key) _pressLogoKey(key);
7880
});
7981
document.addEventListener("mouseup", () => {
8082
[..._pressedKeys].forEach((k) => _releaseLogoKey(k));
@@ -98,8 +100,8 @@
98100
.hero-logo {
99101
font-size: 1.5rem;
100102
line-height: initial;
103+
cursor: pointer;
101104
user-select: none;
102-
/* cursor: pointer; */
103105

104106
.hero-logo-letter {
105107
color: var(--green);

website/src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ $ hdi
221221

222222
.hero-header {
223223
align-items: center;
224-
--space: 1rem;
224+
--space: 1.5rem;
225225
}
226226

227227
.hero h1 {

0 commit comments

Comments
 (0)