From b00a690a7d69b6bea73b6a7bd8d879d698ff1864 Mon Sep 17 00:00:00 2001 From: natxocc Date: Sat, 21 Mar 2026 14:19:08 +0100 Subject: [PATCH] Actualizar src/sigpro.js --- src/sigpro.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/sigpro.js b/src/sigpro.js index 5ce0967..c74d4b7 100644 --- a/src/sigpro.js +++ b/src/sigpro.js @@ -41,16 +41,16 @@ */ window.$$ = (tag, props = {}, children = []) => { const el = document.createElement(tag); - + // Logic: If props is NOT a plain object or is a Node/Array/Function, // it's actually the children. if ( - typeof props !== 'object' || - props instanceof Node || - Array.isArray(props) || + typeof props !== 'object' || + props instanceof Node || + Array.isArray(props) || typeof props === 'function' ) { - children = props; + children = props; props = {}; } @@ -90,17 +90,26 @@ }; /** - * System Utilities (_) + * Application Mounter (Inspired by Vue) + * @param {HTMLElement|Function} node - Root component. + * @param {HTMLElement} [target] - Container element. */ - window._render = (node, target = document.body) => { + window.mount = (node, target = document.body) => { target.innerHTML = ''; - target.appendChild(typeof node === 'function' ? node() : node); + const root = typeof node === 'function' ? node() : node; + target.appendChild(root); + console.log("%c[SigPro] Mounted successfully", "color: #42b883; font-weight: bold;"); }; - window._router = (routes) => { + /** + * Integrated Router + * @param {Array} routes - Route definitions. + */ + window.router = (routes) => { const sPath = $(window.location.hash.replace(/^#/, "") || "/"); window.addEventListener("hashchange", () => sPath(window.location.hash.replace(/^#/, "") || "/")); - return div({ class: "sigpro-router" }, [ + + return div([ () => { const current = sPath(); const route = routes.find(r => { @@ -109,6 +118,7 @@ if (rP.length !== cP.length) return false; return rP.every((part, i) => part.startsWith(':') || part === cP[i]); }) || routes.find(r => r.path === "*"); + return route ? (typeof route.component === 'function' ? route.component() : route.component) : h1("404"); } ]);