2025-01-14 14:52:31 +01:00
|
|
|
// I would've LOVED to use generics for this but unfortunately that's not possible.
|
|
|
|
// Type safety, but at what cost... >~< thanks TypeScript
|
|
|
|
|
2025-02-12 06:49:22 +01:00
|
|
|
export function findOptionOrFail(on: Element, selector: string): HTMLOptionElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLOptionElement))
|
|
|
|
throw new Error(`${selector} isn't an option`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2025-01-28 23:26:21 +01:00
|
|
|
export function findOlOrFail(on: Element, selector: string): HTMLOListElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLOListElement))
|
|
|
|
throw new Error(`${selector} isn't an ol`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2025-01-20 19:36:38 +01:00
|
|
|
export function findPreOrFail(on: Element, selector: string): HTMLPreElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLPreElement))
|
|
|
|
throw new Error(`${selector} isn't a pre`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findParagraphOrFail(on: Element, selector: string): HTMLParagraphElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLParagraphElement))
|
|
|
|
throw new Error(`${selector} isn't a paragraph`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2025-01-14 15:58:30 +01:00
|
|
|
export function findDialogOrFail(on: Element, selector: string): HTMLDialogElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLDialogElement))
|
|
|
|
throw new Error(`${selector} isn't a dialog`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2025-01-14 14:52:31 +01:00
|
|
|
export function findFormOrFail(on: Element, selector: string): HTMLFormElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLFormElement))
|
|
|
|
throw new Error(`${selector} isn't a form`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findInputOrFail(on: Element, selector: string): HTMLInputElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLInputElement))
|
|
|
|
throw new Error(`${selector} isn't an input`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findButtonOrFail(on: Element, selector: string): HTMLButtonElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLButtonElement))
|
|
|
|
throw new Error(`${selector} isn't a button`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findSelectOrFail(on: Element, selector: string): HTMLSelectElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLSelectElement))
|
|
|
|
throw new Error(`${selector} isn't a select`);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findImageOrFail(on: Element, selector: string): HTMLImageElement {
|
|
|
|
const element = on.querySelector(selector);
|
|
|
|
if (!(element instanceof HTMLImageElement))
|
|
|
|
throw new Error(`${selector} isn't an image`);
|
|
|
|
return element;
|
|
|
|
}
|