@stacksjs/stx 0.2.464 → 0.2.466

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 (67) hide show
  1. package/dist/{chunk-hhsynd7c.js → chunk-01zwbzyw.js} +319 -159
  2. package/dist/{chunk-dqdggvq4.js → chunk-0adxpd3e.js} +18 -18
  3. package/dist/{chunk-nkxa7men.js → chunk-1rbabtw0.js} +1 -1
  4. package/dist/{chunk-0fvz8wad.js → chunk-24xhcqt9.js} +1 -1
  5. package/dist/{chunk-raqqq3mm.js → chunk-45ffx66n.js} +1 -1
  6. package/dist/{chunk-jr3g08vs.js → chunk-4rnncksa.js} +1 -1
  7. package/dist/{chunk-kmb9qrdg.js → chunk-5xsd1dw1.js} +1 -1
  8. package/dist/{chunk-938g2a3d.js → chunk-6qsvh58v.js} +1 -1
  9. package/dist/{chunk-zhexga43.js → chunk-6xd9qbve.js} +1 -1
  10. package/dist/{chunk-mfxf378k.js → chunk-812sn7d5.js} +2 -2
  11. package/dist/{chunk-5yn0gpcj.js → chunk-8bpyr4az.js} +10 -10
  12. package/dist/{chunk-d1x5r4p6.js → chunk-8bsz3ky4.js} +1 -1
  13. package/dist/{chunk-wvxj6r2a.js → chunk-9zx4p42m.js} +1 -1
  14. package/dist/{chunk-y9j2kf3k.js → chunk-ars3cbs5.js} +5 -5
  15. package/dist/{chunk-tsg7bj9p.js → chunk-bnemhyg2.js} +1 -1
  16. package/dist/{chunk-pw34r8r5.js → chunk-cmej3vrr.js} +1 -1
  17. package/dist/{chunk-mxtah7y5.js → chunk-d78wbjkz.js} +1 -1
  18. package/dist/{chunk-nwwzf7h1.js → chunk-eanwntq4.js} +1 -1
  19. package/dist/{chunk-tesmv3m9.js → chunk-ebp212na.js} +2 -2
  20. package/dist/{chunk-y8mx0hab.js → chunk-f9c58ag8.js} +2 -2
  21. package/dist/{chunk-a35c060g.js → chunk-fads0sap.js} +1 -1
  22. package/dist/{chunk-q316y302.js → chunk-fmtyrdgg.js} +1 -1
  23. package/dist/{chunk-1p5ge6fq.js → chunk-gmccacxc.js} +1 -1
  24. package/dist/{chunk-d9360m89.js → chunk-h074e6w3.js} +1 -1
  25. package/dist/{chunk-vhdemrec.js → chunk-h6ayvmaj.js} +1 -1
  26. package/dist/{chunk-39q77svv.js → chunk-hra6t4ch.js} +1 -1
  27. package/dist/chunk-jkf5k215.js +17 -0
  28. package/dist/{chunk-txkfp4v5.js → chunk-k8smv0at.js} +1 -1
  29. package/dist/{chunk-jmhhv817.js → chunk-kax708d4.js} +1 -1
  30. package/dist/{chunk-tzjqtweb.js → chunk-kca543an.js} +1 -1
  31. package/dist/{chunk-bp53x03f.js → chunk-kkrmhb5b.js} +1 -1
  32. package/dist/chunk-m08fk6ds.js +12 -0
  33. package/dist/{chunk-4yjtwjrw.js → chunk-mdkj4jj1.js} +1 -1
  34. package/dist/chunk-n39zm07w.js +2 -0
  35. package/dist/{chunk-xbm2gcb6.js → chunk-na5evt2b.js} +1 -1
  36. package/dist/{chunk-ajqwjevt.js → chunk-pbfwbtg4.js} +1 -1
  37. package/dist/{chunk-ccy6avqe.js → chunk-pyqh70k2.js} +1 -1
  38. package/dist/{chunk-r5gyx7ch.js → chunk-q7bs39wj.js} +1 -1
  39. package/dist/{chunk-krsdcjxk.js → chunk-rdp06c4s.js} +1 -1
  40. package/dist/{chunk-0yba08sr.js → chunk-rx3rxfrj.js} +1 -1
  41. package/dist/{chunk-etjw0he9.js → chunk-sz1s3k89.js} +1 -1
  42. package/dist/{chunk-eegxyqk3.js → chunk-t2hkwjvd.js} +1 -1
  43. package/dist/{chunk-mxt11ejx.js → chunk-tejeej39.js} +1 -1
  44. package/dist/{chunk-qr15ksz9.js → chunk-v6qxmac5.js} +1 -1
  45. package/dist/{chunk-tkakxkbx.js → chunk-vcjfwjr8.js} +1 -1
  46. package/dist/{chunk-dcv6absa.js → chunk-w7m1w5qt.js} +1 -1
  47. package/dist/{chunk-ng61wjke.js → chunk-wfqnxb38.js} +1 -1
  48. package/dist/{chunk-sprx02g0.js → chunk-wx25t40k.js} +1 -1
  49. package/dist/{chunk-raeyd6e5.js → chunk-xk3wf5sh.js} +1 -1
  50. package/dist/{chunk-rjm3n62n.js → chunk-xk5972g0.js} +1 -1
  51. package/dist/{chunk-skjwh35r.js → chunk-y63bv55f.js} +1 -1
  52. package/dist/{chunk-627af18j.js → chunk-zr2trjex.js} +1 -1
  53. package/dist/cli.js +9 -9
  54. package/dist/client-script-bundler.d.ts +10 -0
  55. package/dist/client-script-bundler.js +10 -4
  56. package/dist/composable-loader.js +5 -2
  57. package/dist/craft-entry.js +1 -1
  58. package/dist/craft.js +1 -1
  59. package/dist/native/runtime/native-host.js +1 -1
  60. package/dist/pwa.js +1 -1
  61. package/dist/signals.js +318 -158
  62. package/dist/ssg.js +2 -2
  63. package/dist/strip-literals.js +23 -8
  64. package/package.json +5 -5
  65. package/dist/chunk-kdk0jy1h.js +0 -17
  66. package/dist/chunk-xek78ez1.js +0 -2
  67. package/dist/chunk-y3cqh2jv.js +0 -12
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Ei,_i,Ti}from"./chunk-2jbyks2t.js";import{V,_n,qt,Mr,Nr,Tn,Kt,Xt,Lr,Rn}from"./chunk-14vnnx44.js";function W(r,d=!0,u){if(!d||!r||typeof window>"u")return;let o=window;if(!o.__STX_DATA__){let y=document.querySelector("script[data-stx-server-data]");try{let h=JSON.parse(y?.textContent||"{}");o.__STX_DATA__=h&&typeof h==="object"&&!Array.isArray(h)?h:{}}catch{o.__STX_DATA__={}}}let i=o.__STX_DATA__;if(i&&Object.prototype.hasOwnProperty.call(i,r))try{return{data:u?u(i[r]):i[r]}}catch(y){return{data:null,error:y instanceof Error?y:Error(String(y))}}return}function X(r){if(typeof window>"u")return;let d=window;if(r===void 0)d.__STX_DATA__={};else{if(!d.__STX_DATA__)try{let u=JSON.parse(document.querySelector("script[data-stx-server-data]")?.textContent||"{}");d.__STX_DATA__=u&&typeof u==="object"&&!Array.isArray(u)?u:{}}catch{d.__STX_DATA__={}}if(d.__STX_DATA__)delete d.__STX_DATA__[r]}}function Q(r){let d=null;try{d=typeof indexedDB<"u"?indexedDB:null}catch{d=null}if(!d)return null;let u=d,o=r||"stx-kept",i=null,y=()=>{if(!i)i=new Promise((f,l)=>{let a=u.open(o,1);a.onupgradeneeded=()=>{a.result.createObjectStore("kv")},a.onsuccess=()=>f(a.result),a.onerror=()=>l(a.error),a.onblocked=()=>l(Error("blocked"))}),i.catch(()=>{i=null});return i},h=(f,l)=>y().then((a)=>new Promise((v,g)=>{let t=a.transaction("kv",f),s=l(t.objectStore("kv"));t.oncomplete=()=>v(s?s.result:void 0),t.onerror=()=>g(t.error),t.onabort=()=>g(t.error)}));return{get:(f)=>h("readonly",(l)=>l.get(f)),set:(f,l)=>h("readwrite",(a)=>{a.put(l,f)}),remove:(f)=>h("readwrite",(l)=>{l.delete(f)}),removePrefix:(f)=>h("readwrite",(l)=>{l.delete(IDBKeyRange.bound(f,`${f}\uFFFF`))})}}function G(r,d){let u=r||{},o=null;if(u.storage!==void 0)o=u.storage;else try{o=typeof localStorage<"u"?localStorage:null}catch{o=null}let i=null,y=u.backend!==void 0;if(y)i=u.backend||null;let h=()=>{if(y)return i;y=!0;try{i=d?d():null}catch{i=null}if(i){let e=i;e.get("__stx_probe__").catch(()=>{if(i===e)i=null})}return i},f=u.limit||32768,l=u.defer||((e)=>{let n=typeof requestIdleCallback==="function"?requestIdleCallback:null;if(n)n(e,{timeout:200});else setTimeout(e,16)}),a=new Map,v=new Set,g=new Map,t=!1,s=Promise.resolve(),m=(e)=>{try{return JSON.parse(e)}catch{return e}},p=(e,n)=>{if(!o)return!1;try{return o.setItem(e,n),!0}catch{return!1}},T=(e)=>{try{if(o)o.removeItem(e)}catch{}},S=()=>{if(t=!1,!g.size)return s;let e=Array.from(g.entries());return g.clear(),s=s.then(()=>Promise.all(e.map(([n,c])=>{if(!i){v.delete(n);try{p(n,JSON.stringify(c===void 0?null:c))}catch{}return}let _;try{return _={v:c},i.set(n,_).catch(()=>{let w;try{w=JSON.stringify(c)}catch{return}return i?i.set(n,{j:w}).catch(()=>{p(n,w)}):void 0})}catch{return}}))).then(()=>{}),s},R=(e,n)=>{if(g.set(e,n),v.add(e),t)return;t=!0,l(()=>{S()})},O=(e)=>{if(!e||typeof e!=="object")return;let n=e;if("v"in n)return{value:n.v};if(typeof n.j==="string")return{value:m(n.j)};return},E={peek(e){if(a.has(e))return{value:a.get(e)};let n=null;try{n=o?o.getItem(e):null}catch{n=null}if(n===null||n===void 0)return;let c=m(n);return a.set(e,c),{value:c}},load(e){let n=E.peek(e),c=n?null:h();if(n||!c)return Promise.resolve(n);return c.get(e).then((_)=>{if(a.has(e))return{value:a.get(e)};let w=O(_);if(w)a.set(e,w.value),v.add(e);return w},()=>{return})},set(e,n){if(a.set(e,n),i&&v.has(e)){R(e,n);return}let c;try{c=JSON.stringify(n===void 0?null:n)}catch{return}if(c.length<=f&&p(e,c))return;if(!h()){if(c.length>f)p(e,c);return}T(e),R(e,n)},forget(e){for(let c of Array.from(a.keys()))if(c.indexOf(e)===0)a.delete(c);for(let c of Array.from(g.keys()))if(c.indexOf(e)===0)g.delete(c);for(let c of Array.from(v))if(c.indexOf(e)===0)v.delete(c);try{if(o)for(let c=o.length-1;c>=0;c--){let _=o.key(c);if(_&&_.indexOf(e)===0)o.removeItem(_)}}catch{}let n=h();if(!n)return s;return s=s.then(()=>n.removePrefix(e)).catch(()=>{}),s},flush(){return S()}};try{if(typeof document<"u"&&document.addEventListener)document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="hidden")S()});if(typeof addEventListener==="function")addEventListener("pagehide",()=>{S()})}catch{}return E}function J(r,d){if(!r)return!1;if(r===d.key)return!0;if(!d.url)return!1;if(r===d.url)return!0;try{let u=typeof location<"u"&&location.origin&&location.origin!=="null"?location.origin:"http://localhost",o=new URL(r,u),i=new URL(d.url,u);if(o.origin!==i.origin||o.pathname!==i.pathname)return!1;return!o.search||o.search===i.search}catch{return!1}}function Y(r){let d=r.prefix||"stx:kept:",u=r.matches||((t,s)=>t===s.key||t===s.url),o=new Set,i=new Map,y,h=(t)=>t===void 0?y:t,f=(t,s)=>{let m=h(s);if(m===!1||m===null||m==="")return null;return`${d}${m===void 0?"":`${m}:`}query:${t}`},l=(t)=>{let s=t&&t.value;if(!s||typeof s!=="object"||!("d"in s))return;return{data:s.d,at:Number(s.at)||0}},a=()=>{let t=globalThis;return t.__stx_outboxes instanceof Map?t.__stx_outboxes:null},v={setScope(t){y=t},scope:()=>y,keyFor:f,seed(t,s){let m=f(t,s);return m?l(r.kept.peek(m)):void 0},restore(t,s){let m=f(t,s);return m?r.kept.load(m).then(l):Promise.resolve(void 0)},persist(t,s,m){let p=f(t,m);if(p)r.kept.set(p,{d:s,at:Date.now()})},overlay(t,s,m){let p=a();if(!p||!p.size)return s;let T=s;return p.forEach((S)=>{try{T=S.overlay(t,T,m)}catch{}}),T},watch(t){return o.add(t),()=>{o.delete(t)}},cachedQuery(t,s){let m=i.get(t);if(m){if(s&&m.__options)m.__options(s);return m}let p=s||{},T=p.initial===void 0?null:p.initial,S=()=>typeof p.scope==="function"?p.scope():p.scope,R=()=>(typeof p.url==="function"?p.url():p.url)||null,O=()=>({key:t,url:R()}),E=S(),e=T,n=0,c=null,_=v.seed(t,E);if(_)e=_.data;let w=r.state(v.overlay(O(),e)),H=r.state(!1),q=r.state(!1),B=r.state(null),I=r.state(_?_.at:0),N=0,M=()=>{w.set(v.overlay(O(),e))},z=(b)=>{let x=N;v.restore(t,b).then((C)=>{if(!C||x!==N||n)return;e=C.data,I.set(C.at),M()})};if(!_)z(E);let ee=()=>{let b=S();if(b===E)return;E=b,N++,c=null,n=0;let x=v.seed(t,E);if(e=x?x.data:T,I.set(x?x.at:0),M(),!x)z(E)},te=(b)=>{let x=R(),C=p.timeoutMs||15000,A=typeof AbortController<"u"?new AbortController:null,k=null,ne=new Promise((D,L)=>{k=setTimeout(()=>{if(A)A.abort();L(Error("The request took too long."))},C)}),K;if(p.load)K=p.load({force:b,url:x,signal:A?A.signal:void 0});else if(x){let D=p.fetch||((P,F)=>fetch(P,F)),L={method:"GET",headers:{Accept:"application/json"}};if(b)L.cache="no-cache";if(A)L.signal=A.signal;K=D(x,L).then((P)=>{if(!P.ok)return P.json().catch(()=>null).then((F)=>{throw Error(F&&(F.error||F.message)||`Request failed (${P.status})`)});return P.json()})}else return Promise.resolve(w());return Promise.race([K,ne]).then((D)=>{if(k)clearTimeout(k);return p.transform?p.transform(D):D},(D)=>{if(k)clearTimeout(k);throw D})},U=(b)=>{if(c)return c;let x=N;if(q.set(!0),n===0&&!I())H.set(!0);let C=()=>{if(x!==N)return;c=null,q.set(!1),H.set(!1)},A=te(b).then((k)=>{if(x!==N)return w();return e=k,n=Date.now(),I.set(n),B.set(null),v.persist(t,k,E),M(),C(),w()},(k)=>{if(x===N)B.set(k&&k.message?k.message:"Could not load.");return C(),w()});return c=A,A},j={data:w,loading:H,isFetching:q,error:B,updatedAt:I,get key(){return t},load(b){if(ee(),!b&&n&&Date.now()-n<(p.staleTime||0))return Promise.resolve(w());return U(!!b)},refresh(){return j.load(!0)},set(b){e=typeof b==="function"?b(e):b,v.persist(t,e,E),M()},invalidate(){n=0},__options(b){p={...p,...b}}};if(o.add({target:O,updated:()=>{if(n||I())U(!1)},outbox:(b)=>{if(b)e=v.overlay(O(),e,b.id),n=0,U(!0);M()}}),i.set(t,j),p.immediate)j.load();return j}},g=typeof window<"u"?window:typeof addEventListener==="function"?globalThis:null;if(r.listen!==!1&&g&&typeof g.addEventListener==="function")g.addEventListener("stx:updated",(t)=>{let s=t.detail||{};if(s.kind!=="api"||typeof s.url!=="string")return;o.forEach((m)=>{if(u(s.url,m.target()))m.updated()})}),g.addEventListener("stx:outbox",(t)=>{let s=t.detail||{},m=s.sent&&typeof s.sent.id==="string"?s.sent:null;o.forEach((p)=>{if(m){let T=Array.isArray(m.affects)?m.affects:[],S=p.target();if(!T.some((R)=>u(R,S)))return}p.outbox(m)})});return v}function Z(r,d,u,o,i){let y=!0,h=new Set,f=(a)=>o.get?o.get(a):a,l=()=>f(r());return Object.defineProperty(l,"_isSignal",{value:!0}),Object.defineProperty(l,"modifiers",{get:d}),l.set=(a)=>{if(!y)return;let v=d(),g=o.set?o.set(a,v):a;if(v.trim&&typeof g==="string")g=g.trim();if(v.number&&typeof g==="string"&&g!==""){let t=Number(g);if(!Number.isNaN(t))g=t}if(Object.is(r(),g))return;r.set(g),u(g)},l.update=(a)=>l.set(a(l())),l.input=(a)=>{if(!d().lazy)l.set(a)},l.change=(a)=>{if(d().lazy)l.set(a)},l.subscribe=(a)=>{if(!y)return()=>{};let v=r.subscribe((g,t)=>a(f(g),f(t)));return h.add(v),()=>{v(),h.delete(v)}},Object.defineProperty(l,"value",{get:l,set:l.set}),i(()=>{y=!1,h.forEach((a)=>a()),h.clear()}),l}function Pe(){let r=re(Wt());try{let u=new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(r);return u=u.replace(/\}(var |let |const |function )/g,"};$1"),u}catch{return r}}function re(r){let d=[],u=0,o="console.log(";while(u<r.length){let i=r.indexOf(o,u);if(i===-1){d.push(r.slice(u));break}d.push(r.slice(u,i));let y=1,h=i+o.length;while(h<r.length&&y>0){let f=r[h];if(f==='"'||f==="'"||f==="`"){let l=f;h++;while(h<r.length&&r[h]!==l){if(r[h]==="\\")h++;h++}h++;continue}if(f==="(")y++;else if(f===")")y--;h++}d.push("0"),u=h}return d.join("")}function Wt(){return`
2
+ import{Ei,_i,Ti}from"./chunk-2jbyks2t.js";import{V,_n,qt,Mr,Nr,Tn,Kt,Xt,Lr,Rn}from"./chunk-14vnnx44.js";function W(r,d=!0,u){if(!d||!r||typeof window>"u")return;let s=window;if(!s.__STX_DATA__){let y=document.querySelector("script[data-stx-server-data]");try{let h=JSON.parse(y?.textContent||"{}");s.__STX_DATA__=h&&typeof h==="object"&&!Array.isArray(h)?h:{}}catch{s.__STX_DATA__={}}}let i=s.__STX_DATA__;if(i&&Object.prototype.hasOwnProperty.call(i,r))try{return{data:u?u(i[r]):i[r]}}catch(y){return{data:null,error:y instanceof Error?y:Error(String(y))}}return}function X(r){if(typeof window>"u")return;let d=window;if(r===void 0)d.__STX_DATA__={};else{if(!d.__STX_DATA__)try{let u=JSON.parse(document.querySelector("script[data-stx-server-data]")?.textContent||"{}");d.__STX_DATA__=u&&typeof u==="object"&&!Array.isArray(u)?u:{}}catch{d.__STX_DATA__={}}if(d.__STX_DATA__)delete d.__STX_DATA__[r]}}function Q(r){let d=null;try{d=typeof indexedDB<"u"?indexedDB:null}catch{d=null}if(!d)return null;let u=d,s=r||"stx-kept",i=null,y=()=>{if(!i)i=new Promise((f,l)=>{let a=u.open(s,1);a.onupgradeneeded=()=>{a.result.createObjectStore("kv")},a.onsuccess=()=>f(a.result),a.onerror=()=>l(a.error),a.onblocked=()=>l(Error("blocked"))}),i.catch(()=>{i=null});return i},h=(f,l)=>y().then((a)=>new Promise((v,g)=>{let t=a.transaction("kv",f),o=l(t.objectStore("kv"));t.oncomplete=()=>v(o?o.result:void 0),t.onerror=()=>g(t.error),t.onabort=()=>g(t.error)}));return{get:(f)=>h("readonly",(l)=>l.get(f)),set:(f,l)=>h("readwrite",(a)=>{a.put(l,f)}),remove:(f)=>h("readwrite",(l)=>{l.delete(f)}),removePrefix:(f)=>h("readwrite",(l)=>{l.delete(IDBKeyRange.bound(f,`${f}\uFFFF`))})}}function G(r,d){let u=r||{},s=null;if(u.storage!==void 0)s=u.storage;else try{s=typeof localStorage<"u"?localStorage:null}catch{s=null}let i=null,y=u.backend!==void 0;if(y)i=u.backend||null;let h=()=>{if(y)return i;y=!0;try{i=d?d():null}catch{i=null}if(i){let e=i;e.get("__stx_probe__").catch(()=>{if(i===e)i=null})}return i},f=u.limit||32768,l=u.defer||((e)=>{let n=typeof requestIdleCallback==="function"?requestIdleCallback:null;if(n)n(e,{timeout:200});else setTimeout(e,16)}),a=new Map,v=new Set,g=new Map,t=!1,o=Promise.resolve(),m=(e)=>{try{return JSON.parse(e)}catch{return e}},p=(e,n)=>{if(!s)return!1;try{return s.setItem(e,n),!0}catch{return!1}},T=(e)=>{try{if(s)s.removeItem(e)}catch{}},S=()=>{if(t=!1,!g.size)return o;let e=Array.from(g.entries());return g.clear(),o=o.then(()=>Promise.all(e.map(([n,c])=>{if(!i){v.delete(n);try{p(n,JSON.stringify(c===void 0?null:c))}catch{}return}let _;try{return _={v:c},i.set(n,_).catch(()=>{let w;try{w=JSON.stringify(c)}catch{return}return i?i.set(n,{j:w}).catch(()=>{p(n,w)}):void 0})}catch{return}}))).then(()=>{}),o},R=(e,n)=>{if(g.set(e,n),v.add(e),t)return;t=!0,l(()=>{S()})},O=(e)=>{if(!e||typeof e!=="object")return;let n=e;if("v"in n)return{value:n.v};if(typeof n.j==="string")return{value:m(n.j)};return},E={peek(e){if(a.has(e))return{value:a.get(e)};let n=null;try{n=s?s.getItem(e):null}catch{n=null}if(n===null||n===void 0)return;let c=m(n);return a.set(e,c),{value:c}},load(e){let n=E.peek(e),c=n?null:h();if(n||!c)return Promise.resolve(n);return c.get(e).then((_)=>{if(a.has(e))return{value:a.get(e)};let w=O(_);if(w)a.set(e,w.value),v.add(e);return w},()=>{return})},set(e,n){if(a.set(e,n),i&&v.has(e)){R(e,n);return}let c;try{c=JSON.stringify(n===void 0?null:n)}catch{return}if(c.length<=f&&p(e,c))return;if(!h()){if(c.length>f)p(e,c);return}T(e),R(e,n)},forget(e){for(let c of Array.from(a.keys()))if(c.indexOf(e)===0)a.delete(c);for(let c of Array.from(g.keys()))if(c.indexOf(e)===0)g.delete(c);for(let c of Array.from(v))if(c.indexOf(e)===0)v.delete(c);try{if(s)for(let c=s.length-1;c>=0;c--){let _=s.key(c);if(_&&_.indexOf(e)===0)s.removeItem(_)}}catch{}let n=h();if(!n)return o;return o=o.then(()=>n.removePrefix(e)).catch(()=>{}),o},flush(){return S()}};try{if(typeof document<"u"&&document.addEventListener)document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="hidden")S()});if(typeof addEventListener==="function")addEventListener("pagehide",()=>{S()})}catch{}return E}function J(r,d){if(!r)return!1;if(r===d.key)return!0;if(!d.url)return!1;if(r===d.url)return!0;try{let u=typeof location<"u"&&location.origin&&location.origin!=="null"?location.origin:"http://localhost",s=new URL(r,u),i=new URL(d.url,u);if(s.origin!==i.origin||s.pathname!==i.pathname)return!1;return!s.search||s.search===i.search}catch{return!1}}function Y(r){let d=r.prefix||"stx:kept:",u=r.matches||((t,o)=>t===o.key||t===o.url),s=new Set,i=new Map,y,h=(t)=>t===void 0?y:t,f=(t,o)=>{let m=h(o);if(m===!1||m===null||m==="")return null;return`${d}${m===void 0?"":`${m}:`}query:${t}`},l=(t)=>{let o=t&&t.value;if(!o||typeof o!=="object"||!("d"in o))return;return{data:o.d,at:Number(o.at)||0}},a=()=>{let t=globalThis;return t.__stx_outboxes instanceof Map?t.__stx_outboxes:null},v={setScope(t){y=t},scope:()=>y,keyFor:f,seed(t,o){let m=f(t,o);return m?l(r.kept.peek(m)):void 0},restore(t,o){let m=f(t,o);return m?r.kept.load(m).then(l):Promise.resolve(void 0)},persist(t,o,m){let p=f(t,m);if(p)r.kept.set(p,{d:o,at:Date.now()})},overlay(t,o,m){let p=a();if(!p||!p.size)return o;let T=o;return p.forEach((S)=>{try{T=S.overlay(t,T,m)}catch{}}),T},watch(t){return s.add(t),()=>{s.delete(t)}},cachedQuery(t,o){let m=i.get(t);if(m){if(o&&m.__options)m.__options(o);return m}let p=o||{},T=p.initial===void 0?null:p.initial,S=()=>typeof p.scope==="function"?p.scope():p.scope,R=()=>(typeof p.url==="function"?p.url():p.url)||null,O=()=>({key:t,url:R()}),E=S(),e=T,n=0,c=null,_=v.seed(t,E);if(_)e=_.data;let w=r.state(v.overlay(O(),e)),H=r.state(!1),q=r.state(!1),B=r.state(null),I=r.state(_?_.at:0),N=0,M=()=>{w.set(v.overlay(O(),e))},z=(b)=>{let x=N;v.restore(t,b).then((C)=>{if(!C||x!==N||n)return;e=C.data,I.set(C.at),M()})};if(!_)z(E);let ee=()=>{let b=S();if(b===E)return;E=b,N++,c=null,n=0;let x=v.seed(t,E);if(e=x?x.data:T,I.set(x?x.at:0),M(),!x)z(E)},te=(b)=>{let x=R(),C=p.timeoutMs||15000,A=typeof AbortController<"u"?new AbortController:null,k=null,ne=new Promise((D,L)=>{k=setTimeout(()=>{if(A)A.abort();L(Error("The request took too long."))},C)}),K;if(p.load)K=p.load({force:b,url:x,signal:A?A.signal:void 0});else if(x){let D=p.fetch||((P,F)=>fetch(P,F)),L={method:"GET",headers:{Accept:"application/json"}};if(b)L.cache="no-cache";if(A)L.signal=A.signal;K=D(x,L).then((P)=>{if(!P.ok)return P.json().catch(()=>null).then((F)=>{throw Error(F&&(F.error||F.message)||`Request failed (${P.status})`)});return P.json()})}else return Promise.resolve(w());return Promise.race([K,ne]).then((D)=>{if(k)clearTimeout(k);return p.transform?p.transform(D):D},(D)=>{if(k)clearTimeout(k);throw D})},U=(b)=>{if(c)return c;let x=N;if(q.set(!0),n===0&&!I())H.set(!0);let C=()=>{if(x!==N)return;c=null,q.set(!1),H.set(!1)},A=te(b).then((k)=>{if(x!==N)return w();return e=k,n=Date.now(),I.set(n),B.set(null),v.persist(t,k,E),M(),C(),w()},(k)=>{if(x===N)B.set(k&&k.message?k.message:"Could not load.");return C(),w()});return c=A,A},j={data:w,loading:H,isFetching:q,error:B,updatedAt:I,get key(){return t},load(b){if(ee(),!b&&n&&Date.now()-n<(p.staleTime||0))return Promise.resolve(w());return U(!!b)},refresh(){return j.load(!0)},set(b){e=typeof b==="function"?b(e):b,v.persist(t,e,E),M()},invalidate(){n=0},__options(b){p={...p,...b}}};if(s.add({target:O,updated:()=>{if(n||I())U(!1)},outbox:(b)=>{if(b)e=v.overlay(O(),e,b.id),n=0,U(!0);M()}}),i.set(t,j),p.immediate)j.load();return j}},g=typeof window<"u"?window:typeof addEventListener==="function"?globalThis:null;if(r.listen!==!1&&g&&typeof g.addEventListener==="function")g.addEventListener("stx:updated",(t)=>{let o=t.detail||{};if(o.kind!=="api"||typeof o.url!=="string")return;s.forEach((m)=>{if(u(o.url,m.target()))m.updated()})}),g.addEventListener("stx:outbox",(t)=>{let o=t.detail||{},m=o.sent&&typeof o.sent.id==="string"?o.sent:null;s.forEach((p)=>{if(m){let T=Array.isArray(m.affects)?m.affects:[],S=p.target();if(!T.some((R)=>u(R,S)))return}p.outbox(m)})});return v}function Z(r,d,u,s,i){let y=!0,h=new Set,f=(a)=>s.get?s.get(a):a,l=()=>f(r());return Object.defineProperty(l,"_isSignal",{value:!0}),Object.defineProperty(l,"modifiers",{get:d}),l.set=(a)=>{if(!y)return;let v=d(),g=s.set?s.set(a,v):a;if(v.trim&&typeof g==="string")g=g.trim();if(v.number&&typeof g==="string"&&g!==""){let t=Number(g);if(!Number.isNaN(t))g=t}if(Object.is(r(),g))return;r.set(g),u(g)},l.update=(a)=>l.set(a(l())),l.input=(a)=>{if(!d().lazy)l.set(a)},l.change=(a)=>{if(d().lazy)l.set(a)},l.subscribe=(a)=>{if(!y)return()=>{};let v=r.subscribe((g,t)=>a(f(g),f(t)));return h.add(v),()=>{v(),h.delete(v)}},Object.defineProperty(l,"value",{get:l,set:l.set}),i(()=>{y=!1,h.forEach((a)=>a()),h.clear()}),l}function Pe(){let r=re(Wt());try{let u=new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(r);return u=u.replace(/\}(var |let |const |function )/g,"};$1"),u}catch{return r}}function re(r){let d=[],u=0,s="console.log(";while(u<r.length){let i=r.indexOf(s,u);if(i===-1){d.push(r.slice(u));break}d.push(r.slice(u,i));let y=1,h=i+s.length;while(h<r.length&&y>0){let f=r[h];if(f==='"'||f==="'"||f==="`"){let l=f;h++;while(h<r.length&&r[h]!==l){if(r[h]==="\\")h++;h++}h++;continue}if(f==="(")y++;else if(f===")")y--;h++}d.push("0"),u=h}return d.join("")}function Wt(){return`
3
3
  // STX Signals Runtime (Development Build)
4
4
  console.log('[stx] signals runtime loading');
5
5
  // Pre-initialization shim: capture onMount/onDestroy calls made before the runtime IIFE runs
@@ -6989,6 +6989,281 @@ catch (e) {} }
6989
6989
  }
