UNPKG

0x1

Version:

0x1: Lightning-fast web framework for JavaScript/TypeScript with zero overhead and maximum performance, powered by Bun

2 lines (1 loc) 9.02 kB
var K=Symbol.for("react.fragment"),f=Symbol.for("react.element"),D=Symbol.for("react.fragment");function b(Q,z){let{__0x1_enterComponentContext:Z,__0x1_exitComponentContext:q}=globalThis;if(!Z||!q){console.warn("[0x1 JSX] Hooks context not available, component will run without hooks");try{return Q(z)}catch(J){return console.error("[0x1 JSX] Component error (no hooks context):",J),{type:"div",props:{className:"error-boundary",style:{color:"red",padding:"10px",border:"1px solid red"}},children:[`Error in component: ${J.message}`],key:null}}}let Y=Q.name||"AnonymousComponent",L,$=(typeof window!=="undefined"?window.location.pathname:"/").replace(/[^a-zA-Z0-9]/g,"_")||"root",B=`${Y}_${$}`;if(typeof window!=="undefined"){if(!window.__0x1_stableComponentIds)window.__0x1_stableComponentIds=new Map;let J=window.__0x1_stableComponentIds;if(J.has(B))L=J.get(B);else L=`${Y}_${$}_${Math.random().toString(36).slice(2,3)}`,J.set(B,L)}else L=`${Y}_${Math.random().toString(36).slice(2,5)}`;Z(L);try{let J=Q(z);return V(J,L,Y)}catch(J){return console.error(`[0x1 JSX] Error in component ${L}:`,J),{type:"div",props:{className:"error-boundary",style:{color:"red",padding:"10px",border:"1px solid red"}},children:[`Error in ${Y}: ${J.message}`],key:null}}finally{q()}}function V(Q,z,Z){if(!Q||typeof Q!=="object")return Q;if("type"in Q&&"children"in Q&&typeof Q.type==="symbol"){let q=Q;if(Array.isArray(q.children)){let Y=q.children.map((L,$)=>{if(L&&typeof L==="object"&&"type"in L&&"props"in L){let B={...L};if(!B.props)B.props={};return B.props["data-component-id"]=z,B.props["data-component-name"]=Z,B.props["data-fragment-index"]=$,B}return L});return{...q,children:Y}}return q}if("type"in Q&&"props"in Q){let q=Q;if(!q.props)q.props={};if(q.props["data-component-id"]=z,q.props["data-component-name"]=Z,Z.includes("Layout")||Z.includes("layout")){if(Array.isArray(q.children)&&q.children.length>0){let Y=q.children[0];if(Y&&typeof Y==="object"&&"type"in Y&&"props"in Y){let L=Y.type;if(["div","main","section","article","aside","header","footer"].includes(L)){if(!Y.props)Y.props={};Y.props["data-component-id"]=z,Y.props["data-component-name"]=Z}}}}return q}if(Array.isArray(Q))return Q.map((Y,L)=>{if(Y&&typeof Y==="object"&&"type"in Y&&"props"in Y){let $={...Y};if(!$.props)$.props={};if($.props["data-component-id"]=z,$.props["data-component-name"]=Z,$.props["data-fragment-index"]=L,(Z.includes("Layout")||Z.includes("layout"))&&L===0)$.props["data-component-id"]=z,$.props["data-component-name"]=Z;return $}return Y});return Q}function R(Q,z,Z){let{children:q,...Y}=z||{};if(Q===K||Q===D)return{type:K,props:{},children:Array.isArray(q)?q.flat().filter((L)=>L!=null):q!=null?[q]:[],key:null};if(typeof Q==="function"){let L={...Y};if(q!==void 0)L.children=q;return b(Q,L)}return{type:Q,props:{...Y,children:Array.isArray(q)?q.flat().filter((L)=>L!=null):q!=null?[q]:[]},children:Array.isArray(q)?q.flat().filter((L)=>L!=null):q!=null?[q]:[],key:Z||null}}function S(Q,z,Z){return R(Q,z,Z)}function j(Q,z,Z,q,Y,L){if(Y&&z&&typeof z==="object")z.__source=Y;if(L!==void 0&&z&&typeof z==="object")z.__self=L;return R(Q,z,Z)}function P(Q,z,...Z){let q=Z.flat().filter((Y)=>Y!=null);if(typeof Q==="function"){let Y={...z};if(q.length>0)Y.children=q.length===1?q[0]:q;return b(Q,Y)}return R(Q,{...z,children:q})}function _(Q,z){try{if(Q===null||Q===void 0)return null;if(typeof Q==="string"||typeof Q==="number")return document.createTextNode(String(Q));if(Array.isArray(Q)){let Z=document.createDocumentFragment();return Q.forEach((q)=>{let Y=_(q,z);if(Y)Z.appendChild(Y)}),Z}if(typeof Q==="object"&&Q.type){if(Q.type===K){let L=document.createDocumentFragment();if(Q.children)(Array.isArray(Q.children)?Q.children:[Q.children]).forEach((B)=>{let J=_(B,z);if(J)L.appendChild(J)});return L}if(typeof Q.type==="function"){let L=b(Q.type,Q.props);if(L&&typeof L==="object"&&"props"in L&&Q.props){let $=Q.props["data-component-id"],B=Q.props["data-component-name"];if($&&!L.props["data-component-id"]){if(!L.props)L.props={};L.props["data-component-id"]=$}if(B&&!L.props["data-component-name"]){if(!L.props)L.props={};L.props["data-component-name"]=B}}return _(L,z)}let Z=Q.type,q,Y=new Set(["svg","path","circle","rect","line","ellipse","polygon","polyline","g","defs","use","symbol","marker","clipPath","mask","pattern","linearGradient","radialGradient","stop","text","tspan","textPath","foreignObject","switch","animate","animateTransform","animateMotion"]);if(Y.has(Z))q=document.createElementNS("http://www.w3.org/2000/svg",Z);else q=document.createElement(Z);if(Object.entries(Q.props||{}).forEach(([L,$])=>{if(L==="children")return;if(L==="className")if(Y.has(Z))q.setAttribute("class",String($));else q.className=String($);else if(L.startsWith("on")&&typeof $==="function"){let B=L.slice(2).toLowerCase();if(q[`__0x1_${B}_handler`]=$,q.addEventListener(B,$),B==="click"||B==="change")q.addEventListener("0x1-state-change",(J)=>{let G=J,{componentId:F,hookIndex:A,newValue:U,oldValue:O}=G.detail;if(Z==="button"){if(typeof U==="boolean")if(U)q.classList.add("active","pressed"),q.setAttribute("aria-pressed","true");else q.classList.remove("active","pressed"),q.setAttribute("aria-pressed","false")}if(q.classList.contains("dropdown-toggle")||q.getAttribute("data-dropdown")){let X=q.getAttribute("data-dropdown");if(X&&typeof U==="boolean"){let W=document.getElementById(X)||document.querySelector(`[data-dropdown-content="${X}"]`);if(W)if(U)W.classList.remove("hidden"),W.classList.add("block");else W.classList.add("hidden"),W.classList.remove("block")}}if(q.getAttribute("data-toggle")||q.classList.contains("toggle")){if(typeof U==="boolean"){q.setAttribute("data-state",U?"on":"off");let X=q.textContent||"";if(X.includes("ON")||X.includes("OFF"))q.textContent=X.replace(/ON|OFF/g,U?"ON":"OFF");if(U)q.classList.add("toggle-on","active"),q.classList.remove("toggle-off");else q.classList.add("toggle-off"),q.classList.remove("toggle-on","active")}}q.__0x1_state=q.__0x1_state||{},q.__0x1_state[A]=U})}else if(L==="style"&&typeof $==="object")Object.assign(q.style,$);else if(typeof $==="boolean"){if($)q.setAttribute(L,"")}else if($!=null){if(q.setAttribute(L,String($)),L==="data-component-id"){let B=q.getAttribute("data-component-id");try{q.addEventListener("0x1-state-change",(J)=>{try{let G=J,{hookIndex:F,newValue:A,oldValue:U,componentId:O}=G.detail||{};if(O===B)q.__0x1_state=q.__0x1_state||{},q.__0x1_state[F]=A}catch(G){console.error(`[0x1 JSX] ❌ Error in state-change listener for ${Z}:`,G)}})}catch(J){console.error(`[0x1 JSX] ❌ Failed to attach event listener to ${Z}:`,J)}}}}),Q.children)(Array.isArray(Q.children)?Q.children:[Q.children]).forEach(($)=>{let B=_($,q);if(B)q.appendChild(B)});return q}return null}catch(Z){return console.error("[0x1 JSX] renderToDOM error:",Z),document.createTextNode(`[Render Error: ${Z.message}]`)}}function H(Q){if(!Q)return"";if(typeof Q==="string"||typeof Q==="number")return String(Q);if(Array.isArray(Q))return Q.map((z)=>H(z)).join("");if(typeof Q==="object"&&Q&&"type"in Q){if(Q.type===K)return Q.children.map((L)=>H(L)).join("");if(typeof Q.type==="function"){let L=b(Q.type,Q.props);return H(L)}let z=Q.type,Z=Object.entries(Q.props||{}).filter(([L,$])=>$!=null&&L!=="children").map(([L,$])=>{if(typeof $==="boolean")return $?L:"";return`${L==="className"?"class":L}="${String($).replace(/"/g,"&quot;")}"`}).filter((L)=>L).join(" "),q=Q.children?.map((L)=>H(L)).join("")||"";if(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(z))return`<${z}${Z?" "+Z:""} />`;return`<${z}${Z?" "+Z:""}>${q}</${z}>`}return""}function M(Q,z={},Z){let q=document.createElement(Q);if(Object.entries(z).forEach(([Y,L])=>{if(Y==="className")q.className=String(L);else if(Y.startsWith("on")&&typeof L==="function"){let $=Y.slice(2).toLowerCase();q.addEventListener($,L)}else if(Y==="style"&&typeof L==="object")Object.assign(q.style,L);else if(typeof L==="boolean"){if(L)q.setAttribute(Y,"")}else if(L!=null)q.setAttribute(Y,String(L))}),Z)q.addEventListener("0x1-state-change",(Y)=>{Z(q,Y.detail)});return q}function T(Q,z,Z,q){return M("button",{className:q||"toggle-button",onClick:Z},(Y,L)=>{if(L.hookIndex===z)if(L.newValue)Y.classList.add("active"),Y.setAttribute("aria-pressed","true");else Y.classList.remove("active"),Y.setAttribute("aria-pressed","false")})}function w(){if(typeof window!=="undefined"){if(window.jsx=R,window.jsxs=S,window.jsxDEV=j,window.createElement=P,window.Fragment=K,window.renderToDOM=_,window.createStateResponsiveElement=M,window.createToggleButton=T,window.jsxToDom=_,window.__0x1_renderToDOM=_,!window.React)window.React={};window.React.createElement=P,window.React.Fragment=K,window.React.jsx=R,window.React.jsxs=S}}if(typeof window!=="undefined")setTimeout(w,0);export{H as renderToString,_ as renderToDOM,S as jsxs,j as jsxDEV,R as jsx,T as createToggleButton,M as createStateResponsiveElement,P as createElement,D as REACT_FRAGMENT,f as REACT_ELEMENT,K as Fragment};