@occluze/umber 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -2
- package/dist/chunks/capture.js +2 -0
- package/dist/chunks/covers.js +2 -0
- package/dist/chunks/flip.js +2 -0
- package/dist/chunks/fx.js +102 -0
- package/dist/chunks/gl.js +180 -0
- package/dist/chunks/glsl.js +239 -0
- package/dist/chunks/inspect.js +6 -0
- package/dist/chunks/instances.js +93 -0
- package/dist/chunks/layers.js +21 -0
- package/dist/chunks/licence.js +2 -0
- package/dist/chunks/morph.js +2 -0
- package/dist/chunks/restore.js +2 -0
- package/dist/chunks/shapes.js +2 -0
- package/dist/chunks/sim.js +22 -0
- package/dist/chunks/text.js +52 -0
- package/dist/chunks/video.js +2 -0
- package/dist/chunks/views.js +2 -0
- package/dist/chunks/warm.js +2 -0
- package/dist/modules/debug.js +36 -0
- package/dist/modules/debug.mjs +36 -0
- package/dist/modules/handoff.js +2 -0
- package/dist/modules/handoff.mjs +2 -0
- package/dist/modules/input.js +2 -0
- package/dist/modules/input.mjs +2 -0
- package/dist/modules/router-swap.js +13 -0
- package/dist/modules/router.js +2 -0
- package/dist/modules/router.mjs +2 -0
- package/dist/modules/scroll.js +2 -0
- package/dist/modules/scroll.mjs +2 -0
- package/dist/modules/scrub.js +8 -0
- package/dist/modules/scrub.mjs +8 -0
- package/dist/umber.css +2 -0
- package/dist/umber.js +2 -0
- package/dist/umber.mjs +2 -0
- package/docs/npm.md +69 -0
- package/package.json +118 -4
- package/types/debug.d.ts +27 -0
- package/types/esm.d.ts +33 -0
- package/types/handoff.d.ts +116 -0
- package/types/input.d.ts +235 -0
- package/types/router.d.ts +181 -0
- package/types/scroll.d.ts +132 -0
- package/types/scrub.d.ts +74 -0
- package/types/umber.d.ts +1532 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
function A(e=document.title){let t=document.querySelector("[data-gl-announcer]");t||(t=document.createElement("div"),t.setAttribute("data-gl-announcer",""),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),document.body.appendChild(t)),t.textContent="";let r=t;setTimeout(()=>r.textContent=e,60)}function k(e){let t=(typeof e=="string"?document.querySelector(e):e)||document.querySelector("h1")||document.querySelector("main");return t instanceof HTMLElement?(t.matches("a[href],button,input,select,textarea,[tabindex]")||t.setAttribute("tabindex","-1"),t.focus({preventScroll:!0}),document.activeElement===t):!1}var y="umber:handoff";function h(e,t=typeof location<"u"?location.href:void 0){try{let r=new URL(e,t);return r.hash="",r.href}catch{return""}}function P(e,t,r,n=()=>""){let o=[],a=new Set;for(let u of e){let d=u.el.getAttribute("data-gl-id"),[l,s,m,i]=Array.from(u.rect);if(!d||a.has(d)||u.kind!=="image"||u.status!=="ready"||!(m>0&&i>0&&l<t&&l+m>0&&s<r&&s+i>0))continue;let c=Y(u.el);c&&(a.add(d),o.push({id:d,src:c,rect:[l,s,m,i],radius:n(u.el)}))}return o}function Y(e){let t=e.getAttribute("data-gl-src"),r=e.matches("img")?e:e.querySelector("img"),n=t||r?.currentSrc||r?.getAttribute("src")||"";return n?h(n,e.ownerDocument?.baseURI):""}function R(e,t){try{return e.setItem(y,JSON.stringify(t)),!0}catch{return!1}}function M(e,t){let r=null;try{r=e.getItem(y),r!==null&&e.removeItem(y)}catch{return null}let n=null;try{n=r?JSON.parse(r):null}catch{return null}return _(n,t)?n:null}function _(e,t){let r=e;if(!r||typeof r!="object"||r.v!==1||!Array.isArray(r.items)||t.reload)return!1;let n=t.now-r.at;return!(n>=0&&n<=(t.maxAge??3e3))||!r.to||r.to!==h(t.url,t.url)?!1:(Math.abs(r.vw-t.vw)>1&&(r.items=[]),r.items=r.items.filter(o=>o&&typeof o.id=="string"&&typeof o.src=="string"&&Array.isArray(o.rect)&&o.rect.length===4),!0)}var O=e=>`[data-gl-id="${e.replace(/["\\]/g,"\\$&")}"]`,N=(e,t,r,n)=>[r?e/r:.5,n?t/n:.5];function E(e,t){if(e&&e.navigationType){if(e.navigationType!=="traverse")return 1;let r=e.from?.index,n=e.entry?.index;return typeof r=="number"&&typeof n=="number"&&n>r?1:-1}return t==="back_forward"?-1:1}var q={maxAge:3e3,vt:!0,cover:null,coverDuration:.8,coverEase:"umber",focus:"h1",announce:!1},D=new Set;function H(e,...t){D.has(e)||(D.add(e),console.warn("[umber]",e,...t))}function g(e,t,r,n,o){t&&(t.addEventListener(r,n,o),e.offs.push(()=>t.removeEventListener(r,n,o)))}var T=()=>typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches,S=e=>e.canvas?.parentElement||document.querySelector("[data-gl-host]");var F=1500,j=.8;function J(e,t=document){let r=[];for(let n of e){let o=t.querySelector(`${O(n.id)}[data-gl]`);if(!o||o.getAttribute("data-gl")!=="image")continue;let a=o.getBoundingClientRect();a.width>0&&a.height>0&&a.top<innerHeight&&a.bottom>0&&a.left<innerWidth&&a.right>0&&r.push({item:n,target:o})}return r}function X(e){let t=[],r=[];for(let n of e){let o=document.querySelector(`${O(n.id)}[data-gl=image]`),a=o instanceof HTMLImageElement?o:o?.querySelector("img");a&&!a.complete&&!o.getBoundingClientRect().height&&(o.setAttribute("data-gl-waiting","image"),o.removeAttribute("data-gl"),t.push(o),r.push(a.decode().catch(()=>{})))}return[t,Promise.race([Promise.all(r),new Promise(n=>setTimeout(n,1e3))])]}function Q(e){let t=document.createElement("div"),[r,n,o,a]=e.rect;t.setAttribute("data-gl","image"),t.setAttribute("data-gl-id",e.id),t.setAttribute("data-gl-ghost",""),t.setAttribute("aria-hidden","true"),t.style.cssText=`left:${r}px;top:${n}px;width:${o}px;height:${a}px;border-radius:${e.radius||0}`;let u=document.createElement("img");return u.alt="",u.decoding="sync",u.src=e.src,t.appendChild(u),t}function $(e){return J(e).map(({item:t,target:r})=>{let n=r.getAttribute("data-gl")||"image";r.setAttribute("data-gl-waiting",n),r.removeAttribute("data-gl");let o=Q(t);return document.body.appendChild(o),{item:t,target:r,ghost:o,kind:n}})}function w(e,t=!1){e.ghost.remove(),e.target.hasAttribute("data-gl")||e.target.setAttribute("data-gl",e.kind),t||e.target.removeAttribute("data-gl-waiting")}function Z(e){return e?e.status==="ready"?Promise.resolve(!0):new Promise(t=>{let r=[e.on("ready",()=>o(!0)),e.on("error",()=>o(!1)),e.on("destroy",()=>o(!1))],n=setTimeout(()=>o(!1),F);function o(a){clearTimeout(n),r.forEach(u=>u()),t(a)}}):Promise.resolve(!1)}function ee(e){return new Promise(t=>{let r=0,n=()=>{performance.getEntriesByType?.("resource").some(a=>/chunks\/morph\.js/.test(a.name))||++r>30?e.nextFrame(()=>t()):e.nextFrame(n)};n()})}function te(e){let t=e.target.getBoundingClientRect(),r=getComputedStyle(e.target).borderRadius,n=e.ghost.animate?.([{},{left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`,borderRadius:r}],{duration:j*1e3,easing:"cubic-bezier(0.7, 0, 0.2, 1)",fill:"forwards"});if(!n)return void w(e);n.finished.then(()=>w(e),()=>w(e))}async function U(e){let t=e.arrived,{gl:r}=e;if(!t||!t.items.length||(document.documentElement.setAttribute("data-gl-handoff",""),T()))return b();e.direction<0&&document.readyState!=="complete"&&await new Promise(s=>{addEventListener("load",()=>s(),{once:!0}),setTimeout(s,1e3)});let[n,o]=X(t.items),a=$(t.items);if(b(),n.length&&(await o,n.forEach(s=>(s.setAttribute("data-gl","image"),s.removeAttribute("data-gl-waiting"))),a.push(...$(t.items))),!a.length)return;if(!await r.ready||r.destroyed){a.forEach(te);return}await new Promise(s=>{r.nextFrame(()=>s(),{phase:"render"}),setTimeout(s,F)});let u=await Promise.all(a.map(s=>Z(r.plane(s.ghost)))),d=a.filter((s,m)=>u[m]);if(a.filter((s,m)=>!u[m]).forEach(s=>w(s)),!d.length)return;if(await ee(r),r.destroyed)return void d.forEach(s=>w(s));let l=document.createElement("div");for(let s of d)l.appendChild(document.createElement("i")).setAttribute("data-gl-id",s.item.id);r.morph.capture(l);for(let s of d)w(s,!0);r.nextFrame(()=>r.nextFrame(()=>d.forEach(s=>s.target.removeAttribute("data-gl-waiting"))))}function b(){document.getElementById("umber-handoff")?.remove()}var ne=1500,x=new WeakMap;function L(e){x.get(e)?.el.remove(),x.delete(e)}function re(e){return e.status==="ready"?Promise.resolve(!0):new Promise(t=>{let r=[e.on("ready",()=>o(!0)),e.on("error",()=>o(!1))],n=setTimeout(()=>o(!1),ne);function o(a){clearTimeout(n),r.forEach(u=>u()),t(a)}})}async function C(e,t,r={}){let{gl:n,options:o}=e,a=r.phase==="cover"?"cover":"reveal";if(T())return void(a==="reveal"&&L(e));let u=a==="cover"?0:1,d=1-u,l=r.duration??o.coverDuration,s=x.get(e);if(!s||s.shader!==t||!s.el.isConnected){L(e);let f=document.createElement("div");f.setAttribute("data-gl-cover",""),f.setAttribute("aria-hidden","true"),f.setAttribute("inert",""),f.style.cssText="position:fixed;inset:0;pointer-events:none;z-index:2147483000",u||(f.style.opacity="0"),document.body.appendChild(f),x.set(e,s={el:f,shader:t})}let m=s.el,i=n.destroyed?null:await n.add(m,{type:"shader",shader:t,order:1e4}),c=r.origin??e.origin,p=(f,v)=>i&&f in i.uniforms&&i.set(f,v);i&&!("uCover"in i.uniforms)&&H(`handoff: the cover shader "${t}" reads no uCover, so it cannot cover or reveal. Declare it: gl.shader("${t}", { uniforms: { uCover: 0, uOrigin: [0.5, 0.5], uDirection: 1 }, ... }).`),p("uCover",u),p("uOrigin",c?[c[0]/innerWidth,c[1]/innerHeight]:[.5,.5]),p("uDirection",r.direction??e.direction),i&&"uCover"in i.uniforms&&await re(i)?(m.style.opacity="",await i.tween("uCover",{value:d,duration:l,ease:r.ease??o.coverEase})):await m.animate?.([{opacity:u},{opacity:d}],{duration:l*1e3,easing:"ease-in-out",fill:"forwards"}).finished.catch(()=>{}),a==="reveal"&&x.get(e)?.el===m&&L(e)}var V="::view-transition-group(umber-gl){animation:none}::view-transition-old(umber-gl),::view-transition-new(umber-gl){mix-blend-mode:normal}::view-transition-new(umber-gl){animation:none}",oe="[data-gl-waiting]:is(img,video),[data-gl-waiting] :is(img,video){opacity:0!important}[data-gl-ghost]{position:fixed;margin:0;padding:0;overflow:hidden;pointer-events:none;z-index:2}[data-gl-ghost] img{display:block;width:100%;height:100%;object-fit:cover}[data-gl-announcer]{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}"+V;function B(e=document){if(e.querySelector("style[data-gl-handoff-css]"))return;let t=e.createElement("style");t.setAttribute("data-gl-handoff-css",""),t.textContent=oe,(e.head||e.documentElement).appendChild(t)}var W=`<script>(function(w,d){try{var r=JSON.parse(sessionStorage.getItem("umber:handoff")),n=performance.getEntriesByType("navigation")[0],h=d.documentElement,s=d.createElement("style");s.id="umber-handoff";if(!r||!(Date.now()-r.at<3e3)||n&&n.type=="reload"||r.to!=location.href.split("#")[0])return;s.textContent=(r.items.length?r.items.map(function(i){var k='[data-gl-id="'+i.id.replace(/["\\\\]/g,"\\\\$&")+'"]';return k+':is(img,video),'+k+' :is(img,video)'}).join()+"{opacity:0!important}":"")+`+JSON.stringify(V)+';d.head.appendChild(s);setTimeout(function(){h.hasAttribute("data-gl-handoff")||s.remove()},1500);w.addEventListener("pagereveal",function(e){var v=w.__umberReveal=e.viewTransition||null,g=d.querySelector("[data-gl-host]");if(v&&r.over){if(!g){g=d.createElement("div");g.setAttribute("data-gl-host","");g.style.zIndex=1;(d.body||h).prepend(g)}g.style.viewTransitionName="umber-gl"}})}catch(e){}})(window,document)<\/script>';function z(e){let{gl:t,options:r}=e,n="",o=null,a=!1,u=null,d=!1,l=null;g(e,document,"click",i=>{let c=i.target?.closest?.("a[href]");if(!c||i.defaultPrevented||i.button>0||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||c.target&&c.target!=="_self"||c.hasAttribute("download")||c.origin!==location.origin)return;n=h(c.href),u=i,a=i.detail===0;let p=i.clientX,f=i.clientY;if(a){let v=c.getBoundingClientRect();p=v.left+v.width/2,f=v.top+v.height/2}e.origin=[p,f],e.direction=1,o=N(p,f,innerWidth,innerHeight)},{capture:!0}),g(e,globalThis,"click",i=>{i===u&&i.defaultPrevented&&(n="",o=null)});let s=globalThis.navigation;g(e,s,"navigate",i=>{i.navigationType==="traverse"&&(e.direction=i.destination?.index<s.currentEntry?.index?-1:1),!i.destination?.sameDocument&&i.destination?.url&&(n=h(i.destination.url))}),s||g(e,globalThis,"popstate",()=>e.direction=-1);let m=(i,c)=>{if(d||!i||i===h(location.href))return;let p=P(t.planes(),innerWidth,innerHeight,G=>getComputedStyle(G).borderRadius);if(!p.length&&!r.cover)return;let f=S(t),v=!!f&&!(Number(getComputedStyle(f).zIndex)<0),K={v:1,at:Date.now(),from:h(location.href),to:i,vw:innerWidth,vh:innerHeight,click:o,kb:a,over:v,items:p};d=R(sessionStorage,K),c&&r.vt&&f&&(v?(f.style.viewTransitionName="umber-gl",l=f):H('handoff: a View Transition lifts the canvas over the page only with layer "over"; this page draws GL under it, so it cross-fades with the page. gl.use(Handoff, { vt: false }) keeps it that way without this warning.'))};g(e,globalThis,"pageswap",i=>{let c=i.activation;c&&c.navigationType==="reload"||m(c?.entry?.url?h(c.entry.url):n,i.viewTransition)}),g(e,globalThis,"pagehide",()=>m(n,null)),g(e,globalThis,"pageshow",i=>{if(i.persisted){if(l&&(l.style.viewTransitionName=""),l=null,d)try{sessionStorage.removeItem(y)}catch{}d=!1,n="",o=null}})}var I=()=>performance.getEntriesByType?.("navigation")[0]?.type;function ie(e,t={}){let r=globalThis,n={gl:e,options:{...q,...t},arrived:null,origin:null,direction:E(r.navigation?.activation,I()),viewTransition:r.__umberReveal||null,offs:[]};B(),z(n);let o=d=>{if(n.viewTransition=d,!d)return;let l=S(e);if(!l&&n.options.vt&&n.arrived?.over&&(l=document.createElement("div"),l.setAttribute("data-gl-host",""),l.style.zIndex="1",document.body.prepend(l)),!l||!n.options.vt||!n.arrived?.over)return;l.style.viewTransitionName="umber-gl";let s=l;d.finished.finally(()=>s.style.viewTransitionName="")};g(n,globalThis,"pagereveal",d=>o(d.viewTransition||null));let a=()=>{n.direction=E(r.navigation?.activation,I()),n.arrived=M(sessionStorage,{url:location.href,now:Date.now(),reload:I()==="reload",vw:innerWidth,maxAge:n.options.maxAge}),n.viewTransition&&o(n.viewTransition);let d=n.arrived;if(!d)return b();d.click&&(n.origin=[d.click[0]*innerWidth,d.click[1]*innerHeight]);let l=n.options;l.announce&&A(),d.kb&&l.focus&&k(l.focus),l.cover&&C(n,l.cover,{phase:"reveal"}),U(n)};document.prerendering?g(n,document,"prerenderingchange",()=>queueMicrotask(a),{once:!0}):queueMicrotask(a);let u={get arrived(){return n.arrived},get origin(){return n.origin},get direction(){return n.direction},get viewTransition(){return n.viewTransition},options:n.options,cover:(d,l)=>C(n,d,l),announce:A,focus:k};return e.handoff=u,e.on("destroy",()=>{n.offs.splice(0).forEach(d=>d())}),u}var ae={name:"handoff",version:"0.2.0",attributes:[],install(e,t){ie(e,t)},headSnippet:W},Ae=ae;export{W as HEAD_SNIPPET,ae as Handoff,y as KEY,A as announce,C as cover,Ae as default,E as directionOf,k as focus,ie as handoff,P as itemsOf,h as pageUrl,M as read,_ as valid,R as write};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
"use strict";(()=>{function W(t,e,n,s){return t+(e-t)*(1-Math.pow(1-n,s*60))}function $(){let t=typeof document<"u"&&document.timeline?document.timeline.currentTime:null;return typeof t=="number"?t:performance.now()}var ae=new Set;function _(t,...e){ae.has(t)||(ae.add(t),console.warn("[umber]",t,...e))}var V=[];function K(){let t=new Map,e=(n,s)=>void t.get(n)?.delete(s);return{on(n,s){return t.has(n)||t.set(n,new Set),t.get(n).add(s),()=>e(n,s)},off:e,emit(n,s){let r=t.get(n),o=V.length;r?.forEach(i=>V.push(i));for(let i=o,u=V.length;i<u;i++)if(r.has(V[i]))try{V[i](s)}catch(d){console.error(`[umber] a "${n}" handler threw:`,d)}V.length=o},clear(){t.clear()}}}var se=6,Te=1,ie=new WeakMap;function ue(t,e,n={},s=document){let r=t.track(e),o=typeof e=="string"?e:null,i=r.el.isConnected?r.el:null,u=null,d=n.axis||"both",f=Math.min(.999,Math.max(0,n.inertia??.92)),c=Math.min(1,Math.max(0,n.rubber??.35)),a=[0,0],p={value:[0,0]},E=[0,0],m=K(),I=[0,0,0,0],T=[0,0],M=$(),v=!1,g=-1,w=0,R=null,L=!1,O=!1,C=!1,A=!1,U=[],S={value:a,velocity:p,direction:E,bounds:typeof n.bounds=="function"?null:n.bounds||null,get el(){return i},get pressed(){return v},get target(){return R},get destroyed(){return A},set(l,h=a[1]){a[0]=Number(l)||0,a[1]=Number(h)||0,p.value[0]=p.value[1]=0,C=!0,t.wake(2)},on:m.on,off:m.off,destroy:Y,revert:Y};if(!i&&!o)return _(`gl.drag(${JSON.stringify(String(e))}): no element found. Pass an element, or a selector that matches one.`),A=!0,S;i||_(`gl.drag(${JSON.stringify(o)}): nothing matches yet. It binds to the first match that enters the page.`);let B=l=>(l?S.bounds?.y:S.bounds?.x)||null,X=(l,h)=>{let y=B(h);return y?l<y[0]?y[0]-(y[0]-l)*c:l>y[1]?y[1]+(l-y[1])*c:l:l},z=(l,h)=>{let y=B(h);return y?l<y[0]?c?y[0]-(y[0]-l)/c:y[0]:l>y[1]?c?y[1]+(l-y[1])/c:y[1]:l:l},H=l=>{let h=l;v||h.button!==void 0&&h.button>0||(v=!0,g=h.pointerId,w=0,O=!1,L=!1,R=h.target,I[0]=h.clientX,I[1]=h.clientY,I[2]=z(a[0],0),I[3]=z(a[1],1),m.emit("press",S),t.wake(2))},F=l=>{let h=l;if(!v||h.pointerId!==g)return;if(h.pointerType==="mouse"&&!h.buttons)return q(l);let y=d==="y"?0:h.clientX-I[0],D=d==="x"?0:h.clientY-I[1];if(w=Math.max(w,Math.hypot(y,D)),w>=se&&!L){L=!0;try{i.setPointerCapture?.(g)}catch{}}a[0]=X(I[2]+y,0),a[1]=X(I[3]+D,1),C=!0,t.wake(2)};function q(l){if(!(!v||l.pointerId!==g)){if(v=!1,L)try{i.releasePointerCapture?.(g)}catch{}m.emit("release",S),w>=se?(O=!0,setTimeout(()=>O=!1)):l.type==="pointerup"&&m.emit("tap",S),t.wake(2)}}for(let l of["pointerup","pointercancel"])addEventListener(l,q),U.push(()=>removeEventListener(l,q));let Ee=l=>{O&&(O=!1,l.preventDefault(),l.stopPropagation())},ge=l=>l.preventDefault();function re(l,h){u?.(),i=l;let y=[],D=(b,N,P)=>{l.addEventListener(b,N,P),y.push(()=>l.removeEventListener(b,N,P))};D("pointerdown",H),D("pointermove",F),D("pointerup",q),D("pointercancel",q),D("click",Ee,{capture:!0}),D("dragstart",ge),typeof getComputedStyle=="function"&&(getComputedStyle(l).touchAction||"auto")==="auto"&&_(`gl.drag(): give the element touch-action: ${d==="x"?"pan-y":d==="y"?"pan-x":"none"} in its CSS. With "auto" a finger scrolls the page instead of dragging.`,l);let x=n.bounds;if(typeof x=="function"){let b=()=>void(S.bounds=x(l)||null);b(),y.push(h.on("resize",b))}u=()=>{if(u=null,y.forEach(b=>b()),v){if(L)try{l.releasePointerCapture?.(g)}catch{}v=L=!1,m.emit("release",S)}h.destroy()};let k=()=>{if(!o)return Y();u?.(),queueMicrotask(()=>{let b=s.querySelector(o);b&&oe(b)})};h.destroyed?k():y.push(h.on("destroy",k))}function oe(l){A||l===i&&u||!l.isConnected||(re(l,t.track(l)),a[0]=a[1]=T[0]=T[1]=0,p.value[0]=p.value[1]=0,C=!0,t.wake(2))}let xe=t.on("frame",l=>{let h=l.dt>0?l.dt:.016666666666666666,y=$(),D=y>M?(y-M)/1e3:h;M=y;let x=p.value,k=!1;for(let b=0;b<2;b++){if(v)x[b]=W(x[b],(a[b]-T[b])/D,.4,h);else{a[b]+=x[b]*h;let N=B(b),P=N?a[b]<N[0]?N[0]:a[b]>N[1]?N[1]:null:null;x[b]*=Math.pow(P===null?f:.5,h*60),P!==null&&(a[b]=Math.abs(P-a[b])<.01?P:W(a[b],P,.18,h),a[b]!==P&&(k=!0))}a[b]!==T[b]&&(E[b]=a[b]>T[b]?1:-1,C=!0)}Math.abs(x[0])+Math.abs(x[1])<Te&&(!v||a[0]===T[0]&&a[1]===T[1])&&(x[0]=x[1]=0),T[0]=a[0],T[1]=a[1],C&&m.emit("change",S),C=!1,(k||x[0]!==0||x[1]!==0)&&t.wake()},{always:!1,phase:"measure",order:-1100});if(U.push(xe),i&&re(i,r),o&&!A){let l=s===document?t:s,h=ie.get(l)||new Map;ie.set(l,h);let y=h.get(o);h.set(o,S),y&&queueMicrotask(()=>!A&&y.destroy()),U.push(()=>void(h.get(o)===S&&(y&&!y.destroyed?h.set(o,y):h.delete(o))),t.on("added",D=>{let x=null;if(!((D[0]===document.documentElement||document.readyState==="loading")&&u)){for(let k of D){try{x=[...k.matches(o)?[k]:[],...k.querySelectorAll(o)].find(b=>s.contains(b))||null}catch{return}if(x)break}x&&(x!==i||!u)&&queueMicrotask(()=>oe(x))}}),t.on("destroy",Y))}function Y(){A||(A=!0,u?.(),v=!1,U.forEach(l=>l()),U.length=0,m.clear())}return S}var J=(t,e)=>t.on("frame",e,{always:!1,phase:"update",order:-800});function ce(t,e,n={}){let s=n.smooth??.25,r=n.rest??.001,o=[0],i=()=>{let m=e.value;return typeof m!="number"?m:(o[0]=m,o)},u=typeof e.value=="number",d=Array.from(i()),f=d.map(()=>0),c=$(),a=!1,p={value:u?0:f,get destroyed(){return a},destroy(){a=!0,E()}},E=J(t,m=>{let I=m.dt>0?m.dt:.016666666666666666,T=$(),M=T>c?(T-c)/1e3:I;c=T;let v=i(),g=!1,w=!0;for(let R=0;R<f.length;R++){let L=Number(v[R])||0;L!==d[R]&&(g=!0),f[R]=W(f[R],(L-d[R])/M,s,I),d[R]=L,Math.abs(f[R])>=r&&(w=!1)}w&&!g&&f.fill(0),u&&(p.value=f[0]),(g||!w)&&t.wake()});return p}function de(t,e=16,n={}){let s=n.follow??.5,r=t.pointer.value,o=Array.from({length:Math.max(1,Math.floor(e)||1)},()=>({value:[r[0],r[1]]})),i=!1,u=J(t,d=>{let f=d.dt>0?d.dt:.016666666666666666,c=!1;for(let a=0;a<o.length;a++){let p=o[a].value,E=a?o[a-1].value:r;for(let m=0;m<2;m++)a===0||Math.abs(E[m]-p[m])<.01?p[m]=E[m]:(p[m]=W(p[m],E[m],s,f),c=!0)}c&&t.wake()});return{points:o,get destroyed(){return i},destroy(){i=!0,u()}}}var le=4,we=-1e4;function me(t,e=n=>n){let n=K(),s=Array.from({length:le},()=>({value:[0,0,we]})),r=[],o=0,i={value:s[0].value,recent:s,get count(){return o},on:(c,a)=>e(n.on(c,a)),off:n.off},u=c=>{let a=c;Number.isFinite(a.clientX)&&(r.push([a.clientX,a.clientY]),t.wake())},d=!1,f=J(t,c=>{for(let a=0;a<r.length;a++){for(let E=le-1;E>0;E--)for(let m=0;m<3;m++)s[E].value[m]=s[E-1].value[m];let p=s[0].value;p[0]=r[a][0],p[1]=r[a][1],p[2]=c.time,o++,n.emit("press",i)}r.length=0});return{signal:i,listen(){return d||addEventListener("pointerdown",u,{passive:!0}),d=!0,i},destroy(){f(),d=!0,removeEventListener("pointerdown",u),n.clear()}}}function fe(t,e,n){let s=t.pointer,r=Math.max(1,Number(e)||80),o=[s.value[0],s.value[1]],i=s.active,u=0,d=0,f=()=>i=!1,c=document.documentElement;addEventListener("pointerdown",f,{passive:!0}),c.addEventListener("pointerenter",f,{passive:!0});let a=()=>{E(),p(),removeEventListener("pointerdown",f),c.removeEventListener("pointerenter",f)},p=t.on("destroy",a),E=J(t,()=>{let m=s.value,I=m[0]-o[0],T=m[1]-o[1],M=Math.hypot(I,T),v=r-u;for(i&&(u+=M),i=s.active;u>=r;){u-=r;let g=M?v/M:1;v+=r;try{n([o[0]+I*g,o[1]+T*g],++d)}catch(w){console.error("[umber] a gl.step() callback threw:",w)}}o[0]=m[0],o[1]=m[1]});return a}var Re=t=>!!t&&typeof t=="object"&&ArrayBuffer.isView(t.data);function Ie(t){let e=t;return[e.videoWidth||e.naturalWidth||e.width||0,e.videoHeight||e.naturalHeight||e.height||0]}var pe=new WeakMap;function Q(t){let e=pe.get(t);if(!e){let n=new Set;e={all:n},pe.set(t,e),t.on("restored",()=>n.forEach(s=>s.lost())),t.on("destroy",()=>n.forEach(s=>s.destroy()))}return e}var ne=class{constructor(e,n,s){this.engine=e;this.source=n;this.options=s;this.width=0;this.height=0;this.destroyed=!1;this.tex=null;this.gl=null;this.dirty=!0;this.shape="";this.unwatch=null;Q(e).all.add(this),this.watch()}get texture(){let e=this.engine.context;return!e||this.destroyed?null:((this.gl!==e||!this.tex)&&(this.gl=e,this.tex=e.createTexture(),this.shape="",this.dirty=!0),this.dirty&&this.upload(e),this.tex)}update(e){this.destroyed||(e&&e!==this.source&&(this.source=e,this.watch()),this.dirty=!0,this.engine.wake())}lost(){this.tex=null}destroy(){this.destroyed||(this.destroyed=!0,this.unwatch?.(),Q(this.engine).all.delete(this),this.tex&&this.gl&&!this.gl.isContextLost()&&this.gl.deleteTexture(this.tex),this.tex=null)}watch(){this.unwatch?.(),this.unwatch=null;let e=this.source;if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement){if(e.complete&&e.naturalWidth)return;let r=()=>this.update();e.addEventListener("load",r,{once:!0}),this.unwatch=()=>e.removeEventListener("load",r);return}if(typeof HTMLVideoElement>"u"||!(e instanceof HTMLVideoElement))return;let n=!0,s=()=>this.update();if(typeof e.requestVideoFrameCallback=="function"){let r=0,o=()=>{n&&(s(),r=e.requestVideoFrameCallback(o))};r=e.requestVideoFrameCallback(o),this.unwatch=()=>{n=!1,e.cancelVideoFrameCallback(r)}}else{for(let r of["timeupdate","seeked","loadeddata"])e.addEventListener(r,s);this.unwatch=()=>{for(let r of["timeupdate","seeked","loadeddata"])e.removeEventListener(r,s)}}}upload(e){let n=this.source,[s,r]=Ie(n);if(!s||!r||n instanceof HTMLVideoElement&&n.readyState<2)return;this.dirty=!1;let o=e.getParameter(e.TEXTURE_BINDING_2D);e.bindTexture(e.TEXTURE_2D,this.tex),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.BROWSER_DEFAULT_WEBGL);let i=!1;if(Re(n)){i=n.data instanceof Float32Array;let f=n.data.length/(s*r),c=f===1?e.RED:f===2?e.RG:f===4?e.RGBA:0;if(!c){_(`gl.texture(): data has ${n.data.length} numbers for ${s} x ${r} texels; give 1, 2 or 4 per texel (R, RG or RGBA).`),e.bindTexture(e.TEXTURE_2D,o);return}let a=i?f===1?e.R32F:f===2?e.RG32F:e.RGBA32F:f===1?e.R8:f===2?e.RG8:e.RGBA8,p=i?e.FLOAT:e.UNSIGNED_BYTE,E=n.data instanceof Uint8ClampedArray?new Uint8Array(n.data.buffer,n.data.byteOffset,n.data.length):n.data,m=`${s} ${r} ${a}`;e.pixelStorei(e.UNPACK_ALIGNMENT,1),m===this.shape?e.texSubImage2D(e.TEXTURE_2D,0,0,0,s,r,c,p,E):e.texImage2D(e.TEXTURE_2D,0,a,s,r,0,c,p,E),e.pixelStorei(e.UNPACK_ALIGNMENT,4),this.shape=m}else{let f=`${s} ${r}`;f===this.shape?e.texSubImage2D(e.TEXTURE_2D,0,0,0,e.RGBA,e.UNSIGNED_BYTE,n):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n),this.shape=f}let u=i||this.options.filter==="nearest"?e.NEAREST:e.LINEAR,d=this.options.wrap==="repeat"?e.REPEAT:e.CLAMP_TO_EDGE;e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,d),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,d),e.bindTexture(e.TEXTURE_2D,o),this.width=s,this.height=r}};function Z(t,e,n={}){if(!e||typeof e!="object")throw new TypeError("[umber] gl.texture(source) needs a canvas, ImageBitmap, video, image, ImageData or { data, width, height }.");if(ArrayBuffer.isView(e))throw new TypeError("[umber] gl.texture(numbers) needs their size: gl.texture({ data, width, height }), 1, 2 or 4 numbers per texel.");return new ne(t,e,n)}var j=16;function ye(t,e={}){let n=Math.max(8,Math.round(e.size??64)),s=Math.min(.999,Math.max(0,e.fade??.92)),r=(M,v)=>{if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(M,v);let g=document.createElement("canvas");return g.width=M,g.height=v,g},o=()=>Math.max(1,Math.round(n*(innerHeight||1)/(innerWidth||1))),i=r(n,o()),u=i.getContext("2d"),d=Math.max(1,(e.radius??.08)*n),f=Array.from({length:j},(M,v)=>{let g=r(Math.ceil(d*2),Math.ceil(d*2)),w=g.getContext("2d");if(w){let R=v/j*Math.PI*2,L=`${Math.round((Math.cos(R)*.5+.5)*255)}, ${Math.round((Math.sin(R)*.5+.5)*255)}, 255`,O=w.createRadialGradient(d,d,0,d,d,d);O.addColorStop(0,`rgba(${L}, 1)`),O.addColorStop(1,`rgba(${L}, 0)`),w.fillStyle=O,w.fillRect(0,0,d*2,d*2)}return g}),c=Z(t,i);if(Object.defineProperty(c,"canvas",{value:i}),!u)return _("gl.touch(): this browser gives no 2D canvas; the touch texture stays empty."),c;let a=t.pointer,p=[a.value[0],a.value[1]],E=a.active,m=0,I=t.on("frame",M=>{if(c.destroyed)return I();let v=a.value,g=E&&(v[0]!==p[0]||v[1]!==p[1]);if(!g&&m===0){E=a.active,p[0]=v[0],p[1]=v[1];return}let w=Math.min(.25,M.dt>0?M.dt:1/60),R=o();i.height!==R&&(i.height=R);let L=Math.pow(s,w*60);if(m>0&&(u.globalCompositeOperation="destination-out",u.globalAlpha=1-L,u.fillRect(0,0,i.width,i.height),m*=L),g){let O=i.width/(innerWidth||1),C=i.height/(innerHeight||1),A=p[0]*O,U=p[1]*C,S=v[0]*O-A,B=v[1]*C-U,X=Math.hypot(S,B),z=f[(Math.round(Math.atan2(B,S)/(Math.PI*2)*j)+j)%j];u.globalCompositeOperation="source-over",u.globalAlpha=Math.min(1,.35+X/d);let H=Math.max(1,Math.ceil(X/(d*.5)));for(let F=1;F<=H;F++)u.drawImage(z,A+S*F/H-d,U+B*F/H-d);m=1}m<1/255&&(m=0,u.clearRect(0,0,i.width,i.height)),E=a.active,p[0]=v[0],p[1]=v[1],c.update()},{always:!1,phase:"update",order:-800}),T=c.destroy.bind(c);return c.destroy=()=>{I(),T()},c}function be(t,e){let n=Array.from(typeof e=="string"?document.querySelectorAll(e):e);n.length||_(`gl.rects(${typeof e=="string"?`"${e}"`:"[]"}): no elements; the texture holds one empty rect.`);let s=n.map(f=>t.track(f)),r=new Float32Array(Math.max(1,n.length)*4),o=()=>{let f=!1;for(let c=0;c<s.length;c++){let a=s[c].rect,p=c*4,E=Math.fround;(r[p]!==E(a.x)||r[p+1]!==E(a.y)||r[p+2]!==E(a.width)||r[p+3]!==E(a.height))&&(r[p]=a.x,r[p+1]=a.y,r[p+2]=a.width,r[p+3]=a.height,f=!0)}return f};o();let i=Z(t,{data:r,width:Math.max(1,n.length),height:1});Object.defineProperties(i,{count:{value:n.length},rects:{value:r}});let u=t.on("frame",()=>i.destroyed?u():o()&&i.update(),{always:!1,phase:"update",order:-800}),d=i.destroy.bind(i);return i.destroy=()=>{u();for(let f of s)f.destroy();d()},i}var G=16,he=new Map;function Me(t){let e=he.get(t);return e||(e=fetch(t,{mode:"cors",credentials:"omit"}).then(n=>n.ok?n.blob():Promise.reject(new Error(`HTTP ${n.status}`))).then(n=>createImageBitmap(n,{resizeWidth:G,resizeHeight:G,resizeQuality:"medium"})).then(n=>{let r=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(G,G):Object.assign(document.createElement("canvas"),{width:G,height:G})).getContext("2d");return r.drawImage(n,0,0),n.close(),Le(r.getImageData(0,0,G,G).data)}).catch(n=>(_(`gl.imageColor(): could not read ${t} (it needs CORS, like every GL image); its colour stays [0, 0, 0, 0].`,n),null)),he.set(t,e),e)}function Le(t){let e=[0,0,0,0],n=new Map;for(let u=0;u<t.length;u+=4){let d=t[u+3]/255;if(e[0]+=t[u]*d,e[1]+=t[u+1]*d,e[2]+=t[u+2]*d,e[3]+=d,d<.5)continue;let f=(t[u]>>6)*16+(t[u+1]>>6)*4+(t[u+2]>>6),c=n.get(f)||[0,0,0,0];c[0]+=t[u],c[1]+=t[u+1],c[2]+=t[u+2],c[3]++,n.set(f,c)}let s=t.length/4,r=e[3]?[e[0]/e[3]/255,e[1]/e[3]/255,e[2]/e[3]/255,e[3]/s]:[0,0,0,0],o=[0,0,0,0];n.forEach(u=>u[3]>o[3]&&(o=u));let i=o[3]?[o[0]/o[3]/255,o[1]/o[3]/255,o[2]/o[3]/255,1]:r.slice();return[r,i]}function ve(t,e){let n=typeof e=="string"?document.querySelector(e):e,s=n instanceof HTMLImageElement?n:n?.querySelector("img"),r=n?.getAttribute("data-gl-src")||s?.currentSrc||s?.src||"",o={value:[0,0,0,0],dominant:[0,0,0,0],ready:Promise.resolve(!1)};return r?(o.ready=Me(new URL(r,document.baseURI).href).then(i=>{if(!i)return!1;for(let u=0;u<4;u++)o.value[u]=i[0][u],o.dominant[u]=i[1][u];return t.wake(),!0}),o):(_(`gl.imageColor(${typeof e=="string"?`"${e}"`:"el"}): no image there (an <img>, or data-gl-src).`),o)}function Se(t,e=s=>s,n=()=>document){let s=me(t,e);Q(t),t.velocityOf=(r,o)=>ce(t,r,o),t.drag=(r,o)=>ue(t,r,o,n()),t.trail=(r,o)=>de(t,r,o),t.step=(r,o)=>fe(t,r,o),t.texture=(r,o)=>Z(t,r,o),t.touch=r=>ye(t,r),t.rects=r=>be(t,r),t.imageColor=r=>ve(t,r),Object.defineProperty(t,"press",{configurable:!0,get:()=>s.listen()}),t.on("destroy",()=>s.destroy())}var ee={name:"input",version:"0.2.0",attributes:[],install(t,e,n,s){Se(t,n,s)}};var te=window;te.Umber?.use?te.Umber.use(ee):((te.UmberModules||=[]).push(ee),te.__umber?.engine?.use?.(ee));})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
function W(t,e,n,s){return t+(e-t)*(1-Math.pow(1-n,s*60))}function $(){let t=typeof document<"u"&&document.timeline?document.timeline.currentTime:null;return typeof t=="number"?t:performance.now()}var re=new Set;function C(t,...e){re.has(t)||(re.add(t),console.warn("[umber]",t,...e))}var V=[];function K(){let t=new Map,e=(n,s)=>void t.get(n)?.delete(s);return{on(n,s){return t.has(n)||t.set(n,new Set),t.get(n).add(s),()=>e(n,s)},off:e,emit(n,s){let r=t.get(n),o=V.length;r?.forEach(i=>V.push(i));for(let i=o,u=V.length;i<u;i++)if(r.has(V[i]))try{V[i](s)}catch(d){console.error(`[umber] a "${n}" handler threw:`,d)}V.length=o},clear(){t.clear()}}}var oe=6,xe=1,ae=new WeakMap;function se(t,e,n={},s=document){let r=t.track(e),o=typeof e=="string"?e:null,i=r.el.isConnected?r.el:null,u=null,d=n.axis||"both",m=Math.min(.999,Math.max(0,n.inertia??.92)),c=Math.min(1,Math.max(0,n.rubber??.35)),a=[0,0],p={value:[0,0]},E=[0,0],f=K(),I=[0,0,0,0],T=[0,0],M=$(),v=!1,x=-1,w=0,R=null,L=!1,O=!1,k=!1,A=!1,N=[],S={value:a,velocity:p,direction:E,bounds:typeof n.bounds=="function"?null:n.bounds||null,get el(){return i},get pressed(){return v},get target(){return R},get destroyed(){return A},set(l,h=a[1]){a[0]=Number(l)||0,a[1]=Number(h)||0,p.value[0]=p.value[1]=0,k=!0,t.wake(2)},on:f.on,off:f.off,destroy:Y,revert:Y};if(!i&&!o)return C(`gl.drag(${JSON.stringify(String(e))}): no element found. Pass an element, or a selector that matches one.`),A=!0,S;i||C(`gl.drag(${JSON.stringify(o)}): nothing matches yet. It binds to the first match that enters the page.`);let B=l=>(l?S.bounds?.y:S.bounds?.x)||null,X=(l,h)=>{let y=B(h);return y?l<y[0]?y[0]-(y[0]-l)*c:l>y[1]?y[1]+(l-y[1])*c:l:l},z=(l,h)=>{let y=B(h);return y?l<y[0]?c?y[0]-(y[0]-l)/c:y[0]:l>y[1]?c?y[1]+(l-y[1])/c:y[1]:l:l},H=l=>{let h=l;v||h.button!==void 0&&h.button>0||(v=!0,x=h.pointerId,w=0,O=!1,L=!1,R=h.target,I[0]=h.clientX,I[1]=h.clientY,I[2]=z(a[0],0),I[3]=z(a[1],1),f.emit("press",S),t.wake(2))},F=l=>{let h=l;if(!v||h.pointerId!==x)return;if(h.pointerType==="mouse"&&!h.buttons)return q(l);let y=d==="y"?0:h.clientX-I[0],D=d==="x"?0:h.clientY-I[1];if(w=Math.max(w,Math.hypot(y,D)),w>=oe&&!L){L=!0;try{i.setPointerCapture?.(x)}catch{}}a[0]=X(I[2]+y,0),a[1]=X(I[3]+D,1),k=!0,t.wake(2)};function q(l){if(!(!v||l.pointerId!==x)){if(v=!1,L)try{i.releasePointerCapture?.(x)}catch{}f.emit("release",S),w>=oe?(O=!0,setTimeout(()=>O=!1)):l.type==="pointerup"&&f.emit("tap",S),t.wake(2)}}for(let l of["pointerup","pointercancel"])addEventListener(l,q),N.push(()=>removeEventListener(l,q));let be=l=>{O&&(O=!1,l.preventDefault(),l.stopPropagation())},ve=l=>l.preventDefault();function te(l,h){u?.(),i=l;let y=[],D=(b,U,P)=>{l.addEventListener(b,U,P),y.push(()=>l.removeEventListener(b,U,P))};D("pointerdown",H),D("pointermove",F),D("pointerup",q),D("pointercancel",q),D("click",be,{capture:!0}),D("dragstart",ve),typeof getComputedStyle=="function"&&(getComputedStyle(l).touchAction||"auto")==="auto"&&C(`gl.drag(): give the element touch-action: ${d==="x"?"pan-y":d==="y"?"pan-x":"none"} in its CSS. With "auto" a finger scrolls the page instead of dragging.`,l);let g=n.bounds;if(typeof g=="function"){let b=()=>void(S.bounds=g(l)||null);b(),y.push(h.on("resize",b))}u=()=>{if(u=null,y.forEach(b=>b()),v){if(L)try{l.releasePointerCapture?.(x)}catch{}v=L=!1,f.emit("release",S)}h.destroy()};let _=()=>{if(!o)return Y();u?.(),queueMicrotask(()=>{let b=s.querySelector(o);b&&ne(b)})};h.destroyed?_():y.push(h.on("destroy",_))}function ne(l){A||l===i&&u||!l.isConnected||(te(l,t.track(l)),a[0]=a[1]=T[0]=T[1]=0,p.value[0]=p.value[1]=0,k=!0,t.wake(2))}let Ee=t.on("frame",l=>{let h=l.dt>0?l.dt:.016666666666666666,y=$(),D=y>M?(y-M)/1e3:h;M=y;let g=p.value,_=!1;for(let b=0;b<2;b++){if(v)g[b]=W(g[b],(a[b]-T[b])/D,.4,h);else{a[b]+=g[b]*h;let U=B(b),P=U?a[b]<U[0]?U[0]:a[b]>U[1]?U[1]:null:null;g[b]*=Math.pow(P===null?m:.5,h*60),P!==null&&(a[b]=Math.abs(P-a[b])<.01?P:W(a[b],P,.18,h),a[b]!==P&&(_=!0))}a[b]!==T[b]&&(E[b]=a[b]>T[b]?1:-1,k=!0)}Math.abs(g[0])+Math.abs(g[1])<xe&&(!v||a[0]===T[0]&&a[1]===T[1])&&(g[0]=g[1]=0),T[0]=a[0],T[1]=a[1],k&&f.emit("change",S),k=!1,(_||g[0]!==0||g[1]!==0)&&t.wake()},{always:!1,phase:"measure",order:-1100});if(N.push(Ee),i&&te(i,r),o&&!A){let l=s===document?t:s,h=ae.get(l)||new Map;ae.set(l,h);let y=h.get(o);h.set(o,S),y&&queueMicrotask(()=>!A&&y.destroy()),N.push(()=>void(h.get(o)===S&&(y&&!y.destroyed?h.set(o,y):h.delete(o))),t.on("added",D=>{let g=null;if(!((D[0]===document.documentElement||document.readyState==="loading")&&u)){for(let _ of D){try{g=[..._.matches(o)?[_]:[],..._.querySelectorAll(o)].find(b=>s.contains(b))||null}catch{return}if(g)break}g&&(g!==i||!u)&&queueMicrotask(()=>ne(g))}}),t.on("destroy",Y))}function Y(){A||(A=!0,u?.(),v=!1,N.forEach(l=>l()),N.length=0,f.clear())}return S}var J=(t,e)=>t.on("frame",e,{always:!1,phase:"update",order:-800});function ue(t,e,n={}){let s=n.smooth??.25,r=n.rest??.001,o=[0],i=()=>{let f=e.value;return typeof f!="number"?f:(o[0]=f,o)},u=typeof e.value=="number",d=Array.from(i()),m=d.map(()=>0),c=$(),a=!1,p={value:u?0:m,get destroyed(){return a},destroy(){a=!0,E()}},E=J(t,f=>{let I=f.dt>0?f.dt:.016666666666666666,T=$(),M=T>c?(T-c)/1e3:I;c=T;let v=i(),x=!1,w=!0;for(let R=0;R<m.length;R++){let L=Number(v[R])||0;L!==d[R]&&(x=!0),m[R]=W(m[R],(L-d[R])/M,s,I),d[R]=L,Math.abs(m[R])>=r&&(w=!1)}w&&!x&&m.fill(0),u&&(p.value=m[0]),(x||!w)&&t.wake()});return p}function le(t,e=16,n={}){let s=n.follow??.5,r=t.pointer.value,o=Array.from({length:Math.max(1,Math.floor(e)||1)},()=>({value:[r[0],r[1]]})),i=!1,u=J(t,d=>{let m=d.dt>0?d.dt:.016666666666666666,c=!1;for(let a=0;a<o.length;a++){let p=o[a].value,E=a?o[a-1].value:r;for(let f=0;f<2;f++)a===0||Math.abs(E[f]-p[f])<.01?p[f]=E[f]:(p[f]=W(p[f],E[f],s,m),c=!0)}c&&t.wake()});return{points:o,get destroyed(){return i},destroy(){i=!0,u()}}}var ie=4,ge=-1e4;function ce(t,e=n=>n){let n=K(),s=Array.from({length:ie},()=>({value:[0,0,ge]})),r=[],o=0,i={value:s[0].value,recent:s,get count(){return o},on:(c,a)=>e(n.on(c,a)),off:n.off},u=c=>{let a=c;Number.isFinite(a.clientX)&&(r.push([a.clientX,a.clientY]),t.wake())},d=!1,m=J(t,c=>{for(let a=0;a<r.length;a++){for(let E=ie-1;E>0;E--)for(let f=0;f<3;f++)s[E].value[f]=s[E-1].value[f];let p=s[0].value;p[0]=r[a][0],p[1]=r[a][1],p[2]=c.time,o++,n.emit("press",i)}r.length=0});return{signal:i,listen(){return d||addEventListener("pointerdown",u,{passive:!0}),d=!0,i},destroy(){m(),d=!0,removeEventListener("pointerdown",u),n.clear()}}}function de(t,e,n){let s=t.pointer,r=Math.max(1,Number(e)||80),o=[s.value[0],s.value[1]],i=s.active,u=0,d=0,m=()=>i=!1,c=document.documentElement;addEventListener("pointerdown",m,{passive:!0}),c.addEventListener("pointerenter",m,{passive:!0});let a=()=>{E(),p(),removeEventListener("pointerdown",m),c.removeEventListener("pointerenter",m)},p=t.on("destroy",a),E=J(t,()=>{let f=s.value,I=f[0]-o[0],T=f[1]-o[1],M=Math.hypot(I,T),v=r-u;for(i&&(u+=M),i=s.active;u>=r;){u-=r;let x=M?v/M:1;v+=r;try{n([o[0]+I*x,o[1]+T*x],++d)}catch(w){console.error("[umber] a gl.step() callback threw:",w)}}o[0]=f[0],o[1]=f[1]});return a}var Te=t=>!!t&&typeof t=="object"&&ArrayBuffer.isView(t.data);function we(t){let e=t;return[e.videoWidth||e.naturalWidth||e.width||0,e.videoHeight||e.naturalHeight||e.height||0]}var fe=new WeakMap;function Q(t){let e=fe.get(t);if(!e){let n=new Set;e={all:n},fe.set(t,e),t.on("restored",()=>n.forEach(s=>s.lost())),t.on("destroy",()=>n.forEach(s=>s.destroy()))}return e}var ee=class{constructor(e,n,s){this.engine=e;this.source=n;this.options=s;this.width=0;this.height=0;this.destroyed=!1;this.tex=null;this.gl=null;this.dirty=!0;this.shape="";this.unwatch=null;Q(e).all.add(this),this.watch()}get texture(){let e=this.engine.context;return!e||this.destroyed?null:((this.gl!==e||!this.tex)&&(this.gl=e,this.tex=e.createTexture(),this.shape="",this.dirty=!0),this.dirty&&this.upload(e),this.tex)}update(e){this.destroyed||(e&&e!==this.source&&(this.source=e,this.watch()),this.dirty=!0,this.engine.wake())}lost(){this.tex=null}destroy(){this.destroyed||(this.destroyed=!0,this.unwatch?.(),Q(this.engine).all.delete(this),this.tex&&this.gl&&!this.gl.isContextLost()&&this.gl.deleteTexture(this.tex),this.tex=null)}watch(){this.unwatch?.(),this.unwatch=null;let e=this.source;if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement){if(e.complete&&e.naturalWidth)return;let r=()=>this.update();e.addEventListener("load",r,{once:!0}),this.unwatch=()=>e.removeEventListener("load",r);return}if(typeof HTMLVideoElement>"u"||!(e instanceof HTMLVideoElement))return;let n=!0,s=()=>this.update();if(typeof e.requestVideoFrameCallback=="function"){let r=0,o=()=>{n&&(s(),r=e.requestVideoFrameCallback(o))};r=e.requestVideoFrameCallback(o),this.unwatch=()=>{n=!1,e.cancelVideoFrameCallback(r)}}else{for(let r of["timeupdate","seeked","loadeddata"])e.addEventListener(r,s);this.unwatch=()=>{for(let r of["timeupdate","seeked","loadeddata"])e.removeEventListener(r,s)}}}upload(e){let n=this.source,[s,r]=we(n);if(!s||!r||n instanceof HTMLVideoElement&&n.readyState<2)return;this.dirty=!1;let o=e.getParameter(e.TEXTURE_BINDING_2D);e.bindTexture(e.TEXTURE_2D,this.tex),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.BROWSER_DEFAULT_WEBGL);let i=!1;if(Te(n)){i=n.data instanceof Float32Array;let m=n.data.length/(s*r),c=m===1?e.RED:m===2?e.RG:m===4?e.RGBA:0;if(!c){C(`gl.texture(): data has ${n.data.length} numbers for ${s} x ${r} texels; give 1, 2 or 4 per texel (R, RG or RGBA).`),e.bindTexture(e.TEXTURE_2D,o);return}let a=i?m===1?e.R32F:m===2?e.RG32F:e.RGBA32F:m===1?e.R8:m===2?e.RG8:e.RGBA8,p=i?e.FLOAT:e.UNSIGNED_BYTE,E=n.data instanceof Uint8ClampedArray?new Uint8Array(n.data.buffer,n.data.byteOffset,n.data.length):n.data,f=`${s} ${r} ${a}`;e.pixelStorei(e.UNPACK_ALIGNMENT,1),f===this.shape?e.texSubImage2D(e.TEXTURE_2D,0,0,0,s,r,c,p,E):e.texImage2D(e.TEXTURE_2D,0,a,s,r,0,c,p,E),e.pixelStorei(e.UNPACK_ALIGNMENT,4),this.shape=f}else{let m=`${s} ${r}`;m===this.shape?e.texSubImage2D(e.TEXTURE_2D,0,0,0,e.RGBA,e.UNSIGNED_BYTE,n):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,n),this.shape=m}let u=i||this.options.filter==="nearest"?e.NEAREST:e.LINEAR,d=this.options.wrap==="repeat"?e.REPEAT:e.CLAMP_TO_EDGE;e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,u),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,d),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,d),e.bindTexture(e.TEXTURE_2D,o),this.width=s,this.height=r}};function Z(t,e,n={}){if(!e||typeof e!="object")throw new TypeError("[umber] gl.texture(source) needs a canvas, ImageBitmap, video, image, ImageData or { data, width, height }.");if(ArrayBuffer.isView(e))throw new TypeError("[umber] gl.texture(numbers) needs their size: gl.texture({ data, width, height }), 1, 2 or 4 numbers per texel.");return new ee(t,e,n)}var j=16;function pe(t,e={}){let n=Math.max(8,Math.round(e.size??64)),s=Math.min(.999,Math.max(0,e.fade??.92)),r=(M,v)=>{if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(M,v);let x=document.createElement("canvas");return x.width=M,x.height=v,x},o=()=>Math.max(1,Math.round(n*(innerHeight||1)/(innerWidth||1))),i=r(n,o()),u=i.getContext("2d"),d=Math.max(1,(e.radius??.08)*n),m=Array.from({length:j},(M,v)=>{let x=r(Math.ceil(d*2),Math.ceil(d*2)),w=x.getContext("2d");if(w){let R=v/j*Math.PI*2,L=`${Math.round((Math.cos(R)*.5+.5)*255)}, ${Math.round((Math.sin(R)*.5+.5)*255)}, 255`,O=w.createRadialGradient(d,d,0,d,d,d);O.addColorStop(0,`rgba(${L}, 1)`),O.addColorStop(1,`rgba(${L}, 0)`),w.fillStyle=O,w.fillRect(0,0,d*2,d*2)}return x}),c=Z(t,i);if(Object.defineProperty(c,"canvas",{value:i}),!u)return C("gl.touch(): this browser gives no 2D canvas; the touch texture stays empty."),c;let a=t.pointer,p=[a.value[0],a.value[1]],E=a.active,f=0,I=t.on("frame",M=>{if(c.destroyed)return I();let v=a.value,x=E&&(v[0]!==p[0]||v[1]!==p[1]);if(!x&&f===0){E=a.active,p[0]=v[0],p[1]=v[1];return}let w=Math.min(.25,M.dt>0?M.dt:1/60),R=o();i.height!==R&&(i.height=R);let L=Math.pow(s,w*60);if(f>0&&(u.globalCompositeOperation="destination-out",u.globalAlpha=1-L,u.fillRect(0,0,i.width,i.height),f*=L),x){let O=i.width/(innerWidth||1),k=i.height/(innerHeight||1),A=p[0]*O,N=p[1]*k,S=v[0]*O-A,B=v[1]*k-N,X=Math.hypot(S,B),z=m[(Math.round(Math.atan2(B,S)/(Math.PI*2)*j)+j)%j];u.globalCompositeOperation="source-over",u.globalAlpha=Math.min(1,.35+X/d);let H=Math.max(1,Math.ceil(X/(d*.5)));for(let F=1;F<=H;F++)u.drawImage(z,A+S*F/H-d,N+B*F/H-d);f=1}f<1/255&&(f=0,u.clearRect(0,0,i.width,i.height)),E=a.active,p[0]=v[0],p[1]=v[1],c.update()},{always:!1,phase:"update",order:-800}),T=c.destroy.bind(c);return c.destroy=()=>{I(),T()},c}function he(t,e){let n=Array.from(typeof e=="string"?document.querySelectorAll(e):e);n.length||C(`gl.rects(${typeof e=="string"?`"${e}"`:"[]"}): no elements; the texture holds one empty rect.`);let s=n.map(m=>t.track(m)),r=new Float32Array(Math.max(1,n.length)*4),o=()=>{let m=!1;for(let c=0;c<s.length;c++){let a=s[c].rect,p=c*4,E=Math.fround;(r[p]!==E(a.x)||r[p+1]!==E(a.y)||r[p+2]!==E(a.width)||r[p+3]!==E(a.height))&&(r[p]=a.x,r[p+1]=a.y,r[p+2]=a.width,r[p+3]=a.height,m=!0)}return m};o();let i=Z(t,{data:r,width:Math.max(1,n.length),height:1});Object.defineProperties(i,{count:{value:n.length},rects:{value:r}});let u=t.on("frame",()=>i.destroyed?u():o()&&i.update(),{always:!1,phase:"update",order:-800}),d=i.destroy.bind(i);return i.destroy=()=>{u();for(let m of s)m.destroy();d()},i}var G=16,me=new Map;function Re(t){let e=me.get(t);return e||(e=fetch(t,{mode:"cors",credentials:"omit"}).then(n=>n.ok?n.blob():Promise.reject(new Error(`HTTP ${n.status}`))).then(n=>createImageBitmap(n,{resizeWidth:G,resizeHeight:G,resizeQuality:"medium"})).then(n=>{let r=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(G,G):Object.assign(document.createElement("canvas"),{width:G,height:G})).getContext("2d");return r.drawImage(n,0,0),n.close(),Ie(r.getImageData(0,0,G,G).data)}).catch(n=>(C(`gl.imageColor(): could not read ${t} (it needs CORS, like every GL image); its colour stays [0, 0, 0, 0].`,n),null)),me.set(t,e),e)}function Ie(t){let e=[0,0,0,0],n=new Map;for(let u=0;u<t.length;u+=4){let d=t[u+3]/255;if(e[0]+=t[u]*d,e[1]+=t[u+1]*d,e[2]+=t[u+2]*d,e[3]+=d,d<.5)continue;let m=(t[u]>>6)*16+(t[u+1]>>6)*4+(t[u+2]>>6),c=n.get(m)||[0,0,0,0];c[0]+=t[u],c[1]+=t[u+1],c[2]+=t[u+2],c[3]++,n.set(m,c)}let s=t.length/4,r=e[3]?[e[0]/e[3]/255,e[1]/e[3]/255,e[2]/e[3]/255,e[3]/s]:[0,0,0,0],o=[0,0,0,0];n.forEach(u=>u[3]>o[3]&&(o=u));let i=o[3]?[o[0]/o[3]/255,o[1]/o[3]/255,o[2]/o[3]/255,1]:r.slice();return[r,i]}function ye(t,e){let n=typeof e=="string"?document.querySelector(e):e,s=n instanceof HTMLImageElement?n:n?.querySelector("img"),r=n?.getAttribute("data-gl-src")||s?.currentSrc||s?.src||"",o={value:[0,0,0,0],dominant:[0,0,0,0],ready:Promise.resolve(!1)};return r?(o.ready=Re(new URL(r,document.baseURI).href).then(i=>{if(!i)return!1;for(let u=0;u<4;u++)o.value[u]=i[0][u],o.dominant[u]=i[1][u];return t.wake(),!0}),o):(C(`gl.imageColor(${typeof e=="string"?`"${e}"`:"el"}): no image there (an <img>, or data-gl-src).`),o)}function Me(t,e=s=>s,n=()=>document){let s=ce(t,e);Q(t),t.velocityOf=(r,o)=>ue(t,r,o),t.drag=(r,o)=>se(t,r,o,n()),t.trail=(r,o)=>le(t,r,o),t.step=(r,o)=>de(t,r,o),t.texture=(r,o)=>Z(t,r,o),t.touch=r=>pe(t,r),t.rects=r=>he(t,r),t.imageColor=r=>ye(t,r),Object.defineProperty(t,"press",{configurable:!0,get:()=>s.listen()}),t.on("destroy",()=>s.destroy())}var Le={name:"input",version:"0.2.0",attributes:[],install(t,e,n,s){Me(t,n,s)}},Ge=Le;export{Le as Input,ce as createPress,Ge as default,se as drag,ye as imageColor,Me as input,he as rects,de as step,Z as texture,pe as touch,le as trail,ue as velocityOf};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (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.0",attributes:[],install(t,d){He(t,d)}};var q=window,Pe=document.currentScript?.src;xe(Pe?Pe.replace(/[^/]*$/,""):`${be}/umber@0.2.0/modules/`);q.Umber?.use?q.Umber.use(C):((q.UmberModules||=[]).push(C),q.__umber?.engine?.use?.(C));})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (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.0",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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (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.0",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));})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (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.0",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};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
"use strict";(()=>{function qe(n){let e=n.trim().toLowerCase();if(e===""||e==="true"||e==="1"||e==="yes")return!0;if(e==="false"||e==="0"||e==="no")return!1}function Ee(n,e){let t=n.trim();if(e==="number"){let r=parseFloat(t);return Number.isFinite(r)?r:void 0}return e==="boolean"?qe(t):e==="list"?t.split(/[\s,]+/).filter(Boolean):t.replace(/^["']|["']$/g,"")}function Xe(n){return n.type?n.type:typeof n.default=="number"?"number":typeof n.default=="boolean"?"boolean":Array.isArray(n.default)?"list":"string"}var xe=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);function Te(n,e,t,r){if(typeof e=="string"){let o=e.replace(/^data-/,""),i=t||{},a={};for(let s in i)a[s]={attr:`data-${o}-${xe(s)}`,css:`--${o}-${xe(s)}`,default:i[s]};return ke(n,a,r)}return ke(n,e,t)}function ke(n,e,t){let r={},o=t;for(let i in e){let a=e[i],s=Xe(a),f;if(a.attr){let l=n.getAttribute(a.attr);l!==null&&(f=Ee(l,s))}if(f===void 0&&a.css){o||=getComputedStyle(n);let l=o.getPropertyValue(a.css);l&&l.trim()!==""&&(f=Ee(l,s))}r[i]=f===void 0?a.default:f}return r}var Ae={top:0,left:0,center:.5,middle:.5,bottom:1,right:1};function Ke(n){let e=/^(top|left|center|middle|bottom|right|-?\d*\.?\d+(?:px|%)?)?(?:([+-])=?(\d*\.?\d+)(px|%)?)?$/.exec(n);if(!e||!e[1]&&!e[2])return null;let t=0,r=0;if(e[1]&&e[1]in Ae)t=Ae[e[1]];else if(e[1]){let o=parseFloat(e[1]);e[1].endsWith("%")?t=o/100:r=o}if(e[2]){let o=parseFloat(e[3])*(e[2]==="-"?-1:1);e[4]==="%"?t+=o/100:r+=o}return[t,r]}function K(n,e){let t=(n||"").trim().toLowerCase();if(!t)return e;let r=Ke(t);return r?/^[+-]/.test(t)&&!/^-\d/.test(t)?[e[0]+r[0],e[1]+r[1]]:r:e}var Qe={cover:"0110",contain:"11000011",entry:"01110100",exit:"00101110","entry-crossing":"0111","exit-crossing":"0010"};function Ye(n,e){let t=Qe[n[0]],r=n[1]||(e?"100%":"0%"),o=r.endsWith("%")?0:parseFloat(r)||0,i=o?0:parseFloat(r)/100||0,a=s=>({el:+t[s]+(+t[s+2]-+t[s])*i,elPx:o,vp:+t[s+1]+(+t[s+3]-+t[s+1])*i,vpPx:0});return t?{...a(0),alt:t[4]?a(4):void 0}:null}function Q(n,e){let t=(n||e).trim().split(/\s+/),r=Ye(t.map(l=>l.toLowerCase()),e.startsWith("bottom"));if(r)return r;let o=e.split(/\s+/),[i,a]=K(t[0],K(o[0],[0,0])),[s,f]=K(t[1],K(o[1],[0,0]));return{el:i,elPx:a,vp:s,vpPx:f}}function fe(n,e,t,r,o){let i=l=>(l.alt&&e>t&&(l=l.alt),n+e*l.el+l.elPx-(t*l.vp+l.vpPx)),a=i(r),s=i(o),f=a-s;return Math.abs(f)>1e-6?Math.min(1,Math.max(0,a/f)):a<=0?1:0}function Ue(n,e,t,r){return!(t>0)||!(r>0)?e:n+(e-n)*(1-Math.exp(-r/t))}function Ce(n,e,t,r,o){if(e<=0)return null;let i=Math.max(0,Math.min(e-1,n)),a=Math.floor(i),s=i-a;if(o&&s>.001&&a+1<e&&t(a)&&t(a+1))return{a,b:a+1,mix:s};let f=Math.round(i);if(t(f))return{a:f,b:-1,mix:0};let l=-1;for(let M of r())(l<0||Math.abs(M-i)<Math.abs(l-i))&&(l=M);return l<0?null:{a:l,b:-1,mix:0}}function Fe(n,e){return n.replace(/\{(\d+)\}/,(t,r)=>String(parseInt(r,10)+e).padStart(r.length,"0"))}var Re=(n,e)=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]);function W(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function G(n,e,t=n.length){if(e+8>t)return null;let r=W(n),o=r.getUint32(e),i=Re(n,e+4),a=e+8;if(o===1){if(e+16>t)return null;o=r.getUint32(e+8)*2**32+r.getUint32(e+12),a=e+16}else o===0&&(o=1/0);return o<a-e?null:{type:i,start:e,body:a,end:e+o}}function me(n,e,t){let r=[],o=e;for(;o<t;){let i=G(n,o,t);if(!i||i.end>t||i.end<=o)break;r.push(i),o=i.end}return r}var V=(n,e,t)=>me(n,e.body,e.end).find(r=>r.type===t)||null;function Y(n,e,...t){for(let r of t){if(!e)return null;e=V(n,e,r)}return e}function Ge(n){let e=t=>t.toString(16).padStart(2,"0");return`avc1.${e(n[1])}${e(n[2])}${e(n[3])}`}function Pe(n,e){let t=V(n,e,"mvhd"),r=t?W(n).getUint32(t.body+(n[t.body]===1?20:12)):0;for(let o of me(n,e.body,e.end)){if(o.type!=="trak")continue;let i=Y(n,o,"mdia","hdlr");if(!i||Re(n,i.body+8)!=="vide")continue;let a=Ze(n,o,r);if(a)return V(n,e,"mvex")&&(a.fragmented=!0),a}return null}function Ze(n,e,t){let r=W(n),o=Y(n,e,"mdia","mdhd"),i=Y(n,e,"mdia","minf","stbl");if(!o||!i)return null;let a=n[o.body]===1,s=r.getUint32(o.body+(a?20:12))||1,f=V(n,i,"stsd");if(!f)return null;let l=G(n,f.body+8,f.end);if(!l)return null;let M=l.type,E=r.getUint16(l.body+24),w=r.getUint16(l.body+26),U="",F=null,m=me(n,l.body+78,l.end).find(u=>u.type==="avcC");m&&(M==="avc1"||M==="avc3")&&(F=n.slice(m.body,m.end),U=Ge(F));let x=V(n,e,"tkhd");if(x){let u=x.body+(n[x.body]===1?88:76);if(u+8<=x.end){let v=r.getUint32(u)/65536,C=r.getUint32(u+4)/65536;v&&C&&(E=Math.round(v),w=Math.round(C))}}let g=Je(n,i);if(!g)return null;let T=g.length,P=je(n,e,s,t||s),S=P==="cuts"?null:P,b=g.map((u,v)=>v).filter(u=>!S||g[u].cts+g[u].duration/2>=S[0]&&g[u].cts+g[u].duration/2<S[1]).sort((u,v)=>g[u].cts-g[v].cts||u-v),H=new Array(T),k=0,A=1;for(let u=0;u<T;u++)g[u].key&&(u&&(A=Math.max(A,u-k)),k=u),H[u]=k;T&&(A=Math.max(A,T-k));let _=b.length?g[b[b.length-1]]:null,c=(_?_.cts+_.duration-g[b[0]].cts:0)/s;return{codec:U,format:M,description:F,width:E,height:w,timescale:s,duration:c,fps:c>0?b.length/c:30,samples:g,order:b,keyOf:H,gop:A,cuts:P==="cuts"}}function je(n,e,t,r){let o=Y(n,e,"edts","elst");if(!o)return null;let i=W(n),a=n[o.body]===1,s=a?20:12,f=i.getUint32(o.body+4),l=null;for(let M=0;M<f;M++){let E=o.body+8+M*s;if(E+s>o.end)break;let w=a?i.getUint32(E)*2**32+i.getUint32(E+4):i.getUint32(E),U=a?i.getInt32(E+8)*2**32+i.getUint32(E+12):i.getInt32(E+4);if(!(U<0)){if(l)return"cuts";l=[U,w?U+w*t/r:1/0]}}return l}function Je(n,e){let t=W(n),r=h=>V(n,e,h),o=[],i=r("stsz"),a=r("stz2");if(i){let h=t.getUint32(i.body+4),c=t.getUint32(i.body+8);o=new Array(c);for(let u=0;u<c;u++)o[u]=h||t.getUint32(i.body+12+u*4)}else if(a){let h=n[a.body+7],c=t.getUint32(a.body+8);o=new Array(c);for(let u=0;u<c;u++){let v=a.body+12;h===16?o[u]=t.getUint16(v+u*2):h===8?o[u]=n[v+u]:o[u]=n[v+(u>>1)]>>(u&1?0:4)&15}}else return null;let s=o.length,f=r("stco"),l=r("co64"),M=[];if(f){let h=t.getUint32(f.body+4);for(let c=0;c<h;c++)M.push(t.getUint32(f.body+8+c*4))}else if(l){let h=t.getUint32(l.body+4);for(let c=0;c<h;c++)M.push(t.getUint32(l.body+8+c*8)*2**32+t.getUint32(l.body+12+c*8))}else return null;let E=r("stsc");if(!E)return null;let w=[],U=t.getUint32(E.body+4);for(let h=0;h<U;h++){let c=E.body+8+h*12;w.push({first:t.getUint32(c)-1,per:t.getUint32(c+4)})}let F=new Array(s),m=0;for(let h=0;h<w.length&&m<s;h++){let c=h+1<w.length?w[h+1].first:M.length;for(let u=w[h].first;u<c&&m<s;u++){let v=M[u];for(let C=0;C<w[h].per&&m<s;C++)F[m]=v,v+=o[m],m++}}if(m<s)return null;let x=r("stts");if(!x)return null;let g=new Array(s),T=new Array(s),P=0;m=0;let S=t.getUint32(x.body+4);for(let h=0;h<S&&m<s;h++){let c=t.getUint32(x.body+8+h*8),u=t.getUint32(x.body+12+h*8);for(let v=0;v<c&&m<s;v++)g[m]=P,T[m]=u,P+=u,m++}for(;m<s;m++)g[m]=P,T[m]=0;let b=g.slice(),H=r("ctts");if(H){let h=t.getUint32(H.body+4);m=0;for(let c=0;c<h&&m<s;c++){let u=t.getUint32(H.body+8+c*8),v=t.getInt32(H.body+12+c*8);for(let C=0;C<u&&m<s;C++)b[m++]+=v}}let k=r("stss"),A=new Array(s).fill(!k);if(k){let h=t.getUint32(k.body+4);for(let c=0;c<h;c++){let u=t.getUint32(k.body+8+c*4)-1;u>=0&&u<s&&(A[u]=!0)}}s&&(A[0]=!0);let _=new Array(s);for(let h=0;h<s;h++)_[h]={offset:F[h],size:o[h],dts:g[h],cts:b[h],duration:T[h],key:A[h]};return _}var Z=class{constructor(){this.bytes=new Uint8Array(0);this.loaded=0;this.total=0;this.done=!1;this.track=null;this.late=!1;this.onTrack=null;this.onData=null;this.onError=null;this.cursor=0;this.sawMdat=!1;this.abort=null}start(e){this.abort=typeof AbortController<"u"?new AbortController:null,this.run(e).catch(t=>{this.abort?.signal.aborted||this.onError?.(t)})}async run(e){let t=await fetch(e,{mode:"cors",credentials:"omit",signal:this.abort?.signal});if(!t.ok)throw new Error(`HTTP ${t.status}`);let r=Number(t.headers.get("content-length"))||0;r&&!t.headers.get("content-encoding")&&(this.total=r);let o=t.body?.getReader?.();if(!o){this.push(new Uint8Array(await t.arrayBuffer())),this.finish();return}for(;;){let{done:i,value:a}=await o.read();if(i)break;a?.length&&this.push(a)}this.finish()}push(e){let t=this.loaded+e.length;if(t>this.bytes.length){let r=new Uint8Array(Math.max(t,this.total,this.bytes.length*2,1048576));r.set(this.bytes.subarray(0,this.loaded)),this.bytes=r}this.bytes.set(e,this.loaded),this.loaded=t,this.scan(),this.onData?.()}finish(){this.done=!0,this.scan(),this.track||this.onError?.(new Error("no H.264 video track found (is it an MP4?)")),this.onData?.()}scan(){for(;!this.track;){let e=G(this.bytes,this.cursor,this.loaded);if(!e)return;if(e.type==="moov"){if(e.end>this.loaded)return;this.late=this.sawMdat;let t=Pe(this.bytes,e);if(!t){this.onError?.(new Error("the MP4 has no video track"));return}this.track=t,this.onTrack?.(t);return}if(e.type==="mdat"&&(this.sawMdat=!0),!Number.isFinite(e.end))return;this.cursor=e.end}}has(e){return e.offset+e.size<=this.loaded}data(e){return this.bytes.subarray(e.offset,e.offset+e.size)}stop(){this.abort?.abort(),this.onTrack=this.onData=this.onError=null}};var j=class{constructor(e,t){this.track=e;this.host=t;this.target=-1;this.dir=0;this.busy=null;this.fetched=new Set;this.present=new Array(e.order.length),e.order.forEach((r,o)=>this.present[r]=o)}get frames(){return this.track.order.length}want(e,t=0){let r=this.frames,o=r?Math.max(0,Math.min(r-1,Math.round(e))):-1;o!==this.target&&this.fetched.clear(),this.target=o,this.dir=t>0?1:t<0?-1:0}next(){if(this.busy||this.target<0)return null;let e=this.reachable(this.target);if(e<0)return null;let t=this.host.has(e)?this.ahead(e):e;if(t<0)return null;t!==e&&this.fetched.add(t);let r=this.track.order[t],o=this.track.keyOf[r],i=Math.max(1,Math.floor(this.host.window()/2)),a=new Set([t]);for(let s=o;s<r;s++){let f=this.present[s];Math.abs(f-e)<=i&&!this.host.has(f)&&a.add(f)}return this.busy={from:o,to:r,goal:t,keep:a},this.busy}forget(){this.fetched.clear()}done(){this.busy=null}ready(e){let t=this.track.order[e];return t!==void 0&&this.host.available(t)&&this.host.available(this.track.keyOf[t])}reachable(e){if(this.ready(e))return e;let t=this.frames;for(let r=1;r<t;r++){if(e-r>=0&&this.ready(e-r))return e-r;if(e+r<t&&this.ready(e+r))return e+r}return-1}ahead(e){let t=this.frames,r=this.host.window(),o=Math.min(12,Math.max(1,Math.floor(r/2)-1),Math.floor((r-1)/2));for(let i=1;i<=o;i++)for(let a=0;a<(this.dir?1:2);a++){let s=e+i*(this.dir||1-2*a);if(!(s<0||s>=t)&&!this.host.has(s)&&!this.fetched.has(s)&&this.ready(s))return s}return-1}},et=25,tt=10;function rt(n){if(!n.length)return 0;let e=n.slice().sort((t,r)=>t-r);return e[Math.min(e.length-1,Math.ceil(e.length*.95)-1)]}function He(n){return n.length<tt?null:rt(n)>et}var st=3,_e="umber:scrub-decode",ot=()=>typeof navigator<"u"&&/Android/i.test(navigator.userAgent||"");function it(){try{let n=localStorage.getItem(_e);return n==="prefer-software"||n==="prefer-hardware"?n:null}catch{return null}}var at={hvc1:"HEVC (hvc1)",hev1:"HEVC (hev1)",av01:"AV1",vp09:"VP9",vp08:"VP8"},Oe=()=>typeof globalThis.VideoDecoder=="function"&&typeof globalThis.EncodedVideoChunk=="function",J=class{constructor(e,t){this.url=e;this.host=t;this.tier="decoder";this.stream=new Z;this.track=null;this.schedule=null;this.decoder=null;this.config=null;this.made=null;this.accel="no-preference";this.byTime=new Map;this.running=!1;this.on=!0;this.dead=!1;this.errors=0;this.timings=[];this.keep=null;this.outputs=0}start(){let e=this.stream;e.onTrack=t=>this.configure(t),e.onData=()=>this.pump(),e.onError=t=>this.fail(`could not read the video (${t instanceof Error?t.message:t})`),e.start(this.url)}async configure(e){if(!e.codec||!e.description)return this.fail(`is ${at[e.format]||e.format||"not H.264"}, and WebCodecs scrubbing reads H.264`,!0);if(e.fragmented&&!e.order.length)return this.fail("is a fragmented MP4 (its frames are indexed in fragments), which WebCodecs scrubbing doesn't read",!0);if(!e.order.length)return this.fail("has no frames in its index",!0);this.stream.late&&!this.stream.done&&this.host.log.warn('scrub video is not "faststart" (its index is at the end), so nothing shows until it fully downloads. Encode it with: npm run scrub -- input.mov'),e.cuts&&this.host.log.warn("scrub video has an edit list with several cuts, which the scrub does not follow: it shows every frame of the file. Re-encode it with: npm run scrub -- input.mov"),e.gop>10&&this.host.log.warn(`scrub video has a keyframe only every ${e.gop} frames: each step back decodes up to that many. For smooth scrubbing encode it with: npm run scrub -- input.mov`);let t=globalThis.VideoDecoder,r={codec:e.codec,codedWidth:e.width,codedHeight:e.height,description:e.description,optimizeForLatency:!0},o=ot()?it()||"prefer-hardware":"no-preference",i=o==="no-preference"?["no-preference"]:[o,"no-preference"];for(let s of i)try{let f=s==="no-preference"?r:{...r,hardwareAcceleration:s},l=await t.isConfigSupported(f);if(this.dead)return;if(l?.supported){this.config=f,this.accel=s;break}}catch{}if(!this.config)return this.fail(`this browser can't decode ${e.codec} with WebCodecs`);this.track=e,e.order.forEach((s,f)=>this.byTime.set(this.micros(e.samples[s].cts),f));let a=this.host.frames;this.schedule=new j(e,{has:s=>a.has(s),available:s=>this.stream.has(e.samples[s]),window:()=>Math.min(a.capacity(e.width,e.height),48)}),this.host.ready({frames:e.order.length,fps:e.fps,width:e.width,height:e.height}),this.pump()}micros(e){return Math.round(e/this.track.timescale*1e6)}request(e,t){this.schedule&&(this.schedule.want(e,t),this.pump())}active(e){this.on=e,e?(this.schedule?.forget(),this.pump()):this.close()}reset(){this.schedule?.forget(),this.pump()}decoderNow(){if(this.decoder&&this.decoder.state!=="closed"&&this.made===this.config)return this.decoder;this.close();let e=globalThis.VideoDecoder,t=new e({output:r=>this.output(r),error:r=>this.onError(t,r)});return t.configure(this.made=this.config),this.decoder=t,t}output(e){this.outputs++;let t=this.byTime.get(e.timestamp);if(t===void 0||this.dead||!this.keep?.has(t)||this.host.frames.ready(t)){e.close();return}this.host.frames.put(t,e,!0),this.host.delivered()}onError(e,t){e===this.decoder&&(this.decoder=null),t?.name!=="QuotaExceededError"&&this.host.log.info("scrub decoder error",t)}async pump(){if(this.running||this.dead||!this.on||!this.schedule||!this.track)return;let e=this.schedule.next();if(!e)return;this.running=!0;let t=this.track,r=performance.now(),o=this.errors,i=!0;try{let a=this.decoderNow();this.keep=e.keep,this.outputs=0;let s=globalThis.EncodedVideoChunk;for(let f=e.from;f<=e.to;f++){let l=t.samples[f];a.decode(new s({type:f===e.from||l.key?"key":"delta",timestamp:this.micros(l.cts),duration:this.micros(l.duration),data:this.stream.data(l)}))}await a.flush(),this.outputs===0&&(i=!1,this.errors++,this.close())}catch(a){i=!1,a?.name!=="QuotaExceededError"&&a?.name!=="AbortError"&&this.errors++,this.close()}if(this.running=!1,this.schedule?.done(),!this.dead){if(i)this.errors=0,this.time((performance.now()-r)/(e.to-e.from+1));else{if(this.errors>=st)return this.fail("the video decoder keeps failing");this.errors>o&&this.schedule?.forget()}this.pump()}}time(e){if(this.accel!=="prefer-hardware"||(this.timings.push(e),this.timings.length===1))return;let t=He(this.timings.slice(1));if(t===null)return;let r=t?"prefer-software":"prefer-hardware";try{localStorage.setItem(_e,r)}catch{}if(this.accel="no-preference",!t)return;let o={...this.config,hardwareAcceleration:"prefer-software"};globalThis.VideoDecoder.isConfigSupported(o).then(i=>{!i?.supported||this.dead||(this.host.log.info("scrub: hardware decoding is slow at seeking here; using the software decoder"),this.config=o,this.accel="prefer-software",this.running||this.close())}).catch(()=>{})}close(){let e=this.decoder;if(this.decoder=null,e&&e.state!=="closed")try{e.close()}catch{}}fail(e,t){this.dead||(this.destroy(),this.host.failed(e,t))}destroy(){this.dead=!0,this.stream.stop(),this.close(),this.schedule=null}};var ee=class{constructor(e,t,r,o){this.video=e;this.host=t;this.fps=r;this.src=o;this.tier="video";this.frames=0;this.target=-1;this.seeking=-1;this.landed=-1;this.fastFor=-1;this.errors=0;this.on=!0;this.dead=!1;this.cors=!1;this.offs=[]}start(){let e=this.video;e.muted=!0,e.playsInline=!0,e.setAttribute("playsinline",""),e.setAttribute("webkit-playsinline",""),e.disableRemotePlayback=!0,e.pause();let t=e.currentSrc||e.getAttribute("src")||e.querySelector("source")?.getAttribute("src")||"",r=this.src||t,o=e.preload!=="auto";e.preload="auto";try{r&&new URL(r,location.href).origin!==location.origin&&!e.crossOrigin&&(e.crossOrigin="anonymous",this.cors=o=!0)}catch{}this.src&&this.src!==t&&(e.src=this.src,o=!0),this.listen("seeked",()=>this.onSeeked()),this.listen("error",a=>{let s=e.querySelectorAll("source");(a.target===e||a.target===s[s.length-1])&&this.fail(this.cors?"the video failed to load (another domain: no CORS headers?)":"the video failed to load")},!0),e.readyState>=1&&!o?this.onMeta():(this.listen("loadedmetadata",()=>this.onMeta()),this.meta()),o&&e.load();let i=()=>{this.dead||e.readyState>=2||e.play().then(()=>e.pause()).catch(()=>{})};addEventListener("touchstart",i,{once:!0,passive:!0}),this.offs.push(()=>removeEventListener("touchstart",i))}listen(e,t,r=!1){this.video.addEventListener(e,t,r),this.offs.push(()=>this.video.removeEventListener(e,t,r))}meta(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.frames||this.dead||(this.video.networkState===1?this.meta():this.fail("the video's metadata never loaded"))},1e4)}onMeta(){if(this.frames||this.dead)return;let e=this.video;if(!Number.isFinite(e.duration)||e.duration<=0)return this.fail("the video has no duration (a live stream?)");this.frames=Math.max(1,Math.round(e.duration*this.fps)),this.host.ready({frames:this.frames,fps:this.fps,width:e.videoWidth,height:e.videoHeight}),this.pump()}request(e){this.frames&&(this.target=Math.max(0,Math.min(this.frames-1,Math.round(e))),this.pump())}active(e){this.on=e,this.pump()}reset(){this.seeking=-1,this.landed=-1,this.pump()}pump(){if(this.dead||!this.on||this.target<0)return;if(this.seeking>=0){let i=this.host.frames;if(this.landed>=0&&(i.ready(this.landed)||!i.has(this.landed)))this.seeking=-1,this.landed=-1;else return}let e=this.target;if(this.host.frames.has(e))return;let t=this.video;if(t.readyState<1)return;this.seeking=e,this.landed=-1;let r=Math.min((e+.5)/this.fps,Math.max(0,t.duration-.001)),o=Math.round(t.currentTime*this.fps-.5);typeof t.fastSeek=="function"&&Math.abs(e-o)>6&&e!==this.fastFor?(this.fastFor=e,t.fastSeek(r)):t.currentTime=r,clearTimeout(this.timer),this.timer=setTimeout(()=>{this.seeking<0||this.landed>=0||(this.seeking=-1,++this.errors>=3?this.fail("seeking the video never lands"):this.pump())},4e3)}onSeeked(){if(this.dead||this.seeking<0)return;clearTimeout(this.timer),this.errors=0;let e=this.video,t=Math.max(0,Math.min(this.frames-1,Math.floor(e.currentTime*this.fps+.001)));this.landed=t,this.host.frames.put(t,e,!1),this.host.delivered()}fail(e){this.dead||(this.destroy(),this.cors&&(this.video.removeAttribute("crossorigin"),this.video.load()),this.host.failed(e))}destroy(){this.dead=!0,clearTimeout(this.timer),this.offs.forEach(e=>e()),this.offs=[]}};var ut=4,ct=8,lt=2,dt=4,te=class{constructor(e,t,r,o){this.pattern=e;this.count=t;this.fps=r;this.host=o;this.tier="frames";this.target=-1;this.dir=0;this.loading=new Set;this.failedFrames=new Set;this.errors=0;this.known=!1;this.width=0;this.height=0;this.on=!0;this.dead=!1;this.abort=typeof AbortController<"u"?new AbortController:null}start(){if(!(this.count>0))return this.fail('data-gl-scrub-frames needs data-gl-scrub-count="<number of frames>"');this.load(0)}request(e,t){this.target=Math.max(0,Math.min(this.count-1,Math.round(e))),this.dir=t>0?1:t<0?-1:0,this.pump()}active(e){this.on=e,this.pump()}reset(){this.pump()}pump(){if(this.dead||!this.on||!this.known||this.target<0)return;let e=this.host.frames,t=this.dir>=0?1:-1,r=e.capacity(this.width,this.height)-1,o=Math.min(lt,r>>2),i=Math.min(ct,r-o);for(let a=0;a<=Math.max(0,i+o)&&this.loading.size<ut;a++){let s=this.target+(a<=i?a:i-a)*t;s<0||s>=this.count||e.has(s)||this.loading.has(s)||this.failedFrames.has(s)||this.load(s)}}async load(e){this.loading.add(e);let t=Fe(this.pattern,e);try{let r=await fetch(t,{mode:"cors",credentials:"omit",signal:this.abort?.signal});if(!r.ok)throw new Error(`HTTP ${r.status}`);let o=await r.blob(),i=await createImageBitmap(o,{premultiplyAlpha:"none",colorSpaceConversion:"default"}),a=this.host.maxTexture;if(i.width>a||i.height>a){let s=a/Math.max(i.width,i.height),f=await createImageBitmap(i,{resizeWidth:Math.floor(i.width*s),resizeHeight:Math.floor(i.height*s),resizeQuality:"high"});i.close(),i=f}if(this.loading.delete(e),this.dead)return i.close();this.errors=0,this.known||(this.known=!0,this.width=i.width,this.height=i.height,this.host.ready({frames:this.count,fps:this.fps,width:i.width,height:i.height})),this.host.frames.put(e,i,!0),this.host.delivered()}catch(r){if(this.loading.delete(e),this.dead)return;if(this.failedFrames.add(e),this.host.log.warn(`scrub frame ${t} failed to load`,r),!this.known||++this.errors>=dt)return this.fail(`the image sequence ${this.pattern} does not load`)}this.pump()}fail(e){this.dead||(this.destroy(),this.host.failed(e))}destroy(){this.dead=!0,this.abort?.abort()}};var Le=()=>{let n=typeof window<"u"&&window.occluzeCapture;return n?.version==1?n:null},pe=()=>new Promise(n=>{let e=new MessageChannel;e.port1.onmessage=n,e.port2.postMessage(0)});var Be=n=>new Promise(e=>{let t=AbortSignal.timeout?.(n);t?t.onabort=()=>e():setTimeout(e,n)});var ht={high:128,mid:48,low:32},Ve=new Set,ft=.12,mt=250,pt=20,be={start:"top bottom",end:"bottom top",track:"",smooth:-1,source:"auto",src:"",srcMobile:"",frames:"",count:0,fps:0,blend:!0,cache:0,reduced:""},$e={uniforms:{uScrubProgress:0,uScrubVelocity:0},fragment:{head:`uniform sampler2D uFrameNext;
|
|
3
|
+
uniform float uFrameMix;
|
|
4
|
+
vec4 scrubNext(vec2 uv) {
|
|
5
|
+
vec2 f = fitUv(uv);
|
|
6
|
+
if (uFit > 0.5 && uFit < 1.5 && (f.x < 0.0 || f.y < 0.0 || f.x > 1.0 || f.y > 1.0)) return vec4(0.0);
|
|
7
|
+
return texture(uFrameNext, f);
|
|
8
|
+
}`,color:"if (uFrameMix > 0.0) color = mix(color, scrubNext(uv), uFrameMix);"}};function bt(n,e){let t=e.trim();if(!t||t==="self")return null;if(t==="parent")return n.parentElement;try{return t.startsWith("closest ")?n.closest(t.slice(8).trim()):n.closest(t)||document.querySelector(t)}catch{return null}}function gt(n,e){return e||n?.currentSrc||n?.getAttribute("src")||n?.querySelector("source")?.getAttribute("src")||""}function De(n){let{el:e,log:t}=n,r=Te(e,"gl-scrub",be),o=(e.getAttribute("data-gl-scrub")||"").trim().toLowerCase(),i=Q(r.start,be.start),a=Q(r.end,be.end),s=n.media instanceof HTMLVideoElement?n.media:null,f=n.tier!=="high"&&!!r.srcMobile,l=gt(s,f?r.srcMobile:r.src),M=(f?r.srcMobile:r.src)||"",E=n.options,w=null,U=()=>w||(w=n.frames,w.budget=(r.cache>0?r.cache:E.cacheMB||ht[n.tier])*2**20,w),F=String(r.source||"auto").toLowerCase(),m;F==="decoder"||F==="video"||F==="frames"?m=[F]:(m=[],l&&Oe()&&m.push("decoder"),s&&l&&m.push("video"),r.frames&&m.push("frames"));let x=new Map,g=d=>{let p=x.get(d);if(p){for(let y of[...p])if(p.has(y))try{y(B)}catch(R){t.error(`a scrub "${d}" handler threw:`,R)}}},T="loading",P=0,S=null,b=null,H=!1,k=!1,A=o==="manual",_=0,h=0,c=0,u=0,v=0,C=0,$=!0,se=!0,q=()=>{},Ie=new Promise(d=>q=d),ge=Le(),O=null,ye=[],oe=0,ve=()=>ye.every(d=>U().has(d));function ze(d){ye=d,!(O||oe>=pt)&&ge.wait(new Promise(p=>{let y=O=R=>{O===y&&(O=null,R&&oe++,p())};ve()&&pe().then(()=>y()),Be(mt).then(()=>y(!0))}))}let ie=bt(e,r.track);r.track&&!ie&&r.track.trim()!=="self"&&t.warn(`data-gl-scrub-track="${r.track}": no such element; the video's own position drives it.`,e);let we=n.engine,D=ie&&we.track?we.track(ie):null,I=null;function ae(d){!s||d===(I!==null)||(d?(I=s.autoplay,s.autoplay=!1,s.pause()):(s.autoplay=I,I&&s.isConnected&&s.play().catch(()=>{}),I=null))}function ue(d){ae(!1),T="poster",S?.destroy(),S=null,b=null,n.busy(!1),n.fail(d),q(!1),O?.(),g("tier")}let ce={get frames(){return U()},log:t,maxTexture:n.maxTexture,ready(d){k||(T==="decoder"&&(P=d.fps),b&&b.frames!==d.frames&&(c=Math.min(c,d.frames-1)),b=d,$=!0,n.wake())},delivered(){k||(se&&(se=!1,q(!0),g("ready")),O&&ve()&&pe().then(()=>O?.()),n.wake())},failed(d,p){if(k)return;let y=p?new URL(l,location.href).href:"";if(p&&(d=`the video ${y} ${d}. Encode it with: npm run scrub -- input.mov`),p&&m.length&&!Ve.has(y)){Ve.add(y);let R=m[0]==="video"?"by seeking the <video>, which is choppier":"from its image sequence";t.warn(`scrub: ${d.replace(/\. Encode/,`, so it scrubs ${R}. Encode`)}`,e)}else t.info(`scrub: ${T} tier failed (${d})`,e);w?.clear(),b=null,S=null,O?.(),le(d)}};function le(d){let p=m.shift();if(!p)return g("error"),ue(`scrub: ${d||"nothing to scrub (no video src and no data-gl-scrub-frames)"}; the <video> and its poster show instead.`);if(T=p,ae(!0),p==="decoder"){let y=new J(new URL(l,location.href).href,ce);S=y,y.start()}else if(p==="video"){if(!s)return le('data-gl-scrub-source="video" needs a <video>');let y=new ee(s,ce,r.fps>0?r.fps:P||30,M);S=y,y.start()}else{let y=new te(r.frames,Math.round(r.count),r.fps>0?r.fps:30,ce);S=y,y.start()}g("tier")}function Ne(){return n.reducedMotion?0:r.smooth>=0?r.smooth:n.scrollKind==="lenis"||n.engine.scroll||document.documentElement.classList.contains("lenis")?0:ft}let B={get progress(){return h},set progress(d){A=!0,_=Math.min(1,Math.max(0,Number(d)||0)),n.wake()},get drive(){return A?"manual":"scroll"},set drive(d){A=d==="manual",A&&(_=h),n.wake()},get time(){return b?c/b.fps:0},set time(d){b&&(B.progress=d*b.fps/Math.max(1,b.frames-1))},get frame(){return c},get frames(){return b?.frames||0},get fps(){return b?.fps||0},get duration(){return b?b.frames/b.fps:0},get tier(){return T},ready:Ie,on(d,p){return x.has(d)||x.set(d,new Set),x.get(d).add(p),()=>B.off(d,p)},off(d,p){x.get(d)?.delete(p)},destroy(){n.plane.destroy()}},Me={uniforms:$e.uniforms},We=String(r.reduced||E.reducedMotion||"poster").toLowerCase();return n.reducedMotion&&We!=="scrub"?(ue(),{api:B,source:!0,effect:Me}):m.length?{api:B,source:!0,effect:$e,near(d){if(!(k||T==="poster")){if(d&&($=!0),!H&&d){H=!0,le();return}S?.active(d),d||w?.clear(!0)}},update(d,p,y){if(!b||!S||k)return!1;if(A)h=_;else{let L=D?D.rect.y:p[1],Se=D?D.rect.height:p[3];if(!(Se>0))return!1;h=fe(L,Se,y.height,i,a)}let R=b.frames;u=h*(R-1);let de=c;c=$?u:Ue(c,u,Ne(),d.dt),$=!1,Math.abs(u-c)<.01&&(c=u),v=d.dt>0?(c-de)/Math.max(1,R-1)/d.dt:0,C=Math.sign(u-c)||Math.sign(c-de)||C,n.busy(c!==u);let z=U();z.focus(Math.round(c)),S.request(c,C);let X=Ce(c,R,L=>z.ready(L),()=>z.keys(),r.blend!==!1);if(X&&z.show(X.a,X.b,X.mix),ge&&p[1]<y.height&&p[1]+p[3]>0&&p[0]<y.width&&p[0]+p[2]>0){let L=[Math.round(Math.max(0,Math.min(R-1,c)))];z.ready(L[0])?oe=0:ze(L)}let N=n.plane.uniforms;N.uScrubProgress&&(N.uScrubProgress.value=c/Math.max(1,R-1));let he=c!==de;if(N.uScrubVelocity){let L=he?v:0;he||=N.uScrubVelocity.value!==L,N.uScrubVelocity.value=L}return he},lost(){$=!0},src:()=>!M,restored(){S?.reset(),n.wake()},destroy(){k=!0,S?.destroy(),S=null,ae(!1),D?.destroy(),x.clear(),O?.(),se&&q(!1)}}:(ue(`scrub: nothing to scrub here (${s?"the <video> has no src":"no <video> inside"} and no data-gl-scrub-frames); it shows as plain DOM.`),{api:B,source:!0,effect:Me})}var re={name:"scrub",version:"0.2.0",attributes:["scrub"],plane:n=>De(n)};var ne=window;ne.Umber?.use?ne.Umber.use(re):((ne.UmberModules||=[]).push(re),ne.__umber?.engine?.use?.(re));})();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*! Umber v0.2.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
function Ne(n){let e=n.trim().toLowerCase();if(e===""||e==="true"||e==="1"||e==="yes")return!0;if(e==="false"||e==="0"||e==="no")return!1}function Me(n,e){let t=n.trim();if(e==="number"){let r=parseFloat(t);return Number.isFinite(r)?r:void 0}return e==="boolean"?Ne(t):e==="list"?t.split(/[\s,]+/).filter(Boolean):t.replace(/^["']|["']$/g,"")}function We(n){return n.type?n.type:typeof n.default=="number"?"number":typeof n.default=="boolean"?"boolean":Array.isArray(n.default)?"list":"string"}var Se=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);function xe(n,e,t,r){if(typeof e=="string"){let o=e.replace(/^data-/,""),i=t||{},a={};for(let s in i)a[s]={attr:`data-${o}-${Se(s)}`,css:`--${o}-${Se(s)}`,default:i[s]};return Ee(n,a,r)}return Ee(n,e,t)}function Ee(n,e,t){let r={},o=t;for(let i in e){let a=e[i],s=We(a),f;if(a.attr){let l=n.getAttribute(a.attr);l!==null&&(f=Me(l,s))}if(f===void 0&&a.css){o||=getComputedStyle(n);let l=o.getPropertyValue(a.css);l&&l.trim()!==""&&(f=Me(l,s))}r[i]=f===void 0?a.default:f}return r}var ke={top:0,left:0,center:.5,middle:.5,bottom:1,right:1};function qe(n){let e=/^(top|left|center|middle|bottom|right|-?\d*\.?\d+(?:px|%)?)?(?:([+-])=?(\d*\.?\d+)(px|%)?)?$/.exec(n);if(!e||!e[1]&&!e[2])return null;let t=0,r=0;if(e[1]&&e[1]in ke)t=ke[e[1]];else if(e[1]){let o=parseFloat(e[1]);e[1].endsWith("%")?t=o/100:r=o}if(e[2]){let o=parseFloat(e[3])*(e[2]==="-"?-1:1);e[4]==="%"?t+=o/100:r+=o}return[t,r]}function K(n,e){let t=(n||"").trim().toLowerCase();if(!t)return e;let r=qe(t);return r?/^[+-]/.test(t)&&!/^-\d/.test(t)?[e[0]+r[0],e[1]+r[1]]:r:e}var Xe={cover:"0110",contain:"11000011",entry:"01110100",exit:"00101110","entry-crossing":"0111","exit-crossing":"0010"};function Ke(n,e){let t=Xe[n[0]],r=n[1]||(e?"100%":"0%"),o=r.endsWith("%")?0:parseFloat(r)||0,i=o?0:parseFloat(r)/100||0,a=s=>({el:+t[s]+(+t[s+2]-+t[s])*i,elPx:o,vp:+t[s+1]+(+t[s+3]-+t[s+1])*i,vpPx:0});return t?{...a(0),alt:t[4]?a(4):void 0}:null}function Q(n,e){let t=(n||e).trim().split(/\s+/),r=Ke(t.map(l=>l.toLowerCase()),e.startsWith("bottom"));if(r)return r;let o=e.split(/\s+/),[i,a]=K(t[0],K(o[0],[0,0])),[s,f]=K(t[1],K(o[1],[0,0]));return{el:i,elPx:a,vp:s,vpPx:f}}function de(n,e,t,r,o){let i=l=>(l.alt&&e>t&&(l=l.alt),n+e*l.el+l.elPx-(t*l.vp+l.vpPx)),a=i(r),s=i(o),f=a-s;return Math.abs(f)>1e-6?Math.min(1,Math.max(0,a/f)):a<=0?1:0}function Te(n,e,t,r){return!(t>0)||!(r>0)?e:n+(e-n)*(1-Math.exp(-r/t))}function Ae(n,e,t,r,o){if(e<=0)return null;let i=Math.max(0,Math.min(e-1,n)),a=Math.floor(i),s=i-a;if(o&&s>.001&&a+1<e&&t(a)&&t(a+1))return{a,b:a+1,mix:s};let f=Math.round(i);if(t(f))return{a:f,b:-1,mix:0};let l=-1;for(let M of r())(l<0||Math.abs(M-i)<Math.abs(l-i))&&(l=M);return l<0?null:{a:l,b:-1,mix:0}}function Ue(n,e){return n.replace(/\{(\d+)\}/,(t,r)=>String(parseInt(r,10)+e).padStart(r.length,"0"))}var Ce=(n,e)=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]);function W(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function G(n,e,t=n.length){if(e+8>t)return null;let r=W(n),o=r.getUint32(e),i=Ce(n,e+4),a=e+8;if(o===1){if(e+16>t)return null;o=r.getUint32(e+8)*2**32+r.getUint32(e+12),a=e+16}else o===0&&(o=1/0);return o<a-e?null:{type:i,start:e,body:a,end:e+o}}function he(n,e,t){let r=[],o=e;for(;o<t;){let i=G(n,o,t);if(!i||i.end>t||i.end<=o)break;r.push(i),o=i.end}return r}var V=(n,e,t)=>he(n,e.body,e.end).find(r=>r.type===t)||null;function Y(n,e,...t){for(let r of t){if(!e)return null;e=V(n,e,r)}return e}function Qe(n){let e=t=>t.toString(16).padStart(2,"0");return`avc1.${e(n[1])}${e(n[2])}${e(n[3])}`}function Fe(n,e){let t=V(n,e,"mvhd"),r=t?W(n).getUint32(t.body+(n[t.body]===1?20:12)):0;for(let o of he(n,e.body,e.end)){if(o.type!=="trak")continue;let i=Y(n,o,"mdia","hdlr");if(!i||Ce(n,i.body+8)!=="vide")continue;let a=Ye(n,o,r);if(a)return V(n,e,"mvex")&&(a.fragmented=!0),a}return null}function Ye(n,e,t){let r=W(n),o=Y(n,e,"mdia","mdhd"),i=Y(n,e,"mdia","minf","stbl");if(!o||!i)return null;let a=n[o.body]===1,s=r.getUint32(o.body+(a?20:12))||1,f=V(n,i,"stsd");if(!f)return null;let l=G(n,f.body+8,f.end);if(!l)return null;let M=l.type,E=r.getUint16(l.body+24),w=r.getUint16(l.body+26),U="",F=null,m=he(n,l.body+78,l.end).find(u=>u.type==="avcC");m&&(M==="avc1"||M==="avc3")&&(F=n.slice(m.body,m.end),U=Qe(F));let x=V(n,e,"tkhd");if(x){let u=x.body+(n[x.body]===1?88:76);if(u+8<=x.end){let v=r.getUint32(u)/65536,C=r.getUint32(u+4)/65536;v&&C&&(E=Math.round(v),w=Math.round(C))}}let b=Ze(n,i);if(!b)return null;let T=b.length,P=Ge(n,e,s,t||s),S=P==="cuts"?null:P,g=b.map((u,v)=>v).filter(u=>!S||b[u].cts+b[u].duration/2>=S[0]&&b[u].cts+b[u].duration/2<S[1]).sort((u,v)=>b[u].cts-b[v].cts||u-v),H=new Array(T),k=0,A=1;for(let u=0;u<T;u++)b[u].key&&(u&&(A=Math.max(A,u-k)),k=u),H[u]=k;T&&(A=Math.max(A,T-k));let O=g.length?b[g[g.length-1]]:null,c=(O?O.cts+O.duration-b[g[0]].cts:0)/s;return{codec:U,format:M,description:F,width:E,height:w,timescale:s,duration:c,fps:c>0?g.length/c:30,samples:b,order:g,keyOf:H,gop:A,cuts:P==="cuts"}}function Ge(n,e,t,r){let o=Y(n,e,"edts","elst");if(!o)return null;let i=W(n),a=n[o.body]===1,s=a?20:12,f=i.getUint32(o.body+4),l=null;for(let M=0;M<f;M++){let E=o.body+8+M*s;if(E+s>o.end)break;let w=a?i.getUint32(E)*2**32+i.getUint32(E+4):i.getUint32(E),U=a?i.getInt32(E+8)*2**32+i.getUint32(E+12):i.getInt32(E+4);if(!(U<0)){if(l)return"cuts";l=[U,w?U+w*t/r:1/0]}}return l}function Ze(n,e){let t=W(n),r=h=>V(n,e,h),o=[],i=r("stsz"),a=r("stz2");if(i){let h=t.getUint32(i.body+4),c=t.getUint32(i.body+8);o=new Array(c);for(let u=0;u<c;u++)o[u]=h||t.getUint32(i.body+12+u*4)}else if(a){let h=n[a.body+7],c=t.getUint32(a.body+8);o=new Array(c);for(let u=0;u<c;u++){let v=a.body+12;h===16?o[u]=t.getUint16(v+u*2):h===8?o[u]=n[v+u]:o[u]=n[v+(u>>1)]>>(u&1?0:4)&15}}else return null;let s=o.length,f=r("stco"),l=r("co64"),M=[];if(f){let h=t.getUint32(f.body+4);for(let c=0;c<h;c++)M.push(t.getUint32(f.body+8+c*4))}else if(l){let h=t.getUint32(l.body+4);for(let c=0;c<h;c++)M.push(t.getUint32(l.body+8+c*8)*2**32+t.getUint32(l.body+12+c*8))}else return null;let E=r("stsc");if(!E)return null;let w=[],U=t.getUint32(E.body+4);for(let h=0;h<U;h++){let c=E.body+8+h*12;w.push({first:t.getUint32(c)-1,per:t.getUint32(c+4)})}let F=new Array(s),m=0;for(let h=0;h<w.length&&m<s;h++){let c=h+1<w.length?w[h+1].first:M.length;for(let u=w[h].first;u<c&&m<s;u++){let v=M[u];for(let C=0;C<w[h].per&&m<s;C++)F[m]=v,v+=o[m],m++}}if(m<s)return null;let x=r("stts");if(!x)return null;let b=new Array(s),T=new Array(s),P=0;m=0;let S=t.getUint32(x.body+4);for(let h=0;h<S&&m<s;h++){let c=t.getUint32(x.body+8+h*8),u=t.getUint32(x.body+12+h*8);for(let v=0;v<c&&m<s;v++)b[m]=P,T[m]=u,P+=u,m++}for(;m<s;m++)b[m]=P,T[m]=0;let g=b.slice(),H=r("ctts");if(H){let h=t.getUint32(H.body+4);m=0;for(let c=0;c<h&&m<s;c++){let u=t.getUint32(H.body+8+c*8),v=t.getInt32(H.body+12+c*8);for(let C=0;C<u&&m<s;C++)g[m++]+=v}}let k=r("stss"),A=new Array(s).fill(!k);if(k){let h=t.getUint32(k.body+4);for(let c=0;c<h;c++){let u=t.getUint32(k.body+8+c*4)-1;u>=0&&u<s&&(A[u]=!0)}}s&&(A[0]=!0);let O=new Array(s);for(let h=0;h<s;h++)O[h]={offset:F[h],size:o[h],dts:b[h],cts:g[h],duration:T[h],key:A[h]};return O}var Z=class{constructor(){this.bytes=new Uint8Array(0);this.loaded=0;this.total=0;this.done=!1;this.track=null;this.late=!1;this.onTrack=null;this.onData=null;this.onError=null;this.cursor=0;this.sawMdat=!1;this.abort=null}start(e){this.abort=typeof AbortController<"u"?new AbortController:null,this.run(e).catch(t=>{this.abort?.signal.aborted||this.onError?.(t)})}async run(e){let t=await fetch(e,{mode:"cors",credentials:"omit",signal:this.abort?.signal});if(!t.ok)throw new Error(`HTTP ${t.status}`);let r=Number(t.headers.get("content-length"))||0;r&&!t.headers.get("content-encoding")&&(this.total=r);let o=t.body?.getReader?.();if(!o){this.push(new Uint8Array(await t.arrayBuffer())),this.finish();return}for(;;){let{done:i,value:a}=await o.read();if(i)break;a?.length&&this.push(a)}this.finish()}push(e){let t=this.loaded+e.length;if(t>this.bytes.length){let r=new Uint8Array(Math.max(t,this.total,this.bytes.length*2,1048576));r.set(this.bytes.subarray(0,this.loaded)),this.bytes=r}this.bytes.set(e,this.loaded),this.loaded=t,this.scan(),this.onData?.()}finish(){this.done=!0,this.scan(),this.track||this.onError?.(new Error("no H.264 video track found (is it an MP4?)")),this.onData?.()}scan(){for(;!this.track;){let e=G(this.bytes,this.cursor,this.loaded);if(!e)return;if(e.type==="moov"){if(e.end>this.loaded)return;this.late=this.sawMdat;let t=Fe(this.bytes,e);if(!t){this.onError?.(new Error("the MP4 has no video track"));return}this.track=t,this.onTrack?.(t);return}if(e.type==="mdat"&&(this.sawMdat=!0),!Number.isFinite(e.end))return;this.cursor=e.end}}has(e){return e.offset+e.size<=this.loaded}data(e){return this.bytes.subarray(e.offset,e.offset+e.size)}stop(){this.abort?.abort(),this.onTrack=this.onData=this.onError=null}};var j=class{constructor(e,t){this.track=e;this.host=t;this.target=-1;this.dir=0;this.busy=null;this.fetched=new Set;this.present=new Array(e.order.length),e.order.forEach((r,o)=>this.present[r]=o)}get frames(){return this.track.order.length}want(e,t=0){let r=this.frames,o=r?Math.max(0,Math.min(r-1,Math.round(e))):-1;o!==this.target&&this.fetched.clear(),this.target=o,this.dir=t>0?1:t<0?-1:0}next(){if(this.busy||this.target<0)return null;let e=this.reachable(this.target);if(e<0)return null;let t=this.host.has(e)?this.ahead(e):e;if(t<0)return null;t!==e&&this.fetched.add(t);let r=this.track.order[t],o=this.track.keyOf[r],i=Math.max(1,Math.floor(this.host.window()/2)),a=new Set([t]);for(let s=o;s<r;s++){let f=this.present[s];Math.abs(f-e)<=i&&!this.host.has(f)&&a.add(f)}return this.busy={from:o,to:r,goal:t,keep:a},this.busy}forget(){this.fetched.clear()}done(){this.busy=null}ready(e){let t=this.track.order[e];return t!==void 0&&this.host.available(t)&&this.host.available(this.track.keyOf[t])}reachable(e){if(this.ready(e))return e;let t=this.frames;for(let r=1;r<t;r++){if(e-r>=0&&this.ready(e-r))return e-r;if(e+r<t&&this.ready(e+r))return e+r}return-1}ahead(e){let t=this.frames,r=this.host.window(),o=Math.min(12,Math.max(1,Math.floor(r/2)-1),Math.floor((r-1)/2));for(let i=1;i<=o;i++)for(let a=0;a<(this.dir?1:2);a++){let s=e+i*(this.dir||1-2*a);if(!(s<0||s>=t)&&!this.host.has(s)&&!this.fetched.has(s)&&this.ready(s))return s}return-1}},je=25,Je=10;function et(n){if(!n.length)return 0;let e=n.slice().sort((t,r)=>t-r);return e[Math.min(e.length-1,Math.ceil(e.length*.95)-1)]}function Re(n){return n.length<Je?null:et(n)>je}var rt=3,Pe="umber:scrub-decode",nt=()=>typeof navigator<"u"&&/Android/i.test(navigator.userAgent||"");function st(){try{let n=localStorage.getItem(Pe);return n==="prefer-software"||n==="prefer-hardware"?n:null}catch{return null}}var ot={hvc1:"HEVC (hvc1)",hev1:"HEVC (hev1)",av01:"AV1",vp09:"VP9",vp08:"VP8"},He=()=>typeof globalThis.VideoDecoder=="function"&&typeof globalThis.EncodedVideoChunk=="function",J=class{constructor(e,t){this.url=e;this.host=t;this.tier="decoder";this.stream=new Z;this.track=null;this.schedule=null;this.decoder=null;this.config=null;this.made=null;this.accel="no-preference";this.byTime=new Map;this.running=!1;this.on=!0;this.dead=!1;this.errors=0;this.timings=[];this.keep=null;this.outputs=0}start(){let e=this.stream;e.onTrack=t=>this.configure(t),e.onData=()=>this.pump(),e.onError=t=>this.fail(`could not read the video (${t instanceof Error?t.message:t})`),e.start(this.url)}async configure(e){if(!e.codec||!e.description)return this.fail(`is ${ot[e.format]||e.format||"not H.264"}, and WebCodecs scrubbing reads H.264`,!0);if(e.fragmented&&!e.order.length)return this.fail("is a fragmented MP4 (its frames are indexed in fragments), which WebCodecs scrubbing doesn't read",!0);if(!e.order.length)return this.fail("has no frames in its index",!0);this.stream.late&&!this.stream.done&&this.host.log.warn('scrub video is not "faststart" (its index is at the end), so nothing shows until it fully downloads. Encode it with: npm run scrub -- input.mov'),e.cuts&&this.host.log.warn("scrub video has an edit list with several cuts, which the scrub does not follow: it shows every frame of the file. Re-encode it with: npm run scrub -- input.mov"),e.gop>10&&this.host.log.warn(`scrub video has a keyframe only every ${e.gop} frames: each step back decodes up to that many. For smooth scrubbing encode it with: npm run scrub -- input.mov`);let t=globalThis.VideoDecoder,r={codec:e.codec,codedWidth:e.width,codedHeight:e.height,description:e.description,optimizeForLatency:!0},o=nt()?st()||"prefer-hardware":"no-preference",i=o==="no-preference"?["no-preference"]:[o,"no-preference"];for(let s of i)try{let f=s==="no-preference"?r:{...r,hardwareAcceleration:s},l=await t.isConfigSupported(f);if(this.dead)return;if(l?.supported){this.config=f,this.accel=s;break}}catch{}if(!this.config)return this.fail(`this browser can't decode ${e.codec} with WebCodecs`);this.track=e,e.order.forEach((s,f)=>this.byTime.set(this.micros(e.samples[s].cts),f));let a=this.host.frames;this.schedule=new j(e,{has:s=>a.has(s),available:s=>this.stream.has(e.samples[s]),window:()=>Math.min(a.capacity(e.width,e.height),48)}),this.host.ready({frames:e.order.length,fps:e.fps,width:e.width,height:e.height}),this.pump()}micros(e){return Math.round(e/this.track.timescale*1e6)}request(e,t){this.schedule&&(this.schedule.want(e,t),this.pump())}active(e){this.on=e,e?(this.schedule?.forget(),this.pump()):this.close()}reset(){this.schedule?.forget(),this.pump()}decoderNow(){if(this.decoder&&this.decoder.state!=="closed"&&this.made===this.config)return this.decoder;this.close();let e=globalThis.VideoDecoder,t=new e({output:r=>this.output(r),error:r=>this.onError(t,r)});return t.configure(this.made=this.config),this.decoder=t,t}output(e){this.outputs++;let t=this.byTime.get(e.timestamp);if(t===void 0||this.dead||!this.keep?.has(t)||this.host.frames.ready(t)){e.close();return}this.host.frames.put(t,e,!0),this.host.delivered()}onError(e,t){e===this.decoder&&(this.decoder=null),t?.name!=="QuotaExceededError"&&this.host.log.info("scrub decoder error",t)}async pump(){if(this.running||this.dead||!this.on||!this.schedule||!this.track)return;let e=this.schedule.next();if(!e)return;this.running=!0;let t=this.track,r=performance.now(),o=this.errors,i=!0;try{let a=this.decoderNow();this.keep=e.keep,this.outputs=0;let s=globalThis.EncodedVideoChunk;for(let f=e.from;f<=e.to;f++){let l=t.samples[f];a.decode(new s({type:f===e.from||l.key?"key":"delta",timestamp:this.micros(l.cts),duration:this.micros(l.duration),data:this.stream.data(l)}))}await a.flush(),this.outputs===0&&(i=!1,this.errors++,this.close())}catch(a){i=!1,a?.name!=="QuotaExceededError"&&a?.name!=="AbortError"&&this.errors++,this.close()}if(this.running=!1,this.schedule?.done(),!this.dead){if(i)this.errors=0,this.time((performance.now()-r)/(e.to-e.from+1));else{if(this.errors>=rt)return this.fail("the video decoder keeps failing");this.errors>o&&this.schedule?.forget()}this.pump()}}time(e){if(this.accel!=="prefer-hardware"||(this.timings.push(e),this.timings.length===1))return;let t=Re(this.timings.slice(1));if(t===null)return;let r=t?"prefer-software":"prefer-hardware";try{localStorage.setItem(Pe,r)}catch{}if(this.accel="no-preference",!t)return;let o={...this.config,hardwareAcceleration:"prefer-software"};globalThis.VideoDecoder.isConfigSupported(o).then(i=>{!i?.supported||this.dead||(this.host.log.info("scrub: hardware decoding is slow at seeking here; using the software decoder"),this.config=o,this.accel="prefer-software",this.running||this.close())}).catch(()=>{})}close(){let e=this.decoder;if(this.decoder=null,e&&e.state!=="closed")try{e.close()}catch{}}fail(e,t){this.dead||(this.destroy(),this.host.failed(e,t))}destroy(){this.dead=!0,this.stream.stop(),this.close(),this.schedule=null}};var ee=class{constructor(e,t,r,o){this.video=e;this.host=t;this.fps=r;this.src=o;this.tier="video";this.frames=0;this.target=-1;this.seeking=-1;this.landed=-1;this.fastFor=-1;this.errors=0;this.on=!0;this.dead=!1;this.cors=!1;this.offs=[]}start(){let e=this.video;e.muted=!0,e.playsInline=!0,e.setAttribute("playsinline",""),e.setAttribute("webkit-playsinline",""),e.disableRemotePlayback=!0,e.pause();let t=e.currentSrc||e.getAttribute("src")||e.querySelector("source")?.getAttribute("src")||"",r=this.src||t,o=e.preload!=="auto";e.preload="auto";try{r&&new URL(r,location.href).origin!==location.origin&&!e.crossOrigin&&(e.crossOrigin="anonymous",this.cors=o=!0)}catch{}this.src&&this.src!==t&&(e.src=this.src,o=!0),this.listen("seeked",()=>this.onSeeked()),this.listen("error",a=>{let s=e.querySelectorAll("source");(a.target===e||a.target===s[s.length-1])&&this.fail(this.cors?"the video failed to load (another domain: no CORS headers?)":"the video failed to load")},!0),e.readyState>=1&&!o?this.onMeta():(this.listen("loadedmetadata",()=>this.onMeta()),this.meta()),o&&e.load();let i=()=>{this.dead||e.readyState>=2||e.play().then(()=>e.pause()).catch(()=>{})};addEventListener("touchstart",i,{once:!0,passive:!0}),this.offs.push(()=>removeEventListener("touchstart",i))}listen(e,t,r=!1){this.video.addEventListener(e,t,r),this.offs.push(()=>this.video.removeEventListener(e,t,r))}meta(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.frames||this.dead||(this.video.networkState===1?this.meta():this.fail("the video's metadata never loaded"))},1e4)}onMeta(){if(this.frames||this.dead)return;let e=this.video;if(!Number.isFinite(e.duration)||e.duration<=0)return this.fail("the video has no duration (a live stream?)");this.frames=Math.max(1,Math.round(e.duration*this.fps)),this.host.ready({frames:this.frames,fps:this.fps,width:e.videoWidth,height:e.videoHeight}),this.pump()}request(e){this.frames&&(this.target=Math.max(0,Math.min(this.frames-1,Math.round(e))),this.pump())}active(e){this.on=e,this.pump()}reset(){this.seeking=-1,this.landed=-1,this.pump()}pump(){if(this.dead||!this.on||this.target<0)return;if(this.seeking>=0){let i=this.host.frames;if(this.landed>=0&&(i.ready(this.landed)||!i.has(this.landed)))this.seeking=-1,this.landed=-1;else return}let e=this.target;if(this.host.frames.has(e))return;let t=this.video;if(t.readyState<1)return;this.seeking=e,this.landed=-1;let r=Math.min((e+.5)/this.fps,Math.max(0,t.duration-.001)),o=Math.round(t.currentTime*this.fps-.5);typeof t.fastSeek=="function"&&Math.abs(e-o)>6&&e!==this.fastFor?(this.fastFor=e,t.fastSeek(r)):t.currentTime=r,clearTimeout(this.timer),this.timer=setTimeout(()=>{this.seeking<0||this.landed>=0||(this.seeking=-1,++this.errors>=3?this.fail("seeking the video never lands"):this.pump())},4e3)}onSeeked(){if(this.dead||this.seeking<0)return;clearTimeout(this.timer),this.errors=0;let e=this.video,t=Math.max(0,Math.min(this.frames-1,Math.floor(e.currentTime*this.fps+.001)));this.landed=t,this.host.frames.put(t,e,!1),this.host.delivered()}fail(e){this.dead||(this.destroy(),this.cors&&(this.video.removeAttribute("crossorigin"),this.video.load()),this.host.failed(e))}destroy(){this.dead=!0,clearTimeout(this.timer),this.offs.forEach(e=>e()),this.offs=[]}};var it=4,at=8,ut=2,ct=4,te=class{constructor(e,t,r,o){this.pattern=e;this.count=t;this.fps=r;this.host=o;this.tier="frames";this.target=-1;this.dir=0;this.loading=new Set;this.failedFrames=new Set;this.errors=0;this.known=!1;this.width=0;this.height=0;this.on=!0;this.dead=!1;this.abort=typeof AbortController<"u"?new AbortController:null}start(){if(!(this.count>0))return this.fail('data-gl-scrub-frames needs data-gl-scrub-count="<number of frames>"');this.load(0)}request(e,t){this.target=Math.max(0,Math.min(this.count-1,Math.round(e))),this.dir=t>0?1:t<0?-1:0,this.pump()}active(e){this.on=e,this.pump()}reset(){this.pump()}pump(){if(this.dead||!this.on||!this.known||this.target<0)return;let e=this.host.frames,t=this.dir>=0?1:-1,r=e.capacity(this.width,this.height)-1,o=Math.min(ut,r>>2),i=Math.min(at,r-o);for(let a=0;a<=Math.max(0,i+o)&&this.loading.size<it;a++){let s=this.target+(a<=i?a:i-a)*t;s<0||s>=this.count||e.has(s)||this.loading.has(s)||this.failedFrames.has(s)||this.load(s)}}async load(e){this.loading.add(e);let t=Ue(this.pattern,e);try{let r=await fetch(t,{mode:"cors",credentials:"omit",signal:this.abort?.signal});if(!r.ok)throw new Error(`HTTP ${r.status}`);let o=await r.blob(),i=await createImageBitmap(o,{premultiplyAlpha:"none",colorSpaceConversion:"default"}),a=this.host.maxTexture;if(i.width>a||i.height>a){let s=a/Math.max(i.width,i.height),f=await createImageBitmap(i,{resizeWidth:Math.floor(i.width*s),resizeHeight:Math.floor(i.height*s),resizeQuality:"high"});i.close(),i=f}if(this.loading.delete(e),this.dead)return i.close();this.errors=0,this.known||(this.known=!0,this.width=i.width,this.height=i.height,this.host.ready({frames:this.count,fps:this.fps,width:i.width,height:i.height})),this.host.frames.put(e,i,!0),this.host.delivered()}catch(r){if(this.loading.delete(e),this.dead)return;if(this.failedFrames.add(e),this.host.log.warn(`scrub frame ${t} failed to load`,r),!this.known||++this.errors>=ct)return this.fail(`the image sequence ${this.pattern} does not load`)}this.pump()}fail(e){this.dead||(this.destroy(),this.host.failed(e))}destroy(){this.dead=!0,this.abort?.abort()}};var Oe=()=>{let n=typeof globalThis<"u"&&globalThis.occluzeCapture;return n?.version==1?n:null},fe=()=>new Promise(n=>{let e=new MessageChannel;e.port1.onmessage=n,e.port2.postMessage(0)});var Le=n=>new Promise(e=>{let t=AbortSignal.timeout?.(n);t?t.onabort=()=>e():setTimeout(e,n)});var lt={high:128,mid:48,low:32},_e=new Set,dt=.12,ht=250,ft=20,me={start:"top bottom",end:"bottom top",track:"",smooth:-1,source:"auto",src:"",srcMobile:"",frames:"",count:0,fps:0,blend:!0,cache:0,reduced:""},Be={uniforms:{uScrubProgress:0,uScrubVelocity:0},fragment:{head:`uniform sampler2D uFrameNext;
|
|
3
|
+
uniform float uFrameMix;
|
|
4
|
+
vec4 scrubNext(vec2 uv) {
|
|
5
|
+
vec2 f = fitUv(uv);
|
|
6
|
+
if (uFit > 0.5 && uFit < 1.5 && (f.x < 0.0 || f.y < 0.0 || f.x > 1.0 || f.y > 1.0)) return vec4(0.0);
|
|
7
|
+
return texture(uFrameNext, f);
|
|
8
|
+
}`,color:"if (uFrameMix > 0.0) color = mix(color, scrubNext(uv), uFrameMix);"}};function mt(n,e){let t=e.trim();if(!t||t==="self")return null;if(t==="parent")return n.parentElement;try{return t.startsWith("closest ")?n.closest(t.slice(8).trim()):n.closest(t)||document.querySelector(t)}catch{return null}}function pt(n,e){return e||n?.currentSrc||n?.getAttribute("src")||n?.querySelector("source")?.getAttribute("src")||""}function Ve(n){let{el:e,log:t}=n,r=xe(e,"gl-scrub",me),o=(e.getAttribute("data-gl-scrub")||"").trim().toLowerCase(),i=Q(r.start,me.start),a=Q(r.end,me.end),s=n.media instanceof HTMLVideoElement?n.media:null,f=n.tier!=="high"&&!!r.srcMobile,l=pt(s,f?r.srcMobile:r.src),M=(f?r.srcMobile:r.src)||"",E=n.options,w=null,U=()=>w||(w=n.frames,w.budget=(r.cache>0?r.cache:E.cacheMB||lt[n.tier])*2**20,w),F=String(r.source||"auto").toLowerCase(),m;F==="decoder"||F==="video"||F==="frames"?m=[F]:(m=[],l&&He()&&m.push("decoder"),s&&l&&m.push("video"),r.frames&&m.push("frames"));let x=new Map,b=d=>{let p=x.get(d);if(p){for(let y of[...p])if(p.has(y))try{y(B)}catch(R){t.error(`a scrub "${d}" handler threw:`,R)}}},T="loading",P=0,S=null,g=null,H=!1,k=!1,A=o==="manual",O=0,h=0,c=0,u=0,v=0,C=0,$=!0,re=!0,q=()=>{},$e=new Promise(d=>q=d),pe=Oe(),L=null,ge=[],ne=0,be=()=>ge.every(d=>U().has(d));function De(d){ge=d,!(L||ne>=ft)&&pe.wait(new Promise(p=>{let y=L=R=>{L===y&&(L=null,R&&ne++,p())};be()&&fe().then(()=>y()),Le(ht).then(()=>y(!0))}))}let se=mt(e,r.track);r.track&&!se&&r.track.trim()!=="self"&&t.warn(`data-gl-scrub-track="${r.track}": no such element; the video's own position drives it.`,e);let ye=n.engine,D=se&&ye.track?ye.track(se):null,I=null;function oe(d){!s||d===(I!==null)||(d?(I=s.autoplay,s.autoplay=!1,s.pause()):(s.autoplay=I,I&&s.isConnected&&s.play().catch(()=>{}),I=null))}function ie(d){oe(!1),T="poster",S?.destroy(),S=null,g=null,n.busy(!1),n.fail(d),q(!1),L?.(),b("tier")}let ae={get frames(){return U()},log:t,maxTexture:n.maxTexture,ready(d){k||(T==="decoder"&&(P=d.fps),g&&g.frames!==d.frames&&(c=Math.min(c,d.frames-1)),g=d,$=!0,n.wake())},delivered(){k||(re&&(re=!1,q(!0),b("ready")),L&&be()&&fe().then(()=>L?.()),n.wake())},failed(d,p){if(k)return;let y=p?new URL(l,location.href).href:"";if(p&&(d=`the video ${y} ${d}. Encode it with: npm run scrub -- input.mov`),p&&m.length&&!_e.has(y)){_e.add(y);let R=m[0]==="video"?"by seeking the <video>, which is choppier":"from its image sequence";t.warn(`scrub: ${d.replace(/\. Encode/,`, so it scrubs ${R}. Encode`)}`,e)}else t.info(`scrub: ${T} tier failed (${d})`,e);w?.clear(),g=null,S=null,L?.(),ue(d)}};function ue(d){let p=m.shift();if(!p)return b("error"),ie(`scrub: ${d||"nothing to scrub (no video src and no data-gl-scrub-frames)"}; the <video> and its poster show instead.`);if(T=p,oe(!0),p==="decoder"){let y=new J(new URL(l,location.href).href,ae);S=y,y.start()}else if(p==="video"){if(!s)return ue('data-gl-scrub-source="video" needs a <video>');let y=new ee(s,ae,r.fps>0?r.fps:P||30,M);S=y,y.start()}else{let y=new te(r.frames,Math.round(r.count),r.fps>0?r.fps:30,ae);S=y,y.start()}b("tier")}function Ie(){return n.reducedMotion?0:r.smooth>=0?r.smooth:n.scrollKind==="lenis"||n.engine.scroll||document.documentElement.classList.contains("lenis")?0:dt}let B={get progress(){return h},set progress(d){A=!0,O=Math.min(1,Math.max(0,Number(d)||0)),n.wake()},get drive(){return A?"manual":"scroll"},set drive(d){A=d==="manual",A&&(O=h),n.wake()},get time(){return g?c/g.fps:0},set time(d){g&&(B.progress=d*g.fps/Math.max(1,g.frames-1))},get frame(){return c},get frames(){return g?.frames||0},get fps(){return g?.fps||0},get duration(){return g?g.frames/g.fps:0},get tier(){return T},ready:$e,on(d,p){return x.has(d)||x.set(d,new Set),x.get(d).add(p),()=>B.off(d,p)},off(d,p){x.get(d)?.delete(p)},destroy(){n.plane.destroy()}},ve={uniforms:Be.uniforms},ze=String(r.reduced||E.reducedMotion||"poster").toLowerCase();return n.reducedMotion&&ze!=="scrub"?(ie(),{api:B,source:!0,effect:ve}):m.length?{api:B,source:!0,effect:Be,near(d){if(!(k||T==="poster")){if(d&&($=!0),!H&&d){H=!0,ue();return}S?.active(d),d||w?.clear(!0)}},update(d,p,y){if(!g||!S||k)return!1;if(A)h=O;else{let _=D?D.rect.y:p[1],we=D?D.rect.height:p[3];if(!(we>0))return!1;h=de(_,we,y.height,i,a)}let R=g.frames;u=h*(R-1);let ce=c;c=$?u:Te(c,u,Ie(),d.dt),$=!1,Math.abs(u-c)<.01&&(c=u),v=d.dt>0?(c-ce)/Math.max(1,R-1)/d.dt:0,C=Math.sign(u-c)||Math.sign(c-ce)||C,n.busy(c!==u);let z=U();z.focus(Math.round(c)),S.request(c,C);let X=Ae(c,R,_=>z.ready(_),()=>z.keys(),r.blend!==!1);if(X&&z.show(X.a,X.b,X.mix),pe&&p[1]<y.height&&p[1]+p[3]>0&&p[0]<y.width&&p[0]+p[2]>0){let _=[Math.round(Math.max(0,Math.min(R-1,c)))];z.ready(_[0])?ne=0:De(_)}let N=n.plane.uniforms;N.uScrubProgress&&(N.uScrubProgress.value=c/Math.max(1,R-1));let le=c!==ce;if(N.uScrubVelocity){let _=le?v:0;le||=N.uScrubVelocity.value!==_,N.uScrubVelocity.value=_}return le},lost(){$=!0},src:()=>!M,restored(){S?.reset(),n.wake()},destroy(){k=!0,S?.destroy(),S=null,oe(!1),D?.destroy(),x.clear(),L?.(),re&&q(!1)}}:(ie(`scrub: nothing to scrub here (${s?"the <video> has no src":"no <video> inside"} and no data-gl-scrub-frames); it shows as plain DOM.`),{api:B,source:!0,effect:ve})}var gt={name:"scrub",version:"0.2.0",attributes:["scrub"],plane:n=>Ve(n)},Dt=gt;export{gt as Scrub,Dt as default};
|
package/dist/umber.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.2.0 */
|
|
2
|
+
[data-gl-host]{position:fixed;top:0;left:0;right:0;height:100vh;height:100lvh;pointer-events:none}[data-gl-host]>canvas{position:absolute;inset:0;width:100%;height:100%;display:block}@media print{[data-gl-host]{display:none!important}}@media not print{.has-gl [data-gl]:not([data-gl=group])[data-gl-status=ready] [data-gl-media],.has-gl [data-gl][data-gl-status=ready][data-gl-media]{opacity:0!important}.has-gl [data-gl=text][data-gl-status=ready],.has-gl [data-gl=text][data-gl-status=ready] *{-webkit-text-fill-color:transparent!important;text-shadow:none!important;text-decoration-color:transparent!important}.has-gl [data-gl=shader][data-gl-status=ready]{background:transparent!important}.has-gl [data-gl]:not([data-gl=group])[data-gl-status=loading][data-gl-play] [data-gl-media],.has-gl [data-gl][data-gl-status=loading][data-gl-play][data-gl-media]{opacity:0!important}.has-gl [data-gl=text][data-gl-status=loading][data-gl-play],.has-gl [data-gl=text][data-gl-status=loading][data-gl-play] *{-webkit-text-fill-color:transparent!important;text-shadow:none!important;text-decoration-color:transparent!important}.has-gl [data-gl][data-gl-morphing] [data-gl-media],.has-gl [data-gl][data-gl-morphing][data-gl-media]{opacity:0!important}.has-gl [data-gl=text][data-gl-morphing],.has-gl [data-gl=text][data-gl-morphing] *{-webkit-text-fill-color:transparent!important;text-shadow:none!important;text-decoration-color:transparent!important}.has-gl [data-gl=shader][data-gl-morphing]{background:transparent!important}}:where([data-gl-above]){position:relative;z-index:2}
|