import React , { ReactChildren , ReactElement } from 'react' ; import PropTypes from 'prop-types' ; import { DrawCommand , DrawConfig , DefaultContext , DynamicVariable } from 'regl' ; import defregl , { DeferredRegl } from 'deferred-regl' ; type MergeLeft < T1 , T2 extends Record < any , any > > = { [ Prop in keyof T1 as Exclude < Prop , keyof T2 > ] : T1 [ Prop ] ; } ; type Merge < T1 , T2 > = MergeLeft < T1 , T2 > & T2 ; const globalDeferredRegl = defregl ( ) ; export interface ReactReglComponent < DefinitionProps > extends DrawCommand { < ExecutionProps extends { } = { } > ( executionProps , contextOrRef ) : React . ReactElement < DefinitionProps & ExecutionProps & DeferredRegl , 'ReglDraw' > | null ; } type ReactRegl < Props extends { } = { } > = Merge < DeferredRegl , { ( drawConfig ? ) : ReactReglComponent < Props > ; prop < Key > ( name ) : DynamicVariable < Key > ; } > ; const reactRegl = function ( definitionProps ) { let drawCommand = null ; const ReactReglComponent = ( executionProps ? , contextOrRef ? ) => { if ( executionProps && contextOrRef ?. reactify === true ) { const merged = { definitionProps , executionProps } ; const children = executionProps . children ? executionProps . children : null ; return React . createElement ( 'ReglDraw' , merged , children ) ; } if ( drawCommand === null ) { drawCommand = globalDeferredRegl ( definitionProps ) ; } if ( drawCommand === null ) { throw new Error ( 'failed to initalize regl drawCommand' ) ; } let drawCommandProps = executionProps ? executionProps : { } ; return drawCommand ( drawCommandProps , contextOrRef ) ; } ; ReactReglComponent . contextTypes = { reactify : PropTypes . bool } ; return ReactReglComponent ; } ; Object . setPrototypeOf ( reactRegl , globalDeferredRegl ) ; export default reactRegl as ReactRegl ;