UNPKG

@skirtle/vue-vnode-utils

Version:
147 lines (146 loc) 3.82 kB
import { isVNode as y, Text as h, Fragment as T, Comment as b, Static as F, cloneVNode as g, createTextVNode as L, createCommentVNode as O } from "vue"; const j = (t) => c(t) === "comment", A = (t) => c(t) === "component", D = (t) => c(t) === "element", d = (t) => c(t) === "fragment", z = (t) => A(t) && typeof t.type == "function", B = (t) => A(t) && typeof t.type == "object", H = (t) => c(t) === "static", _ = (t) => c(t) === "text", x = (t) => { if (typeof t == "string") return t; if (typeof t == "number") return String(t); if (y(t) && t.type === h) return String(t.children); }, c = (t) => { const n = typeof t; if (t == null || n === "boolean") return "comment"; if (n === "string" || n === "number") return "text"; if (Array.isArray(t)) return "fragment"; if (y(t)) { const { type: r } = t, e = typeof r; if (e === "symbol") { if (r === T) return "fragment"; if (r === h) return "text"; if (r === b) return "comment"; if (r === F) return "static"; } else { if (e === "string") return "element"; if (e === "object" || e === "function") return "component"; } } }, I = (t) => { for (const n in t) return !1; return !0; }, S = (t) => { if (Array.isArray(t)) return t; const { children: n } = t; return Array.isArray(n) ? n : []; }; const E = { element: !0, component: !0 }, C = { element: !0, component: !0, text: !0, static: !0 }, m = { element: !0, component: !0, text: !0, static: !0, comment: !0 }, N = (t, n) => { const r = c(t); return !r || r === "fragment" || !n[r] ? null : y(t) ? t : r === "text" ? L(x(t)) : O(); }, K = (t, n, r = E) => a(t, (e) => { const s = n(e); if (s && !I(s)) return g(e, s, !0); }, r), R = (t, n, r = C) => a(t, n, r), a = (t, n, r) => { var s; let e = null; for (let o = 0; o < t.length; ++o) { const u = t[o]; if (d(u)) { const l = S(u), i = a(l, n, r); let p = u; l !== i && (e != null || (e = t.slice(0, o)), Array.isArray(u) ? p = i : (p = g(u), p.children = i)), e && e.push(p); } else { const l = N(u, r); if (l) { const i = (s = n(l)) != null ? s : l; i !== u && (e != null || (e = t.slice(0, o))), Array.isArray(i) ? e && e.push(...i) : e && e.push(i); } else e && e.push(u); } } return e != null ? e : t; }, W = (t, n, r = C) => { let e = null; return a(t, (s) => { let o; if (e && (o = n(e, s)), e = s, !(o == null || Array.isArray(o) && o.length === 0)) return Array.isArray(o) ? [...o, s] : [o, s]; }, r); }, P = (t, n, r = m) => f(t, n, r), f = (t, n, r) => { for (const e of t) if (d(e)) { if (P(S(e), n, r)) return !0; } else { const s = N(e, r); if (s && n(s)) return !0; } return !1; }, q = (t, n, r = m) => !f(t, (e) => !n(e), r), G = (t, n, r = m) => { f(t, (e) => { n(e); }, r); }, w = (t, n, r = m) => { let e; return f(t, (s) => { if (n(s)) return e = s, !0; }, r), e; }, J = (t, n, r, e = m) => (f(t, (s) => { r = n(r, s); }, e), r), M = /\S|\u00a0/, Q = (t) => !f(t, (n) => { if (_(n)) { const r = x(n) || ""; return M.test(r); } return !0; }, C), U = (t) => w(t, () => !0, E); export { m as ALL_VNODES, E as COMPONENTS_AND_ELEMENTS, C as SKIP_COMMENTS, K as addProps, W as betweenChildren, G as eachChild, q as everyChild, U as extractSingleChild, w as findChild, x as getText, c as getType, j as isComment, A as isComponent, D as isElement, Q as isEmpty, d as isFragment, z as isFunctionalComponent, B as isStatefulComponent, H as isStatic, _ as isText, J as reduceChildren, R as replaceChildren, P as someChild };