@occluze/umber 0.2.1 → 0.3.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.
Files changed (84) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +78 -48
  3. package/dist/chunks/badge.js +2 -0
  4. package/dist/chunks/basis.js +2 -0
  5. package/dist/chunks/basis_transcoder.js +2 -0
  6. package/dist/chunks/basis_transcoder.wasm +0 -0
  7. package/dist/chunks/capture.js +2 -2
  8. package/dist/chunks/covers.js +2 -2
  9. package/dist/chunks/curves.js +2 -0
  10. package/dist/chunks/flip.js +2 -2
  11. package/dist/chunks/fx.js +2 -102
  12. package/dist/chunks/gl.js +2 -180
  13. package/dist/chunks/glsl.js +2 -239
  14. package/dist/chunks/inspect.js +2 -6
  15. package/dist/chunks/instances.js +2 -93
  16. package/dist/chunks/layers.js +2 -21
  17. package/dist/chunks/licence.js +2 -2
  18. package/dist/chunks/morph.js +2 -2
  19. package/dist/chunks/patch.js +2 -0
  20. package/dist/chunks/prepared.js +2 -0
  21. package/dist/chunks/profiler.js +2 -0
  22. package/dist/chunks/restore.js +2 -2
  23. package/dist/chunks/shapes.js +2 -2
  24. package/dist/chunks/sim.js +2 -22
  25. package/dist/chunks/text.js +2 -52
  26. package/dist/chunks/video.js +2 -2
  27. package/dist/chunks/views.js +2 -2
  28. package/dist/chunks/vocabulary.js +2 -0
  29. package/dist/chunks/warm.js +2 -2
  30. package/dist/frameworks/astro.mjs +2 -0
  31. package/dist/frameworks/react.mjs +2 -0
  32. package/dist/frameworks/svelte.mjs +2 -0
  33. package/dist/frameworks/vue.mjs +2 -0
  34. package/dist/modules/debug.js +2 -36
  35. package/dist/modules/debug.mjs +2 -36
  36. package/dist/modules/handoff.js +2 -2
  37. package/dist/modules/handoff.mjs +2 -2
  38. package/dist/modules/input.js +2 -2
  39. package/dist/modules/input.mjs +2 -2
  40. package/dist/modules/router-swap.js +2 -13
  41. package/dist/modules/router.js +2 -2
  42. package/dist/modules/router.mjs +2 -2
  43. package/dist/modules/scroll-more.js +2 -0
  44. package/dist/modules/scroll-touch.js +2 -0
  45. package/dist/modules/scroll.js +2 -2
  46. package/dist/modules/scroll.mjs +2 -2
  47. package/dist/modules/scrollfx.js +2 -0
  48. package/dist/modules/scrollfx.mjs +2 -0
  49. package/dist/modules/scrub.js +2 -8
  50. package/dist/modules/scrub.mjs +2 -8
  51. package/dist/modules/three.js +2 -0
  52. package/dist/modules/three.mjs +2 -0
  53. package/dist/node/assets.mjs +9 -0
  54. package/dist/node/astro.mjs +47 -0
  55. package/dist/node/cli.mjs +109 -0
  56. package/dist/node/shared-3Q24RNIF.mjs +602 -0
  57. package/dist/node/shared-4FIU6DYP.mjs +200 -0
  58. package/dist/node/vite.mjs +10 -0
  59. package/dist/umber.css +2 -2
  60. package/dist/umber.js +2 -2
  61. package/dist/umber.mjs +2 -2
  62. package/docs/AI-quick.md +116 -54
  63. package/docs/AI.md +1275 -805
  64. package/docs/npm.md +37 -26
  65. package/package.json +181 -12
  66. package/types/assets.d.ts +87 -0
  67. package/types/astro.d.ts +43 -0
  68. package/types/debug.d.ts +17 -16
  69. package/types/esm.d.ts +12 -12
  70. package/types/global.d.ts +17 -0
  71. package/types/handoff.d.ts +26 -25
  72. package/types/input.d.ts +63 -55
  73. package/types/loop.d.ts +75 -0
  74. package/types/module.d.ts +108 -0
  75. package/types/react.d.ts +15 -0
  76. package/types/router.d.ts +87 -45
  77. package/types/scroll.d.ts +96 -38
  78. package/types/scrollfx.d.ts +80 -0
  79. package/types/scrub.d.ts +33 -32
  80. package/types/svelte.d.ts +16 -0
  81. package/types/three.d.ts +226 -0
  82. package/types/umber.d.ts +633 -357
  83. package/types/vite.d.ts +33 -0
  84. package/types/vue.d.ts +14 -0
