@akashjs/runtime 0.1.9 → 0.1.11

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.
Files changed (57) hide show
  1. package/dist/chunk-5PZHDZ6H.cjs +2 -0
  2. package/dist/chunk-5PZHDZ6H.cjs.map +1 -0
  3. package/dist/chunk-ABRPXTHE.js +2 -0
  4. package/dist/chunk-ABRPXTHE.js.map +1 -0
  5. package/dist/{chunk-IH54XQBC.cjs → chunk-AS2LLR6T.cjs} +2 -2
  6. package/dist/{chunk-IH54XQBC.cjs.map → chunk-AS2LLR6T.cjs.map} +1 -1
  7. package/dist/{chunk-ONEN7EMK.cjs → chunk-BXTEZJDO.cjs} +2 -2
  8. package/dist/{chunk-ONEN7EMK.cjs.map → chunk-BXTEZJDO.cjs.map} +1 -1
  9. package/dist/chunk-F2MANNOP.js +2 -0
  10. package/dist/chunk-F2MANNOP.js.map +1 -0
  11. package/dist/{chunk-PGZQFMX2.cjs → chunk-F57HJQAZ.cjs} +3 -3
  12. package/dist/{chunk-PGZQFMX2.cjs.map → chunk-F57HJQAZ.cjs.map} +1 -1
  13. package/dist/{chunk-TXBFQLNL.js → chunk-K7ZSZXEF.js} +3 -3
  14. package/dist/{chunk-TXBFQLNL.js.map → chunk-K7ZSZXEF.js.map} +1 -1
  15. package/dist/{chunk-IXRAKXD7.js → chunk-LAWZZ7JW.js} +2 -2
  16. package/dist/{chunk-IXRAKXD7.js.map → chunk-LAWZZ7JW.js.map} +1 -1
  17. package/dist/{chunk-FB3CM2UH.cjs → chunk-NG3F5KZG.cjs} +2 -2
  18. package/dist/{chunk-FB3CM2UH.cjs.map → chunk-NG3F5KZG.cjs.map} +1 -1
  19. package/dist/{chunk-SLMGQKLH.js → chunk-PQKI432Q.js} +3 -3
  20. package/dist/chunk-PQKI432Q.js.map +1 -0
  21. package/dist/{chunk-6G3EALVL.js → chunk-S37V44GX.js} +2 -2
  22. package/dist/{chunk-6G3EALVL.js.map → chunk-S37V44GX.js.map} +1 -1
  23. package/dist/{chunk-RVHMMGJG.cjs → chunk-SZ3HD5NP.cjs} +3 -3
  24. package/dist/chunk-SZ3HD5NP.cjs.map +1 -0
  25. package/dist/chunk-U6G4NYUT.cjs +2 -0
  26. package/dist/chunk-U6G4NYUT.cjs.map +1 -0
  27. package/dist/{chunk-UID3D5XB.js → chunk-VXWWYPWW.js} +2 -2
  28. package/dist/{chunk-UID3D5XB.js.map → chunk-VXWWYPWW.js.map} +1 -1
  29. package/dist/core.cjs +1 -1
  30. package/dist/core.js +1 -1
  31. package/dist/index.cjs +6 -6
  32. package/dist/index.js +1 -1
  33. package/dist/machine.cjs +1 -1
  34. package/dist/machine.js +1 -1
  35. package/dist/offline.cjs +1 -1
  36. package/dist/offline.js +1 -1
  37. package/dist/pwa.cjs +1 -1
  38. package/dist/pwa.js +1 -1
  39. package/dist/ssr.cjs +1 -1
  40. package/dist/ssr.js +1 -1
  41. package/dist/store.cjs +1 -1
  42. package/dist/store.js +1 -1
  43. package/dist/sync.cjs +1 -1
  44. package/dist/sync.js +1 -1
  45. package/dist/test.cjs +1 -1
  46. package/dist/test.js +1 -1
  47. package/package.json +1 -1
  48. package/dist/chunk-3Q7GK4DL.cjs +0 -2
  49. package/dist/chunk-3Q7GK4DL.cjs.map +0 -1
  50. package/dist/chunk-7R4T4V3T.cjs +0 -2
  51. package/dist/chunk-7R4T4V3T.cjs.map +0 -1
  52. package/dist/chunk-FX7RHVM5.js +0 -2
  53. package/dist/chunk-FX7RHVM5.js.map +0 -1
  54. package/dist/chunk-JKO64Z6H.js +0 -2
  55. package/dist/chunk-JKO64Z6H.js.map +0 -1
  56. package/dist/chunk-RVHMMGJG.cjs.map +0 -1
  57. package/dist/chunk-SLMGQKLH.js.map +0 -1
package/dist/store.js CHANGED
@@ -1,2 +1,2 @@
1
- export{b as clearStores,a as defineStore}from'./chunk-JKO64Z6H.js';import'./chunk-FX7RHVM5.js';//# sourceMappingURL=store.js.map
1
+ export{b as clearStores,a as defineStore}from'./chunk-ABRPXTHE.js';import'./chunk-F2MANNOP.js';//# sourceMappingURL=store.js.map
2
2
  //# sourceMappingURL=store.js.map
package/dist/sync.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkONEN7EMK_cjs=require('./chunk-ONEN7EMK.cjs');require('./chunk-3Q7GK4DL.cjs');Object.defineProperty(exports,"LWWRegister",{enumerable:true,get:function(){return chunkONEN7EMK_cjs.a}});Object.defineProperty(exports,"createLocalTransport",{enumerable:true,get:function(){return chunkONEN7EMK_cjs.c}});Object.defineProperty(exports,"createSync",{enumerable:true,get:function(){return chunkONEN7EMK_cjs.d}});Object.defineProperty(exports,"createWebSocketTransport",{enumerable:true,get:function(){return chunkONEN7EMK_cjs.b}});//# sourceMappingURL=sync.cjs.map
1
+ 'use strict';var chunkBXTEZJDO_cjs=require('./chunk-BXTEZJDO.cjs');require('./chunk-5PZHDZ6H.cjs');Object.defineProperty(exports,"LWWRegister",{enumerable:true,get:function(){return chunkBXTEZJDO_cjs.a}});Object.defineProperty(exports,"createLocalTransport",{enumerable:true,get:function(){return chunkBXTEZJDO_cjs.c}});Object.defineProperty(exports,"createSync",{enumerable:true,get:function(){return chunkBXTEZJDO_cjs.d}});Object.defineProperty(exports,"createWebSocketTransport",{enumerable:true,get:function(){return chunkBXTEZJDO_cjs.b}});//# sourceMappingURL=sync.cjs.map
2
2
  //# sourceMappingURL=sync.cjs.map
package/dist/sync.js CHANGED
@@ -1,2 +1,2 @@
1
- export{a as LWWRegister,c as createLocalTransport,d as createSync,b as createWebSocketTransport}from'./chunk-UID3D5XB.js';import'./chunk-FX7RHVM5.js';//# sourceMappingURL=sync.js.map
1
+ export{a as LWWRegister,c as createLocalTransport,d as createSync,b as createWebSocketTransport}from'./chunk-VXWWYPWW.js';import'./chunk-F2MANNOP.js';//# sourceMappingURL=sync.js.map
2
2
  //# sourceMappingURL=sync.js.map
