Terrace/packages/js/core/dist/document.js
2022-11-12 21:30:22 -05:00

43 lines
1.1 KiB
JavaScript

import { parseLine as f, createLineData as s } from "./parser.js";
function d(t, l = " ") {
let n = s(null, l);
const i = {
ended: !1,
clone() {
return d(t.clone(), l);
},
async next() {
if (n.line = await t.next(), n.line === null)
return !0;
f(n);
},
current() {
return i;
},
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);
},
async content(e = -1, r = []) {
var u;
return e === -1 && (e = n.level + 1), await i.next() || n.level < e ? r.join(`
`) : (r.push(((u = n.line) == null ? void 0 : u.slice(e)) || ""), i.content(e, r));
},
async seek(e, r = -1) {
return r === -1 && (r = n.level), await i.next() ? !1 : i.head() === e ? i : n.level < r ? !1 : i.seek(e, r);
}
};
return i;
}
export {
d as useDocument
};