@@ -1,13 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- var D='link[rel~="stylesheet"][href], style',M=e=>new URL(e||"",location.href).href,K=e=>[...e.children],W=e=>K(e.head).filter(t=>!/^(script|noscript|title)$/.test(t.localName)),R=e=>e.matches(D);function S(e,t){if(e.localName!==t.localName)return!1;if(e.localName==="link"&&e.matches(D))return t.matches(D)&&M(e.getAttribute("href"))===M(t.getAttribute("href"));if(!e.hasAttribute("nonce")&&!t.hasAttribute("nonce"))return e.isEqualNode(t);let[n,r]=[e.cloneNode(!0),t.cloneNode(!0)];return n.removeAttribute("nonce"),r.removeAttribute("nonce"),n.isEqualNode(r)}function C(e){let t=e.getAttribute("name")||e.getAttribute("property")||e.getAttribute("itemprop")||e.getAttribute("http-equiv");return e.localName==="meta"?t?`meta ${t}`:e.hasAttribute("charset")?"meta charset":"":e.localName==="base"?"base":e.localName==="link"&&!R(e)?`link ${e.getAttribute("rel")} ${e.getAttribute("hreflang")||""} ${e.getAttribute("media")||""} ${e.getAttribute("sizes")||""}`:""}function B(e,t,n){let r=new Set([...t.getAttributeNames(),...n?.getAttributeNames()||[]]);for(let o of r){if(o==="class"||o==="style")continue;let s=t.getAttribute(o);n&&n.getAttribute(o)===s||(s==null?e.removeAttribute(o):e.setAttribute(o,s))}n?.classList.forEach(o=>t.classList.contains(o)||e.classList.remove(o)),t.classList.forEach(o=>n?.classList.contains(o)||e.classList.add(o))}function ie(e){let t=n=>[...n.querySelectorAll("head [data-gl-router-track]")].map(r=>r.outerHTML).join("");return t(document)!==t(e)}function V(){let e=null;function t(n,r=3e3){let o=e,s=W(n),m=()=>K(document.head),f=s.filter(i=>R(i)&&!m().some(a=>S(a,i))),p=(i,a)=>!a(i)&&!s.some(l=>S(l,i))&&(!!o&&W(o).some(l=>S(l,i))||!!C(i)&&s.some(l=>C(l)===C(i))),u=f.filter(i=>i.localName==="link").map(i=>{let a=document.createElement("link");a.rel="preload",a.as="style",a.href=M(i.getAttribute("href"));let l=i.getAttribute("crossorigin");return l!=null&&a.setAttribute("crossorigin",l),document.head.append(a),a});return{styles(){u.forEach(l=>l.remove());let i=f.map(l=>{let c=document.importNode(l,!0),g=l.localName==="link"?new Promise(b=>c.onload=c.onerror=b):null;return document.head.append(c),g}),a;return Promise.race([Promise.all(i),new Promise(l=>a=setTimeout(l,r))]).finally(()=>clearTimeout(a))},swap(){document.title=n.title;for(let i of m())p(i,R)&&i.remove();for(let i of s)!R(i)&&!m().some(a=>S(a,i))&&document.head.append(document.importNode(i,!0));B(document.documentElement,n.documentElement,o?.documentElement),document.body&&n.body&&B(document.body,n.body,o?.body)},done(){for(let i of m())R(i)&&p(i,()=>!1)&&i.remove();e=n}}}return{prepare:t,know:n=>void(e||=n)}}var se=e=>new RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}/?$`);function $(e,t){if(Array.isArray(e))return e.some(r=>$(r,t));if(typeof e=="function")return!!e(t);let n=new URL(t.url,location.href).pathname;return e instanceof RegExp?e.test(n):e[0]==="/"?se(e).test(n):e===t.page}function ae(e,t){let n=0,r=t.trigger instanceof Element?t.trigger:null;if(e.from!=null){if(!$(e.from,t.current))return-1;n+=1}if(e.to!=null){if(!$(e.to,t.next))return-1;n+=2}if(e.links!=null){if(!r||!(typeof e.links=="function"?e.links(r):r.matches(e.links)))return-1;n+=4}if(e.custom){if(!e.custom(t))return-1;n+=8}return n}function O(e,t){let n,r=-1;for(let o of e){let s=ae(o,t);s>=0&&s>=r&&(n=o,r=s)}return[n,r]}var F="data-gl-router-prevent";function H(e){let t=new URL(e,location.href);return t.hash="",t.href}var P="cubic-bezier(0.76, 0, 0.24, 1)",le="cubic-bezier(0.16, 1, 0.3, 1)",ce="cubic-bezier(0.5, 0, 0.75, 0)";function E(e,t,n,r,o,s){if(!e?.animate)return;let m=e.animate(t,{duration:(n.duration??r)*1e3,easing:n.ease||o,fill:"both"});return m.finished.then(()=>s||m.cancel())}var x=e=>e.direction==="back"?-1:1,A=(e,t)=>e.next.container&&Object.assign(e.next.container.style,t);function G(e="#111"){let t=document.createElement("div");return t.setAttribute("aria-hidden","true"),t.style.cssText=`position:fixed;inset:0;z-index:2147483000;pointer-events:none;background:${e}`,document.body.append(t),t}var ue=e=>({leave:t=>E(t.current.container,[{opacity:1},{opacity:0}],e,.4,"cubic-bezier(0.4, 0, 1, 1)",!0),beforeEnter:t=>A(t,{opacity:"0"}),enter(t){let n=E(t.next.container,[{opacity:0},{opacity:1}],e,.4,"cubic-bezier(0, 0, 0.2, 1)");return A(t,{opacity:""}),n}});function fe(e){let t=o=>`translateX(${o}%)`,n=document.documentElement.style,r=null;return{sync:!0,beforeEnter(o){r=n.overflowX,n.overflowX="clip",A(o,{transform:t(100*x(o)),position:"relative",zIndex:"1",boxShadow:"0 0 80px rgb(0 0 0 / 0.18)"})},leave:o=>E(o.current.container,[{transform:t(0),filter:"brightness(1)"},{transform:t(-30*x(o)),filter:"brightness(0.7)"}],e,.9,P,!0),enter(o){let s=E(o.next.container,[{transform:t(100*x(o))},{transform:t(0)}],e,.9,P);return A(o,{transform:""}),Promise.resolve(s).finally(()=>{A(o,{position:"",zIndex:"",boxShadow:""}),r!=null&&(n.overflowX=r),r=null})}}}var me=e=>({leave:t=>E(t.current.container,[{opacity:1,transform:"scale(1)"},{opacity:0,transform:"scale(0.94)"}],e,.5,ce,!0),beforeEnter:t=>A(t,{opacity:"0"}),enter(t){let n=E(t.next.container,[{opacity:0,transform:"scale(1.06)"},{opacity:1,transform:"scale(1)"}],e,.7,le);return A(t,{opacity:""}),n}});function X(e){return t=>{let n=null,r=o=>e==="curtain"?{transform:`translateY(${o*100}%)`}:{clipPath:o>0?"inset(0 0 0 100%)":o<0?"inset(0 100% 0 0)":"inset(0)"};return{leave(o){return n=G(t.color),E(n,[r(e==="curtain"?x(o):-x(o)),r(0)],t,.65,P,!0)},enter:o=>Promise.resolve(E(n,[r(0),r(e==="curtain"?-x(o):x(o))],t,.65,P,!0)).finally(()=>n?.remove())}}}var _={"router-cover":`vec2 s = uViewport / uViewport.y, p = vUv * s, c = uOrigin * s;
3
- float far = max(max(length(c), length(c - vec2(s.x, 0.0))), max(length(c - vec2(0.0, 1.0)), length(c - s)));
4
- float r = uCover * (far + 0.12);
5
- color = vec4(uColor.rgb, uColor.a * (1.0 - smoothstep(r - 0.12, r, distance(p, c))));`,"router-dissolve":`vec2 p = vUv * uViewport / uViewport.y * 5.0, i = floor(p), f = fract(p), k = vec2(127.1, 311.7);
6
- f = f * f * (3.0 - 2.0 * f);
7
- vec4 h = fract(sin(vec4(dot(i, k), dot(i + vec2(1.0, 0.0), k), dot(i + vec2(0.0, 1.0), k), dot(i + 1.0, k))) * 43758.5453);
8
- float n = mix(mix(h.x, h.y, f.x), mix(h.z, h.w, f.x), f.y) * 0.75 + fract(sin(dot(floor(p * 9.0), k)) * 43758.5453) * 0.25;
9
- float edge = uCover * 1.5 - 0.3 + ((uDirection < 0.0 ? 1.0 - vUv.y : vUv.y) - 0.5) * 0.15;
10
- color = vec4(uColor.rgb, uColor.a * smoothstep(n - 0.12, n + 0.12, edge));`},Y=new WeakMap;function J(e){return(t,n)=>{let r=null,o=null,s=null,m=f=>o?.tween("uCover",{value:f,duration:t.duration??.8,ease:t.ease||"expo.inOut"})??E(r,[{opacity:1-f},{opacity:f}],t,.6,P,!0);return{async leave(f){let p=t.shader||e,u=n&&Y.get(n);n&&_[p]&&!u?.has(p)&&(u?u.add(p):Y.set(n,new Set([p])),n.shader(p,{animate:!1,uniforms:{uCover:0,uOrigin:[.5,.5],uDirection:1,uColor:"#111"},fragment:_[p]})),r=G("transparent"),r.setAttribute("data-gl-cover",""),o=await n?.add(r,{type:"shader",shader:p,order:1e4}).catch(()=>null),o&&!("uCover"in o.uniforms)&&(o=null);let i=o,a=(l,c)=>i&&l in i.uniforms&&i.set(l,c);if(a("uCover",0),a("uOrigin",f.origin?[f.origin[0]/innerWidth,f.origin[1]/innerHeight]:[.5,.5]),a("uDirection",x(f)),t.color&&a("uColor",t.color),i&&i.status!=="ready"&&await new Promise(l=>{let c=()=>(clearTimeout(b),g.forEach(h=>h()),l()),g=[i.on("ready",c),i.on("error",c)],b=setTimeout(c,1e3)}),i?.status!=="ready")n?.canvas&&console.warn(`[umber] router: the ${e.slice(7)} transition could not draw ${t.shader?`the shader "${t.shader}" (is it defined with gl.shader("${t.shader}", { uniforms: { uCover: 0 }, fragment: ... })?)`:"its shader"}: a plain panel fades instead.`),o=null,r.style.background=t.color||"#111";else if(t.above!=null&&t.above!==!1&&t.above!=="false"){let l=n?.canvas?.parentElement;l&&(s=[l,l.style.zIndex],l.style.zIndex="2147483000")}return m(1)},enter:()=>Promise.resolve(m(0)).finally(()=>{r?.remove(),s&&(s[0].style.zIndex=s[1]),s=null})}}}var T={none:()=>({}),fade:ue,slide:fe,zoom:me,curtain:X("curtain"),wipe:X("wipe"),cover:J("router-cover"),dissolve:J("router-dissolve")};var pe=/^\s*(text\/javascript|application\/javascript|module)?\s*$/i,de=e=>pe.test(e.getAttribute("type")||"")&&!e.hasAttribute(F)&&!(e.hasAttribute("nomodule")&&"noModule"in e),Q=e=>{let t=e.getAttribute("src");return t?"src "+new URL(t,location.href).href:e.textContent||""},he=/already been declared|redeclaration of|duplicate variable/i,N=(e,t)=>{let n=/^\s*(["'])use strict\1;?/.exec(e)?.[0]||"";return`${n}{
11
- ${e.slice(n.length)}
12
- }`+(t?`
13
- //# sourceURL=${t}`:"")};function Z(e){let t=customElements,n=t.define;t.define=(r,o,s)=>void(t.get(r)||n.call(t,r,o,s));try{e()}finally{t.define=n}}function ee(e,t,n,r=!1){let o=e.getAttribute("src"),s=!/module/i.test(e.type),m=e.hasAttribute("async"),f=(a,l)=>{let c=document.createElement("script");for(let g of e.attributes)(l||g.name!=="src"&&g.name!=="integrity")&&c.setAttribute(g.name,g.value);return c.textContent=a,m||(c.async=!1),c},p=(a,l=!1)=>{let c=f(a,l),g=l&&!m?new Promise(y=>(c.onload=c.onerror=y,setTimeout(y,n))):null;if(l||!s)return t(c),g||Promise.resolve();let b=!1,h=y=>{he.test(y.message||"")&&(b=!0,y.preventDefault())};return addEventListener("error",h),Z(()=>t(c)),removeEventListener("error",h),b&&Z(()=>c.replaceWith(f(N(e.textContent||""),!1))),Promise.resolve()};if(!(r&&s))return p(e.textContent,!!o);if(!o)return p(N(e.textContent||""));let u=new URL(o,location.href).href,i=fetch(u,{integrity:e.integrity}).then(a=>a.ok?a.text():Promise.reject()).then(a=>p(N(a,u)),()=>p(null,!0));return m?Promise.resolve():i}function te(){let e=s=>[...s.querySelectorAll("script")],t=new Set(e(document).map(Q)),n=new Set([...t].filter(s=>s.startsWith("src "))),r=new Set(t);async function o(s,m,f=3e3,p=4e3){let u=new Set,i=Date.now()+p,a=l=>Date.now()<i?l:null;for(let l of s){if(!de(l))continue;let c=Q(l),g=r.has(c);if(r.add(c),m.contains(l)){await a(ee(l,h=>l.replaceWith(h),f,g));continue}if(u.add(c),t.has(c)||n.has(c))continue;c.startsWith("src ")&&n.add(c);let b=l.closest("head")?document.head:document.body;await a(ee(l,h=>b.append(h),f,g))}t=u}return{next:o}}var U=()=>{};function ne(e){if(Array.isArray(e))return Promise.all(e.map(ne)).then(U);if(!e||typeof e!="object"&&typeof e!="function")return Promise.resolve();let t=e;if(typeof t.playState=="string"&&typeof t.finished?.then=="function")return t.finished.then(U,U);let n=typeof t.totalDuration=="function"&&"parent"in t,r=()=>!t.parent||!t.totalDuration();return n&&r()||typeof t.then!="function"?Promise.resolve():new Promise((o,s)=>{let m=!0,f=()=>(m=!1,o());t.then(f,i=>(m=!1,s(i)));let p=Date.now()+6e4,u=()=>m&&(r()?f():Date.now()<p&&requestAnimationFrame(u));n&&requestAnimationFrame(u)})}function z(e){try{return ne(e())}catch(t){return Promise.reject(t)}}function re(e,t){for(let n of[e,t,document.body,document.documentElement]){let r=parseFloat(n?.getAttribute("data-gl-scroll-offset")??"");if(!isNaN(r))return r}return null}var I="data-gl-transition";function Oe(e,t,n,r){let o=(u,i)=>typeof u!="string"?u:e.filter(a=>a.name===u).pop()||{preset:u,at:i};if(t)return o(t,n.trigger instanceof Element?n.trigger.closest(`[${I}]`):null);let[s,m]=O(e.filter(u=>!u.once||u.leave||u.enter||u.preset||u.sync),n),f=n.next.container.getAttribute(I);if(f&&m<2)return o(f,n.next.container);if(s)return s;let p=document.querySelector('[data-gl-router="wrapper"]');return o(p?.getAttribute(I)||r,p)}var oe=(e,t)=>`${e} of transition '${t.name||"(no name)"}'`;function He(e,t,n){let[r]=O(e.filter(o=>o.once&&o.from==null),t);if(r)return t.transition=r.name||"",n(z(()=>r.once(t)),oe("once",r))}function Ne(e,t,n,r){e?.disconnect();let o=window;if(o.navigator.connection?.saveData||!o.IntersectionObserver)return null;let s=new IntersectionObserver(m=>{for(let f of m){if(!f.isIntersecting)continue;s.unobserve(f.target);let p=f.target.href;(o.requestIdleCallback||setTimeout)(()=>n(p))}});return t.querySelectorAll("a[href]").forEach(m=>r(m)&&s.observe(m)),s}var Ue=()=>({head:V(),js:te()});function ge(e){let t={},n="data-gl-transition-";for(let r of e?.attributes||[])r.name.startsWith(n)&&(t[r.name.slice(n.length).replace(/-(\w)/g,(o,s)=>s.toUpperCase())]=r.value!==""&&!isNaN(+r.value)?+r.value:r.value);return t}function ze(e,t,n){let r=e.preset;if(!r)return e;if(n&&r!=="none"&&T[r])return{...e,name:r,...T.fade({duration:.2}),sync:!1};if(!T[r])return console.warn(`[umber] router: no transition or preset "${r}" (presets: ${Object.keys(T).join(", ")}): it swaps at once.`),{name:r};let o="at"in e?{...ge(e.at),...e}:e;return{name:r,...T[r](o,t),...o}}async function Ie({t:e,d:t,o:n,gl:r,s:o,asked:s,y:m,timed:f,emit:p}){let u=document,i=t.current.container,a=t.next.container,l=t.next.document,c=n.head?o.head.prepare(l):null,g=n.scripts?[...l.scripts]:[],b=r.scroll?.scrollTo?r.scroll:null,h=v=>Promise.all([f(z(()=>e[v]?.call(e,t)),oe(v,e)),f(p(v,t),`the "${v}" hooks`)]),y=null;async function q(){await c?.styles();let v=i.getBoundingClientRect(),j=()=>{let d=i.getBoundingClientRect();Object.assign(i.style,{top:parseFloat(i.style.top)+v.top-d.top+"px",left:parseFloat(i.style.left)+v.left-d.left+"px"})};if(e.sync?(Object.assign(i.style,{position:"fixed",top:v.top+"px",left:v.left+"px",width:v.width+"px",margin:"0",pointerEvents:"none"}),j(),i.after(a),y=be(a)):i.replaceWith(a),c?.swap(),e.sync||c?.done(),n.scroll){let d=decodeURIComponent(new URL(t.next.url).hash.slice(1)),w=m??(d&&u.getElementById(d)||0),L=typeof w=="number"?0:re(t.trigger instanceof Element?t.trigger:null,w)||0;b?(b.resize(),b.scrollTo(w,{immediate:!0,force:!0,offset:L,jump:!0})):typeof w=="number"?scrollTo({top:w,left:0,behavior:"instant"}):(w.scrollIntoView({behavior:"instant"}),L&&scrollBy({top:L,behavior:"instant"}))}e.sync&&j(),await h("beforeEnter"),a.getBoundingClientRect(),u.fonts?.status==="loading"&&await Promise.race([u.fonts.ready,new Promise(d=>setTimeout(d,1e3))]),await o.js.next(g,a);let k=window.Webflow;if(n.webflow&&k?.require)try{k.destroy?.(),k.ready?.(),k.require("ix2")?.init?.(),u.dispatchEvent(new Event("readystatechange"))}catch(d){console.warn("[umber] router: Webflow did not start again on the new page:",d)}for(let d of u.links){if(a.contains(d))continue;let w=!d.hash&&d.getAttribute("href")?.[0]!=="#"&&[t.next.url,s].some(L=>H(L)===H(d.href));w?d.setAttribute("aria-current","page"):d.getAttribute("aria-current")==="page"&&d.removeAttribute("aria-current"),k&&d.classList.toggle("w--current",w)}if(b?.resize(),n.focus!==!1&&t.keyboard){let d=n.focus&&a.querySelector(n.focus)||a;d.matches("a[href],button,input,select,textarea,[tabindex]")||(d.setAttribute("tabindex","-1"),d.addEventListener("blur",()=>d.removeAttribute("tabindex"),{once:!0})),d.focus({preventScroll:!0})}}await h("beforeLeave"),e.sync?(await q(),await Promise.all([h("leave"),h("enter")]),y&&a.removeAttribute(y),i.remove(),c?.done(),await h("afterLeave")):(await h("leave"),await h("afterLeave"),await q(),await h("enter")),await h("afterEnter"),b?.resize(),n.announce&&ve(l.title||a.querySelector("h1")?.textContent||"")}function be(e){let t=getComputedStyle(e),r=!/^(none)?$/.test(t.backgroundImage)||!/^(|transparent|rgba\(.*,\s*0\))$/.test(t.backgroundColor)?"data-gl-occlude":"data-gl-above";return e.hasAttribute(r)?null:(e.setAttribute(r,""),r)}function ve(e){let t=document.querySelector("[data-gl-router-announcer]");t||(t=document.createElement("div"),t.setAttribute("data-gl-router-announcer",""),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.cssText="position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap",document.body.append(t)),t.textContent="";let n=t;setTimeout(()=>n.textContent=e,60)}export{T as PRESETS,ve as announce,Oe as choose,be as layer,ze as make,He as once,ge as optionsOf,z as outcome,Ue as session,ie as stale,Ie as swap,Ne as watch};
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ function e(){return window}var t=()=>{};function n(t){let n=e();n.requestIdleCallback?n.requestIdleCallback(t):setTimeout(t)}function r(...e){for(let t of e)if(t)return t;return""}var o='link[rel~="stylesheet"][href], style',i=e=>new URL(e??"",location.href).href,a=e=>[...e.children],l=e=>a(e.head).filter(e=>!/^(script|noscript|title)$/.test(e.localName)),u=e=>e.matches(o);function s(e){if(!e.hasAttribute("nonce"))return e;let t=e.cloneNode(!0);return t.removeAttribute("nonce"),t}function c(e,t){return e.localName===t.localName&&("link"===e.localName&&e.matches(o)?t.matches(o)&&i(e.getAttribute("href"))===i(t.getAttribute("href")):s(e).isEqualNode(s(t)))}function f(e){if("meta"===e.localName){let t=r(...["name","property","itemprop","http-equiv"].map(t=>e.getAttribute(t)));return t?`meta ${t}`:e.hasAttribute("charset")?"meta charset":""}if("base"===e.localName)return"base";if("link"===e.localName&&!u(e)){let t=t=>e.getAttribute(t)??"";return`link ${String(e.getAttribute("rel"))} ${t("hreflang")} ${t("media")} ${t("sizes")}`}return""}function m(e,t,n){let r=new Set([...t.getAttributeNames(),...n?.getAttributeNames()??[]]);for(let o of r){if("class"===o||"style"===o)continue;let r=t.getAttribute(o);n?.getAttribute(o)!==r&&(null==r?e.removeAttribute(o):e.setAttribute(o,r))}n?.classList.forEach(n=>{t.classList.contains(n)||e.classList.remove(n)}),t.classList.forEach(t=>{n?.classList.contains(t)||e.classList.add(t)})}function d(e){let t=e=>[...e.querySelectorAll("head [data-umber-router-track]")].map(e=>s(e).outerHTML).join("");return t(document)!==t(e)}function p(){let e=null;return{prepare:function(t,n,r=3e3){let o=e,s=l(t),d=()=>a(document.head),p=s.filter(e=>u(e)&&!d().some(t=>c(t,e))),h=(e,t)=>!t(e)&&!s.some(t=>c(t,e))&&(!!o&&l(o).some(t=>c(t,e))||!!f(e)&&s.some(t=>f(t)===f(e))),b=p.filter(e=>"link"===e.localName).map(e=>{let t=document.createElement("link");t.rel="preload",t.as="style",t.href=i(e.getAttribute("href"));let n=e.getAttribute("crossorigin");return null!=n&&t.setAttribute("crossorigin",n),document.head.append(t),t});return{styles(){b.forEach(e=>{e.remove()});let e=[];for(let t of p){let r=n.nonce(document.importNode(t,!0),t);r instanceof HTMLLinkElement&&e.push(new Promise(e=>{r.onload=e,r.onerror=e})),document.head.append(r)}let t,o=new Promise(e=>{t=setTimeout(e,r)});return Promise.race([Promise.all(e),o]).finally(()=>{clearTimeout(t)})},swap(){document.title=t.title;for(let e of d())h(e,u)&&e.remove();for(let e of s)!u(e)&&!d().some(t=>c(t,e))&&document.head.append(n.nonce(document.importNode(e,!0),e));m(document.documentElement,t.documentElement,o?.documentElement);let e=document.body;e&&m(e,t.body,o?.body)},done(){for(let e of d())u(e)&&h(e,()=>!1)&&e.remove();e=t}}},know(t){e??=t}}}function h(e,t){if(Array.isArray(e))return e.some(e=>h(e,t));if("function"==typeof e)return e(t);let n=new URL(t.url,location.href).pathname;return e instanceof RegExp?(e.lastIndex=0,e.test(n)):e.startsWith("/")?(e=>new RegExp(`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}/?$`))(e).test(n):e===t.page}function b(e,t){let n=0,r=t.trigger instanceof Element?t.trigger:null;if(null!=e.from){if(!h(e.from,t.current))return-1;n+=1}if(null!=e.to){if(!h(e.to,t.next))return-1;n+=2}if(null!=e.links){if(!r||!function(e,t){if("function"==typeof e)return e(t);try{return t.matches(e)}catch{return!1}}(e.links,r))return-1;n+=4}if(e.custom){if(!e.custom(t))return-1;n+=8}return n}function y(e,t){let n,r=-1;for(let o of e){let e=b(o,t);e>=0&&e>=r&&(n=o,r=e)}return[n,r]}function v(e){let t=new URL(e,location.href);return t.hash="",t.href}var g={warn:t,error:t};function w(e){e&&(g=e)}var A="cubic-bezier(0.76, 0, 0.24, 1)",x=(e,t,n)=>({duration:1e3*(e.duration??t),easing:r(e.ease,n),fill:"both"});function $(e){let n=[],r=[],o=[];return{anim(r,o,i,a){if(!r||!(e=>"function"==typeof e.animate)(r))return;let l=r.animate(o,i);return n.push(l),e&&function(e,t){let n=t.now(),r=Number(e.effect?.getComputedTiming().endTime??0),o=n,i=performance.now(),a=1,l=t.each(()=>{if("idle"===e.playState)return void l();let u=t.now(),s=performance.now(),c=u-n;if(c>=r)return l(),void e.finish();s-i>=4&&(a=u===o?0:a+((u-o)/(s-i)-a)/2,o=u,i=s,Math.abs(a-e.playbackRate)>.05&&e.updatePlaybackRate(a)),Math.abs(Number(e.currentTime??0)-c)>12&&(e.currentTime=c)})}(l,e),l.finished.then(()=>{a||l.cancel()},t)},panel(e="#111"){let t=document.createElement("div");return t.setAttribute("aria-hidden","true"),t.style.cssText=`position:fixed;inset:0;z-index:2147483000;pointer-events:none;background:${e}`,document.body.append(t),r.push(t),t},also(e){o.push(e)},undo:()=>{n.forEach(e=>{e.cancel()}),r.forEach(e=>{e.remove()}),o.forEach(e=>{e()})}}}var E=e=>"back"===e.direction?-1:1,k=(e,t)=>{e.next.container&&Object.assign(e.next.container.style,t)};function S(e){return(t,n,r)=>{let o=$(r),i=null,a=t=>"curtain"===e?{transform:`translateY(${100*t}%)`}:{clipPath:C(t)};return{leave:n=>(i=o.panel(t.color),o.anim(i,[a("curtain"===e?E(n):-E(n)),a(0)],x(t,.65,A),!0)),enter:n=>Promise.resolve(o.anim(i,[a(0),a("curtain"===e?-E(n):E(n))],x(t,.65,A),!0)).finally(()=>{i?.remove()}),undo:o.undo}}}function C(e){return e>0?"inset(0 0 0 100%)":e<0?"inset(0 100% 0 0)":"inset(0)"}var P={"router-cover":"vec2 s = uViewport / uViewport.y, p = vUv * s, c = uOrigin * s;\nfloat far = max(max(length(c), length(c - vec2(s.x, 0.0))), max(length(c - vec2(0.0, 1.0)), length(c - s)));\nfloat r = uCover * (far + 0.12);\ncolor = vec4(uColor.rgb, uColor.a * (1.0 - smoothstep(r - 0.12, r, distance(p, c))));","router-dissolve":"vec2 p = vUv * uViewport / uViewport.y * 5.0, i = floor(p), f = fract(p), k = vec2(127.1, 311.7);\nf = f * f * (3.0 - 2.0 * f);\nvec4 h = fract(sin(vec4(dot(i, k), dot(i + vec2(1.0, 0.0), k), dot(i + vec2(0.0, 1.0), k), dot(i + 1.0, k))) * 43758.5453);\nfloat n = mix(mix(h.x, h.y, f.x), mix(h.z, h.w, f.x), f.y) * 0.75 + fract(sin(dot(floor(p * 9.0), k)) * 43758.5453) * 0.25;\nfloat edge = uCover * 1.5 - 0.3 + ((uDirection < 0.0 ? 1.0 - vUv.y : vUv.y) - 0.5) * 0.15;\ncolor = vec4(uColor.rgb, uColor.a * smoothstep(n - 0.12, n + 0.12, edge));"},L=new WeakMap;function T(e){return(t,n,o)=>{let i=$(o),a=null,l=null,u=null,s=()=>{u&&(u[0].style.zIndex=u[1]),u=null};i.also(s);let c=e=>l?.tween("uCover",{value:e,duration:t.duration??.8,ease:r(t.ease,"expo.inOut")})??i.anim(a,[{opacity:1-e},{opacity:e}],x(t,.6,A),!0);return{async leave(o){let s=r(t.shader,e);if(n&&function(e,t){let n=P[t],r=L.get(e);void 0===n||r?.has(t)||(r?r.add(t):L.set(e,new Set([t])),e.shader(t,{animate:!1,uniforms:{uCover:0,uOrigin:[.5,.5],uDirection:1,uColor:"#111"},fragment:n}))}(n,s),a=i.panel("transparent"),a.setAttribute("data-umber-cover",""),l=await async function(e,r,o){let i=n?await n.add(e,{type:"shader",shader:r,order:1e4}).catch(()=>null):null;if(!i||!("uCover"in i.uniforms))return null;let a=(e,t)=>{e in i.uniforms&&i.set(e,t)};return a("uCover",0),a("uOrigin",o.origin?[o.origin[0]/innerWidth,o.origin[1]/innerHeight]:[.5,.5]),a("uDirection",E(o)),t.color&&a("uColor",t.color),"ready"!==i.status&&await function(e){return new Promise(t=>{let n=()=>{clearTimeout(o),r.forEach(e=>{e()}),t()},r=[e.on("ready",n),e.on("error",n)],o=setTimeout(n,1e3)})}(i),"ready"===i.status?i:null}(a,s,o),l){if((e=>null!=e&&!1!==e&&"false"!==e)(t.above)){let e=n?.canvas?.parentElement;e&&(u=[e,e.style.zIndex],e.style.zIndex="2147483000")}}else n?.canvas&&g.warn(`[umber] router: the ${e.slice(7)} transition could not draw ${t.shader?`the shader "${t.shader}" (is it defined with umber.shader("${t.shader}", { uniforms: { uCover: 0 }, fragment: ... })?)`:"its shader"}: a plain panel fades instead.`),a.style.background=r(t.color,"#111");return c(1)},enter:()=>Promise.resolve(c(0)).finally(()=>{a?.remove(),s()}),undo:i.undo}}}var q={none:()=>({}),fade:function(e,t,n){let r=$(n);return{leave:t=>r.anim(t.current.container,[{opacity:1},{opacity:0}],x(e,.4,"cubic-bezier(0.4, 0, 1, 1)"),!0),beforeEnter(e){k(e,{opacity:"0"})},enter(t){let n=r.anim(t.next.container,[{opacity:0},{opacity:1}],x(e,.4,"cubic-bezier(0, 0, 0.2, 1)"));return k(t,{opacity:""}),n},undo:r.undo}},slide:function(e,t,n){let r=$(n),o=e=>`translateX(${e}%)`,i=document.documentElement.style,a=null;return{sync:!0,beforeEnter(e){a=i.overflowX,i.overflowX="clip",k(e,{transform:o(100*E(e)),position:"relative",zIndex:"1",boxShadow:"0 0 80px rgb(0 0 0 / 0.18)"})},leave:t=>r.anim(t.current.container,[{transform:o(0),filter:"brightness(1)"},{transform:o(-30*E(t)),filter:"brightness(0.7)"}],x(e,.9,A),!0),enter(t){let n=r.anim(t.next.container,[{transform:o(100*E(t))},{transform:o(0)}],x(e,.9,A));return k(t,{transform:""}),Promise.resolve(n).finally(()=>{k(t,{position:"",zIndex:"",boxShadow:""}),null!=a&&(i.overflowX=a),a=null})}}},zoom:function(e,t,n){let r=$(n);return{leave:t=>r.anim(t.current.container,[{opacity:1,transform:"scale(1)"},{opacity:0,transform:"scale(0.94)"}],x(e,.5,"cubic-bezier(0.5, 0, 0.75, 0)"),!0),beforeEnter(e){k(e,{opacity:"0"})},enter(t){let n=r.anim(t.next.container,[{opacity:0,transform:"scale(1.06)"},{opacity:1,transform:"scale(1)"}],x(e,.7,"cubic-bezier(0.16, 1, 0.3, 1)"));return k(t,{opacity:""}),n},undo:r.undo}},curtain:S("curtain"),wipe:S("wipe"),cover:T("router-cover"),dissolve:T("router-dissolve"),native:()=>({native:!0})},N=/^\s*(text\/javascript|application\/javascript|module)?\s*$/i,O=e=>N.test(e.getAttribute("type")??"")&&!e.matches("[data-umber~=skip]")&&!(e.hasAttribute("nomodule")&&"noModule"in e),R=e=>{let t=e.getAttribute("src");return t?"src "+new URL(t,location.href).href:e.textContent},z=/already been declared|redeclaration of|duplicate variable/i,j="glRan",I=(e,t)=>{let n=/^\s*(["'])use strict\1;?/.exec(e)?.[0]??"";return`${n}${t?`document.currentScript.${j}=1;`:""}{\n${e.slice(n.length)}\n}`+(t?`\n//# sourceURL=${t}`:"")};function D(e){let t=customElements,n=Object.getOwnPropertyDescriptor(t,"define"),r=n?n.value:null;t.define=(e,n,o)=>{t.get(e)||(r?r.call(t,e,n,o):CustomElementRegistry.prototype.define.call(t,e,n,o))};try{e()}finally{n?Object.defineProperty(t,"define",n):Reflect.deleteProperty(t,"define")}}function U(e,t,n,{trust:r,again:o=!1}){let i=e.getAttribute("src"),a=!/module/i.test(e.type),l=e.hasAttribute("async"),u=e,s=(t,n)=>{let o=u=document.createElement("script");for(let t of e.attributes)(n||"src"!==t.name&&"integrity"!==t.name)&&o.setAttribute(t.name,t.value);return r.nonce(o,e),o.textContent=t,l||(o.async=!1),o},c=(r,o=!1,i=t)=>{let u=s(r,o),c=o&&!l?new Promise(e=>{let t=setTimeout(e,n),r=()=>{clearTimeout(t),e()};u.onload=r,u.onerror=r}):null;return o||!a?(i(u),c??Promise.resolve()):(function(e,t){let n=!1,r=e=>{z.test(e.message)&&(n=!0,e.preventDefault())};return addEventListener("error",r),D(()=>{t(e)}),removeEventListener("error",r),n}(u,i)&&D(()=>{u.replaceWith(s(I(e.textContent),!1))}),Promise.resolve())};if(!o||!a)return c(e.textContent,!!i);if(!i)return c(I(e.textContent));let f=new URL(i,location.href).href,m=async function(e,t){let n=await fetch(e,t);if(!n.ok)throw new Error(`${e} answered ${n.status}`);return n}(f,{integrity:e.integrity}).then(e=>e.text()).then(e=>{let t=c(I(e,f)),n=u;return j in n?t:c(null,!0,e=>{n.replaceWith(e)})},()=>c(null,!0));return l?Promise.resolve():m}function W(){let e=new Set((r=document,[...r.querySelectorAll("script")]).map(R)),t=new Set([...e].filter(e=>e.startsWith("src "))),n=new Set(e);var r;return{next:async function(r,o,i,{cap:a=3e3,all:l=4e3}={}){let u=new Set,s=Date.now()+l,c=e=>Date.now()<s?e:null;for(let l of r){if(!O(l)||i.refused(l))continue;let r=R(l),s=n.has(r);if(n.add(r),[o].flat().some(e=>e.contains(l))){await c(U(l,e=>{l.replaceWith(e)},a,{trust:i,again:s}));continue}if(u.add(r),e.has(r)||t.has(r))continue;r.startsWith("src ")&&t.add(r);let f=l.closest("head")?document.head:document.body;await c(U(l,e=>{f.append(e)},a,{trust:i,again:s}))}e=u}}}var B="[data-umber~=container]",M=e=>{let t=e.nonce;return t?.length?t:e.getAttribute("nonce")??""};function V(){let e=e=>[...document.querySelectorAll(e)].map(M).find(Boolean)??"",t=e("script[nonce]"),n=e("style[nonce],link[nonce]");return{script:t||n,style:n||t}}var F=e=>"object"==typeof e&&null!==e||"function"==typeof e,X=e=>F(e)&&"then"in e&&"function"==typeof e.then,H=e=>!e.parent||!e.totalDuration();function J(e){if(Array.isArray(e))return Promise.all(e.map(J)).then(t);if(!F(e))return Promise.resolve();if((e=>"playState"in e&&"string"==typeof e.playState&&"finished"in e&&X(e.finished))(e))return new Promise(t=>{e.finished.then(()=>{t()},()=>{t()})});let n=(e=>"totalDuration"in e&&"function"==typeof e.totalDuration&&"parent"in e)(e)?e:null;if(n&&H(n)||!X(e))return Promise.resolve();let r=new Promise((t,n)=>{e.then(()=>{t()},n)});return n?Promise.race([r,Y(n,r)]):r}function Y(e,t){let n=!0,r=()=>{n=!1};t.then(r,r);let o=Date.now()+6e4;return new Promise(t=>{let r=()=>{n&&(H(e)?t():Date.now()<o&&requestAnimationFrame(r))};requestAnimationFrame(r)})}async function G(e){await J(e())}var K="data-umber-transition";function Q(e,t,{asked:n,arriving:o,fallback:i}){let a=(t,n)=>"string"!=typeof t?t:e.filter(e=>e.name===t).pop()??{preset:t,at:n};if(n)return a(n,t.trigger instanceof Element?t.trigger.closest(`[${K}]`):null);let[l,u]=y(e.filter(ee),t),s=o.getAttribute(K);if(s&&u<2)return a(s,o);if(l)return l;let c=document.querySelector("[data-umber~=wrapper]");return a(r(c?.getAttribute(K),i),c)}function Z(e,t,{asked:n,fallback:o,named:i}){let a=(t,n)=>"string"!=typeof t?t:e.filter(e=>e.name===t).pop()??{preset:t,at:n};if(n)return a(n,t.trigger instanceof Element?t.trigger.closest(`[${K}]`):null);let l=e.filter(ee);if(l.some(e=>"function"==typeof e.custom||null!=e.to&&!_(e.to)))return null;let[u,s]=y(l,t);if(s<2&&""!==i)return null;if(u)return u;let c=document.querySelector("[data-umber~=wrapper]");return a(r(c?.getAttribute(K),o),c)}var _=e=>Array.isArray(e)?e.every(_):e instanceof RegExp||"string"==typeof e&&e.startsWith("/"),ee=e=>!e.once||[e.leave,e.enter,e.preset,e.sync].some(Boolean),te=(e,t)=>`${e} of transition '${t.name??"(no name)"}'`;function ne(e,t,n){let[r]=y(e.filter(e=>"function"==typeof e.once&&null==e.from),t);if(r)return t.transition=r.name??"",n(G(()=>r.once(t)),te("once",r))}function re(t,r,{fetch:o,allowed:i,limit:a}){if(t?.disconnect(),function(){let e=navigator;return!0===e.connection?.saveData||(e.connection?.effectiveType??"").includes("2g")}()||!e().IntersectionObserver||a<1)return null;let l=new Set,u=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;u.unobserve(t.target);let e=t.target.href;if(!l.has(v(e))&&(l.add(v(e)),l.size>=a&&u.disconnect(),n(()=>{o(e)}),l.size>=a))return}});for(let e of r.querySelectorAll("a[href]"))i(e)&&u.observe(e);return u}var oe=()=>({nonce:V(),head:p(),js:W()});function ie({t:e,d:t,timed:n,emit:r,again:o}){return i=>Promise.all([n(G(()=>e[i]?.call(e,t)),te(i,e)),o&&/leave$/i.test(i)?null:n(r(i,t),`the "${i}" hooks`)])}function ae(e,t){return e===t||!!e.preset&&e.preset===t.preset&&JSON.stringify({...ue(e.at),...e,at:0})===JSON.stringify({...ue(t.at),...t,at:0})}async function le(e){let t=ie(e);await t("beforeLeave"),await t("leave"),await t("afterLeave")}function ue(e){let t={};for(let n of e?.attributes??[])n.name.startsWith("data-umber-transition-")&&(t[n.name.slice(22).replace(/-(\w)/g,(e,t)=>t.toUpperCase())]=""===n.value||isNaN(+n.value)?n.value:+n.value);return t}function se(e,t,n,r){let o=e.preset;if(!o)return e;let i=function(e){let t=q;return Object.prototype.hasOwnProperty.call(q,e)?t[e]:void 0}(o);if(!i)return g.warn(`[umber] router: no transition or preset "${o}" (presets: ${Object.keys(q).join(", ")}): it swaps at once.`),{name:o};let a="at"in e?{...ue(e.at),...e}:e;return n&&"none"!==o||"native"===o&&!fe()?{...e,name:o,...q.fade(n?{duration:.1}:a,void 0,r),sync:!1}:{name:o,...i(a,t,r),...a}}var ce=()=>document,fe=()=>"function"==typeof ce().startViewTransition;function me(e){let t="data-umber-router-update",n=[];for(let r of document.querySelectorAll(`[${t}]`)){if(r.closest(B))continue;let o=[...e.querySelectorAll(`[${t}="${CSS.escape(r.getAttribute(t)??"")}"]`)].find(e=>!e.closest(B));o?(r.replaceWith(o),n.push(o)):r.remove()}return n}async function de(n){let{t:r,d:o,o:i,gl:a,s:l,asked:u,spot:s,timed:c}=n,f=n.leaving,m=n.arriving,d=n.document,p=function(e,t,n){let r=[t,...[...n.head.querySelectorAll(":scope > meta[http-equiv]")].filter(e=>/^content-security-policy$/i.test(e.httpEquiv)).map(e=>e.content)].join(",").split(","),o=e=>r.flatMap(t=>{let n=t.split(";").map(e=>e.trim().split(/\s+/)),r=[`${e}-src-elem`,`${e}-src`,"default-src"].map(e=>n.find(([t])=>t?.toLowerCase()===e)).find(Boolean);return r?.some(e=>/^'nonce-/i.test(e))?[r.slice(1)]:[]}),i={script:o("script"),style:o("style")},a=e=>(e=>"script"===e.localName||/modulepreload/i.test(e.getAttribute("rel")??"")||"script"===e.getAttribute("as"))(e)?"script":"style",l=e=>{let t=M(e),n=i[a(e)];return!!t&&n.length>0&&n.every(e=>e.some(e=>/^'nonce-/i.test(e)&&e.slice(7,-1)===t))};return{nonce(t,n){let r=e[a(n)];return r&&l(n)?t.setAttribute("nonce",r):t.removeAttribute("nonce"),t},refused:e=>!l(e)&&i.script.some(e=>e.some(e=>"'strict-dynamic'"===e.toLowerCase()))}}(l.nonce,n.csp,d),h=i.head?l.head.prepare(d,p):null,b=i.scripts?[...d.scripts]:[],y=a.scroll?.scrollTo?a.scroll:null,w=ie(n);async function A(){await(h?.styles());let t=null,n=null;r.sync&&(n=function(e){let t=e.getBoundingClientRect(),n=()=>{let n=e.getBoundingClientRect();Object.assign(e.style,{top:parseFloat(e.style.top)+t.top-n.top+"px",left:parseFloat(e.style.left)+t.left-n.left+"px"})};return Object.assign(e.style,{position:"fixed",top:`${t.top}px`,left:`${t.left}px`,width:`${t.width}px`,margin:"0",pointerEvents:"none"}),n(),n}(f)),f.after(m),function(e,t){let n="data-umber-router-persist";for(let r of t.querySelectorAll(`[${n}]`)){let t=e.querySelector(`[${n}="${CSS.escape(r.getAttribute(n)??"")}"]`),o=r.parentNode;!t||!o||(o.moveBefore?o.moveBefore(t,r):o.insertBefore(t,r),r.remove())}}(f,m),r.sync?t=pe(m):f.remove();let a=[m,...me(d)];return h?.swap(),r.sync||h?.done(),i.scroll&&function(e,t,n){let r=t?.y??function(e){if(!e)return null;let t=document.getElementById(e);if(t)return t;try{return document.getElementById(decodeURIComponent(e))}catch{return null}}(new URL(e.next.url).hash.slice(1))??0,o="number"==typeof r?0:function(e,t){for(let n of[e,t,document.body,document.documentElement]){let e=parseFloat(n?.getAttribute("data-umber-scroll-offset")??"");if(!isNaN(e))return e}return null}(e.trigger instanceof Element?e.trigger:null,r)??0;n?(n.resize(),n.scrollTo(r,{immediate:!0,force:!0,offset:o,jump:!0})):"number"==typeof r?scrollTo({top:r,left:0,behavior:"instant"}):(r.scrollIntoView({behavior:"instant"}),o&&scrollBy({top:o,behavior:"instant"})),t?.x&&scrollTo({left:t.x,behavior:"instant"});for(let[e,[n,r]]of Object.entries(t?.els??{}))document.querySelector(`[data-umber-router-scroll="${CSS.escape(e)}"]`)?.scrollTo({left:n,top:r,behavior:"instant"})}(o,s,y),n?.(),await w("beforeEnter"),m.getBoundingClientRect(),await async function(){let e=document.fonts;"loading"===e?.status&&await Promise.race([e.ready,new Promise(e=>setTimeout(e,1e3))])}(),await l.js.next(b,a,p),function(e,t,n){for(let r of document.links){if(e.contains(r))continue;let o=!r.hash&&"#"!==r.getAttribute("href")?.[0]&&t.some(e=>v(e)===v(r.href));o?r.setAttribute("aria-current","page"):"page"===r.getAttribute("aria-current")&&r.removeAttribute("aria-current"),n&&r.classList.toggle("w--current",o)}}(m,[o.next.url,u],function(t){let n=e().Webflow;if(t&&n?.require)try{n.destroy?.(),n.ready?.(),n.require("ix2")?.init?.(),document.dispatchEvent(new Event("readystatechange"))}catch(e){g.warn("[umber] router: Webflow did not start again on the new page:",e)}return void 0!==n}(i.webflow)),y?.resize(),!1!==i.focus&&o.keyboard&&function(e,t){let n=(t?e.querySelector(t):null)??e;n.matches("a[href],button,input,select,textarea,[tabindex]")||(n.setAttribute("tabindex","-1"),n.addEventListener("blur",()=>{n.removeAttribute("tabindex")},{once:!0})),n.focus({preventScroll:!0})}(m,i.focus),t}if(r.sync){await w("beforeLeave");let e=await A();await Promise.all([w("leave"),w("enter")]),e?.(),f.remove(),h?.done(),await w("afterLeave")}else if(r.native&&fe()){n.left||await le(n);let e=ce().startViewTransition?.(A);await c(e?.updateCallbackDone,te("put",r)),await Promise.all([w("enter"),c(e?.finished.catch(t),te("view transition",r))])}else n.left||await le(n),await A(),await w("enter");await w("afterEnter"),y?.resize(),i.announce&&be(d.title||(m.querySelector("h1")?.textContent??""))}function pe(e){let t=getComputedStyle(e);if(!/^(none)?$/.test(t.backgroundImage)||!he(t.backgroundColor))return e.hasAttribute("data-umber-occlude")?null:(e.setAttribute("data-umber-occlude",""),()=>{e.removeAttribute("data-umber-occlude")});let n=e.getAttribute("data-umber");return e.matches("[data-umber~=above]")?null:(e.setAttribute("data-umber",n?`${n} above`:"above"),()=>{null===n?e.removeAttribute("data-umber"):e.setAttribute("data-umber",n)})}function he(e){let t=e.trim();if(""===t||"transparent"===t)return!0;let n=/\((.*)\)$/.exec(t)?.[1]??"",r=n.split(","),o=4===r.length?r[3]:null;if(n.includes("/")&&(o=n.slice(n.lastIndexOf("/")+1)),null==o)return!1;let i=o.trim();return"none"===i||0===parseFloat(i)}function be(e){let t=document.querySelector("[data-umber-router-announcer]");t||(t=document.createElement("div"),t.setAttribute("data-umber-router-announcer",""),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.cssText="position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap",document.body.append(t)),t.textContent="";let n=t;setTimeout(()=>{n.textContent=e},60)}export{q as PRESETS,be as announce,w as bindLog,Q as choose,he as clear,Z as early,pe as layer,le as leave,se as make,ne as once,ue as optionsOf,G as outcome,ae as same,oe as session,d as stale,de as swap,re as watch};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- "use strict";(()=>{var be="https://umber.occluze.com";var Le="data-gl-router-prevent",Me=/\.(pdf|zip|rar|7z|gz|tgz|dmg|exe|apk|mp[34]|m4a|mov|webm|ogg|wav|jpe?g|png|gif|webp|avif|svg|ico|csv|xlsx?|docx?|pptx?|txt|xml|json|rss|ics)$/i;function b(t){let d=new URL(t,location.href);return d.hash="",d.href}function Z(t,d,i){let a=t.getAttribute("href"),n=t.getAttribute("target");if(a==null||a[0]==="#"||n&&n!=="_self"||t.hasAttribute("download")||/(^|\s)external(\s|$)/i.test(t.getAttribute("rel")||"")||t.closest(`[${Le}]`))return null;let u;try{u=new URL(a,document.baseURI)}catch{return null}return u.origin!==location.origin||!/^https?:$/.test(u.protocol)||Me.test(u.pathname)||u.hash&&b(u)===b(location.href)||d?.(t,i)?null:u}function we(t,d){if(!d||d.search||/log-?(out|off)|sign-?out/i.test(d.pathname)||b(d)===b(location.href))return!1;let i=t.getAttribute("data-method")||t.getAttribute("data-turbo-method");return!(i&&i.toLowerCase()!=="get")&&!t.matches("[data-confirm],[data-remote],[data-turbo-confirm]")&&t.closest('[data-gl-router-prefetch="false"]')==null}function ve(t,d){if(t.defaultPrevented||t.button||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return null;let a=(t.composedPath?.()[0]||t.target)?.closest?.("a[href],area[href]"),n=a&&Z(a,d,t);return n?{a,url:n}:null}var ee="umberRouter";function ye(t){let d=()=>history.state&&typeof history.state=="object"?history.state:{},i=()=>d()[ee],a=i()?.i??0,n=location.href,u=t(),g=new Map,p=(f,s)=>`${f} ${s}`,m=f=>history.replaceState({...d(),[ee]:{i:a,u:location.href,...f}},""),R=history.scrollRestoration,h=f=>{try{history.scrollRestoration=f}catch{}};return{get url(){return n},own(){h("manual"),i()||m()},release(){h(R||"auto")},hide(){m({y:u}),h("auto")},push(f){g.set(p(a,n),u=t()),m({y:u}),history.pushState({[ee]:{i:++a,u:f}},"",f),g.delete(p(a,f)),n=location.href,u=0},replace(f){history.replaceState(history.state,"",f),n=location.href},moved(){let f=i();g.set(p(a,n),u);let s=f&&f.i<a?"back":"forward";return a=f?f.i:a+1,f||m(),n=location.href,[s,g.get(p(a,n))??(f?.u===n?f.y:void 0)]},scrolled(){n!==location.href&&this.moved(),g.set(p(a,n),u=t())},landed(){u=t()}}}function Re(t,d){let i=new Map,a=(u,g)=>i.get(u)===g&&i.delete(u);function n(u,g){let p=b(u),m=i.get(p);if(m)return i.delete(p),i.set(p,m),m.p;let R=new AbortController,h=setTimeout(()=>R.abort(),d()),f=m={ctl:R,p:fetch(p,{signal:R.signal,credentials:"same-origin",headers:{accept:"text/html,application/xhtml+xml"},...g?{priority:"low"}:{}}).then(async s=>{if(s.url&&new URL(s.url).origin!==location.origin)throw new Error(`${p} redirects to another site`);if(!s.ok||s.status===204||/attachment/i.test(s.headers.get("content-disposition")||"")||!/html/i.test(s.headers.get("content-type")||""))throw new Error(`${p} answered ${s.status} ${s.headers.get("content-type")||""}`);let y=await s.text();return(/no-store/i.test(s.headers.get("cache-control")||"")||!t())&&a(p,f),{url:b(s.url||p),html:y}}).finally(()=>{clearTimeout(h),f.done=!0})};m.p.catch(()=>a(p,f)),i.set(p,m);for(let s of i.keys()){if(i.size<=Math.max(t(),1))break;s!==p&&i.delete(s)}return m.p}return{load:n,abortOthers(u){let g=b(u);for(let[p,m]of i)p!==g&&!m.done&&m.ctl.abort()}}}var Ae='[data-gl-router="wrapper"]',re='[data-gl-router="container"]',Ee="data-gl-transition",Ne={transition:"fade",prefetch:"hover",cache:10,timeout:6e3,focus:"h1",announce:!0,scroll:!0,scripts:!0,head:!0,webflow:!0,prevent:null},te={load(t,d){d?location.replace(t):location.assign(t)},reload:()=>location.reload()},O=t=>(t.querySelector(Ae)||t).querySelector(re),_=(t,d,i)=>({url:d,page:t?.getAttribute("data-gl-page")||"",container:t,document:i}),_e="",xe=t=>_e=t,ke=null,Ie=()=>ke||=import(_e+"router-swap.js").catch(t=>{throw ke=null,t});function He(t,d={}){let i={...Ne,...d},a=window,n=document,u=n.documentElement,g=[],p=new Map,m=Re(()=>i.cache,()=>i.timeout),R=[],h=(e,r,o,c)=>{e.addEventListener(r,o,c),R.push(()=>e.removeEventListener(r,o,c))},f=()=>history.state&&typeof history.state=="object"?history.state:{},s=null,y=null,x=!1,E=!1,A=!1,P=()=>Promise.resolve(),U=b(location.href),V=!1,T,$=null,oe=null,L=()=>oe||=Ie().then(e=>[e,e.session()],e=>(oe=null,Promise.reject(e))),N=()=>t.scroll?.scrollTo?t.scroll:null,ne=e=>new DOMParser().parseFromString(e,"text/html"),Te=location.href,Se=null,ie=()=>Se||=m.load(Te,!0).then(e=>ne(e.html),()=>null),v=ye(()=>N()?.animatedScroll??scrollY),se=(e,r)=>{let o=N();o?o.scrollTo(e,{immediate:!r,force:!0,jump:!r}):typeof e=="number"?scrollTo({top:e,left:0,behavior:r?"smooth":"instant"}):e.scrollIntoView({behavior:"instant"})},ae=()=>!!matchMedia?.("(prefers-reduced-motion: reduce)").matches,F=(e,r)=>{let o=[...p.get(e)||[]];return o.length?L().then(([c])=>Promise.all(o.map(l=>c.outcome(()=>l(r)))).then(()=>{})):Promise.resolve()},z=(e,r)=>{let o;return Promise.race([e,new Promise((c,l)=>o=setTimeout(()=>l(new Error(`${r} took over ${i.timeout} ms`)),i.timeout))]).finally(()=>clearTimeout(o))},I=!1,K=(e,r,o,c="forward",l=null)=>({current:e,next:r,trigger:o,direction:c,origin:l,reducedMotion:ae(),keyboard:I,transition:""});function W(e,r,o={}){let c,l,w=new Promise((G,S)=>(c=G,l=S));return w.catch(()=>{}),{url:e,trigger:r,direction:"forward",origin:null,...o,done:w,resolve:c,reject:l}}let le=(e,r)=>r.done.then(e.resolve,e.reject);function Y(e){return E||(s&&!s.started&&(s.dropped=!0,le(s,e),s=null),s?(y&&le(y,e),y=e):de(e)),e.done}function Oe(e){let r=!T;P=t.transition?.(e)||P,r&&(N()?.stop(),T=setTimeout(()=>{let o=t.hold?.(),c=P;P=async()=>o?.(),c()},7e3))}async function ue(){if(!x)return;x=!1,u.removeAttribute("data-gl-router-busy");let e=P;P=()=>Promise.resolve(),T&&N()?.start(),clearTimeout(T),T=void 0,v.landed(),await e()}async function ce(e,r){s===e&&(s=null);let o=y;y=null,o||await ue(),r&&await F("after",r).catch(c=>console.error("[umber] router: after",c)),e.resolve(),o&&de(o)}function fe(e,r){e.dropped||E||(console.warn(`[umber] router: loading ${e.url} in full:`,r),p.get("error")?.forEach(o=>{try{o({error:r,url:e.url})}catch{}}),s===e&&(s=null),y?.reject(r),y=null,V=!0,ue(),te.load(e.url,!!e.shown),e.reject(r))}async function de(e){s=e,A=!0,V=!1;let r=O(n);if(!r)return fe(e,new Error("this page has no "+re));if(b(e.url)===U)return e.trigger instanceof Element&&se(0,!ae()),ce(e);x=!0,u.setAttribute("data-gl-router-busy",""),m.abortOthers(e.url),ie();let o=K(_(r,U),_(null,e.url),e.trigger,e.direction,e.origin);try{await z(F("before",o),'the "before" hooks');let[c,[l,w],G]=await Promise.all([m.load(e.url),L(),ie()]);if(e.dropped)return;w.head.know(G);let S=ne(c.html),J=O(S);if(!J)throw new Error(`${c.url} has no ${re}`);if(l.stale(S))throw new Error(`${c.url} has changed tracked <head> elements`);let M=c.url+new URL(e.url).hash;e.started=!0,e.pop?b(M)!==b(e.url)&&v.replace(M):v.push(M),e.shown=!0,Oe(S),o.next=_(J,M,S);let ge=l.make(l.choose(g,e.transition,o,i.transition),t,o.reducedMotion);o.transition=ge.name||"",await l.swap({t:ge,d:o,o:i,gl:t,s:w,asked:e.url,y:e.y,timed:z,emit:F}),U=b(M),i.prefetch==="viewport"&&($=l.watch($,J,D,Q))}catch(c){return fe(e,c)}return ce(e,o)}let pe=!t.licensed||t.licence===!0,k=()=>pe&&!E&&!!O(n)&&!Ue(),me=!1;function Ue(){let r=[["Barba",a.barba?.init],["Swup",a.swup||a.Swup],["Turbo",a.Turbo?.session],["htmx hx-boost",a.htmx&&n.querySelector("[hx-boost]")],["Astro's client router",n.querySelector('meta[name="astro-view-transitions-enabled"]')],["WordPress's Interactivity API",f().wpInteractivityId!=null||n.querySelector("[data-wp-interactive]")]].find(([,o])=>o)?.[0]||"";return r&&!me&&console.warn(`[umber] router: ${r} runs on this page too, so Umber's router stays off. Use one of them.`),me||=!!r,r}h(n,"keydown",()=>I=!0,{capture:!0}),h(n,"pointerdown",()=>I=!1,{capture:!0}),h(n,"click",e=>{e.detail===0&&(I=!0);let r=k()&&ve(e,i.prevent);if(!r)return;e.preventDefault();let o=r.a.closest(`[${Ee}]:not([data-gl-router])`);Y(W(r.url.href,r.a,{origin:e.detail?[e.clientX,e.clientY]:null,transition:o?.getAttribute(Ee)||void 0}))}),h(window,"popstate",()=>{if(!k())return;let[e,r]=v.moved();if(b(v.url)===U&&!s){let o=decodeURIComponent(location.hash.slice(1));return se(r??(o&&n.getElementById(o)||0))}Y(W(v.url,"popstate",{direction:e,pop:!0,shown:!0,y:r}))}),h(window,"hashchange",()=>k()&&v.url!==location.href&&v.moved()),h(window,"scroll",()=>x||!k()||v.scrolled(),{passive:!0});let H=()=>k()&&v.own();n.readyState==="loading"?h(n,"DOMContentLoaded",H):H(),t.licensed?.().then(e=>{pe=e,e&&!E&&n.readyState!=="loading"&&H()}),h(window,"pagehide",()=>{V&&(E=!0),k()&&v.hide()}),h(window,"pageshow",e=>{if(e.persisted&&(E||x))return te.reload();H()});let D=e=>m.load(e,!0).then(()=>{},()=>{}),Q=e=>we(e,Z(e,i.prevent)),j,X=e=>{let r=i.prefetch&&k()&&e.target?.closest?.("a[href]");clearTimeout(j),r&&Q(r)&&(j=setTimeout(()=>D(r.href),e.type==="pointerover"?65:0))};h(n,"pointerover",X,{passive:!0}),h(n,"touchstart",X,{passive:!0}),h(n,"focusin",X),h(n,"pointerout",()=>clearTimeout(j),{passive:!0}),(a.requestIdleCallback||setTimeout)(()=>{k()&&L().then(([e])=>i.prefetch==="viewport"&&($=e.watch($,n,D,Q)),()=>{})});let he=!1;function $e(){he||A||(he=!0,(t.licensed?.()??Promise.resolve(!0)).then(e=>{let r=O(n);if(!e||A||E||!r)return;let o=t.transition?.(),c=K(_(null,""),_(r,location.href),"load");L().then(([l])=>l.once(g,c,z)).catch(l=>console.warn("[umber] router: the first page's intro:",l)).finally(()=>o?.())}))}t.on("destroy",()=>{R.splice(0).forEach(e=>e()),$?.disconnect(),E=!0,clearTimeout(T),clearTimeout(j),u.removeAttribute("data-gl-router-busy"),v.release(),t.router===B&&delete t.router});let B={options:i,get busy(){return x},get url(){return U},get page(){return O(n)?.getAttribute("data-gl-page")||""},go(e,r={}){let o=new URL(e,location.href);return/^https?:$/.test(o.protocol)?o.origin!==location.origin?(te.load(o.href,!1),Promise.reject(new Error(`${o.href} is on another site`))):Y(W(o.href,r.trigger??"go",{transition:r.transition})):Promise.reject(new Error(`http(s) URLs only: ${o.protocol}`))},prefetch:D,transition(e){return g.push(e),e.once&&$e(),()=>{let r=g.indexOf(e);r>=0&&g.splice(r,1)}},on(e,r){let o=p.get(e);return o||p.set(e,o=new Set),o.add(r),()=>void o.delete(r)},view(e,r){let o=["beforeEnter","afterEnter","beforeLeave","afterLeave"].map(l=>B.on(l,w=>w[l.endsWith("Enter")?"next":"current"].page===e?r[l]?.(w):void 0)),c=O(n);if(!A&&c?.getAttribute("data-gl-page")===e){let l=K(_(null,""),_(c,location.href),"load");L().then(([w])=>w.outcome(()=>r.beforeEnter?.(l)).then(()=>w.outcome(()=>r.afterEnter?.(l)))).catch(w=>console.error(`[umber] router: view "${e}"`,w))}return()=>o.forEach(l=>l())}};return t.router=B,B}var C={name:"router",version:"0.2.1",attributes:[],install(t,d){He(t,d)}};var q=window,Pe=document.currentScript?.src;xe(Pe?Pe.replace(/[^/]*$/,""):`${be}/umber@0.2.1/modules/`);q.Umber?.use?q.Umber.use(C):((q.UmberModules||=[]).push(C),q.__umber?.engine?.use?.(C));})();
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ (()=>{function e(){return window}function t(e,t=location.href){try{return new URL(e,t)}catch{return null}}function r(e){return("string"==typeof e?t(e):e)?.origin===location.origin}var n=()=>{};function o(...e){for(let t of e)if(t)return t;return""}var i="[data-umber~=skip]",s=/\.(pdf|zip|rar|7z|gz|tgz|dmg|exe|apk|mp[34]|m4a|mov|webm|ogg|wav|jpe?g|png|gif|webp|avif|svg|ico|csv|xlsx?|docx?|pptx?|txt|xml|json|rss|ics)$/i;function a(e){let t=new URL(e,location.href);return t.hash="",t.href}function l(e,n,o){let l=e.getAttribute("href"),u=e.getAttribute("target");if(null==l||l.startsWith("#")||u&&"_self"!==u||e.hasAttribute("download")||/(^|\s)external(\s|$)/i.test(e.getAttribute("rel")??"")||e.closest(i))return null;let h=t(l,document.baseURI);return!h||!r(h)||!/^https?:$/.test(h.protocol)||s.test(h.pathname)||h.hash&&a(h)===a(location.href)||n?.(e,o)?null:h}var u="umberRouter";function h(){let e=history.state;return"object"==typeof e&&null!==e?{...e}:{}}var c=(e,t)=>e.headers.get(t)??"";function d(e,t,{timeout:n,headers:o},i){let s=new AbortController,l=setTimeout(()=>{s.abort()},n());return{p:fetch(e,{...t,signal:s.signal,credentials:"same-origin",headers:{...o(),accept:"text/html,application/xhtml+xml"}}).then(async n=>{if(n.url&&!r(n.url))throw new Error(`${e} redirects to another site`);if(!n.ok&&!t.body||204===n.status||/attachment/i.test(c(n,"content-disposition"))||!/html/i.test(c(n,"content-type")))throw new Error(`${e} answered ${n.status} ${c(n,"content-type")}`);let o=await n.text();i(n);let s=a(n.url||e);return{url:s,html:o,csp:c(n,"content-security-policy"),redirected:s!==e}}).finally(()=>{clearTimeout(l)}),ctl:s}}var m={warn:n,error:n},f="",p=null,g="[data-umber~=wrapper]",w="[data-umber~=container]",b="data-umber-transition",y={transition:"fade",prefetch:"hover",cache:10,timeout:6e3,focus:"h1",announce:!0,scroll:!0,scripts:!0,head:!0,webflow:!0,prevent:null,wait:!1,headers:{}},v={load(e,{replace:t=!1}={}){t?location.replace(e):location.assign(e)},reload(){location.reload()},submit(e,t){try{e.requestSubmit(t)}catch{e.requestSubmit()}}};function k(){let e=navigator;return!0===e.connection?.saveData||(e.connection?.effectiveType??"").includes("2g")}var x=e=>(e.querySelector(g)??e).querySelector(w),S=(e,t,r)=>({url:t,page:e?.getAttribute("data-umber-page")??"",container:e,document:r});function P(e,t,r={}){let{promise:o,resolve:i,reject:s}=function(){let e,t;return{promise:new Promise((r,n)=>{e=r,t=n}),resolve:e,reject:t}}();return o.catch(n),{url:e,trigger:t,direction:"forward",origin:null,...r,done:o,resolve:i,reject:s}}var $=e=>!0===e.dropped,q=(e,t)=>{t.done.then(e.resolve,e.reject)},A=e=>(new DOMParser).parseFromString(e,"text/html"),E=class{constructor(e,t,r){this.gl=e,this.o=t,this.ahead=r,this.change={kind:"idle"},this.open=!1,this.gone=!1,this.started=!1,this.keyed=!1,this.here=a(location.href),this.defs=[],this.hooks=new Map,this.errorHooks=[],this.resent=new WeakSet,this.io=null,this.end=()=>Promise.resolve(),this.held=!1,this.swapper=null,this.firstDoc=null,this.firstUrl=location.href,this.leaving=null,this.named=new Map,this.naming=!1,this.warmed=new WeakSet,this.waiting=[],this.requests=0,this.emit=(e,t)=>{let r=this.hooks.get(e),o=r?T(r):[];return o.length?this.ready().then(([e])=>Promise.all(o.map(r=>e.outcome(()=>r(t)))).then(n)):Promise.resolve()},this.timed=(e,t)=>{let r=n;return Promise.race([e,new Promise((e,n)=>{r=this.clock.after(this.o.timeout,()=>{n(new Error(`${t} took over ${this.o.timeout} ms`))})})]).finally(()=>{r()})},this.prefetch=e=>this.load(e,{lowPriority:!0,warm:!0}).then(n,n),this.view=e=>{k()||!this.o.cache||(this.waiting.push(e),this.pump())},this.cache=function(e){let{max:t}=e,r=new Map,o=(e,t)=>{r.get(e)===t&&r.delete(e)};function i(e,t){t.done?r.delete(e):t.forgotten=!0}return{load:function(n,{lowPriority:s=!1,fresh:l=!1}={}){let u=a(n),h=r.get(u);if(h&&!l)return r.delete(u),r.set(u,h),h.p;h&&i(u,h);let m={...d(u,s?{priority:"low"}:{},e,e=>{(/no-store/i.test(c(e,"cache-control"))||!t()||m.forgotten)&&o(u,m)})};m.p.then(()=>{m.done=!0},()=>{m.done=!0,o(u,m)}),r.set(u,m);for(let e of r.keys()){if(r.size<=Math.max(t(),1))break;e!==u&&r.get(e)?.done&&r.delete(e)}return m.p},send:(t,r)=>d(a(t),{method:"POST",body:r},e,n).p,abortOthers(...e){let t=new Set(e.map(a));for(let[e,n]of r)!t.has(e)&&!n.done&&n.ctl.abort()},has:e=>r.has(a(e))&&!r.get(a(e))?.forgotten,delete:e=>{let t=a(e),n=r.get(t);return n&&i(t,n),!!n},clear:()=>{for(let[e,t]of r)i(e,t)}}}({max:()=>t.cache,timeout:()=>t.timeout,headers:()=>t.headers}),this.hist=function(e){let t=()=>{let e=h()[u];return(e=>"object"==typeof e&&null!==e&&"i"in e&&"number"==typeof e.i&&"u"in e&&"string"==typeof e.u)(e)?e:void 0},r=t()?.i??0,n=location.href,o=e(!1),i=new Map,s=(e,t)=>`${e} ${t}`,a=(e,t)=>{i.delete(e),i.set(e,t),i.size>100&&i.delete(i.keys().next().value??"")},l=()=>{let t={...o,els:e(!0).els};return a(s(r,n),t),t},c=e=>{let t=e?{x:e.x,y:e.y,e:e.els}:{};history.replaceState({...h(),[u]:{i:r,u:location.href,...t}},"")},d=history.scrollRestoration,m=e=>{try{history.scrollRestoration=e}catch{}};return{get url(){return n},own(){m("manual"),t()||c()},release(){m(d??"auto")},hide(){c({...o,els:e(!0).els}),m("auto")},push(t){o=e(!1),c(l()),history.pushState({[u]:{i:++r,u:t}},"",t),i.delete(s(r,t)),n=location.href,o={x:0,y:0}},replace(e){i.delete(s(r,n)),history.replaceState({...h(),[u]:{i:r,u:new URL(e,location.href).href}},"",e),n=location.href},moved(){let e=t();l();let o=e&&e.i<r?"back":"forward";r=e?e.i:r+1,e||c(),n=location.href;let a=e?.u===n&&"number"==typeof e.y?{x:e.x??0,y:e.y,els:e.e}:void 0;return[o,i.get(s(r,n))??a]},scrolled(){n!==location.href&&this.moved(),o=e(!1),a(s(r,n),o)},landed(){o=e(!1)}}}(e=>this.where(e)),this.clock=function(e){let t,r=0,n=0,o=!1,i=!1,s=0,a=null,l=new Set,u=()=>{for(let e of[...l])e()},h=()=>{t=setTimeout(()=>{if(!1===e.loop?.playing)n=performance.now(),u();else if(o)s=0;else if(++s>=(i?2:1)){let e=performance.now();r+=e-n,n=e,u()}o=!1,l.size&&h()},100)},c=()=>{a?.(),a=null,clearTimeout(t)},d=t=>(l.add(t),a||(n=performance.now(),o=!1,i=!1,s=0,a=e.on("frame",e=>{r+=1e3*e.dt,n=performance.now(),o=!0,i=!0,s=0,u()},{phase:"measure",order:-1500,label:"router"}),h()),()=>{l.delete(t),l.size||c()});return{now:()=>r,each:d,after(e,t){let n=r+e,o=d(()=>{r<n||(o(),t())});return o},stop(){l.clear(),c()}}}(e);let o=x(document);this.learn(location.href,o?.getAttribute("data-umber-transition")??"")}where(e){let t={x:scrollX,y:this.smooth()?.animatedScroll??scrollY};if(!e)return t;for(let e of document.querySelectorAll("[data-umber-router-scroll]")){let r=e.getAttribute("data-umber-router-scroll");r&&((t.els??={})[r]=[e.scrollLeft,e.scrollTop])}return t}ready(){return this.swapper??=(p??=import(f+"router-swap.js").then(e=>(e.bindLog(m),e),e=>{throw p=null,e})).then(e=>[e,e.session()],e=>{throw this.swapper=null,e})}smooth(){return this.gl.scroll?.scrollTo?this.gl.scroll:null}reduced(){return(e().matchMedia?window.matchMedia("(prefers-reduced-motion: reduce)"):null)?.matches??!1}jump(e,t){let r=this.smooth();r?r.scrollTo(e,{immediate:!t,force:!0,jump:!t}):"number"==typeof e?scrollTo({top:e,left:0,behavior:t?"smooth":"instant"}):e.scrollIntoView({behavior:"instant"})}data(e,t,r,n){return{current:e,next:t,trigger:r,direction:n?.direction??"forward",origin:n?.origin??null,reducedMotion:this.reduced(),keyboard:this.keyed,transition:""}}first(){return this.firstDoc??=this.cache.load(this.firstUrl,{lowPriority:!0}).then(e=>A(e.html),()=>null)}namedAt(e){let t=a(e);return this.named.has(t)?this.named.get(t):this.naming?void 0:""}learn(e,t){this.named.set(a(e),t),t&&(this.naming=!0)}load(e,{lowPriority:t=!1,warm:r=!1,fresh:i=!1}={}){let s=this.cache.load(e,{lowPriority:t,fresh:i});return s.then(t=>{let n=function(e){let t=/<[a-z][^>]*\sdata-umber\s*=\s*["']?(?:[^"'>]*\s)?container\b[^>]*>/i.exec(e)?.[0]??"",r=/\sdata-umber-transition\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(t);return o(r?.[1],r?.[2],r?.[3])}(t.html);if(this.learn(e,n),this.learn(t.url,n),r&&this.gl.preload&&!this.warmed.has(t)){this.warmed.add(t);try{this.gl.preload(A(t.html))}catch(e){m.warn("[umber] router: umber.preload():",e)}}},n),s}pump(){for(;this.requests<4&&this.waiting.length;){let e=this.waiting.shift()??"";this.cache.has(e)||(this.requests++,this.load(e,{lowPriority:!0}).catch(n).finally(()=>{this.requests--,this.pump()}))}}request(e){if(this.gone)return e.done;let t=this.change;return"running"!==t.kind?(this.start(e),e.done):t.nav.started?(t.queued&&q(t.queued,e),t.queued=e,e.body||this.load(e.url,{warm:!0}).catch(n),e.done):(t.nav.dropped=!0,q(t.nav,e),this.start(e),e.done)}begin(e){if(this.held)return;let t=!this.cap;this.end=this.gl.transition?.(e)??this.end,t&&(this.smooth()?.stop(),this.cap=setTimeout(()=>{this.held=!0;let e=this.gl.hold?.(),t=this.end;this.end=()=>(e?.(),Promise.resolve()),t()},7e3))}mark(e){this.open=e;let t=document.documentElement;e?(t.setAttribute("data-umber-router-busy",""),t.setAttribute("aria-busy","true")):(t.removeAttribute("data-umber-router-busy"),t.removeAttribute("aria-busy"))}async close(){if(!this.open)return;this.mark(!1);let e=this.end;this.end=()=>Promise.resolve(),this.cap&&this.smooth()?.start(),clearTimeout(this.cap),this.cap=void 0,this.held=!1,this.hist.landed(),await e()}async settle(e,t){let r=this.change,n="running"===r.kind&&r.nav===e?r.queued:null;n?this.change={kind:"running",nav:n,queued:null}:("running"===r.kind&&r.nav===e&&(this.change={kind:"idle"}),await this.close()),t&&await this.emit("after",t).catch(e=>{m.error("[umber] router: after",e)}),e.resolve(),n&&!n.dropped&&this.start(n)}fail(e,t){if(e.dropped||this.gone)return;m.warn(`[umber] router: loading ${e.url} in full:`,t);let r=this.data(S(x(document),this.here),S(null,e.url),e.trigger,e);for(let n of T(this.errorHooks))try{n({...r,error:t,url:e.url})}catch{}"running"===this.change.kind&&this.change.queued?.reject(t),this.leaving?.t.undo?.(),this.leaving=null,this.change={kind:"leaving"},this.close();let n=e.form;e.body&&n&&!e.shown?(this.resent.add(n.el),v.submit(n.el,n.submitter)):v.load(e.body?location.href:e.url,{replace:!!e.shown}),e.reject(t)}async start(e){this.change={kind:"running",nav:e,queued:null},this.started=!0;let t=x(document);if(!t)return void this.fail(e,new Error("this page has no "+w));if(a(e.url)===this.here&&!this.leaving&&!e.body)return e.trigger instanceof Element&&this.jump(0,!this.reduced()),this.settle(e);this.mark(!0),this.waiting.length=0,this.cache.abortOthers(e.url,this.firstUrl),this.first();let r=this.data(S(t,this.here),S(null,e.url),e.trigger,e);try{if(!await this.run(e,r,t))return}catch(t){return void this.fail(e,t)}return this.settle(e,r)}leaveNow(e,t,r){if(this.leaving)return this.leaving;let o=this.namedAt(e.url),i=this.o.wait?null:r.early(this.defs,t,{asked:e.transition,fallback:this.o.transition,named:o}),s=i&&r.make(i,this.gl,t.reducedMotion,this.clock);if(!i||!s||s.sync||s.wait||s.native)return null;t.transition=s.name??"",this.begin();let{timed:l,emit:u}=this,h=r.leave({t:s,d:t,timed:l,emit:u});h.catch(n);let c=""!==o||this.named.has(a(e.url))?"":e.url;return this.leaving={t:s,from:i,done:h,guess:c}}async run(e,t,r){if(await this.timed(this.emit("before",t),'the "before" hooks'),$(e))return!1;let o=e.body?this.cache.send(e.url,e.body):this.load(e.url,{warm:!0,fresh:!!e.form});o.catch(n);let[i,s]=await this.ready();if($(e))return!1;let l=this.leaveNow(e,t,i),[u,h]=await Promise.all([o,this.first()]);if($(e))return!1;s.head.know(h);let c=A(u.html),d=x(c);if(!d)return this.fail(e,new Error(`${u.url} has no ${w}`)),!1;if(i.stale(c))return this.fail(e,new Error(`${u.url} has changed tracked <head> elements`)),!1;let m=!!e.body&&!u.redirected,f=m?location.href:u.url+new URL(e.url).hash;m&&(e.replace=!0),t.next=S(d,f,c);let{t:p,again:g}=this.transitionOf(e,l,i,{data:t,arriving:d});if(t.transition=p.name??"",l&&(await l.done,$(e)))return!1;this.show(e,f,c);let{o:b,gl:y,timed:v,emit:k}=this;return await i.swap({t:p,d:t,o:b,gl:y,s:s,asked:e.url,spot:e.spot,timed:v,emit:k,left:!!l&&!g,again:g,leaving:r,arriving:d,document:c,csp:u.csp}),this.here=a(f),"viewport"===b.prefetch&&(this.io=i.watch(this.io,d,{fetch:this.view,allowed:this.ahead,limit:b.cache})),!0}transitionOf(e,t,r,{data:n,arriving:o}){let i=e=>r.make(e,this.gl,n.reducedMotion,this.clock),s=()=>r.choose(this.defs,n,{asked:e.transition,arriving:o,fallback:this.o.transition});if(!t)return{t:i(s()),again:!1};let a=t.guess===e.url&&t.t.undo?s():null;return!a||r.same(a,t.from)?{t:t.t,again:!1}:(t.t.undo?.(),this.leaving=null,{t:i(a),again:!0})}show(e,t,r){e.started=!0,this.leaving=null,e.pop?a(t)!==a(e.url)&&this.hist.replace(t):e.replace?this.hist.replace(t):this.hist.push(t),e.shown=!0,this.begin(r)}destroy(){this.io?.disconnect(),this.waiting.length=0,this.gone=!0,clearTimeout(this.cap),this.mark(!1),this.clock.stop(),this.hist.release()}};function T(e){let t=e.slice().sort((e,t)=>e.order-t.order);for(let r of t)r.once&&e.splice(e.indexOf(r),1);return t.map(e=>e.hook)}function U(e,t,r={}){let n={hook:t,once:!!r.once,order:r.order??0};return e.push(n),()=>{let t=e.indexOf(n);t>=0&&e.splice(t,1)}}function L(e){return{transition:e.closest(`[${b}]:not(${w},${g})`)?.getAttribute(b)??void 0,replace:"replace"===e.closest("[data-umber-router-history]")?.getAttribute("data-umber-router-history")}}var j,M={textureSource:()=>"umber.texture(source) needs a canvas, ImageBitmap, video, image, ImageData or { data, width, height }.",textureSize:()=>"umber.texture(numbers) needs their size: umber.texture({ data, width, height }), 1, 2 or 4 numbers per texel.",routerProtocol:e=>`umber.router.go(url): http(s) URLs only, not ${e}`},I=class extends Error{constructor(e,...t){super(`[umber] ${M[e](...t)}`),this.code=e,this.name="UmberError"}};function R(s,u={}){let c={...y,...u};c.headers={...c.headers};let d=new E(s,c,e=>function(e,t){if(!t||t.search||/log-?(out|off)|sign-?out/i.test(t.pathname)||a(t)===a(location.href))return!1;let r=e.getAttribute("data-method")??e.getAttribute("data-turbo-method");return!(r&&"get"!==r.toLowerCase()||e.matches("[data-confirm],[data-remote],[data-turbo-confirm]")||null!=e.closest('[data-umber-router-prefetch="false"]'))}(e,l(e,c.prevent))),f=[],p=(e=>(t,r,n,o)=>{e.push(function(e,t,r,n){let o=r;return e.addEventListener(t,o,n),()=>{e.removeEventListener(t,o,n)}}(t,r,n,o))})(f),g=!s.licensed||!0===s.licence,w=s.licensed?.().then(e=>g=e),b=function(t,r,n){let o=!1;return()=>{if(!r()||t.gone||!n())return!1;let i=function(){let t=e();return[["Barba",t.barba?.init],["Swup",t.swup??t.Swup],["Turbo",t.Turbo?.session],["htmx hx-boost",t.htmx&&document.querySelector("[hx-boost]")],["Astro's client router",document.querySelector('meta[name="astro-view-transitions-enabled"]')],["WordPress's Interactivity API",null!=h().wpInteractivityId||document.querySelector("[data-wp-interactive]")]].find(([,e])=>e)?.[0]??""}();return i&&!o&&(o=!0,m.warn(`[umber] router: ${i} runs on this page too, so Umber's router stays off. Use one of them.`)),!i}}(d,()=>g,()=>!!x(document));(function(e,n,s){let a=t=>()=>{e.keyed=t};n(document,"keydown",a(!0),{capture:!0}),n(document,"pointerdown",a(!1),{capture:!0}),n(document,"click",t=>{0===t.detail&&(e.keyed=!0);let r=function(e,t){if(e.defaultPrevented||e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return null;let r=e.composedPath(),n=r.length?r[0]:e.target,o=n instanceof Element?n.closest("a[href],area[href]"):null,i=o&&l(o,t,e);return i?{a:o,url:i}:null}(t,e.o.prevent);if(!r||!s())return;t.preventDefault(),"running"!==e.change.kind&&e.mark(!0);let n=t.detail?[t.clientX,t.clientY]:null;queueMicrotask(()=>{e.request(P(r.url.href,r.a,{origin:n,...L(r.a)}))})}),n(document,"submit",n=>{let a=s()&&!e.resent.delete(n.target)&&function(e,n){let s=e.target;if(e.defaultPrevented||!(s instanceof HTMLFormElement)||!s.closest("[data-umber-router-form]"))return null;let a,l=e.submitter,u=(e,t)=>l?.getAttribute(e)??s.getAttribute(t),h=(u("formmethod","method")??"get").toLowerCase(),c=(u("formenctype","enctype")??"").toLowerCase(),d=u("formtarget","target"),m=t(o(u("formaction","action"),location.href),document.baseURI);if(!m||!/^(get|post)$/.test(h)||"text/plain"===c||d&&"_self"!==d||!r(m)||!/^https?:$/.test(m.protocol)||s.closest(i)||n?.(s,e))return null;try{a=new FormData(s,l)}catch{a=new FormData(s)}let f=new URLSearchParams([...a].map(([e,t])=>[e,"string"==typeof t?t:t.name]));return"get"===h?(m.search=f.toString(),{form:s,by:l,url:m,body:void 0}):{form:s,by:l,url:m,body:"multipart/form-data"===c?a:f}}(n,e.o.prevent);a&&(n.preventDefault(),e.request(P(a.url.href,a.form,{...L(a.form),body:a.body,form:{el:a.form,submitter:a.by}})))})})(d,p,b),function(e,t,r){let{hist:n}=e;t(window,"popstate",t=>{if(!r())return;let[o,i]=n.moved();if(a(n.url)===e.here&&"running"!==e.change.kind)return void e.jump(i?.y??function(e){if(!e)return null;let t=document.getElementById(e);if(t)return t;try{return document.getElementById(decodeURIComponent(e))}catch{return null}}(location.hash.slice(1))??0);let s=!0===t.hasUAVisualTransition;e.request(P(n.url,"popstate",{direction:o,pop:!0,shown:!0,spot:i,...s?{transition:"none"}:{}}))}),t(window,"hashchange",()=>{r()&&n.url!==location.href&&n.moved()}),t(window,"scroll",()=>{!e.open&&r()&&n.scrolled()},{passive:!0})}(d,p,b),function(e,t,r,n){let o=()=>{r()&&e.hist.own()};"loading"===document.readyState?t(document,"DOMContentLoaded",o):o(),n?.then(t=>{t&&!e.gone&&"loading"!==document.readyState&&o()}),t(window,"pagehide",()=>{"leaving"===e.change.kind&&(e.gone=!0),r()&&e.hist.hide()}),t(window,"pageshow",t=>{t.persisted&&(e.gone||e.open)?v.reload():o()})}(d,p,b,w);let $=function(e,t,r){let o,i=t=>{let i=e.o.prefetch&&r()&&t.target instanceof Element?t.target.closest("a[href]"):null;if(clearTimeout(o),!i||!e.ahead(i)||k())return;let s="pointerdown"===t.type;s&&0!==t.button||(o=setTimeout(()=>{e.load(i.href,{lowPriority:!s,warm:!0}).catch(n)},"pointerover"===t.type?65:0))},s=()=>{clearTimeout(o)};return t(document,"pointerover",i,{passive:!0}),t(document,"touchstart",i,{passive:!0}),t(document,"focusin",i),t(document,"pointerdown",i,{passive:!0,capture:!0}),t(document,"pointerout",s,{passive:!0}),s}(d,p,b);(function(t){let r=e();r.requestIdleCallback?r.requestIdleCallback(t):setTimeout(t)})(()=>{b()&&d.ready().then(([e])=>{"viewport"===c.prefetch&&(d.io=e.watch(d.io,document,{fetch:d.view,allowed:d.ahead,limit:c.cache}))},n)}),s.on("destroy",()=>{f.splice(0).forEach(e=>{e()}),$(),d.destroy(),s.router===q&&delete s.router});let q=function(e,t){let{cache:n}=e,o={options:e.o,get busy(){return e.open},get url(){return e.here},get page(){return x(document)?.getAttribute("data-umber-page")??""},go(t,n={}){let o=new URL(t,location.href);return/^https?:$/.test(o.protocol)?r(o)?e.request(P(o.href,n.trigger??"go",{transition:n.transition,replace:"replace"===n.history})):(v.load(o.href),Promise.reject(new Error(`${o.href} is on another site`))):Promise.reject(new I("routerProtocol",o.protocol))},prefetch:e.prefetch,cache:{clear:n.clear,delete:n.delete,has:n.has},transition:r=>(function(e){if("string"!=typeof e)return!1;try{return document.createDocumentFragment().querySelector(e),!1}catch{return!0}}(r.links)&&m.error(`[umber] router: transition "${r.name??""}": links "${String(r.links)}" is not a valid selector, so it matches no link`),e.defs.push(r),r.once&&t(),()=>{let t=e.defs.indexOf(r);t>=0&&e.defs.splice(t,1)}),on:function(...[t,r,n]){if("error"===t)return U(e.errorHooks,r,n);let o=e.hooks.get(t)??[];return e.hooks.set(t,o),U(o,r,n)},view(t,r){let n=["beforeEnter","afterEnter","beforeLeave","afterLeave"].map(e=>o.on(e,n=>n[e.endsWith("Enter")?"next":"current"].page===t?r[e]?.(n):void 0)),i=x(document);if(!e.started&&i?.getAttribute("data-umber-page")===t){let n=e.data(S(null,""),S(i,location.href),"load");e.ready().then(([e])=>e.outcome(()=>r.beforeEnter?.(n)).then(()=>e.outcome(()=>r.afterEnter?.(n)))).catch(e=>{m.error(`[umber] router: view "${t}"`,e)})}return()=>{n.forEach(e=>{e()})}}};return o}(d,function(e){let t=!1;return()=>{t||e.started||(t=!0,(e.gl.licensed?.()??Promise.resolve(!0)).then(t=>{let r=x(document);if(!t||e.started||e.gone||!r)return;let n=e.gl.transition?.(),o=e.data(S(null,""),S(r,location.href),"load");e.ready().then(([t])=>t.once(e.defs,o,e.timed)).catch(e=>{m.warn("[umber] router: the first page's intro:",e)}).finally(()=>n?.())}))}}(d));return s.router=q,q}!function(t){let r=function(e){(e=>{f=e})(e?.src?e.src.replace(/[^/]*$/,""):"https://umber.occluze.com/umber@0.3.0/modules/")}?.(document.currentScript instanceof HTMLScriptElement?document.currentScript:null),n=e();n.Umber?.use?n.Umber.use(t,r):(n.UmberModules??=[],n.UmberModules.push(r?[t,r]:t),n.__umber?.engine?.use?.(t,r))}({name:"router",version:"0.3.0",attributes:[],install:(j=({engine:e,options:t})=>{R(e,t)},(...e)=>{let[t,r,n,o,i]=e;(function(e){e&&(m=e)})(i),j({engine:t,options:r,keep:n,root:o})})})})();
@@ -1,2 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- var ge="data-gl-router-prevent",Se=/\.(pdf|zip|rar|7z|gz|tgz|dmg|exe|apk|mp[34]|m4a|mov|webm|ogg|wav|jpe?g|png|gif|webp|avif|svg|ico|csv|xlsx?|docx?|pptx?|txt|xml|json|rss|ics)$/i;function b(t){let d=new URL(t,location.href);return d.hash="",d.href}function C(t,d,i){let a=t.getAttribute("href"),n=t.getAttribute("target");if(a==null||a[0]==="#"||n&&n!=="_self"||t.hasAttribute("download")||/(^|\s)external(\s|$)/i.test(t.getAttribute("rel")||"")||t.closest(`[${ge}]`))return null;let u;try{u=new URL(a,document.baseURI)}catch{return null}return u.origin!==location.origin||!/^https?:$/.test(u.protocol)||Se.test(u.pathname)||u.hash&&b(u)===b(location.href)||d?.(t,i)?null:u}function be(t,d){if(!d||d.search||/log-?(out|off)|sign-?out/i.test(d.pathname)||b(d)===b(location.href))return!1;let i=t.getAttribute("data-method")||t.getAttribute("data-turbo-method");return!(i&&i.toLowerCase()!=="get")&&!t.matches("[data-confirm],[data-remote],[data-turbo-confirm]")&&t.closest('[data-gl-router-prefetch="false"]')==null}function J(t,d){if(t.defaultPrevented||t.button||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return null;let a=(t.composedPath?.()[0]||t.target)?.closest?.("a[href],area[href]"),n=a&&C(a,d,t);return n?{a,url:n}:null}var Z="umberRouter";function we(t){let d=()=>history.state&&typeof history.state=="object"?history.state:{},i=()=>d()[Z],a=i()?.i??0,n=location.href,u=t(),g=new Map,p=(f,s)=>`${f} ${s}`,m=f=>history.replaceState({...d(),[Z]:{i:a,u:location.href,...f}},""),R=history.scrollRestoration,h=f=>{try{history.scrollRestoration=f}catch{}};return{get url(){return n},own(){h("manual"),i()||m()},release(){h(R||"auto")},hide(){m({y:u}),h("auto")},push(f){g.set(p(a,n),u=t()),m({y:u}),history.pushState({[Z]:{i:++a,u:f}},"",f),g.delete(p(a,f)),n=location.href,u=0},replace(f){history.replaceState(history.state,"",f),n=location.href},moved(){let f=i();g.set(p(a,n),u);let s=f&&f.i<a?"back":"forward";return a=f?f.i:a+1,f||m(),n=location.href,[s,g.get(p(a,n))??(f?.u===n?f.y:void 0)]},scrolled(){n!==location.href&&this.moved(),g.set(p(a,n),u=t())},landed(){u=t()}}}function ve(t,d){let i=new Map,a=(u,g)=>i.get(u)===g&&i.delete(u);function n(u,g){let p=b(u),m=i.get(p);if(m)return i.delete(p),i.set(p,m),m.p;let R=new AbortController,h=setTimeout(()=>R.abort(),d()),f=m={ctl:R,p:fetch(p,{signal:R.signal,credentials:"same-origin",headers:{accept:"text/html,application/xhtml+xml"},...g?{priority:"low"}:{}}).then(async s=>{if(s.url&&new URL(s.url).origin!==location.origin)throw new Error(`${p} redirects to another site`);if(!s.ok||s.status===204||/attachment/i.test(s.headers.get("content-disposition")||"")||!/html/i.test(s.headers.get("content-type")||""))throw new Error(`${p} answered ${s.status} ${s.headers.get("content-type")||""}`);let y=await s.text();return(/no-store/i.test(s.headers.get("cache-control")||"")||!t())&&a(p,f),{url:b(s.url||p),html:y}}).finally(()=>{clearTimeout(h),f.done=!0})};m.p.catch(()=>a(p,f)),i.set(p,m);for(let s of i.keys()){if(i.size<=Math.max(t(),1))break;s!==p&&i.delete(s)}return m.p}return{load:n,abortOthers(u){let g=b(u);for(let[p,m]of i)p!==g&&!m.done&&m.ctl.abort()}}}var _e='[data-gl-router="wrapper"]',te='[data-gl-router="container"]',ye="data-gl-transition",Oe={transition:"fade",prefetch:"hover",cache:10,timeout:6e3,focus:"h1",announce:!0,scroll:!0,scripts:!0,head:!0,webflow:!0,prevent:null},ee={load(t,d){d?location.replace(t):location.assign(t)},reload:()=>location.reload()},O=t=>(t.querySelector(_e)||t).querySelector(te),x=(t,d,i)=>({url:d,page:t?.getAttribute("data-gl-page")||"",container:t,document:i}),Ae="",Ve=t=>Ae=t,Re=null,Le=()=>Re||=import("./router-swap.js").catch(t=>{throw Re=null,t});function Me(t,d={}){let i={...Oe,...d},a=globalThis,n=document,u=n.documentElement,g=[],p=new Map,m=ve(()=>i.cache,()=>i.timeout),R=[],h=(e,r,o,c)=>{e.addEventListener(r,o,c),R.push(()=>e.removeEventListener(r,o,c))},f=()=>history.state&&typeof history.state=="object"?history.state:{},s=null,y=null,P=!1,E=!1,N=!1,T=()=>Promise.resolve(),A=b(location.href),V=!1,S,L=null,re=null,M=()=>re||=Le().then(e=>[e,e.session()],e=>(re=null,Promise.reject(e))),$=()=>t.scroll?.scrollTo?t.scroll:null,oe=e=>new DOMParser().parseFromString(e,"text/html"),Ee=location.href,ke=null,ne=()=>ke||=m.load(Ee,!0).then(e=>oe(e.html),()=>null),v=we(()=>$()?.animatedScroll??scrollY),ie=(e,r)=>{let o=$();o?o.scrollTo(e,{immediate:!r,force:!0,jump:!r}):typeof e=="number"?scrollTo({top:e,left:0,behavior:r?"smooth":"instant"}):e.scrollIntoView({behavior:"instant"})},se=()=>!!matchMedia?.("(prefers-reduced-motion: reduce)").matches,B=(e,r)=>{let o=[...p.get(e)||[]];return o.length?M().then(([c])=>Promise.all(o.map(l=>c.outcome(()=>l(r)))).then(()=>{})):Promise.resolve()},F=(e,r)=>{let o;return Promise.race([e,new Promise((c,l)=>o=setTimeout(()=>l(new Error(`${r} took over ${i.timeout} ms`)),i.timeout))]).finally(()=>clearTimeout(o))},H=!1,z=(e,r,o,c="forward",l=null)=>({current:e,next:r,trigger:o,direction:c,origin:l,reducedMotion:se(),keyboard:H,transition:""});function K(e,r,o={}){let c,l,w=new Promise((X,_)=>(c=X,l=_));return w.catch(()=>{}),{url:e,trigger:r,direction:"forward",origin:null,...o,done:w,resolve:c,reject:l}}let ae=(e,r)=>r.done.then(e.resolve,e.reject);function W(e){return E||(s&&!s.started&&(s.dropped=!0,ae(s,e),s=null),s?(y&&ae(y,e),y=e):fe(e)),e.done}function xe(e){let r=!S;T=t.transition?.(e)||T,r&&($()?.stop(),S=setTimeout(()=>{let o=t.hold?.(),c=T;T=async()=>o?.(),c()},7e3))}async function le(){if(!P)return;P=!1,u.removeAttribute("data-gl-router-busy");let e=T;T=()=>Promise.resolve(),S&&$()?.start(),clearTimeout(S),S=void 0,v.landed(),await e()}async function ue(e,r){s===e&&(s=null);let o=y;y=null,o||await le(),r&&await B("after",r).catch(c=>console.error("[umber] router: after",c)),e.resolve(),o&&fe(o)}function ce(e,r){e.dropped||E||(console.warn(`[umber] router: loading ${e.url} in full:`,r),p.get("error")?.forEach(o=>{try{o({error:r,url:e.url})}catch{}}),s===e&&(s=null),y?.reject(r),y=null,V=!0,le(),ee.load(e.url,!!e.shown),e.reject(r))}async function fe(e){s=e,N=!0,V=!1;let r=O(n);if(!r)return ce(e,new Error("this page has no "+te));if(b(e.url)===A)return e.trigger instanceof Element&&ie(0,!se()),ue(e);P=!0,u.setAttribute("data-gl-router-busy",""),m.abortOthers(e.url),ne();let o=z(x(r,A),x(null,e.url),e.trigger,e.direction,e.origin);try{await F(B("before",o),'the "before" hooks');let[c,[l,w],X]=await Promise.all([m.load(e.url),M(),ne()]);if(e.dropped)return;w.head.know(X);let _=oe(c.html),G=O(_);if(!G)throw new Error(`${c.url} has no ${te}`);if(l.stale(_))throw new Error(`${c.url} has changed tracked <head> elements`);let U=c.url+new URL(e.url).hash;e.started=!0,e.pop?b(U)!==b(e.url)&&v.replace(U):v.push(U),e.shown=!0,xe(_),o.next=x(G,U,_);let he=l.make(l.choose(g,e.transition,o,i.transition),t,o.reducedMotion);o.transition=he.name||"",await l.swap({t:he,d:o,o:i,gl:t,s:w,asked:e.url,y:e.y,timed:F,emit:B}),A=b(U),i.prefetch==="viewport"&&(L=l.watch(L,G,j,Y))}catch(c){return ce(e,c)}return ue(e,o)}let de=!t.licensed||t.licence===!0,k=()=>de&&!E&&!!O(n)&&!Pe(),pe=!1;function Pe(){let r=[["Barba",a.barba?.init],["Swup",a.swup||a.Swup],["Turbo",a.Turbo?.session],["htmx hx-boost",a.htmx&&n.querySelector("[hx-boost]")],["Astro's client router",n.querySelector('meta[name="astro-view-transitions-enabled"]')],["WordPress's Interactivity API",f().wpInteractivityId!=null||n.querySelector("[data-wp-interactive]")]].find(([,o])=>o)?.[0]||"";return r&&!pe&&console.warn(`[umber] router: ${r} runs on this page too, so Umber's router stays off. Use one of them.`),pe||=!!r,r}h(n,"keydown",()=>H=!0,{capture:!0}),h(n,"pointerdown",()=>H=!1,{capture:!0}),h(n,"click",e=>{e.detail===0&&(H=!0);let r=k()&&J(e,i.prevent);if(!r)return;e.preventDefault();let o=r.a.closest(`[${ye}]:not([data-gl-router])`);W(K(r.url.href,r.a,{origin:e.detail?[e.clientX,e.clientY]:null,transition:o?.getAttribute(ye)||void 0}))}),h(globalThis,"popstate",()=>{if(!k())return;let[e,r]=v.moved();if(b(v.url)===A&&!s){let o=decodeURIComponent(location.hash.slice(1));return ie(r??(o&&n.getElementById(o)||0))}W(K(v.url,"popstate",{direction:e,pop:!0,shown:!0,y:r}))}),h(globalThis,"hashchange",()=>k()&&v.url!==location.href&&v.moved()),h(globalThis,"scroll",()=>P||!k()||v.scrolled(),{passive:!0});let I=()=>k()&&v.own();n.readyState==="loading"?h(n,"DOMContentLoaded",I):I(),t.licensed?.().then(e=>{de=e,e&&!E&&n.readyState!=="loading"&&I()}),h(globalThis,"pagehide",()=>{V&&(E=!0),k()&&v.hide()}),h(globalThis,"pageshow",e=>{if(e.persisted&&(E||P))return ee.reload();I()});let j=e=>m.load(e,!0).then(()=>{},()=>{}),Y=e=>be(e,C(e,i.prevent)),D,Q=e=>{let r=i.prefetch&&k()&&e.target?.closest?.("a[href]");clearTimeout(D),r&&Y(r)&&(D=setTimeout(()=>j(r.href),e.type==="pointerover"?65:0))};h(n,"pointerover",Q,{passive:!0}),h(n,"touchstart",Q,{passive:!0}),h(n,"focusin",Q),h(n,"pointerout",()=>clearTimeout(D),{passive:!0}),(a.requestIdleCallback||setTimeout)(()=>{k()&&M().then(([e])=>i.prefetch==="viewport"&&(L=e.watch(L,n,j,Y)),()=>{})});let me=!1;function Te(){me||N||(me=!0,(t.licensed?.()??Promise.resolve(!0)).then(e=>{let r=O(n);if(!e||N||E||!r)return;let o=t.transition?.(),c=z(x(null,""),x(r,location.href),"load");M().then(([l])=>l.once(g,c,F)).catch(l=>console.warn("[umber] router: the first page's intro:",l)).finally(()=>o?.())}))}t.on("destroy",()=>{R.splice(0).forEach(e=>e()),L?.disconnect(),E=!0,clearTimeout(S),clearTimeout(D),u.removeAttribute("data-gl-router-busy"),v.release(),t.router===q&&delete t.router});let q={options:i,get busy(){return P},get url(){return A},get page(){return O(n)?.getAttribute("data-gl-page")||""},go(e,r={}){let o=new URL(e,location.href);return/^https?:$/.test(o.protocol)?o.origin!==location.origin?(ee.load(o.href,!1),Promise.reject(new Error(`${o.href} is on another site`))):W(K(o.href,r.trigger??"go",{transition:r.transition})):Promise.reject(new Error(`http(s) URLs only: ${o.protocol}`))},prefetch:j,transition(e){return g.push(e),e.once&&Te(),()=>{let r=g.indexOf(e);r>=0&&g.splice(r,1)}},on(e,r){let o=p.get(e);return o||p.set(e,o=new Set),o.add(r),()=>void o.delete(r)},view(e,r){let o=["beforeEnter","afterEnter","beforeLeave","afterLeave"].map(l=>q.on(l,w=>w[l.endsWith("Enter")?"next":"current"].page===e?r[l]?.(w):void 0)),c=O(n);if(!N&&c?.getAttribute("data-gl-page")===e){let l=z(x(null,""),x(c,location.href),"load");M().then(([w])=>w.outcome(()=>r.beforeEnter?.(l)).then(()=>w.outcome(()=>r.afterEnter?.(l)))).catch(w=>console.error(`[umber] router: view "${e}"`,w))}return()=>o.forEach(l=>l())}};return t.router=q,q}var Ue={name:"router",version:"0.2.1",attributes:[],install(t,d){Me(t,d)}},Be=Ue;export{te as CONTAINER,Oe as DEFAULTS,ge as PREVENT,Ue as Router,_e as WRAPPER,ee as browser,O as containerOf,Be as default,J as linkOf,b as pageOf,C as routable,Me as router,Ve as swapFrom};
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ function e(){return globalThis}function t(e,t=location.href){try{return new URL(e,t)}catch{return null}}function r(e){return("string"==typeof e?t(e):e)?.origin===location.origin}var o=()=>{};function n(...e){for(let t of e)if(t)return t;return""}var i="[data-umber~=skip]",a=/\.(pdf|zip|rar|7z|gz|tgz|dmg|exe|apk|mp[34]|m4a|mov|webm|ogg|wav|jpe?g|png|gif|webp|avif|svg|ico|csv|xlsx?|docx?|pptx?|txt|xml|json|rss|ics)$/i;function s(e){let t=new URL(e,location.href);return t.hash="",t.href}function l(e,o,n){let l=e.getAttribute("href"),u=e.getAttribute("target");if(null==l||l.startsWith("#")||u&&"_self"!==u||e.hasAttribute("download")||/(^|\s)external(\s|$)/i.test(e.getAttribute("rel")??"")||e.closest(i))return null;let h=t(l,document.baseURI);return!h||!r(h)||!/^https?:$/.test(h.protocol)||a.test(h.pathname)||h.hash&&s(h)===s(location.href)||o?.(e,n)?null:h}function u(e,t){if(e.defaultPrevented||e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return null;let r=e.composedPath(),o=r.length?r[0]:e.target,n=o instanceof Element?o.closest("a[href],area[href]"):null,i=n&&l(n,t,e);return i?{a:n,url:i}:null}var h="umberRouter";function c(){let e=history.state;return"object"==typeof e&&null!==e?{...e}:{}}var d=(e,t)=>e.headers.get(t)??"";function m(e,t,{timeout:o,headers:n},i){let a=new AbortController,l=setTimeout(()=>{a.abort()},o());return{p:fetch(e,{...t,signal:a.signal,credentials:"same-origin",headers:{...n(),accept:"text/html,application/xhtml+xml"}}).then(async o=>{if(o.url&&!r(o.url))throw new Error(`${e} redirects to another site`);if(!o.ok&&!t.body||204===o.status||/attachment/i.test(d(o,"content-disposition"))||!/html/i.test(d(o,"content-type")))throw new Error(`${e} answered ${o.status} ${d(o,"content-type")}`);let n=await o.text();i(o);let a=s(o.url||e);return{url:a,html:n,csp:d(o,"content-security-policy"),redirected:a!==e}}).finally(()=>{clearTimeout(l)}),ctl:a}}var f={warn:o,error:o},p=e=>{},g=null,b="[data-umber~=wrapper]",w="[data-umber~=container]",y="data-umber-transition",v={transition:"fade",prefetch:"hover",cache:10,timeout:6e3,focus:"h1",announce:!0,scroll:!0,scripts:!0,head:!0,webflow:!0,prevent:null,wait:!1,headers:{}},k={load(e,{replace:t=!1}={}){t?location.replace(e):location.assign(e)},reload(){location.reload()},submit(e,t){try{e.requestSubmit(t)}catch{e.requestSubmit()}}};function x(){let e=navigator;return!0===e.connection?.saveData||(e.connection?.effectiveType??"").includes("2g")}var P=e=>(e.querySelector(b)??e).querySelector(w),S=(e,t,r)=>({url:t,page:e?.getAttribute("data-umber-page")??"",container:e,document:r});function T(e,t,r={}){let{promise:n,resolve:i,reject:a}=function(){let e,t;return{promise:new Promise((r,o)=>{e=r,t=o}),resolve:e,reject:t}}();return n.catch(o),{url:e,trigger:t,direction:"forward",origin:null,...r,done:n,resolve:i,reject:a}}var A=e=>!0===e.dropped,q=(e,t)=>{t.done.then(e.resolve,e.reject)},E=e=>(new DOMParser).parseFromString(e,"text/html"),$=class{constructor(e,t,r){this.gl=e,this.o=t,this.ahead=r,this.change={kind:"idle"},this.open=!1,this.gone=!1,this.started=!1,this.keyed=!1,this.here=s(location.href),this.defs=[],this.hooks=new Map,this.errorHooks=[],this.resent=new WeakSet,this.io=null,this.end=()=>Promise.resolve(),this.held=!1,this.swapper=null,this.firstDoc=null,this.firstUrl=location.href,this.leaving=null,this.named=new Map,this.naming=!1,this.warmed=new WeakSet,this.waiting=[],this.requests=0,this.emit=(e,t)=>{let r=this.hooks.get(e),n=r?L(r):[];return n.length?this.ready().then(([e])=>Promise.all(n.map(r=>e.outcome(()=>r(t)))).then(o)):Promise.resolve()},this.timed=(e,t)=>{let r=o;return Promise.race([e,new Promise((e,o)=>{r=this.clock.after(this.o.timeout,()=>{o(new Error(`${t} took over ${this.o.timeout} ms`))})})]).finally(()=>{r()})},this.prefetch=e=>this.load(e,{lowPriority:!0,warm:!0}).then(o,o),this.view=e=>{x()||!this.o.cache||(this.waiting.push(e),this.pump())},this.cache=function(e){let{max:t}=e,r=new Map,n=(e,t)=>{r.get(e)===t&&r.delete(e)};function i(e,t){t.done?r.delete(e):t.forgotten=!0}return{load:function(o,{lowPriority:a=!1,fresh:l=!1}={}){let u=s(o),h=r.get(u);if(h&&!l)return r.delete(u),r.set(u,h),h.p;h&&i(u,h);let c={...m(u,a?{priority:"low"}:{},e,e=>{(/no-store/i.test(d(e,"cache-control"))||!t()||c.forgotten)&&n(u,c)})};c.p.then(()=>{c.done=!0},()=>{c.done=!0,n(u,c)}),r.set(u,c);for(let e of r.keys()){if(r.size<=Math.max(t(),1))break;e!==u&&r.get(e)?.done&&r.delete(e)}return c.p},send:(t,r)=>m(s(t),{method:"POST",body:r},e,o).p,abortOthers(...e){let t=new Set(e.map(s));for(let[e,o]of r)!t.has(e)&&!o.done&&o.ctl.abort()},has:e=>r.has(s(e))&&!r.get(s(e))?.forgotten,delete:e=>{let t=s(e),o=r.get(t);return o&&i(t,o),!!o},clear:()=>{for(let[e,t]of r)i(e,t)}}}({max:()=>t.cache,timeout:()=>t.timeout,headers:()=>t.headers}),this.hist=function(e){let t=()=>{let e=c()[h];return(e=>"object"==typeof e&&null!==e&&"i"in e&&"number"==typeof e.i&&"u"in e&&"string"==typeof e.u)(e)?e:void 0},r=t()?.i??0,o=location.href,n=e(!1),i=new Map,a=(e,t)=>`${e} ${t}`,s=(e,t)=>{i.delete(e),i.set(e,t),i.size>100&&i.delete(i.keys().next().value??"")},l=()=>{let t={...n,els:e(!0).els};return s(a(r,o),t),t},u=e=>{let t=e?{x:e.x,y:e.y,e:e.els}:{};history.replaceState({...c(),[h]:{i:r,u:location.href,...t}},"")},d=history.scrollRestoration,m=e=>{try{history.scrollRestoration=e}catch{}};return{get url(){return o},own(){m("manual"),t()||u()},release(){m(d??"auto")},hide(){u({...n,els:e(!0).els}),m("auto")},push(t){n=e(!1),u(l()),history.pushState({[h]:{i:++r,u:t}},"",t),i.delete(a(r,t)),o=location.href,n={x:0,y:0}},replace(e){i.delete(a(r,o)),history.replaceState({...c(),[h]:{i:r,u:new URL(e,location.href).href}},"",e),o=location.href},moved(){let e=t();l();let n=e&&e.i<r?"back":"forward";r=e?e.i:r+1,e||u(),o=location.href;let s=e?.u===o&&"number"==typeof e.y?{x:e.x??0,y:e.y,els:e.e}:void 0;return[n,i.get(a(r,o))??s]},scrolled(){o!==location.href&&this.moved(),n=e(!1),s(a(r,o),n)},landed(){n=e(!1)}}}(e=>this.where(e)),this.clock=function(e){let t,r=0,o=0,n=!1,i=!1,a=0,s=null,l=new Set,u=()=>{for(let e of[...l])e()},h=()=>{t=setTimeout(()=>{if(!1===e.loop?.playing)o=performance.now(),u();else if(n)a=0;else if(++a>=(i?2:1)){let e=performance.now();r+=e-o,o=e,u()}n=!1,l.size&&h()},100)},c=()=>{s?.(),s=null,clearTimeout(t)},d=t=>(l.add(t),s||(o=performance.now(),n=!1,i=!1,a=0,s=e.on("frame",e=>{r+=1e3*e.dt,o=performance.now(),n=!0,i=!0,a=0,u()},{phase:"measure",order:-1500,label:"router"}),h()),()=>{l.delete(t),l.size||c()});return{now:()=>r,each:d,after(e,t){let o=r+e,n=d(()=>{r<o||(n(),t())});return n},stop(){l.clear(),c()}}}(e);let n=P(document);this.learn(location.href,n?.getAttribute("data-umber-transition")??"")}where(e){let t={x:scrollX,y:this.smooth()?.animatedScroll??scrollY};if(!e)return t;for(let e of document.querySelectorAll("[data-umber-router-scroll]")){let r=e.getAttribute("data-umber-router-scroll");r&&((t.els??={})[r]=[e.scrollLeft,e.scrollTop])}return t}ready(){return this.swapper??=(g??=import("./router-swap.js").then(e=>(e.bindLog(f),e),e=>{throw g=null,e})).then(e=>[e,e.session()],e=>{throw this.swapper=null,e})}smooth(){return this.gl.scroll?.scrollTo?this.gl.scroll:null}reduced(){return(e().matchMedia?globalThis.matchMedia("(prefers-reduced-motion: reduce)"):null)?.matches??!1}jump(e,t){let r=this.smooth();r?r.scrollTo(e,{immediate:!t,force:!0,jump:!t}):"number"==typeof e?scrollTo({top:e,left:0,behavior:t?"smooth":"instant"}):e.scrollIntoView({behavior:"instant"})}data(e,t,r,o){return{current:e,next:t,trigger:r,direction:o?.direction??"forward",origin:o?.origin??null,reducedMotion:this.reduced(),keyboard:this.keyed,transition:""}}first(){return this.firstDoc??=this.cache.load(this.firstUrl,{lowPriority:!0}).then(e=>E(e.html),()=>null)}namedAt(e){let t=s(e);return this.named.has(t)?this.named.get(t):this.naming?void 0:""}learn(e,t){this.named.set(s(e),t),t&&(this.naming=!0)}load(e,{lowPriority:t=!1,warm:r=!1,fresh:i=!1}={}){let a=this.cache.load(e,{lowPriority:t,fresh:i});return a.then(t=>{let o=function(e){let t=/<[a-z][^>]*\sdata-umber\s*=\s*["']?(?:[^"'>]*\s)?container\b[^>]*>/i.exec(e)?.[0]??"",r=/\sdata-umber-transition\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(t);return n(r?.[1],r?.[2],r?.[3])}(t.html);if(this.learn(e,o),this.learn(t.url,o),r&&this.gl.preload&&!this.warmed.has(t)){this.warmed.add(t);try{this.gl.preload(E(t.html))}catch(e){f.warn("[umber] router: umber.preload():",e)}}},o),a}pump(){for(;this.requests<4&&this.waiting.length;){let e=this.waiting.shift()??"";this.cache.has(e)||(this.requests++,this.load(e,{lowPriority:!0}).catch(o).finally(()=>{this.requests--,this.pump()}))}}request(e){if(this.gone)return e.done;let t=this.change;return"running"!==t.kind?(this.start(e),e.done):t.nav.started?(t.queued&&q(t.queued,e),t.queued=e,e.body||this.load(e.url,{warm:!0}).catch(o),e.done):(t.nav.dropped=!0,q(t.nav,e),this.start(e),e.done)}begin(e){if(this.held)return;let t=!this.cap;this.end=this.gl.transition?.(e)??this.end,t&&(this.smooth()?.stop(),this.cap=setTimeout(()=>{this.held=!0;let e=this.gl.hold?.(),t=this.end;this.end=()=>(e?.(),Promise.resolve()),t()},7e3))}mark(e){this.open=e;let t=document.documentElement;e?(t.setAttribute("data-umber-router-busy",""),t.setAttribute("aria-busy","true")):(t.removeAttribute("data-umber-router-busy"),t.removeAttribute("aria-busy"))}async close(){if(!this.open)return;this.mark(!1);let e=this.end;this.end=()=>Promise.resolve(),this.cap&&this.smooth()?.start(),clearTimeout(this.cap),this.cap=void 0,this.held=!1,this.hist.landed(),await e()}async settle(e,t){let r=this.change,o="running"===r.kind&&r.nav===e?r.queued:null;o?this.change={kind:"running",nav:o,queued:null}:("running"===r.kind&&r.nav===e&&(this.change={kind:"idle"}),await this.close()),t&&await this.emit("after",t).catch(e=>{f.error("[umber] router: after",e)}),e.resolve(),o&&!o.dropped&&this.start(o)}fail(e,t){if(e.dropped||this.gone)return;f.warn(`[umber] router: loading ${e.url} in full:`,t);let r=this.data(S(P(document),this.here),S(null,e.url),e.trigger,e);for(let o of L(this.errorHooks))try{o({...r,error:t,url:e.url})}catch{}"running"===this.change.kind&&this.change.queued?.reject(t),this.leaving?.t.undo?.(),this.leaving=null,this.change={kind:"leaving"},this.close();let o=e.form;e.body&&o&&!e.shown?(this.resent.add(o.el),k.submit(o.el,o.submitter)):k.load(e.body?location.href:e.url,{replace:!!e.shown}),e.reject(t)}async start(e){this.change={kind:"running",nav:e,queued:null},this.started=!0;let t=P(document);if(!t)return void this.fail(e,new Error("this page has no "+w));if(s(e.url)===this.here&&!this.leaving&&!e.body)return e.trigger instanceof Element&&this.jump(0,!this.reduced()),this.settle(e);this.mark(!0),this.waiting.length=0,this.cache.abortOthers(e.url,this.firstUrl),this.first();let r=this.data(S(t,this.here),S(null,e.url),e.trigger,e);try{if(!await this.run(e,r,t))return}catch(t){return void this.fail(e,t)}return this.settle(e,r)}leaveNow(e,t,r){if(this.leaving)return this.leaving;let n=this.namedAt(e.url),i=this.o.wait?null:r.early(this.defs,t,{asked:e.transition,fallback:this.o.transition,named:n}),a=i&&r.make(i,this.gl,t.reducedMotion,this.clock);if(!i||!a||a.sync||a.wait||a.native)return null;t.transition=a.name??"",this.begin();let{timed:l,emit:u}=this,h=r.leave({t:a,d:t,timed:l,emit:u});h.catch(o);let c=""!==n||this.named.has(s(e.url))?"":e.url;return this.leaving={t:a,from:i,done:h,guess:c}}async run(e,t,r){if(await this.timed(this.emit("before",t),'the "before" hooks'),A(e))return!1;let n=e.body?this.cache.send(e.url,e.body):this.load(e.url,{warm:!0,fresh:!!e.form});n.catch(o);let[i,a]=await this.ready();if(A(e))return!1;let l=this.leaveNow(e,t,i),[u,h]=await Promise.all([n,this.first()]);if(A(e))return!1;a.head.know(h);let c=E(u.html),d=P(c);if(!d)return this.fail(e,new Error(`${u.url} has no ${w}`)),!1;if(i.stale(c))return this.fail(e,new Error(`${u.url} has changed tracked <head> elements`)),!1;let m=!!e.body&&!u.redirected,f=m?location.href:u.url+new URL(e.url).hash;m&&(e.replace=!0),t.next=S(d,f,c);let{t:p,again:g}=this.transitionOf(e,l,i,{data:t,arriving:d});if(t.transition=p.name??"",l&&(await l.done,A(e)))return!1;this.show(e,f,c);let{o:b,gl:y,timed:v,emit:k}=this;return await i.swap({t:p,d:t,o:b,gl:y,s:a,asked:e.url,spot:e.spot,timed:v,emit:k,left:!!l&&!g,again:g,leaving:r,arriving:d,document:c,csp:u.csp}),this.here=s(f),"viewport"===b.prefetch&&(this.io=i.watch(this.io,d,{fetch:this.view,allowed:this.ahead,limit:b.cache})),!0}transitionOf(e,t,r,{data:o,arriving:n}){let i=e=>r.make(e,this.gl,o.reducedMotion,this.clock),a=()=>r.choose(this.defs,o,{asked:e.transition,arriving:n,fallback:this.o.transition});if(!t)return{t:i(a()),again:!1};let s=t.guess===e.url&&t.t.undo?a():null;return!s||r.same(s,t.from)?{t:t.t,again:!1}:(t.t.undo?.(),this.leaving=null,{t:i(s),again:!0})}show(e,t,r){e.started=!0,this.leaving=null,e.pop?s(t)!==s(e.url)&&this.hist.replace(t):e.replace?this.hist.replace(t):this.hist.push(t),e.shown=!0,this.begin(r)}destroy(){this.io?.disconnect(),this.waiting.length=0,this.gone=!0,clearTimeout(this.cap),this.mark(!1),this.clock.stop(),this.hist.release()}};function L(e){let t=e.slice().sort((e,t)=>e.order-t.order);for(let r of t)r.once&&e.splice(e.indexOf(r),1);return t.map(e=>e.hook)}function U(e,t,r={}){let o={hook:t,once:!!r.once,order:r.order??0};return e.push(o),()=>{let t=e.indexOf(o);t>=0&&e.splice(t,1)}}function j(e){return{transition:e.closest(`[${y}]:not(${w},${b})`)?.getAttribute(y)??void 0,replace:"replace"===e.closest("[data-umber-router-history]")?.getAttribute("data-umber-router-history")}}var R={textureSource:()=>"umber.texture(source) needs a canvas, ImageBitmap, video, image, ImageData or { data, width, height }.",textureSize:()=>"umber.texture(numbers) needs their size: umber.texture({ data, width, height }), 1, 2 or 4 numbers per texel.",routerProtocol:e=>`umber.router.go(url): http(s) URLs only, not ${e}`},I=class extends Error{constructor(e,...t){super(`[umber] ${R[e](...t)}`),this.code=e,this.name="UmberError"}};function M(a,h={}){let d={...v,...h};d.headers={...d.headers};let m=new $(a,d,e=>function(e,t){if(!t||t.search||/log-?(out|off)|sign-?out/i.test(t.pathname)||s(t)===s(location.href))return!1;let r=e.getAttribute("data-method")??e.getAttribute("data-turbo-method");return!(r&&"get"!==r.toLowerCase()||e.matches("[data-confirm],[data-remote],[data-turbo-confirm]")||null!=e.closest('[data-umber-router-prefetch="false"]'))}(e,l(e,d.prevent))),p=[],g=(e=>(t,r,o,n)=>{e.push(function(e,t,r,o){let n=r;return e.addEventListener(t,n,o),()=>{e.removeEventListener(t,n,o)}}(t,r,o,n))})(p),b=!a.licensed||!0===a.licence,w=a.licensed?.().then(e=>b=e),y=function(t,r,o){let n=!1;return()=>{if(!r()||t.gone||!o())return!1;let i=function(){let t=e();return[["Barba",t.barba?.init],["Swup",t.swup??t.Swup],["Turbo",t.Turbo?.session],["htmx hx-boost",t.htmx&&document.querySelector("[hx-boost]")],["Astro's client router",document.querySelector('meta[name="astro-view-transitions-enabled"]')],["WordPress's Interactivity API",null!=c().wpInteractivityId||document.querySelector("[data-wp-interactive]")]].find(([,e])=>e)?.[0]??""}();return i&&!n&&(n=!0,f.warn(`[umber] router: ${i} runs on this page too, so Umber's router stays off. Use one of them.`)),!i}}(m,()=>b,()=>!!P(document));(function(e,o,a){let s=t=>()=>{e.keyed=t};o(document,"keydown",s(!0),{capture:!0}),o(document,"pointerdown",s(!1),{capture:!0}),o(document,"click",t=>{0===t.detail&&(e.keyed=!0);let r=u(t,e.o.prevent);if(!r||!a())return;t.preventDefault(),"running"!==e.change.kind&&e.mark(!0);let o=t.detail?[t.clientX,t.clientY]:null;queueMicrotask(()=>{e.request(T(r.url.href,r.a,{origin:o,...j(r.a)}))})}),o(document,"submit",o=>{let s=a()&&!e.resent.delete(o.target)&&function(e,o){let a=e.target;if(e.defaultPrevented||!(a instanceof HTMLFormElement)||!a.closest("[data-umber-router-form]"))return null;let s,l=e.submitter,u=(e,t)=>l?.getAttribute(e)??a.getAttribute(t),h=(u("formmethod","method")??"get").toLowerCase(),c=(u("formenctype","enctype")??"").toLowerCase(),d=u("formtarget","target"),m=t(n(u("formaction","action"),location.href),document.baseURI);if(!m||!/^(get|post)$/.test(h)||"text/plain"===c||d&&"_self"!==d||!r(m)||!/^https?:$/.test(m.protocol)||a.closest(i)||o?.(a,e))return null;try{s=new FormData(a,l)}catch{s=new FormData(a)}let f=new URLSearchParams([...s].map(([e,t])=>[e,"string"==typeof t?t:t.name]));return"get"===h?(m.search=f.toString(),{form:a,by:l,url:m,body:void 0}):{form:a,by:l,url:m,body:"multipart/form-data"===c?s:f}}(o,e.o.prevent);s&&(o.preventDefault(),e.request(T(s.url.href,s.form,{...j(s.form),body:s.body,form:{el:s.form,submitter:s.by}})))})})(m,g,y),function(e,t,r){let{hist:o}=e;t(globalThis,"popstate",t=>{if(!r())return;let[n,i]=o.moved();if(s(o.url)===e.here&&"running"!==e.change.kind)return void e.jump(i?.y??function(e){if(!e)return null;let t=document.getElementById(e);if(t)return t;try{return document.getElementById(decodeURIComponent(e))}catch{return null}}(location.hash.slice(1))??0);let a=!0===t.hasUAVisualTransition;e.request(T(o.url,"popstate",{direction:n,pop:!0,shown:!0,spot:i,...a?{transition:"none"}:{}}))}),t(globalThis,"hashchange",()=>{r()&&o.url!==location.href&&o.moved()}),t(globalThis,"scroll",()=>{!e.open&&r()&&o.scrolled()},{passive:!0})}(m,g,y),function(e,t,r,o){let n=()=>{r()&&e.hist.own()};"loading"===document.readyState?t(document,"DOMContentLoaded",n):n(),o?.then(t=>{t&&!e.gone&&"loading"!==document.readyState&&n()}),t(globalThis,"pagehide",()=>{"leaving"===e.change.kind&&(e.gone=!0),r()&&e.hist.hide()}),t(globalThis,"pageshow",t=>{t.persisted&&(e.gone||e.open)?k.reload():n()})}(m,g,y,w);let A=function(e,t,r){let n,i=t=>{let i=e.o.prefetch&&r()&&t.target instanceof Element?t.target.closest("a[href]"):null;if(clearTimeout(n),!i||!e.ahead(i)||x())return;let a="pointerdown"===t.type;a&&0!==t.button||(n=setTimeout(()=>{e.load(i.href,{lowPriority:!a,warm:!0}).catch(o)},"pointerover"===t.type?65:0))},a=()=>{clearTimeout(n)};return t(document,"pointerover",i,{passive:!0}),t(document,"touchstart",i,{passive:!0}),t(document,"focusin",i),t(document,"pointerdown",i,{passive:!0,capture:!0}),t(document,"pointerout",a,{passive:!0}),a}(m,g,y);(function(t){let r=e();r.requestIdleCallback?r.requestIdleCallback(t):setTimeout(t)})(()=>{y()&&m.ready().then(([e])=>{"viewport"===d.prefetch&&(m.io=e.watch(m.io,document,{fetch:m.view,allowed:m.ahead,limit:d.cache}))},o)}),a.on("destroy",()=>{p.splice(0).forEach(e=>{e()}),A(),m.destroy(),a.router===q&&delete a.router});let q=function(e,t){let{cache:o}=e,n={options:e.o,get busy(){return e.open},get url(){return e.here},get page(){return P(document)?.getAttribute("data-umber-page")??""},go(t,o={}){let n=new URL(t,location.href);return/^https?:$/.test(n.protocol)?r(n)?e.request(T(n.href,o.trigger??"go",{transition:o.transition,replace:"replace"===o.history})):(k.load(n.href),Promise.reject(new Error(`${n.href} is on another site`))):Promise.reject(new I("routerProtocol",n.protocol))},prefetch:e.prefetch,cache:{clear:o.clear,delete:o.delete,has:o.has},transition:r=>(function(e){if("string"!=typeof e)return!1;try{return document.createDocumentFragment().querySelector(e),!1}catch{return!0}}(r.links)&&f.error(`[umber] router: transition "${r.name??""}": links "${String(r.links)}" is not a valid selector, so it matches no link`),e.defs.push(r),r.once&&t(),()=>{let t=e.defs.indexOf(r);t>=0&&e.defs.splice(t,1)}),on:function(...[t,r,o]){if("error"===t)return U(e.errorHooks,r,o);let n=e.hooks.get(t)??[];return e.hooks.set(t,n),U(n,r,o)},view(t,r){let o=["beforeEnter","afterEnter","beforeLeave","afterLeave"].map(e=>n.on(e,o=>o[e.endsWith("Enter")?"next":"current"].page===t?r[e]?.(o):void 0)),i=P(document);if(!e.started&&i?.getAttribute("data-umber-page")===t){let o=e.data(S(null,""),S(i,location.href),"load");e.ready().then(([e])=>e.outcome(()=>r.beforeEnter?.(o)).then(()=>e.outcome(()=>r.afterEnter?.(o)))).catch(e=>{f.error(`[umber] router: view "${t}"`,e)})}return()=>{o.forEach(e=>{e()})}}};return n}(m,function(e){let t=!1;return()=>{t||e.started||(t=!0,(e.gl.licensed?.()??Promise.resolve(!0)).then(t=>{let r=P(document);if(!t||e.started||e.gone||!r)return;let o=e.gl.transition?.(),n=e.data(S(null,""),S(r,location.href),"load");e.ready().then(([t])=>t.once(e.defs,n,e.timed)).catch(e=>{f.warn("[umber] router: the first page's intro:",e)}).finally(()=>o?.())}))}}(m));return a.router=q,q}var O,D={name:"router",version:"0.3.0",attributes:[],install:(O=({engine:e,options:t})=>{M(e,t)},(...e)=>{let[t,r,o,n,i]=e;(function(e){e&&(f=e)})(i),O({engine:t,options:r,keep:o,root:n})})},z=D;export{w as CONTAINER,v as DEFAULTS,D as Router,i as SKIP,b as WRAPPER,k as browser,P as containerOf,z as default,u as linkOf,s as pageOf,l as routable,M as router,p as swapFrom};
@@ -0,0 +1,2 @@
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ function t(t){if(!t)return null;let e=document.getElementById(t);if(e)return e;try{return document.getElementById(decodeURIComponent(t))}catch{return null}}function e(t,e,n,r){return r.ctrlKey?0:"both"===n?Math.abs(e)>Math.abs(t)?e:t:"horizontal"===n?t||(r.shiftKey?e:0):r.shiftKey||Math.abs(t)>Math.abs(e)?0:e}var n=/^(Arrow(Up|Down|Left|Right)|Page(Up|Down)|Home|End| |Spacebar|Tab)$/;function r(t,e){for(let n of[t,e,document.body,document.documentElement]){let t=parseFloat(n?.getAttribute("data-umber-scroll-offset")??"");if(!isNaN(t))return t}return null}var a=(t,e)=>r=>{(function(t){if(!n.test(t.key)||t.ctrlKey||t.metaKey||t.altKey)return!1;let e=t.target;return!(e&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)))})(r)&&(e("key",r,0)?r.preventDefault():t.active&&!r.defaultPrevented&&t.halt())},o=0;function l(t,e){t.rafAt=performance.now(),t.step(o?Math.min(.1,Math.max(0,(e-o)/1e3)):1/60),o=e}function i(t,e){let n="string"==typeof e?c(e):e;if("number"==typeof n)return n;if(!(n instanceof Element))return null;let r=t.page.horizontal,a=t=>r?t.left:t.top,o=a(n.getBoundingClientRect())-(t.wrapper?a(t.wrapper.getBoundingClientRect()):0),l=t=>parseFloat(t)||0,i=l(getComputedStyle(n)[r?"scrollMarginLeft":"scrollMarginTop"]);return o+t.read()-i-l(getComputedStyle(t.page.root)[r?"scrollPaddingLeft":"scrollPaddingTop"])}function u(t,e){if(!e){if(!t.stopped)return;return t.stopped=!1,t.settle(),void t.publish()}if(t.stopped||t.destroyed)return;let{wrapper:n,root:r}=t.page;t.page.gutter=Math.max(0,(n?n.offsetWidth-2*n.clientLeft:innerWidth)-r.clientWidth),t.settle(),t.stopped=!0,t.publish()}function s(t,e,n){t.animated+=n,"tween"===e.kind&&(e.from+=n),t.target=t.clamp(t.target+n)}function c(e){if(/^(#|#?top|start)$/.test(e))return 0;if(/^(#?bottom|end)$/.test(e))return 1/0;let n=e.startsWith("#")?t(e.slice(1)):null;if(n)return n;try{return document.querySelector(e)}catch{return null}}var d=t=>t<1?1-2**(-10*t):1;function f(t,e,n,r){let a=e.easing??t.o.easing??d;t.motion={...n,kind:"tween",from:t.animated,duration:r,elapsed:0,ease:a}}function p(t,e,n){e.elapsed+=n;let r=Math.min(1,e.elapsed/e.duration);return t.animated=e.from+(t.target-e.from)*e.ease(r),r>=1}function m(t,e){let n=t.wrapper??document,r=()=>{clearTimeout(a),n.removeEventListener("scrollend",r),e(t.api())},a=setTimeout(r,1500);n.addEventListener("scrollend",r)}function h(t,e){let n=t.page.limit;return n>0?(e%n+n)%n:e}function g(t,e){let n=t.page.limit;if(!n)return e;let r=t.active?t.animated:t.read(),a=e-h(t,r);return a>n/2?r+a-n:a<-n/2?r+a+n:r+a}function b(e,n,a){let o=function(e){if(e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return null;let n=e.target instanceof Element?e.target.closest("a[href]"):null;if(!n?.hash||n.target&&"_self"!==n.target||n.hasAttribute("download")||n.origin!==location.origin||n.pathname!==location.pathname||n.search!==location.search)return null;let r=n.hash.slice(1),a=t(r)??("top"===r?document.documentElement:null);return a&&[n,a]}(a)??function(e){if(e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return null;let n=e.target instanceof Element?e.target.closest("[data-umber-scroll-to]"):null;if(!n)return null;let r=n.getAttribute("data-umber-scroll-to"),a=(""===r||null===r?n.getAttribute("href"):r)??"";if(/^#?(top)?$/.test(a))return[n,document.documentElement];let o=a.startsWith("#")?t(a.slice(1)):null;try{o??=document.querySelector(a)}catch{}return o&&[n,o]}(a);if(!o)return;let[l,i]=o;e.page.revalidate();let u=n("anchor",a,0);if(!u||(a.preventDefault(),1===u))return;let s="object"==typeof e.o.anchors?e.o.anchors:{},c=parseFloat(l.getAttribute("data-umber-scroll-duration")??"");e.scrollTo(i===document.documentElement?0:i,{...s,...c>=0?{duration:c}:{},offset:r(l,i)??s.offset??0}),l instanceof HTMLAnchorElement&&function(t,e,n){if(location.hash!==t.hash){let e=location.href;history.pushState(null,"",t.href),dispatchEvent(new HashChangeEvent("hashchange",{oldURL:e,newURL:location.href}))}if(!n||e===document.documentElement)return;let r=e;!r.hasAttribute("tabindex")&&r.tabIndex<0&&(r.setAttribute("tabindex","-1"),r.addEventListener("blur",()=>{r.removeAttribute("tabindex")},{once:!0})),r.focus({preventScroll:!0})}(l,i,!a.detail)}function y(t,e){let n=t.page.root,r=()=>{if(n.getAttribute("data-umber-scroll-state")?.includes("stopped")&&!a)return;let r=getComputedStyle(n),o=t.wrapper?r:getComputedStyle(document.body),l=/hidden|clip/.test(r.overflow+o.overflow);l&&!t.stopped?(a=!0,e().stop()):!l&&a&&(a=!1,e().start())},a=!1,o=new MutationObserver(r);for(let e of t.wrapper?[n]:[n,document.body])o.observe(e,{attributes:!0,attributeFilter:["style","class"]});return r(),()=>{o.disconnect()}}var v=new WeakMap,w=new WeakSet;function E({glide:t,api:e,offs:n,create:r},a){t.o.autoToggle&&!w.has(e)&&(w.add(e),n.push(y(t,()=>e)));let o=v.get(e);if(!o){v.set(e,o=new Map);let t=o;n.push(()=>{for(let e of t.values())e.destroy()})}for(let[t,e]of o)t.isConnected||(o.delete(t),e.destroy());let l=(t,e={})=>{let n=o.get(t);return n||o.set(t,n=r({anchors:!1,...e,wrapper:t})),n};if(!t.wrapper)for(let t of document.querySelectorAll("[data-umber~=nested]"))l(t);if(!a)return null;let i="string"==typeof a[0]?document.querySelector(a[0]):a[0];return i?l(i,a[1]):null}export{p as advance,e as along,y as autoToggle,b as click,d as expoOut,a as key,m as landed,g as nearest,l as raf,i as resolve,E as setUp,s as shift,u as stop,c as target,f as tween,h as wrap};
@@ -0,0 +1,2 @@
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ function t(t,e,n,a){let i={deltaX:e,deltaY:n,event:a};return!1!==t.o.virtualScroll?.(i)&&(t.notify.gesture(i),!0)}var e=16.666666666666668,n={ctrlKey:!1,shiftKey:!1};function a(t,e){let n=i(t,e),a=["touchstart","touchmove","touchend","touchcancel"].map(e=>function(t,e,n,a){let i=n;return t.addEventListener(e,i,a),()=>{t.removeEventListener(e,i,a)}}(t.events,e,n,{passive:"touchmove"!==e}));return()=>{for(let t of a)t()}}var i=(a,i)=>o=>{let r=o.touches.length?o.touches[0]:void 0;"touchstart"===o.type?function(e,n,a){let i=e.gesture;i.phase="none",!(e.destroyed||!a||n.touches.length>1)&&(!t(e,0,0,n)||function(t){let e=getSelection();if(!e||e.isCollapsed||!e.rangeCount)return!1;let n=e.getRangeAt(0).getClientRects(),a=n[0],i=n[n.length-1];if(!a||!i)return!1;let o=(e,n)=>Math.hypot(t.clientX-e,t.clientY-n)<=l;return o(a.left,a.top)||o(i.right,i.bottom)}(a)||(e.page.revalidate(),i.x=a.clientX,i.y=a.clientY,i.t=n.timeStamp,i.v=0,i.phase="undecided",e.locked||e.halt()))}(a,o,r):r?"none"!==a.gesture.phase&&function(e,a,i,l){let o=e.gesture,r=e.o.touchMultiplier,u=(o.x-l.clientX)*r,h=(o.y-l.clientY)*r;if(!t(e,u,h,i))return;let c=function(t,e,n,a){return a.ctrlKey?0:"both"===n?Math.abs(e)>Math.abs(t)?e:t:"horizontal"===n?t||(a.shiftKey?e:0):a.shiftKey||Math.abs(t)>Math.abs(e)?0:e}(u,h,e.o.gestureOrientation,n);if("undecided"===o.phase){let t=c?a("touch",i,c,((t,e)=>Math.abs(t)>Math.abs(e)?{d:t,x:!0}:{d:e,x:!1})(u,h)):0;if(0===t)return void(o.phase="none");o.phase=2===t?"mine":"held"}if(i.cancelable&&i.preventDefault(),"mine"!==o.phase)return;let s=i.timeStamp-o.t;s>0&&(o.v+=(c/s-o.v)*Math.min(1,s/30)),o.x=l.clientX,o.y=l.clientY,o.t=i.timeStamp,e.move(e.clamp(e.target+c),{lerp:1},"input")}(a,i,o,r):function(n,a){let i=n.gesture,l=n.o;if("mine"===i.phase&&t(n,0,0,a)){let t=a.timeStamp-i.t>100?0:i.v,o=l.touchInertiaExponent,r=null==o?325*t:Math.sign(t)*Math.abs(t*e)**o;n.move(n.clamp(n.target+r),{lerp:l.touchLerp??e/325},"input")}i.phase="none"}(a,o)},l=40;export{a as listenTouch};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- "use strict";(()=>{var be=new Set;function W(t,...r){be.has(t)||(be.add(t),console.warn("[umber]",t,...r))}function ve(t,r){return t.ctrlKey||t.defaultPrevented||t.shiftKey||Math.abs(t.deltaX)>Math.abs(t.deltaY)?0:t.deltaY*(t.deltaMode===1?19.2:t.deltaMode===2?r:1)}var qe=/^(Arrow(Up|Down)|Page(Up|Down)|Home|End| |Spacebar|Tab)$/;function ye(t){if(!qe.test(t.key)||t.ctrlKey||t.metaKey||t.altKey)return!1;let r=t.target;return!(r&&(r.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(r.tagName)))}var te={any:"[data-gl-scroll-prevent],[data-lenis-prevent]",wheel:"[data-gl-scroll-prevent-wheel],[data-lenis-prevent-wheel]",touch:"[data-gl-scroll-prevent-touch],[data-lenis-prevent-touch]"};function ze(t,r,s,l,i,f=!0,d=$e){let o=t.composedPath();for(let b=0;b<o.length;b++){let c=o[b];if(c===r||!c.matches)break;if(c.matches(te.any)||te[s]&&c.matches(te[s])||i&&i(c))return!0;if(!f||!l||c===document.body)continue;let u=d(c);if(u&1&&c.scrollHeight>c.clientHeight&&(u&2||(l<0?c.scrollTop>0:c.scrollTop+c.clientHeight<c.scrollHeight-1)))return!0}return!1}var $e=t=>{let r=getComputedStyle(t);return(/auto|scroll|overlay/.test(r.overflowY)?1:0)+(/contain|none/.test(r.overscrollBehaviorY)?2:0)};function ge(t,r,s,l){let i=l.options,f=l.page;return l.destroyed||l.stopped||f.off||r.defaultPrevented||(t==="anchor"?!i.anchors:t!=="key"&&!i[t])?0:t==="key"?l.locked&&r.key!=="Tab"?1:0:t==="anchor"?l.locked?1:f.limit?2:0:l.reduced||!s||f.snap||f.held||ze(r,f.root,t,s,i.prevent,i.nested,f.style)?0:l.locked?1:!l.active&&(s<0?l.at<=0:l.at>=f.limit)?0:2}function Ee(t){if(t.button||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return null;let r=t.target?.closest?.("a[href]");if(!r||!r.hash||r.target&&r.target!=="_self"||r.hasAttribute("download")||r.origin!==location.origin||r.pathname!==location.pathname||r.search!==location.search)return null;let s=decodeURIComponent(r.hash.slice(1)),l=document.getElementById(s)||(s==="top"?document.documentElement:null);return l&&[r,l]}function Se(t,r){for(let s of[t,r,document.body,document.documentElement]){let l=parseFloat(s?.getAttribute("data-gl-scroll-offset")??"");if(!isNaN(l))return l}return null}function we(t,r,s){if(location.hash!==t.hash){let i=location.href;history.pushState(null,"",t.href),dispatchEvent(new HashChangeEvent("hashchange",{oldURL:i,newURL:location.href}))}if(!s||r===document.documentElement)return;let l=r;!l.hasAttribute("tabindex")&&l.tabIndex<0&&(l.setAttribute("tabindex","-1"),l.addEventListener("blur",()=>l.removeAttribute("tabindex"),{once:!0})),l.focus({preventScroll:!0})}var I="data-gl-scroll-state",je=[()=>window.ScrollTrigger?.update?.()];function Te(t,r){let s=new Set,l="",i=d=>{try{d()}catch(o){console.error("[umber]",o)}},f=d=>{try{d(r())}catch(o){console.error("[umber]",o)}};return{publish(d,o){d&&je.forEach(i),o!==l&&(l=o,o?t.setAttribute(I,o):t.removeAttribute(I)),s.forEach(f)},on(d){return s.add(d),()=>void s.delete(d)},off:d=>void s.delete(d),clear(){s.clear(),t.removeAttribute(I)}}}var Xe="html.lenis, html.has-scroll-smooth, #smooth-wrapper";function Me(t,r,s){let l=window,i=document.documentElement,f=t||i,d=new WeakMap,o=0,b=[],c={root:f,wrapper:t,limit:0,vh:800,gutter:0,version:0,snap:!1,held:!1,off:!1,attr:u=>document.body?.getAttribute(u)??i.getAttribute(u),measure(){let u=t||document.scrollingElement||i,h=Math.max(0,u.scrollHeight-u.clientHeight),w=(t?t.clientHeight:l.innerHeight)||800;(h!==c.limit||w!==c.vh)&&c.version++,c.limit=h,c.vh=w,/stopped/.test(f.getAttribute("data-gl-scroll-state")||"")||(c.gutter=Math.max(0,(t?t.offsetWidth-2*t.clientLeft:l.innerWidth)-f.clientWidth))},revalidate(){o++;let u=getComputedStyle(f),h=t?u:getComputedStyle(document.body);c.snap=(u.scrollSnapType||"none")+(h.scrollSnapType||"none")!=="nonenone",c.held=/hidden|clip/.test(u.overflowY+h.overflowY)||!t&&h.position==="fixed",c.off=/^(off|native)$/.test(c.attr("data-gl-scroll")||"")||!!document.querySelector(Xe)},style(u){let h=d.get(u);if(h===void 0||h>>2!==o){let w=getComputedStyle(u),O=w.overflowY,m=w.overscrollBehaviorY;d.set(u,h=o*4+(O==="auto"||O==="scroll"||O==="overlay"?1:0)+(m==="contain"||m==="none"?2:0))}return h&3},destroy:()=>b.splice(0).forEach(u=>u())};if(c.measure(),c.revalidate(),s){let u=()=>c.measure();if(l.addEventListener("resize",u),b.push(()=>l.removeEventListener("resize",u)),l.ResizeObserver){let h=new ResizeObserver(u);h.observe(r||t?.firstElementChild||i),t&&h.observe(t),b.push(()=>h.disconnect())}}return c}var Ge=`[${I}~=stopped]{overflow:hidden!important}[${I}~=gutter]{scrollbar-gutter:stable!important}[${I}~=smooth] iframe{pointer-events:none}[data-gl-scroll-prevent],[data-lenis-prevent]{overscroll-behavior:contain}`,xe=0,_=null;function Ae(){xe++||(_=document.createElement("style"),_.setAttribute("data-gl-scroll-style",""),_.textContent=Ge,document.head.append(_));let t=!0;return()=>{t&&!(t=!1)&&!--xe&&(_?.remove(),_=null)}}var oe=16.666666666666668,ne=0,re=1,le=2;function Oe(t){let r=0,s=0,l=0,i=-1e9,f=o=>o&&(l=o>0?1:-1),d={written:t,get velocity(){return s},get direction(){return l},recent:(o=performance.now())=>o-i<150,wrote(o,b){d.written=o,r=b},reconcile(o,b,c,u,h){let w=o-d.written;return w<=1.5&&w>=-1.5?ne:b&&u!==r&&!c&&Math.abs(w)<h?re:le},step(o,b){s=o/(b||1),f(o)},native(o,b,c){let u=Math.max(1,(b-i)/oe);s=0,!c&&(u<30&&(s=o/u),i=b,f(o))},rest:()=>void(s=0),turn:f};return d}var Ie=t=>t<1?1-2**(-10*t):1,Je={lerp:.1,duration:0,easing:Ie,wheelMultiplier:1,wheel:!0,touchMultiplier:1,anchors:!0,autoResize:!0,nested:!0},Ze=(t,r,s,l)=>t+(r-t)*(1-Math.pow(1-Math.min(1,s),l*60)),Re=325,et=.5,tt=300,ot=100,nt=1500,rt=100,lt=100,it=30,Le=t=>typeof t=="string"?document.querySelector(t):t instanceof Element?t:null,at=t=>t==null||t.trim()===""?NaN:+t,st=t=>document.body?.getAttribute(t)??document.documentElement.getAttribute(t);function ct(t,r={}){let s=window,l=document.documentElement,i={...Je};/touch/.test(st("data-gl-scroll")||"")&&(i.touch=!0);for(let e in r)r[e]!==void 0&&(i[e]=r[e]);let f=new Set(Object.keys(r).filter(e=>r[e]!==void 0));for(let e of["lerp","duration"]){let n=i[e];Object.defineProperty(i,e,{enumerable:!0,get(){let a=f.has(e)?NaN:at(o.attr("data-gl-scroll-"+e));return a>0||a===0&&e!=="lerp"?a:n},set(a){n=a,f.add(e)}})}let d=i.wrapper===s?null:Le(i.wrapper)||(i.wrapper==null?document.querySelector("[data-gl-scroll-wrapper]"):null);d&&!d.hasAttribute("data-gl-scroll-wrapper")&&W("gl.scroll: mark the wrapper data-gl-scroll-wrapper",d);let o=Me(d,Le(i.content),i.autoResize),b=o.root,c=d||s,u=d?()=>d.scrollTop:()=>s.scrollY||0,h={top:0,behavior:"instant"},w=e=>{h.top=e,y.wrote(e,o.version),(d||s).scrollTo(h)},O=Te(o.root,()=>R),m=u(),g=m,y=Oe(m),v=!1,N=!1,k=!1,M=!1,ae=i.lerp,C=0,$=0,U=0,se=Ie,j=!1,X=null,ce=-1e9,ue=-1e9,G=0,de=0,Q=0,F=0,K=0,T=0,V=!1,H=e=>Math.max(0,Math.min(o.limit,e)),x=e=>O.publish(!!e,N?o.gutter?"stopped gutter":"stopped":v?"smooth":""),me=0,ke=d||document;function _e(){me=performance.now()+ot,ke.dispatchEvent(new CustomEvent("scrollend",{bubbles:!d,detail:{umber:!0}}))}let He=e=>{(v||performance.now()<me)&&!e.detail?.umber&&e.stopImmediatePropagation()};function J(){let e=v;A(),e&&x()}function A(e=u()){D?.(),D=null,v=j=k=!1,X=null,y.rest(),m=g=y.written=e}let D=null,Pe=e=>ue<performance.now()-rt&&fe(e.dt);function Ce(){v=!0,D=t.on("frame",Pe,{phase:"measure",order:-2e3})}function fe(e){if(!v||M)return;let n=u(),a=y.reconcile(n,v,!!T,o.version,o.vh);if(a===le)return A(n),x();if(a===re){let E=n-y.written;m=n,U+=E,g=H(g+E)}let p=m,S;if(C>0){$+=e;let E=Math.min(1,$/C);m=U+(g-U)*se(E),S=E>=1}else m=Ze(m,g,ae,e),S=Math.abs(g-m)<et;if(S&&(m=g),w(m),y.step(m-p,e*60),S){let E=X;A(u()),x(!0),_e(),E?.(R)}else x(!0)}function Y(e,n,a){let p=n.duration??i.duration;j=a,X=n.onComplete||null,k=!!n.lock,ae=n.lerp??i.lerp,p>0?(C=p,$=0,U=m,se=n.easing||i.easing):C=0,y.turn(e-g),g=e,Ce()}function Ue(e){if(typeof e=="number")return e;if(typeof e=="string"){if(/^(#|#?top|start)$/.test(e))return 0;if(/^(#?bottom|end)$/.test(e))return 1/0;let a=e[0]==="#"?document.getElementById(decodeURIComponent(e.slice(1))):null;try{e=a||document.querySelector(e)}catch{e=null}}return e instanceof Element?e.getBoundingClientRect().top-(d?d.getBoundingClientRect().top:0)+u()-(parseFloat(getComputedStyle(e).scrollMarginTop)||0)-(parseFloat(getComputedStyle(b).scrollPaddingTop)||0):null}function pe(e,n={}){if(M||(N||k)&&!n.force&&!n.immediate)return;let a=Ue(e);if(a===null||Number.isNaN(a))return W("gl.scroll.scrollTo(): no target",e);if(o.measure(),a=H(a+(n.offset||0)),n.immediate||V){let p=a-(v?m:u());return A(a),w(a),y.native(p,performance.now(),!!n.jump||Math.abs(p)>=o.vh),x(!0),t.wake(1),n.onComplete?.(R)}if(v||A(),o.revalidate(),o.snap||Z){(d||s).scrollTo({top:a,behavior:"smooth"});let p=n.onComplete;if(p){let S=d||document,E=()=>{clearTimeout(We),S.removeEventListener("scrollend",E),p(R)},We=setTimeout(E,nt);S.addEventListener("scrollend",E)}return}Y(a,n,!0)}let Z=!!t.licensed&&t.licence!==!0,B=(e,n,a)=>Z?0:ge(e,n,a,Fe),Fe={page:o,options:i,get destroyed(){return M},get stopped(){return N},get reduced(){return V},get locked(){return k},get active(){return v},get at(){return m}};function Ke(e){e.timeStamp-ce>tt&&o.revalidate(),ce=e.timeStamp,!v&&!M&&A();let n=ve(e,o.vh)*i.wheelMultiplier,a=B("wheel",e,n);a&&(e.preventDefault(),a>1&&Y(H((j?m:g)+n),{},!1))}function Ve(e){if(v||M)return;let n=u();if(y.reconcile(n,!1,!1,o.version,o.vh)===ne)return void(m=g=n);let a=n-y.written;y.native(a,e.timeStamp,Math.abs(a)>=o.vh),m=g=y.written=n,x()}function De(e){ye(e)&&(B("key",e,0)?e.preventDefault():v&&!e.defaultPrevented&&J())}function Ye(e){let n=Ee(e);if(!n)return;let[a,p]=n;o.revalidate();let S=B("anchor",e,0);if(!S||(e.preventDefault(),S===1))return;let E=typeof i.anchors=="object"?i.anchors:{};pe(p===l?0:p,{...E,offset:Se(a,p)??E.offset??0}),we(a,p,!e.detail)}function Be(e){let n=e.touches[0];if(e.type==="touchstart"){if(T=0,M||e.touches.length>1)return;o.revalidate(),de=n.clientX,Q=n.clientY,F=e.timeStamp,K=0,T=1,k||J()}else if(!n)T>2&&Y(H(g+(e.timeStamp-F>lt?0:K*Re)),{lerp:1-Math.exp(-oe/Re)},!1),T=0;else if(T){let a=(Q-n.clientY)*i.touchMultiplier;if(T===1){let S=Math.abs(n.clientX-de)>Math.abs(a)?0:B("touch",e,a);if(S===0)return void(T=0);T=1+S}if(e.cancelable&&e.preventDefault(),T<3)return;let p=e.timeStamp-F;p>0&&(K+=(a/p-K)*Math.min(1,p/it)),Q=n.clientY,F=e.timeStamp,Y(H(g+a),{lerp:1},!1)}}let P=[],L=(e,n,a,p={passive:!0})=>{e.addEventListener(n,a,p),P.push(()=>e.removeEventListener(n,a,p))};if(L(c,"wheel",Ke,{passive:!1}),L(c,"scroll",Ve),L(s,"scrollend",He,{capture:!0}),L(s,"keydown",De,{capture:!1}),L(document,"click",Ye,{capture:!1}),i.touch)for(let e of["touchstart","touchmove","touchend","touchcancel"])L(c,e,Be,{passive:e[5]!="m"});let ee=s.matchMedia?.("(prefers-reduced-motion: reduce)"),he=()=>{V=!!ee?.matches,V&&J()};he(),ee&&L(ee,"change",he),P.push(o.destroy,Ae()),P.push(()=>D?.()),P.push(t.on("destroy",()=>R.destroy())),o.off&&l.classList.contains("lenis")&&W("gl.scroll: Lenis runs here too; the wheel stays with it");let R={get animatedScroll(){return m},get scroll(){return m},get targetScroll(){return g},get actualScroll(){return u()},get limit(){return o.limit},get velocity(){return v||y.recent()?y.velocity:0},get direction(){return y.direction},get progress(){return o.limit?Math.min(1,Math.max(0,m/o.limit)):0},get isScrolling(){return v?"smooth":y.recent()&&"native"},get isStopped(){return N},get isLocked(){return k},rootElement:b,options:i,scrollTo:pe,stop(){N||M||(A(),N=!0,x())},start(){N&&(N=!1,A(),x())},resize(){o.revalidate(),o.measure(),v||A(),x()},on:(e,n)=>e==="scroll"?O.on(n):()=>{},off:(e,n)=>O.off(n),raf(e){ue=performance.now();let n=G?Math.min(.1,Math.max(0,(e-G)/1e3)):1/60;G=e,fe(n)},destroy(){M||(M=!0,v=!1,P.splice(0).forEach(e=>e()),O.clear(),t.scroll===R&&(t.scroll=void 0))}};return t.scroll=R,t.licensed?.().then(e=>Z=!e),R}var q={name:"scroll",version:"0.2.1",attributes:[],install(t,r){ct(t,r)}};var z=window;z.Umber?.use?z.Umber.use(q):((z.UmberModules||=[]).push(q),z.__umber?.engine?.use?.(q));})();
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ (()=>{function e(){return window}function t(){return document.body}var r=()=>{};function i(e,t,r,i){let o=r;return e.addEventListener(t,o,i),()=>{e.removeEventListener(t,o,i)}}var o={warn:r,error:r},n="data-umber-scroll-state",s=[()=>{e().ScrollTrigger?.update?.()}],l=e=>"auto"===e||"scroll"===e||"overlay"===e,a=e=>"contain"===e||"none"===e,h=e=>""!==e&&"none"!==e;function u(e){return(l(e.overflowY)?1:0)+(a(e.overscrollBehaviorY)?2:0)+(l(e.overflowX)?4:0)+(a(e.overscrollBehaviorX)?8:0)}var d=`[${n}~=smooth] iframe{pointer-events:none}[data-umber-scroll-prevent],[data-lenis-prevent]{overscroll-behavior:contain}`,c=0,p=null;var m="";function f(e){let t=null;return()=>t??=e().catch(e=>{throw t=null,e})}var v=f(()=>import(m+"scroll-touch.js")),g=null,w=f(()=>import(m+"scroll-more.js").then(e=>g=e)),b=class{constructor(e,t,r){this.engine=e,this.o=t,this.motion={kind:"rest"},this.stopped=!1,this.destroyed=!1,this.reduced=!1,this.userData={},this.more=g,this.arrived=()=>{},this.gesture={phase:"none",x:0,y:0,t:0,v:0},this.to={behavior:"instant"},this.quiet=0,this.keeper=null,this.rafAt=-1e9,this.ownEnd=null,this.onScrollEnd=e=>{(this.active||performance.now()<this.quiet)&&e!==this.ownEnd&&e.stopImmediatePropagation()},this.tick=e=>{this.rafAt<performance.now()-100&&this.step(e.dt)},this.scrollTo=(e,t={})=>{if("number"!=typeof e&&!this.more)return void this.need(()=>{this.scrollTo(e,t)});if(this.destroyed||(this.stopped||this.locked)&&!t.force&&!t.immediate)return;let r=this.place(e,t.offset);if(null!==r){if(t.immediate||this.reduced)return void this.jump(r,t);if(this.active||this.settle(),this.page.revalidate(),this.page.snap||this.held){this.scroller.scrollTo({[this.side]:r,behavior:"smooth"});let e=t.onComplete;e&&this.need(t=>{t.landed(this,e)})}else this.move(r,t,"script");t.onStart?.(this.api())}},this.onScroll=e=>{if(this.active||this.destroyed)return;let t=this.read();if(0===this.pos.reconcile(t,this.page,{moving:!1,touching:!1}))return this.target=t,void(this.animated=t);let r=t-this.pos.written;this.pos.native(r,e.timeStamp,Math.abs(r)>=this.page.screen),this.pos.written=t,this.target=t,this.animated=t,this.publish()},({wrapper:this.wrapper,page:this.page,notify:this.notify,api:this.api}=r);let i=this.wrapper;this.scroller=this.events=i??window;let o=this.page.horizontal;this.side=o?"left":"top",this.read=i?o?()=>i.scrollLeft:()=>i.scrollTop:o?()=>window.scrollX:()=>window.scrollY,this.animated=this.read(),this.target=this.animated,this.pos=function(e){let t=0,r=e=>{n.lastVelocity=n.velocity,n.velocity=e},i=-1e9,o=e=>{e&&(n.direction=e>0?1:-1)},n={written:e,velocity:0,lastVelocity:0,direction:0,recent:(e=performance.now())=>e-i<150,wrote(e,r){n.written=e,t=r},reconcile(e,r,i){let o=e-n.written;return o<=1.5&&o>=-1.5?0:i.moving&&r.version!==t&&!i.touching&&Math.abs(o)<r.screen?1:2},step(e,t){r(e/(t||1)),o(e)},native(e,t,n){let s=Math.max(1,(t-i)/16.666666666666668);r(n||s>=30?0:e/s),!n&&(i=t,o(e))},rest(){n.velocity&&r(0)},turn:o};return n}(this.animated),this.held=!!e.licensed&&!0!==e.licence}get active(){return"rest"!==this.motion.kind}get locked(){return"rest"!==this.motion.kind&&this.motion.lock}clamp(e){return this.o.infinite?e:Math.max(0,Math.min(this.page.limit,e))}wrap(e){return this.o.infinite&&this.more?this.more.wrap(this,e):e}need(e=()=>{}){this.more?e(this.more):w().then(t=>{this.more||this.arrived(this.more=t),this.destroyed||e(t)},e=>{o.warn("[umber] umber.scroll: modules/scroll-more.js could not load",e)})}write(e){e=this.wrap(e),this.to[this.side]=e,this.pos.wrote(e,this.page.version),this.scroller.scrollTo(this.to)}stateName(){return this.stopped?this.page.gutter?"stopped gutter":"stopped":this.active?"smooth":""}publish(e=!1){this.notify.publish(e,this.stateName())}landed(){this.quiet=performance.now()+100,(this.wrapper??document).dispatchEvent(this.ownEnd=new Event("scrollend",{bubbles:!this.wrapper}))}halt(){let e=this.active;this.settle(),e&&this.publish()}settle(e=this.read()){this.keeper?.(),this.keeper=null,this.motion={kind:"rest"},this.pos.rest(),this.pos.written=e,this.target=e,this.animated=e}go(){this.keeper=this.engine.on("frame",this.tick,{phase:"measure",order:-2e3})}step(e){let t=this.motion;if("rest"===t.kind||this.destroyed)return;let r=this.read(),i=this.pos.reconcile(r,this.page,{moving:!0,touching:"none"!==this.gesture.phase});if(2===i||1===i&&!this.more)return 1===i&&this.need(),this.settle(r),void this.publish();1===i&&this.more?.shift(this,t,r-this.pos.written);let o=this.animated,n="lerp"===t.kind?this.advance(t.amount,e):!this.more||this.more.advance(this,t,e);n&&(this.animated=this.target),this.write(this.animated),this.pos.step(this.animated-o,60*e),n?(this.settle(this.read()),this.publish(!0),this.landed(),t.complete?.(this.api()),this.userData={}):this.publish(!0)}advance(e,t){return this.animated=((e,t,r,i)=>r>=1?t:e+(t-e)*(1-Math.exp(60*-r*i)))(this.animated,this.target,e,t),Math.abs(this.target-this.animated)<.5}move(e,t,r){let i=t.duration??this.o.duration,o={by:r,lock:!!t.lock,complete:t.onComplete??null};!(i>0||t.lock)||this.more?(this.userData=t.userData??{},i>0?this.more?.tween(this,t,o,i):this.motion={...o,kind:"lerp",amount:t.lerp??this.o.lerp},this.pos.turn(e-this.target),this.target=e,this.go()):this.need(()=>{this.move(e,t,r)})}inputFrom(){return"rest"!==this.motion.kind&&"script"===this.motion.by?this.animated:this.target}place(e,t=0){let r="number"==typeof e?e:this.more?.resolve(this,e)??null;if(null===r||Number.isNaN(r))return o.warn("[umber] umber.scroll.scrollTo(): no target",e),null;this.page.measure();let i=Math.max(0,Math.min(this.page.limit,r+(n=t,Number.isNaN(n)?0:n)));var n;return this.o.infinite&&this.more?this.more.nearest(this,i):i}jump(e,t){let r=e-(this.active?this.animated:this.read());this.settle(this.wrap(e)),this.userData=t.userData??{},t.onStart?.(this.api()),this.write(e),this.pos.native(r,performance.now(),!!t.jump||Math.abs(r)>=this.page.screen),this.publish(!0),this.engine.wake(1),t.onComplete?.(this.api()),this.userData={}}end(){this.destroyed=!0,this.keeper?.(),this.keeper=null,this.motion={kind:"rest"}}},y=e=>`[data-umber-scroll-prevent${e}],[data-lenis-prevent${e}]`;function S(e,t,r,i){return e.matches(`${y("")},${y("-"+t)},${y(r?"-horizontal":"-vertical")}`)||!!i?.(e)}function k(e,{d:t,x:r},i){let o=i>>(r?2:0),n=r?e.scrollWidth:e.scrollHeight,s=r?e.clientWidth:e.clientHeight,l=r?e.scrollLeft:e.scrollTop;return!!(1&o)&&n>s&&(!!(2&o)||(t<0?l>0:l+s<n-1))}var E=e=>!e.held&&!e.destroyed&&!e.reduced&&e.o.wheel&&!e.page.off;var M=(e,t)=>r=>{e.more?.click(e,t,r)};function z(e){let t=t=>{!e.more&&e.o.anchors&&t.target instanceof Element&&t.target.closest('a[href*="#"],[data-umber-scroll-to]')&&e.need()};return["pointerover","focusin"].map(e=>i(document,e,t,{passive:!0,capture:!0}))}var T={gestureOrientation:"vertical",lerp:.1,duration:0,wheelMultiplier:1,wheel:!0,touchMultiplier:1,anchors:!0,autoResize:!0,nested:!0};function N(e){return"string"==typeof e?document.querySelector(e):e instanceof Element?e:null}var A,D=e=>null==e||""===e.trim()?NaN:+e,x=e=>t()?.getAttribute(e)??document.documentElement.getAttribute(e);function L(e,t={}){let r=O(e,t);return e.scroll=r,r}function O(l,a){let{options:m,fromPage:f}=function(e){let t={...T};for(let[r,i]of Object.entries(e))void 0!==i&&Object.assign(t,{[r]:i});let r=x("data-umber-scroll")??"";r.includes("touch")&&(t.touch=!0),r.includes("horizontal")&&!e.orientation&&(t.orientation="horizontal"),r.includes("infinite")&&(t.infinite=!0),"horizontal"===t.orientation&&!e.gestureOrientation&&(t.gestureOrientation="both");let i={lerp:NaN,duration:NaN},o=()=>{for(let r of["lerp","duration"]){let o=D(x("data-umber-scroll-"+r));void 0!==e[r]||!Number.isNaN(i[r])&&t[r]!==i[r]||(t[r]=i[r]=o>0||0===o&&"lerp"!==r?o:T[r])}};return o(),{options:t,fromPage:o}}(a),g=function(e){return e===window?null:N(e)??(null==e?document.querySelector("[data-umber~=scroller]"):null)}(m.wrapper),w=function(i,o,n,s){let l=window,a=document.documentElement,d=i??a,c=new WeakMap,p=0,m=[],f={root:d,wrapper:i,horizontal:s,limit:0,screen:800,gutter:0,version:0,snap:!1,held:!1,off:!1,attr:e=>t()?.getAttribute(e)??a.getAttribute(e),measure(){!function(e){let{wrapper:t,horizontal:r}=e,i=t??document.scrollingElement??document.documentElement,o=Math.max(0,r?i.scrollWidth-i.clientWidth:i.scrollHeight-i.clientHeight),n=function({wrapper:e,horizontal:t}){return e?t?e.clientWidth:e.clientHeight:t?innerWidth:innerHeight}(e)||800;(o!==e.limit||n!==e.screen)&&e.version++,e.limit=o,e.screen=n}(f)},revalidated:r,revalidate(){p++;let e=getComputedStyle(d),t=i?e:getComputedStyle(document.body);f.snap=h(e.scrollSnapType)||h(t.scrollSnapType);let r=s?"overflowX":"overflowY";f.held=/hidden|clip/.test(e[r]+t[r])||!i&&"fixed"===t.position,f.off=/^(off|native)$/.test(f.attr("data-umber-scroll")??"")||null!==document.querySelector("html.lenis, html.has-scroll-smooth, #smooth-wrapper"),f.revalidated()},style:e=>{let t=c.get(e);if(void 0!==t&&t>>4===p)return 15&t;let r=u(getComputedStyle(e));return c.set(e,16*p+r),r},destroy:()=>{m.splice(0).forEach(e=>{e()})}};if(f.measure(),f.revalidate(),n){let t=()=>{f.measure()};if(l.addEventListener("resize",t),m.push(()=>{l.removeEventListener("resize",t)}),e().ResizeObserver){let e=new ResizeObserver(t);e.observe(o??i?.firstElementChild??a),i&&e.observe(i),m.push(()=>{e.disconnect()})}}return f}(g,N(m.content),m.autoResize,"horizontal"===m.orientation),y=function(e){let t=new Set,r=new Set,i="",l=(e,t)=>{try{e(t)}catch(e){o.error("[umber]",e)}},a={publish(r,o){if(r)for(let e of s)l(e,void 0);o!==i&&(i=o,o?e.setAttribute(n,o):e.removeAttribute(n));let a=q;for(let e of t)l(e,a)},gesture(e){for(let t of r)l(t,e)},on:(e,i)=>("scroll"===e?t.add(i):"virtual-scroll"===e&&r.add(i),()=>{a.off(i)}),off(e){t.delete(e),r.delete(e)},clear(){t.clear(),r.clear(),e.removeAttribute(n)}};return a}(w.root),E=new b(l,m,{wrapper:g,page:w,notify:y,api:()=>q});E.events=N(m.eventsTarget)??E.scroller;let A=function(t){let r=function(e){return(t,r,i,o)=>function(e,t,r,i){if(function(e,t,r){let i=r.o;return!!(r.held||r.destroyed||r.stopped||r.page.off||t.defaultPrevented)||("anchor"===e?!i.anchors:"key"!==e&&!i[e])}(e,t,i))return 0;if("key"===e)return i.locked&&"Tab"!==t.key?1:0;if("anchor"===e)return function(e){return e.locked?1:e.page.limit?2:0}(i);if(function(e,t,r,i){let o=i.page,n=i.o;return!(!i.reduced&&r.d&&!o.snap&&!o.held)||function(e,t,r,i){let{root:o,prevent:n,nested:s=!0,style:l=e=>u(getComputedStyle(e))}=i;for(let i of e.composedPath()){if(i===o||!(i instanceof Element))break;if(S(i,t,r.x,n)||s&&r.d&&i!==document.body&&k(i,r,l(i)))return!0}return!1}(t,e,r.way,{root:o.root,prevent:n.prevent,nested:n.nested,style:o.style})}(e,t,r,i))return 0;if(i.locked)return 1;let o=r.d<0?i.animated<=0:i.animated>=i.page.limit;return i.active||!o||i.o.infinite?2:0}(t,r,{d:i,way:o??{d:i,x:e.page.horizontal}},e)}(t),n=[W(t,r),i(t.scroller,"scroll",t.onScroll,{passive:!0}),i(window,"scrollend",t.onScrollEnd,{capture:!0}),i(document,"click",M(t,r),{capture:!1}),...z(t)],s=e=>{n.push(i(window,"keydown",e.key(t,r),{capture:!1}))};t.more?s(t.more):t.arrived=s,t.o.touch&&v().then(e=>{t.destroyed||n.push(e.listenTouch(t,r))},e=>{o.warn("[umber] umber.scroll: smooth touch could not load; touch stays native",e)});let l=e().matchMedia?window.matchMedia("(prefers-reduced-motion: reduce)"):null,a=()=>{t.reduced=l?.matches??!1,t.reduced&&t.halt(),t.page.revalidated()};return a(),l&&n.push(i(l,"change",a,{passive:!0})),n}(E);A.push(()=>{w.destroy()},function(){c++||(p=function(e=""){let t=new CSSStyleSheet;return t.replaceSync(e),document.adoptedStyleSheets=[...document.adoptedStyleSheets,t],t}(d));let e=!1;return()=>{e||(e=!0,! --c&&(function(e){e&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(t=>t!==e))}(p),p=null))}}(),l.on("destroy",()=>{q.destroy()}));let L=r,q=function(e,{removeAll:t,resized:r}){let{page:i,pos:o,notify:n}=e;return{get animatedScroll(){return e.animated},get scroll(){return e.wrap(e.animated)},get targetScroll(){return e.target},get actualScroll(){return e.read()},get limit(){return i.limit},get velocity(){return e.active||o.recent()?o.velocity:0},get lastVelocity(){return o.lastVelocity},get userData(){return e.userData},get direction(){return o.direction},get progress(){return i.limit?Math.min(1,Math.max(0,e.wrap(e.animated)/i.limit)):0},get isScrolling(){return e.active?"smooth":o.recent()&&"native"},get isStopped(){return e.stopped},get isLocked(){return e.locked},nest:()=>Promise.resolve(null),rootElement:i.root,isHorizontal:i.horizontal,options:e.o,scrollTo:e.scrollTo,stop(){e.need(t=>{t.stop(e,!0)})},start(){e.more?.stop(e,!1)},resize(){r(),i.revalidate(),i.measure(),e.active||e.settle(),e.publish()},on:(e,t)=>n.on(e,t),off:(e,t)=>{n.off(t)},raf(t){e.need(r=>{r.raf(e,t)})},destroy(){e.destroyed||(e.end(),t(),n.clear())}}}(E,{removeAll(){A.splice(0).forEach(e=>{e()}),l.scroll===q&&(l.scroll=void 0)},resized(){f(),L()}}),C=e=>new Promise(t=>{E.need(r=>{t(r.setUp({glide:E,api:q,offs:A,create:e=>O(l,e)},e))})});return q.nest=(e,t)=>C([e,t]),L=()=>{!g&&document.querySelector("[data-umber~=nested]")&&C()},(m.infinite||m.duration||m.autoToggle||"vertical"!==m.gestureOrientation||document.querySelector("[data-umber~=container],[data-umber~=wrapper]")||!g&&document.querySelector("[data-umber~=nested]"))&&C(),l.licensed?.().then(e=>{E.held=!e,w.revalidated()}),q}function W(e,t){let o=null,n=r,s=()=>{let r=!E(e);r!==o&&(o=r,n(),n=i(e.events,"wheel",function(e,t,r){let i=-1e9;return o=>{if(o.timeStamp-i>300&&e.page.revalidate(),i=o.timeStamp,r||!E(e))return void e.page.revalidated();!e.active&&!e.destroyed&&e.settle();let n=e.o.wheelMultiplier,s=e.page,[l,a]=function(e,t,r){let i=e.deltaMode;return i===WheelEvent.DOM_DELTA_LINE?[19.2*e.deltaX,19.2*e.deltaY]:i===WheelEvent.DOM_DELTA_PAGE?[e.deltaX*t,e.deltaY*r]:[e.deltaX,e.deltaY]}(o,s.horizontal?s.screen:innerWidth,s.horizontal?innerHeight:s.screen);if(!function(e,t,r,i){let o={deltaX:t,deltaY:r,event:i};return!1!==e.o.virtualScroll?.(o)&&(e.notify.gesture(o),!0)}(e,l*n,a*n,o))return;let h=e.o.gestureOrientation,u=o.ctrlKey||o.shiftKey||Math.abs(l)>Math.abs(a)?0:a*n,d="vertical"===h?u:e.more?.along(l*n,a*n,h,o)??0,c=t("wheel",o,d,((e,t)=>Math.abs(e)>Math.abs(t)?{d:e,x:!0}:{d:t,x:!1})(l,a));c&&(o.preventDefault(),c>1&&e.move(e.clamp(e.inputFrom()+d),{},"input"))}}(e,t,r),{passive:r}))};return e.page.revalidated=s,s(),()=>{e.page.revalidated=r,n()}}!function(t){let r=function(e){(e=>{m=e})(e?.src?e.src.replace(/[^/]*$/,""):"https://umber.occluze.com/umber@0.3.0/modules/")}?.(document.currentScript instanceof HTMLScriptElement?document.currentScript:null),i=e();i.Umber?.use?i.Umber.use(t,r):(i.UmberModules??=[],i.UmberModules.push(r?[t,r]:t),i.__umber?.engine?.use?.(t,r))}({name:"scroll",version:"0.3.0",attributes:[],install:(A=({engine:e,options:t})=>{L(e,t)},(...e)=>{let[t,r,i,n,s]=e;(function(e){e&&(o=e)})(s),A({engine:t,options:r,keep:i,root:n})})})})();
@@ -1,2 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- var be=new Set;function W(t,...r){be.has(t)||(be.add(t),console.warn("[umber]",t,...r))}var Be=19.2;function Z(t,r){return t.ctrlKey||t.defaultPrevented||t.shiftKey||Math.abs(t.deltaX)>Math.abs(t.deltaY)?0:t.deltaY*(t.deltaMode===1?19.2:t.deltaMode===2?r:1)}var We=/^(Arrow(Up|Down)|Page(Up|Down)|Home|End| |Spacebar|Tab)$/;function ee(t){if(!We.test(t.key)||t.ctrlKey||t.metaKey||t.altKey)return!1;let r=t.target;return!(r&&(r.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(r.tagName)))}var te={any:"[data-gl-scroll-prevent],[data-lenis-prevent]",wheel:"[data-gl-scroll-prevent-wheel],[data-lenis-prevent-wheel]",touch:"[data-gl-scroll-prevent-touch],[data-lenis-prevent-touch]"};function qe(t,r,s,l,i,f=!0,d=ze){let o=t.composedPath();for(let b=0;b<o.length;b++){let c=o[b];if(c===r||!c.matches)break;if(c.matches(te.any)||te[s]&&c.matches(te[s])||i&&i(c))return!0;if(!f||!l||c===document.body)continue;let u=d(c);if(u&1&&c.scrollHeight>c.clientHeight&&(u&2||(l<0?c.scrollTop>0:c.scrollTop+c.clientHeight<c.scrollHeight-1)))return!0}return!1}var ze=t=>{let r=getComputedStyle(t);return(/auto|scroll|overlay/.test(r.overflowY)?1:0)+(/contain|none/.test(r.overscrollBehaviorY)?2:0)};function ve(t,r,s,l){let i=l.options,f=l.page;return l.destroyed||l.stopped||f.off||r.defaultPrevented||(t==="anchor"?!i.anchors:t!=="key"&&!i[t])?0:t==="key"?l.locked&&r.key!=="Tab"?1:0:t==="anchor"?l.locked?1:f.limit?2:0:l.reduced||!s||f.snap||f.held||qe(r,f.root,t,s,i.prevent,i.nested,f.style)?0:l.locked?1:!l.active&&(s<0?l.at<=0:l.at>=f.limit)?0:2}function ye(t){if(t.button||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return null;let r=t.target?.closest?.("a[href]");if(!r||!r.hash||r.target&&r.target!=="_self"||r.hasAttribute("download")||r.origin!==location.origin||r.pathname!==location.pathname||r.search!==location.search)return null;let s=decodeURIComponent(r.hash.slice(1)),l=document.getElementById(s)||(s==="top"?document.documentElement:null);return l&&[r,l]}function ge(t,r){for(let s of[t,r,document.body,document.documentElement]){let l=parseFloat(s?.getAttribute("data-gl-scroll-offset")??"");if(!isNaN(l))return l}return null}function Ee(t,r,s){if(location.hash!==t.hash){let i=location.href;history.pushState(null,"",t.href),dispatchEvent(new HashChangeEvent("hashchange",{oldURL:i,newURL:location.href}))}if(!s||r===document.documentElement)return;let l=r;!l.hasAttribute("tabindex")&&l.tabIndex<0&&(l.setAttribute("tabindex","-1"),l.addEventListener("blur",()=>l.removeAttribute("tabindex"),{once:!0})),l.focus({preventScroll:!0})}var I="data-gl-scroll-state",$e=[()=>globalThis.ScrollTrigger?.update?.()];function Se(t,r){let s=new Set,l="",i=d=>{try{d()}catch(o){console.error("[umber]",o)}},f=d=>{try{d(r())}catch(o){console.error("[umber]",o)}};return{publish(d,o){d&&$e.forEach(i),o!==l&&(l=o,o?t.setAttribute(I,o):t.removeAttribute(I)),s.forEach(f)},on(d){return s.add(d),()=>void s.delete(d)},off:d=>void s.delete(d),clear(){s.clear(),t.removeAttribute(I)}}}var je="html.lenis, html.has-scroll-smooth, #smooth-wrapper";function we(t,r,s){let l=globalThis,i=document.documentElement,f=t||i,d=new WeakMap,o=0,b=[],c={root:f,wrapper:t,limit:0,vh:800,gutter:0,version:0,snap:!1,held:!1,off:!1,attr:u=>document.body?.getAttribute(u)??i.getAttribute(u),measure(){let u=t||document.scrollingElement||i,h=Math.max(0,u.scrollHeight-u.clientHeight),w=(t?t.clientHeight:l.innerHeight)||800;(h!==c.limit||w!==c.vh)&&c.version++,c.limit=h,c.vh=w,/stopped/.test(f.getAttribute("data-gl-scroll-state")||"")||(c.gutter=Math.max(0,(t?t.offsetWidth-2*t.clientLeft:l.innerWidth)-f.clientWidth))},revalidate(){o++;let u=getComputedStyle(f),h=t?u:getComputedStyle(document.body);c.snap=(u.scrollSnapType||"none")+(h.scrollSnapType||"none")!=="nonenone",c.held=/hidden|clip/.test(u.overflowY+h.overflowY)||!t&&h.position==="fixed",c.off=/^(off|native)$/.test(c.attr("data-gl-scroll")||"")||!!document.querySelector(je)},style(u){let h=d.get(u);if(h===void 0||h>>2!==o){let w=getComputedStyle(u),O=w.overflowY,m=w.overscrollBehaviorY;d.set(u,h=o*4+(O==="auto"||O==="scroll"||O==="overlay"?1:0)+(m==="contain"||m==="none"?2:0))}return h&3},destroy:()=>b.splice(0).forEach(u=>u())};if(c.measure(),c.revalidate(),s){let u=()=>c.measure();if(l.addEventListener("resize",u),b.push(()=>l.removeEventListener("resize",u)),l.ResizeObserver){let h=new ResizeObserver(u);h.observe(r||t?.firstElementChild||i),t&&h.observe(t),b.push(()=>h.disconnect())}}return c}var Xe=`[${I}~=stopped]{overflow:hidden!important}[${I}~=gutter]{scrollbar-gutter:stable!important}[${I}~=smooth] iframe{pointer-events:none}[data-gl-scroll-prevent],[data-lenis-prevent]{overscroll-behavior:contain}`,Te=0,H=null;function Me(){Te++||(H=document.createElement("style"),H.setAttribute("data-gl-scroll-style",""),H.textContent=Xe,document.head.append(H));let t=!0;return()=>{t&&!(t=!1)&&!--Te&&(H?.remove(),H=null)}}var oe=16.666666666666668,ne=0,re=1,le=2;function xe(t){let r=0,s=0,l=0,i=-1e9,f=o=>o&&(l=o>0?1:-1),d={written:t,get velocity(){return s},get direction(){return l},recent:(o=performance.now())=>o-i<150,wrote(o,b){d.written=o,r=b},reconcile(o,b,c,u,h){let w=o-d.written;return w<=1.5&&w>=-1.5?ne:b&&u!==r&&!c&&Math.abs(w)<h?re:le},step(o,b){s=o/(b||1),f(o)},native(o,b,c){let u=Math.max(1,(b-i)/oe);s=0,!c&&(u<30&&(s=o/u),i=b,f(o))},rest:()=>void(s=0),turn:f};return d}var Re=t=>t<1?1-2**(-10*t):1,Qe={lerp:.1,duration:0,easing:Re,wheelMultiplier:1,wheel:!0,touchMultiplier:1,anchors:!0,autoResize:!0,nested:!0},Je=(t,r,s,l)=>t+(r-t)*(1-Math.pow(1-Math.min(1,s),l*60)),Oe=325,Ze=.5,et=300,tt=100,ot=1500,nt=100,rt=100,lt=30,Ne=t=>typeof t=="string"?document.querySelector(t):t instanceof Element?t:null,it=t=>t==null||t.trim()===""?NaN:+t,at=t=>document.body?.getAttribute(t)??document.documentElement.getAttribute(t);function st(t,r={}){let s=globalThis,l=document.documentElement,i={...Qe};/touch/.test(at("data-gl-scroll")||"")&&(i.touch=!0);for(let e in r)r[e]!==void 0&&(i[e]=r[e]);let f=new Set(Object.keys(r).filter(e=>r[e]!==void 0));for(let e of["lerp","duration"]){let n=i[e];Object.defineProperty(i,e,{enumerable:!0,get(){let a=f.has(e)?NaN:it(o.attr("data-gl-scroll-"+e));return a>0||a===0&&e!=="lerp"?a:n},set(a){n=a,f.add(e)}})}let d=i.wrapper===s?null:Ne(i.wrapper)||(i.wrapper==null?document.querySelector("[data-gl-scroll-wrapper]"):null);d&&!d.hasAttribute("data-gl-scroll-wrapper")&&W("gl.scroll: mark the wrapper data-gl-scroll-wrapper",d);let o=we(d,Ne(i.content),i.autoResize),b=o.root,c=d||s,u=d?()=>d.scrollTop:()=>s.scrollY||0,h={top:0,behavior:"instant"},w=e=>{h.top=e,y.wrote(e,o.version),(d||s).scrollTo(h)},O=Se(o.root,()=>R),m=u(),g=m,y=xe(m),v=!1,N=!1,k=!1,M=!1,ae=i.lerp,C=0,q=0,F=0,se=Re,z=!1,$=null,ce=-1e9,ue=-1e9,j=0,de=0,X=0,K=0,V=0,T=0,U=!1,P=e=>Math.max(0,Math.min(o.limit,e)),x=e=>O.publish(!!e,N?o.gutter?"stopped gutter":"stopped":v?"smooth":""),me=0,Le=d||document;function Ie(){me=performance.now()+tt,Le.dispatchEvent(new CustomEvent("scrollend",{bubbles:!d,detail:{umber:!0}}))}let ke=e=>{(v||performance.now()<me)&&!e.detail?.umber&&e.stopImmediatePropagation()};function G(){let e=v;A(),e&&x()}function A(e=u()){D?.(),D=null,v=z=k=!1,$=null,y.rest(),m=g=y.written=e}let D=null,He=e=>ue<performance.now()-nt&&fe(e.dt);function Pe(){v=!0,D=t.on("frame",He,{phase:"measure",order:-2e3})}function fe(e){if(!v||M)return;let n=u(),a=y.reconcile(n,v,!!T,o.version,o.vh);if(a===le)return A(n),x();if(a===re){let E=n-y.written;m=n,F+=E,g=P(g+E)}let p=m,S;if(C>0){q+=e;let E=Math.min(1,q/C);m=F+(g-F)*se(E),S=E>=1}else m=Je(m,g,ae,e),S=Math.abs(g-m)<Ze;if(S&&(m=g),w(m),y.step(m-p,e*60),S){let E=$;A(u()),x(!0),Ie(),E?.(R)}else x(!0)}function Y(e,n,a){let p=n.duration??i.duration;z=a,$=n.onComplete||null,k=!!n.lock,ae=n.lerp??i.lerp,p>0?(C=p,q=0,F=m,se=n.easing||i.easing):C=0,y.turn(e-g),g=e,Pe()}function _e(e){if(typeof e=="number")return e;if(typeof e=="string"){if(/^(#|#?top|start)$/.test(e))return 0;if(/^(#?bottom|end)$/.test(e))return 1/0;let a=e[0]==="#"?document.getElementById(decodeURIComponent(e.slice(1))):null;try{e=a||document.querySelector(e)}catch{e=null}}return e instanceof Element?e.getBoundingClientRect().top-(d?d.getBoundingClientRect().top:0)+u()-(parseFloat(getComputedStyle(e).scrollMarginTop)||0)-(parseFloat(getComputedStyle(b).scrollPaddingTop)||0):null}function pe(e,n={}){if(M||(N||k)&&!n.force&&!n.immediate)return;let a=_e(e);if(a===null||Number.isNaN(a))return W("gl.scroll.scrollTo(): no target",e);if(o.measure(),a=P(a+(n.offset||0)),n.immediate||U){let p=a-(v?m:u());return A(a),w(a),y.native(p,performance.now(),!!n.jump||Math.abs(p)>=o.vh),x(!0),t.wake(1),n.onComplete?.(R)}if(v||A(),o.revalidate(),o.snap||Q){(d||s).scrollTo({top:a,behavior:"smooth"});let p=n.onComplete;if(p){let S=d||document,E=()=>{clearTimeout(Ye),S.removeEventListener("scrollend",E),p(R)},Ye=setTimeout(E,ot);S.addEventListener("scrollend",E)}return}Y(a,n,!0)}let Q=!!t.licensed&&t.licence!==!0,B=(e,n,a)=>Q?0:ve(e,n,a,Ce),Ce={page:o,options:i,get destroyed(){return M},get stopped(){return N},get reduced(){return U},get locked(){return k},get active(){return v},get at(){return m}};function Fe(e){e.timeStamp-ce>et&&o.revalidate(),ce=e.timeStamp,!v&&!M&&A();let n=Z(e,o.vh)*i.wheelMultiplier,a=B("wheel",e,n);a&&(e.preventDefault(),a>1&&Y(P((z?m:g)+n),{},!1))}function Ke(e){if(v||M)return;let n=u();if(y.reconcile(n,!1,!1,o.version,o.vh)===ne)return void(m=g=n);let a=n-y.written;y.native(a,e.timeStamp,Math.abs(a)>=o.vh),m=g=y.written=n,x()}function Ve(e){ee(e)&&(B("key",e,0)?e.preventDefault():v&&!e.defaultPrevented&&G())}function Ue(e){let n=ye(e);if(!n)return;let[a,p]=n;o.revalidate();let S=B("anchor",e,0);if(!S||(e.preventDefault(),S===1))return;let E=typeof i.anchors=="object"?i.anchors:{};pe(p===l?0:p,{...E,offset:ge(a,p)??E.offset??0}),Ee(a,p,!e.detail)}function De(e){let n=e.touches[0];if(e.type==="touchstart"){if(T=0,M||e.touches.length>1)return;o.revalidate(),de=n.clientX,X=n.clientY,K=e.timeStamp,V=0,T=1,k||G()}else if(!n)T>2&&Y(P(g+(e.timeStamp-K>rt?0:V*Oe)),{lerp:1-Math.exp(-oe/Oe)},!1),T=0;else if(T){let a=(X-n.clientY)*i.touchMultiplier;if(T===1){let S=Math.abs(n.clientX-de)>Math.abs(a)?0:B("touch",e,a);if(S===0)return void(T=0);T=1+S}if(e.cancelable&&e.preventDefault(),T<3)return;let p=e.timeStamp-K;p>0&&(V+=(a/p-V)*Math.min(1,p/lt)),X=n.clientY,K=e.timeStamp,Y(P(g+a),{lerp:1},!1)}}let _=[],L=(e,n,a,p={passive:!0})=>{e.addEventListener(n,a,p),_.push(()=>e.removeEventListener(n,a,p))};if(L(c,"wheel",Fe,{passive:!1}),L(c,"scroll",Ke),L(s,"scrollend",ke,{capture:!0}),L(s,"keydown",Ve,{capture:!1}),L(document,"click",Ue,{capture:!1}),i.touch)for(let e of["touchstart","touchmove","touchend","touchcancel"])L(c,e,De,{passive:e[5]!="m"});let J=s.matchMedia?.("(prefers-reduced-motion: reduce)"),he=()=>{U=!!J?.matches,U&&G()};he(),J&&L(J,"change",he),_.push(o.destroy,Me()),_.push(()=>D?.()),_.push(t.on("destroy",()=>R.destroy())),o.off&&l.classList.contains("lenis")&&W("gl.scroll: Lenis runs here too; the wheel stays with it");let R={get animatedScroll(){return m},get scroll(){return m},get targetScroll(){return g},get actualScroll(){return u()},get limit(){return o.limit},get velocity(){return v||y.recent()?y.velocity:0},get direction(){return y.direction},get progress(){return o.limit?Math.min(1,Math.max(0,m/o.limit)):0},get isScrolling(){return v?"smooth":y.recent()&&"native"},get isStopped(){return N},get isLocked(){return k},rootElement:b,options:i,scrollTo:pe,stop(){N||M||(A(),N=!0,x())},start(){N&&(N=!1,A(),x())},resize(){o.revalidate(),o.measure(),v||A(),x()},on:(e,n)=>e==="scroll"?O.on(n):()=>{},off:(e,n)=>O.off(n),raf(e){ue=performance.now();let n=j?Math.min(.1,Math.max(0,(e-j)/1e3)):1/60;j=e,fe(n)},destroy(){M||(M=!0,v=!1,_.splice(0).forEach(e=>e()),O.clear(),t.scroll===R&&(t.scroll=void 0))}};return t.scroll=R,t.licensed?.().then(e=>Q=!e),R}var ct={name:"scroll",version:"0.2.1",attributes:[],install(t,r){st(t,r)}},Ot=ct;export{Qe as DEFAULTS,Be as LINE,ct as Scroll,Je as damp,Ot as default,Re as expoOut,ee as scrollKey,st as smoothScroll,Z as wheelY};
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ function e(){return globalThis}function t(){return document.body}var r=()=>{};function i(e,t,r,i){let o=r;return e.addEventListener(t,o,i),()=>{e.removeEventListener(t,o,i)}}var o={warn:r,error:r},n="data-umber-scroll-state",s=[()=>{e().ScrollTrigger?.update?.()}],l=e=>"auto"===e||"scroll"===e||"overlay"===e,a=e=>"contain"===e||"none"===e,h=e=>""!==e&&"none"!==e;function u(e){return(l(e.overflowY)?1:0)+(a(e.overscrollBehaviorY)?2:0)+(l(e.overflowX)?4:0)+(a(e.overscrollBehaviorX)?8:0)}var d=`[${n}~=smooth] iframe{pointer-events:none}[data-umber-scroll-prevent],[data-lenis-prevent]{overscroll-behavior:contain}`,c=0,p=null;function m(e){let t=null;return()=>t??=e().catch(e=>{throw t=null,e})}var f=m(()=>import("./scroll-touch.js")),v=null,g=m(()=>import("./scroll-more.js").then(e=>v=e)),b=(e,t,r,i)=>r>=1?t:e+(t-e)*(1-Math.exp(60*-r*i)),y=class{constructor(e,t,r){this.engine=e,this.o=t,this.motion={kind:"rest"},this.stopped=!1,this.destroyed=!1,this.reduced=!1,this.userData={},this.more=v,this.arrived=()=>{},this.gesture={phase:"none",x:0,y:0,t:0,v:0},this.to={behavior:"instant"},this.quiet=0,this.keeper=null,this.rafAt=-1e9,this.ownEnd=null,this.onScrollEnd=e=>{(this.active||performance.now()<this.quiet)&&e!==this.ownEnd&&e.stopImmediatePropagation()},this.tick=e=>{this.rafAt<performance.now()-100&&this.step(e.dt)},this.scrollTo=(e,t={})=>{if("number"!=typeof e&&!this.more)return void this.need(()=>{this.scrollTo(e,t)});if(this.destroyed||(this.stopped||this.locked)&&!t.force&&!t.immediate)return;let r=this.place(e,t.offset);if(null!==r){if(t.immediate||this.reduced)return void this.jump(r,t);if(this.active||this.settle(),this.page.revalidate(),this.page.snap||this.held){this.scroller.scrollTo({[this.side]:r,behavior:"smooth"});let e=t.onComplete;e&&this.need(t=>{t.landed(this,e)})}else this.move(r,t,"script");t.onStart?.(this.api())}},this.onScroll=e=>{if(this.active||this.destroyed)return;let t=this.read();if(0===this.pos.reconcile(t,this.page,{moving:!1,touching:!1}))return this.target=t,void(this.animated=t);let r=t-this.pos.written;this.pos.native(r,e.timeStamp,Math.abs(r)>=this.page.screen),this.pos.written=t,this.target=t,this.animated=t,this.publish()},({wrapper:this.wrapper,page:this.page,notify:this.notify,api:this.api}=r);let i=this.wrapper;this.scroller=this.events=i??globalThis;let o=this.page.horizontal;this.side=o?"left":"top",this.read=i?o?()=>i.scrollLeft:()=>i.scrollTop:o?()=>globalThis.scrollX:()=>globalThis.scrollY,this.animated=this.read(),this.target=this.animated,this.pos=function(e){let t=0,r=e=>{n.lastVelocity=n.velocity,n.velocity=e},i=-1e9,o=e=>{e&&(n.direction=e>0?1:-1)},n={written:e,velocity:0,lastVelocity:0,direction:0,recent:(e=performance.now())=>e-i<150,wrote(e,r){n.written=e,t=r},reconcile(e,r,i){let o=e-n.written;return o<=1.5&&o>=-1.5?0:i.moving&&r.version!==t&&!i.touching&&Math.abs(o)<r.screen?1:2},step(e,t){r(e/(t||1)),o(e)},native(e,t,n){let s=Math.max(1,(t-i)/16.666666666666668);r(n||s>=30?0:e/s),!n&&(i=t,o(e))},rest(){n.velocity&&r(0)},turn:o};return n}(this.animated),this.held=!!e.licensed&&!0!==e.licence}get active(){return"rest"!==this.motion.kind}get locked(){return"rest"!==this.motion.kind&&this.motion.lock}clamp(e){return this.o.infinite?e:Math.max(0,Math.min(this.page.limit,e))}wrap(e){return this.o.infinite&&this.more?this.more.wrap(this,e):e}need(e=()=>{}){this.more?e(this.more):g().then(t=>{this.more||this.arrived(this.more=t),this.destroyed||e(t)},e=>{o.warn("[umber] umber.scroll: modules/scroll-more.js could not load",e)})}write(e){e=this.wrap(e),this.to[this.side]=e,this.pos.wrote(e,this.page.version),this.scroller.scrollTo(this.to)}stateName(){return this.stopped?this.page.gutter?"stopped gutter":"stopped":this.active?"smooth":""}publish(e=!1){this.notify.publish(e,this.stateName())}landed(){this.quiet=performance.now()+100,(this.wrapper??document).dispatchEvent(this.ownEnd=new Event("scrollend",{bubbles:!this.wrapper}))}halt(){let e=this.active;this.settle(),e&&this.publish()}settle(e=this.read()){this.keeper?.(),this.keeper=null,this.motion={kind:"rest"},this.pos.rest(),this.pos.written=e,this.target=e,this.animated=e}go(){this.keeper=this.engine.on("frame",this.tick,{phase:"measure",order:-2e3})}step(e){let t=this.motion;if("rest"===t.kind||this.destroyed)return;let r=this.read(),i=this.pos.reconcile(r,this.page,{moving:!0,touching:"none"!==this.gesture.phase});if(2===i||1===i&&!this.more)return 1===i&&this.need(),this.settle(r),void this.publish();1===i&&this.more?.shift(this,t,r-this.pos.written);let o=this.animated,n="lerp"===t.kind?this.advance(t.amount,e):!this.more||this.more.advance(this,t,e);n&&(this.animated=this.target),this.write(this.animated),this.pos.step(this.animated-o,60*e),n?(this.settle(this.read()),this.publish(!0),this.landed(),t.complete?.(this.api()),this.userData={}):this.publish(!0)}advance(e,t){return this.animated=b(this.animated,this.target,e,t),Math.abs(this.target-this.animated)<.5}move(e,t,r){let i=t.duration??this.o.duration,o={by:r,lock:!!t.lock,complete:t.onComplete??null};!(i>0||t.lock)||this.more?(this.userData=t.userData??{},i>0?this.more?.tween(this,t,o,i):this.motion={...o,kind:"lerp",amount:t.lerp??this.o.lerp},this.pos.turn(e-this.target),this.target=e,this.go()):this.need(()=>{this.move(e,t,r)})}inputFrom(){return"rest"!==this.motion.kind&&"script"===this.motion.by?this.animated:this.target}place(e,t=0){let r="number"==typeof e?e:this.more?.resolve(this,e)??null;if(null===r||Number.isNaN(r))return o.warn("[umber] umber.scroll.scrollTo(): no target",e),null;this.page.measure();let i=Math.max(0,Math.min(this.page.limit,r+(n=t,Number.isNaN(n)?0:n)));var n;return this.o.infinite&&this.more?this.more.nearest(this,i):i}jump(e,t){let r=e-(this.active?this.animated:this.read());this.settle(this.wrap(e)),this.userData=t.userData??{},t.onStart?.(this.api()),this.write(e),this.pos.native(r,performance.now(),!!t.jump||Math.abs(r)>=this.page.screen),this.publish(!0),this.engine.wake(1),t.onComplete?.(this.api()),this.userData={}}end(){this.destroyed=!0,this.keeper?.(),this.keeper=null,this.motion={kind:"rest"}}},w=19.2;function S(e,t,r){let i=e.deltaMode;return i===WheelEvent.DOM_DELTA_LINE?[19.2*e.deltaX,19.2*e.deltaY]:i===WheelEvent.DOM_DELTA_PAGE?[e.deltaX*t,e.deltaY*r]:[e.deltaX,e.deltaY]}function k(e,t,r,i){return i.ctrlKey?0:"both"===r?Math.abs(t)>Math.abs(e)?t:e:"horizontal"===r?e||(i.shiftKey?t:0):i.shiftKey||Math.abs(e)>Math.abs(t)?0:t}var E=/^(Arrow(Up|Down|Left|Right)|Page(Up|Down)|Home|End| |Spacebar|Tab)$/;function T(e){if(!E.test(e.key)||e.ctrlKey||e.metaKey||e.altKey)return!1;let t=e.target;return!(t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))}var M=e=>`[data-umber-scroll-prevent${e}],[data-lenis-prevent${e}]`;function z(e,t,r,i){return e.matches(`${M("")},${M("-"+t)},${M(r?"-horizontal":"-vertical")}`)||!!i?.(e)}function N(e,{d:t,x:r},i){let o=i>>(r?2:0),n=r?e.scrollWidth:e.scrollHeight,s=r?e.clientWidth:e.clientHeight,l=r?e.scrollLeft:e.scrollTop;return!!(1&o)&&n>s&&(!!(2&o)||(t<0?l>0:l+s<n-1))}var A=e=>!e.held&&!e.destroyed&&!e.reduced&&e.o.wheel&&!e.page.off;var D=(e,t)=>r=>{e.more?.click(e,t,r)};function x(e){let t=t=>{!e.more&&e.o.anchors&&t.target instanceof Element&&t.target.closest('a[href*="#"],[data-umber-scroll-to]')&&e.need()};return["pointerover","focusin"].map(e=>i(document,e,t,{passive:!0,capture:!0}))}var L={gestureOrientation:"vertical",lerp:.1,duration:0,wheelMultiplier:1,wheel:!0,touchMultiplier:1,anchors:!0,autoResize:!0,nested:!0};function C(e){return"string"==typeof e?document.querySelector(e):e instanceof Element?e:null}var O=e=>null==e||""===e.trim()?NaN:+e,P=e=>t()?.getAttribute(e)??document.documentElement.getAttribute(e);function W(e,t={}){let r=q(e,t);return e.scroll=r,r}function q(l,a){let{options:m,fromPage:v}=function(e){let t={...L};for(let[r,i]of Object.entries(e))void 0!==i&&Object.assign(t,{[r]:i});let r=P("data-umber-scroll")??"";r.includes("touch")&&(t.touch=!0),r.includes("horizontal")&&!e.orientation&&(t.orientation="horizontal"),r.includes("infinite")&&(t.infinite=!0),"horizontal"===t.orientation&&!e.gestureOrientation&&(t.gestureOrientation="both");let i={lerp:NaN,duration:NaN},o=()=>{for(let r of["lerp","duration"]){let o=O(P("data-umber-scroll-"+r));void 0!==e[r]||!Number.isNaN(i[r])&&t[r]!==i[r]||(t[r]=i[r]=o>0||0===o&&"lerp"!==r?o:L[r])}};return o(),{options:t,fromPage:o}}(a),g=function(e){return e===globalThis?null:C(e)??(null==e?document.querySelector("[data-umber~=scroller]"):null)}(m.wrapper),b=function(i,o,n,s){let l=globalThis,a=document.documentElement,d=i??a,c=new WeakMap,p=0,m=[],f={root:d,wrapper:i,horizontal:s,limit:0,screen:800,gutter:0,version:0,snap:!1,held:!1,off:!1,attr:e=>t()?.getAttribute(e)??a.getAttribute(e),measure(){!function(e){let{wrapper:t,horizontal:r}=e,i=t??document.scrollingElement??document.documentElement,o=Math.max(0,r?i.scrollWidth-i.clientWidth:i.scrollHeight-i.clientHeight),n=function({wrapper:e,horizontal:t}){return e?t?e.clientWidth:e.clientHeight:t?innerWidth:innerHeight}(e)||800;(o!==e.limit||n!==e.screen)&&e.version++,e.limit=o,e.screen=n}(f)},revalidated:r,revalidate(){p++;let e=getComputedStyle(d),t=i?e:getComputedStyle(document.body);f.snap=h(e.scrollSnapType)||h(t.scrollSnapType);let r=s?"overflowX":"overflowY";f.held=/hidden|clip/.test(e[r]+t[r])||!i&&"fixed"===t.position,f.off=/^(off|native)$/.test(f.attr("data-umber-scroll")??"")||null!==document.querySelector("html.lenis, html.has-scroll-smooth, #smooth-wrapper"),f.revalidated()},style:e=>{let t=c.get(e);if(void 0!==t&&t>>4===p)return 15&t;let r=u(getComputedStyle(e));return c.set(e,16*p+r),r},destroy:()=>{m.splice(0).forEach(e=>{e()})}};if(f.measure(),f.revalidate(),n){let t=()=>{f.measure()};if(l.addEventListener("resize",t),m.push(()=>{l.removeEventListener("resize",t)}),e().ResizeObserver){let e=new ResizeObserver(t);e.observe(o??i?.firstElementChild??a),i&&e.observe(i),m.push(()=>{e.disconnect()})}}return f}(g,C(m.content),m.autoResize,"horizontal"===m.orientation),w=function(e){let t=new Set,r=new Set,i="",l=(e,t)=>{try{e(t)}catch(e){o.error("[umber]",e)}},a={publish(r,o){if(r)for(let e of s)l(e,void 0);o!==i&&(i=o,o?e.setAttribute(n,o):e.removeAttribute(n));let a=T;for(let e of t)l(e,a)},gesture(e){for(let t of r)l(t,e)},on:(e,i)=>("scroll"===e?t.add(i):"virtual-scroll"===e&&r.add(i),()=>{a.off(i)}),off(e){t.delete(e),r.delete(e)},clear(){t.clear(),r.clear(),e.removeAttribute(n)}};return a}(b.root),S=new y(l,m,{wrapper:g,page:b,notify:w,api:()=>T});S.events=C(m.eventsTarget)??S.scroller;let k=function(t){let r=function(e){return(t,r,i,o)=>function(e,t,r,i){if(function(e,t,r){let i=r.o;return!!(r.held||r.destroyed||r.stopped||r.page.off||t.defaultPrevented)||("anchor"===e?!i.anchors:"key"!==e&&!i[e])}(e,t,i))return 0;if("key"===e)return i.locked&&"Tab"!==t.key?1:0;if("anchor"===e)return function(e){return e.locked?1:e.page.limit?2:0}(i);if(function(e,t,r,i){let o=i.page,n=i.o;return!(!i.reduced&&r.d&&!o.snap&&!o.held)||function(e,t,r,i){let{root:o,prevent:n,nested:s=!0,style:l=e=>u(getComputedStyle(e))}=i;for(let i of e.composedPath()){if(i===o||!(i instanceof Element))break;if(z(i,t,r.x,n)||s&&r.d&&i!==document.body&&N(i,r,l(i)))return!0}return!1}(t,e,r.way,{root:o.root,prevent:n.prevent,nested:n.nested,style:o.style})}(e,t,r,i))return 0;if(i.locked)return 1;let o=r.d<0?i.animated<=0:i.animated>=i.page.limit;return i.active||!o||i.o.infinite?2:0}(t,r,{d:i,way:o??{d:i,x:e.page.horizontal}},e)}(t),n=[H(t,r),i(t.scroller,"scroll",t.onScroll,{passive:!0}),i(globalThis,"scrollend",t.onScrollEnd,{capture:!0}),i(document,"click",D(t,r),{capture:!1}),...x(t)],s=e=>{n.push(i(globalThis,"keydown",e.key(t,r),{capture:!1}))};t.more?s(t.more):t.arrived=s,t.o.touch&&f().then(e=>{t.destroyed||n.push(e.listenTouch(t,r))},e=>{o.warn("[umber] umber.scroll: smooth touch could not load; touch stays native",e)});let l=e().matchMedia?globalThis.matchMedia("(prefers-reduced-motion: reduce)"):null,a=()=>{t.reduced=l?.matches??!1,t.reduced&&t.halt(),t.page.revalidated()};return a(),l&&n.push(i(l,"change",a,{passive:!0})),n}(S);k.push(()=>{b.destroy()},function(){c++||(p=function(e=""){let t=new CSSStyleSheet;return t.replaceSync(e),document.adoptedStyleSheets=[...document.adoptedStyleSheets,t],t}(d));let e=!1;return()=>{e||(e=!0,! --c&&(function(e){e&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(t=>t!==e))}(p),p=null))}}(),l.on("destroy",()=>{T.destroy()}));let E=r,T=function(e,{removeAll:t,resized:r}){let{page:i,pos:o,notify:n}=e;return{get animatedScroll(){return e.animated},get scroll(){return e.wrap(e.animated)},get targetScroll(){return e.target},get actualScroll(){return e.read()},get limit(){return i.limit},get velocity(){return e.active||o.recent()?o.velocity:0},get lastVelocity(){return o.lastVelocity},get userData(){return e.userData},get direction(){return o.direction},get progress(){return i.limit?Math.min(1,Math.max(0,e.wrap(e.animated)/i.limit)):0},get isScrolling(){return e.active?"smooth":o.recent()&&"native"},get isStopped(){return e.stopped},get isLocked(){return e.locked},nest:()=>Promise.resolve(null),rootElement:i.root,isHorizontal:i.horizontal,options:e.o,scrollTo:e.scrollTo,stop(){e.need(t=>{t.stop(e,!0)})},start(){e.more?.stop(e,!1)},resize(){r(),i.revalidate(),i.measure(),e.active||e.settle(),e.publish()},on:(e,t)=>n.on(e,t),off:(e,t)=>{n.off(t)},raf(t){e.need(r=>{r.raf(e,t)})},destroy(){e.destroyed||(e.end(),t(),n.clear())}}}(S,{removeAll(){k.splice(0).forEach(e=>{e()}),l.scroll===T&&(l.scroll=void 0)},resized(){v(),E()}}),M=e=>new Promise(t=>{S.need(r=>{t(r.setUp({glide:S,api:T,offs:k,create:e=>q(l,e)},e))})});return T.nest=(e,t)=>M([e,t]),E=()=>{!g&&document.querySelector("[data-umber~=nested]")&&M()},(m.infinite||m.duration||m.autoToggle||"vertical"!==m.gestureOrientation||document.querySelector("[data-umber~=container],[data-umber~=wrapper]")||!g&&document.querySelector("[data-umber~=nested]"))&&M(),l.licensed?.().then(e=>{S.held=!e,b.revalidated()}),T}function H(e,t){let o=null,n=r,s=()=>{let r=!A(e);r!==o&&(o=r,n(),n=i(e.events,"wheel",function(e,t,r){let i=-1e9;return o=>{if(o.timeStamp-i>300&&e.page.revalidate(),i=o.timeStamp,r||!A(e))return void e.page.revalidated();!e.active&&!e.destroyed&&e.settle();let n=e.o.wheelMultiplier,s=e.page,[l,a]=S(o,s.horizontal?s.screen:innerWidth,s.horizontal?innerHeight:s.screen);if(!function(e,t,r,i){let o={deltaX:t,deltaY:r,event:i};return!1!==e.o.virtualScroll?.(o)&&(e.notify.gesture(o),!0)}(e,l*n,a*n,o))return;let h=e.o.gestureOrientation,u=o.ctrlKey||o.shiftKey||Math.abs(l)>Math.abs(a)?0:a*n,d="vertical"===h?u:e.more?.along(l*n,a*n,h,o)??0,c=t("wheel",o,d,((e,t)=>Math.abs(e)>Math.abs(t)?{d:e,x:!0}:{d:t,x:!1})(l,a));c&&(o.preventDefault(),c>1&&e.move(e.clamp(e.inputFrom()+d),{},"input"))}}(e,t,r),{passive:r}))};return e.page.revalidated=s,s(),()=>{e.page.revalidated=r,n()}}var K,X={name:"scroll",version:"0.3.0",attributes:[],install:(K=({engine:e,options:t})=>{W(e,t)},(...e)=>{let[t,r,i,n,s]=e;(function(e){e&&(o=e)})(s),K({engine:t,options:r,keep:i,root:n})})},$=X;export{L as DEFAULTS,w as LINE,X as Scroll,k as along,b as damp,$ as default,T as scrollKey,W as smoothScroll,S as wheelPx};
@@ -0,0 +1,2 @@
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ (()=>{function e(){return window}var t=()=>{};function r(t){return e().matchMedia?window.matchMedia(t):null}var a={warn:t,error:t},n=(e,t)=>parseFloat(e.getAttribute(t)??""),o=(e,t)=>{let r=e.getAttribute(t);return null===r||""===r?void 0:r},l=new Set;function s(e=""){let t=new CSSStyleSheet;return t.replaceSync(e),document.adoptedStyleSheets=[...document.adoptedStyleSheets,t],t}var i="[data-umber~=pin],[data-umber-pin]{position:sticky;top:0}[data-umber~=horizontal]{position:relative;overflow-x:clip}[data-umber~=horizontal]>:first-child{position:sticky;top:0;width:max-content;translate:calc(var(--umber-horizontal,0)*var(--umber-horizontal-px,0px)*-1) 0}",u=null,d=0;function c(e){let t=e.getAttribute("data-umber-fx")??String(++d);e.setAttribute("data-umber-fx",t);let r=new Map,a=null;return{set(e,n){r.get(e)!==n&&(r.set(e,n),(a??=((e,t)=>e.cssRules[e.insertRule(`${t}{}`,e.cssRules.length)])(u??=s(i),`[data-umber-fx="${t}"]`)).style.setProperty(e,n))},remove(){r.clear(),function(e){let t=e?.parentStyleSheet;if(!t)return;let r=[...t.cssRules].indexOf(e);r>=0&&t.deleteRule(r)}(a),a=null}}}function m(e,t,r){return{target:e,way:t?"enter":"leave",from:r<.5?"start":"end"}}function p(e,t,r,a){let n=1-Math.min(1,Math.max(0,r));return e+(t-e)*(1-Math.pow(n,60*Math.max(0,a)))}var h=(e,t=0,r=1)=>Math.min(r,Math.max(t,e)),f=`:is(${["image","video","text","shader","layer","model","group"].map(e=>`[data-umber~=${e}]`).join()})`;function b(e,t,r,a){return e<a?-h(r/Math.max(1,e+t))*a:v(e,t,r,a)}function v(e,t,r,a){return-(2*h((r-e+a)/Math.max(1,a+t))-1)*a}function g(e,t,r){let a=n(t,"data-umber-speed")||0,o=h(n(t,"data-umber-lag")||0),l=[...t.matches(f)?[t]:[],...t.querySelectorAll(f)];return e.wake(),{el:t,t:e.track(t),rule:c(t),speed:a,lag:o,smooth:r,touch:t.hasAttribute("data-umber-speed-touch"),fold:!t.hasAttribute("data-umber-speed-ignore-fold"),measured:NaN,base:0,written:0,trail:NaN,drawn:NaN,speedPx:0,velocity:{value:0},lagPx:{value:0},planes:l,planeEls:l}}function x(e,t,r){let{s:a,screen:n}=t;if(e.trail=Math.abs(a-e.trail)<n?p(e.trail,a,e.lag,t.dt):a,e.lagPx.value=e.lag?a-e.trail:0,!t.moves(e))return 0;let o=(e.speed?(e.fold?b:v)(e.base,r,a,n)*e.speed:0)+e.lagPx.value;return Math.round(100*o)/100}function y(e,t,r){let a=t.t.rect,n=(r.x?a.x:a.y)+r.s;n!==t.measured&&(t.measured=n,t.base=n-t.written);let o=x(t,r,r.x?a.width:a.height);o!==t.written&&(t.written=o,t.rule.set("translate",r.x?`${o}px 0`:`0 ${o}px`)),function(e,t,r,a){let n=null;r&&(n=a?[r,0]:[0,r]);for(let r of t.planeEls){let t=e.plane(r);t&&(t.offset=n)}}(e,t,o,r.x),t.lag&&t.rule.set("--umber-lag",`${t.lagPx.value.toFixed(2)}px`);let l=Math.abs(t.lagPx.value)>.05,s=!!t.smooth&&function(e,t){let r=e.base-t.s+e.written,a=e.drawn-r;e.drawn=r;let n=Math.abs(a)<t.screen&&t.dt>0?a/t.dt:0;return e.speedPx=p(e.speedPx,n,e.smooth,t.dt),!n&&Math.abs(e.speedPx)<1&&(e.speedPx=0),e.velocity.value=h(e.speedPx/t.fullSpeed,-1,1),e.rule.set("--umber-velocity",e.velocity.value.toFixed(4)),0!==e.speedPx}(t,r);return t.planes.length&&function(e,t){t.planes=t.planes.filter(r=>{let a=e.plane(r);return!a||("uPlaneVelocity"in a.uniforms&&a.set("uPlaneVelocity",t.velocity),"uPlaneLag"in a.uniforms&&a.set("uPlaneLag",t.lagPx),!1)})}(e,t),l||s}function w(e,t,r){return"center"===e?t/2-r/2:"end"===e?t-r:0}function S(e){let t=e.isHorizontal,r=t?innerWidth:innerHeight,a=[];for(let n of document.querySelectorAll("[data-umber-snap]")){let o=n.getBoundingClientRect(),l=(t?o.left:o.top)+e.actualScroll,s=t?o.width:o.height;for(let t of(n.getAttribute("data-umber-snap")??"").split(/[\s,]+/)){let n=l+w(t,s,r);a.push(Math.round(Math.max(0,Math.min(e.limit,n))))}}return a.sort((e,t)=>e-t)}new Set(["data-umber","data-umber-effect","data-umber-shader","data-umber-layer","data-umber-instances"]);var M,A="[data-umber~=inview],[data-umber-inview]",P="[data-umber~=pin],[data-umber-pin]",z="[data-umber~=horizontal]",E=`${A},${P},${z},[data-umber-call],[data-umber-progress],[data-umber-speed],[data-umber-lag],[data-umber-velocity]`,$=e=>{for(let t of e)t()};function k(e,r,s,i){let u=[];(r.matches(A)||r.hasAttribute("data-umber-call"))&&u.push(function(e,t,r){let a=t.matches("[data-umber~=inview],[data-umber-inview]")?o(t,"data-umber-inview")??"is-inview":"",n=t.hasAttribute("data-umber-inview-repeat"),l=t.getAttribute("data-umber-call"),s=e.progress(t,{start:o(t,"data-umber-inview-start"),end:o(t,"data-umber-inview-end"),axis:r}),i=!1,u=0;return s.on("change",()=>{let e=s.value,r=e>0&&e<1,o=r?u:e;u=e,r!==i&&(r||n)&&(i=r,a&&t.classList.toggle(a,r),l&&dispatchEvent(new CustomEvent(l,{detail:m(t,r,o)})),r&&!n&&queueMicrotask(()=>{s.destroy()}))}),()=>{s.destroy()}}(e,r,s)),r.hasAttribute("data-umber-progress")&&u.push(function(e,t,r){let a=e.progress(t,{css:o(t,"data-umber-progress")??"--progress",start:o(t,"data-umber-progress-start"),end:o(t,"data-umber-progress-end"),axis:r}),n=t.getAttribute("data-umber-progress-event");return n&&a.on("change",()=>{dispatchEvent(new CustomEvent(n,{detail:{target:t,progress:a.value}}))}),()=>{a.destroy()}}(e,r,s)),r.matches(P)&&u.push(function(e,t){let r=o(t,"data-umber-pin"),a=void 0===r?null:c(t);void 0!==r&&a?.set("top",r);let n=t.parentElement,l=n?e.progress(n,{css:"--umber-pin",start:`top ${r??"top"}`,end:"bottom bottom"}):null;return()=>{l?.destroy(),a?.remove()}}(e,r)),r.matches(z)&&u.push(function(e,r){let n=r.firstElementChild;if(!n)return function(e,...t){l.has(e)||(l.add(e),a.warn("[umber]",e,...t))}('data-umber="horizontal": the section needs a track (its first child)',r),t;let o=c(r),s=()=>{let e=Math.max(0,n.scrollWidth-r.clientWidth);o.set("--umber-horizontal-px",`${e}px`),o.set("height",`calc(${e}px + 100vh)`)};s();let i=typeof ResizeObserver>"u"?null:new ResizeObserver(s);i?.observe(n),i?.observe(r),addEventListener("resize",s);let u=e.progress(r,{css:"--umber-horizontal",start:"top top",end:"bottom bottom"});return()=>{i?.disconnect(),removeEventListener("resize",s),u.destroy(),o.remove()}}(e,r));let d=r.hasAttribute("data-umber-velocity")?n(r,"data-umber-velocity")||(i.velocitySmooth??.12):0;return{offs:u,mover:d||r.hasAttribute("data-umber-speed")||r.hasAttribute("data-umber-lag")?g(e,r,d):null}}function C(e){"loading"!==document.readyState?e():addEventListener("DOMContentLoaded",e,{once:!0})}function N(e,t){e.delete(t),t.t.destroy(),t.rule.remove()}function L(e,t={}){let a=new WeakSet,n=new Map,o=new Set,l=r("(prefers-reduced-motion: reduce)"),d=r("(pointer: coarse)"),c=!1,m=function(e,t){let r={open:!e.licensed};return r.open&&C(t),e.licensed?.().then(e=>{r.open=e,e&&C(t)}),r}(e,()=>{b()}),p={s:0,screen:1,x:!1,dt:0,moves:t=>!l?.matches&&(t.touch||!d?.matches||!!e.scroll?.options.touch),fullSpeed:t.fullSpeed??3600},h=()=>e.scroll?.isHorizontal?"x":"y";function f(r){if(a.has(r))return;a.add(r);let l=k(e,r,h(),t);l.offs.length&&n.set(r,l.offs),l.mover&&o.add(l.mover)}function b(e=document){if(!c&&m.open){for(let[e,t]of n)e.isConnected||(n.delete(e),$(t));e instanceof Element&&e.matches(E)&&f(e),e.querySelectorAll(E).forEach(f)}}let v=function(e,t){let r,a,n="object"==typeof t?t:{},o=!1===t,l=!1,s=(e,t,r)=>{!function(e,t,r,a){let n=r[a];if(void 0===n)return;let o={index:a,value:n};e.scrollTo(n,{lerp:t.lerp,duration:t.duration,easing:t.easing,userData:{initiator:"snap"},onStart:()=>{t.onSnapStart?.(o)},onComplete:()=>{t.onSnapComplete?.(o)}})}(e,n,t,r)},i=NaN,u=()=>{r=void 0;let t=e.scroll;if(o||l||!t||t.isStopped||t.isLocked||!(Math.abs(t.targetScroll-i)>=1))return;let a=S(t);if(!a.length)return;let u=t.targetScroll,d=function(e,t){let r=0;return e.forEach((a,n)=>{Math.abs(a-t)<Math.abs((e[r]??0)-t)&&(r=n)}),r}(a,u),c=function(e,t){return"number"==typeof e?e:parseFloat(e)*(e.endsWith("%")?t/100:1)}(n.distance??"50%",t.isHorizontal?innerWidth:innerHeight);("mandatory"===(n.type??document.body?.getAttribute("data-umber-snap-type"))||Math.abs((a[d]??0)-u)<=c)&&s(t,a,d)},d=({event:t})=>{"touchstart"===t.type||"touchmove"===t.type?l=!0:("touchend"===t.type||"touchcancel"===t.type)&&(l=!1),void 0===r&&(i=e.scroll?.targetScroll??NaN),clearTimeout(r),r=setTimeout(u,n.debounce??150)},c=()=>{a??=e.scroll?.on("virtual-scroll",d)};c();let m=t=>{let r=e.scroll;if(!r)return;let a=S(r);s(r,a,function(e,t,r){let a=-1;for(let r=0;r<e.length&&(e[r]??0)<=t;r++)a=r;let n=e[a]===t;return Math.max(0,Math.min(e.length-1,n||r>0?a+r:a))}(a,Math.round(r.targetScroll),t))};return{api:{next:()=>{m(1)},previous:()=>{m(-1)},goTo(t){let r=e.scroll;r&&s(r,S(r),t)},stop(){o=!0},start(){o=!1}},attach:c,destroy(){clearTimeout(r),a?.()}}}(e,t.snap??!0);!u&&(u=s(i),1)&&e.invalidate();let g=[e.on("frame",function(t){if(!m.open)return;v.attach(),function(e,t,r){e.s=r?t.scroll.x:t.scroll.y,e.screen=(r?innerWidth:innerHeight)||1,e.x=r,e.dt=t.dt}(p,t,"x"===h());let r=!1;for(let t of o)t.el.isConnected?y(e,t,p)&&(r=!0):N(o,t);r&&e.wake()},{phase:"measure",order:-950,always:!1}),e.on("added",e=>{m.open&&(v.attach(),e.forEach(b))}),e.on("destroy",()=>{x.destroy()})],x={scan:b,snap:v.api,destroy(){if(!c){c=!0,$(g),v.destroy();for(let e of o)N(o,e);for(let e of n.values())$(e);n.clear(),function(){var e;(e=u)&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(t=>t!==e)),u=null}(),e.scrollFx===x&&(e.scrollFx=void 0)}}};return e.scrollFx=x,x}!function(t){let r,a=e();a.Umber?.use?a.Umber.use(t,r):(a.UmberModules??=[],a.UmberModules.push(r?[t,r]:t),a.__umber?.engine?.use?.(t,r))}({name:"scrollfx",version:"0.3.0",attributes:[],install:(M=({engine:e,options:t})=>{L(e,t)},(...e)=>{let[t,r,n,o,l]=e;(function(e){e&&(a=e)})(l),M({engine:t,options:r,keep:n,root:o})})})})();
@@ -0,0 +1,2 @@
1
+ /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=()=>{};function t(e){return globalThis.matchMedia?globalThis.matchMedia(e):null}var a={warn:e,error:e},r=(e,t)=>parseFloat(e.getAttribute(t)??""),n=(e,t)=>{let a=e.getAttribute(t);return null===a||""===a?void 0:a},o=new Set;function l(e=""){let t=new CSSStyleSheet;return t.replaceSync(e),document.adoptedStyleSheets=[...document.adoptedStyleSheets,t],t}var s="[data-umber~=pin],[data-umber-pin]{position:sticky;top:0}[data-umber~=horizontal]{position:relative;overflow-x:clip}[data-umber~=horizontal]>:first-child{position:sticky;top:0;width:max-content;translate:calc(var(--umber-horizontal,0)*var(--umber-horizontal-px,0px)*-1) 0}",i=null,u=0;function d(e){let t=e.getAttribute("data-umber-fx")??String(++u);e.setAttribute("data-umber-fx",t);let a=new Map,r=null;return{set(e,n){a.get(e)!==n&&(a.set(e,n),(r??=((e,t)=>e.cssRules[e.insertRule(`${t}{}`,e.cssRules.length)])(i??=l(s),`[data-umber-fx="${t}"]`)).style.setProperty(e,n))},remove(){a.clear(),function(e){let t=e?.parentStyleSheet;if(!t)return;let a=[...t.cssRules].indexOf(e);a>=0&&t.deleteRule(a)}(r),r=null}}}function c(e,t,a){return{target:e,way:t?"enter":"leave",from:a<.5?"start":"end"}}function m(e,t,a,r){let n=1-Math.min(1,Math.max(0,a));return e+(t-e)*(1-Math.pow(n,60*Math.max(0,r)))}var p=(e,t=0,a=1)=>Math.min(a,Math.max(t,e)),h=`:is(${["image","video","text","shader","layer","model","group"].map(e=>`[data-umber~=${e}]`).join()})`;function f(e,t,a,r){return e<r?-p(a/Math.max(1,e+t))*r:b(e,t,a,r)}function b(e,t,a,r){return-(2*p((a-e+r)/Math.max(1,r+t))-1)*r}function v(e,t,a){let n=r(t,"data-umber-speed")||0,o=p(r(t,"data-umber-lag")||0),l=[...t.matches(h)?[t]:[],...t.querySelectorAll(h)];return e.wake(),{el:t,t:e.track(t),rule:d(t),speed:n,lag:o,smooth:a,touch:t.hasAttribute("data-umber-speed-touch"),fold:!t.hasAttribute("data-umber-speed-ignore-fold"),measured:NaN,base:0,written:0,trail:NaN,drawn:NaN,speedPx:0,velocity:{value:0},lagPx:{value:0},planes:l,planeEls:l}}function g(e,t,a){let r=t.t.rect,n=(a.x?r.x:r.y)+a.s;n!==t.measured&&(t.measured=n,t.base=n-t.written);let o=function(e,t,a){let{s:r,screen:n}=t;if(e.trail=Math.abs(r-e.trail)<n?m(e.trail,r,e.lag,t.dt):r,e.lagPx.value=e.lag?r-e.trail:0,!t.moves(e))return 0;let o=(e.speed?(e.fold?f:b)(e.base,a,r,n)*e.speed:0)+e.lagPx.value;return Math.round(100*o)/100}(t,a,a.x?r.width:r.height);o!==t.written&&(t.written=o,t.rule.set("translate",a.x?`${o}px 0`:`0 ${o}px`)),function(e,t,a,r){let n=null;a&&(n=r?[a,0]:[0,a]);for(let a of t.planeEls){let t=e.plane(a);t&&(t.offset=n)}}(e,t,o,a.x),t.lag&&t.rule.set("--umber-lag",`${t.lagPx.value.toFixed(2)}px`);let l=Math.abs(t.lagPx.value)>.05,s=!!t.smooth&&function(e,t){let a=e.base-t.s+e.written,r=e.drawn-a;e.drawn=a;let n=Math.abs(r)<t.screen&&t.dt>0?r/t.dt:0;return e.speedPx=m(e.speedPx,n,e.smooth,t.dt),!n&&Math.abs(e.speedPx)<1&&(e.speedPx=0),e.velocity.value=p(e.speedPx/t.fullSpeed,-1,1),e.rule.set("--umber-velocity",e.velocity.value.toFixed(4)),0!==e.speedPx}(t,a);return t.planes.length&&function(e,t){t.planes=t.planes.filter(a=>{let r=e.plane(a);return!r||("uPlaneVelocity"in r.uniforms&&r.set("uPlaneVelocity",t.velocity),"uPlaneLag"in r.uniforms&&r.set("uPlaneLag",t.lagPx),!1)})}(e,t),l||s}function x(e,t,a){return"center"===e?t/2-a/2:"end"===e?t-a:0}function y(e){let t=e.isHorizontal,a=t?innerWidth:innerHeight,r=[];for(let n of document.querySelectorAll("[data-umber-snap]")){let o=n.getBoundingClientRect(),l=(t?o.left:o.top)+e.actualScroll,s=t?o.width:o.height;for(let t of(n.getAttribute("data-umber-snap")??"").split(/[\s,]+/)){let n=l+x(t,s,a);r.push(Math.round(Math.max(0,Math.min(e.limit,n))))}}return r.sort((e,t)=>e-t)}new Set(["data-umber","data-umber-effect","data-umber-shader","data-umber-layer","data-umber-instances"]);var S="[data-umber~=inview],[data-umber-inview]",w="[data-umber~=pin],[data-umber-pin]",M="[data-umber~=horizontal]",A=`${S},${w},${M},[data-umber-call],[data-umber-progress],[data-umber-speed],[data-umber-lag],[data-umber-velocity]`,P=e=>{for(let t of e)t()};function z(t,l,s,i){let u=[];(l.matches(S)||l.hasAttribute("data-umber-call"))&&u.push(function(e,t,a){let r=t.matches("[data-umber~=inview],[data-umber-inview]")?n(t,"data-umber-inview")??"is-inview":"",o=t.hasAttribute("data-umber-inview-repeat"),l=t.getAttribute("data-umber-call"),s=e.progress(t,{start:n(t,"data-umber-inview-start"),end:n(t,"data-umber-inview-end"),axis:a}),i=!1,u=0;return s.on("change",()=>{let e=s.value,a=e>0&&e<1,n=a?u:e;u=e,a!==i&&(a||o)&&(i=a,r&&t.classList.toggle(r,a),l&&dispatchEvent(new CustomEvent(l,{detail:c(t,a,n)})),a&&!o&&queueMicrotask(()=>{s.destroy()}))}),()=>{s.destroy()}}(t,l,s)),l.hasAttribute("data-umber-progress")&&u.push(function(e,t,a){let r=e.progress(t,{css:n(t,"data-umber-progress")??"--progress",start:n(t,"data-umber-progress-start"),end:n(t,"data-umber-progress-end"),axis:a}),o=t.getAttribute("data-umber-progress-event");return o&&r.on("change",()=>{dispatchEvent(new CustomEvent(o,{detail:{target:t,progress:r.value}}))}),()=>{r.destroy()}}(t,l,s)),l.matches(w)&&u.push(function(e,t){let a=n(t,"data-umber-pin"),r=void 0===a?null:d(t);void 0!==a&&r?.set("top",a);let o=t.parentElement,l=o?e.progress(o,{css:"--umber-pin",start:`top ${a??"top"}`,end:"bottom bottom"}):null;return()=>{l?.destroy(),r?.remove()}}(t,l)),l.matches(M)&&u.push(function(t,r){let n=r.firstElementChild;if(!n)return function(e,...t){o.has(e)||(o.add(e),a.warn("[umber]",e,...t))}('data-umber="horizontal": the section needs a track (its first child)',r),e;let l=d(r),s=()=>{let e=Math.max(0,n.scrollWidth-r.clientWidth);l.set("--umber-horizontal-px",`${e}px`),l.set("height",`calc(${e}px + 100vh)`)};s();let i=typeof ResizeObserver>"u"?null:new ResizeObserver(s);i?.observe(n),i?.observe(r),addEventListener("resize",s);let u=t.progress(r,{css:"--umber-horizontal",start:"top top",end:"bottom bottom"});return()=>{i?.disconnect(),removeEventListener("resize",s),u.destroy(),l.remove()}}(t,l));let m=l.hasAttribute("data-umber-velocity")?r(l,"data-umber-velocity")||(i.velocitySmooth??.12):0;return{offs:u,mover:m||l.hasAttribute("data-umber-speed")||l.hasAttribute("data-umber-lag")?v(t,l,m):null}}function E(e){"loading"!==document.readyState?e():addEventListener("DOMContentLoaded",e,{once:!0})}function $(e,t){e.delete(t),t.t.destroy(),t.rule.remove()}function k(e,a={}){let r=new WeakSet,n=new Map,o=new Set,u=t("(prefers-reduced-motion: reduce)"),d=t("(pointer: coarse)"),c=!1,m=function(e,t){let a={open:!e.licensed};return a.open&&E(t),e.licensed?.().then(e=>{a.open=e,e&&E(t)}),a}(e,()=>{b()}),p={s:0,screen:1,x:!1,dt:0,moves:t=>!u?.matches&&(t.touch||!d?.matches||!!e.scroll?.options.touch),fullSpeed:a.fullSpeed??3600},h=()=>e.scroll?.isHorizontal?"x":"y";function f(t){if(r.has(t))return;r.add(t);let l=z(e,t,h(),a);l.offs.length&&n.set(t,l.offs),l.mover&&o.add(l.mover)}function b(e=document){if(!c&&m.open){for(let[e,t]of n)e.isConnected||(n.delete(e),P(t));e instanceof Element&&e.matches(A)&&f(e),e.querySelectorAll(A).forEach(f)}}let v=function(e,t){let a,r,n="object"==typeof t?t:{},o=!1===t,l=!1,s=(e,t,a)=>{!function(e,t,a,r){let n=a[r];if(void 0===n)return;let o={index:r,value:n};e.scrollTo(n,{lerp:t.lerp,duration:t.duration,easing:t.easing,userData:{initiator:"snap"},onStart:()=>{t.onSnapStart?.(o)},onComplete:()=>{t.onSnapComplete?.(o)}})}(e,n,t,a)},i=NaN,u=()=>{a=void 0;let t=e.scroll;if(o||l||!t||t.isStopped||t.isLocked||!(Math.abs(t.targetScroll-i)>=1))return;let r=y(t);if(!r.length)return;let u=t.targetScroll,d=function(e,t){let a=0;return e.forEach((r,n)=>{Math.abs(r-t)<Math.abs((e[a]??0)-t)&&(a=n)}),a}(r,u),c=function(e,t){return"number"==typeof e?e:parseFloat(e)*(e.endsWith("%")?t/100:1)}(n.distance??"50%",t.isHorizontal?innerWidth:innerHeight);("mandatory"===(n.type??document.body?.getAttribute("data-umber-snap-type"))||Math.abs((r[d]??0)-u)<=c)&&s(t,r,d)},d=({event:t})=>{"touchstart"===t.type||"touchmove"===t.type?l=!0:("touchend"===t.type||"touchcancel"===t.type)&&(l=!1),void 0===a&&(i=e.scroll?.targetScroll??NaN),clearTimeout(a),a=setTimeout(u,n.debounce??150)},c=()=>{r??=e.scroll?.on("virtual-scroll",d)};c();let m=t=>{let a=e.scroll;if(!a)return;let r=y(a);s(a,r,function(e,t,a){let r=-1;for(let a=0;a<e.length&&(e[a]??0)<=t;a++)r=a;let n=e[r]===t;return Math.max(0,Math.min(e.length-1,n||a>0?r+a:r))}(r,Math.round(a.targetScroll),t))};return{api:{next:()=>{m(1)},previous:()=>{m(-1)},goTo(t){let a=e.scroll;a&&s(a,y(a),t)},stop(){o=!0},start(){o=!1}},attach:c,destroy(){clearTimeout(a),r?.()}}}(e,a.snap??!0);!i&&(i=l(s),1)&&e.invalidate();let x=[e.on("frame",function(t){if(!m.open)return;v.attach(),function(e,t,a){e.s=a?t.scroll.x:t.scroll.y,e.screen=(a?innerWidth:innerHeight)||1,e.x=a,e.dt=t.dt}(p,t,"x"===h());let a=!1;for(let t of o)t.el.isConnected?g(e,t,p)&&(a=!0):$(o,t);a&&e.wake()},{phase:"measure",order:-950,always:!1}),e.on("added",e=>{m.open&&(v.attach(),e.forEach(b))}),e.on("destroy",()=>{S.destroy()})],S={scan:b,snap:v.api,destroy(){if(!c){c=!0,P(x),v.destroy();for(let e of o)$(o,e);for(let e of n.values())P(e);n.clear(),function(){var e;(e=i)&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(t=>t!==e)),i=null}(),e.scrollFx===S&&(e.scrollFx=void 0)}}};return e.scrollFx=S,S}var C,N={name:"scrollfx",version:"0.3.0",attributes:[],install:(C=({engine:e,options:t})=>{k(e,t)},(...e)=>{let[t,r,n,o,l]=e;(function(e){e&&(a=e)})(l),C({engine:t,options:r,keep:n,root:o})})},F=N;export{N as ScrollFx,b as across,F as default,f as parallax,k as scrollFx};