laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
97 lines (96 loc) • 2.53 kB
JavaScript
"use client";
const k = {
resolveAll: g()
}, m = x("string"), y = x("text");
function x(r) {
return {
resolveAll: g(r === "text" ? p : void 0),
tokenize: s
};
function s(t) {
const i = this, e = this.parser.constructs[r], n = t.attempt(e, a, f);
return a;
function a(l) {
return u(l) ? n(l) : f(l);
}
function f(l) {
if (l === null) {
t.consume(l);
return;
}
return t.enter("data"), t.consume(l), o;
}
function o(l) {
return u(l) ? (t.exit("data"), n(l)) : (t.consume(l), o);
}
function u(l) {
if (l === null)
return !0;
const c = e[l];
let d = -1;
if (c)
for (; ++d < c.length; ) {
const h = c[d];
if (!h.previous || h.previous.call(i, i.previous))
return !0;
}
return !1;
}
}
}
function g(r) {
return s;
function s(t, i) {
let e = -1, n;
for (; ++e <= t.length; )
n === void 0 ? t[e] && t[e][1].type === "data" && (n = e, e++) : (!t[e] || t[e][1].type !== "data") && (e !== n + 2 && (t[n][1].end = t[e - 1][1].end, t.splice(n + 2, e - n - 2), e = n + 2), n = void 0);
return r ? r(t, i) : t;
}
}
function p(r, s) {
let t = 0;
for (; ++t <= r.length; )
if ((t === r.length || r[t][1].type === "lineEnding") && r[t - 1][1].type === "data") {
const i = r[t - 1][1], e = s.sliceStream(i);
let n = e.length, a = -1, f = 0, o;
for (; n--; ) {
const u = e[n];
if (typeof u == "string") {
for (a = u.length; u.charCodeAt(a - 1) === 32; )
f++, a--;
if (a) break;
a = -1;
} else if (u === -2)
o = !0, f++;
else if (u !== -1) {
n++;
break;
}
}
if (s._contentTypeTextTrailing && t === r.length && (f = 0), f) {
const u = {
type: t === r.length || o || f < 2 ? "lineSuffix" : "hardBreakTrailing",
start: {
_bufferIndex: n ? a : i.start._bufferIndex + a,
_index: i.start._index + n,
line: i.end.line,
column: i.end.column - f,
offset: i.end.offset - f
},
end: {
...i.end
}
};
i.end = {
...u.start
}, i.start.offset === i.end.offset ? Object.assign(i, u) : (r.splice(t, 0, ["enter", u, s], ["exit", u, s]), t += 2);
}
t++;
}
return r;
}
export {
k as resolver,
m as string,
y as text
};