6990
6990
  };
6991
6991
 
6992
+ // \u2500\u2500 Overlay stack \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
6993
+ //
6994
+ // One stack for everything that takes over the page: stxAlert/stxConfirm,
6995
+ // the runtime modal and drawer, @stacksjs/components' Dialog and Drawer, and
6996
+ // anything an app draws itself (window.stx.overlays). Each of those used to
6997
+ // keep its own listener, its own scroll lock and its own idea of whether it
6998
+ // was on top, so with one open over another a single Escape closed both, two
6999
+ // Tab traps fought over focus, and the first to close unlocked the page under
7000
+ // the one still open (stacksjs/stx#2057; #1998 fixed the same thing for the
7001
+ // confirm dialogs alone).
7002
+ //
7003
+ // Only the topmost overlay answers Escape and owns Tab. The page is locked
7004
+ // from the first open to the last close. Focus moves into an overlay when it
7005
+ // opens and back to whatever opened it when it closes.
7006
+ //
7007
+ // A popup - a menu, a listbox, a popover - goes on the same stack as a
7008
+ // non-modal layer (modal: false). It takes Escape while it is on top, so one
7009
+ // Escape inside a dialog closes the menu and leaves the dialog, but it does
7010
+ // not lock the page, trap Tab or move focus: those follow the topmost MODAL
7011
+ // layer. Each popup used to listen for Escape on the document itself, and
7012
+ // whichever listener was registered first won.
7013
+ var _overlays = [];
7014
+ var _overlayScroll = null;
7015
+ var _overlayInerted = [];
7016
+ var _overlayListening = false;
7017
+ var _OVERLAY_FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
7018
+
7019
+ function _overlayTop() {
7020
+ return _overlays.length ? _overlays[_overlays.length - 1] : null;
7021
+ }
7022
+
7023
+ // The layer that owns Tab and the page lock: the topmost modal one.
7024
+ function _overlayTopModal() {
7025
+ for (var i = _overlays.length - 1; i >= 0; i--) {
7026
+ if (_overlays[i].modal) return _overlays[i];
7027
+ }
7028
+ return null;
7029
+ }
7030
+
7031
+ function _overlayIndex(id) {
7032
+ for (var i = 0; i < _overlays.length; i++) {
7033
+ if (_overlays[i].id === id) return i;
7034
+ }
7035
+ return -1;
7036
+ }
7037
+
7038
+ // The panel is asked for, not held: a component's panel may not be rendered
7039
+ // yet on the frame it opens, and may be replaced while open.
7040
+ function _overlayPanel(entry) {
7041
+ var panel = entry && entry.panel;
7042
+ try {
7043
+ // A selector is looked up each time, like a function: the element it
7044
+ // names may be rendered after the overlay opens, or replaced while open.
7045
+ if (typeof panel === 'string') panel = document.querySelector(panel);
7046
+ else if (typeof panel === 'function') panel = panel();
7047
+ }
7048
+ catch (_e) { panel = null; }
7049
+ return panel || entry.root || null;
7050
+ }
7051
+
7052
+ function _overlayFocusable(panel) {
7053
+ return Array.prototype.filter.call(panel.querySelectorAll(_OVERLAY_FOCUSABLE), function(el) {
7054
+ return el.offsetParent !== null || el === document.activeElement;
7055
+ });
7056
+ }
7057
+
7058
+ // One listener for every overlay, in the bubble phase: a widget inside an
7059
+ // overlay that consumes Escape (a menu closing itself) calls preventDefault
7060
+ // and the overlay leaves it alone.
7061
+ function _overlayKey(e) {
7062
+ var top = _overlayTop();
7063
+ if (!top) return;
7064
+ if (e.key === 'Escape') {
7065
+ if (e.defaultPrevented || !top.onEscape) return;
7066
+ e.preventDefault();
7067
+ top.onEscape();
7068
+ return;
7069
+ }
7070
+ if (e.key !== 'Tab') return;
7071
+ var trap = _overlayTopModal();
7072
+ if (!trap) return;
7073
+ var panel = _overlayPanel(trap);
7074
+ if (!panel) return;
7075
+ var items = _overlayFocusable(panel);
7076
+ if (!items.length) {
7077
+ e.preventDefault();
7078
+ if (panel.focus) panel.focus();
7079
+ return;
7080
+ }
7081
+ var first = items[0];
7082
+ var last = items[items.length - 1];
7083
+ var active = document.activeElement;
7084
+ if (!panel.contains(active)) {
7085
+ e.preventDefault();
7086
+ (e.shiftKey ? last : first).focus();
7087
+ return;
7088
+ }
7089
+ if (e.shiftKey && active === first) {
7090
+ e.preventDefault();
7091
+ last.focus();
7092
+ }
7093
+ else if (!e.shiftKey && active === last) {
7094
+ e.preventDefault();
7095
+ first.focus();
7096
+ }
7097
+ }
7098
+
7099
+ // Lock, listen and inert to match the stack after any change.
7100
+ function _overlaySync() {
7101
+ for (var i = 0; i < _overlayInerted.length; i++) {
7102
+ try { _overlayInerted[i].inert = false; }
7103
+ catch (_e) { /* element may be gone */ }
7104
+ }
7105
+ _overlayInerted = [];
7106
+
7107
+ var top = _overlayTop();
7108
+ var modal = _overlayTopModal();
7109
+ if (!modal && _overlayScroll) {
7110
+ document.body.style.overflow = _overlayScroll.body;
7111
+ document.documentElement.style.overflow = _overlayScroll.html;
7112
+ document.body.style.paddingRight = _overlayScroll.pad;
7113
+ _overlayScroll = null;
7114
+ }
7115
+ if (!top) {
7116
+ if (_overlayScroll) {
7117
+ document.body.style.overflow = _overlayScroll.body;
7118
+ document.documentElement.style.overflow = _overlayScroll.html;
7119
+ document.body.style.paddingRight = _overlayScroll.pad;
7120
+ _overlayScroll = null;
7121
+ }
7122
+ if (_overlayListening) {
7123
+ document.removeEventListener('keydown', _overlayKey);
7124
+ _overlayListening = false;
7125
+ }
7126
+ return;
7127
+ }
7128
+
7129
+ if (modal && !_overlayScroll) {
7130
+ _overlayScroll = {
7131
+ body: document.body.style.overflow,
7132
+ html: document.documentElement.style.overflow,
7133
+ pad: document.body.style.paddingRight
7134
+ };
7135
+ // The scrollbar's width comes back as padding, so the page does not jump
7136
+ // sideways when it disappears.
7137
+ var gap = window.innerWidth - document.documentElement.clientWidth;
7138
+ if (gap > 0) {
7139
+ var existing = Number.parseFloat(window.getComputedStyle(document.body).paddingRight) || 0;
7140
+ document.body.style.paddingRight = (existing + gap) + 'px';
7141
+ }
7142
+ document.body.style.overflow = 'hidden';
7143
+ document.documentElement.style.overflow = 'hidden';
7144
+ }
7145
+ if (!_overlayListening) {
7146
+ document.addEventListener('keydown', _overlayKey);
7147
+ _overlayListening = true;
7148
+ }
7149
+
7150
+ // inert, rather than aria-hidden, takes the page behind out of the tab
7151
+ // order and the accessibility tree together (#1998). Only for an overlay
7152
+ // that is itself a child of the body element - one the runtime appended. An overlay
7153
+ // rendered inside the page's own markup would go inert with the page; its
7154
+ // Tab trap is what holds it.
7155
+ var root = modal && modal.root;
7156
+ if (root && root.parentNode === document.body) {
7157
+ var kids = document.body.children;
7158
+ for (var k = 0; k < kids.length; k++) {
7159
+ var kid = kids[k];
7160
+ if (kid === root || kid.inert) continue;
7161
+ try {
7162
+ kid.inert = true;
7163
+ _overlayInerted.push(kid);
7164
+ }
7165
+ catch (_e) { /* inert unsupported; the Tab trap still holds */ }
7166
+ }
7167
+ }
7168
+ }
7169
+
7170
+ // The next chance to act, whichever comes first: rAF is suspended in a
7171
+ // background tab, so a timer races it.
7172
+ function _overlaySoon(callback) {
7173
+ var done = false;
7174
+ var once = function() {
7175
+ if (done) return;
7176
+ done = true;
7177
+ callback();
7178
+ };
7179
+ if (typeof requestAnimationFrame === 'function') requestAnimationFrame(once);
7180
+ setTimeout(once, 32);
7181
+ }
7182
+
7183
+ // Retried, because focus() on an element that is not displayed yet is a
7184
+ // silent no-op. Stops once the overlay has closed.
7185
+ function _overlayFocusIn(entry, attempts) {
7186
+ if (_overlayIndex(entry.id) === -1) return;
7187
+ var target = null;
7188
+ try { target = typeof entry.initialFocus === 'function' ? entry.initialFocus() : entry.initialFocus; }
7189
+ catch (_e) { target = null; }
7190
+ var panel = _overlayPanel(entry);
7191
+ if (!target && panel) target = panel.querySelector('[autofocus]') || _overlayFocusable(panel)[0] || panel;
7192
+ if (target && target.focus) target.focus();
7193
+ if (target && document.activeElement === target) return;
7194
+ if (attempts > 0) _overlaySoon(function() { _overlayFocusIn(entry, attempts - 1); });
7195
+ }
7196
+
7197
+ var overlays = {
7198
+ /**
7199
+ * Put an overlay on top. Calling it again for an open id updates its
7200
+ * options and nothing else, so it is safe from an effect that re-runs.
7201
+ *
7202
+ * options: modal (default true; false for a popup, which takes Escape
7203
+ * while on top but does not lock, trap or move focus), panel (an element,
7204
+ * a selector, or a function returning one; focus stays inside it), root (the overlay's outermost element, if it is not the panel),
7205
+ * onEscape (leave out for one that must be answered), initialFocus
7206
+ * (element or function; defaults to [autofocus], then the first focusable,
7207
+ * then the panel), opener (where focus goes back; defaults to whatever had
7208
+ * it), restoreFocus (default true).
7209
+ */
7210
+ open: function(id, options) {
7211
+ var opts = options || {};
7212
+ var at = _overlayIndex(id);
7213
+ if (at !== -1) {
7214
+ var existing = _overlays[at];
7215
+ for (var key in opts) {
7216
+ if (Object.prototype.hasOwnProperty.call(opts, key)) existing[key] = opts[key];
7217
+ }
7218
+ _overlaySync();
7219
+ return;
7220
+ }
7221
+ var isModal = opts.modal !== false;
7222
+ var entry = {
7223
+ id: id,
7224
+ modal: isModal,
7225
+ panel: opts.panel,
7226
+ root: opts.root || null,
7227
+ onEscape: opts.onEscape || null,
7228
+ initialFocus: opts.initialFocus || null,
7229
+ // A popup hands focus back itself, to its own trigger, and only when
7230
+ // focus was inside it; a modal layer always does.
7231
+ restoreFocus: opts.restoreFocus !== undefined ? opts.restoreFocus !== false : isModal,
7232
+ opener: opts.opener !== undefined ? opts.opener : document.activeElement
7233
+ };
7234
+ _overlays.push(entry);
7235
+ _overlaySync();
7236
+ // Synchronously first, so a caller that asserts focus straight after
7237
+ // opening sees it; then retried for a panel that is not displayed yet.
7238
+ // A popup keeps focus where its own keyboard handling puts it.
7239
+ if (isModal || opts.initialFocus) _overlayFocusIn(entry, 10);
7240
+ },
7241
+ /** Take an overlay off the stack, wherever it is in it. */
7242
+ close: function(id) {
7243
+ var at = _overlayIndex(id);
7244
+ if (at === -1) return;
7245
+ var wasTop = at === _overlays.length - 1;
7246
+ var entry = _overlays.splice(at, 1)[0];
7247
+ _overlaySync();
7248
+ // Only the overlay that had the keyboard gives it back. Closing one
7249
+ // underneath (its owner went away) must not pull focus out of the top.
7250
+ var opener = entry.opener;
7251
+ if (wasTop && entry.restoreFocus && opener && opener.isConnected !== false && typeof opener.focus === 'function') {
7252
+ try { opener.focus(); }
7253
+ catch (_e) { /* gone; nothing to give focus back to */ }
7254
+ }
7255
+ },
7256
+ /** Whether this overlay is the one that has the keyboard. */
7257
+ isTop: function(id) {
7258
+ var top = _overlayTop();
7259
+ return !!top && top.id === id;
7260
+ },
7261
+ /** Open overlay ids, outermost first. */
7262
+ list: function() {
7263
+ return _overlays.map(function(o) { return o.id; });
7264
+ }
7265
+ };
7266
+
6992
7267
  // \u2500\u2500 Modal system \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
