import { api } from './index.js' ; type Value = Node | string | number ; type Frag = { _startMark : Text ; } ; type FragReturn = Frag | Node | undefined ; const asNode = ( value ) : Text | Node | DocumentFragment => { if ( typeof value === 'string' ) { return document . createTextNode ( value ) ; } if ( ! ( value instanceof Node ) ) { return api . h ( [ ] , value ) as DocumentFragment ; } return value ; } ; const maybeFragOrNode = ( value ) : FragReturn => { const { childNodes } = value ; if ( value . nodeType != 11 ) return ; if ( childNodes . length < 2 ) return childNodes [ 0 ] ; return { _startMark : api . add ( value , '' , childNodes [ 0 ] ) as Text } ; } ; /** Add a node before a reference node or at the end. */ const add = ( parent , value , endMark ? ) => { value = asNode ( value ) ; const fragOrNode = maybeFragOrNode ( value ) || value ; parent . insertBefore ( value , ( endMark && endMark . parentNode && endMark ) as Node | null ) ; return fragOrNode ; } ; export { add } ;