Wire up garden controls

This commit is contained in:
Andras Schmelczer 2026-05-24 10:58:21 +01:00
parent 018f8c9d4d
commit 839747304e
15 changed files with 1457 additions and 393 deletions

24
src/utils/dom.ts Normal file
View file

@ -0,0 +1,24 @@
import { ErrorCode, RuntimeError } from './error-handler';
type ElementConstructor<T extends Element> = abstract new () => T;
export const queryRequiredElement = <T extends Element>(
selector: string,
constructor: ElementConstructor<T>
): T => {
const element = document.querySelector(selector);
if (!(element instanceof constructor)) {
throw new RuntimeError(
ErrorCode.DOM_ELEMENT_MISSING,
`Missing required DOM element: ${selector}`,
{
details: {
expectedType: constructor.name,
selector,
},
}
);
}
return element;
};