resuma 1.3.1

Resuma — resumable SSR Rust web framework: zero hydration, islands, server actions, Flow (Axum).
Documentation
1
var k=!1,D=0,U=!1;function _(e){k!==e&&(k=e,window.__rIdle=k,document.dispatchEvent(new CustomEvent("resuma:presence",{detail:{idle:k,hidden:document.hidden}})))}function P(){_(!1),window.clearTimeout(D),D=window.setTimeout(()=>_(!0),6e4)}function O(){U||(U=!0,["pointerdown","keydown","scroll","touchstart"].forEach(e=>{document.addEventListener(e,P,{passive:!0})}),document.addEventListener("visibilitychange",()=>{document.hidden?_(!0):P()}),P())}var F=!1;function R(){F||(F=!0,document.addEventListener("keydown",e=>{e.key==="Tab"&&(document.documentElement.dataset.rNav="keyboard")},!0),document.addEventListener("pointerdown",()=>{delete document.documentElement.dataset.rNav},!0))}function x(e){window.__resuma?.onCleanup?.(e)}var I=()=>typeof HTMLElement<"u"&&"popover"in HTMLElement.prototype,N=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("anchor-name: --x"),Q=()=>typeof HTMLDialogElement<"u"&&"closedBy"in HTMLDialogElement.prototype,Z=typeof HTMLButtonElement<"u"&&"command"in HTMLButtonElement.prototype;function tt(e){return e.startsWith("r-popup-")?e:`r-popup-${e}`}function et(e){return e.startsWith("r-modal-")?e:`r-modal-${e}`}function W(e){return document.getElementById(tt(e))??document.querySelector(`[data-r-popup="${CSS.escape(e)}"]`)}function j(e){return document.getElementById(`r-popup-anchor-${e}`)??document.querySelector(`[data-r-popup-trigger="${CSS.escape(e)}"]`)}function G(e){let t=document.getElementById(et(e))??document.querySelector(`[data-r-modal="${CSS.escape(e)}"]`);return t instanceof HTMLDialogElement?t:null}function nt(e){return(e.getAttribute("data-r-popup-positions")??"bottom right top left").split(/[\s,]+/).filter(Boolean)}function q(e,t){let n=t.getBoundingClientRect(),o=e.getBoundingClientRect(),r=innerWidth,i=innerHeight,a=6,d=nt(e),m=l=>l==="top"?{top:n.top-o.height-a,left:n.left}:l==="right"?{top:n.top,left:n.right+a}:l==="left"?{top:n.top,left:n.left-o.width-a}:{top:n.bottom+a,left:n.left},u=m(d[0]??"bottom");for(let l of d){let h=m(l);if(h.top>=0&&h.left>=0&&h.top+o.height<=i&&h.left+o.width<=r){u=h;break}}e.style.position="fixed",e.style.top=`${Math.max(8,u.top)}px`,e.style.left=`${Math.max(8,u.left)}px`,e.setAttribute("data-r-popup-fallback","")}function M(e){try{if(e.matches(":popover-open"))return!0}catch{}return e.classList.contains("r-popover-open")}function K(e){let t=W(e),n=j(e);if(!t||!n)return!1;if(t.hasAttribute("data-r-popup-dismiss-if-shown")&&M(t))return T(e),!1;if(X(e,n),N||q(t,n),I()&&"showPopover"in t)try{t.showPopover()}catch{}else t.classList.add("r-popover-open"),t.style.display="block";return!0}function T(e){let t=W(e);if(t){if(I()&&"hidePopover"in t)try{t.hidePopover()}catch{}t.classList.remove("r-popover-open"),I()||(t.style.display="none")}}function ot(){document.querySelectorAll("[data-r-popup]").forEach(e=>{let t=e.getAttribute("data-r-popup");t&&T(t)})}var B=[],$=new Map;function X(e,t){$.set(e,t)}function rt(e){let t=$.get(e);$.delete(e),t?.isConnected&&window.__resuma?.focus?.(t)}function V(e){let t=G(e);if(!t)return!1;if(t.open)return!0;let n=document.activeElement;return n instanceof HTMLElement&&X(e,n),t.showModal(),B.push(e),!0}function J(e){let t=G(e);t?.open&&t.close()}function ft(){ot(),[...B].reverse().forEach(J)}function z(e){if(!e.id)return;let t=M(e);document.querySelectorAll(`[popovertarget="${CSS.escape(e.id)}"]`).forEach(n=>{n.setAttribute("aria-expanded",t?"true":"false")})}function it(e){e.querySelectorAll("[data-r-popup]").forEach(t=>{if(t.dataset.rUiBound)return;t.dataset.rUiBound="1";let n=t.getAttribute("data-r-popup")??"",o=j(n),r=()=>{z(t),!N&&o&&M(t)&&q(t,o)};if(t.addEventListener("toggle",r),z(t),I()){if(!N&&o){let i=()=>{M(t)&&q(t,o)};window.addEventListener("scroll",i,{capture:!0,passive:!0}),x(()=>window.removeEventListener("scroll",i,!0))}}else{t.style.display="none",o?.addEventListener("click",a=>{a.preventDefault(),M(t)&&t.hasAttribute("data-r-popup-dismiss-if-shown")?T(n):K(n)});let i=a=>{if(!M(t))return;let d=a.target;d instanceof Node&&(t.contains(d)||o?.contains(d)||T(n))};document.addEventListener("click",i),x(()=>document.removeEventListener("click",i))}})}function st(e){e.querySelectorAll("dialog[data-r-modal]").forEach(t=>{if(t.dataset.rUiBound)return;t.dataset.rUiBound="1";let n=t.getAttribute("data-r-modal")??t.id.replace(/^r-modal-/,"");Q()||t.addEventListener("click",o=>{if(o.target!==t)return;let r=t.getBoundingClientRect();o.clientX>=r.left&&o.clientX<=r.right&&o.clientY>=r.top&&o.clientY<=r.bottom||t.close()}),t.addEventListener("close",()=>{let o=B.lastIndexOf(n);o>=0&&B.splice(o,1),rt(n);let r=t.getAttribute("data-r-open-signal");if(r){let i=window.__resuma?.signals.get(r);i&&i.value&&i.set(!1)}})}),e.querySelectorAll("[data-r-modal-open]").forEach(t=>{t.dataset.rUiBound||Z&&t.hasAttribute("command")||(t.dataset.rUiBound="1",t.addEventListener("click",()=>{let n=t.getAttribute("data-r-modal-open");n&&(X(n,t),V(n))}))})}function at(e){let t=window.__resuma?.signals;t&&e.querySelectorAll("[data-r-open-signal]").forEach(n=>{if(n.dataset.rOpenBound)return;n.dataset.rOpenBound="1";let o=n.getAttribute("data-r-open-signal");if(!o)return;let r=t.get(o);if(!r)return;let i=n.getAttribute("data-r-popup")??n.getAttribute("data-r-modal")??"",a=n.hasAttribute("data-r-modal"),d=m=>{let u=m===!0||m==="true"||m===1;a?u?V(i):J(i):u?K(i):T(i)};d(r.value),x(r.subscribe(d))})}function y(e,t,n){let o=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}),r=e.getAttribute(`data-r-on:${t}`),i=window.__resuma?.runHandler;if(r&&typeof i=="function"){let a=(e.getAttribute(`data-r-cap:${t}`)??"").split(",").map(d=>d.trim()).filter(Boolean);i(r,e.getAttribute(`data-r-inline:${t}`),o,a,e);return}e.dispatchEvent(o)}function dt(e){e.querySelectorAll("[data-r-gesture]").forEach(t=>{if(t.dataset.rUiBound)return;t.dataset.rUiBound="1";let n=Number(t.getAttribute("data-r-pan-threshold")??"10")||10,o=t.getAttribute("data-r-preferred-pan")??"",r=null,i=0,a=0,d=0,m=0,u=!1,l=new Map,h=0,v=()=>{m&&window.clearTimeout(m),m=0};t.addEventListener("pointerdown",s=>{if(l.set(s.pointerId,s),l.size===2){let[c,p]=[...l.values()];h=Math.hypot(c.clientX-p.clientX,c.clientY-p.clientY),v();return}r=s.pointerId,i=s.clientX,a=s.clientY,u=!1,t.setPointerCapture?.(s.pointerId),v(),m=window.setTimeout(()=>y(t,"longpress",{x:i,y:a}),500)}),t.addEventListener("pointermove",s=>{if(l.has(s.pointerId)&&l.set(s.pointerId,s),l.size===2&&h){let[E,S]=[...l.values()],A=Math.hypot(E.clientX-S.clientX,E.clientY-S.clientY);y(t,"pinch",{scale:A/h});return}if(r!==s.pointerId)return;let c=s.clientX-i,p=s.clientY-a;if(!u&&Math.hypot(c,p)<n)return;if(!u){if(o==="horizontal"&&Math.abs(c)<Math.abs(p)||o==="vertical"&&Math.abs(p)<Math.abs(c))return;u=!0,v()}let f={dx:c,dy:p,startX:i,startY:a};y(t,"pan",f),y(t,Math.abs(c)>=Math.abs(p)?"panhorizontal":"panvertical",f)});let b=s=>{if(l.delete(s.pointerId),l.size<2&&(h=0),r!==s.pointerId)return;let c=s.clientX-i,p=s.clientY-a;if(v(),!u&&Math.hypot(c,p)<n){let f=Date.now();f-d<300&&y(t,"doubletap",{x:s.clientX,y:s.clientY}),d=f}r=null,u=!1};t.addEventListener("pointerup",b),t.addEventListener("pointercancel",b),t.addEventListener("wheel",s=>y(t,"scrollwheel",{dx:s.deltaX,dy:s.deltaY}),{passive:!0})})}function lt(e){if(e&&typeof e=="object")for(let t of["title","name","label","text"]){let n=e[t];if(typeof n=="string")return n}return e==null?"":String(e)}function ut(e,t,n){if(t&&e&&typeof e=="object"){let o=e[t];if(o!=null)return String(o)}return String(n)}function mt(e,t,n,o){let r=e.querySelector("[data-r-for-list]");if(!r)return;let i=Math.max(1,Number(e.getAttribute("data-r-item-height")??"48")||48),a=Math.max(0,Number(e.getAttribute("data-r-overscan")??"6")||6),d=e.closest("[data-r-virtual-scroller]")??r.parentElement??e,m=(c,p)=>{let f=r.querySelector(`[${c}]`);return f||(f=document.createElement("div"),f.className="r-virtual-spacer",f.setAttribute(c,""),p?r.insertBefore(f,r.firstChild):r.appendChild(f)),f},u=m("data-r-virtual-top",!0),l=m("data-r-virtual-bot",!1),h=r.querySelector("[data-r-for-item]")??void 0,v=new Map,b=()=>{let c=Array.isArray(t.value)?t.value:[],p=c.length,f=d.clientHeight||window.innerHeight,E=Math.max(0,Math.floor(d.scrollTop/i)-a),S=Math.ceil(f/i)+a*2,A=Math.min(p,E+S);u.style.height=`${E*i}px`,l.style.height=`${Math.max(0,p-A)*i}px`;let Y=new Set,H=document.createDocumentFragment();H.appendChild(u);for(let w=E;w<A;w++){let L=c[w],C=ut(L,n,w);Y.add(C);let g=v.get(C);g||(g=h?h.cloneNode(!0):document.createElement("div"),g.setAttribute("data-r-for-item",""),g.setAttribute("data-r-for-new","true"),v.set(C,g)),g.setAttribute("data-r-for-key",C),g.style.height=`${i}px`,!g.querySelector("[data-r-signal]")&&g.childElementCount===0&&(g.textContent=lt(L)),H.appendChild(g)}H.appendChild(l),r.replaceChildren(H),v.forEach((w,L)=>{Y.has(L)||v.delete(L)}),o(r)};b();let s=()=>b();d.addEventListener("scroll",s,{passive:!0}),x(()=>d.removeEventListener("scroll",s)),x(t.subscribe(b))}function ht(e=document){R(),O(),it(e),st(e),at(e),dt(e)}export{mt as bindVirtualFor,ft as dismissAll,ot as hideAllPopups,J as hideModal,T as hidePopup,ht as initUi,V as showModal,K as showPopup};