6993
7268
  var modal = {
6994
7269
  open: function(id) {
@@ -6998,16 +7273,14 @@ catch (e) {} }
6998
7273
  // Force reflow then animate
6999
7274
  void el.offsetHeight;
7000
7275
  el.setAttribute('data-stx-modal-open', '');
7001
- document.body.style.overflow = 'hidden';
7002
- // Escape key handler
7003
- if (el.getAttribute('data-close-escape') !== 'false') {
7004
- var escHandler = function(e) {
7005
- if (e.key === 'Escape') { modal.close(id); document.removeEventListener('keydown', escHandler); }
7006
- };
7007
- document.addEventListener('keydown', escHandler);
7008
- el._stxEscHandler = escHandler;
7009
- }
7010
- // Backdrop click
7276
+ // The lock, Escape for the topmost and the Tab trap come from the
7277
+ // overlay stack, shared with every other overlay (stacksjs/stx#2057).
7278
+ // Each modal used to bind its own Escape and set body overflow itself,
7279
+ // so two open closed together and the first to close unlocked the page.
7280
+ overlays.open('stx-modal:' + id, {
7281
+ panel: el,
7282
+ onEscape: el.getAttribute('data-close-escape') !== 'false' ? function() { modal.close(id); } : null
7283
+ });
7011
7284
  if (el.getAttribute('data-close-backdrop') !== 'false') {
7012
7285
  el.onclick = function(e) { if (e.target === el) modal.close(id); };
7013
7286
  }
@@ -7016,12 +7289,10 @@ catch (e) {} }
7016
7289
  var el = document.querySelector('[data-stx-modal="' + id + '"]');
