humn 1.3.4 → 1.4.0

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.
package/dist/humn.js CHANGED
@@ -1,5 +1,5 @@
1
1
  let N = null, x = null;
2
- const M = () => N, b = (t) => {
2
+ const j = () => N, v = (t) => {
3
3
  N = t;
4
4
  }, S = () => x, w = (t) => {
5
5
  x = t;
@@ -8,8 +8,8 @@ class T {
8
8
  constructor({ memory: e, synapses: r }) {
9
9
  const o = { ...e };
10
10
  this._persistenceMap = /* @__PURE__ */ new Map();
11
- for (const [n, s] of Object.entries(e)) if (s && s.__humn_persist) {
12
- const c = s.config.key || n;
11
+ for (const [n, s] of Object.entries(e)) if (s && typeof s == "object" && s.__humn_persist) {
12
+ const c = s.config?.key || n;
13
13
  this._persistenceMap.set(n, c);
14
14
  try {
15
15
  const i = localStorage.getItem(c);
@@ -59,7 +59,7 @@ class T {
59
59
  } });
60
60
  }
61
61
  get memory() {
62
- const e = M();
62
+ const e = j();
63
63
  if (!e) return this._memory;
64
64
  this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
65
65
  const r = this._listeners.get(e);
@@ -136,7 +136,7 @@ function A(t, e = {}, r = {}) {
136
136
  else t.removeAttribute(n);
137
137
  }
138
138
  }
139
- function j(t, e, r) {
139
+ function M(t, e, r) {
140
140
  if (!(E(e) || E(r))) {
141
141
  const o = Math.max(e.length, r.length);
142
142
  for (let n = 0; n < o; n++) m(t, e[n], r[n], n);
@@ -152,8 +152,8 @@ function j(t, e, r) {
152
152
  if (k) {
153
153
  const h = k.vNode;
154
154
  m(o, i, h, l);
155
- const u = i.el || h.el, v = o.childNodes[l];
156
- u && v !== u && o.insertBefore(u, v), delete c[a];
155
+ const u = i.el || h.el, b = o.childNodes[l];
156
+ u && b !== u && o.insertBefore(u, b), delete c[a];
157
157
  } else {
158
158
  const h = f(i, y(o)), u = o.childNodes[l];
159
159
  u ? o.insertBefore(h, u) : o.appendChild(h);
@@ -196,14 +196,14 @@ function m(t, e, r, o = 0) {
196
196
  return;
197
197
  }
198
198
  const n = r.el || t.childNodes[o];
199
- n && (e.el = n, A(n, e.props, r.props), j(n, e.children, r.children));
199
+ n && (e.el = n, A(n, e.props, r.props), M(n, e.children, r.children));
200
200
  }
201
201
  const R = (t, e) => {
202
202
  let r = null;
203
203
  const o = () => {
204
- b(o);
204
+ v(o);
205
205
  const n = { tag: e, props: {}, children: [] };
206
- m(t, n, r), b(null), r = n;
206
+ m(t, n, r), v(null), r = n;
207
207
  };
208
208
  o();
209
209
  }, W = (t, e = {}) => ({ __humn_persist: !0, initial: t, config: e });
package/dist/humn.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"humn.js","sources":["../src/observer.js","../src/cortex.js","../src/css.js","../src/h.js","../src/lifecycle.js","../src/patch.js","../src/mount.js","../src/persist.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null // For Cortex/State dependency\nlet currentInstance = null // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs\n}\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst\n}\n","import { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * @typedef {object} Synapses\n * @property {function} set - Function to update the memory\n * @property {function} get - Function to get the memory\n */\n\n/**\n * @typedef {object} CortexParams\n * @property {object} memory - The initial state\n * @property {function(function, function): object} synapses - The synapses function\n */\n\n/**\n * The Cortex class manages the state of the application.\n * This uses a Proxy for fine-grained reactivity, ensuring only those components\n * which use the updated value get re-rendered.\n *\n * WHY: We use Proxies instead of simple getters/setters because it allows us to\n * detect access to nested properties dynamically without needing to declare\n * dependencies upfront. This \"magic\" auto-subscription is what makes Humn's\n * DX so clean.\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexParams} CortexParams - The parameters for the Cortex.\n */\n constructor({ memory, synapses }) {\n const liveMemory = { ...memory }\n this._persistenceMap = new Map()\n\n // Load in any existing values from local-storage\n for (const [key, value] of Object.entries(memory)) {\n if (value && value.__humn_persist) {\n const storageKey = value.config.key || key\n this._persistenceMap.set(key, storageKey)\n\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored !== null) {\n liveMemory[key] = JSON.parse(stored)\n } else {\n liveMemory[key] = value.initial\n }\n } catch (err) {\n if (isDev)\n console.warn(`Humn: Failed to load '${key}' from storage.`, err)\n liveMemory[key] = value.initial\n }\n }\n }\n\n this._memory = liveMemory\n this._listeners = new Map()\n\n const get = () => this._memory\n\n const set = (updater) => {\n let nextState\n let changedPaths = new Set()\n\n if (typeof updater === 'function') {\n const clone = structuredClone(this._memory)\n const proxy = this._createChangeTrackingProxy(clone, changedPaths)\n const result = updater(proxy)\n\n if (result && typeof result === 'object') {\n nextState = { ...this._memory, ...result }\n Object.keys(result).forEach((key) => changedPaths.add(key))\n } else {\n nextState = clone\n }\n } else {\n nextState = { ...this._memory, ...updater }\n changedPaths = new Set(Object.keys(updater))\n }\n\n this._memory = nextState\n\n // If we need to persist any of the values\n // we save them to localStorage here\n if (this._persistenceMap.size > 0) {\n this._persistenceMap.forEach((storageKey, stateKey) => {\n const isDirty = Array.from(changedPaths).some(\n (path) => path === stateKey || path.startsWith(stateKey + '.'),\n )\n\n if (isDirty) {\n try {\n const value = this._memory[stateKey]\n localStorage.setItem(storageKey, JSON.stringify(value))\n } catch (err) {\n if (isDev)\n console.error(`Humn: Failed to save '${stateKey}'.`, err)\n }\n }\n })\n }\n\n this._notifyRelevantListeners(changedPaths)\n }\n\n this.synapses = synapses(set, get)\n }\n\n /**\n * Creates a Proxy that tracks which properties are being mutated.\n * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.\n *\n * WHY: We need to know exactly which paths were changed so we can notify ONLY\n * the components that care about those specific paths. If we just knew \"something changed\",\n * we'd have to re-render the whole app (like Redux) or rely on manual optimization.\n */\n _createChangeTrackingProxy(obj, changedPaths, path = '') {\n return new Proxy(obj, {\n get: (target, prop) => {\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const value = target[prop]\n const fullPath = path ? `${path}.${prop}` : prop\n\n // Recursively proxy nested objects so we can trap their sets too\n if (typeof value === 'object' && value !== null) {\n return this._createChangeTrackingProxy(value, changedPaths, fullPath)\n }\n return value\n },\n set: (target, prop, value) => {\n if (typeof prop === 'symbol' || prop === '__proto__') {\n target[prop] = value\n return true\n }\n\n const fullPath = path ? `${path}.${prop}` : prop\n changedPaths.add(fullPath)\n\n target[prop] = value\n return true\n },\n })\n }\n\n /**\n * Only notify listeners that read properties which changed\n */\n _notifyRelevantListeners(changedPaths) {\n this._listeners.forEach((accessedPaths, renderFn) => {\n const shouldNotify = Array.from(accessedPaths).some((accessedPath) => {\n return Array.from(changedPaths).some((changedPath) => {\n // Check for exact match or parent/child relationship\n return (\n accessedPath === changedPath ||\n accessedPath.startsWith(changedPath + '.') ||\n changedPath.startsWith(accessedPath + '.')\n )\n })\n })\n\n if (shouldNotify) renderFn()\n })\n }\n\n /**\n * Creates a Proxy that tracks which properties are accessed during render\n *\n * WHY: This is the other half of the magic. By tracking what a component READS\n * during its render, we build a precise dependency graph. If a component reads\n * `state.user.name`, it will only re-render when `state.user.name` changes,\n * not when `state.count` changes.\n */\n _createAccessTrackingProxy(obj, accessedPaths, path = '') {\n if (typeof obj !== 'object' || obj === null) return obj\n\n return new Proxy(obj, {\n get: (target, prop) => {\n // We don't care about prototype and symbol properties\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const fullPath = path ? `${path}.${prop}` : prop\n accessedPaths.add(fullPath)\n\n const value = target[prop]\n\n // Recursively wrap nested objects\n if (typeof value === 'object' && value !== null)\n return this._createAccessTrackingProxy(value, accessedPaths, fullPath)\n\n return value\n },\n })\n }\n\n /**\n * Returns memory wrapped in a tracking Proxy\n */\n get memory() {\n const currentObserver = getObserver()\n\n if (!currentObserver) return this._memory\n\n if (!this._listeners.has(currentObserver))\n this._listeners.set(currentObserver, new Set())\n\n const accessedPaths = this._listeners.get(currentObserver)\n\n return this._createAccessTrackingProxy(this._memory, accessedPaths)\n }\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null\nconst cache = new Set()\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381\n let i = str.length\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i)\n }\n return (hash >>> 0).toString(36)\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse newlines/tabs to single space\n .trim() // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n * Supports two signatures:\n * 1. Tagged Template: css`...`\n * 2. Function: css(string, isSingleRoot)\n */\nexport function css(stringsOrStr, ...args) {\n let raw = ''\n let isSingleRoot = false\n\n // Detect usage of Tagged Template vs Function Call\n if (Array.isArray(stringsOrStr) && stringsOrStr.raw) {\n raw = stringsOrStr.reduce((acc, str, i) => {\n return acc + str + (args[i] || '')\n }, '')\n } else {\n raw = stringsOrStr\n // If called as function, the first arg is our boolean flag\n isSingleRoot = args[0] === true\n }\n let content = minify(raw)\n\n if (!content) return ''\n\n if (isSingleRoot) {\n // Transforms selectors to apply to BOTH the root (using &) AND descendants.\n // e.g. \"div\" -> \"div&, div\"\n\n // Regex Breakdown:\n // 1. (^|[{};,]) -> Hard Start (Line start, brace, semi, comma)\n // 2. (\\s*) -> Whitespace\n // 3. (?!from|to) -> Negative Lookahead: Ignore 'from'/'to' (keyframes)\n // 4. ( ... )+ -> Compound Selector:\n // (?:[.#]?[\\w-]+ ... ) -> Matches tags (div), classes (.class), ids (#id)\n // 5. (?=\\s*\\{) -> Lookahead: Must be followed by {\n\n content = content.replace(\n /(^|[{};,])(\\s*)(?!from|to)((?:[.#]?[\\w-]+|\\[[^\\]]+\\]|:{1,2}[^:,{\\s]+)+)(?=\\s*\\{)/gi,\n '$1$2$3&, $3',\n )\n }\n\n const hash = hashString(content)\n const hashedClassName = `humn-${hash}`\n\n if (cache.has(hash)) {\n return hashedClassName\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement('style')\n styleSheet.id = 'humn-styles'\n document.head.appendChild(styleSheet)\n }\n\n styleSheet.textContent += `.${hashedClassName} { \n ${content} \n }\\n`\n cache.add(hash)\n\n return hashedClassName\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children]\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat()\n .filter((c) => c !== null && c !== undefined && c !== false && c !== '')\n\n return {\n tag,\n props,\n children: cleanChildren,\n }\n}\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from './observer.js'\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance()\n if (instance) {\n instance.mounts.push(fn)\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance()\n if (instance) {\n instance.cleanups.push(fn)\n }\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { track } from './metrics.js'\nimport { setInstance } from './observer.js'\n\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h.js\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null)\n}\n\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\n if (typeof vNode === 'string' || typeof vNode === 'number') {\n return document.createTextNode(String(vNode))\n }\n\n if (typeof vNode.tag === 'function') {\n const childVNode = renderComponent(vNode)\n vNode.child = childVNode\n\n const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (vNode.hooks?.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n *\n * WHY: We check against the LIVE DOM value for inputs (value/checked) to prevent\n * the \"cursor jumping\" bug. If we just blindly set the attribute, the browser\n * might reset the cursor position to the end of the input.\n */\nfunction patchProps(element, newProps = {}, oldProps = {}) {\n if (!element) return\n\n const allProps = { ...oldProps, ...newProps }\n\n for (const key in allProps) {\n const oldValue = oldProps[key]\n const newValue = newProps[key]\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n element.removeAttribute(key)\n track('patches')\n continue\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === 'value' || key === 'checked') {\n if (element[key] !== newValue) {\n element[key] = newValue\n track('patches')\n }\n continue\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue\n\n track('patches')\n\n // Handle Events\n if (key.startsWith('on')) {\n const eventName = key.slice(2).toLowerCase()\n if (oldValue) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.setAttribute(key, newValue)\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h.js\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h.js\").VNode>} oldChildren - The old list of children.\n *\n * WHY: This is the most complex part of the VDOM. We need to efficiently update\n * a list of items. Without keys, we just update index-by-index, which is fast\n * but causes issues if items are reordered (state gets mixed up).\n * With keys, we can track items as they move around, preserving their state\n * and minimizing DOM operations.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren)\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length)\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i)\n }\n return\n }\n\n reconcileKeyedChildren(parent, newChildren, oldChildren)\n}\n\n/**\n * Handles the complex logic of reconciling keyed children.\n *\n * WHY: When keys are present, we can't just iterate by index. We need to map\n * existing children by their key so we can find them even if they've moved.\n * This allows us to re-use DOM nodes (preserving focus/state) instead of\n * destroying and re-creating them.\n */\nfunction reconcileKeyedChildren(parent, newChildren, oldChildren) {\n // Map existing children by Key for O(1) lookup\n const keyed = {}\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i\n keyed[key] = { vNode: child, index: i }\n })\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i\n const existingChildMatch = keyed[key]\n\n if (existingChildMatch) {\n // A. MATCH FOUND - The item existed before\n const oldVNode = existingChildMatch.vNode\n\n // Update the node's content recursively\n patch(parent, newChild, oldVNode, i)\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const element = newChild.el || oldVNode.el\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i]\n\n // If the element exists but is in the wrong place, move it\n if (element && domChildAtIndex !== element) {\n parent.insertBefore(element, domChildAtIndex)\n track('patches')\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key]\n } else {\n // B. NO MATCH - This is a new item\n const newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\n }\n }\n })\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n runUnmount(vNode) // Clean up hooks\n parent.removeChild(vNode.el)\n track('elementsRemoved')\n }\n })\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h.js\").VNode} vNode - The component vNode.\n * @returns {import(\"./h.js\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n track('componentsRendered')\n\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n }\n\n // 2. Set Global Scope\n setInstance(hooks)\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props)\n\n // 4. Clear Global Scope\n setInstance(null)\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks\n\n return renderedVNode\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h.js\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn())\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child)\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount)\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h.js\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h.js\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n track('diffs')\n\n // Case 1: Removal - The new node is null/undefined, so we remove the old one.\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index]\n\n // Recursive Cleanup\n runUnmount(oldVNode)\n\n if (el) {\n parent.removeChild(el)\n track('elementsRemoved')\n }\n return\n }\n\n // Case 2: Component - If it's a function, we delegate to the component logic.\n if (typeof newVNode.tag === 'function') {\n const isNew = !oldVNode\n\n const childVNode = renderComponent(newVNode)\n newVNode.child = childVNode\n\n const oldChild = oldVNode ? oldVNode.child : undefined\n patch(parent, childVNode, oldChild, index)\n\n newVNode.el = childVNode.el\n\n // Run mount hooks on the next tick\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn())\n }, 0)\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return\n }\n\n // Case 3: Creation - No old node exists, so we create a new one.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode, getNamespace(parent)))\n return\n }\n\n // Case 4: Replacement - The node type changed (e.g. div -> span), so we replace it entirely.\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== 'string' && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index]\n if (el) {\n parent.replaceChild(createElement(newVNode, getNamespace(parent)), el)\n track('patches')\n }\n return\n }\n\n // Case 5: Text Update - It's a text node, so we just update the text content.\n if (typeof newVNode === 'string' || typeof newVNode === 'number') {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index]\n if (el) {\n el.nodeValue = String(newVNode)\n track('patches')\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)))\n }\n }\n return\n }\n\n // Case 6: Update - Same tag, so we update props and recurse into children.\n const el = oldVNode.el || parent.childNodes[index]\n\n if (!el) return\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el\n\n patchProps(el, newVNode.props, oldVNode.props)\n\n reconcileChildren(el, newVNode.children, oldVNode.children)\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from './observer.js'\nimport { patch } from './patch.js'\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null\n\n const lifecycle = () => {\n setObserver(lifecycle)\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n }\n\n patch(target, nextVNode, prevVNode)\n setObserver(null)\n prevVNode = nextVNode\n }\n\n lifecycle()\n}\n","/**\n * @typedef {object} HumnPersist\n * @property {boolean} __humn_persist\n * @property {any} initial\n * @property {PersistConfig} config\n */\n\n/**\n * @typedef {object} PersistConfig\n * @property {string} key\n */\n\n/**\n * Marks a section of the state for persistence in localStorage.\n *\n * @param {any} initial - The initial value of the state.\n * @param {PersistConfig} config - The configuration for persistence.\n * @returns {HumnPersist}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","liveMemory","this","_persistenceMap","Map","key","value","Object","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","err","_memory","_listeners","updater","nextState","changedPaths","Set","clone","structuredClone","result","_createChangeTrackingProxy","keys","forEach","add","size","stateKey","Array","from","some","path","startsWith","setItem","stringify","_notifyRelevantListeners","obj","Proxy","get","target","prop","fullPath","accessedPaths","renderFn","accessedPath","changedPath","_createAccessTrackingProxy","has","styleSheet","cache","css","stringsOrStr","args","raw","isSingleRoot","isArray","reduce","acc","str","i","content","replace","trim","hash","length","charCodeAt","toString","hashedClassName","document","createElement","id","head","appendChild","textContent","h","tag","props","children","flat","filter","c","onMount","fn","instance","mounts","push","onCleanup","cleanups","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","vNode","namespace","createTextNode","String","childVNode","renderComponent","child","el","hooks","setTimeout","element","createElementNS","patchProps","childNS","newProps","oldProps","allProps","oldValue","newValue","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","values","parentNode","runUnmount","removeChild","renderedV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VWE,IAAU,CAAC7I,GAASP,IAAS,QAAE,EAC1CF,gBAAAA,IACAS,SAAAA,GACAP;"}
1
+ {"version":3,"file":"humn.js","sources":["../src/observer.js","../src/cortex.js","../src/css.js","../src/h.js","../src/lifecycle.js","../src/patch.js","../src/mount.js","../src/persist.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null // For Cortex/State dependency\nlet currentInstance = null // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs\n}\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst\n}\n","import { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * Mapped type for the Memory configuration object.\n * Allows each property to be the raw value OR a persisted wrapper.\n * @template T\n * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput\n */\n\n/**\n * Deeply unwraps persisted values from the memory shape.\n * @template {object} T\n * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory\n */\n\n/**\n * @template T\n * @callback Getter\n * @returns {T}\n */\n\n/**\n * @template T\n * @callback Setter\n * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater\n * @returns {void}\n */\n\n/**\n * @template M, S\n * @callback SynapsesBuilder\n * @param {Setter<M>} set\n * @param {Getter<M>} get\n * @returns {S}\n */\n\n/**\n * @template M, S\n * @typedef {object} CortexConfig\n * @property {MemoryInput<M>} memory - The initial state configuration\n * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function\n */\n\n/**\n * The Cortex class manages the state of the application.\n *\n * @template {object} MemoryType The shape of the application state\n * @template {object} SynapsesType The shape of the actions/methods\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexConfig<MemoryType, SynapsesType>} config\n */\n constructor({ memory, synapses }) {\n const liveMemory = { ...memory }\n this._persistenceMap = new Map()\n\n // Load in any existing values from local-storage\n for (const [key, value] of Object.entries(memory)) {\n if (value && typeof value === 'object' && value.__humn_persist) {\n const storageKey = value.config?.key || key\n this._persistenceMap.set(key, storageKey)\n\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored !== null) {\n liveMemory[key] = JSON.parse(stored)\n } else {\n liveMemory[key] = value.initial\n }\n } catch (err) {\n if (isDev)\n console.warn(`Humn: Failed to load '${key}' from storage.`, err)\n liveMemory[key] = value.initial\n }\n }\n }\n\n /** @type {UnwrappedMemory<MemoryType>} */\n this._memory = liveMemory\n this._listeners = new Map()\n\n /** @type {Getter<UnwrappedMemory<MemoryType>>} */\n const get = () => this._memory\n\n /** @type {Setter<UnwrappedMemory<MemoryType>>} */\n const set = (updater) => {\n let nextState\n let changedPaths = new Set()\n\n if (typeof updater === 'function') {\n const clone = structuredClone(this._memory)\n const proxy = this._createChangeTrackingProxy(clone, changedPaths)\n const result = updater(proxy)\n\n if (result && typeof result === 'object') {\n nextState = { ...this._memory, ...result }\n Object.keys(result).forEach((key) => changedPaths.add(key))\n } else {\n nextState = clone\n }\n } else {\n nextState = { ...this._memory, ...updater }\n changedPaths = new Set(Object.keys(updater))\n }\n\n this._memory = nextState\n\n // Persistence logic\n if (this._persistenceMap.size > 0) {\n this._persistenceMap.forEach((storageKey, stateKey) => {\n const isDirty = Array.from(changedPaths).some(\n (path) => path === stateKey || path.startsWith(stateKey + '.'),\n )\n\n if (isDirty) {\n try {\n const value = this._memory[stateKey]\n localStorage.setItem(storageKey, JSON.stringify(value))\n } catch (err) {\n if (isDev)\n console.error(`Humn: Failed to save '${stateKey}'.`, err)\n }\n }\n })\n }\n\n this._notifyRelevantListeners(changedPaths)\n }\n\n /** @type {SynapsesType} */\n this.synapses = synapses(set, get)\n }\n\n /**\n * Creates a Proxy that tracks which properties are being mutated.\n * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.\n *\n * WHY: We need to know exactly which paths were changed so we can notify ONLY\n * the components that care about those specific paths. If we just knew \"something changed\",\n * we'd have to re-render the whole app (like Redux) or rely on manual optimization.\n */\n _createChangeTrackingProxy(obj, changedPaths, path = '') {\n return new Proxy(obj, {\n get: (target, prop) => {\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const value = target[prop]\n const fullPath = path ? `${path}.${prop}` : prop\n\n // Recursively proxy nested objects so we can trap their sets too\n if (typeof value === 'object' && value !== null) {\n return this._createChangeTrackingProxy(value, changedPaths, fullPath)\n }\n return value\n },\n set: (target, prop, value) => {\n if (typeof prop === 'symbol' || prop === '__proto__') {\n target[prop] = value\n return true\n }\n\n const fullPath = path ? `${path}.${prop}` : prop\n changedPaths.add(fullPath)\n\n target[prop] = value\n return true\n },\n })\n }\n\n /**\n * Only notify listeners that read properties which changed\n */\n _notifyRelevantListeners(changedPaths) {\n this._listeners.forEach((accessedPaths, renderFn) => {\n const shouldNotify = Array.from(accessedPaths).some((accessedPath) => {\n return Array.from(changedPaths).some((changedPath) => {\n // Check for exact match or parent/child relationship\n return (\n accessedPath === changedPath ||\n accessedPath.startsWith(changedPath + '.') ||\n changedPath.startsWith(accessedPath + '.')\n )\n })\n })\n\n if (shouldNotify) renderFn()\n })\n }\n\n /**\n * Creates a Proxy that tracks which properties are accessed during render\n *\n * WHY: This is the other half of the magic. By tracking what a component READS\n * during its render, we build a precise dependency graph. If a component reads\n * `state.user.name`, it will only re-render when `state.user.name` changes,\n * not when `state.count` changes.\n */\n _createAccessTrackingProxy(obj, accessedPaths, path = '') {\n if (typeof obj !== 'object' || obj === null) return obj\n\n return new Proxy(obj, {\n get: (target, prop) => {\n // We don't care about prototype and symbol properties\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const fullPath = path ? `${path}.${prop}` : prop\n accessedPaths.add(fullPath)\n\n const value = target[prop]\n\n // Recursively wrap nested objects\n if (typeof value === 'object' && value !== null)\n return this._createAccessTrackingProxy(value, accessedPaths, fullPath)\n\n return value\n },\n })\n }\n\n /**\n * @returns {UnwrappedMemory<MemoryType>}\n */\n get memory() {\n const currentObserver = getObserver()\n\n if (!currentObserver) return this._memory\n\n if (!this._listeners.has(currentObserver))\n this._listeners.set(currentObserver, new Set())\n\n const accessedPaths = this._listeners.get(currentObserver)\n\n return this._createAccessTrackingProxy(this._memory, accessedPaths)\n }\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null\nconst cache = new Set()\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381\n let i = str.length\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i)\n }\n return (hash >>> 0).toString(36)\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse newlines/tabs to single space\n .trim() // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n * Supports two signatures:\n * 1. Tagged Template: css`...`\n * 2. Function: css(string, isSingleRoot)\n */\nexport function css(stringsOrStr, ...args) {\n let raw = ''\n let isSingleRoot = false\n\n // Detect usage of Tagged Template vs Function Call\n if (Array.isArray(stringsOrStr) && stringsOrStr.raw) {\n raw = stringsOrStr.reduce((acc, str, i) => {\n return acc + str + (args[i] || '')\n }, '')\n } else {\n raw = stringsOrStr\n // If called as function, the first arg is our boolean flag\n isSingleRoot = args[0] === true\n }\n let content = minify(raw)\n\n if (!content) return ''\n\n if (isSingleRoot) {\n // Transforms selectors to apply to BOTH the root (using &) AND descendants.\n // e.g. \"div\" -> \"div&, div\"\n\n // Regex Breakdown:\n // 1. (^|[{};,]) -> Hard Start (Line start, brace, semi, comma)\n // 2. (\\s*) -> Whitespace\n // 3. (?!from|to) -> Negative Lookahead: Ignore 'from'/'to' (keyframes)\n // 4. ( ... )+ -> Compound Selector:\n // (?:[.#]?[\\w-]+ ... ) -> Matches tags (div), classes (.class), ids (#id)\n // 5. (?=\\s*\\{) -> Lookahead: Must be followed by {\n\n content = content.replace(\n /(^|[{};,])(\\s*)(?!from|to)((?:[.#]?[\\w-]+|\\[[^\\]]+\\]|:{1,2}[^:,{\\s]+)+)(?=\\s*\\{)/gi,\n '$1$2$3&, $3',\n )\n }\n\n const hash = hashString(content)\n const hashedClassName = `humn-${hash}`\n\n if (cache.has(hash)) {\n return hashedClassName\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement('style')\n styleSheet.id = 'humn-styles'\n document.head.appendChild(styleSheet)\n }\n\n styleSheet.textContent += `.${hashedClassName} { \n ${content} \n }\\n`\n cache.add(hash)\n\n return hashedClassName\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children]\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat()\n .filter((c) => c !== null && c !== undefined && c !== false && c !== '')\n\n return {\n tag,\n props,\n children: cleanChildren,\n }\n}\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from './observer.js'\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance()\n if (instance) {\n instance.mounts.push(fn)\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance()\n if (instance) {\n instance.cleanups.push(fn)\n }\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { track } from './metrics.js'\nimport { setInstance } from './observer.js'\n\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h.js\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null)\n}\n\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\n if (typeof vNode === 'string' || typeof vNode === 'number') {\n return document.createTextNode(String(vNode))\n }\n\n if (typeof vNode.tag === 'function') {\n const childVNode = renderComponent(vNode)\n vNode.child = childVNode\n\n const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (vNode.hooks?.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n *\n * WHY: We check against the LIVE DOM value for inputs (value/checked) to prevent\n * the \"cursor jumping\" bug. If we just blindly set the attribute, the browser\n * might reset the cursor position to the end of the input.\n */\nfunction patchProps(element, newProps = {}, oldProps = {}) {\n if (!element) return\n\n const allProps = { ...oldProps, ...newProps }\n\n for (const key in allProps) {\n const oldValue = oldProps[key]\n const newValue = newProps[key]\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n element.removeAttribute(key)\n track('patches')\n continue\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === 'value' || key === 'checked') {\n if (element[key] !== newValue) {\n element[key] = newValue\n track('patches')\n }\n continue\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue\n\n track('patches')\n\n // Handle Events\n if (key.startsWith('on')) {\n const eventName = key.slice(2).toLowerCase()\n if (oldValue) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.setAttribute(key, newValue)\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h.js\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h.js\").VNode>} oldChildren - The old list of children.\n *\n * WHY: This is the most complex part of the VDOM. We need to efficiently update\n * a list of items. Without keys, we just update index-by-index, which is fast\n * but causes issues if items are reordered (state gets mixed up).\n * With keys, we can track items as they move around, preserving their state\n * and minimizing DOM operations.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren)\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length)\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i)\n }\n return\n }\n\n reconcileKeyedChildren(parent, newChildren, oldChildren)\n}\n\n/**\n * Handles the complex logic of reconciling keyed children.\n *\n * WHY: When keys are present, we can't just iterate by index. We need to map\n * existing children by their key so we can find them even if they've moved.\n * This allows us to re-use DOM nodes (preserving focus/state) instead of\n * destroying and re-creating them.\n */\nfunction reconcileKeyedChildren(parent, newChildren, oldChildren) {\n // Map existing children by Key for O(1) lookup\n const keyed = {}\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i\n keyed[key] = { vNode: child, index: i }\n })\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i\n const existingChildMatch = keyed[key]\n\n if (existingChildMatch) {\n // A. MATCH FOUND - The item existed before\n const oldVNode = existingChildMatch.vNode\n\n // Update the node's content recursively\n patch(parent, newChild, oldVNode, i)\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const element = newChild.el || oldVNode.el\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i]\n\n // If the element exists but is in the wrong place, move it\n if (element && domChildAtIndex !== element) {\n parent.insertBefore(element, domChildAtIndex)\n track('patches')\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key]\n } else {\n // B. NO MATCH - This is a new item\n const newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\n }\n }\n })\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n runUnmount(vNode) // Clean up hooks\n parent.removeChild(vNode.el)\n track('elementsRemoved')\n }\n })\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h.js\").VNode} vNode - The component vNode.\n * @returns {import(\"./h.js\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n track('componentsRendered')\n\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n }\n\n // 2. Set Global Scope\n setInstance(hooks)\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props)\n\n // 4. Clear Global Scope\n setInstance(null)\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks\n\n return renderedVNode\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h.js\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn())\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child)\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount)\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h.js\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h.js\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n track('diffs')\n\n // Case 1: Removal - The new node is null/undefined, so we remove the old one.\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index]\n\n // Recursive Cleanup\n runUnmount(oldVNode)\n\n if (el) {\n parent.removeChild(el)\n track('elementsRemoved')\n }\n return\n }\n\n // Case 2: Component - If it's a function, we delegate to the component logic.\n if (typeof newVNode.tag === 'function') {\n const isNew = !oldVNode\n\n const childVNode = renderComponent(newVNode)\n newVNode.child = childVNode\n\n const oldChild = oldVNode ? oldVNode.child : undefined\n patch(parent, childVNode, oldChild, index)\n\n newVNode.el = childVNode.el\n\n // Run mount hooks on the next tick\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn())\n }, 0)\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return\n }\n\n // Case 3: Creation - No old node exists, so we create a new one.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode, getNamespace(parent)))\n return\n }\n\n // Case 4: Replacement - The node type changed (e.g. div -> span), so we replace it entirely.\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== 'string' && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index]\n if (el) {\n parent.replaceChild(createElement(newVNode, getNamespace(parent)), el)\n track('patches')\n }\n return\n }\n\n // Case 5: Text Update - It's a text node, so we just update the text content.\n if (typeof newVNode === 'string' || typeof newVNode === 'number') {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index]\n if (el) {\n el.nodeValue = String(newVNode)\n track('patches')\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)))\n }\n }\n return\n }\n\n // Case 6: Update - Same tag, so we update props and recurse into children.\n const el = oldVNode.el || parent.childNodes[index]\n\n if (!el) return\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el\n\n patchProps(el, newVNode.props, oldVNode.props)\n\n reconcileChildren(el, newVNode.children, oldVNode.children)\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from './observer.js'\nimport { patch } from './patch.js'\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null\n\n const lifecycle = () => {\n setObserver(lifecycle)\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n }\n\n patch(target, nextVNode, prevVNode)\n setObserver(null)\n prevVNode = nextVNode\n }\n\n lifecycle()\n}\n","/**\n * Represents a value wrapped by the persist() function.\n * @template T\n * @typedef {object} Persisted\n * @property {T} initial\n * @property {boolean} __humn_persist\n * @property {PersistConfig} [config]\n */\n\n/**\n * @typedef {object} PersistConfig\n * @property {string} key\n */\n\n/**\n * Marks a section of the state for persistence in localStorage.\n * @template T\n * @param {T} initial\n * @param {PersistConfig} [config]\n * @returns {Persisted<T>}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","liveMemory","this","_persistenceMap","Map","key","value","Object","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","err","_memory","_listeners","updater","nextState","changedPaths","Set","clone","structuredClone","result","_createChangeTrackingProxy","keys","forEach","add","size","stateKey","Array","from","some","path","startsWith","setItem","stringify","_notifyRelevantListeners","obj","Proxy","get","target","prop","fullPath","accessedPaths","renderFn","accessedPath","changedPath","_createAccessTrackingProxy","has","styleSheet","cache","css","stringsOrStr","args","raw","isSingleRoot","isArray","reduce","acc","str","i","content","replace","trim","hash","length","charCodeAt","toString","hashedClassName","document","createElement","id","head","appendChild","textContent","h","tag","props","children","flat","filter","c","onMount","fn","instance","mounts","push","onCleanup","cleanups","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","vNode","namespace","createTextNode","String","childVNode","renderComponent","child","el","hooks","setTimeout","element","createElementNS","patchProps","childNS","newProps","oldProps","allProps","oldValue","newValue","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","values","parentNode","runUnmount","removeChild","renderedVNode","newVNode","isNew","replaceChild","nodeValue","mount","Component","prevVNode","lifecycle","nextVNode","persist"],"mappings":"AAKA,IAAIA,IAAkB,MAClBC,IAAkB;AAMf,MAAMC,IAAc,MAAMF,GAMpBG,IAAeC,OAAAA;AAC1BJ,EAAAA,IAAkBI;AAAAA,GAOPC,IAAc,MAAMJ,GAMpBK,IAAeC,CAAAA,MAAAA;AAC1BN,EAAAA,IAAkBM;AAAAA;ACiBb,MAAMC,EAAAA;AAAAA,EAKX,cAAYC,QAAEA,GAAMC,UAAEA,EAAAA,GAAAA;AACpB,UAAMC,IAAa,EAAA,GAAKF,EAAAA;AACxBG,SAAKC,kBAAkB,oBAAIC;AAG3B,eAAK,CAAOC,GAAKC,CAAAA,KAAUC,OAAOC,QAAQT,GACxC,KAAIO,KAA0B,OAAVA,KAAU,YAAYA,EAAMG,gBAAgB;AAC9D,YAAMC,IAAaJ,EAAMK,QAAQN,OAAOA;AACxCH,WAAKC,gBAAgBS,IAAIP,GAAKK,CAAAA;AAE9B;AACE,cAAMG,IAASC,aAAaC,QAAQL;AAElCT,QAAAA,EAAWI,CAAAA,IADTQ,MAAW,OACKG,KAAKC,MAAMJ,CAAAA,IAEXP,EAAMY;AAAAA,MAE5B,QAASC;AAGPlB,QAAAA,EAAWI,KAAOC,EAAMY;AAAAA,MAC1B;AAAA,IACF;AAIFhB,SAAKkB,UAAUnB,GACfC,KAAKmB,aAAa,oBAAIjB,OAmDtBF,KAAKF,WAAWA,EA7CHsB,CAAAA,MAAAA;AACX,UAAIC,GACAC,IAAe,oBAAIC;AAEvB,UAAuB,OAAZH,KAAY,YAAY;AACjC,cAAMI,IAAQC,gBAAgBzB,KAAKkB,OAAAA,GAE7BQ,IAASN,EADDpB,KAAK2B,2BAA2BH,GAAOF,CAAAA,CAAAA;AAGjDI,QAAAA,YAAiBA,KAAW,YAC9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A,EAAAA;AAGdD,EAAAA,EAAAA;AAAAA,GCRWE,IAAU,CAAC7I,GAASP,IAAS,QAAE,EAC1CF,gBAAAA,IACAS,SAAAA,GACAP;"}
package/dist/humn.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(a,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):h((a=typeof globalThis<"u"?globalThis:a||self).Humn={})})(this,function(a){"use strict";let h=null,v=null;const j=()=>h,w=t=>{h=t},x=()=>v,C=t=>{v=t};let p=null;const E=new Set;function _(t){return t.namespaceURI===b&&t.tagName!=="foreignObject"?b:t.namespaceURI===k?k:null}function N(t){return t&&t.some(e=>e&&e.props&&e.props.key!=null)}const b="http://www.w3.org/2000/svg",k="http://www.w3.org/1998/Math/MathML";function d(t,e){if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.tag=="function"){const r=A(t);t.child=r;const i=d(r,e);return t.el=i,t.hooks?.mounts.length>0&&setTimeout(()=>t.hooks.mounts.forEach(c=>c()),0),i}const s=t.tag;s==="svg"?e=b:s==="math"&&(e=k);const o=e?document.createElementNS(e,s):document.createElement(s);t.el=o,S(o,t.props);const n=s==="foreignObject"?null:e;return t.children.forEach(r=>{o.appendChild(d(r,n))}),o}function S(t,e={},s={}){if(!t)return;const o={...s,...e};for(const n in o){const r=s[n],i=e[n];if(i!=null)if(n!=="value"&&n!=="checked"){if(r!==i){if(n.startsWith("on")){const c=n.slice(2).toLowerCase();r&&t.removeEventListener(c,r),t.addEventListener(c,i)}n==="disabled"?t.disabled=i===!0||i==="true":t.setAttribute(n,i)}}else t[n]!==i&&(t[n]=i);else t.removeAttribute(n)}}function M(t,e,s){if(!(N(e)||N(s))){const o=Math.max(e.length,s.length);for(let n=0;n<o;n++)g(t,e[n],s[n],n);return}(function(o,n,r){const i={};r.forEach((c,l)=>{const u=(c.props&&c.props.key)!=null?c.props.key:l;i[u]={vNode:c,index:l}}),n.forEach((c,l)=>{const u=(c.props&&c.props.key)!=null?c.props.key:l,T=i[u];if(T){const m=T.vNode;g(o,c,m,l);const f=c.el||m.el,$=o.childNodes[l];f&&$!==f&&o.insertBefore(f,$),delete i[u]}else{const m=d(c,_(o)),f=o.childNodes[l];f?o.insertBefore(m,f):o.appendChild(m)}}),Object.values(i).forEach(({vNode:c})=>{c.el&&c.el.parentNode===o&&(y(c),o.removeChild(c.el))})})(t,e,s)}function A(t){const e={mounts:[],cleanups:[]};C(e);const s=t.tag(t.props);return C(null),t.hooks=e,s}function y(t){t&&(t.hooks&&t.hooks.cleanups&&t.hooks.cleanups.forEach(e=>e()),t.child&&y(t.child),t.children&&t.children.forEach(y))}function g(t,e,s,o=0){if(e==null){const r=s.el||t.childNodes[o];return y(s),void(r&&t.removeChild(r))}if(typeof e.tag=="function"){const r=!s,i=A(e);return e.child=i,g(t,i,s?s.child:void 0,o),e.el=i.el,void(r&&e.hooks&&e.hooks.mounts.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(c=>c())},0))}if(s==null)return void t.appendChild(d(e,_(t)));if(typeof e!=typeof s||typeof e!="string"&&e.tag!==s.tag){const r=s.el||t.childNodes[o];return void(r&&t.replaceChild(d(e,_(t)),r))}if(typeof e=="string"||typeof e=="number"){if(e!==s){const r=t.childNodes[o];r?r.nodeValue=String(e):t.appendChild(document.createTextNode(String(e)))}return}const n=s.el||t.childNodes[o];n&&(e.el=n,S(n,e.props,s.props),M(n,e.children,s.children))}a.Cortex=class{constructor({memory:t,synapses:e}){const s={...t};this._persistenceMap=new Map;for(const[o,n]of Object.entries(t))if(n&&n.__humn_persist){const r=n.config.key||o;this._persistenceMap.set(o,r);try{const i=localStorage.getItem(r);s[o]=i!==null?JSON.parse(i):n.initial}catch{s[o]=n.initial}}this._memory=s,this._listeners=new Map,this.synapses=e(o=>{let n,r=new Set;if(typeof o=="function"){const i=structuredClone(this._memory),c=o(this._createChangeTrackingProxy(i,r));c&&typeof c=="object"?(n={...this._memory,...c},Object.keys(c).forEach(l=>r.add(l))):n=i}else n={...this._memory,...o},r=new Set(Object.keys(o));this._memory=n,this._persistenceMap.size>0&&this._persistenceMap.forEach((i,c)=>{if(Array.from(r).some(l=>l===c||l.startsWith(c+".")))try{const l=this._memory[c];localStorage.setItem(i,JSON.stringify(l))}catch{}}),this._notifyRelevantListeners(r)},()=>this._memory)}_createChangeTrackingProxy(t,e,s=""){return new Proxy(t,{get:(o,n)=>{if(typeof n=="symbol"||n==="__proto__")return o[n];const r=o[n],i=s?`${s}.${n}`:n;return typeof r=="object"&&r!==null?this._createChangeTrackingProxy(r,e,i):r},set:(o,n,r)=>{if(typeof n=="symbol"||n==="__proto__")return o[n]=r,!0;const i=s?`${s}.${n}`:n;return e.add(i),o[n]=r,!0}})}_notifyRelevantListeners(t){this._listeners.forEach((e,s)=>{Array.from(e).some(o=>Array.from(t).some(n=>o===n||o.startsWith(n+".")||n.startsWith(o+".")))&&s()})}_createAccessTrackingProxy(t,e,s=""){return typeof t!="object"||t===null?t:new Proxy(t,{get:(o,n)=>{if(typeof n=="symbol"||n==="__proto__")return o[n];const r=s?`${s}.${n}`:n;e.add(r);const i=o[n];return typeof i=="object"&&i!==null?this._createAccessTrackingProxy(i,e,r):i}})}get memory(){const t=j();if(!t)return this._memory;this._listeners.has(t)||this._listeners.set(t,new Set);const e=this._listeners.get(t);return this._createAccessTrackingProxy(this._memory,e)}},a.css=function(t,...e){let s="",o=!1;Array.isArray(t)&&t.raw?s=t.reduce((c,l,u)=>c+l+(e[u]||""),""):(s=t,o=e[0]===!0);let n=(function(c){return c.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim()})(s);if(!n)return"";o&&(n=n.replace(/(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi,"$1$2$3&, $3"));const r=(function(c){let l=5381,u=c.length;for(;u;)l=33*l^c.charCodeAt(--u);return(l>>>0).toString(36)})(n),i=`humn-${r}`;return E.has(r)||(p||(p=document.createElement("style"),p.id="humn-styles",document.head.appendChild(p)),p.textContent+=`.${i} {
1
+ (function(a,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):h((a=typeof globalThis<"u"?globalThis:a||self).Humn={})})(this,function(a){"use strict";let h=null,v=null;const $=()=>h,w=t=>{h=t},x=()=>v,C=t=>{v=t};let p=null;const E=new Set;function _(t){return t.namespaceURI===b&&t.tagName!=="foreignObject"?b:t.namespaceURI===k?k:null}function N(t){return t&&t.some(e=>e&&e.props&&e.props.key!=null)}const b="http://www.w3.org/2000/svg",k="http://www.w3.org/1998/Math/MathML";function d(t,e){if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.tag=="function"){const r=j(t);t.child=r;const i=d(r,e);return t.el=i,t.hooks?.mounts.length>0&&setTimeout(()=>t.hooks.mounts.forEach(c=>c()),0),i}const s=t.tag;s==="svg"?e=b:s==="math"&&(e=k);const o=e?document.createElementNS(e,s):document.createElement(s);t.el=o,S(o,t.props);const n=s==="foreignObject"?null:e;return t.children.forEach(r=>{o.appendChild(d(r,n))}),o}function S(t,e={},s={}){if(!t)return;const o={...s,...e};for(const n in o){const r=s[n],i=e[n];if(i!=null)if(n!=="value"&&n!=="checked"){if(r!==i){if(n.startsWith("on")){const c=n.slice(2).toLowerCase();r&&t.removeEventListener(c,r),t.addEventListener(c,i)}n==="disabled"?t.disabled=i===!0||i==="true":t.setAttribute(n,i)}}else t[n]!==i&&(t[n]=i);else t.removeAttribute(n)}}function M(t,e,s){if(!(N(e)||N(s))){const o=Math.max(e.length,s.length);for(let n=0;n<o;n++)g(t,e[n],s[n],n);return}(function(o,n,r){const i={};r.forEach((c,l)=>{const u=(c.props&&c.props.key)!=null?c.props.key:l;i[u]={vNode:c,index:l}}),n.forEach((c,l)=>{const u=(c.props&&c.props.key)!=null?c.props.key:l,A=i[u];if(A){const m=A.vNode;g(o,c,m,l);const f=c.el||m.el,T=o.childNodes[l];f&&T!==f&&o.insertBefore(f,T),delete i[u]}else{const m=d(c,_(o)),f=o.childNodes[l];f?o.insertBefore(m,f):o.appendChild(m)}}),Object.values(i).forEach(({vNode:c})=>{c.el&&c.el.parentNode===o&&(y(c),o.removeChild(c.el))})})(t,e,s)}function j(t){const e={mounts:[],cleanups:[]};C(e);const s=t.tag(t.props);return C(null),t.hooks=e,s}function y(t){t&&(t.hooks&&t.hooks.cleanups&&t.hooks.cleanups.forEach(e=>e()),t.child&&y(t.child),t.children&&t.children.forEach(y))}function g(t,e,s,o=0){if(e==null){const r=s.el||t.childNodes[o];return y(s),void(r&&t.removeChild(r))}if(typeof e.tag=="function"){const r=!s,i=j(e);return e.child=i,g(t,i,s?s.child:void 0,o),e.el=i.el,void(r&&e.hooks&&e.hooks.mounts.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(c=>c())},0))}if(s==null)return void t.appendChild(d(e,_(t)));if(typeof e!=typeof s||typeof e!="string"&&e.tag!==s.tag){const r=s.el||t.childNodes[o];return void(r&&t.replaceChild(d(e,_(t)),r))}if(typeof e=="string"||typeof e=="number"){if(e!==s){const r=t.childNodes[o];r?r.nodeValue=String(e):t.appendChild(document.createTextNode(String(e)))}return}const n=s.el||t.childNodes[o];n&&(e.el=n,S(n,e.props,s.props),M(n,e.children,s.children))}a.Cortex=class{constructor({memory:t,synapses:e}){const s={...t};this._persistenceMap=new Map;for(const[o,n]of Object.entries(t))if(n&&typeof n=="object"&&n.__humn_persist){const r=n.config?.key||o;this._persistenceMap.set(o,r);try{const i=localStorage.getItem(r);s[o]=i!==null?JSON.parse(i):n.initial}catch{s[o]=n.initial}}this._memory=s,this._listeners=new Map,this.synapses=e(o=>{let n,r=new Set;if(typeof o=="function"){const i=structuredClone(this._memory),c=o(this._createChangeTrackingProxy(i,r));c&&typeof c=="object"?(n={...this._memory,...c},Object.keys(c).forEach(l=>r.add(l))):n=i}else n={...this._memory,...o},r=new Set(Object.keys(o));this._memory=n,this._persistenceMap.size>0&&this._persistenceMap.forEach((i,c)=>{if(Array.from(r).some(l=>l===c||l.startsWith(c+".")))try{const l=this._memory[c];localStorage.setItem(i,JSON.stringify(l))}catch{}}),this._notifyRelevantListeners(r)},()=>this._memory)}_createChangeTrackingProxy(t,e,s=""){return new Proxy(t,{get:(o,n)=>{if(typeof n=="symbol"||n==="__proto__")return o[n];const r=o[n],i=s?`${s}.${n}`:n;return typeof r=="object"&&r!==null?this._createChangeTrackingProxy(r,e,i):r},set:(o,n,r)=>{if(typeof n=="symbol"||n==="__proto__")return o[n]=r,!0;const i=s?`${s}.${n}`:n;return e.add(i),o[n]=r,!0}})}_notifyRelevantListeners(t){this._listeners.forEach((e,s)=>{Array.from(e).some(o=>Array.from(t).some(n=>o===n||o.startsWith(n+".")||n.startsWith(o+".")))&&s()})}_createAccessTrackingProxy(t,e,s=""){return typeof t!="object"||t===null?t:new Proxy(t,{get:(o,n)=>{if(typeof n=="symbol"||n==="__proto__")return o[n];const r=s?`${s}.${n}`:n;e.add(r);const i=o[n];return typeof i=="object"&&i!==null?this._createAccessTrackingProxy(i,e,r):i}})}get memory(){const t=$();if(!t)return this._memory;this._listeners.has(t)||this._listeners.set(t,new Set);const e=this._listeners.get(t);return this._createAccessTrackingProxy(this._memory,e)}},a.css=function(t,...e){let s="",o=!1;Array.isArray(t)&&t.raw?s=t.reduce((c,l,u)=>c+l+(e[u]||""),""):(s=t,o=e[0]===!0);let n=(function(c){return c.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim()})(s);if(!n)return"";o&&(n=n.replace(/(^|[{};,])(\s*)(?!from|to)((?:[.#]?[\w-]+|\[[^\]]+\]|:{1,2}[^:,{\s]+)+)(?=\s*\{)/gi,"$1$2$3&, $3"));const r=(function(c){let l=5381,u=c.length;for(;u;)l=33*l^c.charCodeAt(--u);return(l>>>0).toString(36)})(n),i=`humn-${r}`;return E.has(r)||(p||(p=document.createElement("style"),p.id="humn-styles",document.head.appendChild(p)),p.textContent+=`.${i} {
2
2
  ${n}
3
3
  }
4
4
  `,E.add(r)),i},a.h=(t,e={},s=[])=>({tag:t,props:e,children:(Array.isArray(s)?s:[s]).flat().filter(o=>o!=null&&o!==!1&&o!=="")}),a.mount=(t,e)=>{let s=null;const o=()=>{w(o);const n={tag:e,props:{},children:[]};g(t,n,s),w(null),s=n};o()},a.onCleanup=function(t){const e=x();e&&e.cleanups.push(t)},a.onMount=function(t){const e=x();e&&e.mounts.push(t)},a.persist=(t,e={})=>({__humn_persist:!0,initial:t,config:e}),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- {"version":3,"file":"humn.umd.js","sources":["../src/observer.js","../src/css.js","../src/patch.js","../src/persist.js","../src/cortex.js","../src/h.js","../src/mount.js","../src/lifecycle.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null // For Cortex/State dependency\nlet currentInstance = null // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs\n}\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null\nconst cache = new Set()\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381\n let i = str.length\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i)\n }\n return (hash >>> 0).toString(36)\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse newlines/tabs to single space\n .trim() // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n * Supports two signatures:\n * 1. Tagged Template: css`...`\n * 2. Function: css(string, isSingleRoot)\n */\nexport function css(stringsOrStr, ...args) {\n let raw = ''\n let isSingleRoot = false\n\n // Detect usage of Tagged Template vs Function Call\n if (Array.isArray(stringsOrStr) && stringsOrStr.raw) {\n raw = stringsOrStr.reduce((acc, str, i) => {\n return acc + str + (args[i] || '')\n }, '')\n } else {\n raw = stringsOrStr\n // If called as function, the first arg is our boolean flag\n isSingleRoot = args[0] === true\n }\n let content = minify(raw)\n\n if (!content) return ''\n\n if (isSingleRoot) {\n // Transforms selectors to apply to BOTH the root (using &) AND descendants.\n // e.g. \"div\" -> \"div&, div\"\n\n // Regex Breakdown:\n // 1. (^|[{};,]) -> Hard Start (Line start, brace, semi, comma)\n // 2. (\\s*) -> Whitespace\n // 3. (?!from|to) -> Negative Lookahead: Ignore 'from'/'to' (keyframes)\n // 4. ( ... )+ -> Compound Selector:\n // (?:[.#]?[\\w-]+ ... ) -> Matches tags (div), classes (.class), ids (#id)\n // 5. (?=\\s*\\{) -> Lookahead: Must be followed by {\n\n content = content.replace(\n /(^|[{};,])(\\s*)(?!from|to)((?:[.#]?[\\w-]+|\\[[^\\]]+\\]|:{1,2}[^:,{\\s]+)+)(?=\\s*\\{)/gi,\n '$1$2$3&, $3',\n )\n }\n\n const hash = hashString(content)\n const hashedClassName = `humn-${hash}`\n\n if (cache.has(hash)) {\n return hashedClassName\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement('style')\n styleSheet.id = 'humn-styles'\n document.head.appendChild(styleSheet)\n }\n\n styleSheet.textContent += `.${hashedClassName} { \n ${content} \n }\\n`\n cache.add(hash)\n\n return hashedClassName\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { track } from './metrics.js'\nimport { setInstance } from './observer.js'\n\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h.js\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null)\n}\n\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\n if (typeof vNode === 'string' || typeof vNode === 'number') {\n return document.createTextNode(String(vNode))\n }\n\n if (typeof vNode.tag === 'function') {\n const childVNode = renderComponent(vNode)\n vNode.child = childVNode\n\n const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (vNode.hooks?.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n *\n * WHY: We check against the LIVE DOM value for inputs (value/checked) to prevent\n * the \"cursor jumping\" bug. If we just blindly set the attribute, the browser\n * might reset the cursor position to the end of the input.\n */\nfunction patchProps(element, newProps = {}, oldProps = {}) {\n if (!element) return\n\n const allProps = { ...oldProps, ...newProps }\n\n for (const key in allProps) {\n const oldValue = oldProps[key]\n const newValue = newProps[key]\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n element.removeAttribute(key)\n track('patches')\n continue\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === 'value' || key === 'checked') {\n if (element[key] !== newValue) {\n element[key] = newValue\n track('patches')\n }\n continue\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue\n\n track('patches')\n\n // Handle Events\n if (key.startsWith('on')) {\n const eventName = key.slice(2).toLowerCase()\n if (oldValue) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.setAttribute(key, newValue)\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h.js\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h.js\").VNode>} oldChildren - The old list of children.\n *\n * WHY: This is the most complex part of the VDOM. We need to efficiently update\n * a list of items. Without keys, we just update index-by-index, which is fast\n * but causes issues if items are reordered (state gets mixed up).\n * With keys, we can track items as they move around, preserving their state\n * and minimizing DOM operations.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren)\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length)\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i)\n }\n return\n }\n\n reconcileKeyedChildren(parent, newChildren, oldChildren)\n}\n\n/**\n * Handles the complex logic of reconciling keyed children.\n *\n * WHY: When keys are present, we can't just iterate by index. We need to map\n * existing children by their key so we can find them even if they've moved.\n * This allows us to re-use DOM nodes (preserving focus/state) instead of\n * destroying and re-creating them.\n */\nfunction reconcileKeyedChildren(parent, newChildren, oldChildren) {\n // Map existing children by Key for O(1) lookup\n const keyed = {}\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i\n keyed[key] = { vNode: child, index: i }\n })\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i\n const existingChildMatch = keyed[key]\n\n if (existingChildMatch) {\n // A. MATCH FOUND - The item existed before\n const oldVNode = existingChildMatch.vNode\n\n // Update the node's content recursively\n patch(parent, newChild, oldVNode, i)\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const element = newChild.el || oldVNode.el\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i]\n\n // If the element exists but is in the wrong place, move it\n if (element && domChildAtIndex !== element) {\n parent.insertBefore(element, domChildAtIndex)\n track('patches')\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key]\n } else {\n // B. NO MATCH - This is a new item\n const newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\n }\n }\n })\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n runUnmount(vNode) // Clean up hooks\n parent.removeChild(vNode.el)\n track('elementsRemoved')\n }\n })\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h.js\").VNode} vNode - The component vNode.\n * @returns {import(\"./h.js\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n track('componentsRendered')\n\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n }\n\n // 2. Set Global Scope\n setInstance(hooks)\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props)\n\n // 4. Clear Global Scope\n setInstance(null)\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks\n\n return renderedVNode\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h.js\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn())\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child)\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount)\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h.js\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h.js\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n track('diffs')\n\n // Case 1: Removal - The new node is null/undefined, so we remove the old one.\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index]\n\n // Recursive Cleanup\n runUnmount(oldVNode)\n\n if (el) {\n parent.removeChild(el)\n track('elementsRemoved')\n }\n return\n }\n\n // Case 2: Component - If it's a function, we delegate to the component logic.\n if (typeof newVNode.tag === 'function') {\n const isNew = !oldVNode\n\n const childVNode = renderComponent(newVNode)\n newVNode.child = childVNode\n\n const oldChild = oldVNode ? oldVNode.child : undefined\n patch(parent, childVNode, oldChild, index)\n\n newVNode.el = childVNode.el\n\n // Run mount hooks on the next tick\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn())\n }, 0)\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return\n }\n\n // Case 3: Creation - No old node exists, so we create a new one.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode, getNamespace(parent)))\n return\n }\n\n // Case 4: Replacement - The node type changed (e.g. div -> span), so we replace it entirely.\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== 'string' && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index]\n if (el) {\n parent.replaceChild(createElement(newVNode, getNamespace(parent)), el)\n track('patches')\n }\n return\n }\n\n // Case 5: Text Update - It's a text node, so we just update the text content.\n if (typeof newVNode === 'string' || typeof newVNode === 'number') {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index]\n if (el) {\n el.nodeValue = String(newVNode)\n track('patches')\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)))\n }\n }\n return\n }\n\n // Case 6: Update - Same tag, so we update props and recurse into children.\n const el = oldVNode.el || parent.childNodes[index]\n\n if (!el) return\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el\n\n patchProps(el, newVNode.props, oldVNode.props)\n\n reconcileChildren(el, newVNode.children, oldVNode.children)\n}\n","/**\n * @typedef {object} HumnPersist\n * @property {boolean} __humn_persist\n * @property {any} initial\n * @property {PersistConfig} config\n */\n\n/**\n * @typedef {object} PersistConfig\n * @property {string} key\n */\n\n/**\n * Marks a section of the state for persistence in localStorage.\n *\n * @param {any} initial - The initial value of the state.\n * @param {PersistConfig} config - The configuration for persistence.\n * @returns {HumnPersist}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n","import { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * @typedef {object} Synapses\n * @property {function} set - Function to update the memory\n * @property {function} get - Function to get the memory\n */\n\n/**\n * @typedef {object} CortexParams\n * @property {object} memory - The initial state\n * @property {function(function, function): object} synapses - The synapses function\n */\n\n/**\n * The Cortex class manages the state of the application.\n * This uses a Proxy for fine-grained reactivity, ensuring only those components\n * which use the updated value get re-rendered.\n *\n * WHY: We use Proxies instead of simple getters/setters because it allows us to\n * detect access to nested properties dynamically without needing to declare\n * dependencies upfront. This \"magic\" auto-subscription is what makes Humn's\n * DX so clean.\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexParams} CortexParams - The parameters for the Cortex.\n */\n constructor({ memory, synapses }) {\n const liveMemory = { ...memory }\n this._persistenceMap = new Map()\n\n // Load in any existing values from local-storage\n for (const [key, value] of Object.entries(memory)) {\n if (value && value.__humn_persist) {\n const storageKey = value.config.key || key\n this._persistenceMap.set(key, storageKey)\n\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored !== null) {\n liveMemory[key] = JSON.parse(stored)\n } else {\n liveMemory[key] = value.initial\n }\n } catch (err) {\n if (isDev)\n console.warn(`Humn: Failed to load '${key}' from storage.`, err)\n liveMemory[key] = value.initial\n }\n }\n }\n\n this._memory = liveMemory\n this._listeners = new Map()\n\n const get = () => this._memory\n\n const set = (updater) => {\n let nextState\n let changedPaths = new Set()\n\n if (typeof updater === 'function') {\n const clone = structuredClone(this._memory)\n const proxy = this._createChangeTrackingProxy(clone, changedPaths)\n const result = updater(proxy)\n\n if (result && typeof result === 'object') {\n nextState = { ...this._memory, ...result }\n Object.keys(result).forEach((key) => changedPaths.add(key))\n } else {\n nextState = clone\n }\n } else {\n nextState = { ...this._memory, ...updater }\n changedPaths = new Set(Object.keys(updater))\n }\n\n this._memory = nextState\n\n // If we need to persist any of the values\n // we save them to localStorage here\n if (this._persistenceMap.size > 0) {\n this._persistenceMap.forEach((storageKey, stateKey) => {\n const isDirty = Array.from(changedPaths).some(\n (path) => path === stateKey || path.startsWith(stateKey + '.'),\n )\n\n if (isDirty) {\n try {\n const value = this._memory[stateKey]\n localStorage.setItem(storageKey, JSON.stringify(value))\n } catch (err) {\n if (isDev)\n console.error(`Humn: Failed to save '${stateKey}'.`, err)\n }\n }\n })\n }\n\n this._notifyRelevantListeners(changedPaths)\n }\n\n this.synapses = synapses(set, get)\n }\n\n /**\n * Creates a Proxy that tracks which properties are being mutated.\n * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.\n *\n * WHY: We need to know exactly which paths were changed so we can notify ONLY\n * the components that care about those specific paths. If we just knew \"something changed\",\n * we'd have to re-render the whole app (like Redux) or rely on manual optimization.\n */\n _createChangeTrackingProxy(obj, changedPaths, path = '') {\n return new Proxy(obj, {\n get: (target, prop) => {\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const value = target[prop]\n const fullPath = path ? `${path}.${prop}` : prop\n\n // Recursively proxy nested objects so we can trap their sets too\n if (typeof value === 'object' && value !== null) {\n return this._createChangeTrackingProxy(value, changedPaths, fullPath)\n }\n return value\n },\n set: (target, prop, value) => {\n if (typeof prop === 'symbol' || prop === '__proto__') {\n target[prop] = value\n return true\n }\n\n const fullPath = path ? `${path}.${prop}` : prop\n changedPaths.add(fullPath)\n\n target[prop] = value\n return true\n },\n })\n }\n\n /**\n * Only notify listeners that read properties which changed\n */\n _notifyRelevantListeners(changedPaths) {\n this._listeners.forEach((accessedPaths, renderFn) => {\n const shouldNotify = Array.from(accessedPaths).some((accessedPath) => {\n return Array.from(changedPaths).some((changedPath) => {\n // Check for exact match or parent/child relationship\n return (\n accessedPath === changedPath ||\n accessedPath.startsWith(changedPath + '.') ||\n changedPath.startsWith(accessedPath + '.')\n )\n })\n })\n\n if (shouldNotify) renderFn()\n })\n }\n\n /**\n * Creates a Proxy that tracks which properties are accessed during render\n *\n * WHY: This is the other half of the magic. By tracking what a component READS\n * during its render, we build a precise dependency graph. If a component reads\n * `state.user.name`, it will only re-render when `state.user.name` changes,\n * not when `state.count` changes.\n */\n _createAccessTrackingProxy(obj, accessedPaths, path = '') {\n if (typeof obj !== 'object' || obj === null) return obj\n\n return new Proxy(obj, {\n get: (target, prop) => {\n // We don't care about prototype and symbol properties\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const fullPath = path ? `${path}.${prop}` : prop\n accessedPaths.add(fullPath)\n\n const value = target[prop]\n\n // Recursively wrap nested objects\n if (typeof value === 'object' && value !== null)\n return this._createAccessTrackingProxy(value, accessedPaths, fullPath)\n\n return value\n },\n })\n }\n\n /**\n * Returns memory wrapped in a tracking Proxy\n */\n get memory() {\n const currentObserver = getObserver()\n\n if (!currentObserver) return this._memory\n\n if (!this._listeners.has(currentObserver))\n this._listeners.set(currentObserver, new Set())\n\n const accessedPaths = this._listeners.get(currentObserver)\n\n return this._createAccessTrackingProxy(this._memory, accessedPaths)\n }\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children]\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat()\n .filter((c) => c !== null && c !== undefined && c !== false && c !== '')\n\n return {\n tag,\n props,\n children: cleanChildren,\n }\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from './observer.js'\nimport { patch } from './patch.js'\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null\n\n const lifecycle = () => {\n setObserver(lifecycle)\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n }\n\n patch(target, nextVNode, prevVNode)\n setObserver(null)\n prevVNode = nextVNode\n }\n\n lifecycle()\n}\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from './observer.js'\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance()\n if (instance) {\n instance.mounts.push(fn)\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance()\n if (instance) {\n instance.cleanups.push(fn)\n }\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","Humn","this","currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","styleSheet","cache","Set","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","children","some","c","props","key","createElement","vNode","namespace","document","createTextNode","String","tag","childVNode","renderComponent","child","el","hooks","mounts","length","setTimeout","forEach","fn","element","createElementNS","patchProps","childNS","appendChild","newProps","oldProps","allProps","oldValue","newValue","startsWith","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","i","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","Object","values","parentNode","runUnmount","removeChild","cleanups","renderedVNode","newVNode","isNew","replaceChild","nodeValue","Cortex","constructor","memory","synapses","liveMemory","_persistenceMap","Map","value","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","err","_memory","_listeners","updater","nextState","changedPaths","clone","structuredClone","result","_createChangeTrackingProxy","keys","add","size","stateKey","Array","from","path","setItem","stringify","_notifyRelevantListeners","obj","Proxy","get","target","prop","fullPath","accessedPaths","renderFn","accessedPath","changedPath","_createAccessTrackingProxy","has","css","stringsOrStr","args","raw","isSingleRoot","isArray","reduce","acc","str","content","replace","trim","hash","charCodeAt","toString","hashedClassName","id","head","textContent","h","flat","filter","mount","Component","prev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AAYpC,CAAAA,GAG5BA,EAAWoJ,aAAe,IAAIH,CAAAA;AAAAA,MAC1BN,CAAAA;AAAAA;AAAAA,EAEJ1I,EAAM4G,IAAIiC,CAAAA,GAZDG,CAeX,EEvECjK,EAAAqK,EEPgB,CAAChI,EAAKR,EAAQ,CAAA,EAAIH,EAAW,CAAA,KAQrC,CACLW,MACAR,MAAAA,EACAH,UAViBsG,MAAMuB,QAAQ7H,GAAYA,EAAW,CAACA,CAAAA,GAItD4I,KAAAA,EACAC,OAAQ3I,GAAMA,GAAAA,MAAiCA,IAAjCA,IAAgDA,IAAM,EAANA,CAAAA,GFClE5B,EAAAwK,MGXoB,CAAC/B,EAAQgC,IAAAA,CAC5B,IAAIC,EAAY,KAEhB,MAAMC,EAAY,IAAA,CAChBhK,EAAYgK,GAEZ,MAAMC,EAAY,CAChBvI,IAAKoI,EACL5I,MAAO,CAAA,EACPH,SAAU,IAGZgD,EAAM+D,EAAQmC,EAAWF,CAAAA,EACzB/J,EAAY,IAAA,EACZ+J,EAAYE,CAAAA,EAGdD,EAAAA,CAAAA,EHND3K,EAAA6K,UIFM,SAAmB9H,EAAAA,CACxB,MAAM+H,EAAWjK,EAAAA,EACbiK,GACFA,EAASrF,SAASsF,KAAKhI,CAAAA,CAE3B,EJHC/C,EAAAgL,QIbM,SAAiBjI,EAAAA,CACtB,MAAM+H,EAAWjK,IACbiK,GACFA,EAASnI,OAAOoI,KAAKhI,EAEzB,EJQC/C,EAAAiL,QAJsB,CAAChE,EAASP,EAAS,MAAE,CAC1CF,kBACAS,QAAAA,EACAP,OAAAA,CAAAA,GACDtB,OAAA8F,eAAAlL,EAAAmL,OAAAC,YAAA,CAAA9E,MAAA,QAAA,CAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"humn.umd.js","sources":["../src/observer.js","../src/css.js","../src/patch.js","../src/persist.js","../src/cortex.js","../src/h.js","../src/mount.js","../src/lifecycle.js"],"sourcesContent":["/**\n * @file Observer module for tracking global state during rendering.\n * @module observer\n */\n\nlet currentObserver = null // For Cortex/State dependency\nlet currentInstance = null // For Lifecycle Hooks\n\n/**\n * Gets the current observer (render function).\n * @returns {function|null}\n */\nexport const getObserver = () => currentObserver\n\n/**\n * Sets the current observer.\n * @param {function|null} obs\n */\nexport const setObserver = (obs) => {\n currentObserver = obs\n}\n\n/**\n * Gets the current component instance (hook container).\n * @returns {object|null}\n */\nexport const getInstance = () => currentInstance\n\n/**\n * Sets the current component instance.\n * @param {object|null} inst\n */\nexport const setInstance = (inst) => {\n currentInstance = inst\n}\n","/**\n * @file Runtime Scoped CSS implementation using Native CSS Nesting.\n * @module css\n */\n\nlet styleSheet = null\nconst cache = new Set()\n\n/**\n * Simple DJB2 hashing function.\n */\nfunction hashString(str) {\n let hash = 5381\n let i = str.length\n while (i) {\n hash = (hash * 33) ^ str.charCodeAt(--i)\n }\n return (hash >>> 0).toString(36)\n}\n\n/**\n * Lightweight Runtime Minifier.\n * Removes comments and collapses whitespace.\n * We do not strip spaces around colons/brackets to ensure safety for calc().\n */\nfunction minify(css) {\n return css\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse newlines/tabs to single space\n .trim() // Remove leading/trailing\n}\n\n/**\n * Scoped CSS Tag.\n * Wraps content in a unique class using Native CSS Nesting.\n * Supports two signatures:\n * 1. Tagged Template: css`...`\n * 2. Function: css(string, isSingleRoot)\n */\nexport function css(stringsOrStr, ...args) {\n let raw = ''\n let isSingleRoot = false\n\n // Detect usage of Tagged Template vs Function Call\n if (Array.isArray(stringsOrStr) && stringsOrStr.raw) {\n raw = stringsOrStr.reduce((acc, str, i) => {\n return acc + str + (args[i] || '')\n }, '')\n } else {\n raw = stringsOrStr\n // If called as function, the first arg is our boolean flag\n isSingleRoot = args[0] === true\n }\n let content = minify(raw)\n\n if (!content) return ''\n\n if (isSingleRoot) {\n // Transforms selectors to apply to BOTH the root (using &) AND descendants.\n // e.g. \"div\" -> \"div&, div\"\n\n // Regex Breakdown:\n // 1. (^|[{};,]) -> Hard Start (Line start, brace, semi, comma)\n // 2. (\\s*) -> Whitespace\n // 3. (?!from|to) -> Negative Lookahead: Ignore 'from'/'to' (keyframes)\n // 4. ( ... )+ -> Compound Selector:\n // (?:[.#]?[\\w-]+ ... ) -> Matches tags (div), classes (.class), ids (#id)\n // 5. (?=\\s*\\{) -> Lookahead: Must be followed by {\n\n content = content.replace(\n /(^|[{};,])(\\s*)(?!from|to)((?:[.#]?[\\w-]+|\\[[^\\]]+\\]|:{1,2}[^:,{\\s]+)+)(?=\\s*\\{)/gi,\n '$1$2$3&, $3',\n )\n }\n\n const hash = hashString(content)\n const hashedClassName = `humn-${hash}`\n\n if (cache.has(hash)) {\n return hashedClassName\n }\n\n if (!styleSheet) {\n styleSheet = document.createElement('style')\n styleSheet.id = 'humn-styles'\n document.head.appendChild(styleSheet)\n }\n\n styleSheet.textContent += `.${hashedClassName} { \n ${content} \n }\\n`\n cache.add(hash)\n\n return hashedClassName\n}\n","/**\n * @file This file contains the diffing and patching algorithm for the virtual DOM,\n * including support for Keyed Diffing.\n * @module patch\n */\nimport { track } from './metrics.js'\nimport { setInstance } from './observer.js'\n\nfunction getNamespace(parent) {\n if (parent.namespaceURI === SVG_NS && parent.tagName !== 'foreignObject') {\n return SVG_NS\n }\n if (parent.namespaceURI === MATH_NS) {\n return MATH_NS\n }\n return null\n}\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h.js\").VNode>} children - The list of VNodes.\n * @returns {boolean} True if keys are present.\n */\nexport function hasKeys(children) {\n return children && children.some((c) => c && c.props && c.props.key != null)\n}\n\nconst SVG_NS = 'http://www.w3.org/2000/svg'\nconst MATH_NS = 'http://www.w3.org/1998/Math/MathML'\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h.js\").VNode | string | number} vNode\n * @param {string} [namespace] - The current namespace URI (if any).\n * @returns {Text | HTMLElement | SVGElement}\n */\nfunction createElement(vNode, namespace) {\n if (typeof vNode === 'string' || typeof vNode === 'number') {\n return document.createTextNode(String(vNode))\n }\n\n if (typeof vNode.tag === 'function') {\n const childVNode = renderComponent(vNode)\n vNode.child = childVNode\n\n const el = createElement(childVNode, namespace)\n\n vNode.el = el\n if (vNode.hooks?.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0)\n }\n return el\n }\n\n track('elementsCreated')\n\n const tag = vNode.tag\n\n // We prioritize specific tag declarations over the inherited namespace.\n if (tag === 'svg') namespace = SVG_NS\n else if (tag === 'math') namespace = MATH_NS\n // NOTE: If we are inside 'foreignObject', we must NOT use the SVG NS.\n // We handle this by resetting 'ns' in the recursion step below,\n // so 'ns' entering here is already null for the foreignObject's children.\n\n // createElementNS is slower than createElement, so only use it if we have a namespace.\n const element = namespace\n ? document.createElementNS(namespace, tag)\n : document.createElement(tag)\n\n vNode.el = element\n patchProps(element, vNode.props)\n\n // If we are currently at a 'foreignObject', children must exit the SVG namespace.\n const childNS = tag === 'foreignObject' ? null : namespace\n\n vNode.children.forEach((child) => {\n element.appendChild(createElement(child, childNS))\n })\n\n return element\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} element - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n *\n * WHY: We check against the LIVE DOM value for inputs (value/checked) to prevent\n * the \"cursor jumping\" bug. If we just blindly set the attribute, the browser\n * might reset the cursor position to the end of the input.\n */\nfunction patchProps(element, newProps = {}, oldProps = {}) {\n if (!element) return\n\n const allProps = { ...oldProps, ...newProps }\n\n for (const key in allProps) {\n const oldValue = oldProps[key]\n const newValue = newProps[key]\n\n // Handle removed props\n if (newValue === undefined || newValue === null) {\n element.removeAttribute(key)\n track('patches')\n continue\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === 'value' || key === 'checked') {\n if (element[key] !== newValue) {\n element[key] = newValue\n track('patches')\n }\n continue\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue\n\n track('patches')\n\n // Handle Events\n if (key.startsWith('on')) {\n const eventName = key.slice(2).toLowerCase()\n if (oldValue) element.removeEventListener(eventName, oldValue)\n element.addEventListener(eventName, newValue)\n }\n // Handle the disabled attribute\n if (key === 'disabled') {\n element.disabled = newValue === true || newValue === 'true'\n }\n // Handle standard attributes\n else {\n element.setAttribute(key, newValue)\n }\n }\n}\n\n/**\n * Reconciles the children of a node, handling both simple lists and keyed reordering.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {Array<import(\"./h.js\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h.js\").VNode>} oldChildren - The old list of children.\n *\n * WHY: This is the most complex part of the VDOM. We need to efficiently update\n * a list of items. Without keys, we just update index-by-index, which is fast\n * but causes issues if items are reordered (state gets mixed up).\n * With keys, we can track items as they move around, preserving their state\n * and minimizing DOM operations.\n */\nfunction reconcileChildren(parent, newChildren, oldChildren) {\n const isKeyed = hasKeys(newChildren) || hasKeys(oldChildren)\n\n // If no keys are used, use the fast index-based simple loop.\n // This is faster for static lists or simple text replacements.\n if (!isKeyed) {\n const maxLen = Math.max(newChildren.length, oldChildren.length)\n for (let i = 0; i < maxLen; i++) {\n patch(parent, newChildren[i], oldChildren[i], i)\n }\n return\n }\n\n reconcileKeyedChildren(parent, newChildren, oldChildren)\n}\n\n/**\n * Handles the complex logic of reconciling keyed children.\n *\n * WHY: When keys are present, we can't just iterate by index. We need to map\n * existing children by their key so we can find them even if they've moved.\n * This allows us to re-use DOM nodes (preserving focus/state) instead of\n * destroying and re-creating them.\n */\nfunction reconcileKeyedChildren(parent, newChildren, oldChildren) {\n // Map existing children by Key for O(1) lookup\n const keyed = {}\n oldChildren.forEach((child, i) => {\n const key = (child.props && child.props.key) != null ? child.props.key : i\n keyed[key] = { vNode: child, index: i }\n })\n\n newChildren.forEach((newChild, i) => {\n const key =\n (newChild.props && newChild.props.key) != null ? newChild.props.key : i\n const existingChildMatch = keyed[key]\n\n if (existingChildMatch) {\n // A. MATCH FOUND - The item existed before\n const oldVNode = existingChildMatch.vNode\n\n // Update the node's content recursively\n patch(parent, newChild, oldVNode, i)\n\n // If the DOM node isn't in the right spot, move it.\n // We use oldVNode.el because patch transfers the ref, but just to be safe:\n const element = newChild.el || oldVNode.el\n\n // Get the node currently at this index in the real DOM\n const domChildAtIndex = parent.childNodes[i]\n\n // If the element exists but is in the wrong place, move it\n if (element && domChildAtIndex !== element) {\n parent.insertBefore(element, domChildAtIndex)\n track('patches')\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key]\n } else {\n // B. NO MATCH - This is a new item\n const newElement = createElement(newChild, getNamespace(parent))\n const domChildAtIndex = parent.childNodes[i]\n\n if (domChildAtIndex) {\n parent.insertBefore(newElement, domChildAtIndex)\n } else {\n parent.appendChild(newElement)\n }\n }\n })\n\n // Remove any old keys that weren't used in the new list\n Object.values(keyed).forEach(({ vNode }) => {\n if (vNode.el && vNode.el.parentNode === parent) {\n runUnmount(vNode) // Clean up hooks\n parent.removeChild(vNode.el)\n track('elementsRemoved')\n }\n })\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h.js\").VNode} vNode - The component vNode.\n * @returns {import(\"./h.js\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\n track('componentsRendered')\n\n // 1. Prepare Hook Container\n const hooks = {\n mounts: [],\n cleanups: [],\n }\n\n // 2. Set Global Scope\n setInstance(hooks)\n\n // 3. Run the User's Component Function\n // We pass props as the first argument\n const renderedVNode = vNode.tag(vNode.props)\n\n // 4. Clear Global Scope\n setInstance(null)\n\n // 5. Attach hooks to the VNode so we can run them later\n vNode.hooks = hooks\n\n return renderedVNode\n}\n\n/**\n * Helper to recursively run cleanup hooks when a tree is removed.\n * @param {import(\"./h.js\").VNode} vNode - The vNode to unmount.\n */\nfunction runUnmount(vNode) {\n if (!vNode) return\n\n // 1. Run hooks for this node\n if (vNode.hooks && vNode.hooks.cleanups) {\n vNode.hooks.cleanups.forEach((fn) => fn())\n }\n\n // 2. Recurse into child (if component)\n if (vNode.child) {\n runUnmount(vNode.child)\n }\n\n // 3. Recurse into children (if element)\n if (vNode.children) {\n vNode.children.forEach(runUnmount)\n }\n}\n\n/**\n * The main diffing function. Compares V-DOM trees and updates the real DOM.\n * @param {HTMLElement} parent - The parent DOM element.\n * @param {import(\"./h.js\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h.js\").VNode | string | number} oldVNode - The old virtual node.\n * @param {number} [index=0] - The index of the child node (used for simple diffing).\n */\nexport function patch(parent, newVNode, oldVNode, index = 0) {\n track('diffs')\n\n // Case 1: Removal - The new node is null/undefined, so we remove the old one.\n if (newVNode === undefined || newVNode === null) {\n const el = oldVNode.el || parent.childNodes[index]\n\n // Recursive Cleanup\n runUnmount(oldVNode)\n\n if (el) {\n parent.removeChild(el)\n track('elementsRemoved')\n }\n return\n }\n\n // Case 2: Component - If it's a function, we delegate to the component logic.\n if (typeof newVNode.tag === 'function') {\n const isNew = !oldVNode\n\n const childVNode = renderComponent(newVNode)\n newVNode.child = childVNode\n\n const oldChild = oldVNode ? oldVNode.child : undefined\n patch(parent, childVNode, oldChild, index)\n\n newVNode.el = childVNode.el\n\n // Run mount hooks on the next tick\n if (isNew && newVNode.hooks && newVNode.hooks.mounts.length > 0) {\n setTimeout(() => {\n newVNode.hooks.mounts.forEach((fn) => fn())\n }, 0)\n }\n // TODO: Handle updates (running old cleanups if necessary) for Phase 2\n return\n }\n\n // Case 3: Creation - No old node exists, so we create a new one.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode, getNamespace(parent)))\n return\n }\n\n // Case 4: Replacement - The node type changed (e.g. div -> span), so we replace it entirely.\n if (\n typeof newVNode !== typeof oldVNode ||\n (typeof newVNode !== 'string' && newVNode.tag !== oldVNode.tag)\n ) {\n const el = oldVNode.el || parent.childNodes[index]\n if (el) {\n parent.replaceChild(createElement(newVNode, getNamespace(parent)), el)\n track('patches')\n }\n return\n }\n\n // Case 5: Text Update - It's a text node, so we just update the text content.\n if (typeof newVNode === 'string' || typeof newVNode === 'number') {\n if (newVNode !== oldVNode) {\n const el = parent.childNodes[index]\n if (el) {\n el.nodeValue = String(newVNode)\n track('patches')\n } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)))\n }\n }\n return\n }\n\n // Case 6: Update - Same tag, so we update props and recurse into children.\n const el = oldVNode.el || parent.childNodes[index]\n\n if (!el) return\n\n // Transfer DOM reference to the new VNode\n newVNode.el = el\n\n patchProps(el, newVNode.props, oldVNode.props)\n\n reconcileChildren(el, newVNode.children, oldVNode.children)\n}\n","/**\n * Represents a value wrapped by the persist() function.\n * @template T\n * @typedef {object} Persisted\n * @property {T} initial\n * @property {boolean} __humn_persist\n * @property {PersistConfig} [config]\n */\n\n/**\n * @typedef {object} PersistConfig\n * @property {string} key\n */\n\n/**\n * Marks a section of the state for persistence in localStorage.\n * @template T\n * @param {T} initial\n * @param {PersistConfig} [config]\n * @returns {Persisted<T>}\n */\nexport const persist = (initial, config = {}) => ({\n __humn_persist: true,\n initial,\n config,\n})\n","import { isDev } from './metrics.js'\nimport { getObserver } from './observer.js'\n\n/**\n * Mapped type for the Memory configuration object.\n * Allows each property to be the raw value OR a persisted wrapper.\n * @template T\n * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput\n */\n\n/**\n * Deeply unwraps persisted values from the memory shape.\n * @template {object} T\n * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory\n */\n\n/**\n * @template T\n * @callback Getter\n * @returns {T}\n */\n\n/**\n * @template T\n * @callback Setter\n * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater\n * @returns {void}\n */\n\n/**\n * @template M, S\n * @callback SynapsesBuilder\n * @param {Setter<M>} set\n * @param {Getter<M>} get\n * @returns {S}\n */\n\n/**\n * @template M, S\n * @typedef {object} CortexConfig\n * @property {MemoryInput<M>} memory - The initial state configuration\n * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function\n */\n\n/**\n * The Cortex class manages the state of the application.\n *\n * @template {object} MemoryType The shape of the application state\n * @template {object} SynapsesType The shape of the actions/methods\n */\nexport class Cortex {\n /**\n * Creates an instance of Cortex.\n * @param {CortexConfig<MemoryType, SynapsesType>} config\n */\n constructor({ memory, synapses }) {\n const liveMemory = { ...memory }\n this._persistenceMap = new Map()\n\n // Load in any existing values from local-storage\n for (const [key, value] of Object.entries(memory)) {\n if (value && typeof value === 'object' && value.__humn_persist) {\n const storageKey = value.config?.key || key\n this._persistenceMap.set(key, storageKey)\n\n try {\n const stored = localStorage.getItem(storageKey)\n if (stored !== null) {\n liveMemory[key] = JSON.parse(stored)\n } else {\n liveMemory[key] = value.initial\n }\n } catch (err) {\n if (isDev)\n console.warn(`Humn: Failed to load '${key}' from storage.`, err)\n liveMemory[key] = value.initial\n }\n }\n }\n\n /** @type {UnwrappedMemory<MemoryType>} */\n this._memory = liveMemory\n this._listeners = new Map()\n\n /** @type {Getter<UnwrappedMemory<MemoryType>>} */\n const get = () => this._memory\n\n /** @type {Setter<UnwrappedMemory<MemoryType>>} */\n const set = (updater) => {\n let nextState\n let changedPaths = new Set()\n\n if (typeof updater === 'function') {\n const clone = structuredClone(this._memory)\n const proxy = this._createChangeTrackingProxy(clone, changedPaths)\n const result = updater(proxy)\n\n if (result && typeof result === 'object') {\n nextState = { ...this._memory, ...result }\n Object.keys(result).forEach((key) => changedPaths.add(key))\n } else {\n nextState = clone\n }\n } else {\n nextState = { ...this._memory, ...updater }\n changedPaths = new Set(Object.keys(updater))\n }\n\n this._memory = nextState\n\n // Persistence logic\n if (this._persistenceMap.size > 0) {\n this._persistenceMap.forEach((storageKey, stateKey) => {\n const isDirty = Array.from(changedPaths).some(\n (path) => path === stateKey || path.startsWith(stateKey + '.'),\n )\n\n if (isDirty) {\n try {\n const value = this._memory[stateKey]\n localStorage.setItem(storageKey, JSON.stringify(value))\n } catch (err) {\n if (isDev)\n console.error(`Humn: Failed to save '${stateKey}'.`, err)\n }\n }\n })\n }\n\n this._notifyRelevantListeners(changedPaths)\n }\n\n /** @type {SynapsesType} */\n this.synapses = synapses(set, get)\n }\n\n /**\n * Creates a Proxy that tracks which properties are being mutated.\n * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.\n *\n * WHY: We need to know exactly which paths were changed so we can notify ONLY\n * the components that care about those specific paths. If we just knew \"something changed\",\n * we'd have to re-render the whole app (like Redux) or rely on manual optimization.\n */\n _createChangeTrackingProxy(obj, changedPaths, path = '') {\n return new Proxy(obj, {\n get: (target, prop) => {\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const value = target[prop]\n const fullPath = path ? `${path}.${prop}` : prop\n\n // Recursively proxy nested objects so we can trap their sets too\n if (typeof value === 'object' && value !== null) {\n return this._createChangeTrackingProxy(value, changedPaths, fullPath)\n }\n return value\n },\n set: (target, prop, value) => {\n if (typeof prop === 'symbol' || prop === '__proto__') {\n target[prop] = value\n return true\n }\n\n const fullPath = path ? `${path}.${prop}` : prop\n changedPaths.add(fullPath)\n\n target[prop] = value\n return true\n },\n })\n }\n\n /**\n * Only notify listeners that read properties which changed\n */\n _notifyRelevantListeners(changedPaths) {\n this._listeners.forEach((accessedPaths, renderFn) => {\n const shouldNotify = Array.from(accessedPaths).some((accessedPath) => {\n return Array.from(changedPaths).some((changedPath) => {\n // Check for exact match or parent/child relationship\n return (\n accessedPath === changedPath ||\n accessedPath.startsWith(changedPath + '.') ||\n changedPath.startsWith(accessedPath + '.')\n )\n })\n })\n\n if (shouldNotify) renderFn()\n })\n }\n\n /**\n * Creates a Proxy that tracks which properties are accessed during render\n *\n * WHY: This is the other half of the magic. By tracking what a component READS\n * during its render, we build a precise dependency graph. If a component reads\n * `state.user.name`, it will only re-render when `state.user.name` changes,\n * not when `state.count` changes.\n */\n _createAccessTrackingProxy(obj, accessedPaths, path = '') {\n if (typeof obj !== 'object' || obj === null) return obj\n\n return new Proxy(obj, {\n get: (target, prop) => {\n // We don't care about prototype and symbol properties\n if (typeof prop === 'symbol' || prop === '__proto__')\n return target[prop]\n\n const fullPath = path ? `${path}.${prop}` : prop\n accessedPaths.add(fullPath)\n\n const value = target[prop]\n\n // Recursively wrap nested objects\n if (typeof value === 'object' && value !== null)\n return this._createAccessTrackingProxy(value, accessedPaths, fullPath)\n\n return value\n },\n })\n }\n\n /**\n * @returns {UnwrappedMemory<MemoryType>}\n */\n get memory() {\n const currentObserver = getObserver()\n\n if (!currentObserver) return this._memory\n\n if (!this._listeners.has(currentObserver))\n this._listeners.set(currentObserver, new Set())\n\n const accessedPaths = this._listeners.get(currentObserver)\n\n return this._createAccessTrackingProxy(this._memory, accessedPaths)\n }\n}\n","/**\n * @typedef {object} VNode\n * @property {string} tag\n * @property {object} props\n * @property {VNode[]} children\n */\n\n/**\n * Creates a virtual DOM node.\n * This is a hyperscript-like function.\n *\n * @param {string} tag - The tag name of the element.\n * @param {object} props - The properties of the element.\n * @param {VNode[]|VNode} children - The children of the element.\n * @returns {VNode} The virtual DOM node.\n */\nexport const h = (tag, props = {}, children = []) => {\n const childArray = Array.isArray(children) ? children : [children]\n\n // Filter out null/false so we don't have \"ghost\" nodes\n const cleanChildren = childArray\n .flat()\n .filter((c) => c !== null && c !== undefined && c !== false && c !== '')\n\n return {\n tag,\n props,\n children: cleanChildren,\n }\n}\n","/**\n * @file Mounts the application to the DOM.\n * @module mount\n */\nimport { setObserver } from './observer.js'\nimport { patch } from './patch.js'\n\n/**\n * Mounts a component to a target DOM element.\n * @param {HTMLElement} target - The DOM element to mount to.\n * @param {function} Component - The root component function.\n */\nexport const mount = (target, Component) => {\n let prevVNode = null\n\n const lifecycle = () => {\n setObserver(lifecycle)\n\n const nextVNode = {\n tag: Component,\n props: {},\n children: [],\n }\n\n patch(target, nextVNode, prevVNode)\n setObserver(null)\n prevVNode = nextVNode\n }\n\n lifecycle()\n}\n","/**\n * @file Lifecycle hooks for components.\n * @module lifecycle\n */\nimport { getInstance } from './observer.js'\n\n/**\n * Registers a callback to run after the component mounts.\n * @param {function} fn - The callback function.\n */\nexport function onMount(fn) {\n const instance = getInstance()\n if (instance) {\n instance.mounts.push(fn)\n }\n}\n\n/**\n * Registers a callback to run when the component unmounts.\n * @param {function} fn - The callback function.\n */\nexport function onCleanup(fn) {\n const instance = getInstance()\n if (instance) {\n instance.cleanups.push(fn)\n }\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","Humn","this","currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","styleSheet","cache","Set","getNamespace","parent","namespaceURI","SVG_NS","tagName","MATH_NS","hasKeys","children","some","c","props","key","createElement","vNode","namespace","document","createTextNode","String","tag","childVNode","renderComponent","child","el","hooks","mounts","length","setTimeout","forEach","fn","element","createElementNS","patchProps","childNS","appendChild","newProps","oldProps","allProps","oldValue","newValue","startsWith","eventName","slice","toLowerCase","removeEventListener","addEventListener","disabled","setAttribute","removeAttribute","reconcileChildren","newChildren","oldChildren","maxLen","Math","max","i","patch","keyed","index","newChild","existingChildMatch","oldVNode","domChildAtIndex","childNodes","insertBefore","newElement","Object","values","parentNode","runUnmount","removeChild","cleanups","renderedVNode","newVNode","isNew","replaceChild","nodeValue","Cortex","constructor","memory","synapses","liveMemory","_persistenceMap","Map","value","entries","__humn_persist","storageKey","config","set","stored","localStorage","getItem","JSON","parse","initial","_memory","_listeners","updater","nextState","changedPaths","clone","structuredClone","result","_createChangeTrackingProxy","keys","add","size","stateKey","Array","from","path","setItem","stringify","_notifyRelevantListeners","obj","Proxy","get","target","prop","fullPath","accessedPaths","renderFn","accessedPath","changedPath","_createAccessTrackingProxy","has","css","stringsOrStr","args","raw","isSingleRoot","isArray","reduce","acc","str","content","replace","trim","hash","charCodeAt","toString","hashedClassName","id","head","textContent","h","flat","filter","mount","Component","prevVNode","lifecycle","nextVNode","onCleanup","instance","push","onMount","persist","defineProperty","Symbol","toStringTag"],"mappings":"CAAA,SAAAA,EAAAC,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X,EErEChK,EAAAoK,EETgB,CAAC/H,EAAKR,EAAQ,CAAA,EAAIH,EAAW,CAAA,KAQrC,CACLW,MACAR,MAAAA,EACAH,UAViBqG,MAAMuB,QAAQ5H,GAAYA,EAAW,CAACA,CAAAA,GAItD2I,KAAAA,EACAC,OAAQ1I,GAAMA,GAAAA,MAAiCA,IAAjCA,IAAgDA,IAAM,EAANA,CAAAA,GFGlE5B,EAAAuK,MGboB,CAAC/B,EAAQgC,IAAAA,CAC5B,IAAIC,EAAY,KAEhB,MAAMC,EAAY,IAAA,CAChB/J,EAAY+J,GAEZ,MAAMC,EAAY,CAChBtI,IAAKmI,EACL3I,MAAO,CAAA,EACPH,SAAU,IAGZgD,EAAM8D,EAAQmC,EAAWF,CAAAA,EACzB9J,EAAY,IAAA,EACZ8J,EAAYE,CAAAA,EAGdD,EAAAA,CAAAA,EHJD1K,EAAA4K,UIJM,SAAmB7H,EAAAA,CACxB,MAAM8H,EAAWhK,EAAAA,EACbgK,GACFA,EAASpF,SAASqF,KAAK/H,CAAAA,CAE3B,EJDC/C,EAAA+K,QIfM,SAAiBhI,EAAAA,CACtB,MAAM8H,EAAWhK,IACbgK,GACFA,EAASlI,OAAOmI,KAAK/H,EAEzB,EJUC/C,EAAAgL,QAJsB,CAAC/D,EAASP,EAAS,MAAE,CAC1CF,kBACAS,QAAAA,EACAP,OAAAA,CAAAA,GACDtB,OAAA6F,eAAAjL,EAAAkL,OAAAC,YAAA,CAAA7E,MAAA,QAAA,CAAA,CAAA,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,33 +1,56 @@
1
1
  /**
2
- * @typedef {object} Synapses@typedef {object} Synapses
3
- * @property {function} set - Function to update the memory
4
- * @property {function} get - Function to get the memory
2
+ * Mapped type for the Memory configuration object.
3
+ * Allows each property to be the raw value OR a persisted wrapper.
4
+ * @template T
5
+ * @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput
5
6
  */
6
7
  /**
7
- * @typedef {object} CortexParams@typedef {object} CortexParams
8
- * @property {object} memory - The initial state
9
- * @property {function(function, function): object} synapses - The synapses function
8
+ * Deeply unwraps persisted values from the memory shape.
9
+ * @template {object} T
10
+ * @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory
11
+ */
12
+ /**
13
+ * @template T
14
+ * @callback Getter@callback Getter
15
+ * @returns {T}
16
+ */
17
+ /**
18
+ * @template T
19
+ * @callback Setter@callback Setter
20
+ * @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater
21
+ * @returns {void}
22
+ */
23
+ /**
24
+ * @template M, S
25
+ * @callback SynapsesBuilder@callback SynapsesBuilder
26
+ * @param {Setter<M>} set
27
+ * @param {Getter<M>} get
28
+ * @returns {S}
29
+ */
30
+ /**
31
+ * @template M, S
32
+ * @typedef {object} CortexConfig@typedef {object} CortexConfig
33
+ * @property {MemoryInput<M>} memory - The initial state configuration
34
+ * @property {SynapsesBuilder<M, S>} synapses - The synapses builder function
10
35
  */
11
36
  /**
12
37
  * The Cortex class manages the state of the application.
13
- * This uses a Proxy for fine-grained reactivity, ensuring only those components
14
- * which use the updated value get re-rendered.
15
38
  *
16
- * WHY: We use Proxies instead of simple getters/setters because it allows us to
17
- * detect access to nested properties dynamically without needing to declare
18
- * dependencies upfront. This "magic" auto-subscription is what makes Humn's
19
- * DX so clean.
39
+ * @template {object} MemoryType The shape of the application state
40
+ * @template {object} SynapsesType The shape of the actions/methods
20
41
  */
21
- export declare class Cortex {
42
+ export declare class Cortex<MemoryType extends unknown, SynapsesType extends unknown> {
22
43
  /**
23
44
  * Creates an instance of Cortex.
24
- * @param {CortexParams} CortexParams - The parameters for the Cortex.
45
+ * @param {CortexConfig<MemoryType, SynapsesType>} config
25
46
  */
26
- constructor({ memory, synapses }: CortexParams);
47
+ constructor({ memory, synapses }: CortexConfig<MemoryType, SynapsesType>);
27
48
  _persistenceMap: Map<any, any>;
28
- _memory: any;
49
+ /** @type {UnwrappedMemory<MemoryType>} */
50
+ _memory: UnwrappedMemory<MemoryType>;
29
51
  _listeners: Map<any, any>;
30
- synapses: any;
52
+ /** @type {SynapsesType} */
53
+ synapses: SynapsesType;
31
54
  /**
32
55
  * Creates a Proxy that tracks which properties are being mutated.
33
56
  * Includes a GET trap to recursively proxy nested objects for deep mutation tracking.
@@ -51,20 +74,20 @@ export declare class Cortex {
51
74
  */
52
75
  _createAccessTrackingProxy(obj: any, accessedPaths: any, path?: string): any;
53
76
  /**
54
- * Returns memory wrapped in a tracking Proxy
77
+ * @returns {UnwrappedMemory<MemoryType>}
55
78
  */
56
- get memory(): any;
79
+ get memory(): UnwrappedMemory<MemoryType>;
57
80
  }
58
81
 
59
- export declare type CortexParams = {
82
+ export declare type CortexConfig<M, S> = {
60
83
  /**
61
- * - The initial state
84
+ * - The initial state configuration
62
85
  */
63
- memory: object;
86
+ memory: MemoryInput<M>;
64
87
  /**
65
- * - The synapses function
88
+ * - The synapses builder function
66
89
  */
67
- synapses: (arg0: Function, arg1: Function) => object;
90
+ synapses: SynapsesBuilder<M, S>;
68
91
  };
69
92
 
70
93
  /**
@@ -76,13 +99,15 @@ export declare type CortexParams = {
76
99
  */
77
100
  export declare function css(stringsOrStr: any, ...args: any[]): string;
78
101
 
102
+ export declare type Getter<T> = () => T;
103
+
79
104
  export declare function h(tag: string, props?: object, children?: VNode[] | VNode): VNode;
80
105
 
81
- export declare type HumnPersist = {
82
- __humn_persist: boolean;
83
- initial: any;
84
- config: PersistConfig;
85
- };
106
+ /**
107
+ * Mapped type for the Memory configuration object.
108
+ * Allows each property to be the raw value OR a persisted wrapper.
109
+ */
110
+ export declare type MemoryInput<T> = { [K in keyof T]: T[K] | Persisted<T[K]>; };
86
111
 
87
112
  export declare function mount(target: HTMLElement, Component: Function): void;
88
113
 
@@ -98,23 +123,30 @@ export declare function onCleanup(fn: Function): void;
98
123
  */
99
124
  export declare function onMount(fn: Function): void;
100
125
 
101
- export declare function persist(initial: any, config?: PersistConfig): HumnPersist;
126
+ export declare function persist<T>(initial: T, config?: PersistConfig): Persisted<T>;
102
127
 
103
128
  export declare type PersistConfig = {
104
129
  key: string;
105
130
  };
106
131
 
107
- export declare type Synapses = {
108
- /**
109
- * - Function to update the memory
110
- */
111
- set: Function;
112
- /**
113
- * - Function to get the memory
114
- */
115
- get: Function;
132
+ /**
133
+ * Represents a value wrapped by the persist() function.
134
+ */
135
+ export declare type Persisted<T> = {
136
+ initial: T;
137
+ __humn_persist: boolean;
138
+ config?: PersistConfig;
116
139
  };
117
140
 
141
+ export declare type Setter<T> = (updater: Partial<T> | ((state: T) => void | Partial<T> | unknown)) => void;
142
+
143
+ export declare type SynapsesBuilder<M, S> = (set: Setter<M>, get: Getter<M>) => S;
144
+
145
+ /**
146
+ * Deeply unwraps persisted values from the memory shape.
147
+ */
148
+ export declare type UnwrappedMemory<T extends unknown> = { [K in keyof T]: T[K] extends Persisted<infer I> ? I : T[K]; };
149
+
118
150
  export declare type VNode = {
119
151
  tag: string;
120
152
  props: object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humn",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "description": "A minimal, human-centric reactive UI library with built in state management.",
5
5
  "keywords": [
6
6
  "reactive",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "scripts": {
36
36
  "build": "vite build",
37
- "dev": "node --inspect ../../node_modules/vite/bin/vite.js --port 3000 --open /playground/",
37
+ "dev": "concurrently 'yarn vite build --watch' 'node --inspect ../../node_modules/vite/bin/vite.js --port 3000 --open /playground/'",
38
38
  "prepublishOnly": "npm run build",
39
39
  "qa:test": "vitest run",
40
40
  "qa:test:watch": "vitest watch"
@@ -46,6 +46,7 @@
46
46
  "@semantic-release/github": "^12.0.2",
47
47
  "@semantic-release/npm": "^13.1.2",
48
48
  "@types/node": "^24.10.1",
49
+ "concurrently": "^9.2.1",
49
50
  "conventional-changelog-conventionalcommits": "^9.1.0",
50
51
  "jsdom": "^27.2.0",
51
52
  "semantic-release": "^25.0.2",