More API cleanup in preparation for a DSL.
This commit is contained in:
2
packages/js/core/dist/document.cjs
vendored
2
packages/js/core/dist/document.cjs
vendored
@@ -1 +1 @@
|
||||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("./parser.cjs");function T(p,b=" "){let c=0;const t=h.createLineData("",b);async function s(){c===0&&(c=1);const e=await p.next();return e===null?(c=2,!0):(t.line=e,h.parseLine(t),!1)}const a=()=>t.level,u=()=>t.line.slice(t.offsetHead),o=()=>t.line.slice(t.offsetHead,t.offsetTail),f=()=>t.line.slice(t.offsetTail),v=e=>e===o();async function d(e){const n=c===0?-1:a();for(;!(await s()||a()<=n||await e()););}async function l(e=-1,n=[u()]){var i;return e===-1&&(e=t.level+1),await s()||t.level<e?n:(n.push(((i=t.line)==null?void 0:i.slice(e))||""),l(e,n))}async function w(e=[],n){const r={};return await d(async()=>{const i=o();if(!!i){if(!e.length||e.includes(i)){r[i]=n?await n():f().trim();return}if(e&&!e.includes(i)&&e.includes("#text")){r["#text"]=await l(a());return}}}),r}async function m(){const e=[["root",[]]];for(;!await s();){const n=a(),r=n+1,i=e[n];if(!i)continue;e.length=r;const x=e[r]=[u(),[]];i[1].push(x)}return e[0]}return{state:c,next:s,line:u,head:o,tail:f,level:a,match:v,each:d,blockAsText:l,buildObject:w,toArrays:m}}exports.useDocument=T;
|
||||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("./parser.cjs");function D(v,b=" "){let a=0;const n=d.createLineData("",b);async function u(){switch(a){case 0:a=1;break;case 2:return a=1,!1}const e=await v.next();return e===null?(a=3,!0):(n.line=e,d.parseLine(n),!1)}const y=()=>a=2,r=()=>n.level,s=()=>n.line.slice(n.offsetHead),c=()=>n.line.slice(n.offsetHead,n.offsetTail),l=()=>n.line.slice(n.offsetTail),j=e=>e===c();async function w(e){const t=a===0?-1:r();for(;;){if(await u())return;if(r()<=t)return y();if(await e())return}}async function f(e=-1,t=[s()]){var i;return e===-1&&(e=r()+1),await u()?t:r()<e?(y(),t):(t.push(((i=n.line)==null?void 0:i.slice(e))||""),f(e,t))}async function x(e){const t={};return await w(async()=>{const i=c();if(!i)return;const o=e?e[i]||e["#any"]:null;if(e?o===!0?t[i]=l().trim():o?t[i]=await o():e!=null&&e["#text"]&&(t["#text"]=await f(r())):t[i]=l().trim(),e&&Object.keys(e).every(p=>t[p]!==void 0))return!0}),t}async function T(){const e=[["root",[]]];for(;!await u();){const t=r(),i=t+1,o=e[t];if(!o)continue;e.length=i;const p=e[i]=[s(),[]];o[1].push(p)}return e[0]}return{next:u,line:s,head:c,tail:l,level:r,match:j,each:w,blockAsText:f,toObject:x,toLineArray:T}}exports.useDocument=D;
|
||||
|
||||
102
packages/js/core/dist/document.js
vendored
102
packages/js/core/dist/document.js
vendored
@@ -1,64 +1,70 @@
|
||||
import { parseLine as v, createLineData as T } from "./parser.js";
|
||||
function y(h, p = " ") {
|
||||
let r = 0;
|
||||
const t = T("", p);
|
||||
async function s() {
|
||||
r === 0 && (r = 1);
|
||||
const e = await h.next();
|
||||
return e === null ? (r = 2, !0) : (t.line = e, v(t), !1);
|
||||
import { parseLine as j, createLineData as D } from "./parser.js";
|
||||
function k(x, d = " ") {
|
||||
let o = 0;
|
||||
const n = D("", d);
|
||||
async function c() {
|
||||
switch (o) {
|
||||
case 0:
|
||||
o = 1;
|
||||
break;
|
||||
case 2:
|
||||
return o = 1, !1;
|
||||
}
|
||||
const e = await x.next();
|
||||
return e === null ? (o = 3, !0) : (n.line = e, j(n), !1);
|
||||
}
|
||||
const a = () => t.level, o = () => t.line.slice(t.offsetHead), u = () => t.line.slice(t.offsetHead, t.offsetTail), l = () => t.line.slice(t.offsetTail), w = (e) => e === u();
|
||||
async function d(e) {
|
||||
const n = r === 0 ? -1 : a();
|
||||
for (; !(await s() || a() <= n || await e()); )
|
||||
;
|
||||
const w = () => o = 2, r = () => n.level, u = () => n.line.slice(n.offsetHead), s = () => n.line.slice(n.offsetHead, n.offsetTail), f = () => n.line.slice(n.offsetTail), v = (e) => e === s();
|
||||
async function y(e) {
|
||||
const t = o === 0 ? -1 : r();
|
||||
for (; ; ) {
|
||||
if (await c())
|
||||
return;
|
||||
if (r() <= t)
|
||||
return w();
|
||||
if (await e())
|
||||
return;
|
||||
}
|
||||
}
|
||||
async function f(e = -1, n = [o()]) {
|
||||
async function l(e = -1, t = [u()]) {
|
||||
var i;
|
||||
return e === -1 && (e = t.level + 1), await s() || t.level < e ? n : (n.push(((i = t.line) == null ? void 0 : i.slice(e)) || ""), f(e, n));
|
||||
return e === -1 && (e = r() + 1), await c() ? t : r() < e ? (w(), t) : (t.push(((i = n.line) == null ? void 0 : i.slice(e)) || ""), l(e, t));
|
||||
}
|
||||
async function x(e = [], n) {
|
||||
const c = {};
|
||||
return await d(async () => {
|
||||
const i = u();
|
||||
if (!!i) {
|
||||
if (!e.length || e.includes(i)) {
|
||||
c[i] = n ? await n() : l().trim();
|
||||
return;
|
||||
}
|
||||
if (e && !e.includes(i) && e.includes("#text")) {
|
||||
c["#text"] = await f(a());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}), c;
|
||||
async function T(e) {
|
||||
const t = {};
|
||||
return await y(async () => {
|
||||
const i = s();
|
||||
if (!i)
|
||||
return;
|
||||
const a = e ? e[i] || e["#any"] : null;
|
||||
if (e ? a === !0 ? t[i] = f().trim() : a ? t[i] = await a() : e != null && e["#text"] && (t["#text"] = await l(r())) : t[i] = f().trim(), e && Object.keys(e).every((p) => t[p] !== void 0))
|
||||
return !0;
|
||||
}), t;
|
||||
}
|
||||
async function b() {
|
||||
const e = [["root", []]];
|
||||
for (; !await s(); ) {
|
||||
const n = a(), c = n + 1, i = e[n];
|
||||
if (!i)
|
||||
for (; !await c(); ) {
|
||||
const t = r(), i = t + 1, a = e[t];
|
||||
if (!a)
|
||||
continue;
|
||||
e.length = c;
|
||||
const m = e[c] = [o(), []];
|
||||
i[1].push(m);
|
||||
e.length = i;
|
||||
const p = e[i] = [u(), []];
|
||||
a[1].push(p);
|
||||
}
|
||||
return e[0];
|
||||
}
|
||||
return {
|
||||
state: r,
|
||||
next: s,
|
||||
line: o,
|
||||
head: u,
|
||||
tail: l,
|
||||
level: a,
|
||||
match: w,
|
||||
each: d,
|
||||
blockAsText: f,
|
||||
buildObject: x,
|
||||
toArrays: b
|
||||
next: c,
|
||||
line: u,
|
||||
head: s,
|
||||
tail: f,
|
||||
level: r,
|
||||
match: v,
|
||||
each: y,
|
||||
blockAsText: l,
|
||||
toObject: T,
|
||||
toLineArray: b
|
||||
};
|
||||
}
|
||||
export {
|
||||
y as useDocument
|
||||
k as useDocument
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user