7017
7290
  if (!el) return;
7018
7291
  el.removeAttribute('data-stx-modal-open');
7019
- if (el._stxEscHandler) { document.removeEventListener('keydown', el._stxEscHandler); el._stxEscHandler = null; }
7020
7292
  el.onclick = null;
7293
+ overlays.close('stx-modal:' + id);
7021
7294
  setTimeout(function() {
7022
- el.style.display = 'none';
7023
- // Restore scroll if no other modals are open
7024
- if (!document.querySelector('[data-stx-modal-open]')) document.body.style.overflow = '';
7295
+ if (!el.hasAttribute('data-stx-modal-open')) el.style.display = 'none';
7025
7296
  }, 200);
7026
7297
  },
7027
7298
  toggle: function(id) {
@@ -7037,78 +7308,9 @@ catch (e) {} }
7037
7308
 
7038
7309
  var _dialogId = 0;
7039
7310
 
7040
- // Shared across every open dialog, because four of the defects in #1998 were
7041
- // each dialog acting as if it were the only one.
7042
- var _dialogStack = [];
7043
- // What WE set inert, so restoring never clears an app's own inert.
7044
- var _dialogInerted = [];
7045
- // Saved once, when the first dialog opens.
7046
- var _dialogScrollLock = null;
7047
-
7048
- /*
7049
- * The page behind an aria-modal dialog does not scroll and is not reachable
7050
- * by a virtual cursor (stacksjs/stx#1998, items 1 and 2).
7051
- *
7052
- * The backdrop is position:fixed;inset:0, so it stayed put while the content
7053
- * behind it scrolled away underneath - the dialog claimed to be modal and the
7054
- * page moved anyway. And the Tab trap, which #1875 added, only covers the
7055
- * keyboard: aria-modal support for the virtual cursor is uneven, so a screen
7056
- * reader could still browse the page behind the dialog.
7057
- *
7058
- * inert rather than aria-hidden on the siblings: aria-hidden on an element
7059
- * that contains focus is itself a violation, and inert removes the subtree
7060
- * from the tab order and the accessibility tree together. Everything except
7061
- * the TOPMOST dialog goes inert, which also settles the two traps competing
7062
- * for Tab while both were open - a backgrounded dialog's buttons stop being
7063
- * focusable at all.
7064
- */
7065
- function _dialogSyncModality() {
7066
- var top = _dialogStack.length ? _dialogStack[_dialogStack.length - 1] : null;
7067
-
7068
- for (var i = 0; i < _dialogInerted.length; i++) {
7069
- try { _dialogInerted[i].inert = false; }
7070
- catch (_e) { /* element may be gone */ }
7071
- }
7072
- _dialogInerted = [];
7073
-
7074
- if (!top) {
7075
- if (_dialogScrollLock) {
7076
- document.body.style.overflow = _dialogScrollLock.body;
7077
- document.documentElement.style.overflow = _dialogScrollLock.html;
7078
- document.body.style.paddingRight = _dialogScrollLock.pad;
7079
- _dialogScrollLock = null;
7080
- }
7081
- return;
7082
- }
7083
-
7084
- if (!_dialogScrollLock) {
7085
- _dialogScrollLock = {
7086
- body: document.body.style.overflow,
7087
- html: document.documentElement.style.overflow,
7088
- pad: document.body.style.paddingRight
7089
- };
7090
- // Compensate for the scrollbar the lock removes, or the whole page shifts
7091
- // sideways the moment a dialog opens.
7092
- var gap = window.innerWidth - document.documentElement.clientWidth;
7093
- if (gap > 0) {
7094
- var existing = Number.parseFloat(window.getComputedStyle(document.body).paddingRight) || 0;
7095
- document.body.style.paddingRight = (existing + gap) + 'px';
7096
- }
7097
- document.body.style.overflow = 'hidden';
7098
- document.documentElement.style.overflow = 'hidden';
7099
- }
7100
-
7101
- var kids = document.body.children;
7102
- for (var k = 0; k < kids.length; k++) {
7103
- var kid = kids[k];
7104
- if (kid === top || kid.inert) continue;
7105
- try {
7106
- kid.inert = true;
7107
- _dialogInerted.push(kid);
7108
- }
7109
- catch (_e) { /* inert unsupported; the Tab trap still holds */ }
7110
- }
7111
- }
7311
+ // Modality - the scroll lock, the inert page behind, the one Escape and the
7312
+ // one Tab trap - comes from the overlay stack above, which these dialogs
7313
+ // share with every other overlay on the page (#1998, stacksjs/stx#2057).
7112
7314
 
