atmx-web 0.83.0 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/atmx.es.js CHANGED
@@ -326,7 +326,7 @@ function T(e, t, n) {
326
326
  let p = String(s);
327
327
  d && (p = String(x(d, t, c)));
328
328
  let m = u.find((e) => e.getAttribute("data-ax-key") === p);
329
- m || (m = e.cloneNode(!0), m.removeAttribute("ax-for"), m.style.removeProperty("display"), m.style.length === 0 && m.removeAttribute("style"), m.setAttribute("data-ax-clone-of", r), m.setAttribute("data-ax-key", p)), l.insertBefore(m, e), w(m, t, !1, c), f.push(m);
329
+ m || (m = e.cloneNode(!0), m.removeAttribute("ax-for"), m.style.removeProperty("display"), m.style.length === 0 && m.removeAttribute("style"), m.setAttribute("data-ax-clone-of", r), m.setAttribute("data-ax-key", p)), l.insertBefore(m, e), w(m, t, !0, c), f.push(m);
330
330
  }), u.forEach((e) => {
331
331
  f.includes(e) || e.remove();
332
332
  });
@@ -369,7 +369,19 @@ var A = 0, j = class {
369
369
  listeners = /* @__PURE__ */ new Set();
370
370
  currentReqId = null;
371
371
  constructor(e, t, n) {
372
- this.key = e, this.route = t, this.args = n, this.state = {
372
+ this.key = e, this.route = t, this.args = n;
373
+ let r = null;
374
+ try {
375
+ let t = sessionStorage.getItem(`atmx_cache_${e}`);
376
+ t && (r = JSON.parse(t));
377
+ } catch {}
378
+ r ? this.state = {
379
+ state: "data",
380
+ isFetching: !1,
381
+ source: "cache",
382
+ data: r,
383
+ error: null
384
+ } : this.state = {
373
385
  state: "idle",
374
386
  isFetching: !1,
375
387
  source: null,
@@ -381,10 +393,13 @@ var A = 0, j = class {
381
393
  this.listeners.add(e), e(this.state);
382
394
  }
383
395
  update(e) {
384
- this.state = {
396
+ if (this.state = {
385
397
  ...this.state,
386
398
  ...e
387
- }, this.listeners.forEach((e) => e(this.state));
399
+ }, this.state.data) try {
400
+ sessionStorage.setItem(`atmx_cache_${this.key}`, JSON.stringify(this.state.data));
401
+ } catch {}
402
+ this.listeners.forEach((e) => e(this.state));
388
403
  }
389
404
  fetch(n = !1) {
390
405
  if (this.state.isFetching && !n) return;
@@ -396,14 +411,10 @@ var A = 0, j = class {
396
411
  let r = ++A;
397
412
  this.currentReqId = r;
398
413
  let { path: i, remainingArgs: a } = o(this.route, this.args), s = new Uint8Array();
399
- Object.keys(a).length > 0 && (s = new TextEncoder().encode(JSON.stringify(a))), q.debug && (console.groupCollapsed(`%c➔ WASM QUERY [#${r}]`, "color: #7c3aed; font-weight: bold;"), console.log("Namespace:", this.route.namespace), console.log("Endpoint ID:", this.route.id), console.log("Path:", i), console.groupEnd()), t.set(r, {
414
+ Object.keys(a).length > 0 && (s = new TextEncoder().encode(JSON.stringify(a))), J.debug && (console.groupCollapsed(`%c➔ WASM QUERY [#${r}]`, "color: #7c3aed; font-weight: bold;"), console.log("Namespace:", this.route.namespace), console.log("Endpoint ID:", this.route.id), console.log("Path:", i), console.groupEnd()), t.set(r, {
400
415
  isStream: this.route.isStream,
401
416
  onResponse: (t) => {
402
417
  if (this.currentReqId === r) {
403
- if (q.debug) {
404
- let e = t.eventType === 1 ? "NetworkSuccess" : t.eventType === 2 ? "CacheHit" : t.eventType === 3 ? "CacheHitAndFetching" : t.eventType === 4 ? "Error" : "Complete";
405
- console.groupCollapsed(`%c← WASM RESP [#${r}]`, "color: #059669; font-weight: bold;"), console.log("Event Type:", e), t.data && console.log("Data:", t.data), t.error && console.log("Error:", t.error), console.groupEnd();
406
- }
407
418
  if (t.eventType === e.Error) {
408
419
  this.update({
409
420
  state: "error",
@@ -424,7 +435,7 @@ var A = 0, j = class {
424
435
  }
425
436
  },
426
437
  onComplete: () => {
427
- this.currentReqId === r && (q.debug && console.log(`%c✔ Stream Complete [#${r}]`, "color: #94a3b8;"), this.update({ isFetching: !1 }));
438
+ this.currentReqId === r && this.update({ isFetching: !1 });
428
439
  }
429
440
  });
430
441
  let c = p(this.route.namespace), l = p(this.route.method), d = p(i), m = f(s), h = p(""), g = p("");
@@ -436,7 +447,7 @@ function P(e, t) {
436
447
  e.hasAttribute(n) && S(e.getAttribute(n), D(e));
437
448
  }
438
449
  function F(e, t, n) {
439
- if (!q.debug) return;
450
+ if (!J.debug) return;
440
451
  let r = e === "OUT" ? "#7c3aed" : "#059669";
441
452
  console.groupCollapsed(`%c${e === "OUT" ? "➔ WASM CALL" : "← WASM RESP"} [#${t}]`, `color: ${r}; font-weight: bold;`), console.log("Details:", n), console.groupEnd();
442
453
  }
@@ -470,7 +481,7 @@ function L(e) {
470
481
  });
471
482
  return;
472
483
  }
473
- let i = `${r.namespace}:${r.id}:${JSON.stringify(n.args)}`, o = M.get(i);
484
+ let i = `${n.target}:${JSON.stringify(n.args)}`, o = M.get(i);
474
485
  o || (o = new j(i, r, n.args), M.set(i, o)), e._axListener || (e._axListener = (t) => {
475
486
  k(e, t), (t.state === "data" || t.state === "error") && (P(e, t.state), e.dispatchEvent(new CustomEvent(`atmx:${t.state}`, {
476
487
  bubbles: !0,
@@ -539,7 +550,7 @@ function z(e, n, r, i, a, o, s, c, l = {}, d = !1) {
539
550
  isStream: s,
540
551
  onResponse: (t) => B(e, t, c, m),
541
552
  onComplete: () => {
542
- q.debug && console.log(`%c✔ Stream Complete [#${m}]`, "color: #94a3b8;");
553
+ J.debug && console.log(`%c✔ Stream Complete [#${m}]`, "color: #94a3b8;");
543
554
  }
544
555
  });
545
556
  let h = p(n), g = p(i), _ = p(a), v = p(""), y = p(Object.keys(l).length > 0 ? JSON.stringify(l) : ""), b = f(o);
@@ -579,7 +590,7 @@ function B(t, n, r, i) {
579
590
  if (n) {
580
591
  let e = a(I(t, t.getAttribute("ax-mutate")).target)?.namespace || "default", r = t.getAttribute("ax-token-target");
581
592
  (r ? r.split(",").map((e) => e.trim()) : [e]).forEach((e) => {
582
- q.setNamespaceAuthToken(e, n);
593
+ J.setNamespaceAuthToken(e, n);
583
594
  });
584
595
  }
585
596
  }
@@ -613,6 +624,25 @@ function H(e) {
613
624
  });
614
625
  }
615
626
  function U(e = document) {
627
+ H(e), e.querySelectorAll("[ax-query]").forEach((e) => {
628
+ let t = e, n = t.getAttribute("ax-query");
629
+ if (!n) return;
630
+ let r = I(t, n);
631
+ if (r) {
632
+ let e = `${r.target}:${JSON.stringify(r.args)}`;
633
+ try {
634
+ let n = sessionStorage.getItem(`atmx_cache_${e}`);
635
+ n && k(t, {
636
+ state: "data",
637
+ data: JSON.parse(n),
638
+ source: "cache",
639
+ isFetching: !0
640
+ });
641
+ } catch {}
642
+ }
643
+ });
644
+ }
645
+ function W(e = document) {
616
646
  H(e), e.querySelectorAll("[ax-query]").forEach((e) => {
617
647
  let t = e;
618
648
  k(t, {});
@@ -634,22 +664,19 @@ function U(e = document) {
634
664
  let n = t.closest("[ax-query]");
635
665
  if (n) {
636
666
  let e = I(n, n.getAttribute("ax-query"));
637
- if (e) {
638
- let t = a(e.target);
639
- if (t) {
640
- let r = `${t.namespace}:${t.id}:${JSON.stringify(e.args)}`, i = M.get(r);
641
- i ? i.fetch(!0) : L(n);
642
- }
667
+ if (e && a(e.target)) {
668
+ let t = `${e.target}:${JSON.stringify(e.args)}`, r = M.get(t);
669
+ r ? r.fetch(!0) : L(n);
643
670
  }
644
671
  }
645
672
  });
646
673
  });
647
674
  }
648
- function W() {
675
+ function G() {
649
676
  new MutationObserver((e) => {
650
677
  e.forEach((e) => {
651
678
  e.addedNodes.forEach((e) => {
652
- e instanceof HTMLElement && U(e);
679
+ e instanceof HTMLElement && W(e);
653
680
  });
654
681
  });
655
682
  }).observe(document.body, {
@@ -659,7 +686,7 @@ function W() {
659
686
  }
660
687
  //#endregion
661
688
  //#region src/dom/components/engine-status.ts
662
- var G = class extends HTMLElement {
689
+ var K = class extends HTMLElement {
663
690
  constructor() {
664
691
  super();
665
692
  }
@@ -680,11 +707,11 @@ var G = class extends HTMLElement {
680
707
  }) : (this.innerText = t, this.getAttribute("class") || (this.className = `text-xs font-bold ${n}`));
681
708
  }
682
709
  };
683
- typeof window < "u" && !customElements.get("ax-engine-status") && customElements.define("ax-engine-status", G);
710
+ typeof window < "u" && !customElements.get("ax-engine-status") && customElements.define("ax-engine-status", K);
684
711
  //#endregion
685
712
  //#region src/index.ts
686
- var K = "0.83.0", q = new class {
687
- version = K;
713
+ var q = "0.85.0", J = new class {
714
+ version = q;
688
715
  initialized = !1;
689
716
  debug = !1;
690
717
  async init(e) {
@@ -694,7 +721,11 @@ var K = "0.83.0", q = new class {
694
721
  initDurationMs: 0
695
722
  };
696
723
  let t = await h(e);
697
- return t.ok ? (this.debug = e.debug || !1, W(), U(document.body), this.initialized = !0, this.debug && console.log("%c🚀 ATMX Debug Mode: Enabled", "color: #2563eb; font-weight: bold;"), console.log(`✅ ATMX v${this.version} Online (${t.initDurationMs}ms). Reactive Engine Started.`), document.dispatchEvent(new CustomEvent("atmx:ready", { detail: t }))) : (console.error("❌ ATMX Initialization Failed:", t.error), document.dispatchEvent(new CustomEvent("atmx:error", { detail: t.error }))), t;
724
+ return t.ok ? (this.debug = e.debug || !1, G(), W(document.body), this.initialized = !0, this.debug && console.log("%c🚀 ATMX Debug Mode: Enabled", "color: #2563eb; font-weight: bold;"), console.log(`✅ ATMX v${this.version} Online (${t.initDurationMs}ms). Reactive Engine Started.`), document.dispatchEvent(new CustomEvent("atmx:ready", { detail: t }))) : (console.error("❌ ATMX Initialization Failed:", t.error), document.dispatchEvent(new CustomEvent("atmx:error", { detail: t.error }))), t;
725
+ }
726
+ hydrate(e) {
727
+ let t = document;
728
+ e && (t = typeof e == "string" ? document.querySelector(e) : e), t && U(t);
698
729
  }
699
730
  triggerQuery(e) {
700
731
  let t = typeof e == "string" ? document.querySelector(e) : e;
@@ -743,6 +774,6 @@ var K = "0.83.0", q = new class {
743
774
  o && o.currentReqId ? y(o.currentReqId, t) : console.warn(`ATMX: Cannot send message, stream not active for ${e}`);
744
775
  }
745
776
  }();
746
- typeof window < "u" && (window.atmx = q);
777
+ typeof window < "u" && (window.atmx = J);
747
778
  //#endregion
748
- export { K as ATMX_VERSION, f as allocBytes, p as allocString, q as atmx, o as buildRequestPath, v as clearAuthToken, h as initWasm, t as pendingRequests, a as resolveRoute, y as sendStreamMessage, g as setAuthToken, b as setGlobalAuthToken, u as wasmEngine };
779
+ export { q as ATMX_VERSION, f as allocBytes, p as allocString, J as atmx, o as buildRequestPath, v as clearAuthToken, h as initWasm, t as pendingRequests, a as resolveRoute, y as sendStreamMessage, g as setAuthToken, b as setGlobalAuthToken, u as wasmEngine };
package/dist/atmx.umd.js CHANGED
@@ -884,4 +884,4 @@
884
884
  return Object.assign(__wbg_init, { initSync }, exports);
885
885
  })({ __proto__: null });
886
886
  `,d=null,f=`atmx_auth_store`;function p(e){if(e.length===0)return 0;let t=d.axiom_malloc(e.length);return new Uint8Array(d.memory.buffer).set(e,t),t}function m(e){if(!e)return{ptr:0,len:0};let t=new TextEncoder().encode(e);return{ptr:p(t),len:t.length}}function h(){return`https://atmx.axiomcore.dev/latest/axiom_runtime.wasm`}async function g(e){let t=performance.now(),n={ok:!1,contracts:{},initDurationMs:0};try{if(!window.wasm_bindgen){let e=document.createElement(`script`);e.type=`text/javascript`,e.text=`${u}\nwindow.wasm_bindgen = wasm_bindgen;`,document.head.appendChild(e)}let t=window.wasm_bindgen,i=`${h()}?t=${Date.now()}`;try{d=await t(fetch(i))}catch(e){throw{stage:`ffiBoundary`,category:`network`,code:`WasmFetchFailed`,message:`Failed to download WASM engine: ${e.message}`,retryable:!0}}r(d),setInterval(()=>{d&&d.axiom_process_responses()},16);let o=m(``),s=d.axiom_wasm_initialize(o.ptr,o.len);if(d.axiom_free_memory(o.ptr,o.len),s!==0)throw{stage:`runtime`,category:`server`,code:`InitFailed`,message:`Engine init failed (Code: ${s})`,retryable:!1};try{let e=JSON.parse(localStorage.getItem(f)||`{}`);for(let[t,n]of Object.entries(e))for(let[e,r]of Object.entries(n))_(t,e,r,!1)}catch(e){console.warn(`ATMX: Failed to hydrate auth tokens`,e)}for(let[t,r]of Object.entries(e.contracts))try{let i=await fetch(r.contractUrl);if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.arrayBuffer(),s=0;try{let e=new TextDecoder().decode(o),n=JSON.parse(e),r=n?.ir?.endpoints;r&&(s=Array.isArray(r)?r.length:Object.keys(r).length),a(t,n)}catch(e){console.error(`ATMX: Failed to parse .axiom contract for '${t}'`,e)}let c=new Uint8Array(o),l=p(c),u=m(t),f=m(r.baseUrl),h=d.axiom_wasm_load_contract(u.ptr,u.len,f.ptr,f.len,l,c.length,0,0,0,0);if(d.axiom_free_memory(l,c.length),d.axiom_free_memory(u.ptr,u.len),d.axiom_free_memory(f.ptr,f.len),h!==0&&h!==-1)throw Error(`Load error (Code: ${h})`);e.debug&&console.log(`%c🔒 Axiom Contract Loaded: ${t} (${s} endpoints)`,`color: #10b981; font-weight: bold;`),n.contracts[t]={loaded:!0,endpointCount:s},document.dispatchEvent(new CustomEvent(`atmx:contract-loaded`,{detail:{namespace:t,endpointCount:s}}))}catch(e){n.contracts[t]={loaded:!1,endpointCount:0,error:e.message},console.error(`ATMX: Contract failed for ${t}`,e)}n.ok=!0}catch(e){n.ok=!1,n.error=e.stage?e:{stage:`runtime`,category:`unknown`,code:`FatalError`,message:e.message||String(e),retryable:!1}}return n.initDurationMs=Math.round(performance.now()-t),n}function _(e,t,n,r=!0){if(!d)return;if(r)try{let r=JSON.parse(localStorage.getItem(f)||`{}`);r[e]||(r[e]={}),r[e][t]=n,localStorage.setItem(f,JSON.stringify(r))}catch{}let i=m(e),a=m(t),o=m(n);d.axiom_wasm_set_auth_token(i.ptr,i.len,a.ptr,a.len,o.ptr,o.len),d.axiom_free_memory(i.ptr,i.len),d.axiom_free_memory(a.ptr,a.len),d.axiom_free_memory(o.ptr,o.len)}function v(e,t,n=!0){if(!d)return;let r=l(e),i=n?JSON.parse(localStorage.getItem(f)||`{}`):{};n&&!i[e]&&(i[e]={});for(let a of r){let r=m(a.namespace),o=m(a.name),s=m(t);d.axiom_wasm_set_auth_token(r.ptr,r.len,o.ptr,o.len,s.ptr,s.len),d.axiom_free_memory(r.ptr,r.len),d.axiom_free_memory(o.ptr,o.len),d.axiom_free_memory(s.ptr,s.len),n&&(i[e][a.name]=t)}n&&localStorage.setItem(f,JSON.stringify(i))}function y(e,t){if(!d)return;try{let n=JSON.parse(localStorage.getItem(f)||`{}`);n[e]&&(delete n[e][t],localStorage.setItem(f,JSON.stringify(n)))}catch{}let n=m(e),r=m(t);d.axiom_wasm_clear_auth_token(n.ptr,n.len,r.ptr,r.len),d.axiom_free_memory(n.ptr,n.len),d.axiom_free_memory(r.ptr,r.len)}function b(e,t){if(!d)return;let n=new TextEncoder().encode(JSON.stringify(t)),r=p(n);d.axiom_wasm_send_stream_message(e,r,n.length),d.axiom_free_memory(r,n.length)}function x(e,t=!0){if(!d)return;let n=c(),r=t?JSON.parse(localStorage.getItem(f)||`{}`):{};for(let i of n){let n=m(i.namespace),a=m(i.name),o=m(e);d.axiom_wasm_set_auth_token(n.ptr,n.len,a.ptr,a.len,o.ptr,o.len),d.axiom_free_memory(n.ptr,n.len),d.axiom_free_memory(a.ptr,a.len),d.axiom_free_memory(o.ptr,o.len),t&&(r[i.namespace]||(r[i.namespace]={}),r[i.namespace][i.name]=e)}t&&localStorage.setItem(f,JSON.stringify(r))}function S(e,t,n={}){if(e)try{let r=Object.keys(n),i=Object.values(n);return Function(`$data`,`$error`,`$state`,...r,`return (${e});`)(t.data||{},t.error||{},t,...i)}catch(t){console.error(`ATMX Eval Error: ${e}`,t);return}}function C(e,t,n={}){if(e)try{let r=Object.keys(n),i=Object.values(n);Function(`$data`,`$error`,`$state`,...r,e)(t.data||{},t.error||{},t,...i)}catch(t){console.error(`ATMX Action Error: ${e}`,t)}}function w(e,t){T(e,t,!0,{})}function T(e,t,n,r){if(!(!n&&(e.hasAttribute(`ax-query`)||e.hasAttribute(`ax-mutate`)))&&!(!n&&e.hasAttribute(`data-ax-clone-of`))){if(e.hasAttribute(`ax-for`)){E(e,t,r);return}if(e.hasAttribute(`ax-when`)&&(e.getAttribute(`ax-when`).split(`,`).map(e=>e.trim()).includes(t.state)?(e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,`true`),e.style.setProperty(`display`,`none`,`important`))),e.hasAttribute(`ax-if`)&&(S(e.getAttribute(`ax-if`),t,r)?(e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,``),e.style.setProperty(`display`,`none`,`important`))),e.hasAttribute(`ax-text`)){let n=S(e.getAttribute(`ax-text`),t,r);e.textContent=n==null?``:String(n)}if(e.hasAttribute(`ax-error-for`)){let n=e.getAttribute(`ax-error-for`),r=``;if(t.state===`error`&&t.error?.code===`ValidationError`){let e=(t.error.details||``).split(`
887
- `);for(let t of e)if(t.startsWith(n+`:`)){r=t.substring(n.length+1).trim();break}}r?(e.textContent=r,e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,``),e.style.setProperty(`display`,`none`,`important`))}Array.from(e.attributes).forEach(n=>{if(n.name.startsWith(`ax-bind:`)){let i=n.name.substring(8),a=S(n.value,t,r);a===!1||a==null?e.removeAttribute(i):e.setAttribute(i,a===!0?i:String(a))}}),Array.from(e.children).forEach(e=>{T(e,t,!1,r)})}}function E(e,t,n){e.style.display=`none`,e.hasAttribute(`data-ax-for-id`)||e.setAttribute(`data-ax-for-id`,Math.random().toString(36).substr(2,9));let r=e.getAttribute(`data-ax-for-id`),i=e.getAttribute(`ax-for`).match(/^\s*(?:(?:\(\s*([\w\$]+)\s*,\s*([\w\$]+)\s*\))|([\w\$]+))\s+in\s+(.+)$/);if(!i)return;let a=i[1]||i[3],o=i[2],s=i[4],c=S(s,t,n),l=e.parentElement;if(!l)return;let u=Array.from(l.querySelectorAll(`[data-ax-clone-of="${r}"]`));if(!c||!Array.isArray(c)){u.forEach(e=>e.remove());return}let d=e.getAttribute(`ax-key`),f=[];c.forEach((i,s)=>{let c={...n,[a]:i};o&&(c[o]=s);let p=String(s);d&&(p=String(S(d,t,c)));let m=u.find(e=>e.getAttribute(`data-ax-key`)===p);m||(m=e.cloneNode(!0),m.removeAttribute(`ax-for`),m.style.removeProperty(`display`),m.style.length===0&&m.removeAttribute(`style`),m.setAttribute(`data-ax-clone-of`,r),m.setAttribute(`data-ax-key`,p)),l.insertBefore(m,e),T(m,t,!1,c),f.push(m)}),u.forEach(e=>{f.includes(e)||e.remove()})}var D=new WeakMap;function O(e){return D.has(e)||D.set(e,{state:`idle`,isFetching:!1,isMutating:!1,source:null,data:null,error:null}),D.get(e)}function k(e){let t=e.parentElement;for(;t;){if(t.hasAttribute(`ax-query`)||t.hasAttribute(`ax-mutate`)){let e=D.get(t);if(e&&e.data)return e.data}t=t.parentElement}return{}}function A(e,t){let n=O(e);Object.assign(n,t),t.state===`loading`&&(n.isFetching=!0),t.state===`mutating`&&(n.isMutating=!0),(t.state===`success`||t.state===`data`&&t.isFetching===!1)&&(n.isFetching=!1,n.isMutating=!1),D.set(e,n),w(e,n)}var j=0,M=class{key;route;args;state;listeners=new Set;currentReqId=null;constructor(e,t,n){this.key=e,this.route=t,this.args=n,this.state={state:`idle`,isFetching:!1,source:null,data:null,error:null}}subscribe(e){this.listeners.add(e),e(this.state)}update(e){this.state={...this.state,...e},this.listeners.forEach(e=>e(this.state))}fetch(e=!1){if(this.state.isFetching&&!e)return;this.update({state:this.state.data?`data`:`loading`,isFetching:!0,error:null});let r=++j;this.currentReqId=r;let{path:i,remainingArgs:a}=s(this.route,this.args),o=new Uint8Array;Object.keys(a).length>0&&(o=new TextEncoder().encode(JSON.stringify(a))),J.debug&&(console.groupCollapsed(`%c➔ WASM QUERY [#${r}]`,`color: #7c3aed; font-weight: bold;`),console.log(`Namespace:`,this.route.namespace),console.log(`Endpoint ID:`,this.route.id),console.log(`Path:`,i),console.groupEnd()),n.set(r,{isStream:this.route.isStream,onResponse:e=>{if(this.currentReqId===r){if(J.debug){let t=e.eventType===1?`NetworkSuccess`:e.eventType===2?`CacheHit`:e.eventType===3?`CacheHitAndFetching`:e.eventType===4?`Error`:`Complete`;console.groupCollapsed(`%c← WASM RESP [#${r}]`,`color: #059669; font-weight: bold;`),console.log(`Event Type:`,t),e.data&&console.log(`Data:`,e.data),e.error&&console.log(`Error:`,e.error),console.groupEnd()}if(e.eventType===t.Error){this.update({state:`error`,error:e.error,isFetching:!1});return}if(e.data){let n=`network`,r=!1;e.eventType===t.CacheHit?(n=`cache`,r=!1):e.eventType===t.CacheHitAndFetching?(n=`cache`,r=!0):e.eventType===t.NetworkSuccess&&(n=`network`,r=!1),this.update({state:`data`,data:e.data,source:n,isFetching:r})}}},onComplete:()=>{this.currentReqId===r&&(J.debug&&console.log(`%c✔ Stream Complete [#${r}]`,`color: #94a3b8;`),this.update({isFetching:!1}))}});let c=m(this.route.namespace),l=m(this.route.method),u=m(i),f=p(o),h=m(``),g=m(``);d.axiom_wasm_call(r,c.ptr,c.len,this.route.id,l.ptr,l.len,u.ptr,u.len,h.ptr,h.len,g.ptr,g.len,f,o.length),d.axiom_free_memory(c.ptr,c.len),d.axiom_free_memory(l.ptr,l.len),d.axiom_free_memory(u.ptr,u.len),d.axiom_free_memory(h.ptr,h.len),d.axiom_free_memory(g.ptr,g.len)}},N=new Map,P=0;function F(e,t){let n=`ax-on:${t}`;e.hasAttribute(n)&&C(e.getAttribute(n),O(e))}function I(e,t,n){if(!J.debug)return;let r=e===`OUT`?`#7c3aed`:`#059669`;console.groupCollapsed(`%c${e===`OUT`?`➔ WASM CALL`:`← WASM RESP`} [#${t}]`,`color: ${r}; font-weight: bold;`),console.log(`Details:`,n),console.groupEnd()}function L(e,t){let n=t.trim().match(/^([\w\.\-]+)(?:\((.*)\))?$/);if(!n)return null;let r=n[1],i={};if(n[2]&&n[2].trim()!==``)try{if(e){let t=O(e),r=t.data||k(e);i=Function(`$data`,`$state`,`return (${n[2]});`)(r,t)||{}}else i=Function(`return (${n[2]});`)()||{}}catch(e){console.error(`ATMX Scope Error in "${t}":`,e)}return{target:r,args:i}}function R(e){let t=e.getAttribute(`ax-query`);if(!t)return;let n=L(e,t);if(!n)return;let r=o(n.target);if(!r){A(e,{state:`error`,error:{message:`Route not found: ${n.target}`}});return}let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=N.get(i);a||(a=new M(i,r,n.args),N.set(i,a)),e._axListener||(e._axListener=t=>{A(e,t),(t.state===`data`||t.state===`error`)&&(F(e,t.state),e.dispatchEvent(new CustomEvent(`atmx:${t.state}`,{bubbles:!0,detail:t.data||t.error})))},a.subscribe(e._axListener)),a.fetch()}function z(e){let t=e.getAttribute(`ax-mutate`);if(!t)return;let n=L(e,t);if(!n)return;let r=o(n.target);if(!r){A(e,{state:`error`,error:{message:`Route not found: ${n.target}`}}),F(e,`error`);return}A(e,{state:`mutating`,error:null,data:null}),F(e,`mutating`);let i={};e instanceof HTMLFormElement&&new FormData(e).forEach((t,n)=>{let r=e.elements.namedItem(n),a=!1;r instanceof HTMLInputElement?a=r.type===`number`:r instanceof RadioNodeList&&r.length>0&&(a=r[0].type===`number`);let o=a&&t!==``?Number(t):t;if(n.includes(`.`)){let e=n.split(`.`),t=i;for(let n=0;n<e.length-1;n++)t[e[n]]||(t[e[n]]={}),t=t[e[n]];t[e[e.length-1]]=o}else i[n]=o});let{path:a,remainingArgs:c}=s(r,{...i,...n.args}),l=c;r.bodyParam&&c[r.bodyParam]!==void 0&&typeof c[r.bodyParam]==`object`&&(l=c[r.bodyParam]);let u={},d=e.getAttribute(`ax-headers`);if(d)try{u=Function(`return (`+d+`);`)()||{}}catch(e){console.error(`ATMX: Invalid ax-headers syntax`,e)}let f=Object.entries(u).some(([e,t])=>e.toLowerCase()===`content-type`&&t.includes(`application/x-www-form-urlencoded`)),p=new Uint8Array;if(Object.keys(l).length>0)if(f){let e=new URLSearchParams;for(let[t,n]of Object.entries(l))e.append(t,String(n));p=new TextEncoder().encode(e.toString())}else p=new TextEncoder().encode(JSON.stringify(l));B(e,r.namespace,r.id,r.method,a,p,r.isStream,!0,u,f)}function B(e,t,r,i,a,o,s,c,l={},u=!1){let f=++P;I(`OUT`,f,{namespace:t,endpointId:r,method:i,path:a,headers:l,payload:o.length>0?u?new TextDecoder().decode(o):JSON.parse(new TextDecoder().decode(o)):null}),n.set(f,{isStream:s,onResponse:t=>V(e,t,c,f),onComplete:()=>{J.debug&&console.log(`%c✔ Stream Complete [#${f}]`,`color: #94a3b8;`)}});let h=m(t),g=m(i),_=m(a),v=m(``),y=m(Object.keys(l).length>0?JSON.stringify(l):``),b=p(o);d.axiom_wasm_call(f,h.ptr,h.len,r,g.ptr,g.len,_.ptr,_.len,v.ptr,v.len,y.ptr,y.len,b,o.length),d.axiom_free_memory(h.ptr,h.len),d.axiom_free_memory(g.ptr,g.len),d.axiom_free_memory(_.ptr,_.len),d.axiom_free_memory(v.ptr,v.len),d.axiom_free_memory(y.ptr,y.len),b&&d.axiom_free_memory(b,o.length)}function V(e,n,r,i){if(I(`IN`,i,{eventType:t[n.eventType],data:n.data,error:n.error}),n.eventType===t.Error){A(e,{state:`error`,error:n.error,isFetching:!1,isMutating:!1}),F(e,`error`),e.dispatchEvent(new CustomEvent(`atmx:error`,{bubbles:!0,detail:n.error}));return}if(n.data){let i=`network`,a=!1;n.eventType===t.CacheHit?i=`cache`:n.eventType===t.CacheHitAndFetching?(i=`cache`,a=!0):n.eventType===t.NetworkSuccess&&(i=`network`);let s=r?`success`:`data`;if(A(e,{state:s,data:n.data,source:i,isFetching:a,isMutating:!1}),r){let t=e.getAttribute(`ax-store-token`);if(t){let n=S(t,O(e));if(n){let t=o(L(e,e.getAttribute(`ax-mutate`)).target)?.namespace||`default`,r=e.getAttribute(`ax-token-target`);(r?r.split(`,`).map(e=>e.trim()):[t]).forEach(e=>{J.setNamespaceAuthToken(e,n)})}}}F(e,s),e.dispatchEvent(new CustomEvent(r?`atmx:success`:`atmx:data`,{bubbles:!0,detail:n.data}))}}var H=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){let t=e.target;t.hasAttribute(`ax-query`)&&R(t),H.unobserve(t)}})});function U(e){e.querySelectorAll(`[\\:ax-query], [\\:ax-mutate]`).forEach(e=>{if(e.hasAttribute(`:ax-query`)){let t=S(e.getAttribute(`:ax-query`),O(e));t&&e.setAttribute(`ax-query`,String(t)),e.removeAttribute(`:ax-query`)}if(e.hasAttribute(`:ax-mutate`)){let t=S(e.getAttribute(`:ax-mutate`),O(e));t&&e.setAttribute(`ax-mutate`,String(t)),e.removeAttribute(`:ax-mutate`)}})}function W(e=document){U(e),e.querySelectorAll(`[ax-query]`).forEach(e=>{let t=e;A(t,{});let n=t.getAttribute(`ax-trigger`)||`load`;n===`load`?R(t):n===`intersect`?H.observe(t):t.addEventListener(n,e=>{e.preventDefault(),R(t)})}),e.querySelectorAll(`[ax-mutate]`).forEach(e=>{let t=e;A(t,{});let n=t.tagName===`FORM`?`submit`:`click`;t.addEventListener(n,e=>{(t.tagName===`A`||t.tagName===`BUTTON`||t.tagName===`FORM`)&&e.preventDefault(),z(t)})}),e.querySelectorAll(`[ax-trigger="refresh"]`).forEach(e=>{let t=e;t.addEventListener(`click`,e=>{e.preventDefault();let n=t.closest(`[ax-query]`);if(n){let e=L(n,n.getAttribute(`ax-query`));if(e){let t=o(e.target);if(t){let r=`${t.namespace}:${t.id}:${JSON.stringify(e.args)}`,i=N.get(r);i?i.fetch(!0):R(n)}}}})})}function G(){new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e instanceof HTMLElement&&W(e)})})}).observe(document.body,{childList:!0,subtree:!0})}var K=class extends HTMLElement{constructor(){super()}connectedCallback(){let e=this.getAttribute(`loading-text`)||`Initializing...`,t=this.getAttribute(`ready-text`)||`Online`,n=this.getAttribute(`error-text`)||`Failed to Connect`;this.renderState(`loading`,e,`text-amber-500 animate-pulse`),document.addEventListener(`atmx:ready`,()=>{this.renderState(`ready`,t,`text-green-600`)}),document.addEventListener(`atmx:error`,e=>{let t=e;t.detail&&t.detail.stage===`runtime`&&this.renderState(`error`,`${n}: ${t.detail.message}`,`text-red-600`)})}renderState(e,t,n){this.setAttribute(`data-state`,e);let r=this.querySelectorAll(`[data-ax-when]`);r.length>0?r.forEach(t=>{t.getAttribute(`data-ax-when`)===e?t.removeAttribute(`hidden`):t.setAttribute(`hidden`,``)}):(this.innerText=t,this.getAttribute(`class`)||(this.className=`text-xs font-bold ${n}`))}};typeof window<`u`&&!customElements.get(`ax-engine-status`)&&customElements.define(`ax-engine-status`,K);var q=`0.83.0`,J=new class{version=q;initialized=!1;debug=!1;async init(e){if(this.initialized)return{ok:!0,contracts:{},initDurationMs:0};let t=await g(e);return t.ok?(this.debug=e.debug||!1,G(),W(document.body),this.initialized=!0,this.debug&&console.log(`%c🚀 ATMX Debug Mode: Enabled`,`color: #2563eb; font-weight: bold;`),console.log(`✅ ATMX v${this.version} Online (${t.initDurationMs}ms). Reactive Engine Started.`),document.dispatchEvent(new CustomEvent(`atmx:ready`,{detail:t}))):(console.error(`❌ ATMX Initialization Failed:`,t.error),document.dispatchEvent(new CustomEvent(`atmx:error`,{detail:t.error}))),t}triggerQuery(e){let t=typeof e==`string`?document.querySelector(e):e;t&&t instanceof HTMLElement&&t.hasAttribute(`ax-query`)&&R(t)}on(e,t){document.addEventListener(`atmx:${e}`,t)}setAuthToken(e,t,n){_(e,t,n)}setNamespaceAuthToken(e,t,n=!0){v(e,t,n)}setGlobalAuthToken(e){x(e)}sendStreamMessage(e,t){b(e,t)}clearAuthToken(e,t){y(e,t)}connect(e){let t=L(null,e);if(!t)return;let n=o(t.target);if(!n)return;let r=`${n.namespace}:${n.id}:${JSON.stringify(t.args)}`,i=N.get(r);i||(i=new M(r,n,t.args),N.set(r,i)),i.fetch()}disconnect(e){let t=L(null,e);if(!t)return;let r=o(t.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(t.args)}`,a=N.get(i);a&&(a.currentReqId&&n.delete(a.currentReqId),N.delete(i),this.debug&&console.log(`🔌 ATMX Disconnected Stream: ${e}`))}send(e,t){let n=L(null,e);if(!n)return;let r=o(n.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=N.get(i);a&&a.currentReqId?b(a.currentReqId,t):console.warn(`ATMX: Cannot send message, stream not active for ${e}`)}};typeof window<`u`&&(window.atmx=J),e.ATMX_VERSION=q,e.allocBytes=p,e.allocString=m,e.atmx=J,e.buildRequestPath=s,e.clearAuthToken=y,e.initWasm=g,e.pendingRequests=n,e.resolveRoute=o,e.sendStreamMessage=b,e.setAuthToken=_,e.setGlobalAuthToken=x,Object.defineProperty(e,`wasmEngine`,{enumerable:!0,get:function(){return d}})});
887
+ `);for(let t of e)if(t.startsWith(n+`:`)){r=t.substring(n.length+1).trim();break}}r?(e.textContent=r,e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,``),e.style.setProperty(`display`,`none`,`important`))}Array.from(e.attributes).forEach(n=>{if(n.name.startsWith(`ax-bind:`)){let i=n.name.substring(8),a=S(n.value,t,r);a===!1||a==null?e.removeAttribute(i):e.setAttribute(i,a===!0?i:String(a))}}),Array.from(e.children).forEach(e=>{T(e,t,!1,r)})}}function E(e,t,n){e.style.display=`none`,e.hasAttribute(`data-ax-for-id`)||e.setAttribute(`data-ax-for-id`,Math.random().toString(36).substr(2,9));let r=e.getAttribute(`data-ax-for-id`),i=e.getAttribute(`ax-for`).match(/^\s*(?:(?:\(\s*([\w\$]+)\s*,\s*([\w\$]+)\s*\))|([\w\$]+))\s+in\s+(.+)$/);if(!i)return;let a=i[1]||i[3],o=i[2],s=i[4],c=S(s,t,n),l=e.parentElement;if(!l)return;let u=Array.from(l.querySelectorAll(`[data-ax-clone-of="${r}"]`));if(!c||!Array.isArray(c)){u.forEach(e=>e.remove());return}let d=e.getAttribute(`ax-key`),f=[];c.forEach((i,s)=>{let c={...n,[a]:i};o&&(c[o]=s);let p=String(s);d&&(p=String(S(d,t,c)));let m=u.find(e=>e.getAttribute(`data-ax-key`)===p);m||(m=e.cloneNode(!0),m.removeAttribute(`ax-for`),m.style.removeProperty(`display`),m.style.length===0&&m.removeAttribute(`style`),m.setAttribute(`data-ax-clone-of`,r),m.setAttribute(`data-ax-key`,p)),l.insertBefore(m,e),T(m,t,!0,c),f.push(m)}),u.forEach(e=>{f.includes(e)||e.remove()})}var D=new WeakMap;function O(e){return D.has(e)||D.set(e,{state:`idle`,isFetching:!1,isMutating:!1,source:null,data:null,error:null}),D.get(e)}function k(e){let t=e.parentElement;for(;t;){if(t.hasAttribute(`ax-query`)||t.hasAttribute(`ax-mutate`)){let e=D.get(t);if(e&&e.data)return e.data}t=t.parentElement}return{}}function A(e,t){let n=O(e);Object.assign(n,t),t.state===`loading`&&(n.isFetching=!0),t.state===`mutating`&&(n.isMutating=!0),(t.state===`success`||t.state===`data`&&t.isFetching===!1)&&(n.isFetching=!1,n.isMutating=!1),D.set(e,n),w(e,n)}var j=0,M=class{key;route;args;state;listeners=new Set;currentReqId=null;constructor(e,t,n){this.key=e,this.route=t,this.args=n;let r=null;try{let t=sessionStorage.getItem(`atmx_cache_${e}`);t&&(r=JSON.parse(t))}catch{}r?this.state={state:`data`,isFetching:!1,source:`cache`,data:r,error:null}:this.state={state:`idle`,isFetching:!1,source:null,data:null,error:null}}subscribe(e){this.listeners.add(e),e(this.state)}update(e){if(this.state={...this.state,...e},this.state.data)try{sessionStorage.setItem(`atmx_cache_${this.key}`,JSON.stringify(this.state.data))}catch{}this.listeners.forEach(e=>e(this.state))}fetch(e=!1){if(this.state.isFetching&&!e)return;this.update({state:this.state.data?`data`:`loading`,isFetching:!0,error:null});let r=++j;this.currentReqId=r;let{path:i,remainingArgs:a}=s(this.route,this.args),o=new Uint8Array;Object.keys(a).length>0&&(o=new TextEncoder().encode(JSON.stringify(a))),Y.debug&&(console.groupCollapsed(`%c➔ WASM QUERY [#${r}]`,`color: #7c3aed; font-weight: bold;`),console.log(`Namespace:`,this.route.namespace),console.log(`Endpoint ID:`,this.route.id),console.log(`Path:`,i),console.groupEnd()),n.set(r,{isStream:this.route.isStream,onResponse:e=>{if(this.currentReqId===r){if(e.eventType===t.Error){this.update({state:`error`,error:e.error,isFetching:!1});return}if(e.data){let n=`network`,r=!1;e.eventType===t.CacheHit?(n=`cache`,r=!1):e.eventType===t.CacheHitAndFetching?(n=`cache`,r=!0):e.eventType===t.NetworkSuccess&&(n=`network`,r=!1),this.update({state:`data`,data:e.data,source:n,isFetching:r})}}},onComplete:()=>{this.currentReqId===r&&this.update({isFetching:!1})}});let c=m(this.route.namespace),l=m(this.route.method),u=m(i),f=p(o),h=m(``),g=m(``);d.axiom_wasm_call(r,c.ptr,c.len,this.route.id,l.ptr,l.len,u.ptr,u.len,h.ptr,h.len,g.ptr,g.len,f,o.length),d.axiom_free_memory(c.ptr,c.len),d.axiom_free_memory(l.ptr,l.len),d.axiom_free_memory(u.ptr,u.len),d.axiom_free_memory(h.ptr,h.len),d.axiom_free_memory(g.ptr,g.len)}},N=new Map,P=0;function F(e,t){let n=`ax-on:${t}`;e.hasAttribute(n)&&C(e.getAttribute(n),O(e))}function I(e,t,n){if(!Y.debug)return;let r=e===`OUT`?`#7c3aed`:`#059669`;console.groupCollapsed(`%c${e===`OUT`?`➔ WASM CALL`:`← WASM RESP`} [#${t}]`,`color: ${r}; font-weight: bold;`),console.log(`Details:`,n),console.groupEnd()}function L(e,t){let n=t.trim().match(/^([\w\.\-]+)(?:\((.*)\))?$/);if(!n)return null;let r=n[1],i={};if(n[2]&&n[2].trim()!==``)try{if(e){let t=O(e),r=t.data||k(e);i=Function(`$data`,`$state`,`return (${n[2]});`)(r,t)||{}}else i=Function(`return (${n[2]});`)()||{}}catch(e){console.error(`ATMX Scope Error in "${t}":`,e)}return{target:r,args:i}}function R(e){let t=e.getAttribute(`ax-query`);if(!t)return;let n=L(e,t);if(!n)return;let r=o(n.target);if(!r){A(e,{state:`error`,error:{message:`Route not found: ${n.target}`}});return}let i=`${n.target}:${JSON.stringify(n.args)}`,a=N.get(i);a||(a=new M(i,r,n.args),N.set(i,a)),e._axListener||(e._axListener=t=>{A(e,t),(t.state===`data`||t.state===`error`)&&(F(e,t.state),e.dispatchEvent(new CustomEvent(`atmx:${t.state}`,{bubbles:!0,detail:t.data||t.error})))},a.subscribe(e._axListener)),a.fetch()}function z(e){let t=e.getAttribute(`ax-mutate`);if(!t)return;let n=L(e,t);if(!n)return;let r=o(n.target);if(!r){A(e,{state:`error`,error:{message:`Route not found: ${n.target}`}}),F(e,`error`);return}A(e,{state:`mutating`,error:null,data:null}),F(e,`mutating`);let i={};e instanceof HTMLFormElement&&new FormData(e).forEach((t,n)=>{let r=e.elements.namedItem(n),a=!1;r instanceof HTMLInputElement?a=r.type===`number`:r instanceof RadioNodeList&&r.length>0&&(a=r[0].type===`number`);let o=a&&t!==``?Number(t):t;if(n.includes(`.`)){let e=n.split(`.`),t=i;for(let n=0;n<e.length-1;n++)t[e[n]]||(t[e[n]]={}),t=t[e[n]];t[e[e.length-1]]=o}else i[n]=o});let{path:a,remainingArgs:c}=s(r,{...i,...n.args}),l=c;r.bodyParam&&c[r.bodyParam]!==void 0&&typeof c[r.bodyParam]==`object`&&(l=c[r.bodyParam]);let u={},d=e.getAttribute(`ax-headers`);if(d)try{u=Function(`return (`+d+`);`)()||{}}catch(e){console.error(`ATMX: Invalid ax-headers syntax`,e)}let f=Object.entries(u).some(([e,t])=>e.toLowerCase()===`content-type`&&t.includes(`application/x-www-form-urlencoded`)),p=new Uint8Array;if(Object.keys(l).length>0)if(f){let e=new URLSearchParams;for(let[t,n]of Object.entries(l))e.append(t,String(n));p=new TextEncoder().encode(e.toString())}else p=new TextEncoder().encode(JSON.stringify(l));B(e,r.namespace,r.id,r.method,a,p,r.isStream,!0,u,f)}function B(e,t,r,i,a,o,s,c,l={},u=!1){let f=++P;I(`OUT`,f,{namespace:t,endpointId:r,method:i,path:a,headers:l,payload:o.length>0?u?new TextDecoder().decode(o):JSON.parse(new TextDecoder().decode(o)):null}),n.set(f,{isStream:s,onResponse:t=>V(e,t,c,f),onComplete:()=>{Y.debug&&console.log(`%c✔ Stream Complete [#${f}]`,`color: #94a3b8;`)}});let h=m(t),g=m(i),_=m(a),v=m(``),y=m(Object.keys(l).length>0?JSON.stringify(l):``),b=p(o);d.axiom_wasm_call(f,h.ptr,h.len,r,g.ptr,g.len,_.ptr,_.len,v.ptr,v.len,y.ptr,y.len,b,o.length),d.axiom_free_memory(h.ptr,h.len),d.axiom_free_memory(g.ptr,g.len),d.axiom_free_memory(_.ptr,_.len),d.axiom_free_memory(v.ptr,v.len),d.axiom_free_memory(y.ptr,y.len),b&&d.axiom_free_memory(b,o.length)}function V(e,n,r,i){if(I(`IN`,i,{eventType:t[n.eventType],data:n.data,error:n.error}),n.eventType===t.Error){A(e,{state:`error`,error:n.error,isFetching:!1,isMutating:!1}),F(e,`error`),e.dispatchEvent(new CustomEvent(`atmx:error`,{bubbles:!0,detail:n.error}));return}if(n.data){let i=`network`,a=!1;n.eventType===t.CacheHit?i=`cache`:n.eventType===t.CacheHitAndFetching?(i=`cache`,a=!0):n.eventType===t.NetworkSuccess&&(i=`network`);let s=r?`success`:`data`;if(A(e,{state:s,data:n.data,source:i,isFetching:a,isMutating:!1}),r){let t=e.getAttribute(`ax-store-token`);if(t){let n=S(t,O(e));if(n){let t=o(L(e,e.getAttribute(`ax-mutate`)).target)?.namespace||`default`,r=e.getAttribute(`ax-token-target`);(r?r.split(`,`).map(e=>e.trim()):[t]).forEach(e=>{Y.setNamespaceAuthToken(e,n)})}}}F(e,s),e.dispatchEvent(new CustomEvent(r?`atmx:success`:`atmx:data`,{bubbles:!0,detail:n.data}))}}var H=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){let t=e.target;t.hasAttribute(`ax-query`)&&R(t),H.unobserve(t)}})});function U(e){e.querySelectorAll(`[\\:ax-query], [\\:ax-mutate]`).forEach(e=>{if(e.hasAttribute(`:ax-query`)){let t=S(e.getAttribute(`:ax-query`),O(e));t&&e.setAttribute(`ax-query`,String(t)),e.removeAttribute(`:ax-query`)}if(e.hasAttribute(`:ax-mutate`)){let t=S(e.getAttribute(`:ax-mutate`),O(e));t&&e.setAttribute(`ax-mutate`,String(t)),e.removeAttribute(`:ax-mutate`)}})}function W(e=document){U(e),e.querySelectorAll(`[ax-query]`).forEach(e=>{let t=e,n=t.getAttribute(`ax-query`);if(!n)return;let r=L(t,n);if(r){let e=`${r.target}:${JSON.stringify(r.args)}`;try{let n=sessionStorage.getItem(`atmx_cache_${e}`);n&&A(t,{state:`data`,data:JSON.parse(n),source:`cache`,isFetching:!0})}catch{}}})}function G(e=document){U(e),e.querySelectorAll(`[ax-query]`).forEach(e=>{let t=e;A(t,{});let n=t.getAttribute(`ax-trigger`)||`load`;n===`load`?R(t):n===`intersect`?H.observe(t):t.addEventListener(n,e=>{e.preventDefault(),R(t)})}),e.querySelectorAll(`[ax-mutate]`).forEach(e=>{let t=e;A(t,{});let n=t.tagName===`FORM`?`submit`:`click`;t.addEventListener(n,e=>{(t.tagName===`A`||t.tagName===`BUTTON`||t.tagName===`FORM`)&&e.preventDefault(),z(t)})}),e.querySelectorAll(`[ax-trigger="refresh"]`).forEach(e=>{let t=e;t.addEventListener(`click`,e=>{e.preventDefault();let n=t.closest(`[ax-query]`);if(n){let e=L(n,n.getAttribute(`ax-query`));if(e&&o(e.target)){let t=`${e.target}:${JSON.stringify(e.args)}`,r=N.get(t);r?r.fetch(!0):R(n)}}})})}function K(){new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e instanceof HTMLElement&&G(e)})})}).observe(document.body,{childList:!0,subtree:!0})}var q=class extends HTMLElement{constructor(){super()}connectedCallback(){let e=this.getAttribute(`loading-text`)||`Initializing...`,t=this.getAttribute(`ready-text`)||`Online`,n=this.getAttribute(`error-text`)||`Failed to Connect`;this.renderState(`loading`,e,`text-amber-500 animate-pulse`),document.addEventListener(`atmx:ready`,()=>{this.renderState(`ready`,t,`text-green-600`)}),document.addEventListener(`atmx:error`,e=>{let t=e;t.detail&&t.detail.stage===`runtime`&&this.renderState(`error`,`${n}: ${t.detail.message}`,`text-red-600`)})}renderState(e,t,n){this.setAttribute(`data-state`,e);let r=this.querySelectorAll(`[data-ax-when]`);r.length>0?r.forEach(t=>{t.getAttribute(`data-ax-when`)===e?t.removeAttribute(`hidden`):t.setAttribute(`hidden`,``)}):(this.innerText=t,this.getAttribute(`class`)||(this.className=`text-xs font-bold ${n}`))}};typeof window<`u`&&!customElements.get(`ax-engine-status`)&&customElements.define(`ax-engine-status`,q);var J=`0.85.0`,Y=new class{version=J;initialized=!1;debug=!1;async init(e){if(this.initialized)return{ok:!0,contracts:{},initDurationMs:0};let t=await g(e);return t.ok?(this.debug=e.debug||!1,K(),G(document.body),this.initialized=!0,this.debug&&console.log(`%c🚀 ATMX Debug Mode: Enabled`,`color: #2563eb; font-weight: bold;`),console.log(`✅ ATMX v${this.version} Online (${t.initDurationMs}ms). Reactive Engine Started.`),document.dispatchEvent(new CustomEvent(`atmx:ready`,{detail:t}))):(console.error(`❌ ATMX Initialization Failed:`,t.error),document.dispatchEvent(new CustomEvent(`atmx:error`,{detail:t.error}))),t}hydrate(e){let t=document;e&&(t=typeof e==`string`?document.querySelector(e):e),t&&W(t)}triggerQuery(e){let t=typeof e==`string`?document.querySelector(e):e;t&&t instanceof HTMLElement&&t.hasAttribute(`ax-query`)&&R(t)}on(e,t){document.addEventListener(`atmx:${e}`,t)}setAuthToken(e,t,n){_(e,t,n)}setNamespaceAuthToken(e,t,n=!0){v(e,t,n)}setGlobalAuthToken(e){x(e)}sendStreamMessage(e,t){b(e,t)}clearAuthToken(e,t){y(e,t)}connect(e){let t=L(null,e);if(!t)return;let n=o(t.target);if(!n)return;let r=`${n.namespace}:${n.id}:${JSON.stringify(t.args)}`,i=N.get(r);i||(i=new M(r,n,t.args),N.set(r,i)),i.fetch()}disconnect(e){let t=L(null,e);if(!t)return;let r=o(t.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(t.args)}`,a=N.get(i);a&&(a.currentReqId&&n.delete(a.currentReqId),N.delete(i),this.debug&&console.log(`🔌 ATMX Disconnected Stream: ${e}`))}send(e,t){let n=L(null,e);if(!n)return;let r=o(n.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=N.get(i);a&&a.currentReqId?b(a.currentReqId,t):console.warn(`ATMX: Cannot send message, stream not active for ${e}`)}};typeof window<`u`&&(window.atmx=Y),e.ATMX_VERSION=J,e.allocBytes=p,e.allocString=m,e.atmx=Y,e.buildRequestPath=s,e.clearAuthToken=y,e.initWasm=g,e.pendingRequests=n,e.resolveRoute=o,e.sendStreamMessage=b,e.setAuthToken=_,e.setGlobalAuthToken=x,Object.defineProperty(e,`wasmEngine`,{enumerable:!0,get:function(){return d}})});
@@ -1,2 +1,3 @@
1
+ export declare function hydrateQueries(root?: HTMLElement | Document): void;
1
2
  export declare function scanAndInitialize(root?: HTMLElement | Document): void;
2
3
  export declare function initMutationObserver(): void;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { AtmxConfig, InitResult } from './core/types';
2
- export declare const ATMX_VERSION = "0.83.0";
2
+ export declare const ATMX_VERSION = "0.85.0";
3
3
  declare class ATMX {
4
4
  version: string;
5
5
  initialized: boolean;
6
6
  debug: boolean;
7
7
  init(config: AtmxConfig): Promise<InitResult>;
8
+ hydrate(elementOrSelector?: string | HTMLElement): void;
8
9
  triggerQuery(elementOrSelector: string | HTMLElement): void;
9
10
  on(eventName: "ready" | "data" | "error" | "success" | "contract-loaded", callback: (e: any) => void): void;
10
11
  setAuthToken(namespace: string, methodName: string, token: string): void;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "files": [
4
4
  "dist"
5
5
  ],
6
- "version": "0.83.0",
6
+ "version": "0.85.0",
7
7
  "description": "Axiom ATMX Core Runtime for Vanilla Web",
8
8
  "type": "module",
9
9
  "main": "./dist/atmx.umd.js",