added gameboard

This commit is contained in:
yoshi 2025-04-22 11:59:50 -07:00
parent 93d278340e
commit fa36efa455
68 changed files with 7800 additions and 1 deletions

View file

@ -0,0 +1,26 @@
import Mousestrap from "mousetrap";
type Options = {
keys: string[];
f: () => void;
};
export function keybind(node: HTMLElement, options: Options) {
console.debug("[keybind] binding:", options.keys);
const mousetrap = new Mousestrap(document.documentElement);
mousetrap.bind(options.keys, () => {
console.debug("[keybind] handling:", options.keys);
options.f();
// Always prevent default behavior
return false;
});
return {
destroy() {
console.debug("[keybind] destorying:", options.keys);
mousetrap.reset();
}
};
}

View file

@ -0,0 +1,20 @@
type Options = {
f: (width: number, height: number) => void;
};
export function resize(node: HTMLElement, options: Options) {
const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
const w = entry.contentBoxSize[0].inlineSize;
const h = entry.contentBoxSize[0].blockSize;
options.f(w, h);
}
});
resizeObserver.observe(node);
return {
destroy() {
resizeObserver.unobserve(node);
}
};
}

View file

@ -0,0 +1,20 @@
import tippy from "tippy.js";
type Options = {
templateId: string;
tippyProps: object;
};
export function tooltip(node: HTMLElement, options: Options) {
const props = {
...options.tippyProps,
allowHTML: true,
content: document.getElementById(options.templateId)?.innerHTML.slice()
};
const tip = tippy(node, props);
return {
destroy: () => tip.destroy()
};
}