7113
7315
  /** Dialogs animate unless the reader asked them not to (#1998 item 5). */
7114
7316
  function _dialogReducedMotion() {
@@ -7202,13 +7404,6 @@ catch (e) {} }
7202
7404
  // already closed the dialog, because the listener outlived it.
7203
7405
  if (closed) return;
7204
7406
  closed = true;
7205
- document.removeEventListener('keydown', keyHandler, true);
7206
-
7207
- // Out of the stack BEFORE resolving, so a caller that opens another
7208
- // dialog the moment this one answers does not land under a backdrop
7209
- // that is still fading.
7210
- var at = _dialogStack.indexOf(backdrop);
7211
- if (at !== -1) _dialogStack.splice(at, 1);
7212
7407
 
7213
7408
  // The fade is 200ms and resolve() is immediate, so for those 200ms a
7214
7409
  // full-viewport element at z-index 999999 was still hit-testing at the
@@ -7219,13 +7414,12 @@ catch (e) {} }
7219
7414
  if (!still) panel.style.transform = 'scale(0.95)';
7220
7415
  setTimeout(function() { backdrop.remove(); }, still ? 0 : 200);
7221
7416
 
7222
- // Unlocks the page and clears inert when this was the last dialog, or
7223
- // hands modality back to the one underneath when it was not.
7224
- _dialogSyncModality();
7225
- if (previouslyFocused && typeof previouslyFocused.focus === 'function') {
7226
- try { previouslyFocused.focus(); }
7227
- catch (_e) { /* element may be gone; not worth failing the dialog over */ }
7228
- }
7417
+ // Out of the stack BEFORE resolving, so a caller that opens another
7418
+ // dialog the moment this one answers does not land under a backdrop
7419
+ // that is still fading. That also unlocks the page and clears inert
7420
+ // when this was the last overlay, hands modality back to the one
7421
+ // underneath when it was not, and gives focus back to the opener.
7422
+ overlays.close(id);
7229
7423
  resolve(result);
