All files / text / mod.ts

100.00% Branches 4/4
100.00% Lines 14/14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
x8
 
 
 
x8
 
x8
x8
x8
x8
x8
x13
x14
x14
x13
x13
x8
 
 
x8


















// Imports
import { type Directive, Phase } from "@mizu/internal/engine"
export type * from "@mizu/internal/engine"

/** `*text` directive. */
export const _text: Directive<{
  Default: true
}> = {
  name: "*text",
  phase: Phase.CONTENT,
  default: "this.innerHTML",
  async execute(this: typeof _text, renderer, element, { attributes: [attribute], ...options }) {
    if (!renderer.isHtmlElement(element)) {
      return
    }
    element.textContent = `${await renderer.evaluate(element, attribute.value || this.default, options)}`
  },
}

/** Default exports. */
export default _text