@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
272 lines (271 loc) • 6.76 kB
JavaScript
import { isString as M } from "../../utils/isString.js";
import { isObject as Q } from "../../utils/tools.js";
const O = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
function $(r, f) {
const p = r && M(r.type), a = p ? r : f;
for (const y in r) {
const c = r[y];
Array.isArray(c) ? c.forEach(function(w) {
$(w, a);
}) : c && Q(c) && $(c, a);
}
return p && Object.defineProperty(r, "parent", {
configurable: !0,
writable: !0,
enumerable: !1,
value: f || null
}), r;
}
function m(r) {
return r ? r.replace(/^\s+|\s+$/g, "") : "";
}
function V(r, f) {
f = f || {};
let p = 1, a = 1;
function y(e) {
const t = e.match(/\n/g);
t && (p += t.length);
const n = e.lastIndexOf(`
`);
a = ~n ? e.length - n : a + e.length;
}
function c() {
const e = { line: p, column: a };
return function(t) {
return t.position = {
start: e,
end: { line: p, column: a },
source: f.source
}, E(), t;
};
}
const w = [];
function s(e) {
const t = new Error(`${f.source}:${p}:${a}: ${e}`);
if (t.reason = e, t.filename = f.source, t.line = p, t.column = a, t.source = r, f.silent)
w.push(t);
else
throw t;
}
function z() {
const e = g();
return {
type: "stylesheet",
stylesheet: {
source: f.source,
rules: e,
parsingErrors: w
}
};
}
function d() {
return o(/^{\s*/);
}
function h() {
return o(/^}/);
}
function g() {
let e;
const t = [];
for (E(), u(t); r.length && r.charAt(0) != "}" && (e = J() || K()); )
e !== !1 && (t.push(e), u(t));
return t;
}
function o(e) {
const t = e.exec(r);
if (!t) return;
const n = t[0];
return y(n), r = r.slice(n.length), t;
}
function E() {
o(/^\s*/);
}
function u(e) {
let t;
for (e = e || []; t = L(); )
t !== !1 && e.push(t);
return e;
}
function L() {
const e = c();
if (r.charAt(0) != "/" || r.charAt(1) != "*") return;
let t = 2;
for (; r.charAt(t) != "" && (r.charAt(t) != "*" || r.charAt(t + 1) != "/"); ) ++t;
if (t += 2, r.charAt(t - 1) === "")
return s("End of comment missing");
const n = r.slice(2, t - 2);
return a += 2, y(n), r = r.slice(t), a += 2, e({
type: "comment",
comment: n
});
}
function x() {
const e = o(/^([^{]+)/);
if (e)
return m(e[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, "").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(t) {
return t.replace(/,/g, "");
}).split(/\s*(?![^(]*\)),\s*/).map(function(t) {
return t.replace(/\u200C/g, ",");
});
}
function k() {
const e = c();
let t = o(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
if (!t) return;
if (t = m(t[0]), !o(/^:\s*/)) return s("property missing ':'");
const n = o(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/), i = e({
type: "declaration",
property: t.replace(O, ""),
value: n ? m(n[0]).replace(O, "") : ""
});
return o(/^[;\s]*/), i;
}
function P() {
const e = [];
if (!d()) return s("missing '{'");
u(e);
let t;
for (; t = k(); )
t !== !1 && (e.push(t), u(e));
return h() ? e : s("missing '}'");
}
function R() {
let e;
const t = [], n = c();
for (; e = o(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/); )
t.push(e[1]), o(/^,\s*/);
if (t.length)
return n({
type: "keyframe",
values: t,
declarations: P()
});
}
function _() {
const e = c();
let t = o(/^@([-\w]+)?keyframes\s*/);
if (!t) return;
const n = t[1];
if (t = o(/^([-\w]+)\s*/), !t) return s("@keyframes missing name");
const i = t[1];
if (!d()) return s("@keyframes missing '{'");
let l, v = u();
for (; l = R(); )
v.push(l), v = v.concat(u());
return h() ? e({
type: "keyframes",
name: i,
vendor: n,
keyframes: v
}) : s("@keyframes missing '}'");
}
function C() {
const e = c(), t = o(/^@supports *([^{]+)/);
if (!t) return;
const n = m(t[1]);
if (!d()) return s("@supports missing '{'");
const i = u().concat(g());
return h() ? e({
type: "supports",
supports: n,
rules: i
}) : s("@supports missing '}'");
}
function I() {
const e = c();
if (!o(/^@host\s*/)) return;
if (!d()) return s("@host missing '{'");
const n = u().concat(g());
return h() ? e({
type: "host",
rules: n
}) : s("@host missing '}'");
}
function N() {
const e = c(), t = o(/^@media *([^{]+)/);
if (!t) return;
const n = m(t[1]);
if (!d()) return s("@media missing '{'");
const i = u().concat(g());
return h() ? e({
type: "media",
media: n,
rules: i
}) : s("@media missing '}'");
}
function S() {
const e = c(), t = o(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
if (t)
return e({
type: "custom-media",
name: m(t[1]),
media: m(t[2])
});
}
function q() {
const e = c();
if (!o(/^@page */)) return;
const n = x() || [];
if (!d()) return s("@page missing '{'");
let i = u(), l;
for (; l = k(); )
i.push(l), i = i.concat(u());
return h() ? e({
type: "page",
selectors: n,
declarations: i
}) : s("@page missing '}'");
}
function B() {
const e = c(), t = o(/^@([-\w]+)?document *([^{]+)/);
if (!t) return;
const n = m(t[1]), i = m(t[2]);
if (!d()) return s("@document missing '{'");
const l = u().concat(g());
return h() ? e({
type: "document",
document: i,
vendor: n,
rules: l
}) : s("@document missing '}'");
}
function D() {
const e = c();
if (!o(/^@font-face\s*/)) return;
if (!d()) return s("@font-face missing '{'");
let n = u(), i;
for (; i = k(); )
n.push(i), n = n.concat(u());
return h() ? e({
type: "font-face",
declarations: n
}) : s("@font-face missing '}'");
}
const F = A("import"), G = A("charset"), H = A("namespace");
function A(e) {
const t = new RegExp(`^@${e}\\s*([^;]+);`);
return function() {
const n = c(), i = o(t);
if (!i) return;
const l = { type: e };
return l[e] = i[1].trim(), n(l);
};
}
function J() {
if (r[0] == "@")
return _() || N() || S() || C() || F() || G() || H() || B() || q() || I() || D();
}
function K() {
const e = c(), t = x();
return t ? (u(), e({
type: "rule",
selectors: t,
declarations: P()
})) : s("selector missing");
}
return $(z());
}
export {
V as parse
};
//# sourceMappingURL=parse.js.map