7230
7424
  }
7231
7425
 
@@ -7254,8 +7448,6 @@ catch (e) {} }
7254
7448
  panel.appendChild(btnRow);
7255
7449
  backdrop.appendChild(panel);
7256
7450
  document.body.appendChild(backdrop);
7257
- _dialogStack.push(backdrop);
7258
- _dialogSyncModality();
7259
7451
 
7260
7452
  // Animate in
7261
7453
  if (!still) {
@@ -7264,50 +7456,6 @@ catch (e) {} }
7264
7456
  panel.style.transform = 'scale(1)';
7265
7457
  }
7266
7458
 
7267
- // Escape, plus a real focus trap.
7268
- //
7269
- // The old handler removed itself ONLY inside the Escape branch, so every
7270
- // dialog dismissed with a button left a permanent keydown listener on
7271
- // document holding this whole closure \u2014 backdrop, panel and resolve \u2014 alive.
7272
- // Removal now lives in cleanup(), which every exit path goes through.
7273
- //
7274
- // aria-modal="true" was already being claimed on the backdrop while Tab
7275
- // walked straight out into the page behind it. Capture phase so the trap
7276
- // wins over anything the page has bound.
7277
- var keyHandler = function(e) {
7278
- // Every dialog binds its own capture-phase handler on document and none
7279
- // of them checked whether they were on top, so ONE Escape resolved every
7280
- // open dialog at once (#1998 item 4). The backgrounded dialogs are inert
7281
- // too, which is what stops their traps competing for Tab.
7282
- if (_dialogStack.length && _dialogStack[_dialogStack.length - 1] !== backdrop) return;
7283
- if (e.key === 'Escape') {
7284
- e.preventDefault();
7285
- cleanup(isConfirm ? false : undefined);
7286
- return;
7287
- }
7288
- if (e.key !== 'Tab') return;
7289
- var focusable = panel.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
7290
- if (!focusable.length) return;
7291
- var first = focusable[0];
7292
- var last = focusable[focusable.length - 1];
7293
- // Focus may sit outside the panel entirely (the page had it when the
7294
- // dialog opened), in which case Tab must pull it back in rather than
7295
- // continue through the document.
7296
- if (!panel.contains(document.activeElement)) {
7297
- e.preventDefault();
7298
- (e.shiftKey ? last : first).focus();
7299
- return;
7300
- }
7301
- if (e.shiftKey && document.activeElement === first) {
7302
- e.preventDefault();
7303
- last.focus();
7304
- }
7305
- else if (!e.shiftKey && document.activeElement === last) {
7306
- e.preventDefault();
7307
- first.focus();
7308
- }
7309
- };
7310
- document.addEventListener('keydown', keyHandler, true);
7311
7459
 
