UNPKG

@react-form-builder/core

Version:

React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required

157 lines (154 loc) 3.67 kB
const A = (t = "st-") => t + Math.random().toString(36).slice(2); function D(t, c) { const e = Object.entries(t).filter(([i, s]) => typeof s < "u").map(([i, s]) => `${i.replace(/[A-Z]/g, (l) => `-${l.toLowerCase()}`)}: ${s};`).join(` `); return c ? `${c} { ${e} }` : e; } const y = ":root"; function v(t) { return t.replace(/\/\*[\s\S]*?\*\//g, "").trim(); } function B(t) { let o = t.split(/;\s*/).map((e) => e.trim()).filter((e) => e.includes(":")).join(`; `); return o.length > 1 && !o.endsWith(";") && (o += `; `), o; } function g(t, c, o = 0) { let e = null; for (let i = o; i < t.length; i++) { const s = t[i]; if (e) { s === e && t[i - 1] !== "\\" && (e = null); continue; } if (s === '"' || s === "'") { e = s; continue; } if (s === c) return i; } return -1; } function p(t, c) { let o = 1, e = c + 1, i = null; for (; o > 0 && e < t.length; ) { const s = t[e]; i ? s === i && t[e - 1] !== "\\" && (i = null) : s === '"' || s === "'" ? i = s : s === "{" ? o++ : s === "}" && o--, e++; } return e; } function N(t) { const c = []; let o = "", e = 0; const i = t.length; for (; e < i; ) { for (; e < i && /\s/.test(t[e]); ) o += t[e], e++; if (e >= i) break; const s = e; let n = null; for (; e < i; ) { const f = t[e]; if (n) { f === n && t[e - 1] !== "\\" && (n = null), e++; continue; } if (f === '"' || f === "'") { n = f, e++; continue; } if (f === "{" || f === ";" || f === "}") break; e++; } if (e >= i) { o += t.slice(s, i); break; } const l = t[e]; if (l === ";") { o += t.slice(s, e + 1), e++; continue; } if (l === "{") { const f = p(t, e); c.push(t.slice(s, f)), e = f; continue; } e++; } return { declarationText: o, nestedBlocks: c }; } function K(t) { t = v(t); const c = []; /^[^{]+{/.test(t) || (t = `${y} { ${t} }`); function e(n, l = [], f = null) { if (g(n, "{") === -1) { const h = B(n); h && c.push({ selectors: l.length ? l : [y], declarations: h, media: f }); return; } let r = 0; const C = n.length; for (; r < C; ) { if (/\s/.test(n[r])) { r++; continue; } if (n[r] === "@" && n[r + 1] && n.slice(r).match(/^@[\w-]+/)) { const u = r; if (r = g(n, "{", r), r === -1) break; const a = n.slice(u, r).trim(), w = p(n, r), M = n.slice(r + 1, w - 1); e(M, l, a), r = w; continue; } const h = r, d = g(n, "{", h); if (d === -1) break; const T = n.slice(h, d).trim(); r = d + 1; const m = p(n, r - 1), L = n.slice(r, m - 1).trim(); r = m; const $ = T.split(",").map((u) => u.trim()).filter(Boolean).flatMap((u) => l.length ? l.map((a) => u.includes("&") ? u.replace(/&&/g, `${a}${a}`).replace(/&/g, a) : `${a} ${u}`) : [u]), { declarationText: I, nestedBlocks: S } = N(L), j = B(I); j && c.push({ selectors: $, declarations: j, media: f }), S.length > 0 && e(S.join(` `), $, f); } } e(t); const i = {}; for (const n of c) { const l = n.media ?? "root"; i[l] ||= [], i[l].push(n); } let s = ""; for (const n in i) { n !== "root" && (s += `${n} { `); for (const l of i[n]) s += `${l.selectors.join(", ")} { ${l.declarations} } `; n !== "root" && (s += `} `); } return s.trim(); } export { K as flattenNestedCSS, A as generateClass, D as reactStylesToCss }; //# sourceMappingURL=css.js.map