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)
| Target | Type |
|---|---|
| injectStyles | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| resolveTarget | uses |
| applyEffect | calls |