import type { ReactNode, Ref } from "react"; import type { BurokkuElement, BurokkuEventMap, BurokkuStyle, BurokkuTagName, } from "@burokku/runtime"; /** Each event handler prop and the type of the event it handles. */ interface EventHandlerTypes { onClick: "click"; onKeyDown: "keydown"; onKeyUp: "keyup"; onPointerDown: "pointerdown"; onPointerUp: "pointerup"; onPointerMove: "pointermove"; onPointerEnter: "pointerenter"; onPointerLeave: "pointerleave"; onPointerCancel: "pointercancel"; onGotPointerCapture: "gotpointercapture"; onLostPointerCapture: "lostpointercapture"; onWheel: "wheel"; onScroll: "scroll"; onFocus: "focus"; onBlur: "blur"; onFocusIn: "focusin"; onFocusOut: "focusout"; onBeforeInput: "beforeinput"; onInput: "input"; onCompositionStart: "compositionstart"; onCompositionUpdate: "compositionupdate"; onCompositionEnd: "compositionend"; } /** * Handlers for the events every element dispatches. Each handles the event of * its name after `on` in lower case, so `onFocus` does not bubble. */ export type BurokkuEventHandlers = { [Prop in keyof EventHandlerTypes]?: (event: BurokkuEventMap[EventHandlerTypes[Prop]]) => void; }; /** * A tag's styles in JSX, where a key set to `null` is removed as one set to * `undefined` is. A key the tag does not support takes neither. */ export type BurokkuStyleProp = { readonly [Key in keyof BurokkuStyle]?: [ Exclude[Key], undefined>, ] extends [never] ? never : BurokkuStyle[Key] | null; }; /** Props every Burokku element takes in JSX; `null` removes an attribute. */ export interface BurokkuElementProps extends BurokkuEventHandlers { children?: ReactNode; ref?: Ref>; style?: BurokkuStyleProp; /** An integer makes the element focusable, in the tab order unless negative. */ tabindex?: number | null; } /** A window's props: its title and opening size are attributes. */ export interface BurokkuWindowProps extends BurokkuElementProps<"window"> { title?: string | null; /** The width in logical pixels the window opens at; later changes do not resize it. */ width?: number | null; /** The height in logical pixels the window opens at; later changes do not resize it. */ height?: number | null; /** Fires when the user asks to close the window; see `BurokkuEventMap`. */ onClose?: (event: BurokkuEventMap["close"]) => void; } /** The props of each Burokku tag in JSX. */ export interface BurokkuIntrinsicElements { div: BurokkuElementProps<"div">; flex: BurokkuElementProps<"flex">; grid: BurokkuElementProps<"grid">; /** Its value is its text, bare or in styled `text` runs. */ input: BurokkuElementProps<"input">; text: BurokkuElementProps<"text">; window: BurokkuWindowProps; }