Something went wrong. Try again.
(WIP) Modern Minecraft server-side HUD framework.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788import { clsx, type ClassValue } from 'clsx';import type { BoundingBox } from 'libmojangles';import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs));}
// eslint-disable-next-line @typescript-eslint/no-explicit-anyexport type WithoutChild<T> = T extends { child?: any } ? Omit<T, 'child'> : T;// eslint-disable-next-line @typescript-eslint/no-explicit-anyexport type WithoutChildren<T> = T extends { children?: any } ? Omit<T, 'children'> : T;export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & { ref?: U | null };
export function boundingBoxOfBoxes(bboxes: BoundingBox[]): BoundingBox { if (bboxes.length === 0) { throw new Error('Cannot compute bounding box of empty list'); }
return { min: [Math.min(...bboxes.map((b) => b.min[0])), Math.min(...bboxes.map((b) => b.min[1]))], max: [Math.max(...bboxes.map((b) => b.max[0])), Math.max(...bboxes.map((b) => b.max[1]))] };}
export type AnchorPosition = | 'top-left' | 'top-center' | 'top-right' | 'middle-left' | 'center' | 'middle-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
export const ANCHOR_POSITIONS: AnchorPosition[] = [ 'top-left', 'top-center', 'top-right', 'middle-left', 'center', 'middle-right', 'bottom-left', 'bottom-center', 'bottom-right'];
export function alignForAnchor(anchor: string): 'left' | 'right' | 'center' { if (anchor.endsWith('-left')) return 'left'; if (anchor.endsWith('-right')) return 'right'; return 'center';}
export function applyAnchorToElement(element: Element, anchor: string) { element.setAttribute('anchor', anchor); element.setAttribute('x', '0'); element.setAttribute('y', anchor.startsWith('bottom-') ? '-18' : '0'); element.setAttribute('align', alignForAnchor(anchor));}
export function getElementPath(element: Element): string { const indices: number[] = []; let current: Element | null = element; while (current && current.parentElement) { const parent: Element = current.parentElement; if (parent.tagName === 'hud') break; const index = Array.from(parent.children).indexOf(current); indices.unshift(index); current = parent; } return indices.join('/');}
export function resolveElementPath(doc: Document, path: string): Element | null { const hud = doc.querySelector('hud'); if (!hud) return null; const indices = path.split('/').map(Number); let current: Element = hud; for (const idx of indices) { const child = current.children[idx]; if (!child) return null; current = child; } return current;}