7312
7460
  /*
7313
7461
  * Initial focus, which was an unconditional okBtn.focus() (#1998 item 3).
@@ -7326,7 +7474,18 @@ catch (e) {} }
7326
7474
  if (want === 'cancel' || (!want && type === 'error')) focusTarget = cancelBtn;
7327
7475
  else if (want === 'confirm') focusTarget = okBtn;
7328
7476
  }
7329
- focusTarget.focus();
7477
+
7478
+ // Onto the overlay stack, which locks the page, makes it inert behind
7479
+ // this backdrop, traps Tab inside the panel and answers Escape for
7480
+ // whichever dialog is on top - so one Escape answers one dialog
7481
+ // (#1998 item 4) and a component Dialog underneath stays open.
7482
+ overlays.open(id, {
7483
+ panel: panel,
7484
+ root: backdrop,
7485
+ initialFocus: focusTarget,
7486
+ opener: previouslyFocused,
7487
+ onEscape: function() { cleanup(isConfirm ? false : undefined); }
7488
+ });
7330
7489
  });
7331
7490
  }
7332
7491
 
@@ -7345,16 +7504,17 @@ catch (e) {} }
7345
7504
  var el = document.querySelector('[data-stx-drawer="' + id + '"]');
7346
7505
  if (!el) { console.warn('[stx:drawer] Drawer "' + id + '" not found'); return; }
7347
7506
  el.style.display = 'flex';
7507
+ // Force reflow then animate
7348
7508
  void el.offsetHeight;
7349
7509
  el.setAttribute('data-stx-drawer-open', '');
7350
- document.body.style.overflow = 'hidden';
7351
- if (el.getAttribute('data-close-escape') !== 'false') {
7352
- var escHandler = function(e) {
7353
- if (e.key === 'Escape') { drawer.close(id); document.removeEventListener('keydown', escHandler); }
7354
- };
7355
- document.addEventListener('keydown', escHandler);
7356
- el._stxEscHandler = escHandler;
7357
- }
7510
+ // The lock, Escape for the topmost and the Tab trap come from the
7511
+ // overlay stack, shared with every other overlay (stacksjs/stx#2057).
7512
+ // Each drawer used to bind its own Escape and set body overflow itself,
7513
+ // so two open closed together and the first to close unlocked the page.
7514
+ overlays.open('stx-drawer:' + id, {
7515
+ panel: el,
7516
+ onEscape: el.getAttribute('data-close-escape') !== 'false' ? function() { drawer.close(id); } : null
7517
+ });
7358
7518
  if (el.getAttribute('data-close-backdrop') !== 'false') {
7359
7519
  el.onclick = function(e) { if (e.target === el) drawer.close(id); };
7360
7520
  }
@@ -7363,11 +7523,10 @@ catch (e) {} }
7363
7523
  var el = document.querySelector('[data-stx-drawer="' + id + '"]');
7364
7524
  if (!el) return;
7365
7525
  el.removeAttribute('data-stx-drawer-open');
7366
- if (el._stxEscHandler) { document.removeEventListener('keydown', el._stxEscHandler); el._stxEscHandler = null; }
7367
7526
  el.onclick = null;
7527
+ overlays.close('stx-drawer:' + id);
7368
7528
  setTimeout(function() {
7369
- el.style.display = 'none';
7370
- if (!document.querySelector('[data-stx-drawer-open]') && !document.querySelector('[data-stx-modal-open]')) document.body.style.overflow = '';
7529
+ if (!el.hasAttribute('data-stx-drawer-open')) el.style.display = 'none';
7371
7530
  }, 300);
7372
7531
  },
7373
7532
  toggle: function(id) {
@@ -7565,6 +7724,7 @@ catch (e) {} }
7565
7724
  toast,
7566
7725
  modal,
7567
7726
  drawer,
7727
+ overlays,
7568
7728
  alert: stxAlert,
7569
7729
  confirm: stxConfirm,
7570
7730
  helpers: globalHelpers,