UNPKG

bruh

Version:

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

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