import { parseLine as f, createLineData as s } from "./parser.js"; function c(a, u = " ") { let n = s(null, u); const t = { ended: !1, clone() { return c(a.clone(), u); }, async next() { if (n.line = await a.next(), n.line === null) return !0; f(n); }, current() { return t; }, line() { var e; return (e = n.line) == null ? void 0 : e.slice(n.offsetHead); }, head() { var e; return (e = n.line) == null ? void 0 : e.slice(n.offsetHead, n.offsetTail); }, tail() { var e; return (e = n.line) == null ? void 0 : e.slice(n.offsetTail); }, level() { return n.level; }, async content(e = -1, r = []) { var l; return e === -1 && (e = n.level + 1), await t.next() || n.level < e ? r : (r.push(((l = n.line) == null ? void 0 : l.slice(e)) || ""), t.content(e, r)); }, match(e) { return e === t.head(); }, async each(e) { const r = t.line() !== void 0 ? t.level() : -1; for (; !(await t.next() || t.level() <= r || await e()); ) ; }, async buildObject(e = [], r) { r || (r = () => t.tail().trim()); const i = {}; return await t.each(async () => { if (!!t.head()) { if (!e.length || e.includes(t.head())) { i[t.head()] = await r(); return; } if (e && !e.includes(t.head()) && e.includes("#text")) { i["#text"] = [t.line(), ...await t.content(t.level())]; return; } } }), i; }, async seek(e, r = -1) { return r === -1 && (r = n.level), await t.next() ? !1 : t.head() === e ? t : n.level < r ? !1 : t.seek(e, r); } }; return t; } export { c as useDocument };