eleva 1.2.7-alpha → 1.2.8-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"eleva.umd.js","sources":["../src/modules/TemplateEngine.js","../src/modules/Signal.js","../src/modules/Emitter.js","../src/modules/Renderer.js","../src/core/Eleva.js"],"sourcesContent":["\"use strict\";\n\n/**\n * @class 🔒 TemplateEngine\n * @classdesc Secure interpolation & dynamic attribute parsing.\n * Provides methods to parse template strings by replacing interpolation expressions\n * with dynamic data values and to evaluate expressions within a given data context.\n */\nexport class TemplateEngine {\n /**\n * Parses a template string and replaces interpolation expressions with corresponding values.\n *\n * @param {string} template - The template string containing expressions in the format `{{ expression }}`.\n * @param {Object<string, any>} data - The data object to use for evaluating expressions.\n * @returns {string} The resulting string with evaluated values.\n */\n static parse(template, data) {\n if (!template || typeof template !== \"string\") return template;\n\n return template.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, expr) => {\n return this.evaluate(expr, data);\n });\n }\n\n /**\n * Evaluates a JavaScript expression using the provided data context.\n *\n * @param {string} expr - The JavaScript expression to evaluate.\n * @param {Object<string, any>} data - The data context for evaluating the expression.\n * @returns {any} The result of the evaluated expression, or an empty string if undefined or on error.\n */\n static evaluate(expr, data) {\n if (!expr || typeof expr !== \"string\") return expr;\n\n try {\n const compiledFn = new Function(\"data\", `with(data) { return ${expr} }`);\n return compiledFn(data);\n } catch (error) {\n console.error(`Template evaluation error:`, {\n expression: expr,\n data,\n error: error.message,\n });\n return \"\";\n }\n }\n}\n","\"use strict\";\n\n/**\n * @class ⚡ Signal\n * @classdesc Fine-grained reactivity.\n * A reactive data holder that notifies registered watchers when its value changes,\n * enabling fine-grained DOM patching rather than full re-renders.\n */\nexport class Signal {\n /**\n * Creates a new Signal instance.\n *\n * @param {*} value - The initial value of the signal.\n */\n constructor(value) {\n /** @private {*} Internal storage for the signal's current value */\n this._value = value;\n /** @private {Set<function>} Collection of callback functions to be notified when value changes */\n this._watchers = new Set();\n /** @private {boolean} Flag to prevent multiple synchronous watcher notifications and batch updates into microtasks */\n this._pending = false;\n }\n\n /**\n * Gets the current value of the signal.\n *\n * @returns {*} The current value.\n */\n get value() {\n return this._value;\n }\n\n /**\n * Sets a new value for the signal and notifies all registered watchers if the value has changed.\n *\n * @param {*} newVal - The new value to set.\n */\n set value(newVal) {\n if (newVal !== this._value) {\n this._value = newVal;\n this._notifyWatchers();\n }\n }\n\n /**\n * Registers a watcher function that will be called whenever the signal's value changes.\n *\n * @param {function(any): void} fn - The callback function to invoke on value change.\n * @returns {function(): boolean} A function to unsubscribe the watcher.\n */\n watch(fn) {\n this._watchers.add(fn);\n return () => this._watchers.delete(fn);\n }\n\n /**\n * Notifies all registered watchers of a value change using microtask scheduling.\n * Uses a pending flag to batch multiple synchronous updates into a single notification.\n * All watcher callbacks receive the current value when executed.\n *\n * @private\n * @returns {void}\n */\n _notifyWatchers() {\n if (!this._pending) {\n this._pending = true;\n queueMicrotask(() => {\n this._pending = false;\n this._watchers.forEach((fn) => fn(this._value));\n });\n }\n }\n}\n","\"use strict\";\n\n/**\n * @class 🎙️ Emitter\n * @classdesc Robust inter-component communication with event bubbling.\n * Implements a basic publish-subscribe pattern for event handling, allowing components\n * to communicate through custom events.\n */\nexport class Emitter {\n /**\n * Creates a new Emitter instance.\n */\n constructor() {\n /** @type {Object.<string, Function[]>} Storage for event handlers mapped by event name */\n this.events = {};\n }\n\n /**\n * Registers an event handler for the specified event.\n *\n * @param {string} event - The name of the event.\n * @param {function(...any): void} handler - The function to call when the event is emitted.\n */\n on(event, handler) {\n (this.events[event] || (this.events[event] = [])).push(handler);\n }\n\n /**\n * Removes a previously registered event handler.\n *\n * @param {string} event - The name of the event.\n * @param {function(...any): void} handler - The handler function to remove.\n */\n off(event, handler) {\n if (this.events[event]) {\n this.events[event] = this.events[event].filter((h) => h !== handler);\n }\n }\n\n /**\n * Emits an event, invoking all handlers registered for that event.\n *\n * @param {string} event - The event name.\n * @param {...any} args - Additional arguments to pass to the event handlers.\n */\n emit(event, ...args) {\n (this.events[event] || []).forEach((handler) => handler(...args));\n }\n}\n","\"use strict\";\n\n/**\n * @class 🎨 Renderer\n * @classdesc Handles DOM patching, diffing, and attribute updates.\n * Provides methods for efficient DOM updates by diffing the new and old DOM structures\n * and applying only the necessary changes.\n */\nexport class Renderer {\n /**\n * Patches the DOM of a container element with new HTML content.\n *\n * @param {HTMLElement} container - The container element to patch.\n * @param {string} newHtml - The new HTML content to apply.\n * @throws {Error} If container is not an HTMLElement or newHtml is not a string\n */\n patchDOM(container, newHtml) {\n if (!(container instanceof HTMLElement)) {\n throw new Error(\"Container must be an HTMLElement\");\n }\n if (typeof newHtml !== \"string\") {\n throw new Error(\"newHtml must be a string\");\n }\n\n const temp = document.createElement(\"div\");\n temp.innerHTML = newHtml;\n this.diff(container, temp);\n temp.innerHTML = \"\";\n }\n\n /**\n * Diffs two DOM trees (old and new) and applies updates to the old DOM.\n *\n * @param {HTMLElement} oldParent - The original DOM element.\n * @param {HTMLElement} newParent - The new DOM element.\n * @throws {Error} If either parent is not an HTMLElement\n */\n diff(oldParent, newParent) {\n if (\n !(oldParent instanceof HTMLElement) ||\n !(newParent instanceof HTMLElement)\n ) {\n throw new Error(\"Both parents must be HTMLElements\");\n }\n\n if (oldParent.isEqualNode(newParent)) return;\n\n const oldC = oldParent.childNodes;\n const newC = newParent.childNodes;\n const len = Math.max(oldC.length, newC.length);\n const operations = [];\n\n for (let i = 0; i < len; i++) {\n const oldNode = oldC[i];\n const newNode = newC[i];\n\n if (!oldNode && newNode) {\n operations.push(() => oldParent.appendChild(newNode.cloneNode(true)));\n continue;\n }\n if (oldNode && !newNode) {\n operations.push(() => oldParent.removeChild(oldNode));\n continue;\n }\n\n const isSameType =\n oldNode.nodeType === newNode.nodeType &&\n oldNode.nodeName === newNode.nodeName;\n\n if (!isSameType) {\n operations.push(() =>\n oldParent.replaceChild(newNode.cloneNode(true), oldNode)\n );\n continue;\n }\n\n if (oldNode.nodeType === Node.ELEMENT_NODE) {\n const oldKey = oldNode.getAttribute(\"key\");\n const newKey = newNode.getAttribute(\"key\");\n\n if (oldKey !== newKey && (oldKey || newKey)) {\n operations.push(() =>\n oldParent.replaceChild(newNode.cloneNode(true), oldNode)\n );\n continue;\n }\n\n this.updateAttributes(oldNode, newNode);\n this.diff(oldNode, newNode);\n } else if (\n oldNode.nodeType === Node.TEXT_NODE &&\n oldNode.nodeValue !== newNode.nodeValue\n ) {\n oldNode.nodeValue = newNode.nodeValue;\n }\n }\n\n if (operations.length) {\n operations.forEach((op) => op());\n }\n }\n\n /**\n * Updates the attributes of an element to match those of a new element.\n *\n * @param {HTMLElement} oldEl - The element to update.\n * @param {HTMLElement} newEl - The element providing the updated attributes.\n * @throws {Error} If either element is not an HTMLElement\n */\n updateAttributes(oldEl, newEl) {\n if (!(oldEl instanceof HTMLElement) || !(newEl instanceof HTMLElement)) {\n throw new Error(\"Both elements must be HTMLElements\");\n }\n\n const oldAttrs = oldEl.attributes;\n const newAttrs = newEl.attributes;\n const operations = [];\n\n // Remove old attributes\n for (const { name } of oldAttrs) {\n if (!name.startsWith(\"@\") && !newEl.hasAttribute(name)) {\n operations.push(() => oldEl.removeAttribute(name));\n }\n }\n\n // Update/add new attributes\n for (const attr of newAttrs) {\n const { name, value } = attr;\n if (name.startsWith(\"@\")) continue;\n\n if (oldEl.getAttribute(name) === value) continue;\n\n operations.push(() => {\n oldEl.setAttribute(name, value);\n\n if (name.startsWith(\"aria-\")) {\n const prop =\n \"aria\" +\n name.slice(5).replace(/-([a-z])/g, (_, l) => l.toUpperCase());\n oldEl[prop] = value;\n } else if (name.startsWith(\"data-\")) {\n oldEl.dataset[name.slice(5)] = value;\n } else {\n const prop = name.replace(/-([a-z])/g, (_, l) => l.toUpperCase());\n if (prop in oldEl) {\n const descriptor = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(oldEl),\n prop\n );\n const isBoolean =\n typeof oldEl[prop] === \"boolean\" ||\n (descriptor?.get &&\n typeof descriptor.get.call(oldEl) === \"boolean\");\n\n if (isBoolean) {\n oldEl[prop] =\n value !== \"false\" &&\n (value === \"\" || value === prop || value === \"true\");\n } else {\n oldEl[prop] = value;\n }\n }\n }\n });\n }\n\n if (operations.length) {\n operations.forEach((op) => op());\n }\n }\n}\n","\"use strict\";\n\nimport { TemplateEngine } from \"../modules/TemplateEngine.js\";\nimport { Signal } from \"../modules/Signal.js\";\nimport { Emitter } from \"../modules/Emitter.js\";\nimport { Renderer } from \"../modules/Renderer.js\";\n\n/**\n * Defines the structure and behavior of a component.\n * @typedef {Object} ComponentDefinition\n * @property {function(Object<string, any>): (Object<string, any>|Promise<Object<string, any>>)} [setup]\n * Optional setup function that initializes the component's reactive state and lifecycle.\n * Receives props and context as an argument and should return an object containing the component's state.\n * Can return either a synchronous object or a Promise that resolves to an object for async initialization.\n *\n * @property {function(Object<string, any>): string} template\n * Required function that defines the component's HTML structure.\n * Receives the merged context (props + setup data) and must return an HTML template string.\n * Supports dynamic expressions using {{ }} syntax for reactive data binding.\n *\n * @property {function(Object<string, any>): string} [style]\n * Optional function that defines component-scoped CSS styles.\n * Receives the merged context and returns a CSS string that will be automatically scoped to the component.\n * Styles are injected into the component's container and only affect elements within it.\n *\n * @property {Object<string, ComponentDefinition>} [children]\n * Optional object that defines nested child components.\n * Keys are CSS selectors that match elements in the template where child components should be mounted.\n * Values are ComponentDefinition objects that define the structure and behavior of each child component.\n */\n\n/**\n * @class 🧩 Eleva\n * @classdesc Signal-based component runtime framework with lifecycle hooks, scoped styles, and plugin support.\n * Manages component registration, plugin integration, event handling, and DOM rendering.\n */\nexport class Eleva {\n /**\n * Creates a new Eleva instance.\n *\n * @param {string} name - The name of the Eleva instance.\n * @param {Object<string, any>} [config={}] - Optional configuration for the instance.\n */\n constructor(name, config = {}) {\n /** @type {string} The unique identifier name for this Eleva instance */\n this.name = name;\n /** @type {Object<string, any>} Optional configuration object for the Eleva instance */\n this.config = config;\n /** @type {Object<string, ComponentDefinition>} Object storing registered component definitions by name */\n this._components = {};\n /** @private {Array<Object>} Collection of installed plugin instances */\n this._plugins = [];\n /** @private {string[]} Array of lifecycle hook names supported by the component */\n this._lifecycleHooks = [\n \"onBeforeMount\",\n \"onMount\",\n \"onBeforeUpdate\",\n \"onUpdate\",\n \"onUnmount\",\n ];\n /** @private {boolean} Flag indicating if component is currently mounted */\n this._isMounted = false;\n /** @private {Emitter} Instance of the event emitter for handling component events */\n this.emitter = new Emitter();\n /** @private {Signal} Instance of the signal for handling plugin and component signals */\n this.signal = Signal;\n /** @private {Renderer} Instance of the renderer for handling DOM updates and patching */\n this.renderer = new Renderer();\n }\n\n /**\n * Integrates a plugin with the Eleva framework.\n *\n * @param {Object} plugin - The plugin object which should have an `install` function.\n * @param {Object<string, any>} [options={}] - Optional options to pass to the plugin.\n * @returns {Eleva} The Eleva instance (for chaining).\n */\n use(plugin, options = {}) {\n if (typeof plugin.install === \"function\") {\n plugin.install(this, options);\n }\n this._plugins.push(plugin);\n return this;\n }\n\n /**\n * Registers a component with the Eleva instance.\n *\n * @param {string} name - The name of the component.\n * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.\n * @returns {Eleva} The Eleva instance (for chaining).\n */\n component(name, definition) {\n this._components[name] = definition;\n return this;\n }\n\n /**\n * Mounts a registered component to a DOM element.\n *\n * @param {HTMLElement} container - A DOM element where the component will be mounted.\n * @param {string|ComponentDefinition} compName - The name of the component to mount or a component definition.\n * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.\n * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.\n * @throws {Error} If the container is not found or if the component is not registered.\n */\n mount(container, compName, props = {}) {\n if (!container) throw new Error(`Container not found: ${container}`);\n\n const definition =\n typeof compName === \"string\" ? this._components[compName] : compName;\n if (!definition) throw new Error(`Component \"${compName}\" not registered.`);\n\n if (typeof definition.template !== \"function\")\n throw new Error(\"Component template must be a function\");\n\n /**\n * Destructure the component definition to access core functionality.\n * - setup: Optional function for component initialization and state management\n * - template: Required function that returns the component's HTML structure\n * - style: Optional function for component-scoped CSS styles\n * - children: Optional object defining nested child components\n */\n const { setup, template, style, children } = definition;\n\n /**\n * Creates the initial context object for the component instance.\n * This context provides core functionality and will be merged with setup data.\n * @type {Object<string, any>}\n * @property {Object<string, any>} props - Component properties passed during mounting\n * @property {Emitter} emitter - Event emitter instance for component event handling\n * @property {function(any): Signal} signal - Factory function to create reactive Signal instances\n * @property {Object<string, function(): void>} ...lifecycleHooks - Prepared lifecycle hook functions\n */\n const context = {\n props,\n emitter: this.emitter,\n signal: (v) => new this.signal(v),\n ...this._prepareLifecycleHooks(),\n };\n\n /**\n * Processes the mounting of the component.\n *\n * @param {Object<string, any>} data - Data returned from the component's setup function.\n * @returns {object} An object with the container, merged context data, and an unmount function.\n */\n const processMount = (data) => {\n const mergedContext = { ...context, ...data };\n const watcherUnsubscribers = [];\n const childInstances = [];\n const cleanupListeners = [];\n\n // Execute before hooks\n if (!this._isMounted) {\n mergedContext.onBeforeMount && mergedContext.onBeforeMount();\n } else {\n mergedContext.onBeforeUpdate && mergedContext.onBeforeUpdate();\n }\n\n /**\n * Renders the component by parsing the template, patching the DOM,\n * processing events, injecting styles, and mounting child components.\n */\n const render = () => {\n const newHtml = TemplateEngine.parse(\n template(mergedContext),\n mergedContext\n );\n this.renderer.patchDOM(container, newHtml);\n this._processEvents(container, mergedContext, cleanupListeners);\n this._injectStyles(container, compName, style, mergedContext);\n this._mountChildren(container, children, childInstances);\n\n if (!this._isMounted) {\n mergedContext.onMount && mergedContext.onMount();\n this._isMounted = true;\n } else {\n mergedContext.onUpdate && mergedContext.onUpdate();\n }\n };\n\n /**\n * Sets up reactive watchers for all Signal instances in the component's data.\n * When a Signal's value changes, the component will re-render to reflect the updates.\n * Stores unsubscribe functions to clean up watchers when component unmounts.\n */\n Object.values(data).forEach((val) => {\n if (val instanceof Signal) watcherUnsubscribers.push(val.watch(render));\n });\n\n render();\n\n return {\n container,\n data: mergedContext,\n /**\n * Unmounts the component, cleaning up watchers and listeners, child components, and clearing the container.\n *\n * @returns {void}\n */\n unmount: () => {\n watcherUnsubscribers.forEach((fn) => fn());\n cleanupListeners.forEach((fn) => fn());\n childInstances.forEach((child) => child.unmount());\n mergedContext.onUnmount && mergedContext.onUnmount();\n container.innerHTML = \"\";\n },\n };\n };\n\n // Handle asynchronous setup.\n return Promise.resolve(\n typeof setup === \"function\" ? setup(context) : {}\n ).then(processMount);\n }\n\n /**\n * Prepares default no-operation lifecycle hook functions.\n *\n * @returns {Object<string, function(): void>} An object with keys for lifecycle hooks mapped to empty functions.\n * @private\n */\n _prepareLifecycleHooks() {\n return this._lifecycleHooks.reduce((acc, hook) => {\n acc[hook] = () => {};\n return acc;\n }, {});\n }\n\n /**\n * Processes DOM elements for event binding based on attributes starting with \"@\".\n * Tracks listeners for cleanup during unmount.\n *\n * @param {HTMLElement} container - The container element in which to search for events.\n * @param {Object<string, any>} context - The current context containing event handler definitions.\n * @param {Array<Function>} cleanupListeners - Array to collect cleanup functions for each event listener.\n * @private\n */\n _processEvents(container, context, cleanupListeners) {\n const elements = container.querySelectorAll(\"*\");\n for (const el of elements) {\n const attrs = el.attributes;\n for (let i = 0; i < attrs.length; i++) {\n const attr = attrs[i];\n if (attr.name.startsWith(\"@\")) {\n const event = attr.name.slice(1);\n const handler = TemplateEngine.evaluate(attr.value, context);\n if (typeof handler === \"function\") {\n el.addEventListener(event, handler);\n el.removeAttribute(attr.name);\n cleanupListeners.push(() => el.removeEventListener(event, handler));\n }\n }\n }\n }\n }\n\n /**\n * Injects scoped styles into the component's container.\n *\n * @param {HTMLElement} container - The container element.\n * @param {string} compName - The component name used to identify the style element.\n * @param {function(Object<string, any>): string} [styleFn] - A function that returns CSS styles as a string.\n * @param {Object<string, any>} context - The current context for style interpolation.\n * @private\n */\n _injectStyles(container, compName, styleFn, context) {\n if (!styleFn) return;\n\n let styleEl = container.querySelector(\n `style[data-eleva-style=\"${compName}\"]`\n );\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.setAttribute(\"data-eleva-style\", compName);\n container.appendChild(styleEl);\n }\n styleEl.textContent = TemplateEngine.parse(styleFn(context), context);\n }\n\n /**\n * Mounts child components within the parent component's container.\n *\n * @param {HTMLElement} container - The parent container element.\n * @param {Object<string, ComponentDefinition>} [children] - An object mapping child component selectors to their definitions.\n * @param {Array<object>} childInstances - An array to store the mounted child component instances.\n * @private\n */\n _mountChildren(container, children, childInstances) {\n childInstances.forEach((child) => child.unmount());\n childInstances.length = 0;\n\n Object.keys(children || {}).forEach((childSelector) => {\n container.querySelectorAll(childSelector).forEach((childEl) => {\n const props = {};\n [...childEl.attributes].forEach(({ name, value }) => {\n if (name.startsWith(\"eleva-prop-\")) {\n props[name.replace(\"eleva-prop-\", \"\")] = value;\n }\n });\n const instance = this.mount(childEl, children[childSelector], props);\n childInstances.push(instance);\n });\n });\n }\n}\n"],"names":["TemplateEngine","parse","template","data","replace","_","expr","evaluate","compiledFn","Function","error","console","expression","message","Signal","constructor","value","_value","_watchers","Set","_pending","newVal","_notifyWatchers","watch","fn","add","delete","queueMicrotask","forEach","Emitter","events","on","event","handler","push","off","filter","h","emit","args","Renderer","patchDOM","container","newHtml","HTMLElement","Error","temp","document","createElement","innerHTML","diff","oldParent","newParent","isEqualNode","oldC","childNodes","newC","len","Math","max","length","operations","i","oldNode","newNode","appendChild","cloneNode","removeChild","isSameType","nodeType","nodeName","replaceChild","Node","ELEMENT_NODE","oldKey","getAttribute","newKey","updateAttributes","TEXT_NODE","nodeValue","op","oldEl","newEl","oldAttrs","attributes","newAttrs","name","startsWith","hasAttribute","removeAttribute","attr","setAttribute","prop","slice","l","toUpperCase","dataset","descriptor","Object","getOwnPropertyDescriptor","getPrototypeOf","isBoolean","get","call","Eleva","config","_components","_plugins","_lifecycleHooks","_isMounted","emitter","signal","renderer","use","plugin","options","install","component","definition","mount","compName","props","setup","style","children","context","v","_prepareLifecycleHooks","processMount","mergedContext","watcherUnsubscribers","childInstances","cleanupListeners","onBeforeMount","onBeforeUpdate","render","_processEvents","_injectStyles","_mountChildren","onMount","onUpdate","values","val","unmount","child","onUnmount","Promise","resolve","then","reduce","acc","hook","elements","querySelectorAll","el","attrs","addEventListener","removeEventListener","styleFn","styleEl","querySelector","textContent","keys","childSelector","childEl","instance"],"mappings":";;;;;;EAEA;EACA;EACA;EACA;EACA;EACA;EACO,MAAMA,cAAc,CAAC;EAC1B;EACF;EACA;EACA;EACA;EACA;EACA;EACE,EAAA,OAAOC,KAAKA,CAACC,QAAQ,EAAEC,IAAI,EAAE;MAC3B,IAAI,CAACD,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ,EAAE,OAAOA,QAAQ;MAE9D,OAAOA,QAAQ,CAACE,OAAO,CAAC,sBAAsB,EAAE,CAACC,CAAC,EAAEC,IAAI,KAAK;EAC3D,MAAA,OAAO,IAAI,CAACC,QAAQ,CAACD,IAAI,EAAEH,IAAI,CAAC;EAClC,KAAC,CAAC;EACJ;;EAEA;EACF;EACA;EACA;EACA;EACA;EACA;EACE,EAAA,OAAOI,QAAQA,CAACD,IAAI,EAAEH,IAAI,EAAE;MAC1B,IAAI,CAACG,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE,OAAOA,IAAI;MAElD,IAAI;QACF,MAAME,UAAU,GAAG,IAAIC,QAAQ,CAAC,MAAM,EAAE,CAAA,oBAAA,EAAuBH,IAAI,CAAA,EAAA,CAAI,CAAC;QACxE,OAAOE,UAAU,CAACL,IAAI,CAAC;OACxB,CAAC,OAAOO,KAAK,EAAE;EACdC,MAAAA,OAAO,CAACD,KAAK,CAAC,CAAA,0BAAA,CAA4B,EAAE;EAC1CE,QAAAA,UAAU,EAAEN,IAAI;UAChBH,IAAI;UACJO,KAAK,EAAEA,KAAK,CAACG;EACf,OAAC,CAAC;EACF,MAAA,OAAO,EAAE;EACX;EACF;EACF;;EC5CA;EACA;EACA;EACA;EACA;EAC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AC;MAClDZ,cAAc,CAACvE,MAAM,GAAG,CAAC;EAEzBsC,IAAAA,MAAM,CAACgE,IAAI,CAACtC,QAAQ,IAAI,EAAE,CAAC,CAAChG,OAAO,CAAEuI,aAAa,IAAK;QACrDzH,SAAS,CAAC+G,gBAAgB,CAACU,aAAa,CAAC,CAACvI,OAAO,CAAEwI,OAAO,IAAK;UAC7D,MAAM3C,KAAK,GAAG,EAAE;UAChB,CAAC,GAAG2C,OAAO,CAAChF,UAAU,CAAC,CAACxD,OAAO,CAAC,CAAC;YAAE0D,IAAI;EAAEtE,UAAAA;EAAM,SAAC,KAAK;EACnD,UAAA,IAAIsE,IAAI,CAACC,UAAU,CAAC,aAAa,CAAC,EAAE;cAClCkC,KAAK,CAACnC,IAAI,CAAClF,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,GAAGY,KAAK;EAChD;EACF,SAAC,CAAC;EACF,QAAA,MAAMqJ,QAAQ,GAAG,IAAI,CAAC9C,KAAK,CAAC6C,OAAO,EAAExC,QAAQ,CAACuC,aAAa,CAAC,EAAE1C,KAAK,CAAC;EACpEU,QAAAA,cAAc,CAACjG,IAAI,CAACmI,QAAQ,CAAC;EAC/B,OAAC,CAAC;EACJ,KAAC,CAAC;EACJ;EACF;;;;;;;;"}
1
+ {"version":3,"file":"eleva.umd.js","sources":["../src/modules/TemplateEngine.js","../src/modules/Signal.js","../src/modules/Emitter.js","../src/modules/Renderer.js","../src/core/Eleva.js"],"sourcesContent":["\"use strict\";\n\n/**\n * @class 🔒 TemplateEngine\n * @classdesc A secure template engine that handles interpolation and dynamic attribute parsing.\n * Provides a safe way to evaluate expressions in templates while preventing XSS attacks.\n * All methods are static and can be called directly on the class.\n *\n * @example\n * const template = \"Hello, {{name}}!\";\n * const data = { name: \"World\" };\n * const result = TemplateEngine.parse(template, data); // Returns: \"Hello, World!\"\n */\nexport class TemplateEngine {\n /**\n * @private {RegExp} Regular expression for matching template expressions in the format {{ expression }}\n */\n static expressionPattern = /\\{\\{\\s*(.*?)\\s*\\}\\}/g;\n\n /**\n * Parses a template string, replacing expressions with their evaluated values.\n * Expressions are evaluated in the provided data context.\n *\n * @public\n * @static\n * @param {string} template - The template string to parse.\n * @param {Object} data - The data context for evaluating expressions.\n * @returns {string} The parsed template with expressions replaced by their values.\n * @example\n * const result = TemplateEngine.parse(\"{{user.name}} is {{user.age}} years old\", {\n * user: { name: \"John\", age: 30 }\n * }); // Returns: \"John is 30 years old\"\n */\n static parse(template, data) {\n if (typeof template !== \"string\") return template;\n return template.replace(this.expressionPattern, (_, expression) =>\n this.evaluate(expression, data)\n );\n }\n\n /**\n * Evaluates an expression in the context of the provided data object.\n * Note: This does not provide a true sandbox and evaluated expressions may access global scope.\n *\n * @public\n * @static\n * @param {string} expression - The expression to evaluate.\n * @param {Object} data - The data context for evaluation.\n * @returns {*} The result of the evaluation, or an empty string if evaluation fails.\n * @example\n * const result = TemplateEngine.evaluate(\"user.name\", { user: { name: \"John\" } }); // Returns: \"John\"\n * const age = TemplateEngine.evaluate(\"user.age\", { user: { age: 30 } }); // Returns: 30\n */\n static evaluate(expression, data) {\n if (typeof expression !== \"string\") return expression;\n try {\n return new Function(\"data\", `with(data) { return ${expression}; }`)(data);\n } catch {\n return \"\";\n }\n }\n}\n","\"use strict\";\n\n/**\n * @class ⚡ Signal\n * @classdesc A reactive data holder that enables fine-grained reactivity in the Eleva framework.\n * Signals notify registered watchers when their value changes, enabling efficient DOM updates\n * through targeted patching rather than full re-renders.\n *\n * @example\n * const count = new Signal(0);\n * count.watch((value) => console.log(`Count changed to: ${value}`));\n * count.value = 1; // Logs: \"Count changed to: 1\"\n */\nexport class Signal {\n /**\n * Creates a new Signal instance with the specified initial value.\n *\n * @public\n * @param {*} value - The initial value of the signal.\n */\n constructor(value) {\n /** @private {T} Internal storage for the signal's current value, where T is the type of the initial value */\n this._value = value;\n /** @private {Set<function(T): void>} Collection of callback functions to be notified when value changes, where T is the value type */\n this._watchers = new Set();\n /** @private {boolean} Flag to prevent multiple synchronous watcher notifications and batch updates into microtasks */\n this._pending = false;\n }\n\n /**\n * Gets the current value of the signal.\n *\n * @public\n * @returns {T} The current value, where T is the type of the initial value.\n */\n get value() {\n return this._value;\n }\n\n /**\n * Sets a new value for the signal and notifies all registered watchers if the value has changed.\n * The notification is batched using microtasks to prevent multiple synchronous updates.\n *\n * @public\n * @param {T} newVal - The new value to set, where T is the type of the initial value.\n * @returns {void}\n */\n set value(newVal) {\n if (newVal !== this._value) {\n this._value = newVal;\n this._notifyWatchers();\n }\n }\n\n /**\n * Registers a watcher function that will be called whenever the signal's value changes.\n * The watcher will receive the new value as its argument.\n *\n * @public\n * @param {function(T): void} fn - The callback function to invoke on value change, where T is the value type.\n * @returns {function(): boolean} A function to unsubscribe the watcher.\n * @example\n * const unsubscribe = signal.watch((value) => console.log(value));\n * // Later...\n * unsubscribe(); // Stops watching for changes\n */\n watch(fn) {\n this._watchers.add(fn);\n return () => this._watchers.delete(fn);\n }\n\n /**\n * Notifies all registered watchers of a value change using microtask scheduling.\n * Uses a pending flag to batch multiple synchronous updates into a single notification.\n * All watcher callbacks receive the current value when executed.\n *\n * @private\n * @returns {void}\n */\n _notifyWatchers() {\n if (!this._pending) {\n this._pending = true;\n queueMicrotask(() => {\n this._pending = false;\n this._watchers.forEach((fn) => fn(this._value));\n });\n }\n }\n}\n","\"use strict\";\n\n/**\n * @class 📡 Emitter\n * @classdesc A robust event emitter that enables inter-component communication through a publish-subscribe pattern.\n * Components can emit events and listen for events from other components, facilitating loose coupling\n * and reactive updates across the application.\n *\n * @example\n * const emitter = new Emitter();\n * emitter.on('user:login', (user) => console.log(`User logged in: ${user.name}`));\n * emitter.emit('user:login', { name: 'John' }); // Logs: \"User logged in: John\"\n */\nexport class Emitter {\n /**\n * Creates a new Emitter instance.\n *\n * @public\n */\n constructor() {\n /** @private {Map<string, Set<function(any): void>>} Map of event names to their registered handler functions */\n this._events = new Map();\n }\n\n /**\n * Registers an event handler for the specified event name.\n * The handler will be called with the event data when the event is emitted.\n *\n * @public\n * @param {string} event - The name of the event to listen for.\n * @param {function(any): void} handler - The callback function to invoke when the event occurs.\n * @returns {function(): boolean} A function to unsubscribe the event handler.\n * @example\n * const unsubscribe = emitter.on('user:login', (user) => console.log(user));\n * // Later...\n * unsubscribe(); // Stops listening for the event\n */\n on(event, handler) {\n if (!this._events.has(event)) this._events.set(event, new Set());\n\n this._events.get(event).add(handler);\n return () => this.off(event, handler);\n }\n\n /**\n * Removes an event handler for the specified event name.\n * If no handler is provided, all handlers for the event are removed.\n *\n * @public\n * @param {string} event - The name of the event.\n * @param {function(any): void} [handler] - The specific handler function to remove.\n * @returns {void}\n */\n off(event, handler) {\n if (!this._events.has(event)) return;\n if (handler) {\n const handlers = this._events.get(event);\n handlers.delete(handler);\n // Remove the event if there are no handlers left\n if (handlers.size === 0) this._events.delete(event);\n } else {\n this._events.delete(event);\n }\n }\n\n /**\n * Emits an event with the specified data to all registered handlers.\n * Handlers are called synchronously in the order they were registered.\n *\n * @public\n * @param {string} event - The name of the event to emit.\n * @param {...any} args - Optional arguments to pass to the event handlers.\n * @returns {void}\n */\n emit(event, ...args) {\n if (!this._events.has(event)) return;\n this._events.get(event).forEach((handler) => handler(...args));\n }\n}\n","\"use strict\";\n\n/**\n * @class 🎨 Renderer\n * @classdesc A DOM renderer that handles efficient DOM updates through patching and diffing.\n * Provides methods for updating the DOM by comparing new and old structures and applying\n * only the necessary changes, minimizing layout thrashing and improving performance.\n *\n * @example\n * const renderer = new Renderer();\n * const container = document.getElementById(\"app\");\n * const newHtml = \"<div>Updated content</div>\";\n * renderer.patchDOM(container, newHtml);\n */\nexport class Renderer {\n /**\n * Patches the DOM of a container element with new HTML content.\n * This method efficiently updates the DOM by comparing the new content with the existing\n * content and applying only the necessary changes.\n *\n * @public\n * @param {HTMLElement} container - The container element to patch.\n * @param {string} newHtml - The new HTML content to apply.\n * @returns {void}\n * @throws {Error} If container is not an HTMLElement or newHtml is not a string.\n */\n patchDOM(container, newHtml) {\n if (!(container instanceof HTMLElement)) {\n throw new Error(\"Container must be an HTMLElement\");\n }\n if (typeof newHtml !== \"string\") {\n throw new Error(\"newHtml must be a string\");\n }\n\n const temp = document.createElement(\"div\");\n temp.innerHTML = newHtml;\n this.diff(container, temp);\n temp.innerHTML = \"\";\n }\n\n /**\n * Diffs two DOM trees (old and new) and applies updates to the old DOM.\n * This method recursively compares nodes and their attributes, applying only\n * the necessary changes to minimize DOM operations.\n *\n * @private\n * @param {HTMLElement} oldParent - The original DOM element.\n * @param {HTMLElement} newParent - The new DOM element.\n * @returns {void}\n * @throws {Error} If either parent is not an HTMLElement.\n */\n diff(oldParent, newParent) {\n if (\n !(oldParent instanceof HTMLElement) ||\n !(newParent instanceof HTMLElement)\n ) {\n throw new Error(\"Both parents must be HTMLElements\");\n }\n\n if (oldParent.isEqualNode(newParent)) return;\n\n const oldC = oldParent.childNodes;\n const newC = newParent.childNodes;\n const len = Math.max(oldC.length, newC.length);\n const operations = [];\n\n for (let i = 0; i < len; i++) {\n const oldNode = oldC[i];\n const newNode = newC[i];\n\n if (!oldNode && newNode) {\n operations.push(() => oldParent.appendChild(newNode.cloneNode(true)));\n continue;\n }\n if (oldNode && !newNode) {\n operations.push(() => oldParent.removeChild(oldNode));\n continue;\n }\n\n const isSameType =\n oldNode.nodeType === newNode.nodeType &&\n oldNode.nodeName === newNode.nodeName;\n\n if (!isSameType) {\n operations.push(() =>\n oldParent.replaceChild(newNode.cloneNode(true), oldNode)\n );\n continue;\n }\n\n if (oldNode.nodeType === Node.ELEMENT_NODE) {\n const oldKey = oldNode.getAttribute(\"key\");\n const newKey = newNode.getAttribute(\"key\");\n\n if (oldKey !== newKey && (oldKey || newKey)) {\n operations.push(() =>\n oldParent.replaceChild(newNode.cloneNode(true), oldNode)\n );\n continue;\n }\n\n this.updateAttributes(oldNode, newNode);\n this.diff(oldNode, newNode);\n } else if (\n oldNode.nodeType === Node.TEXT_NODE &&\n oldNode.nodeValue !== newNode.nodeValue\n ) {\n oldNode.nodeValue = newNode.nodeValue;\n }\n }\n\n if (operations.length) {\n operations.forEach((op) => op());\n }\n }\n\n /**\n * Updates the attributes of an element to match those of a new element.\n * Handles special cases for ARIA attributes, data attributes, and boolean properties.\n *\n * @private\n * @param {HTMLElement} oldEl - The element to update.\n * @param {HTMLElement} newEl - The element providing the updated attributes.\n * @returns {void}\n * @throws {Error} If either element is not an HTMLElement.\n */\n updateAttributes(oldEl, newEl) {\n if (!(oldEl instanceof HTMLElement) || !(newEl instanceof HTMLElement)) {\n throw new Error(\"Both elements must be HTMLElements\");\n }\n\n const oldAttrs = oldEl.attributes;\n const newAttrs = newEl.attributes;\n const operations = [];\n\n // Remove old attributes\n for (const { name } of oldAttrs) {\n if (!name.startsWith(\"@\") && !newEl.hasAttribute(name)) {\n operations.push(() => oldEl.removeAttribute(name));\n }\n }\n\n // Update/add new attributes\n for (const attr of newAttrs) {\n const { name, value } = attr;\n if (name.startsWith(\"@\")) continue;\n\n if (oldEl.getAttribute(name) === value) continue;\n\n operations.push(() => {\n oldEl.setAttribute(name, value);\n\n if (name.startsWith(\"aria-\")) {\n const prop =\n \"aria\" +\n name.slice(5).replace(/-([a-z])/g, (_, l) => l.toUpperCase());\n oldEl[prop] = value;\n } else if (name.startsWith(\"data-\")) {\n oldEl.dataset[name.slice(5)] = value;\n } else {\n const prop = name.replace(/-([a-z])/g, (_, l) => l.toUpperCase());\n if (prop in oldEl) {\n const descriptor = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(oldEl),\n prop\n );\n const isBoolean =\n typeof oldEl[prop] === \"boolean\" ||\n (descriptor?.get &&\n typeof descriptor.get.call(oldEl) === \"boolean\");\n\n if (isBoolean) {\n oldEl[prop] =\n value !== \"false\" &&\n (value === \"\" || value === prop || value === \"true\");\n } else {\n oldEl[prop] = value;\n }\n }\n }\n });\n }\n\n if (operations.length) {\n operations.forEach((op) => op());\n }\n }\n}\n","\"use strict\";\n\nimport { TemplateEngine } from \"../modules/TemplateEngine.js\";\nimport { Signal } from \"../modules/Signal.js\";\nimport { Emitter } from \"../modules/Emitter.js\";\nimport { Renderer } from \"../modules/Renderer.js\";\n\n/**\n * @typedef {Object} ComponentDefinition\n * @property {function(Object<string, any>): (Object<string, any>|Promise<Object<string, any>>)} [setup]\n * Optional setup function that initializes the component's state and returns reactive data\n * @property {function(Object<string, any>): string} template\n * Required function that defines the component's HTML structure\n * @property {function(Object<string, any>): string} [style]\n * Optional function that provides component-scoped CSS styles\n * @property {Object<string, ComponentDefinition>} [children]\n * Optional object defining nested child components\n */\n\n/**\n * @typedef {Object} ElevaPlugin\n * @property {function(Eleva, Object<string, any>): void} install\n * Function that installs the plugin into the Eleva instance\n * @property {string} name\n * Unique identifier name for the plugin\n */\n\n/**\n * @typedef {Object} MountResult\n * @property {HTMLElement} container\n * The DOM element where the component is mounted\n * @property {Object<string, any>} data\n * The component's reactive state and context data\n * @property {function(): void} unmount\n * Function to clean up and unmount the component\n */\n\n/**\n * @class 🧩 Eleva\n * @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,\n * scoped styles, and plugin support. Eleva manages component registration, plugin integration,\n * event handling, and DOM rendering with a focus on performance and developer experience.\n *\n * @example\n * const app = new Eleva(\"myApp\");\n * app.component(\"myComponent\", {\n * template: (ctx) => `<div>Hello ${ctx.props.name}</div>`,\n * setup: (ctx) => ({ count: new Signal(0) })\n * });\n * app.mount(document.getElementById(\"app\"), \"myComponent\", { name: \"World\" });\n */\nexport class Eleva {\n /**\n * Creates a new Eleva instance with the specified name and configuration.\n *\n * @public\n * @param {string} name - The unique identifier name for this Eleva instance.\n * @param {Object<string, any>} [config={}] - Optional configuration object for the instance.\n * May include framework-wide settings and default behaviors.\n */\n constructor(name, config = {}) {\n /** @public {string} The unique identifier name for this Eleva instance */\n this.name = name;\n /** @public {Object<string, any>} Optional configuration object for the Eleva instance */\n this.config = config;\n /** @public {Emitter} Instance of the event emitter for handling component events */\n this.emitter = new Emitter();\n /** @public {typeof Signal} Static reference to the Signal class for creating reactive state */\n this.signal = Signal;\n /** @public {Renderer} Instance of the renderer for handling DOM updates and patching */\n this.renderer = new Renderer();\n\n /** @private {Map<string, ComponentDefinition>} Registry of all component definitions by name */\n this._components = new Map();\n /** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */\n this._plugins = new Map();\n /** @private {string[]} Array of lifecycle hook names supported by components */\n this._lifecycleHooks = [\n \"onBeforeMount\",\n \"onMount\",\n \"onBeforeUpdate\",\n \"onUpdate\",\n \"onUnmount\",\n ];\n /** @private {boolean} Flag indicating if the root component is currently mounted */\n this._isMounted = false;\n }\n\n /**\n * Integrates a plugin with the Eleva framework.\n * The plugin's install function will be called with the Eleva instance and provided options.\n * After installation, the plugin will be available for use by components.\n *\n * @public\n * @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.\n * @param {Object<string, any>} [options={}] - Optional configuration options for the plugin.\n * @returns {Eleva} The Eleva instance (for method chaining).\n * @example\n * app.use(myPlugin, { option1: \"value1\" });\n */\n use(plugin, options = {}) {\n plugin.install(this, options);\n this._plugins.set(plugin.name, plugin);\n\n return this;\n }\n\n /**\n * Registers a new component with the Eleva instance.\n * The component will be available for mounting using its registered name.\n *\n * @public\n * @param {string} name - The unique name of the component to register.\n * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.\n * @returns {Eleva} The Eleva instance (for method chaining).\n * @throws {Error} If the component name is already registered.\n * @example\n * app.component(\"myButton\", {\n * template: (ctx) => `<button>${ctx.props.text}</button>`,\n * style: () => \"button { color: blue; }\"\n * });\n */\n component(name, definition) {\n /** @type {Map<string, ComponentDefinition>} */\n this._components.set(name, definition);\n return this;\n }\n\n /**\n * Mounts a registered component to a DOM element.\n * This will initialize the component, set up its reactive state, and render it to the DOM.\n *\n * @public\n * @param {HTMLElement} container - The DOM element where the component will be mounted.\n * @param {string|ComponentDefinition} compName - The name of the registered component or a direct component definition.\n * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.\n * @returns {Promise<MountResult>}\n * A Promise that resolves to an object containing:\n * - container: The mounted component's container element\n * - data: The component's reactive state and context\n * - unmount: Function to clean up and unmount the component\n * @throws {Error} If the container is not found, or component is not registered.\n * @example\n * const instance = await app.mount(document.getElementById(\"app\"), \"myComponent\", { text: \"Click me\" });\n * // Later...\n * instance.unmount();\n */\n async mount(container, compName, props = {}) {\n if (!container) throw new Error(`Container not found: ${container}`);\n\n /** @type {ComponentDefinition} */\n const definition =\n typeof compName === \"string\" ? this._components.get(compName) : compName;\n if (!definition) throw new Error(`Component \"${compName}\" not registered.`);\n\n if (typeof definition.template !== \"function\")\n throw new Error(\"Component template must be a function\");\n\n /**\n * Destructure the component definition to access core functionality.\n * - setup: Optional function for component initialization and state management\n * - template: Required function that returns the component's HTML structure\n * - style: Optional function for component-scoped CSS styles\n * - children: Optional object defining nested child components\n */\n const { setup, template, style, children } = definition;\n\n /**\n * Creates the initial context object for the component instance.\n * This context provides core functionality and will be merged with setup data.\n * @type {Object<string, any>}\n * @property {Object<string, any>} props - Component properties passed during mounting\n * @property {Emitter} emitter - Event emitter instance for component event handling\n * @property {function(any): Signal} signal - Factory function to create reactive Signal instances\n * @property {Object<string, function(): void>} ...lifecycleHooks - Prepared lifecycle hook functions\n */\n const context = {\n props,\n emitter: this.emitter,\n /** @type {(v: any) => Signal} */\n signal: (v) => new this.signal(v),\n ...this._prepareLifecycleHooks(),\n };\n\n /**\n * Processes the mounting of the component.\n *\n * @param {Object<string, any>} data - Data returned from the component's setup function.\n * @returns {MountResult} An object with the container, merged context data, and an unmount function.\n */\n const processMount = (data) => {\n const mergedContext = { ...context, ...data };\n /** @type {Array<() => void>} */\n const watcherUnsubscribers = [];\n /** @type {Array<MountResult>} */\n const childInstances = [];\n /** @type {Array<() => void>} */\n const cleanupListeners = [];\n\n // Execute before hooks\n if (!this._isMounted) {\n mergedContext.onBeforeMount && mergedContext.onBeforeMount();\n } else {\n mergedContext.onBeforeUpdate && mergedContext.onBeforeUpdate();\n }\n\n /**\n * Renders the component by parsing the template, patching the DOM,\n * processing events, injecting styles, and mounting child components.\n */\n const render = () => {\n const newHtml = TemplateEngine.parse(\n template(mergedContext),\n mergedContext\n );\n this.renderer.patchDOM(container, newHtml);\n this._processEvents(container, mergedContext, cleanupListeners);\n this._injectStyles(container, compName, style, mergedContext);\n this._mountChildren(container, children, childInstances);\n\n if (!this._isMounted) {\n mergedContext.onMount && mergedContext.onMount();\n this._isMounted = true;\n } else {\n mergedContext.onUpdate && mergedContext.onUpdate();\n }\n };\n\n /**\n * Sets up reactive watchers for all Signal instances in the component's data.\n * When a Signal's value changes, the component will re-render to reflect the updates.\n * Stores unsubscribe functions to clean up watchers when component unmounts.\n */\n for (const val of Object.values(data)) {\n if (val instanceof Signal) watcherUnsubscribers.push(val.watch(render));\n }\n\n render();\n\n return {\n container,\n data: mergedContext,\n /**\n * Unmounts the component, cleaning up watchers and listeners, child components, and clearing the container.\n *\n * @returns {void}\n */\n unmount: () => {\n for (const fn of watcherUnsubscribers) fn();\n for (const fn of cleanupListeners) fn();\n for (const child of childInstances) child.unmount();\n mergedContext.onUnmount && mergedContext.onUnmount();\n container.innerHTML = \"\";\n },\n };\n };\n\n // Handle asynchronous setup.\n return Promise.resolve(\n typeof setup === \"function\" ? setup(context) : {}\n ).then(processMount);\n }\n\n /**\n * Prepares default no-operation lifecycle hook functions for a component.\n * These hooks will be called at various stages of the component's lifecycle.\n *\n * @private\n * @returns {Object<string, function(): void>} An object mapping lifecycle hook names to empty functions.\n * The returned object will be merged with the component's context.\n */\n _prepareLifecycleHooks() {\n /** @type {Object<string, () => void>} */\n const hooks = {};\n for (const hook of this._lifecycleHooks) {\n hooks[hook] = () => {};\n }\n return hooks;\n }\n\n /**\n * Processes DOM elements for event binding based on attributes starting with \"@\".\n * This method handles the event delegation system and ensures proper cleanup of event listeners.\n *\n * @private\n * @param {HTMLElement} container - The container element in which to search for event attributes.\n * @param {Object<string, any>} context - The current component context containing event handler definitions.\n * @param {Array<Function>} cleanupListeners - Array to collect cleanup functions for each event listener.\n * @returns {void}\n */\n _processEvents(container, context, cleanupListeners) {\n const elements = container.querySelectorAll(\"*\");\n for (const el of elements) {\n const attrs = el.attributes;\n for (let i = 0; i < attrs.length; i++) {\n const attr = attrs[i];\n if (attr.name.startsWith(\"@\")) {\n const event = attr.name.slice(1);\n const handler = TemplateEngine.evaluate(attr.value, context);\n if (typeof handler === \"function\") {\n el.addEventListener(event, handler);\n el.removeAttribute(attr.name);\n cleanupListeners.push(() => el.removeEventListener(event, handler));\n }\n }\n }\n }\n }\n\n /**\n * Injects scoped styles into the component's container.\n * The styles are automatically prefixed to prevent style leakage to other components.\n *\n * @private\n * @param {HTMLElement} container - The container element where styles should be injected.\n * @param {string} compName - The component name used to identify the style element.\n * @param {function(Object<string, any>): string} [styleFn] - Optional function that returns CSS styles as a string.\n * @param {Object<string, any>} context - The current component context for style interpolation.\n * @returns {void}\n */\n _injectStyles(container, compName, styleFn, context) {\n if (!styleFn) return;\n\n let styleEl = container.querySelector(\n `style[data-eleva-style=\"${compName}\"]`\n );\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.setAttribute(\"data-eleva-style\", compName);\n container.appendChild(styleEl);\n }\n styleEl.textContent = TemplateEngine.parse(styleFn(context), context);\n }\n\n /**\n * Mounts child components within the parent component's container.\n * This method handles the recursive mounting of nested components.\n *\n * @private\n * @param {HTMLElement} container - The parent container element.\n * @param {Object<string, ComponentDefinition>} [children] - Object mapping of child component selectors to their definitions.\n * @param {Array<MountResult>} childInstances - Array to store the mounted child component instances.\n * @returns {void}\n */\n async _mountChildren(container, children, childInstances) {\n for (const child of childInstances) child.unmount();\n childInstances.length = 0;\n\n if (!children) return;\n\n for (const childSelector of Object.keys(children)) {\n if (!childSelector) continue;\n\n for (const childEl of container.querySelectorAll(childSelector)) {\n if (!(childEl instanceof HTMLElement)) continue;\n const props = {};\n for (const { name, value } of [...childEl.attributes]) {\n if (name.startsWith(\"eleva-prop-\")) {\n props[name.replace(\"eleva-prop-\", \"\")] = value;\n }\n }\n const instance = await this.mount(\n childEl,\n children[childSelector],\n props\n );\n childInstances.push(instance);\n }\n }\n }\n}\n"],"names":["TemplateEngine","expressionPattern","parse","template","data","replace","_","expression","evaluate","Function","Signal","constructor","value","_value","_watchers","Set","_pending","newVal","_notifyWatchers","watch","fn","add","delete","queueMicrotask","forEach","Emitter","_events","Map","on","event","handler","has","set","get","off","handlers","size","emit","args","Renderer","patchDOM","container","newHtml","HTMLElement","Error","temp","document","createElement","innerHTML","diff","oldParent","newParent","isEqualNode","oldC","childNodes","newC","len","Math","max","length","operations","i","oldNode","newNode","push","appendChild","cloneNode","removeChild","isSameType","nodeType","nodeName","replaceChild","Node","ELEMENT_NODE","oldKey","getAttribute","newKey","updateAttributes","TEXT_NODE","nodeValue","op","oldEl","newEl","oldAttrs","attributes","newAttrs","name","startsWith","hasAttribute","removeAttribute","attr","setAttribute","prop","slice","l","toUpperCase","dataset","descriptor","Object","getOwnPropertyDescriptor","getPrototypeOf","isBoolean","call","Eleva","config","emitter","signal","renderer","_components","_plugins","_lifecycleHooks","_isMounted","use","plugin","options","install","component","definition","mount","compName","props","setup","style","children","context","v","_prepareLifecycleHooks","processMount","mergedContext","watcherUnsubscribers","childInstances","cleanupListeners","onBeforeMount","onBeforeUpdate","render","_processEvents","_injectStyles","_mountChildren","onMount","onUpdate","val","values","unmount","child","onUnmount","Promise","resolve","then","hooks","hook","elements","querySelectorAll","el","attrs","addEventListener","removeEventListener","styleFn","styleEl","querySelector","textContent","childSelector","keys","childEl","instance"],"mappings":";;;;;;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACO,MAAMA,cAAc,CAAC;EAC1B;EACF;EACA;IACE,OAAOC,iBAAiB,GAAG,sBAAsB;;EAEjD;EACF;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACE,EAAA,OAAOC,KAAKA,CAACC,QAAQ,EAAEC,IAAI,EAAE;EAC3B,IAAA,IAAI,OAAOD,Q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+1,23 @@
1
1
  {
2
2
  "name": "eleva",
3
- "version": "1.2.7-alpha",
3
+ "version": "1.2.8-alpha",
4
4
  "description": "A minimalist and lightweight, pure vanilla JavaScript frontend runtime framework.",
5
5
  "type": "module",
6
- "main": "dist/eleva.js",
6
+ "main": "dist/eleva.cjs.js",
7
7
  "module": "dist/eleva.esm.js",
8
+ "umd": "dist/eleva.umd.js",
9
+ "browser": "dist/eleva.min.js",
8
10
  "unpkg": "dist/eleva.min.js",
9
11
  "types": "dist/eleva.d.ts",
10
12
  "exports": {
11
13
  ".": {
12
- "require": "./dist/eleva.js",
14
+ "types": "./dist/eleva.d.ts",
15
+ "node": "./dist/eleva.cjs.js",
16
+ "require": "./dist/eleva.cjs.js",
13
17
  "import": "./dist/eleva.esm.js",
14
- "types": "./dist/eleva.d.ts"
18
+ "browser": "./dist/eleva.min.js",
19
+ "umd": "./dist/eleva.umd.js",
20
+ "default": "./dist/eleva.esm.js"
15
21
  }
16
22
  },
17
23
  "scripts": {
@@ -73,7 +79,6 @@
73
79
  "rimraf": "^6.0.1",
74
80
  "rollup": "^4.34.8",
75
81
  "rollup-plugin-dts": "^6.1.1",
76
- "size-limit": "^11.2.0",
77
82
  "typescript": "^5.1.6",
78
83
  "vitepress": "^1.6.3"
79
84
  },
@@ -88,14 +93,6 @@
88
93
  "pre-commit": "lint-staged"
89
94
  }
90
95
  },
