match.astro 739 Bytes
---
import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import Node from './node.astro'

const { props: { parent = null, node, index = 0, debug = 0, replacers, slotHandler } } = Astro
const { name: Name, attributes } = node

if (debug) {
  console.log('trying to match against', {node})
}
let slotName
for (const [ matcher, handler ] of replacers) {
  if (debug) console.log('attempting matcher', matcher.toString())
  if (matcher(node, parent, index, false)) {
    if (debug) console.log('matched')
    slotName = handler
  }
}

const nextDebug = debug ? debug - 1 : 0
---
{
  slotName ? slotHandler(slotName, node)
  : <Node parent={parent} node={node} index={index} debug={nextDebug} replacers={replacers} slotHandler={slotHandler}/>
}