Terrace/packages/js/core/dist/document.js
2023-02-05 07:44:11 -05:00

29 lines
631 B
JavaScript

import { parseLine as r, createLineData as u } from "./parser.js";
function h(s, f = " ") {
const e = u("", f);
let n = !1;
async function c(t = -1) {
if (n)
n = !1;
else {
const i = await s();
if (i == null)
return !1;
e.line = i, r(e);
}
return l() <= t ? (n = !0, !1) : !0;
}
const l = () => e.level, o = (t = e.offsetHead) => e.line.slice(t), a = () => e.line.slice(e.offsetHead, e.offsetTail);
return {
next: c,
level: l,
line: o,
head: a,
tail: () => e.line.slice(e.offsetTail),
match: (t) => t === a()
};
}
export {
h as useDocument
};