Current section
Files
Jump to
Current section
Files
src/off_topic/internal/utils_ffi.mjs
import { List$NonEmpty$first, List$NonEmpty$rest } from "../../gleam.mjs";
export function iterate(list, callback) {
if (Array.isArray(list)) {
for (let i = 0; i < list.length; i++) {
callback(list[i]);
}
} else if (list) {
for (list; List$NonEmpty$rest(list); list = List$NonEmpty$rest(list)) {
callback(List$NonEmpty$first(list));
}
}
}
export function resolveElement(target, root) {
if (target instanceof EventTarget) return target;
if (target === "root" || target === ":scope") return root;
if (target === "host") return root?.host;
if (target === "document") return document;
if (target === "window") return window;
if (!root) root = document;
return root instanceof Element && root.matches(target)
? root
: root.querySelector(target);
}