import { register , ComponentType as mComponentType , ICustomElement , FunctionComponent , ComponentOptions , PropsDefinitionInput } from "component-register" ; export { hot , getCurrentElement } from "component-register" ; export type ComponentType < T > = mComponentType < T > ; import { createRoot , createSignal } from "solid-js" ; import { insert } from "solid-js/web" ; function createProps < T > ( raw ) { const keys = Object . keys ( raw ) as ( keyof T ) [ ] ; const props = { } ; for ( let i = 0 ; i < keys . length ; i ++ ) { const [ get , set ] = createSignal ( raw [ keys [ i ] ] ) ; Object . defineProperty ( props , keys [ i ] , { get , set ( v ) { set ( ( ) => v ) ; } } ) ; } return props as T ; } function lookupContext ( el ) { if ( el . assignedSlot && el . assignedSlot . _$owner ) return el . assignedSlot . _$owner ; let next = el . parentNode ; while ( next && ! next . _$owner && ! ( next . assignedSlot && ( next . assignedSlot as Element & { _$owner ? : any ; } ) . _$owner ) ) next = next . parentNode as Element ; return next && next . assignedSlot ? ( next . assignedSlot as Element & { _$owner ? : any ; } ) . _$owner : el . _$owner ; } function withSolid < T > ( ComponentType ) { return ( rawProps , options ) => { const { element } = options as { element : ICustomElement & { _$owner ? : any ; } ; } ; return createRoot ( ( dispose ) => { const props = createProps < T > ( rawProps ) ; element . addPropertyChangedCallback ( ( key , val ) => ( props [ key as keyof T ] = val ) ) ; element . addReleaseCallback ( ( ) => { element . renderRoot . textContent = "" ; dispose ( ) ; } ) ; const comp = ( ComponentType as FunctionComponent < T > ) ( props as T , options ) ; return insert ( element . renderRoot , comp ) ; } , lookupContext ( element ) ) ; } ; } function customElement < T > ( tag , ComponentType ) ; function customElement < T > ( tag , props , ComponentType ) ; function customElement < T > ( tag , props , ComponentType ? ) { if ( arguments . length === 2 ) { ComponentType = props as ComponentType < T > ; props = { } as PropsDefinitionInput < T > ; } return register < T > ( tag , props as PropsDefinitionInput < T > ) ( withSolid ( ComponentType ! ) ) ; } export { withSolid , customElement } ;