showCaption function exported

Last updated: 2026-03-05T10:53:28.860Z

Metrics

LOC: 36 Complexity: 4 Params: 1

Signature

showCaption(config: CaptionConfig): : Promise<void>

Summary

Displays a caption overlay and resolves after the caption is dismissed.

Source Code

export function showCaption(config: CaptionConfig): Promise<void> {
  return new Promise((resolve) => {
    if (!config.text?.trim()) {
      resolve();
      return;
    }

    injectStyles();

    // Remove any existing caption
    document.getElementById(CAPTION_ID)?.remove();

    const position = config.position ?? "bottom";
    const duration = config.duration ?? 3000;

    const el = document.createElement("div");
    el.id = CAPTION_ID;
    el.setAttribute("data-position", position);
    el.textContent = config.text;
    document.body.appendChild(el);

    requestAnimationFrame(() => {
      requestAnimationFrame(() => el.classList.add("visible"));
    });

    log.debug("Caption shown:", config.text);

    setTimeout(() => {
      el.classList.remove("visible");
      setTimeout(() => {
        el.remove();
        resolve();
      }, 300);
    }, duration);
  });
}

Dependencies (Outgoing)

graph LR showCaption["showCaption"] injectStyles["injectStyles"] showCaption -->|calls| injectStyles style showCaption fill:#dbeafe,stroke:#2563eb,stroke-width:2px click showCaption "bc25f610ecfb5828.html" click injectStyles "e97e8d96c98fbc38.html"
TargetType
injectStyles calls

Impact (Incoming)

graph LR showCaption["showCaption"] executeStep["executeStep"] executeStep -->|uses| showCaption style showCaption fill:#dbeafe,stroke:#2563eb,stroke-width:2px click showCaption "bc25f610ecfb5828.html" click executeStep "a26ccfb820921de2.html"
SourceType
executeStep uses