package/dist/test.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var chunkRVHMMGJG_cjs=require('./chunk-RVHMMGJG.cjs');require('./chunk-3Q7GK4DL.cjs');function M(e,n){let t=document.createElement("div");t.setAttribute("data-akash-test-root","");let l=n?.props??{},o=n?.provide,a;return o&&o.size>0?a=chunkRVHMMGJG_cjs.B(()=>{for(let[i,d]of o)chunkRVHMMGJG_cjs.h(i,d);return ()=>e(l)})({}):a=e(l),t.appendChild(a),document.body.appendChild(t),{container:t,unmount(){t.remove();},getByText(r){let i=m(t,r);if(!i)throw new Error(`[AkashJS Test] Could not find element with text: "${r}"
1
+ 'use strict';var chunkSZ3HD5NP_cjs=require('./chunk-SZ3HD5NP.cjs');require('./chunk-5PZHDZ6H.cjs');function M(e,n){let t=document.createElement("div");t.setAttribute("data-akash-test-root","");let l=n?.props??{},o=n?.provide,a;return o&&o.size>0?a=chunkSZ3HD5NP_cjs.B(()=>{for(let[i,d]of o)chunkSZ3HD5NP_cjs.h(i,d);return ()=>e(l)})({}):a=e(l),t.appendChild(a),document.body.appendChild(t),{container:t,unmount(){t.remove();},getByText(r){let i=m(t,r);if(!i)throw new Error(`[AkashJS Test] Could not find element with text: "${r}"
2
2
  Container HTML: ${t.innerHTML.slice(0,200)}`);return i},getByRole(r){let i=t.querySelector(`[role="${r}"]`)??p(t,r);if(!i)throw new Error(`[AkashJS Test] Could not find element with role: "${r}"
3
3
  Container HTML: ${t.innerHTML.slice(0,200)}`);return i},getByTestId(r){let i=t.querySelector(`[data-testid="${r}"]`);if(!i)throw new Error(`[AkashJS Test] Could not find element with data-testid: "${r}"
4
4
  Container HTML: ${t.innerHTML.slice(0,200)}`);return i},queryAll(r){return Array.from(t.querySelectorAll(r))},query(r){return t.querySelector(r)}}}var y={async click(e){e.dispatchEvent(new MouseEvent("click",{bubbles:true,cancelable:true})),await s();},async input(e,n){let t=Object.getOwnPropertyDescriptor(e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLInputElement.prototype,"value")?.set;t?t.call(e,n):e.value=n,e.dispatchEvent(new Event("input",{bubbles:true})),e.dispatchEvent(new Event("change",{bubbles:true})),await s();},async submit(e){e.dispatchEvent(new Event("submit",{bubbles:true,cancelable:true})),await s();},async focus(e){e.focus(),e.dispatchEvent(new FocusEvent("focus",{bubbles:true})),await s();},async blur(e){e.blur(),e.dispatchEvent(new FocusEvent("blur",{bubbles:true})),await s();},async keyDown(e,n,t){e.dispatchEvent(new KeyboardEvent("keydown",{key:n,bubbles:true,...t})),await s();},async keyUp(e,n,t){e.dispatchEvent(new KeyboardEvent("keyup",{key:n,bubbles:true,...t})),await s();}};function s(){return new Promise(e=>queueMicrotask(e))}function m(e,n){let t=null,l=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),o=l.nextNode();for(;o;)o instanceof HTMLElement&&o.textContent?.includes(n)&&(t=o),o=l.nextNode();return !t&&e.textContent?.includes(n)&&(t=e),t}var E={button:["button"],a:["link"],input:["textbox","checkbox","radio","spinbutton","slider"],select:["combobox","listbox"],textarea:["textbox"],img:["img"],form:["form"],nav:["navigation"],main:["main"],header:["banner"],footer:["contentinfo"],aside:["complementary"],section:["region"],article:["article"],ul:["list"],ol:["list"],li:["listitem"],table:["table"],th:["columnheader"],td:["cell"],h1:["heading"],h2:["heading"],h3:["heading"],h4:["heading"],h5:["heading"],h6:["heading"]};function p(e,n){let t=[];for(let[o,a]of Object.entries(E))a.includes(n)&&t.push(o);if(t.length===0)return null;let l=t.join(", ");return e.querySelector(l)}exports.fireEvent=y;exports.mount=M;//# sourceMappingURL=test.cjs.map
package/dist/test.js CHANGED
@@ -1,4 +1,4 @@
1
- import {B,h}from'./chunk-SLMGQKLH.js';import'./chunk-FX7RHVM5.js';function M(e,n){let t=document.createElement("div");t.setAttribute("data-akash-test-root","");let l=n?.props??{},o=n?.provide,a;return o&&o.size>0?a=B(()=>{for(let[i,d]of o)h(i,d);return ()=>e(l)})({}):a=e(l),t.appendChild(a),document.body.appendChild(t),{container:t,unmount(){t.remove();},getByText(r){let i=m(t,r);if(!i)throw new Error(`[AkashJS Test] Could not find element with text: "${r}"
1
+ import {B,h}from'./chunk-PQKI432Q.js';import'./chunk-F2MANNOP.js';function M(e,n){let t=document.createElement("div");t.setAttribute("data-akash-test-root","");let l=n?.props??{},o=n?.provide,a;return o&&o.size>0?a=B(()=>{for(let[i,d]of o)h(i,d);return ()=>e(l)})({}):a=e(l),t.appendChild(a),document.body.appendChild(t),{container:t,unmount(){t.remove();},getByText(r){let i=m(t,r);if(!i)throw new Error(`[AkashJS Test] Could not find element with text: "${r}"
2
2
  Container HTML: ${t.innerHTML.slice(0,200)}`);return i},getByRole(r){let i=t.querySelector(`[role="${r}"]`)??p(t,r);if(!i)throw new Error(`[AkashJS Test] Could not find element with role: "${r}"
3
3
  Container HTML: ${t.innerHTML.slice(0,200)}`);return i},getByTestId(r){let i=t.querySelector(`[data-testid="${r}"]`);if(!i)throw new Error(`[AkashJS Test] Could not find element with data-testid: "${r}"
4
4
  Container HTML: ${t.innerHTML.slice(0,200)}`);return i},queryAll(r){return Array.from(t.querySelectorAll(r))},query(r){return t.querySelector(r)}}}var y={async click(e){e.dispatchEvent(new MouseEvent("click",{bubbles:true,cancelable:true})),await s();},async input(e,n){let t=Object.getOwnPropertyDescriptor(e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLInputElement.prototype,"value")?.set;t?t.call(e,n):e.value=n,e.dispatchEvent(new Event("input",{bubbles:true})),e.dispatchEvent(new Event("change",{bubbles:true})),await s();},async submit(e){e.dispatchEvent(new Event("submit",{bubbles:true,cancelable:true})),await s();},async focus(e){e.focus(),e.dispatchEvent(new FocusEvent("focus",{bubbles:true})),await s();},async blur(e){e.blur(),e.dispatchEvent(new FocusEvent("blur",{bubbles:true})),await s();},async keyDown(e,n,t){e.dispatchEvent(new KeyboardEvent("keydown",{key:n,bubbles:true,...t})),await s();},async keyUp(e,n,t){e.dispatchEvent(new KeyboardEvent("keyup",{key:n,bubbles:true,...t})),await s();}};function s(){return new Promise(e=>queueMicrotask(e))}function m(e,n){let t=null,l=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),o=l.nextNode();for(;o;)o instanceof HTMLElement&&o.textContent?.includes(n)&&(t=o),o=l.nextNode();return !t&&e.textContent?.includes(n)&&(t=e),t}var E={button:["button"],a:["link"],input:["textbox","checkbox","radio","spinbutton","slider"],select:["combobox","listbox"],textarea:["textbox"],img:["img"],form:["form"],nav:["navigation"],main:["main"],header:["banner"],footer:["contentinfo"],aside:["complementary"],section:["region"],article:["article"],ul:["list"],ol:["list"],li:["listitem"],table:["table"],th:["columnheader"],td:["cell"],h1:["heading"],h2:["heading"],h3:["heading"],h4:["heading"],h5:["heading"],h6:["heading"]};function p(e,n){let t=[];for(let[o,a]of Object.entries(E))a.includes(n)&&t.push(o);if(t.length===0)return null;let l=t.join(", ");return e.querySelector(l)}export{y as fireEvent,M as mount};//# sourceMappingURL=test.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akashjs/runtime",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "AkashJS core runtime — signals, components, DOM rendering",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -1,2 +0,0 @@
1
- 'use strict';var r=new Set,c=new Set,i=false,f=0,a=false,b=1e3;function l(){if(i)return;i=true,a=false;let e=0;for(;(r.size>0||c.size>0)&&e<b;){if(e++,r.size>0){let u=[...r].sort(p);r.clear();for(let t of u)t.run();}if(c.size>0){let u=[...c].sort(p);c.clear();for(let t of u)t.run();}}e>=b&&console.error("[AkashJS] Effect flush limit reached. Possible circular dependency."),i=false;}function S(e){e.isRender?r.add(e):c.add(e),f===0&&!i&&!a&&(a=true,queueMicrotask(l));}function y(e){f++;try{e();}finally{f--,f===0&&l();}}function p(e,u){return (e.depth??0)-(u.depth??0)}function m(){l();}var s=null;function w(e,u){let t={value:e,subscribers:new Set,equals:u?.equals??Object.is},n=()=>(g(t),t.value);return n.set=o=>{t.equals(t.value,o)||(t.value=o,d(t));},n.update=o=>{n.set(o(t.value));},n.peek=()=>t.value,n}function k(e,u){let t={_tag:"computed",fn:e,value:void 0,state:1,subscribers:new Set,sources:new Set,equals:u?.equals??Object.is};return ()=>(s&&(t.subscribers.add(s),"sources"in s&&s.sources.add(t)),t.state!==0&&T(t),t.value)}function T(e){for(let t of e.sources)t.subscribers.delete(e);e.sources.clear();let u=s;s=e;try{let t=e.fn(),n=e.value===void 0||!e.equals(e.value,t);e.value=t,e.state=0,n&&d(e);}finally{s=u;}}function q(e,u){let t={_tag:"effect",fn:e,cleanup:null,sources:new Set,disposed:false,isRender:u?.render??false,run(){v(t);}};return v(t),()=>{t.disposed=true,h(t);for(let n of t.sources)n.subscribers.delete(t);t.sources.clear();}}function v(e){if(e.disposed)return;if(e.sources.size>0){let t=false;for(let n of e.sources)if("_tag"in n&&n._tag==="computed"){if(n.state===1){let o=n.value;T(n),n.equals(o,n.value)||(t=true);}}else t=true;if(!t)return}h(e);for(let t of e.sources)t.subscribers.delete(e);e.sources.clear();let u=s;s=e;try{let t=e.fn();typeof t=="function"&&(e.cleanup=t);}finally{s=u;}}function h(e){e.cleanup&&(e.cleanup(),e.cleanup=null);}function C(e){let u=s;s=null;try{return e()}finally{s=u;}}function g(e){s&&(e.subscribers.add(s),"sources"in s&&s.sources.add(e));}function d(e){for(let u of e.subscribers)u._tag==="computed"?(u.state=1,d(u)):u._tag==="effect"&&S(u);}exports.a=y;exports.b=m;exports.c=w;exports.d=k;exports.e=q;exports.f=C;//# sourceMappingURL=chunk-3Q7GK4DL.cjs.map
2
- //# sourceMappingURL=chunk-3Q7GK4DL.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/scheduler.ts","../src/signals.ts"],"names":["pendingRender","pendingUser","flushing","batchDepth","flushScheduled","MAX_FLUSH_ITERATIONS","flush","iterations","queue","byDepth","fx","scheduleEffect","batch","fn","a","b","flushSync","currentSubscriber","signal","initialValue","options","node","read","trackSubscriber","value","notifySubscribers","computed","recompute","source","prevSubscriber","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CAAK,OAAA,CAAQ,KAAA,EAAM,CAEnB,IAAMQ,CAAAA,CAAiBZ,CAAAA,CACvBA,CAAAA,CAAoBI,CAAAA,CAEpB,GAAI,CACF,IAAMgB,CAAAA,CAAShB,CAAAA,CAAK,EAAA,EAAG,CACnB,OAAOgB,CAAAA,EAAW,UAAA,GACpBhB,CAAAA,CAAK,QAAUgB,CAAAA,EAEnB,CAAA,OAAE,CACApB,CAAAA,CAAoBY,EACtB,CACF,CAEA,SAASK,EAAcb,CAAAA,CAAwB,CACzCA,CAAAA,CAAK,OAAA,GACPA,CAAAA,CAAK,OAAA,EAAQ,CACbA,CAAAA,CAAK,OAAA,CAAU,IAAA,EAEnB,CAKO,SAASiB,CAAAA,CAAWzB,CAAAA,CAAgB,CACzC,IAAM0B,EAAOtB,CAAAA,CACbA,CAAAA,CAAoB,IAAA,CACpB,GAAI,CACF,OAAOJ,CAAAA,EACT,QAAE,CACAI,CAAAA,CAAoBsB,EACtB,CACF,CAIA,SAAShB,CAAAA,CACPF,CAAAA,CACM,CACFJ,CAAAA,GACFI,CAAAA,CAAK,WAAA,CAAY,GAAA,CAAIJ,CAAiB,CAAA,CAElC,SAAA,GAAaA,CAAAA,EACfA,EAAkB,OAAA,CAAQ,GAAA,CAAII,CAAI,CAAA,EAGxC,CAEA,SAASI,CAAAA,CACPJ,CAAAA,CACM,CACN,IAAA,IAAWmB,CAAAA,IAAOnB,CAAAA,CAAK,WAAA,CACjBmB,CAAAA,CAAI,IAAA,GAAS,UAAA,EAEfA,CAAAA,CAAI,MAAQ,CAAA,CAIZf,CAAAA,CAAkBe,CAAG,CAAA,EACZA,CAAAA,CAAI,IAAA,GAAS,QAAA,EACtB7B,CAAAA,CAAe6B,CAAG,EAGxB","file":"chunk-3Q7GK4DL.cjs","sourcesContent":["/**\n * Microtask-based effect scheduler with priority levels and deduplication.\n *\n * Render effects (DOM bindings) run before user effects to ensure\n * DOM is consistent before user-side effects execute.\n */\n\nexport interface ScheduledEffect {\n run(): void;\n isRender: boolean;\n /** Depth in the dependency graph (0 = root). Lower depth runs first. */\n depth?: number;\n}\n\nconst pendingRender = new Set<ScheduledEffect>();\nconst pendingUser = new Set<ScheduledEffect>();\nlet flushing = false;\nlet batchDepth = 0;\nlet flushScheduled = false;\n\nconst MAX_FLUSH_ITERATIONS = 1000;\n\nfunction flush(): void {\n if (flushing) return;\n flushing = true;\n flushScheduled = false;\n\n // Process render effects first, then user effects.\n // Effects may enqueue more effects during flush, so loop until empty.\n let iterations = 0;\n while ((pendingRender.size > 0 || pendingUser.size > 0) && iterations < MAX_FLUSH_ITERATIONS) {\n iterations++;\n\n // Drain render effects (sorted by depth — parents before children)\n if (pendingRender.size > 0) {\n const queue = [...pendingRender].sort(byDepth);\n pendingRender.clear();\n for (const fx of queue) {\n fx.run();\n }\n }\n\n // Drain user effects (sorted by depth)\n if (pendingUser.size > 0) {\n const queue = [...pendingUser].sort(byDepth);\n pendingUser.clear();\n for (const fx of queue) {\n fx.run();\n }\n }\n }\n\n if (iterations >= MAX_FLUSH_ITERATIONS) {\n console.error('[AkashJS] Effect flush limit reached. Possible circular dependency.');\n }\n\n flushing = false;\n}\n\nexport function scheduleEffect(fx: ScheduledEffect): void {\n if (fx.isRender) {\n pendingRender.add(fx);\n } else {\n pendingUser.add(fx);\n }\n\n if (batchDepth === 0 && !flushing && !flushScheduled) {\n flushScheduled = true;\n queueMicrotask(flush);\n }\n}\n\n/**\n * Batch multiple signal writes — subscribers are notified only once\n * at the end of the batch.\n */\nexport function batch(fn: () => void): void {\n batchDepth++;\n try {\n fn();\n } finally {\n batchDepth--;\n if (batchDepth === 0) {\n flush();\n }\n }\n}\n\n/** Sort effects by depth (lower depth first = parents before children) */\nfunction byDepth(a: ScheduledEffect, b: ScheduledEffect): number {\n return (a.depth ?? 0) - (b.depth ?? 0);\n}\n\n/** Synchronously flush all pending effects. Useful for testing. */\nexport function flushSync(): void {\n flush();\n}\n","/**\n * Fine-grained reactivity system.\n *\n * Inspired by SolidJS/Preact Signals. Provides signal(), computed(),\n * effect(), and untrack() primitives with automatic dependency tracking\n * and glitch-free diamond dependency resolution.\n */\n\nimport { scheduleEffect, type ScheduledEffect } from './scheduler.js';\n\n// --- Tracking scope ---\n\ntype Subscriber = EffectNode | ComputedNode<unknown>;\n\nlet currentSubscriber: Subscriber | null = null;\n\n// --- Signal ---\n\nexport interface Signal<T> {\n /** Read the current value (tracks dependency if inside a reactive scope) */\n (): T;\n /** Set a new value */\n set(value: T): void;\n /** Update the value using the previous value */\n update(fn: (prev: T) => T): void;\n /** Read without tracking (no dependency registered) */\n peek(): T;\n}\n\nexport type ReadonlySignal<T> = () => T;\n\ninterface SignalNode<T> {\n value: T;\n subscribers: Set<Subscriber>;\n equals: (a: T, b: T) => boolean;\n}\n\nexport function signal<T>(\n initialValue: T,\n options?: { equals?: (a: T, b: T) => boolean },\n): Signal<T> {\n const node: SignalNode<T> = {\n value: initialValue,\n subscribers: new Set(),\n equals: options?.equals ?? Object.is,\n };\n\n const read = (): T => {\n trackSubscriber(node);\n return node.value;\n };\n\n read.set = (value: T): void => {\n if (node.equals(node.value, value)) return;\n node.value = value;\n notifySubscribers(node);\n };\n\n read.update = (fn: (prev: T) => T): void => {\n read.set(fn(node.value));\n };\n\n read.peek = (): T => node.value;\n\n return read;\n}\n\n// --- Computed ---\n\nconst enum ComputedState {\n Clean = 0,\n Dirty = 1,\n}\n\ninterface ComputedNode<T> {\n _tag: 'computed';\n fn: () => T;\n value: T | undefined;\n state: ComputedState;\n subscribers: Set<Subscriber>;\n sources: Set<SignalNode<unknown> | ComputedNode<unknown>>;\n equals: (a: T, b: T) => boolean;\n}\n\nexport function computed<T>(\n fn: () => T,\n options?: { equals?: (a: T, b: T) => boolean },\n): ReadonlySignal<T> {\n const node: ComputedNode<T> = {\n _tag: 'computed',\n fn,\n value: undefined,\n state: ComputedState.Dirty,\n subscribers: new Set(),\n sources: new Set(),\n equals: options?.equals ?? Object.is,\n };\n\n const read = (): T => {\n // Track this computed as a dependency of the current subscriber\n if (currentSubscriber) {\n node.subscribers.add(currentSubscriber);\n if ('sources' in currentSubscriber) {\n currentSubscriber.sources.add(node);\n }\n }\n\n if (node.state !== ComputedState.Clean) {\n recompute(node);\n }\n\n return node.value as T;\n };\n\n return read;\n}\n\nfunction recompute<T>(node: ComputedNode<T>): void {\n // Clean up old source subscriptions\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n\n const prevSubscriber = currentSubscriber;\n currentSubscriber = node;\n\n try {\n const newValue = node.fn();\n const changed =\n node.value === undefined || !node.equals(node.value, newValue);\n node.value = newValue;\n node.state = ComputedState.Clean;\n\n // Only propagate if value actually changed\n if (changed) {\n notifySubscribers(node);\n }\n } finally {\n currentSubscriber = prevSubscriber;\n }\n}\n\n// --- Effect ---\n\ninterface EffectNode extends ScheduledEffect {\n _tag: 'effect';\n fn: () => void | (() => void);\n cleanup: (() => void) | null;\n sources: Set<SignalNode<unknown> | ComputedNode<unknown>>;\n disposed: boolean;\n isRender: boolean;\n}\n\nexport function effect(\n fn: () => void | (() => void),\n options?: { render?: boolean },\n): () => void {\n const node: EffectNode = {\n _tag: 'effect',\n fn,\n cleanup: null,\n sources: new Set(),\n disposed: false,\n isRender: options?.render ?? false,\n run() {\n runEffect(node);\n },\n };\n\n // Run immediately to establish dependencies\n runEffect(node);\n\n // Return dispose function\n return () => {\n node.disposed = true;\n cleanupEffect(node);\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n };\n}\n\nfunction runEffect(node: EffectNode): void {\n if (node.disposed) return;\n\n // Before re-running, check if any dirty computed source actually changed.\n // If all computed sources resolved to the same value, skip the re-run.\n if (node.sources.size > 0) {\n let anyChanged = false;\n for (const source of node.sources) {\n if ('_tag' in source && source._tag === 'computed') {\n if (source.state === ComputedState.Dirty) {\n const oldValue = source.value;\n recompute(source);\n if (!source.equals(oldValue as never, source.value as never)) {\n anyChanged = true;\n }\n }\n } else {\n // Plain signal source — if we got scheduled, something changed\n anyChanged = true;\n }\n }\n if (!anyChanged) return;\n }\n\n // Clean up previous run\n cleanupEffect(node);\n\n // Clean up old source subscriptions\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n\n const prevSubscriber = currentSubscriber;\n currentSubscriber = node;\n\n try {\n const result = node.fn();\n if (typeof result === 'function') {\n node.cleanup = result;\n }\n } finally {\n currentSubscriber = prevSubscriber;\n }\n}\n\nfunction cleanupEffect(node: EffectNode): void {\n if (node.cleanup) {\n node.cleanup();\n node.cleanup = null;\n }\n}\n\n// --- Untrack ---\n\n/** Execute a function without tracking any signal reads */\nexport function untrack<T>(fn: () => T): T {\n const prev = currentSubscriber;\n currentSubscriber = null;\n try {\n return fn();\n } finally {\n currentSubscriber = prev;\n }\n}\n\n// --- Internal helpers ---\n\nfunction trackSubscriber(\n node: SignalNode<unknown> | ComputedNode<unknown>,\n): void {\n if (currentSubscriber) {\n node.subscribers.add(currentSubscriber);\n\n if ('sources' in currentSubscriber) {\n currentSubscriber.sources.add(node);\n }\n }\n}\n\nfunction notifySubscribers(\n node: SignalNode<unknown> | ComputedNode<unknown>,\n): void {\n for (const sub of node.subscribers) {\n if (sub._tag === 'computed') {\n // Mark dirty. The computed will re-evaluate lazily when read.\n sub.state = ComputedState.Dirty;\n // Propagate through the computed chain to reach effects.\n // The effects will re-read the computed, triggering recompute,\n // and only update DOM if the value actually changed.\n notifySubscribers(sub);\n } else if (sub._tag === 'effect') {\n scheduleEffect(sub);\n }\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- 'use strict';var chunk3Q7GK4DL_cjs=require('./chunk-3Q7GK4DL.cjs');var S=new Map;function p(r,a){return ()=>{if(S.has(r))return S.get(r);let o=a.state(),n=u(r,o,a);return S.set(r,n),n}}function u(r,a,o){let n={},i=Object.keys(a);for(let e of i)n[e]=chunk3Q7GK4DL_cjs.c(a[e]);let c={};if(o.getters)for(let[e,t]of Object.entries(o.getters))c[e]=chunk3Q7GK4DL_cjs.d(()=>t(n));let s={$id:r};for(let e of i)s[e]=n[e];for(let[e,t]of Object.entries(c))s[e]=t;if(o.actions)for(let[e,t]of Object.entries(o.actions))s[e]=(...d)=>t.apply(s,d);s.$reset=()=>{let e=o.state();for(let t of i)n[t].set(e[t]);},s.$snapshot=()=>{let e={};for(let t of i)e[t]=n[t]();return e};let g=new Set;return s.$subscribe=e=>(g.add(e),()=>g.delete(e)),s}function l(){S.clear();}exports.a=p;exports.b=l;//# sourceMappingURL=chunk-7R4T4V3T.cjs.map
2
- //# sourceMappingURL=chunk-7R4T4V3T.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/store.ts"],"names":["storeInstances","defineStore","id","definition","initialState","store","createStoreInstance","stateSignals","stateKeys","key","signal","getterComputeds","getterFn","computed","comp","actionFn","args","fresh","snapshot","subscribers","callback","clearStores"],"mappings":"mEA4EA,IAAMA,CAAAA,CAAiB,IAAI,GAAA,CAQpB,SAASC,EAKdC,CAAAA,CACAC,CAAAA,CACsB,CACtB,OAAO,IAAM,CAEX,GAAIH,CAAAA,CAAe,GAAA,CAAIE,CAAE,CAAA,CACvB,OAAOF,EAAe,GAAA,CAAIE,CAAE,CAAA,CAG9B,IAAME,CAAAA,CAAeD,CAAAA,CAAW,OAAM,CAChCE,CAAAA,CAAQC,EAAoBJ,CAAAA,CAAIE,CAAAA,CAAcD,CAAU,CAAA,CAC9D,OAAAH,CAAAA,CAAe,GAAA,CAAIE,CAAAA,CAAIG,CAAK,EACrBA,CACT,CACF,CAEA,SAASC,CAAAA,CAKPJ,CAAAA,CACAE,EACAD,CAAAA,CACgB,CAEhB,IAAMI,CAAAA,CAAgD,EAAC,CACjDC,EAAY,MAAA,CAAO,IAAA,CAAKJ,CAAY,CAAA,CAE1C,IAAA,IAAWK,KAAOD,CAAAA,CAChBD,CAAAA,CAAaE,CAAG,CAAA,CAAIC,mBAAAA,CAAON,CAAAA,CAAaK,CAAG,CAAC,CAAA,CAI9C,IAAME,CAAAA,CAA2D,EAAC,CAClE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AAAA,CAAY,GAAA,CAAIC,CAAQ,CAAA,CACjB,IAAMD,CAAAA,CAAY,MAAA,CAAOC,CAAQ,CAAA,CAAA,CAGnCf,CACT,CAKO,SAASgB,CAAAA,EAAoB,CAClCrB,CAAAA,CAAe,KAAA,GACjB","file":"chunk-7R4T4V3T.cjs","sourcesContent":["/**\n * Global state management via defineStore().\n *\n * Stores are singleton signal containers that persist across\n * components. They provide shared state, computed getters,\n * and actions — no external library needed.\n *\n * ```ts\n * const useCounterStore = defineStore('counter', {\n * state: () => ({ count: 0, name: 'Counter' }),\n * getters: {\n * doubled: (state) => state.count() * 2,\n * },\n * actions: {\n * increment() { this.count.update(c => c + 1); },\n * reset() { this.count.set(0); },\n * },\n * });\n *\n * // In any component:\n * const store = useCounterStore();\n * store.count(); // 0\n * store.doubled(); // 0\n * store.increment();\n * store.count(); // 1\n * ```\n */\n\nimport { signal, computed } from './signals.js';\nimport type { Signal, ReadonlySignal } from './signals.js';\n\n// --- Types ---\n\ntype StateFactory<S> = () => S;\n\ntype Getters<S, G> = {\n [K in keyof G]: (state: SignalifiedState<S>) => G[K];\n};\n\ntype Actions<A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n};\n\n/** Maps plain state values to signals */\ntype SignalifiedState<S> = {\n [K in keyof S]: Signal<S[K]>;\n};\n\n/** The store instance returned to consumers */\nexport type Store<S, G, A> = SignalifiedState<S> & {\n [K in keyof G]: ReadonlySignal<G[K]>;\n} & {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n} & {\n /** Reset all state to initial values */\n $reset(): void;\n /** Subscribe to all state changes */\n $subscribe(callback: (state: S) => void): () => void;\n /** Get a plain snapshot of current state */\n $snapshot(): S;\n /** Store ID */\n $id: string;\n};\n\nexport interface StoreDefinition<S, G, A> {\n state: StateFactory<S>;\n getters?: Getters<S, G>;\n actions?: A;\n}\n\n// --- Store registry (singleton) ---\n\nconst storeInstances = new Map<string, Store<any, any, any>>();\n\n// --- defineStore ---\n\n/**\n * Define a global store. Returns a composable function that\n * always returns the same store instance (singleton).\n */\nexport function defineStore<\n S extends Record<string, unknown>,\n G extends Record<string, unknown> = {},\n A extends Record<string, (...args: any[]) => any> = {},\n>(\n id: string,\n definition: StoreDefinition<S, G, A>,\n): () => Store<S, G, A> {\n return () => {\n // Return existing instance if already created\n if (storeInstances.has(id)) {\n return storeInstances.get(id) as Store<S, G, A>;\n }\n\n const initialState = definition.state();\n const store = createStoreInstance(id, initialState, definition);\n storeInstances.set(id, store);\n return store;\n };\n}\n\nfunction createStoreInstance<\n S extends Record<string, unknown>,\n G extends Record<string, unknown>,\n A extends Record<string, (...args: any[]) => any>,\n>(\n id: string,\n initialState: S,\n definition: StoreDefinition<S, G, A>,\n): Store<S, G, A> {\n // Create signals for each state property\n const stateSignals: Record<string, Signal<unknown>> = {};\n const stateKeys = Object.keys(initialState);\n\n for (const key of stateKeys) {\n stateSignals[key] = signal(initialState[key]);\n }\n\n // Create computed getters\n const getterComputeds: Record<string, ReadonlySignal<unknown>> = {};\n if (definition.getters) {\n for (const [key, getterFn] of Object.entries(definition.getters)) {\n getterComputeds[key] = computed(() =>\n (getterFn as Function)(stateSignals),\n );\n }\n }\n\n // Build the store object\n const store: any = { $id: id };\n\n // Add state signals\n for (const key of stateKeys) {\n store[key] = stateSignals[key];\n }\n\n // Add getters\n for (const [key, comp] of Object.entries(getterComputeds)) {\n store[key] = comp;\n }\n\n // Bind actions with `this` pointing to the full store (state + getters + actions)\n if (definition.actions) {\n for (const [key, actionFn] of Object.entries(definition.actions)) {\n store[key] = (...args: unknown[]) =>\n (actionFn as Function).apply(store, args);\n }\n }\n\n // $reset\n store.$reset = () => {\n const fresh = definition.state();\n for (const key of stateKeys) {\n stateSignals[key].set(fresh[key as keyof S]);\n }\n };\n\n // $snapshot\n store.$snapshot = (): S => {\n const snapshot: Record<string, unknown> = {};\n for (const key of stateKeys) {\n snapshot[key] = stateSignals[key]();\n }\n return snapshot as S;\n };\n\n // $subscribe\n const subscribers = new Set<(state: S) => void>();\n store.$subscribe = (callback: (state: S) => void): (() => void) => {\n subscribers.add(callback);\n return () => subscribers.delete(callback);\n };\n\n return store as Store<S, G, A>;\n}\n\n/**\n * Clear all store instances (useful for testing).\n */\nexport function clearStores(): void {\n storeInstances.clear();\n}\n"]}
@@ -1,2 +0,0 @@
1
- var r=new Set,c=new Set,i=false,f=0,a=false,b=1e3;function l(){if(i)return;i=true,a=false;let e=0;for(;(r.size>0||c.size>0)&&e<b;){if(e++,r.size>0){let u=[...r].sort(p);r.clear();for(let t of u)t.run();}if(c.size>0){let u=[...c].sort(p);c.clear();for(let t of u)t.run();}}e>=b&&console.error("[AkashJS] Effect flush limit reached. Possible circular dependency."),i=false;}function S(e){e.isRender?r.add(e):c.add(e),f===0&&!i&&!a&&(a=true,queueMicrotask(l));}function y(e){f++;try{e();}finally{f--,f===0&&l();}}function p(e,u){return (e.depth??0)-(u.depth??0)}function m(){l();}var s=null;function w(e,u){let t={value:e,subscribers:new Set,equals:u?.equals??Object.is},n=()=>(g(t),t.value);return n.set=o=>{t.equals(t.value,o)||(t.value=o,d(t));},n.update=o=>{n.set(o(t.value));},n.peek=()=>t.value,n}function k(e,u){let t={_tag:"computed",fn:e,value:void 0,state:1,subscribers:new Set,sources:new Set,equals:u?.equals??Object.is};return ()=>(s&&(t.subscribers.add(s),"sources"in s&&s.sources.add(t)),t.state!==0&&T(t),t.value)}function T(e){for(let t of e.sources)t.subscribers.delete(e);e.sources.clear();let u=s;s=e;try{let t=e.fn(),n=e.value===void 0||!e.equals(e.value,t);e.value=t,e.state=0,n&&d(e);}finally{s=u;}}function q(e,u){let t={_tag:"effect",fn:e,cleanup:null,sources:new Set,disposed:false,isRender:u?.render??false,run(){v(t);}};return v(t),()=>{t.disposed=true,h(t);for(let n of t.sources)n.subscribers.delete(t);t.sources.clear();}}function v(e){if(e.disposed)return;if(e.sources.size>0){let t=false;for(let n of e.sources)if("_tag"in n&&n._tag==="computed"){if(n.state===1){let o=n.value;T(n),n.equals(o,n.value)||(t=true);}}else t=true;if(!t)return}h(e);for(let t of e.sources)t.subscribers.delete(e);e.sources.clear();let u=s;s=e;try{let t=e.fn();typeof t=="function"&&(e.cleanup=t);}finally{s=u;}}function h(e){e.cleanup&&(e.cleanup(),e.cleanup=null);}function C(e){let u=s;s=null;try{return e()}finally{s=u;}}function g(e){s&&(e.subscribers.add(s),"sources"in s&&s.sources.add(e));}function d(e){for(let u of e.subscribers)u._tag==="computed"?(u.state=1,d(u)):u._tag==="effect"&&S(u);}export{y as a,m as b,w as c,k as d,q as e,C as f};//# sourceMappingURL=chunk-FX7RHVM5.js.map
2
- //# sourceMappingURL=chunk-FX7RHVM5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/scheduler.ts","../src/signals.ts"],"names":["pendingRender","pendingUser","flushing","batchDepth","flushScheduled","MAX_FLUSH_ITERATIONS","flush","iterations","queue","byDepth","fx","scheduleEffect","batch","fn","a","b","flushSync","currentSubscriber","signal","initialValue","options","node","read","trackSubscriber","value","notifySubscribers","computed","recompute","source","prevSubscriber","newValue","changed","effect","runEffect","cleanupEffect","anyChanged","oldValue","result","untrack","prev","sub"],"mappings":"AAcA,IAAMA,CAAAA,CAAgB,IAAI,GAAA,CACpBC,CAAAA,CAAc,IAAI,GAAA,CACpBC,CAAAA,CAAW,KAAA,CACXC,CAAAA,CAAa,CAAA,CACbC,CAAAA,CAAiB,KAAA,CAEfC,EAAuB,GAAA,CAE7B,SAASC,CAAAA,EAAc,CACrB,GAAIJ,CAAAA,CAAU,OACdA,CAAAA,CAAW,KACXE,CAAAA,CAAiB,KAAA,CAIjB,IAAIG,CAAAA,CAAa,CAAA,CACjB,KAAA,CAAQP,CAAAA,CAAc,IAAA,CAAO,GAAKC,CAAAA,CAAY,IAAA,CAAO,CAAA,GAAMM,CAAAA,CAAaF,CAAAA,EAAsB,CAI5F,GAHAE,CAAAA,EAAAA,CAGIP,CAAAA,C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,GAAI,CACF,OAAOJ,CAAAA,EACT,QAAE,CACAI,CAAAA,CAAoBsB,EACtB,CACF,CAIA,SAAShB,CAAAA,CACPF,CAAAA,CACM,CACFJ,CAAAA,GACFI,CAAAA,CAAK,WAAA,CAAY,GAAA,CAAIJ,CAAiB,CAAA,CAElC,SAAA,GAAaA,CAAAA,EACfA,EAAkB,OAAA,CAAQ,GAAA,CAAII,CAAI,CAAA,EAGxC,CAEA,SAASI,CAAAA,CACPJ,CAAAA,CACM,CACN,IAAA,IAAWmB,CAAAA,IAAOnB,CAAAA,CAAK,WAAA,CACjBmB,CAAAA,CAAI,IAAA,GAAS,UAAA,EAEfA,CAAAA,CAAI,MAAQ,CAAA,CAIZf,CAAAA,CAAkBe,CAAG,CAAA,EACZA,CAAAA,CAAI,IAAA,GAAS,QAAA,EACtB7B,CAAAA,CAAe6B,CAAG,EAGxB","file":"chunk-FX7RHVM5.js","sourcesContent":["/**\n * Microtask-based effect scheduler with priority levels and deduplication.\n *\n * Render effects (DOM bindings) run before user effects to ensure\n * DOM is consistent before user-side effects execute.\n */\n\nexport interface ScheduledEffect {\n run(): void;\n isRender: boolean;\n /** Depth in the dependency graph (0 = root). Lower depth runs first. */\n depth?: number;\n}\n\nconst pendingRender = new Set<ScheduledEffect>();\nconst pendingUser = new Set<ScheduledEffect>();\nlet flushing = false;\nlet batchDepth = 0;\nlet flushScheduled = false;\n\nconst MAX_FLUSH_ITERATIONS = 1000;\n\nfunction flush(): void {\n if (flushing) return;\n flushing = true;\n flushScheduled = false;\n\n // Process render effects first, then user effects.\n // Effects may enqueue more effects during flush, so loop until empty.\n let iterations = 0;\n while ((pendingRender.size > 0 || pendingUser.size > 0) && iterations < MAX_FLUSH_ITERATIONS) {\n iterations++;\n\n // Drain render effects (sorted by depth — parents before children)\n if (pendingRender.size > 0) {\n const queue = [...pendingRender].sort(byDepth);\n pendingRender.clear();\n for (const fx of queue) {\n fx.run();\n }\n }\n\n // Drain user effects (sorted by depth)\n if (pendingUser.size > 0) {\n const queue = [...pendingUser].sort(byDepth);\n pendingUser.clear();\n for (const fx of queue) {\n fx.run();\n }\n }\n }\n\n if (iterations >= MAX_FLUSH_ITERATIONS) {\n console.error('[AkashJS] Effect flush limit reached. Possible circular dependency.');\n }\n\n flushing = false;\n}\n\nexport function scheduleEffect(fx: ScheduledEffect): void {\n if (fx.isRender) {\n pendingRender.add(fx);\n } else {\n pendingUser.add(fx);\n }\n\n if (batchDepth === 0 && !flushing && !flushScheduled) {\n flushScheduled = true;\n queueMicrotask(flush);\n }\n}\n\n/**\n * Batch multiple signal writes — subscribers are notified only once\n * at the end of the batch.\n */\nexport function batch(fn: () => void): void {\n batchDepth++;\n try {\n fn();\n } finally {\n batchDepth--;\n if (batchDepth === 0) {\n flush();\n }\n }\n}\n\n/** Sort effects by depth (lower depth first = parents before children) */\nfunction byDepth(a: ScheduledEffect, b: ScheduledEffect): number {\n return (a.depth ?? 0) - (b.depth ?? 0);\n}\n\n/** Synchronously flush all pending effects. Useful for testing. */\nexport function flushSync(): void {\n flush();\n}\n","/**\n * Fine-grained reactivity system.\n *\n * Inspired by SolidJS/Preact Signals. Provides signal(), computed(),\n * effect(), and untrack() primitives with automatic dependency tracking\n * and glitch-free diamond dependency resolution.\n */\n\nimport { scheduleEffect, type ScheduledEffect } from './scheduler.js';\n\n// --- Tracking scope ---\n\ntype Subscriber = EffectNode | ComputedNode<unknown>;\n\nlet currentSubscriber: Subscriber | null = null;\n\n// --- Signal ---\n\nexport interface Signal<T> {\n /** Read the current value (tracks dependency if inside a reactive scope) */\n (): T;\n /** Set a new value */\n set(value: T): void;\n /** Update the value using the previous value */\n update(fn: (prev: T) => T): void;\n /** Read without tracking (no dependency registered) */\n peek(): T;\n}\n\nexport type ReadonlySignal<T> = () => T;\n\ninterface SignalNode<T> {\n value: T;\n subscribers: Set<Subscriber>;\n equals: (a: T, b: T) => boolean;\n}\n\nexport function signal<T>(\n initialValue: T,\n options?: { equals?: (a: T, b: T) => boolean },\n): Signal<T> {\n const node: SignalNode<T> = {\n value: initialValue,\n subscribers: new Set(),\n equals: options?.equals ?? Object.is,\n };\n\n const read = (): T => {\n trackSubscriber(node);\n return node.value;\n };\n\n read.set = (value: T): void => {\n if (node.equals(node.value, value)) return;\n node.value = value;\n notifySubscribers(node);\n };\n\n read.update = (fn: (prev: T) => T): void => {\n read.set(fn(node.value));\n };\n\n read.peek = (): T => node.value;\n\n return read;\n}\n\n// --- Computed ---\n\nconst enum ComputedState {\n Clean = 0,\n Dirty = 1,\n}\n\ninterface ComputedNode<T> {\n _tag: 'computed';\n fn: () => T;\n value: T | undefined;\n state: ComputedState;\n subscribers: Set<Subscriber>;\n sources: Set<SignalNode<unknown> | ComputedNode<unknown>>;\n equals: (a: T, b: T) => boolean;\n}\n\nexport function computed<T>(\n fn: () => T,\n options?: { equals?: (a: T, b: T) => boolean },\n): ReadonlySignal<T> {\n const node: ComputedNode<T> = {\n _tag: 'computed',\n fn,\n value: undefined,\n state: ComputedState.Dirty,\n subscribers: new Set(),\n sources: new Set(),\n equals: options?.equals ?? Object.is,\n };\n\n const read = (): T => {\n // Track this computed as a dependency of the current subscriber\n if (currentSubscriber) {\n node.subscribers.add(currentSubscriber);\n if ('sources' in currentSubscriber) {\n currentSubscriber.sources.add(node);\n }\n }\n\n if (node.state !== ComputedState.Clean) {\n recompute(node);\n }\n\n return node.value as T;\n };\n\n return read;\n}\n\nfunction recompute<T>(node: ComputedNode<T>): void {\n // Clean up old source subscriptions\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n\n const prevSubscriber = currentSubscriber;\n currentSubscriber = node;\n\n try {\n const newValue = node.fn();\n const changed =\n node.value === undefined || !node.equals(node.value, newValue);\n node.value = newValue;\n node.state = ComputedState.Clean;\n\n // Only propagate if value actually changed\n if (changed) {\n notifySubscribers(node);\n }\n } finally {\n currentSubscriber = prevSubscriber;\n }\n}\n\n// --- Effect ---\n\ninterface EffectNode extends ScheduledEffect {\n _tag: 'effect';\n fn: () => void | (() => void);\n cleanup: (() => void) | null;\n sources: Set<SignalNode<unknown> | ComputedNode<unknown>>;\n disposed: boolean;\n isRender: boolean;\n}\n\nexport function effect(\n fn: () => void | (() => void),\n options?: { render?: boolean },\n): () => void {\n const node: EffectNode = {\n _tag: 'effect',\n fn,\n cleanup: null,\n sources: new Set(),\n disposed: false,\n isRender: options?.render ?? false,\n run() {\n runEffect(node);\n },\n };\n\n // Run immediately to establish dependencies\n runEffect(node);\n\n // Return dispose function\n return () => {\n node.disposed = true;\n cleanupEffect(node);\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n };\n}\n\nfunction runEffect(node: EffectNode): void {\n if (node.disposed) return;\n\n // Before re-running, check if any dirty computed source actually changed.\n // If all computed sources resolved to the same value, skip the re-run.\n if (node.sources.size > 0) {\n let anyChanged = false;\n for (const source of node.sources) {\n if ('_tag' in source && source._tag === 'computed') {\n if (source.state === ComputedState.Dirty) {\n const oldValue = source.value;\n recompute(source);\n if (!source.equals(oldValue as never, source.value as never)) {\n anyChanged = true;\n }\n }\n } else {\n // Plain signal source — if we got scheduled, something changed\n anyChanged = true;\n }\n }\n if (!anyChanged) return;\n }\n\n // Clean up previous run\n cleanupEffect(node);\n\n // Clean up old source subscriptions\n for (const source of node.sources) {\n source.subscribers.delete(node);\n }\n node.sources.clear();\n\n const prevSubscriber = currentSubscriber;\n currentSubscriber = node;\n\n try {\n const result = node.fn();\n if (typeof result === 'function') {\n node.cleanup = result;\n }\n } finally {\n currentSubscriber = prevSubscriber;\n }\n}\n\nfunction cleanupEffect(node: EffectNode): void {\n if (node.cleanup) {\n node.cleanup();\n node.cleanup = null;\n }\n}\n\n// --- Untrack ---\n\n/** Execute a function without tracking any signal reads */\nexport function untrack<T>(fn: () => T): T {\n const prev = currentSubscriber;\n currentSubscriber = null;\n try {\n return fn();\n } finally {\n currentSubscriber = prev;\n }\n}\n\n// --- Internal helpers ---\n\nfunction trackSubscriber(\n node: SignalNode<unknown> | ComputedNode<unknown>,\n): void {\n if (currentSubscriber) {\n node.subscribers.add(currentSubscriber);\n\n if ('sources' in currentSubscriber) {\n currentSubscriber.sources.add(node);\n }\n }\n}\n\nfunction notifySubscribers(\n node: SignalNode<unknown> | ComputedNode<unknown>,\n): void {\n for (const sub of node.subscribers) {\n if (sub._tag === 'computed') {\n // Mark dirty. The computed will re-evaluate lazily when read.\n sub.state = ComputedState.Dirty;\n // Propagate through the computed chain to reach effects.\n // The effects will re-read the computed, triggering recompute,\n // and only update DOM if the value actually changed.\n notifySubscribers(sub);\n } else if (sub._tag === 'effect') {\n scheduleEffect(sub);\n }\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- import {c,d}from'./chunk-FX7RHVM5.js';var S=new Map;function p(r,a){return ()=>{if(S.has(r))return S.get(r);let o=a.state(),n=u(r,o,a);return S.set(r,n),n}}function u(r,a,o){let n={},i=Object.keys(a);for(let e of i)n[e]=c(a[e]);let c$1={};if(o.getters)for(let[e,t]of Object.entries(o.getters))c$1[e]=d(()=>t(n));let s={$id:r};for(let e of i)s[e]=n[e];for(let[e,t]of Object.entries(c$1))s[e]=t;if(o.actions)for(let[e,t]of Object.entries(o.actions))s[e]=(...d)=>t.apply(s,d);s.$reset=()=>{let e=o.state();for(let t of i)n[t].set(e[t]);},s.$snapshot=()=>{let e={};for(let t of i)e[t]=n[t]();return e};let g=new Set;return s.$subscribe=e=>(g.add(e),()=>g.delete(e)),s}function l(){S.clear();}export{p as a,l as b};//# sourceMappingURL=chunk-JKO64Z6H.js.map
2
- //# sourceMappingURL=chunk-JKO64Z6H.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/store.ts"],"names":["storeInstances","defineStore","id","definition","initialState","store","createStoreInstance","stateSignals","stateKeys","key","signal","getterComputeds","getterFn","computed","comp","actionFn","args","fresh","snapshot","subscribers","callback","clearStores"],"mappings":"sCA4EA,IAAMA,CAAAA,CAAiB,IAAI,GAAA,CAQpB,SAASC,EAKdC,CAAAA,CACAC,CAAA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,CAAQZ,EAAW,OAAO,CAAA,CAC7DE,EAAMI,CAAG,CAAA,CAAI,IAAIO,CAAAA,GACdD,CAAAA,CAAsB,KAAA,CAAMV,CAAAA,CAAOW,CAAI,CAAA,CAK9CX,EAAM,MAAA,CAAS,IAAM,CACnB,IAAMY,CAAAA,CAAQd,CAAAA,CAAW,OAAM,CAC/B,IAAA,IAAWM,CAAAA,IAAOD,CAAAA,CAChBD,CAAAA,CAAaE,CAAG,EAAE,GAAA,CAAIQ,CAAAA,CAAMR,CAAc,CAAC,EAE/C,EAGAJ,CAAAA,CAAM,SAAA,CAAY,IAAS,CACzB,IAAMa,CAAAA,CAAoC,EAAC,CAC3C,IAAA,IAAWT,CAAAA,IAAOD,CAAAA,CAChBU,CAAAA,CAAST,CAAG,EAAIF,CAAAA,CAAaE,CAAG,CAAA,EAAE,CAEpC,OAAOS,CACT,EAGA,IAAMC,CAAAA,CAAc,IAAI,GAAA,CACxB,OAAAd,EAAM,UAAA,CAAce,CAAAA,GAClBD,CAAAA,CAAY,GAAA,CAAIC,CAAQ,CAAA,CACjB,IAAMD,CAAAA,CAAY,MAAA,CAAOC,CAAQ,CAAA,CAAA,CAGnCf,CACT,CAKO,SAASgB,CAAAA,EAAoB,CAClCrB,CAAAA,CAAe,KAAA,GACjB","file":"chunk-JKO64Z6H.js","sourcesContent":["/**\n * Global state management via defineStore().\n *\n * Stores are singleton signal containers that persist across\n * components. They provide shared state, computed getters,\n * and actions — no external library needed.\n *\n * ```ts\n * const useCounterStore = defineStore('counter', {\n * state: () => ({ count: 0, name: 'Counter' }),\n * getters: {\n * doubled: (state) => state.count() * 2,\n * },\n * actions: {\n * increment() { this.count.update(c => c + 1); },\n * reset() { this.count.set(0); },\n * },\n * });\n *\n * // In any component:\n * const store = useCounterStore();\n * store.count(); // 0\n * store.doubled(); // 0\n * store.increment();\n * store.count(); // 1\n * ```\n */\n\nimport { signal, computed } from './signals.js';\nimport type { Signal, ReadonlySignal } from './signals.js';\n\n// --- Types ---\n\ntype StateFactory<S> = () => S;\n\ntype Getters<S, G> = {\n [K in keyof G]: (state: SignalifiedState<S>) => G[K];\n};\n\ntype Actions<A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n};\n\n/** Maps plain state values to signals */\ntype SignalifiedState<S> = {\n [K in keyof S]: Signal<S[K]>;\n};\n\n/** The store instance returned to consumers */\nexport type Store<S, G, A> = SignalifiedState<S> & {\n [K in keyof G]: ReadonlySignal<G[K]>;\n} & {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n} & {\n /** Reset all state to initial values */\n $reset(): void;\n /** Subscribe to all state changes */\n $subscribe(callback: (state: S) => void): () => void;\n /** Get a plain snapshot of current state */\n $snapshot(): S;\n /** Store ID */\n $id: string;\n};\n\nexport interface StoreDefinition<S, G, A> {\n state: StateFactory<S>;\n getters?: Getters<S, G>;\n actions?: A;\n}\n\n// --- Store registry (singleton) ---\n\nconst storeInstances = new Map<string, Store<any, any, any>>();\n\n// --- defineStore ---\n\n/**\n * Define a global store. Returns a composable function that\n * always returns the same store instance (singleton).\n */\nexport function defineStore<\n S extends Record<string, unknown>,\n G extends Record<string, unknown> = {},\n A extends Record<string, (...args: any[]) => any> = {},\n>(\n id: string,\n definition: StoreDefinition<S, G, A>,\n): () => Store<S, G, A> {\n return () => {\n // Return existing instance if already created\n if (storeInstances.has(id)) {\n return storeInstances.get(id) as Store<S, G, A>;\n }\n\n const initialState = definition.state();\n const store = createStoreInstance(id, initialState, definition);\n storeInstances.set(id, store);\n return store;\n };\n}\n\nfunction createStoreInstance<\n S extends Record<string, unknown>,\n G extends Record<string, unknown>,\n A extends Record<string, (...args: any[]) => any>,\n>(\n id: string,\n initialState: S,\n definition: StoreDefinition<S, G, A>,\n): Store<S, G, A> {\n // Create signals for each state property\n const stateSignals: Record<string, Signal<unknown>> = {};\n const stateKeys = Object.keys(initialState);\n\n for (const key of stateKeys) {\n stateSignals[key] = signal(initialState[key]);\n }\n\n // Create computed getters\n const getterComputeds: Record<string, ReadonlySignal<unknown>> = {};\n if (definition.getters) {\n for (const [key, getterFn] of Object.entries(definition.getters)) {\n getterComputeds[key] = computed(() =>\n (getterFn as Function)(stateSignals),\n );\n }\n }\n\n // Build the store object\n const store: any = { $id: id };\n\n // Add state signals\n for (const key of stateKeys) {\n store[key] = stateSignals[key];\n }\n\n // Add getters\n for (const [key, comp] of Object.entries(getterComputeds)) {\n store[key] = comp;\n }\n\n // Bind actions with `this` pointing to the full store (state + getters + actions)\n if (definition.actions) {\n for (const [key, actionFn] of Object.entries(definition.actions)) {\n store[key] = (...args: unknown[]) =>\n (actionFn as Function).apply(store, args);\n }\n }\n\n // $reset\n store.$reset = () => {\n const fresh = definition.state();\n for (const key of stateKeys) {\n stateSignals[key].set(fresh[key as keyof S]);\n }\n };\n\n // $snapshot\n store.$snapshot = (): S => {\n const snapshot: Record<string, unknown> = {};\n for (const key of stateKeys) {\n snapshot[key] = stateSignals[key]();\n }\n return snapshot as S;\n };\n\n // $subscribe\n const subscribers = new Set<(state: S) => void>();\n store.$subscribe = (callback: (state: S) => void): (() => void) => {\n subscribers.add(callback);\n return () => subscribers.delete(callback);\n };\n\n return store as Store<S, G, A>;\n}\n\n/**\n * Clear all store instances (useful for testing).\n */\nexport function clearStores(): void {\n storeInstances.clear();\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/context.ts","../src/dom.ts","../src/component.ts"],"names":["errors","DOC_BASE","formatError","code","context","def","msg","akashError","getErrorDef","getAllErrorCodes","CONTEXT_BRAND","currentScope","pushScope","parent","scope","popScope","getCurrentScope","runInScope","fn","prev","createContext","defaultValue","provide","key","value","inject","fallback","createElement","tag","attrs","el","setProperty","createText","cloneTemplate","html","template","event","bindText","node","effect","bindProperty","bindVisible","createAnchor","label","renderConditional","anchor","condition","trueBranch","falseBranch","current","dispose","branch","liveParent","fragment","nodes","renderList","items","keyFn","renderItem","currentItems","newData","newItems","oldMap","item","i","data","existing","Show","props","container","getWhen","nodeToDOM","For","getEach","index","child","insert","domNode","__getter","currentHooks","onMount","onUnmount","onError","ref","defineComponent","setup","component","rawProps","childrenProp","restProps","ctx","target","receiver","val","hooks","prevHooks","parentScope","renderFn","rendered","err","handler","mountFn","cleanup"],"mappings":"mEAqBA,IAAMA,EAAmC,CAEvC,MAAA,CAAQ,CACN,IAAA,CAAM,QAAA,CACN,QAAS,8CAAA,CACT,IAAA,CAAM,oDACR,CAAA,CACA,MAAA,CAAQ,CACN,IAAA,CAAM,QAAA,CACN,QAAS,6CAAA,CACT,IAAA,CAAM,mDACR,CAAA,CACA,MAAA,CAAQ,CACN,IAAA,CAAM,QAAA,CACN,QAAS,yCAAA,CACT,IAAA,CAAM,gEACR,CAAA,CAGA,MAAA,CAAQ,CACN,IAAA,CAAM,QAAA,CACN,QAAS,8CAAA,CACT,IAAA,CAAM,oDACR,CAAA,CACA,MAAA,CAAQ,CACN,IAAA,CAAM,QAAA,CACN,QAAS,gDAAA,CACT,IAAA,CAAM,sDACR,CAAA,CACA,OAAQ,CACN,IAAA,CAAM,SACN,OAAA,CAAS,8CAAA,CACT,KAAM,oDACR,CAAA,CAGA,OAAQ,CACN,IAAA,CAAM,SACN,OAAA,CAAS,kDAAA,CACT,KAAM,uEACR,CAAA,CACA,OAAQ,CACN,IAAA,CAAM,SACN,OAAA,CAAS,yCAAA,CACT,KAAM,gHACR,CAAA,CAGA,OAAQ,CACN,IAAA,CAAM,SACN,OAAA,CAAS,gDAAA,CACT,KAAM,uEACR,CAAA,CACA,OAAQ,CACN,IAAA,CAAM,SACN,OAAA,CAAS,2BAAA,CACT,KAAM,gEACR,CAAA,CAGA,MAAA,CAAQ,CACN,KAAM,QAAA,CACN,OAAA,CAAS,+CACT,IAAA,CAAM,gEACR,EACA,MAAA,CAAQ,CACN,KAAM,QAAA,CACN,OAAA,CAAS,oCACT,IAAA,CAAM,8DACR,EACA,MAAA,CAAQ,CACN,KAAM,QAAA,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AM,MAAA,CAAS,GACvB,cAAA,CAAe,IAAM,CACnB,IAAA,IAAWO,KAAWP,CAAAA,CAAM,KAAA,CAC1B,GAAI,CACF,IAAMQ,CAAAA,CAAUD,CAAAA,EAAQ,CACpB,OAAOC,CAAAA,EAAY,UAAA,EACrBR,CAAAA,CAAM,OAAA,CAAQ,KAAKQ,CAAO,EAE9B,CAAA,MAASH,CAAAA,CAAK,CACZ,IAAA,IAAWC,CAAAA,IAAWN,CAAAA,CAAM,KAAA,CAC1BM,EAAQD,CAAAA,YAAe,KAAA,CAAQA,CAAAA,CAAM,IAAI,KAAA,CAAM,MAAA,CAAOA,CAAG,CAAC,CAAC,EAE/D,CAEJ,CAAC,CAAA,CAGItB,CACT,CAAA,CAEA,OAAAS,CAAAA,CAAU,MAAA,CAAS,KACZA,CACT","file":"chunk-RVHMMGJG.cjs","sourcesContent":["/**\n * Error message catalog.\n *\n * Every AkashJS runtime error has a unique code (AK0001, AK0002, etc.),\n * a one-line description, and a link to detailed documentation.\n *\n * Usage:\n * throw akashError('AK0010', 'provide()');\n */\n\n// --- Error registry ---\n\nexport interface ErrorDef {\n /** Error code */\n code: string;\n /** Short description */\n message: string;\n /** Extended explanation and fix suggestion */\n hint: string;\n}\n\nconst errors: Record<string, ErrorDef> = {\n // --- Context errors (AK001x) ---\n AK0010: {\n code: 'AK0010',\n message: 'provide() called outside of component setup.',\n hint: 'provide() must be called inside defineComponent().',\n },\n AK0012: {\n code: 'AK0012',\n message: 'inject() called outside of component setup.',\n hint: 'inject() must be called inside defineComponent().',\n },\n AK0013: {\n code: 'AK0013',\n message: 'No provider found for injected context.',\n hint: 'Make sure an ancestor component calls provide() with this key.',\n },\n\n // --- Lifecycle errors (AK002x) ---\n AK0020: {\n code: 'AK0020',\n message: 'onMount() called outside of component setup.',\n hint: 'onMount() must be called inside defineComponent().',\n },\n AK0021: {\n code: 'AK0021',\n message: 'onUnmount() called outside of component setup.',\n hint: 'onUnmount() must be called inside defineComponent().',\n },\n AK0022: {\n code: 'AK0022',\n message: 'onError() called outside of component setup.',\n hint: 'onError() must be called inside defineComponent().',\n },\n\n // --- Signal errors (AK003x) ---\n AK0030: {\n code: 'AK0030',\n message: 'Circular dependency detected in computed signal.',\n hint: 'A computed signal is reading itself, directly or via other computeds.',\n },\n AK0031: {\n code: 'AK0031',\n message: 'Signal set() called during computation.',\n hint: 'Do not set signals inside computed() or during effect execution. Use batch() or set signals in event handlers.',\n },\n\n // --- Component errors (AK004x) ---\n AK0040: {\n code: 'AK0040',\n message: 'Component setup must return a render function.',\n hint: 'The function passed to defineComponent() must return () => AkashNode.',\n },\n AK0041: {\n code: 'AK0041',\n message: 'Required prop is missing.',\n hint: 'Check that the parent component is passing all required props.',\n },\n\n // --- Router errors (AK005x) ---\n AK0050: {\n code: 'AK0050',\n message: 'useRoute() called outside of router context.',\n hint: 'Make sure your component is rendered inside a router provider.',\n },\n AK0051: {\n code: 'AK0051',\n message: 'No route matched the current URL.',\n hint: 'Add a catch-all route ([...rest]) to handle unmatched paths.',\n },\n AK0052: {\n code: 'AK0052',\n message: 'Route guard threw an error.',\n hint: 'Check the guard function for unhandled exceptions.',\n },\n\n // --- Form errors (AK006x) ---\n AK0060: {\n code: 'AK0060',\n message: 'Form submitted while invalid.',\n hint: 'The submit handler was not called because validation failed. Check form.errors().',\n },\n AK0061: {\n code: 'AK0061',\n message: 'Async validator timed out.',\n hint: 'The async validator did not resolve within the expected time. Check your async validation logic.',\n },\n\n // --- HTTP errors (AK007x) ---\n AK0070: {\n code: 'AK0070',\n message: 'HTTP request failed.',\n hint: 'Check the server response status and network connectivity.',\n },\n AK0071: {\n code: 'AK0071',\n message: 'createResource() fetcher threw an error.',\n hint: 'Check the fetcher function passed to createResource().',\n },\n};\n\n// --- Public API ---\n\nconst DOC_BASE = 'https://akashjs.dev/errors';\n\n/**\n * Format an AkashJS error with code, message, hint, and doc link.\n */\nexport function formatError(code: string, context?: string): string {\n const def = errors[code];\n if (!def) {\n return `[AkashJS ${code}] Unknown error code.`;\n }\n\n let msg = `[AkashJS ${code}] ${def.message}`;\n if (context) {\n msg += `\\n ${context}`;\n }\n msg += `\\n ${def.hint}`;\n msg += `\\n See: ${DOC_BASE}/${code}`;\n return msg;\n}\n\n/**\n * Create and throw an AkashJS error.\n */\nexport function akashError(code: string, context?: string): Error {\n return new Error(formatError(code, context));\n}\n\n/**\n * Get the error definition for a code.\n */\nexport function getErrorDef(code: string): ErrorDef | undefined {\n return errors[code];\n}\n\n/**\n * Get all registered error codes.\n */\nexport function getAllErrorCodes(): string[] {\n return Object.keys(errors);\n}\n","/**\n * Lightweight dependency injection via provide/inject.\n *\n * Context is scoped to the component tree — no injector hierarchy,\n * no decorators, no classes. Just createContext(), provide(), inject().\n */\n\n// --- Types ---\n\nimport { akashError } from './errors.js';\n\nconst CONTEXT_BRAND = Symbol('akash.context');\n\nexport interface InjectionKey<T> {\n readonly [CONTEXT_BRAND]: true;\n readonly _type: T; // phantom type — never used at runtime\n readonly defaultValue: T | undefined;\n readonly id: symbol;\n}\n\n// --- Context stack (managed by component system) ---\n\ninterface ContextScope {\n values: Map<symbol, unknown>;\n parent: ContextScope | null;\n}\n\nlet currentScope: ContextScope | null = null;\n\n/** @internal — called by defineComponent to push/pop context scopes */\nexport function pushScope(parent: ContextScope | null = currentScope): ContextScope {\n const scope: ContextScope = { values: new Map(), parent };\n currentScope = scope;\n return scope;\n}\n\n/** @internal */\nexport function popScope(scope: ContextScope): void {\n currentScope = scope.parent;\n}\n\n/** @internal */\nexport function getCurrentScope(): ContextScope | null {\n return currentScope;\n}\n\n/**\n * Run a function within a given scope so that provide/inject\n * work correctly for components created asynchronously\n * (e.g., lazy-loaded route components).\n */\nexport function runInScope<T>(scope: ContextScope, fn: () => T): T {\n const prev = currentScope;\n currentScope = scope;\n try {\n return fn();\n } finally {\n currentScope = prev;\n }\n}\n\n// --- Public API ---\n\n/**\n * Create a typed context key with an optional default value.\n *\n * ```ts\n * const ThemeContext = createContext<'light' | 'dark'>('light');\n * ```\n */\nexport function createContext<T>(defaultValue?: T): InjectionKey<T> {\n return {\n [CONTEXT_BRAND]: true,\n _type: undefined as T,\n defaultValue,\n id: Symbol('context'),\n };\n}\n\n/**\n * Provide a value for a context key in the current component scope.\n * All descendant components can inject() this value.\n *\n * Must be called inside defineComponent() setup.\n */\nexport function provide<T>(key: InjectionKey<T>, value: T): void {\n if (!currentScope) {\n throw akashError('AK0010');\n }\n currentScope.values.set(key.id, value);\n}\n\n/**\n * Inject a value from the nearest ancestor that provided it.\n *\n * Must be called inside defineComponent() setup.\n */\nexport function inject<T>(key: InjectionKey<T>): T;\nexport function inject<T>(key: InjectionKey<T>, fallback: T): T;\nexport function inject<T>(key: InjectionKey<T>, fallback?: T): T {\n if (!currentScope) {\n throw akashError('AK0012');\n }\n\n // Walk up the scope chain\n let scope: ContextScope | null = currentScope;\n while (scope) {\n if (scope.values.has(key.id)) {\n return scope.values.get(key.id) as T;\n }\n scope = scope.parent;\n }\n\n // Check fallback, then default\n if (fallback !== undefined) return fallback;\n if (key.defaultValue !== undefined) return key.defaultValue;\n\n throw akashError('AK0013');\n}\n","/**\n * Direct DOM rendering runtime.\n *\n * No virtual DOM. The compiler generates calls to these helpers.\n * Signal reads inside templates become fine-grained effects that\n * update only the specific DOM node that changed.\n */\n\nimport { effect } from './signals.js';\nimport { getCurrentScope, runInScope } from './context.js';\nimport type { AkashNode } from './types.js';\n\n// --- DOM creation helpers (used by compiler output) ---\n\n/** Create an element and optionally set static attributes */\nexport function createElement(\n tag: string,\n attrs?: Record<string, unknown>,\n): HTMLElement {\n const el = document.createElement(tag);\n if (attrs) {\n for (const [key, value] of Object.entries(attrs)) {\n setProperty(el, key, value);\n }\n }\n return el;\n}\n\n/** Create a text node */\nexport function createText(value: string): Text {\n return document.createTextNode(value);\n}\n\n/** Clone a template element for static structure */\nexport function cloneTemplate(html: string): DocumentFragment {\n const template = document.createElement('template');\n template.innerHTML = html;\n return template.content.cloneNode(true) as DocumentFragment;\n}\n\n// --- Property/attribute setting ---\n\nexport function setProperty(el: HTMLElement, key: string, value: unknown): void {\n if (key === 'class' || key === 'className') {\n el.className = value as string;\n } else if (key === 'style' && typeof value === 'object' && value !== null) {\n Object.assign(el.style, value);\n } else if (key === 'innerHTML') {\n el.innerHTML = value as string;\n } else if (key === 'ref') {\n // Handled separately by component system\n } else if (key.startsWith('on')) {\n const event = key.slice(2).toLowerCase();\n el.addEventListener(event, value as EventListener);\n } else if (key in el) {\n (el as Record<string, unknown>)[key] = value;\n } else if (value === false || value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, value === true ? '' : String(value));\n }\n}\n\n// --- Reactive binding (used by compiler for dynamic expressions) ---\n\n/** Bind a reactive expression to a text node's content */\nexport function bindText(node: Text, fn: () => unknown): () => void {\n return effect(\n () => {\n node.textContent = String(fn());\n },\n { render: true },\n );\n}\n\n/** Bind a reactive expression to an element's attribute/property */\nexport function bindProperty(\n el: HTMLElement,\n key: string,\n fn: () => unknown,\n): () => void {\n return effect(\n () => {\n setProperty(el, key, fn());\n },\n { render: true },\n );\n}\n\n/** Bind a reactive expression to an element's visibility (display) */\nexport function bindVisible(el: HTMLElement, fn: () => boolean): () => void {\n return effect(\n () => {\n el.style.display = fn() ? '' : 'none';\n },\n { render: true },\n );\n}\n\n// --- Conditional rendering ---\n\n/** Anchor node type for marking insertion points */\ntype Anchor = Comment;\n\nfunction createAnchor(label = ''): Anchor {\n return document.createComment(label);\n}\n\ninterface ConditionalBlock {\n nodes: Node[];\n dispose: (() => void) | null;\n}\n\n/**\n * Render a conditional block. Swaps DOM fragments based on a reactive\n * condition. Used by the compiler for :if directives and <Show>.\n */\nexport function renderConditional(\n parent: Node,\n anchor: Node,\n condition: () => boolean,\n trueBranch: () => Node,\n falseBranch?: () => Node,\n): () => void {\n let current: ConditionalBlock | null = null;\n\n // Capture scope so children created in branches inherit provide/inject context\n const scope = getCurrentScope();\n\n const dispose = effect(\n () => {\n const value = condition();\n\n // Remove old nodes\n if (current) {\n for (const node of current.nodes) {\n try { node.parentNode?.removeChild(node); } catch {}\n }\n current.dispose?.();\n current = null;\n }\n\n // Insert new nodes — use anchor.parentNode since the anchor may have\n // moved from the initial DocumentFragment into the real DOM\n const branch = value ? trueBranch : falseBranch;\n const liveParent = anchor.parentNode;\n if (branch && liveParent) {\n const fragment = scope ? runInScope(scope, branch) : branch();\n const nodes = fragment instanceof DocumentFragment\n ? Array.from(fragment.childNodes)\n : [fragment];\n for (const node of nodes) {\n liveParent.insertBefore(node, anchor);\n }\n current = { nodes, dispose: null };\n }\n },\n { render: true },\n );\n\n return () => {\n dispose();\n if (current) {\n for (const node of current.nodes) {\n try { node.parentNode?.removeChild(node); } catch {}\n }\n current.dispose?.();\n }\n };\n}\n\n// --- List rendering ---\n\ninterface ListItem<T> {\n key: unknown;\n value: T;\n nodes: Node[];\n dispose: (() => void) | null;\n}\n\n/**\n * Render a reactive list with keyed reconciliation.\n * Used by the compiler for :for directives and <For>.\n */\nexport function renderList<T>(\n parent: Node,\n anchor: Node,\n items: () => T[],\n keyFn: (item: T, index: number) => unknown,\n renderItem: (item: T, index: number) => Node,\n): () => void {\n let currentItems: ListItem<T>[] = [];\n\n // Capture scope so children created in renderItem inherit provide/inject context\n const scope = getCurrentScope();\n\n const dispose = effect(\n () => {\n const newData = items();\n const newItems: ListItem<T>[] = [];\n const oldMap = new Map<unknown, ListItem<T>>();\n\n for (const item of currentItems) {\n oldMap.set(item.key, item);\n }\n\n // Build new list, reuse existing DOM nodes when keys match\n for (let i = 0; i < newData.length; i++) {\n const data = newData[i];\n const key = keyFn(data, i);\n const existing = oldMap.get(key);\n\n if (existing) {\n oldMap.delete(key);\n existing.value = data;\n newItems.push(existing);\n } else {\n const fragment = scope ? runInScope(scope, () => renderItem(data, i)) : renderItem(data, i);\n const nodes = fragment instanceof DocumentFragment\n ? Array.from(fragment.childNodes)\n : [fragment];\n newItems.push({ key, value: data, nodes, dispose: null });\n }\n }\n\n // Remove items that are no longer in the list\n for (const item of oldMap.values()) {\n for (const node of item.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node);\n }\n item.dispose?.();\n }\n\n // Reconcile DOM order — use anchor.parentNode since anchor may have\n // moved from the initial DocumentFragment into the real DOM\n const liveParent = anchor.parentNode;\n if (liveParent) {\n for (const item of newItems) {\n for (const node of item.nodes) {\n liveParent.insertBefore(node, anchor);\n }\n }\n }\n\n currentItems = newItems;\n },\n { render: true },\n );\n\n return () => {\n dispose();\n for (const item of currentItems) {\n for (const node of item.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node);\n }\n item.dispose?.();\n }\n currentItems = [];\n };\n}\n\n// --- Built-in control flow components ---\n\n/** Props for the <Show> component */\nexport interface ShowProps<T> {\n when: (() => T | null | undefined | false) | T | null | undefined | false;\n fallback?: () => AkashNode;\n children: (value: T) => AkashNode;\n}\n\n/**\n * <Show> component — conditionally renders children with type narrowing.\n * The children callback receives the non-null/undefined value.\n * `when` can be a reactive getter or a static value.\n */\nexport function Show<T>(props: ShowProps<T>): Node {\n const anchor = createAnchor('show');\n const container = document.createDocumentFragment();\n container.appendChild(anchor);\n\n // Resolve when — may be a getter (from compiler) or a static value\n const getWhen = typeof props.when === 'function'\n ? props.when as () => T | null | undefined | false\n : () => props.when as T | null | undefined | false;\n\n renderConditional(\n container,\n anchor,\n () => !!getWhen(),\n () => nodeToDOM(props.children(getWhen() as T)),\n props.fallback ? () => nodeToDOM(props.fallback!()) : undefined,\n );\n\n return container;\n}\n\n/** Props for the <For> component */\nexport interface ForProps<T> {\n each: (() => T[]) | T[];\n key: (item: T) => unknown;\n children: (item: T, index: number) => AkashNode;\n}\n\n/**\n * <For> component — renders a list with keyed reconciliation.\n * `each` can be a reactive getter or a static array.\n */\nexport function For<T>(props: ForProps<T>): Node {\n const anchor = createAnchor('for');\n const container = document.createDocumentFragment();\n container.appendChild(anchor);\n\n // Resolve each — may be a getter (from compiler) or a static array\n const getEach = typeof props.each === 'function'\n ? props.each as () => T[]\n : () => props.each as T[];\n\n renderList(\n container,\n anchor,\n getEach,\n props.key,\n (item, index) => nodeToDOM(props.children(item, index)),\n );\n\n return container;\n}\n\n// --- Helpers ---\n\n/** Convert an AkashNode to a DOM Node */\nexport function nodeToDOM(node: AkashNode): Node {\n if (node == null || typeof node === 'boolean') {\n return document.createTextNode('');\n }\n if (typeof node === 'string' || typeof node === 'number') {\n return document.createTextNode(String(node));\n }\n if (node instanceof Node) {\n return node;\n }\n if (Array.isArray(node)) {\n const fragment = document.createDocumentFragment();\n for (const child of node) {\n fragment.appendChild(nodeToDOM(child));\n }\n return fragment;\n }\n return document.createTextNode(String(node));\n}\n\n/** Insert a node into a parent before an anchor */\nexport function insert(parent: Node, node: AkashNode, anchor?: Node): void {\n const domNode = nodeToDOM(node);\n if (anchor) {\n parent.insertBefore(domNode, anchor);\n } else {\n parent.appendChild(domNode);\n }\n}\n","/**\n * Component system.\n *\n * Components are functions. defineComponent() wraps a setup function\n * that runs once, establishes signals and effects, and returns a\n * render function that produces DOM nodes.\n */\n\nimport { effect } from './signals.js';\nimport { pushScope, popScope, getCurrentScope } from './context.js';\nimport { nodeToDOM } from './dom.js';\nimport { akashError } from './errors.js';\nimport type { AkashNode } from './types.js';\n\n// --- Reactive getter marker (used by compiler) ---\n\n/** Mark a function as a compiler-generated reactive getter */\nexport function __getter<T>(fn: () => T): (() => T) & { __reactive: true } {\n (fn as any).__reactive = true;\n return fn as any;\n}\n\n// --- Types ---\n\nexport interface Ref<T = HTMLElement> {\n current: T | undefined;\n}\n\nexport interface ComponentContext<P extends Record<string, unknown> = Record<string, unknown>> {\n props: Readonly<P>;\n children: () => AkashNode;\n}\n\nexport type Component<P extends Record<string, unknown> = Record<string, unknown>> = {\n (props: P & { children?: AkashNode | (() => AkashNode) }): Node;\n _akash: true;\n};\n\n// --- Lifecycle hook storage ---\n\ninterface LifecycleHooks {\n mount: Array<() => void | (() => void)>;\n unmount: Array<() => void>;\n error: Array<(error: Error) => void>;\n}\n\nlet currentHooks: LifecycleHooks | null = null;\n\n// --- Public lifecycle hooks ---\n\n/**\n * Register a callback to run after the component is mounted to the DOM.\n * If the callback returns a function, it will be called on unmount (cleanup).\n */\nexport function onMount(fn: () => void | (() => void)): void {\n if (!currentHooks) {\n throw akashError('AK0020');\n }\n currentHooks.mount.push(fn);\n}\n\n/**\n * Register a callback to run before the component is unmounted.\n */\nexport function onUnmount(fn: () => void): void {\n if (!currentHooks) {\n throw akashError('AK0021');\n }\n currentHooks.unmount.push(fn);\n}\n\n/**\n * Register an error handler for this component and its descendants.\n */\nexport function onError(fn: (error: Error) => void): void {\n if (!currentHooks) {\n throw akashError('AK0022');\n }\n currentHooks.error.push(fn);\n}\n\n/**\n * Create a ref for accessing a DOM element.\n */\nexport function ref<T = HTMLElement>(): Ref<T> {\n return { current: undefined };\n}\n\n// --- defineComponent ---\n\n/**\n * Define a component. The setup function runs once per instance.\n * It receives a context with typed props and must return a render function.\n *\n * ```ts\n * const Counter = defineComponent<{ initial: number }>((ctx) => {\n * const count = signal(ctx.props.initial);\n * return () => <div>{count()}</div>;\n * });\n * ```\n */\nexport function defineComponent<P extends Record<string, unknown> = Record<string, unknown>>(\n setup: (ctx: ComponentContext<P>) => () => AkashNode,\n): Component<P> {\n const component = (rawProps: P & { children?: AkashNode | (() => AkashNode) }): Node => {\n // Separate children from props, unwrap getter functions for reactivity\n const { children: childrenProp, ...restProps } = rawProps ?? {};\n const props = new Proxy(restProps as unknown as P, {\n get(target, key, receiver) {\n const val = Reflect.get(target, key, receiver);\n // Unwrap compiler-generated reactive getters (marked with __reactive)\n if (typeof val === 'function' && (val as any).__reactive) {\n return val();\n }\n return val;\n },\n });\n\n const childrenFn: () => AkashNode =\n typeof childrenProp === 'function'\n ? childrenProp\n : () => childrenProp ?? null;\n\n const ctx: ComponentContext<P> = {\n props,\n children: childrenFn,\n };\n\n // Set up lifecycle hooks collector\n const hooks: LifecycleHooks = { mount: [], unmount: [], error: [] };\n const prevHooks = currentHooks;\n currentHooks = hooks;\n\n // Push context scope for provide/inject\n const parentScope = getCurrentScope();\n const scope = pushScope(parentScope);\n\n let renderFn: () => AkashNode;\n let domNode: Node;\n\n try {\n renderFn = setup(ctx);\n if (typeof renderFn !== 'function') { throw akashError('AK0040'); }\n const rendered = renderFn();\n domNode = nodeToDOM(rendered);\n } catch (err) {\n popScope(scope);\n currentHooks = prevHooks;\n if (hooks.error.length > 0) {\n for (const handler of hooks.error) {\n handler(err instanceof Error ? err : new Error(String(err)));\n }\n return document.createComment('error');\n }\n throw err;\n }\n\n // Restore parent state\n popScope(scope);\n currentHooks = prevHooks;\n\n // Run mount callbacks (microtask to ensure DOM is attached)\n if (hooks.mount.length > 0) {\n queueMicrotask(() => {\n for (const mountFn of hooks.mount) {\n try {\n const cleanup = mountFn();\n if (typeof cleanup === 'function') {\n hooks.unmount.push(cleanup);\n }\n } catch (err) {\n for (const handler of hooks.error) {\n handler(err instanceof Error ? err : new Error(String(err)));\n }\n }\n }\n });\n }\n\n return domNode;\n };\n\n component._akash = true as const;\n return component as Component<P>;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/context.ts","../src/dom.ts","../src/component.ts"],"names":["errors","DOC_BASE","formatError","code","context","def","msg","akashError","getErrorDef","getAllErrorCodes","CONTEXT_BRAND","currentScope","pushScope","parent","scope","popScope","getCurrentScope","runInScope","fn","prev","createContext","defaultValue","provide","key","value","inject","fallback","createElement","tag","attrs","el","setProperty","createText","cloneTemplate","html","template","event","bindText","node","effect","bindProperty","bindVisible","createAnchor","label","renderConditional","anchor","condition","trueBranch","falseBranch","current","dispose","branch","liveParent","fragment","nodes","renderList","items","keyFn","renderItem","currentItems","newData","newItems","oldMap","item","i","data","existing","Show","props","container","getWhen","nodeToDOM","For","getEach","index","child","insert","domNode","__getter","currentHooks","onMount","onUnmount","onError","ref","defineComponent","setup","component","rawProps","childrenProp","restProps","ctx","target","receiver","val","hooks","prevHooks","parentScope","renderFn","rendered","err","handler","mountFn","cleanup"],"mappings":"oCAqBA,IAA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CAAO,EAE9B,CAAA,MAASH,CAAAA,CAAK,CACZ,IAAA,IAAWC,CAAAA,IAAWN,CAAAA,CAAM,KAAA,CAC1BM,EAAQD,CAAAA,YAAe,KAAA,CAAQA,CAAAA,CAAM,IAAI,KAAA,CAAM,MAAA,CAAOA,CAAG,CAAC,CAAC,EAE/D,CAEJ,CAAC,CAAA,CAGItB,CACT,CAAA,CAEA,OAAAS,CAAAA,CAAU,MAAA,CAAS,KACZA,CACT","file":"chunk-SLMGQKLH.js","sourcesContent":["/**\n * Error message catalog.\n *\n * Every AkashJS runtime error has a unique code (AK0001, AK0002, etc.),\n * a one-line description, and a link to detailed documentation.\n *\n * Usage:\n * throw akashError('AK0010', 'provide()');\n */\n\n// --- Error registry ---\n\nexport interface ErrorDef {\n /** Error code */\n code: string;\n /** Short description */\n message: string;\n /** Extended explanation and fix suggestion */\n hint: string;\n}\n\nconst errors: Record<string, ErrorDef> = {\n // --- Context errors (AK001x) ---\n AK0010: {\n code: 'AK0010',\n message: 'provide() called outside of component setup.',\n hint: 'provide() must be called inside defineComponent().',\n },\n AK0012: {\n code: 'AK0012',\n message: 'inject() called outside of component setup.',\n hint: 'inject() must be called inside defineComponent().',\n },\n AK0013: {\n code: 'AK0013',\n message: 'No provider found for injected context.',\n hint: 'Make sure an ancestor component calls provide() with this key.',\n },\n\n // --- Lifecycle errors (AK002x) ---\n AK0020: {\n code: 'AK0020',\n message: 'onMount() called outside of component setup.',\n hint: 'onMount() must be called inside defineComponent().',\n },\n AK0021: {\n code: 'AK0021',\n message: 'onUnmount() called outside of component setup.',\n hint: 'onUnmount() must be called inside defineComponent().',\n },\n AK0022: {\n code: 'AK0022',\n message: 'onError() called outside of component setup.',\n hint: 'onError() must be called inside defineComponent().',\n },\n\n // --- Signal errors (AK003x) ---\n AK0030: {\n code: 'AK0030',\n message: 'Circular dependency detected in computed signal.',\n hint: 'A computed signal is reading itself, directly or via other computeds.',\n },\n AK0031: {\n code: 'AK0031',\n message: 'Signal set() called during computation.',\n hint: 'Do not set signals inside computed() or during effect execution. Use batch() or set signals in event handlers.',\n },\n\n // --- Component errors (AK004x) ---\n AK0040: {\n code: 'AK0040',\n message: 'Component setup must return a render function.',\n hint: 'The function passed to defineComponent() must return () => AkashNode.',\n },\n AK0041: {\n code: 'AK0041',\n message: 'Required prop is missing.',\n hint: 'Check that the parent component is passing all required props.',\n },\n\n // --- Router errors (AK005x) ---\n AK0050: {\n code: 'AK0050',\n message: 'useRoute() called outside of router context.',\n hint: 'Make sure your component is rendered inside a router provider.',\n },\n AK0051: {\n code: 'AK0051',\n message: 'No route matched the current URL.',\n hint: 'Add a catch-all route ([...rest]) to handle unmatched paths.',\n },\n AK0052: {\n code: 'AK0052',\n message: 'Route guard threw an error.',\n hint: 'Check the guard function for unhandled exceptions.',\n },\n\n // --- Form errors (AK006x) ---\n AK0060: {\n code: 'AK0060',\n message: 'Form submitted while invalid.',\n hint: 'The submit handler was not called because validation failed. Check form.errors().',\n },\n AK0061: {\n code: 'AK0061',\n message: 'Async validator timed out.',\n hint: 'The async validator did not resolve within the expected time. Check your async validation logic.',\n },\n\n // --- HTTP errors (AK007x) ---\n AK0070: {\n code: 'AK0070',\n message: 'HTTP request failed.',\n hint: 'Check the server response status and network connectivity.',\n },\n AK0071: {\n code: 'AK0071',\n message: 'createResource() fetcher threw an error.',\n hint: 'Check the fetcher function passed to createResource().',\n },\n};\n\n// --- Public API ---\n\nconst DOC_BASE = 'https://akashjs.dev/errors';\n\n/**\n * Format an AkashJS error with code, message, hint, and doc link.\n */\nexport function formatError(code: string, context?: string): string {\n const def = errors[code];\n if (!def) {\n return `[AkashJS ${code}] Unknown error code.`;\n }\n\n let msg = `[AkashJS ${code}] ${def.message}`;\n if (context) {\n msg += `\\n ${context}`;\n }\n msg += `\\n ${def.hint}`;\n msg += `\\n See: ${DOC_BASE}/${code}`;\n return msg;\n}\n\n/**\n * Create and throw an AkashJS error.\n */\nexport function akashError(code: string, context?: string): Error {\n return new Error(formatError(code, context));\n}\n\n/**\n * Get the error definition for a code.\n */\nexport function getErrorDef(code: string): ErrorDef | undefined {\n return errors[code];\n}\n\n/**\n * Get all registered error codes.\n */\nexport function getAllErrorCodes(): string[] {\n return Object.keys(errors);\n}\n","/**\n * Lightweight dependency injection via provide/inject.\n *\n * Context is scoped to the component tree — no injector hierarchy,\n * no decorators, no classes. Just createContext(), provide(), inject().\n */\n\n// --- Types ---\n\nimport { akashError } from './errors.js';\n\nconst CONTEXT_BRAND = Symbol('akash.context');\n\nexport interface InjectionKey<T> {\n readonly [CONTEXT_BRAND]: true;\n readonly _type: T; // phantom type — never used at runtime\n readonly defaultValue: T | undefined;\n readonly id: symbol;\n}\n\n// --- Context stack (managed by component system) ---\n\ninterface ContextScope {\n values: Map<symbol, unknown>;\n parent: ContextScope | null;\n}\n\nlet currentScope: ContextScope | null = null;\n\n/** @internal — called by defineComponent to push/pop context scopes */\nexport function pushScope(parent: ContextScope | null = currentScope): ContextScope {\n const scope: ContextScope = { values: new Map(), parent };\n currentScope = scope;\n return scope;\n}\n\n/** @internal */\nexport function popScope(scope: ContextScope): void {\n currentScope = scope.parent;\n}\n\n/** @internal */\nexport function getCurrentScope(): ContextScope | null {\n return currentScope;\n}\n\n/**\n * Run a function within a given scope so that provide/inject\n * work correctly for components created asynchronously\n * (e.g., lazy-loaded route components).\n */\nexport function runInScope<T>(scope: ContextScope, fn: () => T): T {\n const prev = currentScope;\n currentScope = scope;\n try {\n return fn();\n } finally {\n currentScope = prev;\n }\n}\n\n// --- Public API ---\n\n/**\n * Create a typed context key with an optional default value.\n *\n * ```ts\n * const ThemeContext = createContext<'light' | 'dark'>('light');\n * ```\n */\nexport function createContext<T>(defaultValue?: T): InjectionKey<T> {\n return {\n [CONTEXT_BRAND]: true,\n _type: undefined as T,\n defaultValue,\n id: Symbol('context'),\n };\n}\n\n/**\n * Provide a value for a context key in the current component scope.\n * All descendant components can inject() this value.\n *\n * Must be called inside defineComponent() setup.\n */\nexport function provide<T>(key: InjectionKey<T>, value: T): void {\n if (!currentScope) {\n throw akashError('AK0010');\n }\n currentScope.values.set(key.id, value);\n}\n\n/**\n * Inject a value from the nearest ancestor that provided it.\n *\n * Must be called inside defineComponent() setup.\n */\nexport function inject<T>(key: InjectionKey<T>): T;\nexport function inject<T>(key: InjectionKey<T>, fallback: T): T;\nexport function inject<T>(key: InjectionKey<T>, fallback?: T): T {\n if (!currentScope) {\n throw akashError('AK0012');\n }\n\n // Walk up the scope chain\n let scope: ContextScope | null = currentScope;\n while (scope) {\n if (scope.values.has(key.id)) {\n return scope.values.get(key.id) as T;\n }\n scope = scope.parent;\n }\n\n // Check fallback, then default\n if (fallback !== undefined) return fallback;\n if (key.defaultValue !== undefined) return key.defaultValue;\n\n throw akashError('AK0013');\n}\n","/**\n * Direct DOM rendering runtime.\n *\n * No virtual DOM. The compiler generates calls to these helpers.\n * Signal reads inside templates become fine-grained effects that\n * update only the specific DOM node that changed.\n */\n\nimport { effect } from './signals.js';\nimport { getCurrentScope, runInScope } from './context.js';\nimport type { AkashNode } from './types.js';\n\n// --- DOM creation helpers (used by compiler output) ---\n\n/** Create an element and optionally set static attributes */\nexport function createElement(\n tag: string,\n attrs?: Record<string, unknown>,\n): HTMLElement {\n const el = document.createElement(tag);\n if (attrs) {\n for (const [key, value] of Object.entries(attrs)) {\n setProperty(el, key, value);\n }\n }\n return el;\n}\n\n/** Create a text node */\nexport function createText(value: string): Text {\n return document.createTextNode(value);\n}\n\n/** Clone a template element for static structure */\nexport function cloneTemplate(html: string): DocumentFragment {\n const template = document.createElement('template');\n template.innerHTML = html;\n return template.content.cloneNode(true) as DocumentFragment;\n}\n\n// --- Property/attribute setting ---\n\nexport function setProperty(el: HTMLElement, key: string, value: unknown): void {\n if (key === 'class' || key === 'className') {\n el.className = value as string;\n } else if (key === 'style' && typeof value === 'object' && value !== null) {\n Object.assign(el.style, value);\n } else if (key === 'innerHTML') {\n el.innerHTML = value as string;\n } else if (key === 'ref') {\n // Handled separately by component system\n } else if (key.startsWith('on')) {\n const event = key.slice(2).toLowerCase();\n el.addEventListener(event, value as EventListener);\n } else if (key in el) {\n (el as Record<string, unknown>)[key] = value;\n } else if (value === false || value == null) {\n el.removeAttribute(key);\n } else {\n el.setAttribute(key, value === true ? '' : String(value));\n }\n}\n\n// --- Reactive binding (used by compiler for dynamic expressions) ---\n\n/** Bind a reactive expression to a text node's content */\nexport function bindText(node: Text, fn: () => unknown): () => void {\n return effect(\n () => {\n node.textContent = String(fn());\n },\n { render: true },\n );\n}\n\n/** Bind a reactive expression to an element's attribute/property */\nexport function bindProperty(\n el: HTMLElement,\n key: string,\n fn: () => unknown,\n): () => void {\n return effect(\n () => {\n setProperty(el, key, fn());\n },\n { render: true },\n );\n}\n\n/** Bind a reactive expression to an element's visibility (display) */\nexport function bindVisible(el: HTMLElement, fn: () => boolean): () => void {\n return effect(\n () => {\n el.style.display = fn() ? '' : 'none';\n },\n { render: true },\n );\n}\n\n// --- Conditional rendering ---\n\n/** Anchor node type for marking insertion points */\ntype Anchor = Comment;\n\nfunction createAnchor(label = ''): Anchor {\n return document.createComment(label);\n}\n\ninterface ConditionalBlock {\n nodes: Node[];\n dispose: (() => void) | null;\n}\n\n/**\n * Render a conditional block. Swaps DOM fragments based on a reactive\n * condition. Used by the compiler for :if directives and <Show>.\n */\nexport function renderConditional(\n parent: Node,\n anchor: Node,\n condition: () => boolean,\n trueBranch: () => Node,\n falseBranch?: () => Node,\n): () => void {\n let current: ConditionalBlock | null = null;\n\n // Capture scope so children created in branches inherit provide/inject context\n const scope = getCurrentScope();\n\n const dispose = effect(\n () => {\n const value = condition();\n\n // Remove old nodes\n if (current) {\n for (const node of current.nodes) {\n try { node.parentNode?.removeChild(node); } catch {}\n }\n current.dispose?.();\n current = null;\n }\n\n // Insert new nodes — use anchor.parentNode since the anchor may have\n // moved from the initial DocumentFragment into the real DOM\n const branch = value ? trueBranch : falseBranch;\n const liveParent = anchor.parentNode;\n if (branch && liveParent) {\n const fragment = scope ? runInScope(scope, branch) : branch();\n const nodes = fragment instanceof DocumentFragment\n ? Array.from(fragment.childNodes)\n : [fragment];\n for (const node of nodes) {\n liveParent.insertBefore(node, anchor);\n }\n current = { nodes, dispose: null };\n }\n },\n { render: true },\n );\n\n return () => {\n dispose();\n if (current) {\n for (const node of current.nodes) {\n try { node.parentNode?.removeChild(node); } catch {}\n }\n current.dispose?.();\n }\n };\n}\n\n// --- List rendering ---\n\ninterface ListItem<T> {\n key: unknown;\n value: T;\n nodes: Node[];\n dispose: (() => void) | null;\n}\n\n/**\n * Render a reactive list with keyed reconciliation.\n * Used by the compiler for :for directives and <For>.\n */\nexport function renderList<T>(\n parent: Node,\n anchor: Node,\n items: () => T[],\n keyFn: (item: T, index: number) => unknown,\n renderItem: (item: T, index: number) => Node,\n): () => void {\n let currentItems: ListItem<T>[] = [];\n\n // Capture scope so children created in renderItem inherit provide/inject context\n const scope = getCurrentScope();\n\n const dispose = effect(\n () => {\n const newData = items();\n const newItems: ListItem<T>[] = [];\n const oldMap = new Map<unknown, ListItem<T>>();\n\n for (const item of currentItems) {\n oldMap.set(item.key, item);\n }\n\n // Build new list, reuse existing DOM nodes when keys match\n for (let i = 0; i < newData.length; i++) {\n const data = newData[i];\n const key = keyFn(data, i);\n const existing = oldMap.get(key);\n\n if (existing) {\n oldMap.delete(key);\n existing.value = data;\n newItems.push(existing);\n } else {\n const fragment = scope ? runInScope(scope, () => renderItem(data, i)) : renderItem(data, i);\n const nodes = fragment instanceof DocumentFragment\n ? Array.from(fragment.childNodes)\n : [fragment];\n newItems.push({ key, value: data, nodes, dispose: null });\n }\n }\n\n // Remove items that are no longer in the list\n for (const item of oldMap.values()) {\n for (const node of item.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node);\n }\n item.dispose?.();\n }\n\n // Reconcile DOM order — use anchor.parentNode since anchor may have\n // moved from the initial DocumentFragment into the real DOM\n const liveParent = anchor.parentNode;\n if (liveParent) {\n for (const item of newItems) {\n for (const node of item.nodes) {\n liveParent.insertBefore(node, anchor);\n }\n }\n }\n\n currentItems = newItems;\n },\n { render: true },\n );\n\n return () => {\n dispose();\n for (const item of currentItems) {\n for (const node of item.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node);\n }\n item.dispose?.();\n }\n currentItems = [];\n };\n}\n\n// --- Built-in control flow components ---\n\n/** Props for the <Show> component */\nexport interface ShowProps<T> {\n when: (() => T | null | undefined | false) | T | null | undefined | false;\n fallback?: () => AkashNode;\n children: (value: T) => AkashNode;\n}\n\n/**\n * <Show> component — conditionally renders children with type narrowing.\n * The children callback receives the non-null/undefined value.\n * `when` can be a reactive getter or a static value.\n */\nexport function Show<T>(props: ShowProps<T>): Node {\n const anchor = createAnchor('show');\n const container = document.createDocumentFragment();\n container.appendChild(anchor);\n\n // Resolve when — may be a getter (from compiler) or a static value\n const getWhen = typeof props.when === 'function'\n ? props.when as () => T | null | undefined | false\n : () => props.when as T | null | undefined | false;\n\n renderConditional(\n container,\n anchor,\n () => !!getWhen(),\n () => nodeToDOM(props.children(getWhen() as T)),\n props.fallback ? () => nodeToDOM(props.fallback!()) : undefined,\n );\n\n return container;\n}\n\n/** Props for the <For> component */\nexport interface ForProps<T> {\n each: (() => T[]) | T[];\n key: (item: T) => unknown;\n children: (item: T, index: number) => AkashNode;\n}\n\n/**\n * <For> component — renders a list with keyed reconciliation.\n * `each` can be a reactive getter or a static array.\n */\nexport function For<T>(props: ForProps<T>): Node {\n const anchor = createAnchor('for');\n const container = document.createDocumentFragment();\n container.appendChild(anchor);\n\n // Resolve each — may be a getter (from compiler) or a static array\n const getEach = typeof props.each === 'function'\n ? props.each as () => T[]\n : () => props.each as T[];\n\n renderList(\n container,\n anchor,\n getEach,\n props.key,\n (item, index) => nodeToDOM(props.children(item, index)),\n );\n\n return container;\n}\n\n// --- Helpers ---\n\n/** Convert an AkashNode to a DOM Node */\nexport function nodeToDOM(node: AkashNode): Node {\n if (node == null || typeof node === 'boolean') {\n return document.createTextNode('');\n }\n if (typeof node === 'string' || typeof node === 'number') {\n return document.createTextNode(String(node));\n }\n if (node instanceof Node) {\n return node;\n }\n if (Array.isArray(node)) {\n const fragment = document.createDocumentFragment();\n for (const child of node) {\n fragment.appendChild(nodeToDOM(child));\n }\n return fragment;\n }\n return document.createTextNode(String(node));\n}\n\n/** Insert a node into a parent before an anchor */\nexport function insert(parent: Node, node: AkashNode, anchor?: Node): void {\n const domNode = nodeToDOM(node);\n if (anchor) {\n parent.insertBefore(domNode, anchor);\n } else {\n parent.appendChild(domNode);\n }\n}\n","/**\n * Component system.\n *\n * Components are functions. defineComponent() wraps a setup function\n * that runs once, establishes signals and effects, and returns a\n * render function that produces DOM nodes.\n */\n\nimport { effect } from './signals.js';\nimport { pushScope, popScope, getCurrentScope } from './context.js';\nimport { nodeToDOM } from './dom.js';\nimport { akashError } from './errors.js';\nimport type { AkashNode } from './types.js';\n\n// --- Reactive getter marker (used by compiler) ---\n\n/** Mark a function as a compiler-generated reactive getter */\nexport function __getter<T>(fn: () => T): (() => T) & { __reactive: true } {\n (fn as any).__reactive = true;\n return fn as any;\n}\n\n// --- Types ---\n\nexport interface Ref<T = HTMLElement> {\n current: T | undefined;\n}\n\nexport interface ComponentContext<P extends Record<string, unknown> = Record<string, unknown>> {\n props: Readonly<P>;\n children: () => AkashNode;\n}\n\nexport type Component<P extends Record<string, unknown> = Record<string, unknown>> = {\n (props: P & { children?: AkashNode | (() => AkashNode) }): Node;\n _akash: true;\n};\n\n// --- Lifecycle hook storage ---\n\ninterface LifecycleHooks {\n mount: Array<() => void | (() => void)>;\n unmount: Array<() => void>;\n error: Array<(error: Error) => void>;\n}\n\nlet currentHooks: LifecycleHooks | null = null;\n\n// --- Public lifecycle hooks ---\n\n/**\n * Register a callback to run after the component is mounted to the DOM.\n * If the callback returns a function, it will be called on unmount (cleanup).\n */\nexport function onMount(fn: () => void | (() => void)): void {\n if (!currentHooks) {\n throw akashError('AK0020');\n }\n currentHooks.mount.push(fn);\n}\n\n/**\n * Register a callback to run before the component is unmounted.\n */\nexport function onUnmount(fn: () => void): void {\n if (!currentHooks) {\n throw akashError('AK0021');\n }\n currentHooks.unmount.push(fn);\n}\n\n/**\n * Register an error handler for this component and its descendants.\n */\nexport function onError(fn: (error: Error) => void): void {\n if (!currentHooks) {\n throw akashError('AK0022');\n }\n currentHooks.error.push(fn);\n}\n\n/**\n * Create a ref for accessing a DOM element.\n */\nexport function ref<T = HTMLElement>(): Ref<T> {\n return { current: undefined };\n}\n\n// --- defineComponent ---\n\n/**\n * Define a component. The setup function runs once per instance.\n * It receives a context with typed props and must return a render function.\n *\n * ```ts\n * const Counter = defineComponent<{ initial: number }>((ctx) => {\n * const count = signal(ctx.props.initial);\n * return () => <div>{count()}</div>;\n * });\n * ```\n */\nexport function defineComponent<P extends Record<string, unknown> = Record<string, unknown>>(\n setup: (ctx: ComponentContext<P>) => () => AkashNode,\n): Component<P> {\n const component = (rawProps: P & { children?: AkashNode | (() => AkashNode) }): Node => {\n // Separate children from props, unwrap getter functions for reactivity\n const { children: childrenProp, ...restProps } = rawProps ?? {};\n const props = new Proxy(restProps as unknown as P, {\n get(target, key, receiver) {\n const val = Reflect.get(target, key, receiver);\n // Unwrap compiler-generated reactive getters (marked with __reactive)\n if (typeof val === 'function' && (val as any).__reactive) {\n return val();\n }\n return val;\n },\n });\n\n const childrenFn: () => AkashNode =\n typeof childrenProp === 'function'\n ? childrenProp\n : () => childrenProp ?? null;\n\n const ctx: ComponentContext<P> = {\n props,\n children: childrenFn,\n };\n\n // Set up lifecycle hooks collector\n const hooks: LifecycleHooks = { mount: [], unmount: [], error: [] };\n const prevHooks = currentHooks;\n currentHooks = hooks;\n\n // Push context scope for provide/inject\n const parentScope = getCurrentScope();\n const scope = pushScope(parentScope);\n\n let renderFn: () => AkashNode;\n let domNode: Node;\n\n try {\n renderFn = setup(ctx);\n if (typeof renderFn !== 'function') { throw akashError('AK0040'); }\n const rendered = renderFn();\n domNode = nodeToDOM(rendered);\n } catch (err) {\n popScope(scope);\n currentHooks = prevHooks;\n if (hooks.error.length > 0) {\n for (const handler of hooks.error) {\n handler(err instanceof Error ? err : new Error(String(err)));\n }\n return document.createComment('error');\n }\n throw err;\n }\n\n // Restore parent state\n popScope(scope);\n currentHooks = prevHooks;\n\n // Run mount callbacks (microtask to ensure DOM is attached)\n if (hooks.mount.length > 0) {\n queueMicrotask(() => {\n for (const mountFn of hooks.mount) {\n try {\n const cleanup = mountFn();\n if (typeof cleanup === 'function') {\n hooks.unmount.push(cleanup);\n }\n } catch (err) {\n for (const handler of hooks.error) {\n handler(err instanceof Error ? err : new Error(String(err)));\n }\n }\n }\n });\n }\n\n return domNode;\n };\n\n component._akash = true as const;\n return component as Component<P>;\n}\n"]}