UNPKG

typing-flow

Version:

Npm package for typing animation for web

55 lines (54 loc) 1.34 kB
import { g as r } from "./browser-oWv6Ioy8.js"; const o = (a) => /^\s+$/.test(a), y = new DOMParser(), c = (a, e = {}) => { const n = [], l = (t) => { if (t.nodeType === Node.TEXT_NODE) { const s = t.textContent.split("").map((i) => ({ type: "text", nodeBuilder: () => ({ text: i, delay: e.instant ? 0 : e.delay, instant: e.instant ?? !1, isTag: !1 }) })); n.push(...s); } else if (t.nodeType === Node.ELEMENT_NODE) { const s = r(t); t.tagName.toLowerCase() !== "body" && n.push({ type: "text", nodeBuilder: () => ({ text: s.open, delay: 0, instant: !0, isTag: !0 }) }); for (const i of t.childNodes) l(i); t.tagName.toLowerCase() !== "body" && n.push({ type: "text", nodeBuilder: () => ({ text: s.close, delay: 0, instant: !0, isTag: !0 }) }); } }; if (o(a)) return a.split("").map((t) => ({ type: "text", nodeBuilder: () => ({ text: t, delay: e.instant ? 0 : e.delay, instant: e.instant ?? !1, isTag: !1 }) })); const d = y.parseFromString(a, "text/html").body; return l(d), n; }; export { c as t };