All files / text / mod.ts

100.00% Branches 4/4
100.00% Lines 13/13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
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 = {
  name: "*text",
  phase: Phase.CONTENT,
  default: "this.innerHTML",
  async execute(renderer, element, { attributes: [attribute], ...options }) {
    if (!renderer.isHtmlElement(element)) {
      return
    }
    element.textContent = `${await renderer.evaluate(element, attribute.value || this.default, options)}`
  },
} as Directive & { default: NonNullable<Directive["default"]> }

/** Default exports. */
export default _text