91
- "size-limit": [
92
- {
93
- "limit": "6 kB",
94
- "path": "dist/eleva.min.js",
95
- "name": "eleva",
96
- "brotli": true
97
- }
98
- ],
99
96
  "keywords": [
100
97
  "modern javascript framework",
101
98
  "lightweight JavaScript framework",
package/src/core/Eleva.js CHANGED
@@ -6,51 +6,75 @@ import { Emitter } from "../modules/Emitter.js";
6
6
  import { Renderer } from "../modules/Renderer.js";
7
7
 
8
8
  /**
9
- * Defines the structure and behavior of a component.
10
9
  * @typedef {Object} ComponentDefinition
11
10
  * @property {function(Object<string, any>): (Object<string, any>|Promise<Object<string, any>>)} [setup]
12
- * Optional setup function that initializes the component's reactive state and lifecycle.
13
- * Receives props and context as an argument and should return an object containing the component's state.
14
- * Can return either a synchronous object or a Promise that resolves to an object for async initialization.
15
- *
11
+ * Optional setup function that initializes the component's state and returns reactive data
16
12
  * @property {function(Object<string, any>): string} template
17
- * Required function that defines the component's HTML structure.
18
- * Receives the merged context (props + setup data) and must return an HTML template string.
19
- * Supports dynamic expressions using {{ }} syntax for reactive data binding.
20
- *
13
+ * Required function that defines the component's HTML structure
21
14
  * @property {function(Object<string, any>): string} [style]
22
- * Optional function that defines component-scoped CSS styles.
23
- * Receives the merged context and returns a CSS string that will be automatically scoped to the component.
24
- * Styles are injected into the component's container and only affect elements within it.
25
- *
15
+ * Optional function that provides component-scoped CSS styles
26
16
  * @property {Object<string, ComponentDefinition>} [children]
27
- * Optional object that defines nested child components.
28
- * Keys are CSS selectors that match elements in the template where child components should be mounted.
29
- * Values are ComponentDefinition objects that define the structure and behavior of each child component.
17
+ * Optional object defining nested child components
18
+ */
19
+
20
+ /**
21
+ * @typedef {Object} ElevaPlugin
22
+ * @property {function(Eleva, Object<string, any>): void} install
23
+ * Function that installs the plugin into the Eleva instance
24
+ * @property {string} name
25
+ * Unique identifier name for the plugin
26
+ */
27
+
28
+ /**
29
+ * @typedef {Object} MountResult
30
+ * @property {HTMLElement} container
31
+ * The DOM element where the component is mounted
32
+ * @property {Object<string, any>} data
33
+ * The component's reactive state and context data
34
+ * @property {function(): void} unmount
35
+ * Function to clean up and unmount the component
30
36
  */
31
37
 
32
38
  /**
33
39
  * @class 🧩 Eleva
34
- * @classdesc Signal-based component runtime framework with lifecycle hooks, scoped styles, and plugin support.
35
- * Manages component registration, plugin integration, event handling, and DOM rendering.
40
+ * @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,
41
+ * scoped styles, and plugin support. Eleva manages component registration, plugin integration,
42
+ * event handling, and DOM rendering with a focus on performance and developer experience.
43
+ *
44
+ * @example
45
+ * const app = new Eleva("myApp");
46
+ * app.component("myComponent", {
47
+ * template: (ctx) => `<div>Hello ${ctx.props.name}</div>`,
48
+ * setup: (ctx) => ({ count: new Signal(0) })
49
+ * });
50
+ * app.mount(document.getElementById("app"), "myComponent", { name: "World" });
36
51
  */
37
52
  export class Eleva {
38
53
  /**
39
- * Creates a new Eleva instance.
54
+ * Creates a new Eleva instance with the specified name and configuration.
40
55
  *
41
- * @param {string} name - The name of the Eleva instance.
42
- * @param {Object<string, any>} [config={}] - Optional configuration for the instance.
56
+ * @public
57
+ * @param {string} name - The unique identifier name for this Eleva instance.
58
+ * @param {Object<string, any>} [config={}] - Optional configuration object for the instance.
59
+ * May include framework-wide settings and default behaviors.
43
60
  */
44
61
  constructor(name, config = {}) {
45
- /** @type {string} The unique identifier name for this Eleva instance */
62
+ /** @public {string} The unique identifier name for this Eleva instance */
46
63
  this.name = name;
47
- /** @type {Object<string, any>} Optional configuration object for the Eleva instance */
64
+ /** @public {Object<string, any>} Optional configuration object for the Eleva instance */
48
65
  this.config = config;
49
- /** @type {Object<string, ComponentDefinition>} Object storing registered component definitions by name */
50
- this._components = {};
51
- /** @private {Array<Object>} Collection of installed plugin instances */
52
- this._plugins = [];
53
- /** @private {string[]} Array of lifecycle hook names supported by the component */
66
+ /** @public {Emitter} Instance of the event emitter for handling component events */
67
+ this.emitter = new Emitter();
68
+ /** @public {typeof Signal} Static reference to the Signal class for creating reactive state */
69
+ this.signal = Signal;
70
+ /** @public {Renderer} Instance of the renderer for handling DOM updates and patching */
71
+ this.renderer = new Renderer();
72
+
73
+ /** @private {Map<string, ComponentDefinition>} Registry of all component definitions by name */
74
+ this._components = new Map();
75
+ /** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */
76
+ this._plugins = new Map();
77
+ /** @private {string[]} Array of lifecycle hook names supported by components */
54
78
  this._lifecycleHooks = [
55
79
  "onBeforeMount",
56
80
  "onMount",
@@ -58,57 +82,75 @@ export class Eleva {
58
82
  "onUpdate",
59
83
  "onUnmount",
60
84
  ];
61
- /** @private {boolean} Flag indicating if component is currently mounted */
85
+ /** @private {boolean} Flag indicating if the root component is currently mounted */
62
86
  this._isMounted = false;
63
- /** @private {Emitter} Instance of the event emitter for handling component events */
64
- this.emitter = new Emitter();
65
- /** @private {Signal} Instance of the signal for handling plugin and component signals */
66
- this.signal = Signal;
67
- /** @private {Renderer} Instance of the renderer for handling DOM updates and patching */
68
- this.renderer = new Renderer();
69
87
  }
70
88
 
71
89
  /**
72
90
  * Integrates a plugin with the Eleva framework.
91
+ * The plugin's install function will be called with the Eleva instance and provided options.
92
+ * After installation, the plugin will be available for use by components.
73
93
  *
74
- * @param {Object} plugin - The plugin object which should have an `install` function.
75
- * @param {Object<string, any>} [options={}] - Optional options to pass to the plugin.
76
- * @returns {Eleva} The Eleva instance (for chaining).
94
+ * @public
95
+ * @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.
96
+ * @param {Object<string, any>} [options={}] - Optional configuration options for the plugin.
97
+ * @returns {Eleva} The Eleva instance (for method chaining).
98
+ * @example
99
+ * app.use(myPlugin, { option1: "value1" });
77
100
  */
78
101
  use(plugin, options = {}) {
79
- if (typeof plugin.install === "function") {
80
- plugin.install(this, options);
81
- }
82
- this._plugins.push(plugin);
102
+ plugin.install(this, options);
103
+ this._plugins.set(plugin.name, plugin);
104
+
83
105
  return this;
84
106
  }
85
107
 
86
108
  /**
87
- * Registers a component with the Eleva instance.
109
+ * Registers a new component with the Eleva instance.
110
+ * The component will be available for mounting using its registered name.
88
111
  *
89
- * @param {string} name - The name of the component.
112
+ * @public
113
+ * @param {string} name - The unique name of the component to register.
90
114
  * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
91
- * @returns {Eleva} The Eleva instance (for chaining).
115
+ * @returns {Eleva} The Eleva instance (for method chaining).
116
+ * @throws {Error} If the component name is already registered.
117
+ * @example
118
+ * app.component("myButton", {
119
+ * template: (ctx) => `<button>${ctx.props.text}</button>`,
120
+ * style: () => "button { color: blue; }"
121
+ * });
92
122
  */
93
123
  component(name, definition) {
94
- this._components[name] = definition;
124
+ /** @type {Map<string, ComponentDefinition>} */
125
+ this._components.set(name, definition);
95
126
  return this;
96
127
  }
97
128
 
98
129
  /**
99
130
  * Mounts a registered component to a DOM element.
131
+ * This will initialize the component, set up its reactive state, and render it to the DOM.
100
132
  *
101
- * @param {HTMLElement} container - A DOM element where the component will be mounted.
102
- * @param {string|ComponentDefinition} compName - The name of the component to mount or a component definition.
133
+ * @public
134
+ * @param {HTMLElement} container - The DOM element where the component will be mounted.
135
+ * @param {string|ComponentDefinition} compName - The name of the registered component or a direct component definition.
103
136
  * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.
104
- * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.
105
- * @throws {Error} If the container is not found or if the component is not registered.
137
+ * @returns {Promise<MountResult>}
138
+ * A Promise that resolves to an object containing:
139
+ * - container: The mounted component's container element
140
+ * - data: The component's reactive state and context
141
+ * - unmount: Function to clean up and unmount the component
142
+ * @throws {Error} If the container is not found, or component is not registered.
143
+ * @example
144
+ * const instance = await app.mount(document.getElementById("app"), "myComponent", { text: "Click me" });
145
+ * // Later...
146
+ * instance.unmount();
106
147
  */
107
- mount(container, compName, props = {}) {
148
+ async mount(container, compName, props = {}) {
108
149
  if (!container) throw new Error(`Container not found: ${container}`);
109
150
 
151
+ /** @type {ComponentDefinition} */
110
152
  const definition =
111
- typeof compName === "string" ? this._components[compName] : compName;
153
+ typeof compName === "string" ? this._components.get(compName) : compName;
112
154
  if (!definition) throw new Error(`Component "${compName}" not registered.`);
113
155
 
114
156
  if (typeof definition.template !== "function")
@@ -135,6 +177,7 @@ export class Eleva {
135
177
  const context = {
136
178
  props,
137
179
  emitter: this.emitter,
180
+ /** @type {(v: any) => Signal} */
138
181
  signal: (v) => new this.signal(v),
139
182
  ...this._prepareLifecycleHooks(),
140
183
  };
@@ -143,12 +186,15 @@ export class Eleva {
143
186
  * Processes the mounting of the component.
144
187
  *
145
188
  * @param {Object<string, any>} data - Data returned from the component's setup function.
146
- * @returns {object} An object with the container, merged context data, and an unmount function.
189
+ * @returns {MountResult} An object with the container, merged context data, and an unmount function.
147
190
  */
148
191
  const processMount = (data) => {
149
192
  const mergedContext = { ...context, ...data };
193
+ /** @type {Array<() => void>} */
150
194
  const watcherUnsubscribers = [];
195
+ /** @type {Array<MountResult>} */
151
196
  const childInstances = [];
197
+ /** @type {Array<() => void>} */
152
198
  const cleanupListeners = [];
153
199
 
154
200
  // Execute before hooks
@@ -185,9 +231,9 @@ export class Eleva {
185
231
  * When a Signal's value changes, the component will re-render to reflect the updates.
186
232
  * Stores unsubscribe functions to clean up watchers when component unmounts.
187
233
  */
188
- Object.values(data).forEach((val) => {
234
+ for (const val of Object.values(data)) {
189
235
  if (val instanceof Signal) watcherUnsubscribers.push(val.watch(render));
190
- });
236
+ }
191
237
 
192
238
  render();
193
239
 
@@ -200,9 +246,9 @@ export class Eleva {
200
246
  * @returns {void}
201
247
  */
202
248
  unmount: () => {
203
- watcherUnsubscribers.forEach((fn) => fn());
204
- cleanupListeners.forEach((fn) => fn());
205
- childInstances.forEach((child) => child.unmount());
249
+ for (const fn of watcherUnsubscribers) fn();
250
+ for (const fn of cleanupListeners) fn();
251
+ for (const child of childInstances) child.unmount();
206
252
  mergedContext.onUnmount && mergedContext.onUnmount();
207
253
  container.innerHTML = "";
208
254
  },
@@ -216,26 +262,31 @@ export class Eleva {
216
262
  }
217
263
 
218
264
  /**
219
- * Prepares default no-operation lifecycle hook functions.
265
+ * Prepares default no-operation lifecycle hook functions for a component.
266
+ * These hooks will be called at various stages of the component's lifecycle.
220
267
  *
221
- * @returns {Object<string, function(): void>} An object with keys for lifecycle hooks mapped to empty functions.
222
268
  * @private
269
+ * @returns {Object<string, function(): void>} An object mapping lifecycle hook names to empty functions.
270
+ * The returned object will be merged with the component's context.
223
271
  */
224
272
  _prepareLifecycleHooks() {
225
- return this._lifecycleHooks.reduce((acc, hook) => {
226
- acc[hook] = () => {};
227
- return acc;
228
- }, {});
273
+ /** @type {Object<string, () => void>} */
274
+ const hooks = {};
275
+ for (const hook of this._lifecycleHooks) {
276
+ hooks[hook] = () => {};
277
+ }
278
+ return hooks;
229
279
  }
230
280
 
231
281
  /**
232
282
  * Processes DOM elements for event binding based on attributes starting with "@".
233
- * Tracks listeners for cleanup during unmount.
283
+ * This method handles the event delegation system and ensures proper cleanup of event listeners.
234
284
  *
235
- * @param {HTMLElement} container - The container element in which to search for events.
236
- * @param {Object<string, any>} context - The current context containing event handler definitions.
237
- * @param {Array<Function>} cleanupListeners - Array to collect cleanup functions for each event listener.
238
285
  * @private
286
+ * @param {HTMLElement} container - The container element in which to search for event attributes.
287
+ * @param {Object<string, any>} context - The current component context containing event handler definitions.
288
+ * @param {Array<Function>} cleanupListeners - Array to collect cleanup functions for each event listener.
289
+ * @returns {void}
239
290
  */
240
291
  _processEvents(container, context, cleanupListeners) {
241
292
  const elements = container.querySelectorAll("*");
@@ -258,12 +309,14 @@ export class Eleva {
258
309
 
259
310
  /**
260
311
  * Injects scoped styles into the component's container.
312
+ * The styles are automatically prefixed to prevent style leakage to other components.
261
313
  *
262
- * @param {HTMLElement} container - The container element.
263
- * @param {string} compName - The component name used to identify the style element.
264
- * @param {function(Object<string, any>): string} [styleFn] - A function that returns CSS styles as a string.
265
- * @param {Object<string, any>} context - The current context for style interpolation.
266
314
  * @private
315
+ * @param {HTMLElement} container - The container element where styles should be injected.
316
+ * @param {string} compName - The component name used to identify the style element.
317
+ * @param {function(Object<string, any>): string} [styleFn] - Optional function that returns CSS styles as a string.
318
+ * @param {Object<string, any>} context - The current component context for style interpolation.
319
+ * @returns {void}
267
320
  */
268
321
  _injectStyles(container, compName, styleFn, context) {
269
322
  if (!styleFn) return;
@@ -281,27 +334,38 @@ export class Eleva {
281
334
 
282
335
  /**
283
336
  * Mounts child components within the parent component's container.
337
+ * This method handles the recursive mounting of nested components.
284
338
  *
285
- * @param {HTMLElement} container - The parent container element.
286
- * @param {Object<string, ComponentDefinition>} [children] - An object mapping child component selectors to their definitions.
287
- * @param {Array<object>} childInstances - An array to store the mounted child component instances.
288
339
  * @private
340
+ * @param {HTMLElement} container - The parent container element.
341
+ * @param {Object<string, ComponentDefinition>} [children] - Object mapping of child component selectors to their definitions.
342
+ * @param {Array<MountResult>} childInstances - Array to store the mounted child component instances.
343
+ * @returns {void}
289
344
  */
290
- _mountChildren(container, children, childInstances) {
291
- childInstances.forEach((child) => child.unmount());
345
+ async _mountChildren(container, children, childInstances) {
346
+ for (const child of childInstances) child.unmount();
292
347
  childInstances.length = 0;
293
348
 
294
- Object.keys(children || {}).forEach((childSelector) => {
295
- container.querySelectorAll(childSelector).forEach((childEl) => {
349
+ if (!children) return;
350
+
351
+ for (const childSelector of Object.keys(children)) {
352
+ if (!childSelector) continue;
353
+
354
+ for (const childEl of container.querySelectorAll(childSelector)) {
355
+ if (!(childEl instanceof HTMLElement)) continue;
296
356
  const props = {};
297
- [...childEl.attributes].forEach(({ name, value }) => {
357
+ for (const { name, value } of [...childEl.attributes]) {
298
358
  if (name.startsWith("eleva-prop-")) {
299
359
  props[name.replace("eleva-prop-", "")] = value;
300
360
  }
301
- });
302
- const instance = this.mount(childEl, children[childSelector], props);
361
+ }
362
+ const instance = await this.mount(
363
+ childEl,
364
+ children[childSelector],
365
+ props
366
+ );
303
367
  childInstances.push(instance);
304
- });
305
- });
368
+ }
369
+ }
306
370
  }
307
371
  }