UNPKG

bruh

Version:

The thinnest possible layer between development and production for the modern web.

227 lines (226 loc) 7.1 kB
var q = Object.defineProperty; var D = (t, e, r) => e in t ? q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; var w = (t, e, r) => (D(t, typeof e != "symbol" ? e + "" : e, r), r), C = (t, e, r) => { if (!e.has(t)) throw TypeError("Cannot " + r); }; var n = (t, e, r) => (C(t, e, "read from private field"), r ? r.call(t) : e.get(t)), c = (t, e, r) => { if (e.has(t)) throw TypeError("Cannot add the same private member more than once"); e instanceof WeakSet ? e.add(t) : e.set(t, r); }, f = (t, e, r, o) => (C(t, e, "write to private field"), o ? o.call(t, r) : e.set(t, r), r); var M = (t, e, r) => (C(t, e, "access private method"), r); const d = Symbol.for("bruh reactive"); var _, h, b; class L { constructor(e) { w(this, _, !0); c(this, h, void 0); c(this, b, /* @__PURE__ */ new Set()); f(this, h, e); } get value() { return n(this, h); } set value(e) { if (e !== n(this, h)) { f(this, h, e); for (const r of n(this, b)) r(); } } addReaction(e) { return n(this, b).add(e), () => n(this, b).delete(e); } } _ = d, h = new WeakMap(), b = new WeakMap(); var F, p, v, A, y, T, u, g, N, E, P; const a = class { constructor(e, r) { c(this, E); w(this, F, !0); c(this, p, void 0); c(this, v, /* @__PURE__ */ new Set()); c(this, A, void 0); c(this, y, 0); c(this, T, /* @__PURE__ */ new Set()); if (!r) { f(this, p, e); return; } f(this, p, r()), f(this, A, r), f(this, y, Math.max(...e.map((o) => n(o, y))) + 1), e.forEach((o) => n(o, T).add(this)); } get value() { if (n(a, u).size) { if (n(this, y) !== 0) a.applyUpdates(); else if (n(a, u).has(this)) return n(a, u).get(this); } return n(this, p); } set value(e) { n(this, y) === 0 && (n(a, u).size || queueMicrotask(a.applyUpdates), n(a, u).set(this, e)); } addReaction(e) { return n(this, v).add(e), () => n(this, v).delete(e); } static applyUpdates() { var e, r, o; if (!!n(a, u).size) { for (const [s, i] of n(a, u).entries()) M(e = s, E, P).call(e, i); n(a, u).clear(); for (const s of n(a, g)) if (s) for (const i of s) M(o = i, E, P).call(o, n(r = i, A).call(r)); n(a, g).length = 0; for (const s of n(a, N)) s(); n(a, N).length = 0; } } }; let m = a; F = d, p = new WeakMap(), v = new WeakMap(), A = new WeakMap(), y = new WeakMap(), T = new WeakMap(), u = new WeakMap(), g = new WeakMap(), N = new WeakMap(), E = new WeakSet(), P = function(e) { if (e === n(this, p)) return; f(this, p, e), n(a, N).push(...n(this, v)); const r = n(a, g); for (const o of n(this, T)) { const s = n(o, y); r[s] || (r[s] = /* @__PURE__ */ new Set()), r[s].add(o); } }, c(m, u, /* @__PURE__ */ new Map()), c(m, g, []), c(m, N, []); const I = (t, e) => new m(t, e), j = (t, e) => { if (t != null && t[d]) return e(t.value), t.addReaction(() => e(t.value)); e(t); }, ee = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, isReactive: d, SimpleReactive: L, FunctionalReactive: m, r: I, reactiveDo: j }, Symbol.toStringTag, { value: "Module" })), J = (t) => (t == null ? void 0 : t[d]) || t instanceof Node || Array.isArray(t) || t == null || !(typeof t == "function" || typeof t == "object"), R = (t) => t instanceof Node ? t : typeof t == "boolean" || t === void 0 || t === null ? document.createComment(t) : document.createTextNode(t), O = (t) => { let e = R(t.value); const r = t.addReaction(() => { if (!e.parentNode) { r(); return; } if (Array.isArray(t.value)) r(), e.replaceWith(...W(t)); else { const o = e; e = R(t.value), o.replaceWith(e); } }); return e; }, W = (t) => { const e = document.createComment("["), r = document.createComment("]"), o = t.addReaction(() => { if (!e.parentNode) { o(); return; } const s = document.createRange(); s.setStartAfter(e), Array.isArray(t.value) ? (s.setEndBefore(r), s.deleteContents(), e.after(...S(t.value))) : (o(), s.setEndAfter(r), s.deleteContents(), e.replaceWith(O(t))); }); return [ e, ...S(t.value), r ]; }, S = (t) => t.flat(1 / 0).flatMap((e) => e != null && e[d] ? Array.isArray(e.value) ? W(e) : [O(e)] : [R(e)]), U = (t, e) => { for (const r in e) j(e[r], (o) => { o !== void 0 ? t.style.setProperty(r, o) : t.style.removeProperty(r); }); }, B = (t, e) => { for (const r in e) j(e[r], (o) => { t.classList.toggle(r, o); }); }, Q = (t, e) => { for (const r in e) j(e[r], (o) => { o !== void 0 ? t.setAttribute(r, o) : t.removeAttribute(r); }); }, X = (t) => { if (!t[d]) return document.createTextNode(t); const e = document.createTextNode(t.value); return t.addReaction(() => { e.textContent = t.value; }), e; }, k = (t) => (...e) => { var z; if (e.length === 0) return document.createElement(t); if (J(e[0])) { const l = document.createElement(t); return l.append(...S(e)), l; } const [r, ...o] = e, { namespace: s } = (z = r.bruh) != null ? z : {}; delete r.bruh; const i = s ? document.createElementNS(s, t) : document.createElement(t); typeof r.style == "object" && !r.style[d] && (U(i, r.style), delete r.style), typeof r.class == "object" && !r.class[d] && (B(i, r.class), delete r.class); for (const l in r) l.startsWith("on") && typeof r[l] == "function" && (i.addEventListener(l.slice(2), r[l]), delete r[l]); return Q(i, r), i.append(...S(o)), i; }, $ = (t, e, ...r) => { if (typeof t == "string") { const o = k(t); return e ? o(e, ...r) : o(...r); } return t({ ...e, children: r }); }, G = ({ children: t }) => t, H = () => { const t = {}, e = document.getElementsByTagName("bruh-textnode"); for (const r of e) { const o = document.createTextNode(r.textContent), s = r.getAttribute("tag"); s && (t[s] = o), r.replaceWith(o); } return t; }, te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, bruhChildrenToNodes: S, applyStyles: U, applyClasses: B, applyAttributes: Q, t: X, e: k, h: $, JSXFragment: G, hydrateTextNodes: H }, Symbol.toStringTag, { value: "Module" })), K = (t, ...e) => e.reduce((r, o) => o(r), t), Y = (t, e, r) => t.dispatchEvent( new CustomEvent(e, { bubbles: !0, cancelable: !0, composed: !0, ...r }) ), Z = (t, e) => { const r = { ...t, [Symbol.iterator]: () => e[Symbol.iterator]() }; return Object.defineProperty(r, Symbol.iterator, { enumerable: !1 }), r; }, V = (t) => new Proxy({}, { get: (e, r) => t(r) }), re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, pipe: K, dispatch: Y, createDestructable: Z, functionAsObject: V }, Symbol.toStringTag, { value: "Module" })); export { te as dom, ee as reactive, re as util }; //# sourceMappingURL=bruh.es.js.map