applyPinEffect function exported

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

Metrics

LOC: 48 Complexity: 6 Params: 3

Signature

applyPinEffect( target: Element | null, config: PinEffect, ): : Promise<void>

Summary

Places a pin marker on the target and removes it after duration ms.

Source Code

export function applyPinEffect(
  target: Element | null,
  config: PinEffect,
): Promise<void> {
  return new Promise((resolve) => {
    if (!target) {
      resolve();
      return;
    }

    injectStyles();

    const duration = config.duration ?? 2000;
    const note = config.note;

    const rect = target.getBoundingClientRect();

    const pin = document.createElement("div");
    pin.className = PIN_CLASS;
    pin.style.top = `${rect.top - 7}px`;
    pin.style.left = `${rect.left + rect.width / 2 - 7}px`;

    const dot = document.createElement("div");
    dot.className = `${PIN_CLASS}__dot`;
    pin.appendChild(dot);

    if (note) {
      const noteEl = document.createElement("div");
      noteEl.className = `${PIN_CLASS}__note`;
      noteEl.textContent = note;
      pin.appendChild(noteEl);
    }

    document.body.appendChild(pin);

    const cleanup = () => {
      pin.remove();
      resolve();
    };

    if (duration > 0) {
      setTimeout(cleanup, duration);
    } else {
      // Keep until resolved externally (caller controls)
      resolve();
    }
  });
}

Dependencies (Outgoing)

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

Impact (Incoming)

graph LR applyPinEffect["applyPinEffect"] resolveTarget["resolveTarget"] applyEffect["applyEffect"] resolveTarget -->|uses| applyPinEffect applyEffect -->|calls| applyPinEffect style applyPinEffect fill:#dbeafe,stroke:#2563eb,stroke-width:2px click applyPinEffect "fad09edaf87b170e.html" click resolveTarget "cefe589bdbdd3b3b.html" click applyEffect "baf0d9f2a6803bb4.html"
SourceType
resolveTarget uses
applyEffect calls