import React from 'react'; export interface LayoutRendererComponentProps { slots: Partial>; refs: Record void>; width: number; height: number; } export type LayoutRendererComponent = React.ComponentType>; // Fluent API for defining and rendering layout export class LayoutBuilder { private layout: Partial> = {}; constructor( private renderer: LayoutRendererComponent, private refsMap: Record void>, private width: number, private height: number ) {} getLayout() { return this.layout; } addSlot(id: T, node: React.ReactNode) { this.layout[id] = node; return this; } clearSlot(id: T) { if (this.layout[id] && this.refsMap[id]) { delete this.layout[id]; this.refsMap[id](null); } return this; } render() { if (!this.layout) { return null; } return React.createElement(this.renderer, { slots: this.layout, refs: this.refsMap, width: this.width, height: this.height, }); } }