i'm upping my prechoster game. really hitting the ball out of the park (playing fetch with myself)
<!--
an easy way to pull text, html or a key-value style interface out of a component's slot
<script>
let slot;
</script>
<p>slot text: {slot}</p>
<Slot bind:text={slot}><slot /></Slot>
-->
<script>
export let element = undefined;
export let text = undefined;
export let html = undefined;
export let children = {
child: function(selector) { return this.parent?.querySelector(selector); },
text: function(selector) { return this.child(selector)?.textContent; },
html: function(selector) { return this.child(selector)?.innerHTML; },
attr: function(selector, attributeName) { return this.child(selector)?.getAttribute(attributeName); }
};
let el;
$: if (el) {
[element, text, html] = [el, el.textContent, el.innerHTML];
children.parent = element;
el.remove();
}
</script>
<div bind:this={el}><slot /></div>syntax highlighting by codehost
