humn 0.0.2

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/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Humn (Human)
2
+
3
+ > **The organic, human-centric UI library for the modern web.**
4
+
5
+ **Humn** is a complete, reactive frontend library with built in state management designed to replace the likes of React/Svelte/Solid AND Zustand/Kea/Redux in your stack.
6
+
7
+ It rejects the complexity of modern frameworks \* no stale closures, no "Hook Rules", and no heavy compilers. Humn decouples your application's **Cortex** (Logic/State) from its **Body** (View), creating applications that are easy to reason about, simple to test, and naturally reactive.
8
+
9
+ ## Core Features
10
+
11
+ - **🧬 Biological Architecture:** A strict separation of concerns. Your data lives in the `Cortex`; your UI is just a dumb projection of that memory.
12
+ - **âš¡ Zero-Build Reactive View:** Write standard JavaScript. Components are just functions that return virtual DOM nodes. No compilation required (unless you want it).
13
+ - **🧠 Built-in Global State:** No need for Redux or Zustand. The `Cortex` is built-in, handling deep updates, async actions, and side effects out of the box.
14
+ - **mutative syntax, immutable updates:** Write `state.count++`. We handle the immutability and render triggers for you.
15
+ - **🎨 Scoped Styles:** Encapsulated CSS that lives alongside your components.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install humn
21
+ # or yarn add humn
22
+ # or pnpm install humn
23
+ ```
24
+
25
+ ## The "Hello World" (That actually scales)
26
+
27
+ Unlike other libraries, Humn encourages separating logic from the start.
28
+
29
+ ### The Cortex (Logic)
30
+
31
+ ```JavaScript
32
+
33
+ import { Cortex } from 'humn';
34
+
35
+ export const appStore = new Cortex({
36
+ memory: {
37
+ count: 0,
38
+ user: 'Guest'
39
+ },
40
+ synapses: (set, get) => ({
41
+ increment: () => set(state => { state.count++ }),
42
+ login: (name) => set({ user: name })
43
+ })
44
+ });
45
+ ```
46
+
47
+ ### The View (UI)
48
+
49
+ ```JavaScript
50
+
51
+ import { h, mount } from 'humn-js';
52
+ import { appStore } from './store';
53
+
54
+ const App = () => {
55
+ // 1. Read Memory (Auto-subscribes)
56
+ const { count, user } = appStore.memory;
57
+ const { increment } = appStore.synapses;
58
+
59
+ // 2. Return V-DOM
60
+ return h('div', { class: 'container' }, [
61
+ h('h1', {}, `Hello, ${user}`),
62
+ h('p', {}, `Vital Signs: ${count}`),
63
+ h('button', { onclick: increment }, 'Pulse')
64
+ ]);
65
+ };
66
+
67
+ // 3. Mount
68
+ mount(document.getElementById('root'), App);
69
+ ```
70
+
71
+ ## Roadmap
72
+
73
+ ### Phase 1: The Core Engine (Current)
74
+
75
+ - [x] **Cortex:** State management with dependency tracking.
76
+ - [x] **Virtual DOM:** Lightweight `h()` function.
77
+ - [x] **Reconciliation:** Keyed Diffing Algorithm.
78
+ - [x] **Scoped Styles:** Runtime CSS-in-JS with `css` tag.
79
+ - [x] **Lifecycle Hooks:** `onMount` and `onCleanup` for components (Needed for API calls/Timers).
80
+
81
+ ### Phase 2: The Ecosystem (Next)
82
+
83
+ - [ ] **Global Store Persist:** Middleware to save Cortex state to `localStorage`.
84
+ - [ ] **Router:** A built-in store that syncs with `window.history`.
85
+ - [ ] **Async Components:** Handling `Promise` rendering (Suspense).
86
+
87
+ ### Phase 3: Developer Experience
88
+
89
+ - [ ] **Humn Compiler:** `.humn` files for Svelte-like syntax.
90
+ - [ ] **DevTools:** Browser extension to inspect the Cortex Memory.
91
+
92
+ ## Contributing
93
+
94
+ We are building a library for humans, by humans. Please read CODING_STANDARDS.md before pushing code.
package/dist/humn.js ADDED
@@ -0,0 +1,207 @@
1
+ let C = null, S = null;
2
+ const x = () => C, g = (t) => {
3
+ C = t;
4
+ }, A = () => S, k = (t) => {
5
+ S = t;
6
+ };
7
+ class T {
8
+ /**
9
+ * Creates an instance of Cortex.
10
+ * @param {CortexParams} CortexParams - The parameters for the Cortex.
11
+ */
12
+ constructor({ memory: e, synapses: s }) {
13
+ this._memory = e, this._listeners = /* @__PURE__ */ new Set();
14
+ const i = () => this._memory, c = (n) => {
15
+ let r;
16
+ if (typeof n == "function") {
17
+ const o = structuredClone(this._memory);
18
+ r = n(o) || o;
19
+ } else
20
+ r = { ...this._memory, ...n };
21
+ this._memory = r, this._listeners.forEach((o) => o());
22
+ };
23
+ this.synapses = s(c, i);
24
+ }
25
+ /**
26
+ * Get the memory and register the current observer.
27
+ * @returns {object} The current state
28
+ */
29
+ get memory() {
30
+ const e = x();
31
+ return e && this._listeners.add(e), this._memory;
32
+ }
33
+ }
34
+ let h = null;
35
+ const E = /* @__PURE__ */ new Set();
36
+ function I(t) {
37
+ let e = 5381, s = t.length;
38
+ for (; s; )
39
+ e = e * 33 ^ t.charCodeAt(--s);
40
+ return (e >>> 0).toString(36);
41
+ }
42
+ function O(t) {
43
+ return t.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").trim();
44
+ }
45
+ function K(t, ...e) {
46
+ const s = t.reduce((r, o, l) => r + o + (e[l] || ""), ""), i = O(s);
47
+ if (!i) return "";
48
+ const c = I(i), n = `humn-${c}`;
49
+ return E.has(c) || (h || (h = document.createElement("style"), h.id = "humn-styles", document.head.appendChild(h)), h.textContent += `.${n} {
50
+ ${i}
51
+ }
52
+ `, E.add(c)), n;
53
+ }
54
+ const $ = (t, e = {}, s = []) => {
55
+ const c = (Array.isArray(s) ? s : [s]).flat().filter((n) => n != null && n !== !1 && n !== "");
56
+ return {
57
+ tag: t,
58
+ props: e,
59
+ children: c
60
+ };
61
+ };
62
+ function B(t) {
63
+ const e = A();
64
+ e && e.mounts.push(t);
65
+ }
66
+ function M(t) {
67
+ const e = A();
68
+ e && e.cleanups.push(t);
69
+ }
70
+ function b(t) {
71
+ return t && t.some((e) => e && e.props && e.props.key != null);
72
+ }
73
+ function a(t) {
74
+ if (typeof t == "string" || typeof t == "number")
75
+ return document.createTextNode(String(t));
76
+ if (typeof t.tag == "function") {
77
+ const s = d(t);
78
+ t.child = s;
79
+ const i = a(s);
80
+ return t.el = i, t.hooks && t.hooks.mounts.length > 0 && setTimeout(() => t.hooks.mounts.forEach((c) => c()), 0), i;
81
+ }
82
+ const e = document.createElement(t.tag);
83
+ return t.el = e, _(e, t.props), t.children.forEach((s) => {
84
+ e.appendChild(a(s));
85
+ }), e;
86
+ }
87
+ function _(t, e = {}, s = {}) {
88
+ if (!t) return;
89
+ const i = { ...s, ...e };
90
+ for (const c in i) {
91
+ const n = s[c], r = e[c];
92
+ if (r == null) {
93
+ t.removeAttribute(c);
94
+ continue;
95
+ }
96
+ if (c === "value" || c === "checked") {
97
+ t[c] !== r && (t[c] = r);
98
+ continue;
99
+ }
100
+ if (n !== r) {
101
+ if (c.startsWith("on")) {
102
+ const o = c.slice(2).toLowerCase();
103
+ n && t.removeEventListener(o, n), t.addEventListener(o, r);
104
+ }
105
+ c === "disabled" ? t.disabled = r === !0 || r === "true" : t.setAttribute(c, r);
106
+ }
107
+ }
108
+ }
109
+ function L(t, e, s) {
110
+ if (!(b(e) || b(s))) {
111
+ const n = Math.max(e.length, s.length);
112
+ for (let r = 0; r < n; r++)
113
+ m(t, e[r], s[r], r);
114
+ return;
115
+ }
116
+ const c = {};
117
+ s.forEach((n, r) => {
118
+ const o = (n.props && n.props.key) != null ? n.props.key : r;
119
+ c[o] = { vNode: n, index: r };
120
+ }), e.forEach((n, r) => {
121
+ const o = (n.props && n.props.key) != null ? n.props.key : r, l = c[o];
122
+ if (l) {
123
+ const f = l.vNode;
124
+ m(t, n, f, r);
125
+ const u = n.el || f.el, y = t.childNodes[r];
126
+ u && y !== u && t.insertBefore(u, y), delete c[o];
127
+ } else {
128
+ const f = a(n), u = t.childNodes[r];
129
+ u ? t.insertBefore(f, u) : t.appendChild(f);
130
+ }
131
+ }), Object.values(c).forEach(({ vNode: n }) => {
132
+ n.el && n.el.parentNode === t && t.removeChild(n.el);
133
+ });
134
+ }
135
+ function d(t) {
136
+ const e = {
137
+ mounts: [],
138
+ cleanups: []
139
+ };
140
+ k(e);
141
+ const s = t.tag(t.props);
142
+ return k(null), t.hooks = e, s;
143
+ }
144
+ function p(t) {
145
+ t && (t.hooks && t.hooks.cleanups && t.hooks.cleanups.forEach((e) => e()), t.child && p(t.child), t.children && t.children.forEach(p));
146
+ }
147
+ function m(t, e, s, i = 0) {
148
+ if (e == null) {
149
+ const n = s.el || t.childNodes[i];
150
+ p(s), n && t.removeChild(n);
151
+ return;
152
+ }
153
+ if (typeof e.tag == "function") {
154
+ const n = !s, r = d(e);
155
+ e.child = r;
156
+ const o = s ? s.child : void 0;
157
+ m(t, r, o, i), e.el = r.el, n && e.hooks && e.hooks.mounts.length > 0 && setTimeout(() => {
158
+ e.hooks.mounts.forEach((l) => l());
159
+ }, 0);
160
+ return;
161
+ }
162
+ if (s == null) {
163
+ t.appendChild(a(e));
164
+ return;
165
+ }
166
+ if (e == null) {
167
+ const n = s.el || t.childNodes[i];
168
+ n && t.removeChild(n);
169
+ return;
170
+ }
171
+ if (typeof e != typeof s || typeof e != "string" && e.tag !== s.tag) {
172
+ const n = s.el || t.childNodes[i];
173
+ n && t.replaceChild(a(e), n);
174
+ return;
175
+ }
176
+ if (typeof e == "string" || typeof e == "number") {
177
+ if (e !== s) {
178
+ const n = t.childNodes[i];
179
+ n ? n.nodeValue = String(e) : t.appendChild(document.createTextNode(String(e)));
180
+ }
181
+ return;
182
+ }
183
+ const c = s.el || t.childNodes[i];
184
+ c && (e.el = c, _(c, e.props, s.props), L(c, e.children, s.children));
185
+ }
186
+ const j = (t, e) => {
187
+ let s = null;
188
+ const i = () => {
189
+ g(i);
190
+ const c = {
191
+ tag: e,
192
+ props: {},
193
+ children: []
194
+ };
195
+ m(t, c, s), g(null), s = c;
196
+ };
197
+ i();
198
+ };
199
+ export {
200
+ T as Cortex,
201
+ K as css,
202
+ $ as h,
203
+ j as mount,
204
+ M as onCleanup,
205
+ B as onMount
206
+ };
207
+ //# sourceMappingURL=humn.js.map
@@ -0,0 +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"],"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 { 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 */\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 this._memory = memory;\n this._listeners = new Set();\n\n const get = () => this._memory;\n\n const set = (updater) => {\n let nextState;\n if (typeof updater === \"function\") {\n const clone = structuredClone(this._memory);\n const result = updater(clone);\n nextState = result || clone;\n } else {\n nextState = { ...this._memory, ...updater };\n }\n\n this._memory = nextState;\n this._listeners.forEach((render) => render());\n };\n\n this.synapses = synapses(set, get);\n }\n\n /**\n * Get the memory and register the current observer.\n * @returns {object} The current state\n */\n get memory() {\n const currentObserver = getObserver();\n if (currentObserver) this._listeners.add(currentObserver);\n return this._memory;\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 */\nexport function css(strings, ...args) {\n const raw = strings.reduce((acc, str, i) => {\n return acc + str + (args[i] || \"\");\n }, \"\");\n\n const content = minify(raw);\n\n if (!content) return \"\";\n\n const hash = hashString(content);\n const className = `humn-${hash}`;\n\n if (cache.has(hash)) {\n return className;\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 += `.${className} { \n ${content} \n }\\n`;\n cache.add(hash);\n\n return className;\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 { setInstance } from \"./observer.js\";\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h\").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\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h\").VNode | string | number} vNode - The virtual node.\n * @returns {Text | HTMLElement} The created DOM element.\n */\nfunction createElement(vNode) {\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 // Recursively create the DOM for the child\n const el = createElement(childVNode);\n vNode.el = el;\n\n // Queue Mount Hooks\n if (vNode.hooks && vNode.hooks.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0);\n }\n return el;\n }\n\n const el = document.createElement(vNode.tag);\n vNode.el = el;\n patchProps(el, vNode.props);\n\n vNode.children.forEach((child) => {\n el.appendChild(createElement(child));\n });\n\n return el;\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} el - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n */\nfunction patchProps(el, newProps = {}, oldProps = {}) {\n if (!el) 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 el.removeAttribute(key);\n continue;\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === \"value\" || key === \"checked\") {\n if (el[key] !== newValue) {\n el[key] = newValue;\n }\n continue;\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue;\n\n // Handle Events\n if (key.startsWith(\"on\")) {\n const eventName = key.slice(2).toLowerCase();\n if (oldValue) el.removeEventListener(eventName, oldValue);\n el.addEventListener(eventName, newValue);\n }\n // Handle the disabled attribute\n if (key === \"disabled\") {\n el.disabled = newValue === true || newValue === \"true\";\n }\n // Handle standard attributes\n else {\n el.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\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h\").VNode>} oldChildren - The old list of children.\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 // Keyed Diffing\n // Map existing children by Key\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 oldItem = keyed[key];\n\n if (oldItem) {\n // A. MATCH FOUND\n const oldVNode = oldItem.vNode;\n\n // Update the node's content (Recursion)\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 el = 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 (el && domChildAtIndex !== el) {\n parent.insertBefore(el, domChildAtIndex);\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key];\n } else {\n // B. NO MATCH (New Item)\n const newEl = createElement(newChild);\n const domChildAtIndex = parent.childNodes[i];\n\n if (domChildAtIndex) {\n parent.insertBefore(newEl, domChildAtIndex);\n } else {\n parent.appendChild(newEl);\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 parent.removeChild(vNode.el);\n }\n });\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h\").VNode} vNode - The component vNode.\n * @returns {import(\"./h\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\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\").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\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h\").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 // --- HANDLE UNMOUNTING (Cleanup Hooks) ---\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) parent.removeChild(el);\n return;\n }\n\n // --- HANDLE COMPONENT (Functional VNode) ---\n if (typeof newVNode.tag === \"function\") {\n const isNew = !oldVNode;\n\n // 1. Render the component function\n const childVNode = renderComponent(newVNode);\n\n // 2. Store the result in the vNode (\"unwrap\" it)\n newVNode.child = childVNode;\n\n // 3. Recursively patch the result\n const oldChild = oldVNode ? oldVNode.child : undefined;\n patch(parent, childVNode, oldChild, index);\n\n // 4. Ensure VNode holds the DOM reference\n newVNode.el = childVNode.el;\n\n // 5. Run Mount Hooks (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 // Start - No old node? Create new.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode));\n return;\n }\n\n // Removal - No new node? Remove old.\n if (newVNode === undefined || newVNode === null) {\n // Try to find the element on the VNode, or fallback to index\n const el = oldVNode.el || parent.childNodes[index];\n if (el) parent.removeChild(el);\n return;\n }\n\n // Changed Type - (e.g. <div> becomes <span>) -> Replace whole node\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) parent.replaceChild(createElement(newVNode), el);\n return;\n }\n\n // Text Update\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 } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)));\n }\n }\n return;\n }\n\n // Same Tag - Update Props & 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"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","get","set","updater","nextState","clone","render","styleSheet","cache","hashString","str","hash","i","minify","css","strings","args","raw","acc","content","className","h","tag","props","children","cleanChildren","c","onMount","fn","instance","onCleanup","hasKeys","createElement","vNode","childVNode","renderComponent","el","patchProps","child","newProps","oldProps","allProps","key","oldValue","newValue","eventName","reconcileChildren","parent","newChildren","oldChildren","maxLen","patch","keyed","newChild","oldItem","oldVNode","domChildAtIndex","newEl","hooks","renderedVNode","runUnmount","newVNode","index","isNew","oldChild","mount","target","Component","prevVNode","lifecycle","nextVNode"],"mappings":"AAKA,IAAIA,IAAkB,MAClBC,IAAkB;AAMf,MAAMC,IAAc,MAAMF,GAMpBG,IAAc,CAACC,MAAQ;AAClC,EAAAJ,IAAkBI;AACpB,GAMaC,IAAc,MAAMJ,GAMpBK,IAAc,CAACC,MAAS;AACnC,EAAAN,IAAkBM;AACpB;ACjBO,MAAMC,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlB,YAAY,EAAE,QAAAC,GAAQ,UAAAC,KAAY;AAChC,SAAK,UAAUD,GACf,KAAK,aAAa,oBAAI,IAAG;AAEzB,UAAME,IAAM,MAAM,KAAK,SAEjBC,IAAM,CAACC,MAAY;AACvB,UAAIC;AACJ,UAAI,OAA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AIW,EAAO,aAAaf,EAAc6B,CAAQ,GAAGzB,CAAE;AACvD;AAAA,EACF;AAGA,MAAI,OAAOyB,KAAa,YAAY,OAAOA,KAAa,UAAU;AAChE,QAAIA,MAAaN,GAAU;AACzB,YAAMnB,IAAKW,EAAO,WAAWe,CAAK;AAClC,MAAI1B,IACFA,EAAG,YAAY,OAAOyB,CAAQ,IAG9Bd,EAAO,YAAY,SAAS,eAAe,OAAOc,CAAQ,CAAC,CAAC;AAAA,IAEhE;AACA;AAAA,EACF;AAGA,QAAMzB,IAAKmB,EAAS,MAAMR,EAAO,WAAWe,CAAK;AAEjD,EAAK1B,MAGLyB,EAAS,KAAKzB,GAEdC,EAAWD,GAAIyB,EAAS,OAAON,EAAS,KAAK,GAE7CT,EAAkBV,GAAIyB,EAAS,UAAUN,EAAS,QAAQ;AAC5D;ACrTY,MAACU,IAAQ,CAACC,GAAQC,MAAc;AAC1C,MAAIC,IAAY;AAEhB,QAAMC,IAAY,MAAM;AACtB,IAAA5E,EAAY4E,CAAS;AAErB,UAAMC,IAAY;AAAA,MAChB,KAAKH;AAAA,MACL,OAAO,CAAA;AAAA,MACP,UAAU,CAAA;AAAA,IAChB;AAEI,IAAAhB,EAAMe,GAAQI,GAAWF,CAAS,GAClC3E,EAAY,IAAI,GAChB2E,IAAYE;AAAA,EACd;AAEA,EAAAD,EAAS;AACX;"}
@@ -0,0 +1,5 @@
1
+ (function(u,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u.Humn={}))})(this,(function(u){"use strict";let f=null,k=null;const I=()=>f,d=t=>{f=t},E=()=>k,b=t=>{k=t};class O{constructor({memory:e,synapses:s}){this._memory=e,this._listeners=new Set;const r=()=>this._memory,c=n=>{let i;if(typeof n=="function"){const o=structuredClone(this._memory);i=n(o)||o}else i={...this._memory,...n};this._memory=i,this._listeners.forEach(o=>o())};this.synapses=s(c,r)}get memory(){const e=I();return e&&this._listeners.add(e),this._memory}}let a=null;const C=new Set;function x(t){let e=5381,s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return(e>>>0).toString(36)}function L(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim()}function M(t,...e){const s=t.reduce((i,o,l)=>i+o+(e[l]||""),""),r=L(s);if(!r)return"";const c=x(r),n=`humn-${c}`;return C.has(c)||(a||(a=document.createElement("style"),a.id="humn-styles",document.head.appendChild(a)),a.textContent+=`.${n} {
2
+ ${r}
3
+ }
4
+ `,C.add(c)),n}const j=(t,e={},s=[])=>{const c=(Array.isArray(s)?s:[s]).flat().filter(n=>n!=null&&n!==!1&&n!=="");return{tag:t,props:e,children:c}};function K(t){const e=E();e&&e.mounts.push(t)}function $(t){const e=E();e&&e.cleanups.push(t)}function S(t){return t&&t.some(e=>e&&e.props&&e.props.key!=null)}function m(t){if(typeof t=="string"||typeof t=="number")return document.createTextNode(String(t));if(typeof t.tag=="function"){const s=_(t);t.child=s;const r=m(s);return t.el=r,t.hooks&&t.hooks.mounts.length>0&&setTimeout(()=>t.hooks.mounts.forEach(c=>c()),0),r}const e=document.createElement(t.tag);return t.el=e,A(e,t.props),t.children.forEach(s=>{e.appendChild(m(s))}),e}function A(t,e={},s={}){if(!t)return;const r={...s,...e};for(const c in r){const n=s[c],i=e[c];if(i==null){t.removeAttribute(c);continue}if(c==="value"||c==="checked"){t[c]!==i&&(t[c]=i);continue}if(n!==i){if(c.startsWith("on")){const o=c.slice(2).toLowerCase();n&&t.removeEventListener(o,n),t.addEventListener(o,i)}c==="disabled"?t.disabled=i===!0||i==="true":t.setAttribute(c,i)}}}function B(t,e,s){if(!(S(e)||S(s))){const n=Math.max(e.length,s.length);for(let i=0;i<n;i++)y(t,e[i],s[i],i);return}const c={};s.forEach((n,i)=>{const o=(n.props&&n.props.key)!=null?n.props.key:i;c[o]={vNode:n,index:i}}),e.forEach((n,i)=>{const o=(n.props&&n.props.key)!=null?n.props.key:i,l=c[o];if(l){const p=l.vNode;y(t,n,p,i);const h=n.el||p.el,T=t.childNodes[i];h&&T!==h&&t.insertBefore(h,T),delete c[o]}else{const p=m(n),h=t.childNodes[i];h?t.insertBefore(p,h):t.appendChild(p)}}),Object.values(c).forEach(({vNode:n})=>{n.el&&n.el.parentNode===t&&t.removeChild(n.el)})}function _(t){const e={mounts:[],cleanups:[]};b(e);const s=t.tag(t.props);return b(null),t.hooks=e,s}function g(t){t&&(t.hooks&&t.hooks.cleanups&&t.hooks.cleanups.forEach(e=>e()),t.child&&g(t.child),t.children&&t.children.forEach(g))}function y(t,e,s,r=0){if(e==null){const n=s.el||t.childNodes[r];g(s),n&&t.removeChild(n);return}if(typeof e.tag=="function"){const n=!s,i=_(e);e.child=i;const o=s?s.child:void 0;y(t,i,o,r),e.el=i.el,n&&e.hooks&&e.hooks.mounts.length>0&&setTimeout(()=>{e.hooks.mounts.forEach(l=>l())},0);return}if(s==null){t.appendChild(m(e));return}if(e==null){const n=s.el||t.childNodes[r];n&&t.removeChild(n);return}if(typeof e!=typeof s||typeof e!="string"&&e.tag!==s.tag){const n=s.el||t.childNodes[r];n&&t.replaceChild(m(e),n);return}if(typeof e=="string"||typeof e=="number"){if(e!==s){const n=t.childNodes[r];n?n.nodeValue=String(e):t.appendChild(document.createTextNode(String(e)))}return}const c=s.el||t.childNodes[r];c&&(e.el=c,A(c,e.props,s.props),B(c,e.children,s.children))}const H=(t,e)=>{let s=null;const r=()=>{d(r);const c={tag:e,props:{},children:[]};y(t,c,s),d(null),s=c};r()};u.Cortex=O,u.css=M,u.h=j,u.mount=H,u.onCleanup=$,u.onMount=K,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
5
+ //# sourceMappingURL=humn.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"humn.umd.js","sources":["../src/observer.js","../src/cortex.js","../src/css.js","../src/h.js","../src/lifecycle.js","../src/patch.js","../src/mount.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 { 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 */\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 this._memory = memory;\n this._listeners = new Set();\n\n const get = () => this._memory;\n\n const set = (updater) => {\n let nextState;\n if (typeof updater === \"function\") {\n const clone = structuredClone(this._memory);\n const result = updater(clone);\n nextState = result || clone;\n } else {\n nextState = { ...this._memory, ...updater };\n }\n\n this._memory = nextState;\n this._listeners.forEach((render) => render());\n };\n\n this.synapses = synapses(set, get);\n }\n\n /**\n * Get the memory and register the current observer.\n * @returns {object} The current state\n */\n get memory() {\n const currentObserver = getObserver();\n if (currentObserver) this._listeners.add(currentObserver);\n return this._memory;\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 */\nexport function css(strings, ...args) {\n const raw = strings.reduce((acc, str, i) => {\n return acc + str + (args[i] || \"\");\n }, \"\");\n\n const content = minify(raw);\n\n if (!content) return \"\";\n\n const hash = hashString(content);\n const className = `humn-${hash}`;\n\n if (cache.has(hash)) {\n return className;\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 += `.${className} { \n ${content} \n }\\n`;\n cache.add(hash);\n\n return className;\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 { setInstance } from \"./observer.js\";\n\n/**\n * Checks if a list of children contains keys.\n * @param {Array<import(\"./h\").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\n/**\n * Creates a real DOM element from a virtual node.\n * @param {import(\"./h\").VNode | string | number} vNode - The virtual node.\n * @returns {Text | HTMLElement} The created DOM element.\n */\nfunction createElement(vNode) {\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 // Recursively create the DOM for the child\n const el = createElement(childVNode);\n vNode.el = el;\n\n // Queue Mount Hooks\n if (vNode.hooks && vNode.hooks.mounts.length > 0) {\n setTimeout(() => vNode.hooks.mounts.forEach((fn) => fn()), 0);\n }\n return el;\n }\n\n const el = document.createElement(vNode.tag);\n vNode.el = el;\n patchProps(el, vNode.props);\n\n vNode.children.forEach((child) => {\n el.appendChild(createElement(child));\n });\n\n return el;\n}\n\n/**\n * Updates the properties (attributes/events) of a DOM element.\n * @param {HTMLElement} el - The DOM element to update.\n * @param {object} [newProps={}] - The new properties.\n * @param {object} [oldProps={}] - The old properties.\n */\nfunction patchProps(el, newProps = {}, oldProps = {}) {\n if (!el) 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 el.removeAttribute(key);\n continue;\n }\n\n // We check against the LIVE DOM value to prevent cursor jumping\n if (key === \"value\" || key === \"checked\") {\n if (el[key] !== newValue) {\n el[key] = newValue;\n }\n continue;\n }\n\n // If prop hasn't changed, skip\n if (oldValue === newValue) continue;\n\n // Handle Events\n if (key.startsWith(\"on\")) {\n const eventName = key.slice(2).toLowerCase();\n if (oldValue) el.removeEventListener(eventName, oldValue);\n el.addEventListener(eventName, newValue);\n }\n // Handle the disabled attribute\n if (key === \"disabled\") {\n el.disabled = newValue === true || newValue === \"true\";\n }\n // Handle standard attributes\n else {\n el.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\").VNode>} newChildren - The new list of children.\n * @param {Array<import(\"./h\").VNode>} oldChildren - The old list of children.\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 // Keyed Diffing\n // Map existing children by Key\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 oldItem = keyed[key];\n\n if (oldItem) {\n // A. MATCH FOUND\n const oldVNode = oldItem.vNode;\n\n // Update the node's content (Recursion)\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 el = 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 (el && domChildAtIndex !== el) {\n parent.insertBefore(el, domChildAtIndex);\n }\n\n // Remove from map so we know it was re-used\n delete keyed[key];\n } else {\n // B. NO MATCH (New Item)\n const newEl = createElement(newChild);\n const domChildAtIndex = parent.childNodes[i];\n\n if (domChildAtIndex) {\n parent.insertBefore(newEl, domChildAtIndex);\n } else {\n parent.appendChild(newEl);\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 parent.removeChild(vNode.el);\n }\n });\n}\n\n/**\n * Executes a Functional Component, tracks hooks, and returns the VNode.\n * @param {import(\"./h\").VNode} vNode - The component vNode.\n * @returns {import(\"./h\").VNode} The rendered child vNode.\n */\nfunction renderComponent(vNode) {\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\").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\").VNode | string | number} newVNode - The new virtual node.\n * @param {import(\"./h\").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 // --- HANDLE UNMOUNTING (Cleanup Hooks) ---\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) parent.removeChild(el);\n return;\n }\n\n // --- HANDLE COMPONENT (Functional VNode) ---\n if (typeof newVNode.tag === \"function\") {\n const isNew = !oldVNode;\n\n // 1. Render the component function\n const childVNode = renderComponent(newVNode);\n\n // 2. Store the result in the vNode (\"unwrap\" it)\n newVNode.child = childVNode;\n\n // 3. Recursively patch the result\n const oldChild = oldVNode ? oldVNode.child : undefined;\n patch(parent, childVNode, oldChild, index);\n\n // 4. Ensure VNode holds the DOM reference\n newVNode.el = childVNode.el;\n\n // 5. Run Mount Hooks (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 // Start - No old node? Create new.\n if (oldVNode === undefined || oldVNode === null) {\n parent.appendChild(createElement(newVNode));\n return;\n }\n\n // Removal - No new node? Remove old.\n if (newVNode === undefined || newVNode === null) {\n // Try to find the element on the VNode, or fallback to index\n const el = oldVNode.el || parent.childNodes[index];\n if (el) parent.removeChild(el);\n return;\n }\n\n // Changed Type - (e.g. <div> becomes <span>) -> Replace whole node\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) parent.replaceChild(createElement(newVNode), el);\n return;\n }\n\n // Text Update\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 } else {\n // Self healing: if text node missing, append it\n parent.appendChild(document.createTextNode(String(newVNode)));\n }\n }\n return;\n }\n\n // Same Tag - Update Props & 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"],"names":["currentObserver","currentInstance","getObserver","setObserver","obs","getInstance","setInstance","inst","Cortex","memory","synapses","get","set","updater","nextState","clone","render","styleSheet","cache","hashString","str","hash","i","minify","css","strings","args","raw","acc","content","className","h","tag","props","children","cleanChildren","c","onMount","fn","instance","onCleanup","hasKeys","createElement","vNode","childVNode","renderComponent","el","patchProps","child","newProps","oldProps","allProps","key","oldValue","newValue","eventName","reconcileChildren","parent","newChildren","oldChildren","maxLen","patch","keyed","newChild","oldItem","oldVNode","domChildAtIndex","newEl","hooks","renderedVNode","runUnmount","newVNode","index","isNew","oldChild","mount","target","Component","prevVNode","lifecycle","nextVNode"],"mappings":"6NAKA,IAAIA,EAAkB,KAClBC,EAAkB,KAMf,MAAMC,EAAc,IAAMF,EAMpBG,EAAeC,GAAQ,CAClCJ,EAAkBI,CACpB,EAMaC,EAAc,IAAMJ,EAMpBK,EAAeC,GAAS,CACnCN,EAAkBM,CACpB,ECjBO,MAAMC,CAAO,CAKlB,YAAY,CAAE,OAAAC,EAAQ,SAAAC,GAAY,CAChC,KAAK,QAAUD,EACf,KAAK,WAAa,IAAI,IAEtB,MAAME,EAAM,IAAM,KAAK,QAEjBC,EAAOC,GAAY,CACvB,IAAIC,EACJ,GAAI,OAAOD,GAAY,WAAY,CACjC,MAAME,EAAQ,gBAAgB,KAAK,OAAO,EAE1CD,EADeD,EAAQE,CAAK,GACNA,CACxB,M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Y,IAAM,CACtB5E,EAAY4E,CAAS,EAErB,MAAMC,EAAY,CAChB,IAAKH,EACL,MAAO,CAAA,EACP,SAAU,CAAA,CAChB,EAEIhB,EAAMe,EAAQI,EAAWF,CAAS,EAClC3E,EAAY,IAAI,EAChB2E,EAAYE,CACd,EAEAD,EAAS,CACX"}
@@ -0,0 +1,80 @@
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
5
+ */
6
+ /**
7
+ * @typedef {object} CortexParams@typedef {object} CortexParams
8
+ * @property {object} memory - The initial state
9
+ * @property {function(function, function): object} synapses - The synapses function
10
+ */
11
+ /**
12
+ * The Cortex class manages the state of the application.
13
+ */
14
+ export declare class Cortex {
15
+ /**
16
+ * Creates an instance of Cortex.
17
+ * @param {CortexParams} CortexParams - The parameters for the Cortex.
18
+ */
19
+ constructor({ memory, synapses }: CortexParams);
20
+ _memory: any;
21
+ _listeners: Set<any>;
22
+ synapses: any;
23
+ /**
24
+ * Get the memory and register the current observer.
25
+ * @returns {object} The current state
26
+ */
27
+ get memory(): object;
28
+ }
29
+
30
+ export declare type CortexParams = {
31
+ /**
32
+ * - The initial state
33
+ */
34
+ memory: object;
35
+ /**
36
+ * - The synapses function
37
+ */
38
+ synapses: (arg0: Function, arg1: Function) => object;
39
+ };
40
+
41
+ /**
42
+ * Scoped CSS Tag.
43
+ * Wraps content in a unique class using Native CSS Nesting.
44
+ */
45
+ export declare function css(strings: any, ...args: any[]): string;
46
+
47
+ export declare function h(tag: string, props?: object, children?: VNode[] | VNode): VNode;
48
+
49
+ export declare function mount(target: HTMLElement, Component: Function): void;
50
+
51
+ /**
52
+ * Registers a callback to run when the component unmounts.
53
+ * @param {function} fn - The callback function.
54
+ */
55
+ export declare function onCleanup(fn: Function): void;
56
+
57
+ /**
58
+ * Registers a callback to run after the component mounts.
59
+ * @param {function} fn - The callback function.
60
+ */
61
+ export declare function onMount(fn: Function): void;
62
+
63
+ export declare type Synapses = {
64
+ /**
65
+ * - Function to update the memory
66
+ */
67
+ set: Function;
68
+ /**
69
+ * - Function to get the memory
70
+ */
71
+ get: Function;
72
+ };
73
+
74
+ export declare type VNode = {
75
+ tag: string;
76
+ props: object;
77
+ children: VNode[];
78
+ };
79
+
80
+ export { }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "humn",
3
+ "version": "0.0.2",
4
+ "description": "A minimal, human-centric reactive UI library with built in state management.",
5
+ "type": "module",
6
+ "main": "./dist/humn.umd.js",
7
+ "module": "./dist/humn.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/humn.js",
13
+ "require": "./dist/humn.umd.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "build": "vite build",
23
+ "test": "vitest",
24
+ "dev": "vite --port 3000 --open /playground/",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "reactive",
29
+ "ui",
30
+ "state",
31
+ "store",
32
+ "cortex"
33
+ ],
34
+ "author": "Keeghan McGarry",
35
+ "license": "MIT",
36
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
37
+ "devDependencies": {
38
+ "@types/node": "^24.10.1",
39
+ "typescript": "^5.9.3",
40
+ "vite": "^7.2.6",
41
+ "vite-plugin-dts": "^4.5.4"
42
+ }
43
+ }