@occluze/umber 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +93 -47
  2. package/THIRD-PARTY-NOTICES.md +33 -0
  3. package/dist/chunks/badge.js +2 -2
  4. package/dist/chunks/basis.js +2 -2
  5. package/dist/chunks/batches.js +2 -0
  6. package/dist/chunks/capture.js +2 -2
  7. package/dist/chunks/covers.js +2 -2
  8. package/dist/chunks/curves.js +2 -2
  9. package/dist/chunks/flip.js +2 -2
  10. package/dist/chunks/fx.js +2 -2
  11. package/dist/chunks/gl.js +2 -2
  12. package/dist/chunks/glsl.js +2 -2
  13. package/dist/chunks/glyphs.js +2 -0
  14. package/dist/chunks/inspect.js +2 -2
  15. package/dist/chunks/instances.js +2 -2
  16. package/dist/chunks/layers.js +2 -2
  17. package/dist/chunks/licence.js +2 -2
  18. package/dist/chunks/morph.js +2 -2
  19. package/dist/chunks/pace.js +2 -0
  20. package/dist/chunks/patch.js +2 -2
  21. package/dist/chunks/prepared.js +2 -2
  22. package/dist/chunks/profiler.js +2 -2
  23. package/dist/chunks/recheck.js +2 -0
  24. package/dist/chunks/resize.js +2 -0
  25. package/dist/chunks/restore.js +2 -2
  26. package/dist/chunks/shapes.js +2 -2
  27. package/dist/chunks/sim.js +2 -2
  28. package/dist/chunks/text.js +2 -2
  29. package/dist/chunks/video.js +2 -2
  30. package/dist/chunks/vocabulary.js +2 -2
  31. package/dist/chunks/warm.js +2 -2
  32. package/dist/modules/debug.js +2 -2
  33. package/dist/modules/debug.mjs +2 -2
  34. package/dist/modules/handoff.js +2 -2
  35. package/dist/modules/handoff.mjs +2 -2
  36. package/dist/modules/input.js +2 -2
  37. package/dist/modules/input.mjs +2 -2
  38. package/dist/modules/scrollfx.js +2 -2
  39. package/dist/modules/scrollfx.mjs +2 -2
  40. package/dist/modules/scrub.js +2 -2
  41. package/dist/modules/scrub.mjs +2 -2
  42. package/dist/modules/three.js +2 -2
  43. package/dist/modules/three.mjs +2 -2
  44. package/dist/node/assets.mjs +4 -2
  45. package/dist/node/astro.mjs +26 -18
  46. package/dist/node/cli.mjs +63 -10
  47. package/dist/node/shared-NFSQ5J4B.mjs +2116 -0
  48. package/dist/node/{shared-4FIU6DYP.mjs → shared-OUFNIXQ7.mjs} +106 -17
  49. package/dist/node/vite.mjs +7 -3
  50. package/dist/prepared.mjs +2 -0
  51. package/dist/umber.css +1 -1
  52. package/dist/umber.js +2 -2
  53. package/dist/umber.mjs +2 -2
  54. package/docs/AI-quick.md +43 -87
  55. package/docs/AI.md +1977 -1829
  56. package/docs/npm.md +13 -16
  57. package/package.json +32 -48
  58. package/types/assets.d.ts +109 -4
  59. package/types/astro.d.ts +20 -23
  60. package/types/debug.d.ts +1 -1
  61. package/types/esm.d.ts +2 -6
  62. package/types/input.d.ts +3 -3
  63. package/types/loop.d.ts +21 -9
  64. package/types/module.d.ts +0 -2
  65. package/types/scrollfx.d.ts +5 -41
  66. package/types/scrub.d.ts +2 -2
  67. package/types/three.d.ts +26 -1
  68. package/types/umber.d.ts +152 -155
  69. package/types/vite.d.ts +3 -3
  70. package/dist/chunks/views.js +0 -2
  71. package/dist/frameworks/astro.mjs +0 -2
  72. package/dist/frameworks/react.mjs +0 -2
  73. package/dist/frameworks/svelte.mjs +0 -2
  74. package/dist/frameworks/vue.mjs +0 -2
  75. package/dist/modules/router-swap.js +0 -2
  76. package/dist/modules/router.js +0 -2
  77. package/dist/modules/router.mjs +0 -2
  78. package/dist/modules/scroll-more.js +0 -2
  79. package/dist/modules/scroll-touch.js +0 -2
  80. package/dist/modules/scroll.js +0 -2
  81. package/dist/modules/scroll.mjs +0 -2
  82. package/dist/node/shared-3Q24RNIF.mjs +0 -602
  83. package/types/react.d.ts +0 -15
  84. package/types/router.d.ts +0 -223
  85. package/types/scroll.d.ts +0 -190
  86. package/types/svelte.d.ts +0 -16
  87. package/types/vue.d.ts +0 -14
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- var e={hash:{used:/\bumberHash\s*\(/,defined:/\bfloat\s+umberHash\s*\(/,code:`float umberHash(vec2 p){\np=fract(p*vec2(123.34,456.21));\np+=dot(p,p+45.32);\nreturn fract(p.x*p.y);\n}\nfloat umberHash(vec3 p){\np=fract(p*vec3(0.1031,0.1030,0.0973));\np+=dot(p,p.yxz+33.33);\nreturn fract((p.x+p.y)*p.z);\n}`},noise2:{used:/\bnoise\s*\(/,defined:/\bfloat\s+noise\s*\(\s*(?:in\s+)?vec2\b/,needs:["hash"],code:`float noise(vec2 p){\nvec2 i=floor(p);\nvec2 f=fract(p);\nvec2 k=f*f*(3.0-2.0*f);\nreturn mix(mix(umberHash(i),umberHash(i+vec2(1.0,0.0)),k.x),mix(umberHash(i+vec2(0.0,1.0)),umberHash(i+vec2(1.0,1.0)),k.x),k.y);\n}`},noise3:{used:/\bnoise\s*\(/,defined:/\bfloat\s+noise\s*\(\s*(?:in\s+)?vec3\b/,needs:["hash"],code:`float noise(vec3 p){\nvec3 i=floor(p);\nvec3 f=fract(p);\nvec3 k=f*f*(3.0-2.0*f);\nvec2 e=vec2(1.0,0.0);\nfloat a=mix(mix(umberHash(i),umberHash(i+e.xyy),k.x),mix(umberHash(i+e.yxy),umberHash(i+e.xxy),k.x),k.y);\nfloat b=mix(mix(umberHash(i+e.yyx),umberHash(i+e.xyx),k.x),mix(umberHash(i+e.yxx),umberHash(i+e.xxx),k.x),k.y);\nreturn mix(a,b,k.z);\n}`},fbm:{used:/\bfbm\s*\(/,defined:/\bfloat\s+fbm\s*\(\s*(?:in\s+)?vec2\b/,needs:["noise2"],code:`float fbm(vec2 p){\nfloat v=0.0;\nfloat a=0.5;\nfor(int i=0;i<4;i++){\nv+=a*noise(p);\np=p*2.03+17.0;\na*=0.5;\n}\nreturn v/0.9375;\n}`},screenPx:{used:/\bscreenPx\s*\(/,defined:/\bvec2\s+screenPx\s*\(/,code:`#ifdef UMBER_FRAGMENT\nvec2 screenPx(){\nreturn uSurface.xy+vec2(gl_FragCoord.x,uCanvas.y-gl_FragCoord.y)/uCanvas*uSurface.zw;\n}\n#endif`},screenUv:{used:/\bscreenUv\s*\(/,defined:/\bvec2\s+screenUv\s*\(/,needs:["screenPx"],code:`#ifdef UMBER_FRAGMENT\nvec2 screenUv(){\nreturn screenPx()/uViewport;\n}\n#endif`},screen:{used:/\buScreen\b/,defined:/(vec2|#define)\s+uScreen\b/,code:"#define uScreen ((uRect.xy + uRect.zw * 0.5) / uViewport * 2.0 - 1.0)"},samplePrev:{used:/\bsamplePrev\s*\(/,defined:/\bvec4\s+samplePrev\s*\(/,code:`vec4 samplePrev(vec2 uv){\nvec2 f=uv;\nif(uFit<1.5){\nvec2 ratio=uSize/max(uPrevSize,vec2(1.0));\nfloat s=uFit<0.5?max(ratio.x,ratio.y):min(ratio.x,ratio.y);\nvec2 scaled=uPrevSize*s;\nf=(uv*uSize-(uSize-scaled)*uFitPosition)/scaled;\n}\nvec4 c=texture(uPrev,f);\nif(uFit>0.5&&uFit<1.5&&(f.x<0.0||f.y<0.0||f.x>1.0||f.y>1.0))c=vec4(0.0);\nreturn vec4(c.rgb/max(c.a,1e-5),c.a);\n}`},rotate2d:{used:/\brotate2d\s*\(/,defined:/\bmat2\s+rotate2d\s*\(/,code:`mat2 rotate2d(float a){\nfloat c=cos(a);\nfloat s=sin(a);\nreturn mat2(c,s,-s,c);\n}`}};var n=()=>{};var t=()=>Promise.reject(new Error("no words"));var r={configure:n,debug:!1,warnings:!1,info:n,warn:n,error:n,report:n,words:t},o=r;function a(e){o=e}var c=/^[ \t]*#include[ \t]+["<]?([\w-]+)[">]?[ \t]*$/gm,i=new Set("if else for while do switch case default return break continue discard uniform in out inout const struct precision layout highp mediump lowp flat smooth centroid invariant".split(" "));function u({effects:e,shader:n,...t},r,{chunks:o,say:a}){let i=new Set,u=[],s=()=>({code:[],seen:new Set}),f=s(),x=s(),d=(e,n)=>e.replace(c,(e,t)=>{if(n.seen.has(t))return"";n.seen.add(t),i.add(t);let r=o.get(t);return r==null?u.includes(t)||u.push(t):n.code.push(`// chunk: ${t}\n${d(r,n)}`),""}),v=(e,n)=>{if(!e)return e;let t={};for(let r in e)typeof e[r]=="string"&&(t[r]=n(e[r]));return t},b=e.map(({name:e,def:n})=>({name:e,def:{...n,vertex:v(n.vertex,e=>d(e,f)),fragment:v(n.fragment,e=>d(e,x))}})),m=n&&{name:n.name,def:{...n.def,head:d(n.def.head??"",x),fragment:d(n.def.fragment,x)}},p=b.map(e=>({fx:e,own:l(`${e.def.vertex?.head??""}\n${e.def.fragment?.head??""}`)})),h=new Map;for(let e of[...p.map(({own:e})=>e),l(m?.def.head??"")])for(let n of e)h.set(n,(h.get(n)??0)+1);if(p.forEach(({fx:e,own:n},t)=>{let r=[...n].filter(e=>(h.get(e)??0)>1);if(!r.length)return;let o=new RegExp(`(^|[^.\\w])(${r.join("|")})\\b`,"g"),a=e=>e.replace(o,`$1e${t}_$2`);e.def={...e.def,vertex:v(e.def.vertex,a),fragment:v(e.def.fragment,a)}}),u.length){for(let e of u)r.missing.push(`chunk:${e}`),a("include",[e],r.el);return r.setStatus("error"),null}return{...t,effects:b,shader:m,chunks:{vertex:f.code.join(`\n\n`),fragment:x.code.join(`\n\n`)},included:[...i]}}function l(e){let n="",t=0;for(let r of e.replace(/\/\/.*|\/\*[\s\S]*?\*\//g,""))(r==="}"||r===")")&&t--,t||(n+=r),(r==="{"||r==="(")&&t++;n=n.replace(/\b(uniform|in|out|precision|layout)\b[^;]*;/g,"");let r=new Set;for(let e of n.matchAll(/#define\s+(\w+)|\b(\w+)\s+(\w+)\s*[(=;,[]/g)){let[,n,t="",o]=e,a=n??o;a&&!i.has(a)&&!i.has(t)&&r.add(a)}return r}var s={quad:"t*t",cubic:"t*t*t",quart:"t*t*t*t",quint:"t*t*t*t*t",sine:"1.0-cos(t*PI*0.5)",expo:"t<=0.0?0.0:pow(2.0,10.0*t-10.0)",circ:"1.0-sqrt(1.0-t*t)"},f={};for(let e in s){let n=`${e}In`;f[n]={code:`float ${n}(float t){\nt=clamp(t,0.0,1.0);\nreturn ${s[e]};\n}`},f[`${e}Out`]={needs:[n],code:`float ${e}Out(float t){\nreturn 1.0-${n}(1.0-t);\n}`},f[`${e}InOut`]={needs:[n],code:`float ${e}InOut(float t){\nreturn t<0.5?${n}(t*2.0)*0.5:1.0-${n}(2.0-t*2.0)*0.5;\n}`}}var x={...f,umberBezierAxis:{code:`float umberBezierAxis(float t,float p1,float p2){\nfloat c=3.0*p1;\nfloat b=3.0*(p2-p1)-c;\nreturn(((1.0-c-b)*t+b)*t+c)*t;\n}`},cubicBezier:{needs:["umberBezierAxis"],code:`float cubicBezier(float x,vec4 h){\nif(x<=0.0||x>=1.0)return clamp(x,0.0,1.0);\nfloat c=3.0*h.x;\nfloat b=3.0*(h.z-h.x)-c;\nfloat a=1.0-c-b;\nfloat t=x;\nfor(int i=0;i<4;i++)t-=(umberBezierAxis(t,h.x,h.z)-x)/max((3.0*a*t+2.0*b)*t+c,1e-6);\nif(t<0.0||t>1.0||abs(umberBezierAxis(t,h.x,h.z)-x)>1e-6){\nfloat lo=0.0;\nfloat hi=1.0;\nfor(int i=0;i<20;i++){\nt=(lo+hi)*0.5;\nif(umberBezierAxis(t,h.x,h.z)<x)lo=t;\nelse hi=t;\n}\nt=(lo+hi)*0.5;\n}\nreturn umberBezierAxis(t,h.y,h.w);\n}`},umberEase:{needs:["cubicBezier"],code:`float umberEase(float t){\nreturn cubicBezier(t,vec4(0.625,0.05,0.0,1.0));\n}`},stagger:{code:`float stagger(float progress,float index,float count,float overlap){\nfloat o=1.0-clamp(overlap,0.0,1.0);\nfloat w=1.0/(1.0+max(count-1.0,0.0)*o);\nreturn clamp((progress-index*w*o)/w,0.0,1.0);\n}`}};var d={umberHash3u:{code:`uvec3 umberHash3u(uvec3 v){\nv=v*0x9E3779B9u+v.yzx;\nv^=v>>16u;\nv=v*0x85EBCA6Bu+v.zxy;\nv^=v>>13u;\nv*=0xC2B2AE35u;\nv^=v>>16u;\nreturn v;\n}`},umberRand3:{needs:["umberHash3u"],code:`vec3 umberRand3(vec3 p){\nreturn vec3(umberHash3u(uvec3(ivec3(floor(p+0.5)))))*(1.0/4294967296.0);\n}`},snoise:{needs:["umberRand3"],code:`float umberCorner(vec2 i,vec2 x){\nfloat t=max(0.5-dot(x,x),0.0);\nfloat a=umberRand3(vec3(i,0.0)).x*6.28318530718;\nt*=t;\nreturn t*t*dot(vec2(cos(a),sin(a)),x);\n}\nfloat snoise(vec2 p){\nconst float F=0.36602540378;\nconst float G=0.2113248654;\nvec2 i=floor(p+(p.x+p.y)*F);\nvec2 x0=p-i+(i.x+i.y)*G;\nvec2 o=x0.x>x0.y?vec2(1.0,0.0):vec2(0.0,1.0);\nreturn 99.2*(umberCorner(i,x0)+umberCorner(i+o,x0-o+G)+umberCorner(i+1.0,x0-1.0+2.0*G));\n}\nfloat umberCorner(vec3 i,vec3 x){\nfloat t=max(0.5-dot(x,x),0.0);\nvec3 h=umberRand3(i);\nfloat z=h.x*2.0-1.0;\nfloat a=h.y*6.28318530718;\nfloat r=sqrt(1.0-z*z);\nt*=t;\nreturn t*t*dot(vec3(r*cos(a),r*sin(a),z),x);\n}\nfloat snoise(vec3 p){\nvec3 i=floor(p+(p.x+p.y+p.z)/3.0);\nvec3 x0=p-i+(i.x+i.y+i.z)/6.0;\nvec3 big=x0.x>=x0.y?(x0.x>=x0.z?vec3(1.0,0.0,0.0):vec3(0.0,0.0,1.0)):(x0.y>=x0.z?vec3(0.0,1.0,0.0):vec3(0.0,0.0,1.0));\nvec3 mid=1.0-(x0.x<x0.y?(x0.x<x0.z?vec3(1.0,0.0,0.0):vec3(0.0,0.0,1.0)):(x0.y<x0.z?vec3(0.0,1.0,0.0):vec3(0.0,0.0,1.0)));\nreturn 108.0*(umberCorner(i,x0)+umberCorner(i+big,x0-big+1.0/6.0)+umberCorner(i+mid,x0-mid+2.0/6.0)+umberCorner(i+1.0,x0-0.5));\n}`},pnoise:{needs:["umberRand3"],code:`float umberSlope(vec2 i,vec2 period,float spin,vec2 x){\nfloat a=umberRand3(vec3(mod(i,period),1.0)).x*6.28318530718+spin;\nreturn dot(vec2(cos(a),sin(a)),x);\n}\nfloat pnoise(vec2 p,vec2 period,float spin){\nvec2 n=max(floor(period+0.5),1.0);\nvec2 i=floor(p);\nvec2 f=p-i;\nvec2 u=f*f*f*(f*(f*6.0-15.0)+10.0);\nfloat a=umberSlope(i,n,spin,f);\nfloat b=umberSlope(i+vec2(1.0,0.0),n,spin,f-vec2(1.0,0.0));\nfloat c=umberSlope(i+vec2(0.0,1.0),n,spin,f-vec2(0.0,1.0));\nfloat d=umberSlope(i+1.0,n,spin,f-1.0);\nreturn 1.41421356*mix(mix(a,b,u.x),mix(c,d,u.x),u.y);\n}`},cellular:{needs:["umberRand3"],code:`vec2 cellular(vec2 p){\nvec2 i=floor(p);\nvec2 f=p-i;\nvec2 d=vec2(8.0);\nfor(int y= -1;y<=1;y++)\nfor(int x= -1;x<=1;x++){\nvec2 c=vec2(float(x),float(y));\nfloat l=length(c+umberRand3(vec3(i+c,2.0)).xy-f);\nif(l<d.x)d=vec2(l,d.x);\nelse if(l<d.y)d.y=l;\n}\nreturn d;\n}\nvec2 cellular(vec3 p){\nvec3 i=floor(p);\nvec3 f=p-i;\nvec2 d=vec2(8.0);\nfor(int z= -1;z<=1;z++)\nfor(int y= -1;y<=1;y++)\nfor(int x= -1;x<=1;x++){\nvec3 c=vec3(float(x),float(y),float(z));\nfloat l=length(c+umberRand3(i+c)-f);\nif(l<d.x)d=vec2(l,d.x);\nelse if(l<d.y)d.y=l;\n}\nreturn d;\n}`}};var v={sdCircle:{code:`float sdCircle(vec2 p,float r){\nreturn length(p)-r;\n}`},sdBox:{code:`float sdBox(vec2 p,vec2 b){\nvec2 d=abs(p)-b;\nreturn length(max(d,0.0))+min(max(d.x,d.y),0.0);\n}`},sdSegment:{code:`float sdSegment(vec2 p,vec2 a,vec2 b){\nvec2 pa=p-a;\nvec2 ba=b-a;\nreturn length(pa-ba*clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.0,1.0));\n}`},opRound:{code:`float opRound(float d,float r){\nreturn d-r;\n}`},opOnion:{code:`float opOnion(float d,float w){\nreturn abs(d)-w;\n}`},opSmoothUnion:{code:`float opSmoothUnion(float a,float b,float k){\nfloat h=clamp(0.5+0.5*(b-a)/max(k,1e-6),0.0,1.0);\nreturn mix(b,a,h)-k*h*(1.0-h);\n}`},opSmoothSubtract:{code:`float opSmoothSubtract(float a,float b,float k){\nfloat h=clamp(0.5-0.5*(a+b)/max(k,1e-6),0.0,1.0);\nreturn mix(a,-b,h)+k*h*(1.0-h);\n}`},opSmoothIntersect:{code:`float opSmoothIntersect(float a,float b,float k){\nfloat h=clamp(0.5-0.5*(b-a)/max(k,1e-6),0.0,1.0);\nreturn mix(b,a,h)+k*h*(1.0-h);\n}`},aa:{code:`#ifdef UMBER_FRAGMENT\nfloat aa(float d){\nreturn clamp(0.5-d/max(length(vec2(dFdx(d),dFdy(d))),1e-6),0.0,1.0);\n}\n#endif`}};var b={blendNormal:{code:`vec3 blendNormal(vec3 base,vec3 top,float opacity){\nreturn mix(base,top,opacity);\n}`},blendAdd:{code:`vec3 blendAdd(vec3 base,vec3 top,float opacity){\nreturn mix(base,min(base+top,1.0),opacity);\n}`},blendScreen:{code:`vec3 blendScreen(vec3 base,vec3 top,float opacity){\nreturn mix(base,base+top-base*top,opacity);\n}`},blendMultiply:{code:`vec3 blendMultiply(vec3 base,vec3 top,float opacity){\nreturn mix(base,base*top,opacity);\n}`}};var m={umberBayer2:{code:`float umberBayer2(vec2 p){\np=mod(floor(p),2.0);\nreturn mod(2.0*p.x+3.0*p.y,4.0);\n}`},bayer4:{needs:["umberBayer2"],code:`float bayer4(vec2 p){\nreturn(4.0*umberBayer2(p)+umberBayer2(p*0.5)+0.5)/16.0;\n}`},bayer8:{needs:["umberBayer2"],code:`float bayer8(vec2 p){\nreturn(16.0*umberBayer2(p)+4.0*umberBayer2(p*0.5)+umberBayer2(p*0.25)+0.5)/64.0;\n}`},blueNoise:{code:`const uint umberBlue[64]=uint[64](\n0xA9D7054Au,0x772B5FE1u,0x31BDE549u,0x2DDF1F4Eu,0x7333A2FEu,0xD4FB890Bu,0x698C159Au,0xC29678F0u,\n0xECC37E63u,0x1C3AB14Du,0xB041F358u,0x123FD30Au,0x145524E7u,0xBC67CE97u,0xC723A582u,0x8BAB5E85u,\n0xF5B59D45u,0xEB017A29u,0x5070CC32u,0xD62F1BF9u,0x866CCA03u,0x4BADE240u,0x38DD0D90u,0x75B9E39Fu,\n0xDA1A37F8u,0x6B20A15Au,0x7CB45CFFu,0x52916806u,0xBA9562A7u,0xBFD17608u,0xED199B2Eu,0xDC253CC1u,\n0xE84CC50Eu,0x1146F634u,0x8D43D581u,0x7FA3D056u,0x832272EEu,0xB69364ACu,0x28A861F1u,0x4717FA74u,\n0x99CF39AEu,0x5726E013u,0xC8E40236u,0x8E60B70Cu,0x54FD00DBu,0xA47DC43Du,0x4F876EC0u,0x27E93598u,\n0xB888669Eu,0xD907EA71u,0xDE16FC48u,0x537BD26Au,0x102CBE3Eu,0x846530A0u,0x2AB39421u,0xC909AA44u,\n0xCB79E61Du,0xEFB251F4u,0x8059CD3Bu,0xF28A18F7u,0x425D8FAFu,0x0FC6921Eu,0xD8046DA6u,0x6F5BBB9Cu\n);\nfloat blueNoise(vec2 p){\nivec2 q=ivec2(mod(floor(p),16.0));\nint i=q.y*16+q.x;\nreturn(float((umberBlue[i>>2]>>(uint(i&3)*8u))&255u)+0.5)/256.0;\n}`},dither:{code:`vec3 dither(vec3 color,float threshold,float levels){\nfloat n=max(levels-1.0,1.0);\nreturn floor(color*n+threshold)/n;\n}`}};var p={srgbToLinear:{code:`vec3 srgbToLinear(vec3 c){\nreturn mix(c/12.92,pow((max(c,0.0)+0.055)/1.055,vec3(2.4)),step(0.04045,c));\n}`},linearToSrgb:{code:`vec3 linearToSrgb(vec3 c){\nreturn mix(c*12.92,1.055*pow(max(c,0.0),vec3(1.0/2.4))-0.055,step(0.0031308,c));\n}`},linearToOklab:{code:`vec3 linearToOklab(vec3 c){\nvec3 lms=c*mat3(0.4122214708,0.5363325363,0.0514459929,0.2119034982,0.6806995451,0.1073969566,0.0883024619,0.2817188376,0.6299787005);\nlms=sign(lms)*pow(abs(lms),vec3(1.0/3.0));\nreturn lms*mat3(0.2104542553,0.7936177850,-0.0040720468,1.9779984951,-2.4285922050,0.4505937099,0.0259040371,0.7827717662,-0.8086757660);\n}`},oklabToLinear:{code:`vec3 oklabToLinear(vec3 c){\nvec3 lms=c*mat3(1.0,0.3963377774,0.2158037573,1.0,-0.1055613458,-0.0638541728,1.0,-0.0894841775,-1.2914855480);\nreturn(lms*lms*lms)*mat3(4.0767416621,-3.3077115913,0.2309699292,-1.2684380046,2.6097574011,-0.3413193965,-0.0041960863,-0.7034186147,1.7076147010);\n}`},mixOklab:{needs:["srgbToLinear","linearToSrgb","linearToOklab","oklabToLinear"],code:`vec3 mixOklab(vec3 a,vec3 b,float t){\nreturn linearToSrgb(oklabToLinear(mix(linearToOklab(srgbToLinear(a)),linearToOklab(srgbToLinear(b)),t)));\n}`}};var h={...x,...d,...v,...b,...m,...p},y="(?:float|u?int|bool|void|[iu]?vec[234]|mat[234])",B={};for(let[e,{code:n,needs:t}]of Object.entries(h))B[e]={used:new RegExp(`\\b${e}\\s*\\(`),defined:new RegExp(`\\b${y}\\s+${e}\\s*\\(`),code:n,needs:t};var g={...e,...B},C=e=>`// ${e}() from the helper pack`;function E(e){a(e.env.host.log);let n=e.env.registry.chunks;for(let e in h)n.has(e)||n.set(e,C(e));return(n,t,r)=>u(n,t,{chunks:r,say:e.env.lib.say})}export{h as GLSL,g as GLSL_HELPERS,E as glsl,C as packChunk};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e={};function n(n,t=e){let r=new Map,o=e=>{let a=t[e];if(!(!a||r.has(e)||a.defined.test(n))){for(let e of a.needs??[])o(e);r.set(e,a)}};for(let[e,r]of Object.entries(t))r.used.test(n)&&o(e);return[...r.values()].map(e=>e.code).join(`\n\n`)}function t(e,n){let t=e=>e.charAt(0).toUpperCase()+e.slice(1),r=e=>e.split(/[-_\s]+/).map(t).join("");return`u${r(e)}${r(n)}`}var r={hash:{used:/\bumberHash\s*\(/,defined:/\bfloat\s+umberHash\s*\(/,code:`float umberHash(vec2 p){\np=fract(p*vec2(123.34,456.21));\np+=dot(p,p+45.32);\nreturn fract(p.x*p.y);\n}\nfloat umberHash(vec3 p){\np=fract(p*vec3(0.1031,0.1030,0.0973));\np+=dot(p,p.yxz+33.33);\nreturn fract((p.x+p.y)*p.z);\n}`},noise2:{used:/\bnoise\s*\(/,defined:/\bfloat\s+noise\s*\(\s*(?:in\s+)?vec2\b/,needs:["hash"],code:`float noise(vec2 p){\nvec2 i=floor(p);\nvec2 f=fract(p);\nvec2 k=f*f*(3.0-2.0*f);\nreturn mix(mix(umberHash(i),umberHash(i+vec2(1.0,0.0)),k.x),mix(umberHash(i+vec2(0.0,1.0)),umberHash(i+vec2(1.0,1.0)),k.x),k.y);\n}`},noise3:{used:/\bnoise\s*\(/,defined:/\bfloat\s+noise\s*\(\s*(?:in\s+)?vec3\b/,needs:["hash"],code:`float noise(vec3 p){\nvec3 i=floor(p);\nvec3 f=fract(p);\nvec3 k=f*f*(3.0-2.0*f);\nvec2 e=vec2(1.0,0.0);\nfloat a=mix(mix(umberHash(i),umberHash(i+e.xyy),k.x),mix(umberHash(i+e.yxy),umberHash(i+e.xxy),k.x),k.y);\nfloat b=mix(mix(umberHash(i+e.yyx),umberHash(i+e.xyx),k.x),mix(umberHash(i+e.yxx),umberHash(i+e.xxx),k.x),k.y);\nreturn mix(a,b,k.z);\n}`},fbm:{used:/\bfbm\s*\(/,defined:/\bfloat\s+fbm\s*\(\s*(?:in\s+)?vec2\b/,needs:["noise2"],code:`float fbm(vec2 p){\nfloat v=0.0;\nfloat a=0.5;\nfor(int i=0;i<4;i++){\nv+=a*noise(p);\np=p*2.03+17.0;\na*=0.5;\n}\nreturn v/0.9375;\n}`},screenPx:{used:/\bscreenPx\s*\(/,defined:/\bvec2\s+screenPx\s*\(/,code:`\n#ifdef UMBER_FRAGMENT\nvec2 screenPx(){\nreturn uSurface.xy+vec2(gl_FragCoord.x,uCanvas.y-gl_FragCoord.y)/uCanvas*uSurface.zw;\n}\n#endif`},screenUv:{used:/\bscreenUv\s*\(/,defined:/\bvec2\s+screenUv\s*\(/,needs:["screenPx"],code:`\n#ifdef UMBER_FRAGMENT\nvec2 screenUv(){\nreturn screenPx()/uViewport;\n}\n#endif`},screenAt:{used:/\bscreen(Px|Uv)\s*\(\s*[^\s)]/,defined:/\bvec2\s+screenPx\s*\(\s*vec2\b/,code:`\n#ifndef UMBER_FRAGMENT\nvec2 screenPx(vec2 uv){\nvec3 h=uPlaneMatrix*vec3(uv*uSize,1.0);\nreturn h.xy/h.z;\n}\nvec2 screenUv(vec2 uv){\nreturn screenPx(uv)/uViewport;\n}\n#endif`},textureSmooth:{used:/\btextureSmooth\s*\(/,defined:/\bvec4\s+textureSmooth\s*\(/,code:`\nvec4 textureSmooth(sampler2D t,vec2 uv,out vec4 dx,out vec4 dy){\nivec2 size=textureSize(t,0);\nvec2 p=uv*vec2(size)-0.5;\nvec2 f=fract(p);\nvec2 g=1.0-f;\nivec2 i=ivec2(floor(p))-1;\nmat4x2 w=mat4x2(g*g*g,4.0+f*f*(3.0*f-6.0),4.0+g*g*(3.0*g-6.0),f*f*f)/6.0;\nmat4x2 d=mat4x2(-g*g,f*(3.0*f-4.0),g*(4.0-3.0*g),f*f)*0.5;\nvec4 sum=vec4(0.0);\ndx=vec4(0.0);\ndy=vec4(0.0);\nfor(int y=0;y<4;y++){\nvec4 row=vec4(0.0);\nvec4 slope=vec4(0.0);\nfor(int x=0;x<4;x++){\nvec4 texel=texelFetch(t,clamp(i+ivec2(x,y),ivec2(0),size-1),0);\nrow+=w[x].x*texel;\nslope+=d[x].x*texel;\n}\nsum+=w[y].y*row;\ndx+=w[y].y*slope;\ndy+=d[y].y*row;\n}\ndx*=float(size.x);\ndy*=float(size.y);\nreturn sum;\n}\nvec4 textureSmooth(sampler2D t,vec2 uv){\nvec4 dx;\nvec4 dy;\nreturn textureSmooth(t,uv,dx,dy);\n}`},flowSmooth:{used:/\bflowSmooth\s*\(/,defined:/\bvec4\s+flowSmooth\s*\(/,needs:["textureSmooth"],code:`\nvec4 flowSmooth(vec2 uv,out vec4 dx,out vec4 dy){\nreturn textureSmooth(uFlow,uv,dx,dy);\n}\nvec4 flowSmooth(vec2 uv){\nreturn textureSmooth(uFlow,uv);\n}`},screen:{used:/\buScreen\b/,defined:/(vec2|#define)\s+uScreen\b/,code:`\n#define uScreen ((uRect.xy + uRect.zw * 0.5) / uViewport * 2.0 - 1.0)`},samplePrev:{used:/\bsamplePrev\s*\(/,defined:/\bvec4\s+samplePrev\s*\(/,code:`\nvec4 samplePrev(vec2 uv){\nvec2 f=uv;\nif(uFit<1.5){\nvec2 ratio=uSize/max(uPrevSize,vec2(1.0));\nfloat s=uFit<0.5?max(ratio.x,ratio.y):min(ratio.x,ratio.y);\nvec2 scaled=uPrevSize*s;\nf=(uv*uSize-(uSize-scaled)*uFitPosition)/scaled;\n}\nvec4 c=texture(uPrev,f);\nif(uFit>0.5&&uFit<1.5&&(f.x<0.0||f.y<0.0||f.x>1.0||f.y>1.0))c=vec4(0.0);\nreturn vec4(c.rgb/max(c.a,1e-5),c.a);\n}`},rotate2d:{used:/\brotate2d\s*\(/,defined:/\bmat2\s+rotate2d\s*\(/,code:`mat2 rotate2d(float a){\nfloat c=cos(a);\nfloat s=sin(a);\nreturn mat2(c,s,-s,c);\n}`}};var o=()=>{};var a=()=>Promise.reject(new Error("no words"));var c={configure:o,debug:!1,warnings:!1,info:o,warn:o,error:o,report:o,words:a},u=c;function i(e){u=e}var s=/^[ \t]*#include[ \t]+["<]?([\w-]+)[">]?[ \t]*$/gm,l=new Set("if else for while do switch case default return break continue discard uniform in out inout const struct precision layout highp mediump lowp flat smooth centroid invariant".split(" ")),f=/#include[ \t]+\\?["<]?([\w-]+)/g;function d(e,n,t=new Set){let r="";for(let[,o=""]of e.matchAll(f)){let e=n.get(o);e==null||t.has(o)||(t.add(o),r+=`${d(e,n,t)}\n${e}\n`)}return r}function x(e){let n=e.find(e=>e.def.options&&"perspective"in e.def.options);if(!n)return e;let r=t(n.name,"perspective");return[{name:"perspective",def:{vertex:{head:"vec2 perspectiveOrigin;",main:"perspectiveOrigin = uSize * 0.5;"}}},...e,{name:"perspective",def:{vertex:{main:`if (${r} > 0.0) pos.xy += (uv * uSize + pos.xy - perspectiveOrigin) * pos.z / max(${r} - pos.z, 1.0);`}}}]}function v({effects:e,shader:n,...t},r,{chunks:o,say:a}){let c=new Set,u=[],i=()=>({code:[],seen:new Set}),l=i(),f=i(),d=(e,n)=>e.replace(s,(e,t)=>{if(n.seen.has(t))return"";n.seen.add(t),c.add(t);let r=o.get(t);return r==null?u.includes(t)||u.push(t):n.code.push(`// chunk: ${t}\n${d(r,n)}`),""}),v=(e,n)=>{if(!e)return e;let t={};for(let r in e)typeof e[r]=="string"&&(t[r]=n(e[r]));return t},p=e.map(({name:e,def:n})=>({name:e,def:{...n,vertex:v(n.vertex,e=>d(e,l)),fragment:v(n.fragment,e=>d(e,f))}})),b=n&&{name:n.name,def:{...n.def,head:d(n.def.head??"",f),fragment:d(n.def.fragment,f)}},h=p.map(e=>({fx:e,own:m(`${e.def.vertex?.head??""}\n${e.def.fragment?.head??""}`)})),y=new Map;for(let e of[...h.map(({own:e})=>e),m(b?.def.head??"")])for(let n of e)y.set(n,(y.get(n)??0)+1);if(h.forEach(({fx:e,own:n},t)=>{let r=[...n].filter(e=>(y.get(e)??0)>1);if(!r.length)return;let o=new RegExp(`(^|[^.\\w])(${r.join("|")})\\b`,"g"),a=e=>e.replace(o,`$1e${t}_$2`);e.def={...e.def,vertex:v(e.def.vertex,a),fragment:v(e.def.fragment,a)}}),u.length){for(let e of u)r.missing.push(`chunk:${e}`),a("include",[e],r.el);return r.setStatus("error"),null}return{...t,effects:x(p),shader:b,chunks:{vertex:l.code.join(`\n\n`),fragment:f.code.join(`\n\n`)},included:[...c]}}function m(e){let n="",t=0;for(let r of e.replace(/\/\/.*|\/\*[\s\S]*?\*\//g,""))(r==="}"||r===")")&&t--,t||(n+=r),(r==="{"||r==="(")&&t++;n=n.replace(/\b(uniform|in|out|precision|layout)\b[^;]*;/g,"");let r=new Set;for(let e of n.matchAll(/#define\s+(\w+)|\b(\w+)\s+(\w+)\s*[(=;,[]/g)){let[,n,t="",o]=e,a=n??o;a&&!l.has(a)&&!l.has(t)&&r.add(a)}return r}var p={quad:"t*t",cubic:"t*t*t",quart:"t*t*t*t",quint:"t*t*t*t*t",sine:"1.0-cos(t*PI*0.5)",expo:"t<=0.0?0.0:pow(2.0,10.0*t-10.0)",circ:"1.0-sqrt(1.0-t*t)"},b={};for(let e in p){let n=`${e}In`;b[n]={code:`float ${n}(float t){\nt=clamp(t,0.0,1.0);\nreturn ${p[e]};\n}`},b[`${e}Out`]={needs:[n],code:`float ${e}Out(float t){\nreturn 1.0-${n}(1.0-t);\n}`},b[`${e}InOut`]={needs:[n],code:`float ${e}InOut(float t){\nreturn t<0.5?${n}(t*2.0)*0.5:1.0-${n}(2.0-t*2.0)*0.5;\n}`}}var h={...b,umberBezierAxis:{code:`\nfloat umberBezierAxis(float t,float p1,float p2){\nfloat c=3.0*p1;\nfloat b=3.0*(p2-p1)-c;\nreturn(((1.0-c-b)*t+b)*t+c)*t;\n}`},cubicBezier:{needs:["umberBezierAxis"],code:`\nfloat cubicBezier(float x,vec4 h){\nif(x<=0.0||x>=1.0)return clamp(x,0.0,1.0);\nfloat c=3.0*h.x;\nfloat b=3.0*(h.z-h.x)-c;\nfloat a=1.0-c-b;\nfloat t=x;\nfor(int i=0;i<4;i++)t-=(umberBezierAxis(t,h.x,h.z)-x)/max((3.0*a*t+2.0*b)*t+c,1e-6);\nif(t<0.0||t>1.0||abs(umberBezierAxis(t,h.x,h.z)-x)>1e-6){\nfloat lo=0.0;\nfloat hi=1.0;\nfor(int i=0;i<20;i++){\nt=(lo+hi)*0.5;\nif(umberBezierAxis(t,h.x,h.z)<x)lo=t;\nelse hi=t;\n}\nt=(lo+hi)*0.5;\n}\nreturn umberBezierAxis(t,h.y,h.w);\n}`},umberEase:{needs:["cubicBezier"],code:`\nfloat umberEase(float t){\nreturn cubicBezier(t,vec4(0.625,0.05,0.0,1.0));\n}`},stagger:{code:`\nfloat stagger(float progress,float index,float count,float overlap){\nfloat o=1.0-clamp(overlap,0.0,1.0);\nfloat w=1.0/(1.0+max(count-1.0,0.0)*o);\nreturn clamp((progress-index*w*o)/w,0.0,1.0);\n}`}};var y={umberHash3u:{code:`\nuvec3 umberHash3u(uvec3 v){\nv=v*0x9E3779B9u+v.yzx;\nv^=v>>16u;\nv=v*0x85EBCA6Bu+v.zxy;\nv^=v>>13u;\nv*=0xC2B2AE35u;\nv^=v>>16u;\nreturn v;\n}`},umberRand3:{needs:["umberHash3u"],code:`\nvec3 umberRand3(vec3 p){\nreturn vec3(umberHash3u(uvec3(ivec3(floor(p+0.5)))))*(1.0/4294967296.0);\n}`},snoise:{needs:["umberRand3"],code:`\nfloat umberCorner(vec2 i,vec2 x){\nfloat t=max(0.5-dot(x,x),0.0);\nfloat a=umberRand3(vec3(i,0.0)).x*6.28318530718;\nt*=t;\nreturn t*t*dot(vec2(cos(a),sin(a)),x);\n}\nfloat snoise(vec2 p){\nconst float F=0.36602540378;\nconst float G=0.2113248654;\nvec2 i=floor(p+(p.x+p.y)*F);\nvec2 x0=p-i+(i.x+i.y)*G;\nvec2 o=x0.x>x0.y?vec2(1.0,0.0):vec2(0.0,1.0);\nreturn 99.2*(umberCorner(i,x0)+umberCorner(i+o,x0-o+G)+umberCorner(i+1.0,x0-1.0+2.0*G));\n}\nfloat umberCorner(vec3 i,vec3 x){\nfloat t=max(0.5-dot(x,x),0.0);\nvec3 h=umberRand3(i);\nfloat z=h.x*2.0-1.0;\nfloat a=h.y*6.28318530718;\nfloat r=sqrt(1.0-z*z);\nt*=t;\nreturn t*t*dot(vec3(r*cos(a),r*sin(a),z),x);\n}\nfloat snoise(vec3 p){\nvec3 i=floor(p+(p.x+p.y+p.z)/3.0);\nvec3 x0=p-i+(i.x+i.y+i.z)/6.0;\nvec3 big=x0.x>=x0.y?(x0.x>=x0.z?vec3(1.0,0.0,0.0):vec3(0.0,0.0,1.0)):(x0.y>=x0.z?vec3(0.0,1.0,0.0):vec3(0.0,0.0,1.0));\nvec3 mid=1.0-(x0.x<x0.y?(x0.x<x0.z?vec3(1.0,0.0,0.0):vec3(0.0,0.0,1.0)):(x0.y<x0.z?vec3(0.0,1.0,0.0):vec3(0.0,0.0,1.0)));\nreturn 108.0*(umberCorner(i,x0)+umberCorner(i+big,x0-big+1.0/6.0)+umberCorner(i+mid,x0-mid+2.0/6.0)+umberCorner(i+1.0,x0-0.5));\n}`},pnoise:{needs:["umberRand3"],code:`\nfloat umberSlope(vec2 i,vec2 period,float spin,vec2 x){\nfloat a=umberRand3(vec3(mod(i,period),1.0)).x*6.28318530718+spin;\nreturn dot(vec2(cos(a),sin(a)),x);\n}\nfloat pnoise(vec2 p,vec2 period,float spin){\nvec2 n=max(floor(period+0.5),1.0);\nvec2 i=floor(p);\nvec2 f=p-i;\nvec2 u=f*f*f*(f*(f*6.0-15.0)+10.0);\nfloat a=umberSlope(i,n,spin,f);\nfloat b=umberSlope(i+vec2(1.0,0.0),n,spin,f-vec2(1.0,0.0));\nfloat c=umberSlope(i+vec2(0.0,1.0),n,spin,f-vec2(0.0,1.0));\nfloat d=umberSlope(i+1.0,n,spin,f-1.0);\nreturn 1.41421356*mix(mix(a,b,u.x),mix(c,d,u.x),u.y);\n}`},cellular:{needs:["umberRand3"],code:`\nvec2 cellular(vec2 p){\nvec2 i=floor(p);\nvec2 f=p-i;\nvec2 d=vec2(8.0);\nfor(int y= -1;y<=1;y++)\nfor(int x= -1;x<=1;x++){\nvec2 c=vec2(float(x),float(y));\nfloat l=length(c+umberRand3(vec3(i+c,2.0)).xy-f);\nif(l<d.x)d=vec2(l,d.x);\nelse if(l<d.y)d.y=l;\n}\nreturn d;\n}\nvec2 cellular(vec3 p){\nvec3 i=floor(p);\nvec3 f=p-i;\nvec2 d=vec2(8.0);\nfor(int z= -1;z<=1;z++)\nfor(int y= -1;y<=1;y++)\nfor(int x= -1;x<=1;x++){\nvec3 c=vec3(float(x),float(y),float(z));\nfloat l=length(c+umberRand3(i+c)-f);\nif(l<d.x)d=vec2(l,d.x);\nelse if(l<d.y)d.y=l;\n}\nreturn d;\n}`}};var g={sdCircle:{code:`\nfloat sdCircle(vec2 p,float r){\nreturn length(p)-r;\n}`},sdBox:{code:`\nfloat sdBox(vec2 p,vec2 b){\nvec2 d=abs(p)-b;\nreturn length(max(d,0.0))+min(max(d.x,d.y),0.0);\n}`},sdSegment:{code:`\nfloat sdSegment(vec2 p,vec2 a,vec2 b){\nvec2 pa=p-a;\nvec2 ba=b-a;\nreturn length(pa-ba*clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.0,1.0));\n}`},opRound:{code:`\nfloat opRound(float d,float r){\nreturn d-r;\n}`},opOnion:{code:`\nfloat opOnion(float d,float w){\nreturn abs(d)-w;\n}`},opSmoothUnion:{code:`\nfloat opSmoothUnion(float a,float b,float k){\nfloat h=clamp(0.5+0.5*(b-a)/max(k,1e-6),0.0,1.0);\nreturn mix(b,a,h)-k*h*(1.0-h);\n}`},opSmoothSubtract:{code:`\nfloat opSmoothSubtract(float a,float b,float k){\nfloat h=clamp(0.5-0.5*(a+b)/max(k,1e-6),0.0,1.0);\nreturn mix(a,-b,h)+k*h*(1.0-h);\n}`},opSmoothIntersect:{code:`\nfloat opSmoothIntersect(float a,float b,float k){\nfloat h=clamp(0.5-0.5*(b-a)/max(k,1e-6),0.0,1.0);\nreturn mix(b,a,h)+k*h*(1.0-h);\n}`},aa:{code:`\n#ifdef UMBER_FRAGMENT\nfloat aa(float d){\nreturn clamp(0.5-d/max(length(vec2(dFdx(d),dFdy(d))),1e-6),0.0,1.0);\n}\n#endif`}};var B={blendNormal:{code:`\nvec3 blendNormal(vec3 base,vec3 top,float opacity){\nreturn mix(base,top,opacity);\n}`},blendAdd:{code:`\nvec3 blendAdd(vec3 base,vec3 top,float opacity){\nreturn mix(base,min(base+top,1.0),opacity);\n}`},blendScreen:{code:`\nvec3 blendScreen(vec3 base,vec3 top,float opacity){\nreturn mix(base,base+top-base*top,opacity);\n}`},blendMultiply:{code:`\nvec3 blendMultiply(vec3 base,vec3 top,float opacity){\nreturn mix(base,base*top,opacity);\n}`}};var S={umberBayer2:{code:`\nfloat umberBayer2(vec2 p){\np=mod(floor(p),2.0);\nreturn mod(2.0*p.x+3.0*p.y,4.0);\n}`},bayer4:{needs:["umberBayer2"],code:`\nfloat bayer4(vec2 p){\nreturn(4.0*umberBayer2(p)+umberBayer2(p*0.5)+0.5)/16.0;\n}`},bayer8:{needs:["umberBayer2"],code:`\nfloat bayer8(vec2 p){\nreturn(16.0*umberBayer2(p)+4.0*umberBayer2(p*0.5)+umberBayer2(p*0.25)+0.5)/64.0;\n}`},blueNoise:{code:`\nconst uint umberBlue[64]=uint[64](\n0xA9D7054Au,0x772B5FE1u,0x31BDE549u,0x2DDF1F4Eu,0x7333A2FEu,0xD4FB890Bu,0x698C159Au,0xC29678F0u,\n0xECC37E63u,0x1C3AB14Du,0xB041F358u,0x123FD30Au,0x145524E7u,0xBC67CE97u,0xC723A582u,0x8BAB5E85u,\n0xF5B59D45u,0xEB017A29u,0x5070CC32u,0xD62F1BF9u,0x866CCA03u,0x4BADE240u,0x38DD0D90u,0x75B9E39Fu,\n0xDA1A37F8u,0x6B20A15Au,0x7CB45CFFu,0x52916806u,0xBA9562A7u,0xBFD17608u,0xED199B2Eu,0xDC253CC1u,\n0xE84CC50Eu,0x1146F634u,0x8D43D581u,0x7FA3D056u,0x832272EEu,0xB69364ACu,0x28A861F1u,0x4717FA74u,\n0x99CF39AEu,0x5726E013u,0xC8E40236u,0x8E60B70Cu,0x54FD00DBu,0xA47DC43Du,0x4F876EC0u,0x27E93598u,\n0xB888669Eu,0xD907EA71u,0xDE16FC48u,0x537BD26Au,0x102CBE3Eu,0x846530A0u,0x2AB39421u,0xC909AA44u,\n0xCB79E61Du,0xEFB251F4u,0x8059CD3Bu,0xF28A18F7u,0x425D8FAFu,0x0FC6921Eu,0xD8046DA6u,0x6F5BBB9Cu\n);\nfloat blueNoise(vec2 p){\nivec2 q=ivec2(mod(floor(p),16.0));\nint i=q.y*16+q.x;\nreturn(float((umberBlue[i>>2]>>(uint(i&3)*8u))&255u)+0.5)/256.0;\n}`},dither:{code:`\nvec3 dither(vec3 color,float threshold,float levels){\nfloat n=max(levels-1.0,1.0);\nreturn floor(color*n+threshold)/n;\n}`}};var w={srgbToLinear:{code:`\nvec3 srgbToLinear(vec3 c){\nreturn mix(c/12.92,pow((max(c,0.0)+0.055)/1.055,vec3(2.4)),step(0.04045,c));\n}`},linearToSrgb:{code:`\nvec3 linearToSrgb(vec3 c){\nreturn mix(c*12.92,1.055*pow(max(c,0.0),vec3(1.0/2.4))-0.055,step(0.0031308,c));\n}`},linearToOklab:{code:`\nvec3 linearToOklab(vec3 c){\nvec3 lms=c*mat3(0.4122214708,0.5363325363,0.0514459929,0.2119034982,0.6806995451,0.1073969566,0.0883024619,0.2817188376,0.6299787005);\nlms=sign(lms)*pow(abs(lms),vec3(1.0/3.0));\nreturn lms*mat3(0.2104542553,0.7936177850,-0.0040720468,1.9779984951,-2.4285922050,0.4505937099,0.0259040371,0.7827717662,-0.8086757660);\n}`},oklabToLinear:{code:`\nvec3 oklabToLinear(vec3 c){\nvec3 lms=c*mat3(1.0,0.3963377774,0.2158037573,1.0,-0.1055613458,-0.0638541728,1.0,-0.0894841775,-1.2914855480);\nreturn(lms*lms*lms)*mat3(4.0767416621,-3.3077115913,0.2309699292,-1.2684380046,2.6097574011,-0.3413193965,-0.0041960863,-0.7034186147,1.7076147010);\n}`},mixOklab:{needs:["srgbToLinear","linearToSrgb","linearToOklab","oklabToLinear"],code:`\nvec3 mixOklab(vec3 a,vec3 b,float t){\nreturn linearToSrgb(oklabToLinear(mix(linearToOklab(srgbToLinear(a)),linearToOklab(srgbToLinear(b)),t)));\n}`}};var z={...h,...y,...g,...B,...S,...w},E="(?:float|u?int|bool|void|[iu]?vec[234]|mat[234])",A={};for(let[e,{code:n,needs:t}]of Object.entries(z))A[e]={used:new RegExp(`\\b${e}\\s*\\(`),defined:new RegExp(`\\b${E}\\s+${e}\\s*\\(`),code:n,needs:t};var C={...r,...A},F=e=>`// ${e}() from the helper pack`;function k(e){i(e.env.host.log);let t=e.env.registry.chunks;for(let e in z)t.has(e)||t.set(e,F(e));return Object.assign((...[n,t,r])=>v(n,t,{chunks:r,say:e.env.lib.say}),{included:e=>d(e,t),reads(e){let r=e+d(e,t);return r+n(r,C)}})}export{z as GLSL,C as GLSL_HELPERS,k as glsl,F as packChunk};
@@ -0,0 +1,2 @@
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=(e,n)=>e[n]??NaN;var n={used:/\bglyph\s*\(/,defined:/\bGlyph\s+glyph\s*\(/,code:`\nstruct Glyph{\nfloat line;\nfloat word;\nfloat char;\nfloat lines;\nfloat words;\nfloat chars;\nvec4 lineBox;\nvec4 wordBox;\nvec4 charBox;\nfloat ink;\nvec4 lineValue;\nvec4 wordValue;\nvec4 charValue;\n};\nuniform highp usampler2D uGlyphIndex;\nuniform highp sampler2D uGlyphData;\nvec4 umberGlyphRow(highp int i){\nreturn texelFetch(uGlyphData,ivec2(i&511,i>>9),0);\n}\nGlyph umberGlyph(vec2 uv){\nGlyph umberG=Glyph(0.0,0.0,0.0,1.0,1.0,1.0,vec4(0.0,0.0,1.0,1.0),vec4(0.0,0.0,1.0,1.0),vec4(0.0,0.0,1.0,1.0),0.0,vec4(0.0),vec4(0.0),vec4(0.0));\nvec4 head=umberGlyphRow(0);\nif(head.x<0.5)return umberG;\nhighp ivec2 size=textureSize(uGlyphIndex,0);\nhighp ivec2 p=clamp(ivec2(floor(uv*vec2(size))),ivec2(0),size-1);\nhighp int c=int(texelFetch(uGlyphIndex,p,0).r)-1;\nif(c<0)return umberG;\nhighp int chars=int(head.x+0.5);\nhighp int words=int(head.y+0.5);\nvec4 info=umberGlyphRow(1+2*c);\numberG.line=info.x;\numberG.word=info.y;\numberG.char=float(c);\numberG.chars=head.x;\numberG.words=head.y;\numberG.lines=head.z;\numberG.charBox=umberGlyphRow(2+2*c);\numberG.wordBox=umberGlyphRow(1+2*chars+int(info.y+0.5));\numberG.lineBox=umberGlyphRow(1+2*chars+words+int(info.x+0.5));\nhighp int lines=int(head.z+0.5);\nhighp int values=1+2*chars+words+lines;\numberG.lineValue=umberGlyphRow(values+int(info.x+0.5));\numberG.wordValue=umberGlyphRow(values+lines+int(info.y+0.5));\numberG.charValue=umberGlyphRow(values+lines+words+c);\nreturn umberG;\n}\nGlyph glyph(vec2 uv){\nGlyph umberG=umberGlyph(uv);\n#ifdef UMBER_FRAGMENT\numberG.ink=sampleImage(uv).a;\n#endif\nreturn umberG;\n}`};function t(e,n){let t=n;for(let n=1;n&&t<e.length;t++)e[t]==="("?n++:e[t]===")"&&n--;return t}function l(e){let n=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,e=>" ".repeat(e.length));if(!n.includes("umberGlyph(")||/#\s*define.*\bink\b/.test(n))return e;let l=e;for(let e of[...n.matchAll(/(?<![\w.]|\bGlyph\s+)glyph\s*\(/g)].reverse()){let h=t(n,e.index+e[0].length),[,r]=/^\s*(;|\.\s*(?!ink\b)[A-Za-z_])/.exec(n.slice(h))??[],[,i=""]=/(?<![\w.])([A-Za-z_]\w*)\s*=\s*$/.exec(n.slice(0,e.index))??[],a=new RegExp(`(?<![\\w.])${i}\\b(?!\\s*=\\s*glyph\\s*\\(|\\s*\\.\\s*(?!ink\\b)[A-Za-z_]|(?<=\\bGlyph\\s+${i})\\s*;)`);r&&(r!==";"||i&&!a.test(n))&&(l=`${l.slice(0,e.index)}umberGlyph${l.slice(e.index+5)}`)}return l}var h=65534,r=(e,n)=>{e.l=Math.min(e.l,n.x),e.t=Math.min(e.t,n.y),e.r=Math.max(e.r,n.x+n.w),e.b=Math.max(e.b,n.y+n.h)},i=e=>({l:e.x,t:e.y,r:e.x+e.w,b:e.y+e.h}),a=e=>e.x+e.w/2;function u(e,n,t){if(e.unit!==void 0&&n?.unit!==void 0)return e.unit!==n.unit;let l=!!n&&(e.rtl?a(e)>n.x+n.w:a(e)<n.x);return e.y+e.h/2>t.b||l&&e.y>=(t.t+t.b)/2}function o(e,n=e.length){let t=new Int32Array(n),l=new Int32Array(n),h=[],a=[],o=null,s,c;for(let d=0;d<n;d++){let n=e[d];if(!n)break;let p=!s||u(n,o,s);p||!s?(s={...i(n),chars:[]},h.push(s)):r(s,n),s.chars.push(d),p||n.lg||!c?(c=i(n),a.push(c)):r(c,n),t[d]=h.length-1,l[d]=a.length-1,o=n}return{ac:t,wordOf:l,lines:h,words:a}}var s=(e,n,t)=>Math.max(0,Math.min(t,Math.round(n*e.scale)));function c(e,n,t,l=2048){let r=Math.min(e.length,h);if(!r||!(n>0)||!(t>0))return null;let i=o(e,r),a=Math.min(1,l/Math.max(n,t)),u={scale:a,width:Math.max(1,Math.ceil(n*a)),height:Math.max(1,Math.ceil(t*a))},s=i.lines.map(t=>d(e,t,u,n)),c=y(e,i,n,t);return{chars:r,words:i.words.length,lines:i.lines.length,index:w(f(s),s,u),width:u.width,height:u.height,data:c.data,dataWidth:c.dataWidth,dataHeight:c.dataHeight,values:c.values}}function d(e,n,t,l){let h={line:n,owner:new Uint16Array(t.width),inkTop:new Float32Array(t.width).fill(1/0),inkBottom:new Float32Array(t.width).fill(-1/0)},r=n.chars.flatMap(n=>{let t=e[n];return t?[{at:n,glyph:t}]:[]}).sort((e,n)=>a(e.glyph)-a(n.glyph)),i=0;for(let[e,{at:n,glyph:a}]of r.entries()){let u=r[e+1]?.glyph,o=u?Math.max(i,(a.x+a.w+u.x)/2):l,c=s(t,i,t.width),d=u?s(t,o,t.width):t.width;d>c&&h.owner.fill(n+1,c,d),i=o,p(h,a,t)}return h}function p(n,t,l){let h=t.ink??{l:t.x,t:t.y,r:t.x+t.w,b:t.y+t.h},{inkTop:r,inkBottom:i}=n;for(let n=s(l,h.l-1,l.width-1),t=s(l,h.r+1,l.width-1);n<=t;n++)h.t-1<e(r,n)&&(r[n]=h.t-1),h.b+1>e(i,n)&&(i[n]=h.b+1)}function f(n){let t=[],l;for(let h of n){if(l){let n=(l.line.b+h.line.t)/2,{inkTop:r}=h;t.push(l.inkBottom.map((t,l)=>{let h=e(r,l);return t>h?(t+h)/2:Math.min(Math.max(n,t),h)}))}l=h}return t}function w(n,t,l){let h=new Uint16Array(l.width*l.height);for(let r=0;r<l.width;r++){let i=0;for(let[a,u]of t.entries()){let t=n[a],o=t?Math.max(i,s(l,e(t,r),l.height)):l.height,c=e(u.owner,r);for(let e=i;e<o;e++)h[e*l.width+r]=c;i=o}}return h}var m=512;function y(n,t,l,h){let{ac:r,wordOf:a,lines:u,words:o}=t,s=r.length,c=1+2*s+o.length+u.length,d=c+s+o.length+u.length,p=Math.min(d,m),f=Math.ceil(d/p),w=new Float32Array(p*f*4),y=(e,n)=>{w.set(n,e*4)},b=(e,n)=>{y(e,[n.l/l,n.t/h,(n.r-n.l)/l,(n.b-n.t)/h])};y(0,[s,o.length,u.length,0]);for(let[t,l]of n.slice(0,s).entries())y(1+2*t,[e(r,t),e(a,t),0,0]),b(2+2*t,i(l));return o.forEach((e,n)=>{b(1+2*s+n,e)}),u.forEach((e,n)=>{b(1+2*s+o.length+n,e)}),{values:c,data:w,dataWidth:p,dataHeight:f}}export{n as GLYPH_HELPER,c as buildGlyphs,l as withoutUnreadInk};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- var e=["image","video","text","shader","layer","model","group"],t=`:is(${e.map(e=>`[data-umber~=${e}]`).join()})`;var a=new Set(["data-umber","data-umber-effect","data-umber-shader","data-umber-layer","data-umber-instances"]),s=[...a,"style","class","hidden","media","disabled","data-umber-src","src","srcset","sizes","data-umber-occlude","data-umber-pass","data-umber-under"];var r="[data-umber-occlude]",n=t+","+r;var o=`${t}:not([data-umber-status="error"]),[data-umber-occlude]`;var i=()=>document.body;var d={scrub:"modules/scrub.js"};var l=(e,t)=>e[t]??NaN;function u(e){if(!e||typeof e.tagName!="string")return"<?>";let t=e.tagName.toLowerCase();if(e.id)return`<${t}#${e.id}>`;let a=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return a?`<${t}.${a}>`:`<${t}>`}var h=2;function m(e,t){let a="",s=h+1;for(let r of t){let t=c(e.toLowerCase(),r.toLowerCase());t<s&&(a=r,s=t)}return a}function c(e,t){let a=Array.from({length:t.length+1},(e,t)=>t);for(let s=1;s<=e.length;s++){let r=s-1;a[0]=s;for(let n=1;n<=t.length;n++){let o=l(a,n);a[n]=Math.min(o+1,l(a,n-1)+1,r+(e[s-1]===t[n-1]?0:1)),r=o}}return l(a,t.length)}var f=e=>!!e.backgroundImage&&e.backgroundImage!=="none"||!/^(transparent|rgba\(.*,\s*0\))$/.test(e.backgroundColor||"transparent"),p=["transform","translate","rotate","scale","perspective","filter","backdropFilter","clipPath","maskImage","webkitMaskImage"],b=e=>e.position!=="static"&&e.zIndex!=="auto"||/fixed|sticky/.test(e.position)||parseFloat(e.opacity)<1||p.some(t=>(e[t]||"none")!=="none")||e.isolation==="isolate"||(e.mixBlendMode||"normal")!=="normal"||/\b(layout|paint|strict|content)\b/.test(e.contain)||/^(size|inline-size)$/.test(e.containerType)||/\b(transform|translate|rotate|scale|perspective|filter|opacity|clip-path|mask|isolation|mix-blend-mode|contain)\b/.test(e.willChange),w=e=>e!==null&&e!==document.body&&e!==document.documentElement;function g(e,t){let a=parseInt(getComputedStyle(t).zIndex,10);if(!(a>0))return null;let s=null,r="auto",n=[];for(let t=e;w(t);t=t.parentElement){let a=getComputedStyle(t);f(a)&&!(t===e&&e.matches("[data-umber~=shader]"))&&n.push(t),b(a)&&(s=t,r=a.position!=="static"?a.zIndex:"auto")}return!s||r==="auto"||+r<a||!n.some(e=>s.contains(e))?null:`${u(s)} (z-index ${r}, with a background) covers Umber's canvas (z-index ${a}): GL inside it is hidden. Drop that z-index (and give it data-umber-occlude if it must still cover the GL elements before it) or move the background behind the content.`}var $="https://umber.occluze.com";var v={textureSource:()=>"umber.texture(source) needs a canvas, ImageBitmap, video, image, ImageData or { data, width, height }.",textureSize:()=>"umber.texture(numbers) needs their size: umber.texture({ data, width, height }), 1, 2 or 4 numbers per texel.",routerProtocol:e=>`umber.router.go(url): http(s) URLs only, not ${e}`};var y={textUnsupported:e=>`data-umber="text" stays normal DOM text: it uses ${e}, which GL text cannot paint. Remove data-umber="text" or that style.`,textOverflow:e=>`data-umber="text" stays normal DOM text: ${e?'its text runs past its box, down, and GL paints only the box. Let its height follow its lines (no fixed height), or put data-umber="text" on an element as tall as its text.':'its text runs past its box, and GL paints only the box. Let it wrap (overflow-wrap: anywhere), or put data-umber="text" on an element as wide as its text.'}`};var x=(e,t)=>{let a=m(e,t);return a?` (did you mean "${a}"?)`:""},k=(e,t)=>{if(e==="umber.css")return"Umber's canvas host is not fixed: umber.css is not on this page, so GL is off and the DOM shows. Link umber.css in <head> on every page.";let a=e.slice(e.lastIndexOf(" has ")+5).split(":")[0];return`${e}, which makes Umber's fixed canvas ${a==="zoom"?"scale":"scroll or turn"} with the page, so GL is off and the DOM shows. Move the ${a} to a wrapper element inside <body>${t?"":", or move the [data-umber-host] element out of it"}.`},L={disabled:"switched off (devices: false, data-umber-disable on <body>, or ?umber=off in the URL)","no-webgl2":"this browser has no WebGL2",device:'a device or screen this site keeps effects off (devices: "desktop" / data-umber-devices, or media / data-umber-media)',editor:"inside the Webflow Designer / Editor (createUmber({ designer: true }) runs it there)","forced-colors":"forced colours (Windows High Contrast) are on","reduced-motion":'the visitor prefers reduced motion and reducedMotion is "off"',"save-data":"the browser asks to save data (createUmber({ respectSaveData: false }) ignores that)",software:"WebGL draws on the processor here (no usable GPU), which would make the page slow (createUmber({ software: true }) or data-umber-software on <body> runs it anyway)",context:"a WebGL2 context could not be created","load-failed":"chunks/gl.js failed to load","load-timeout":"chunks/gl.js took more than 4 s to download",unlicensed:"this domain isn't on an Umber licence (list it under Umber in your occluze dashboard)","licence-unreachable":"the licence check got no clear answer from umber.occluze.com (unreachable, blocked, or chunks/licence.js didn't load)","context-lost":"the WebGL context was lost more than 8 times",error:"an error inside a GL frame (see the [umber] error before this)",server:"not in a browser",destroyed:"umber.destroy() was called"},G=e=>L[e]??e,U={...v,...y,host:k,reason:G,off:e=>`GL off: ${G(e)}`,effect:(e,t,a)=>`data-umber-effect="${t}" on ${u(e)}: no effect with that name${x(t,a)}. Define it first with umber.effect("${t}", {...}): Umber ships no effects ("Writing effects" in ${$}/docs.md). Known: ${a.join(", ")||"none yet"}.`,shader:(e,t,a)=>`data-umber="shader" on ${u(e)} needs data-umber-shader="name" and umber.shader("${t||"name"}", { fragment: "..." })${t?x(t,a):""}.`,glyph:()=>'glyph() is for data-umber="text" planes; on other planes it answers one line, word and character covering the whole element.',busy:e=>`createUmber({ busy }): "${e}" is not a selector; ignored.`,gpu:e=>`?umber-gpu=${e} is ignored: use 0-5, m0-m5, low, mid or high.`,segments:(e,t,a)=>`umber.effect("${e}"): segments: ${t} is more than a grid holds; it draws with ${a}.`,texture:e=>`${e}: a canvas, bitmap, video or numbers need umber.texture(source) from the input module (modules/input.js).`,own:e=>`module "${e}": plane.${e} is Umber's own. Rename the module.`,useTwice:e=>`umber.use(): a module named "${e}" is in use already; keeping the first one.`,use:()=>"umber.use(module) needs an Umber module (an object with a name), for example Scrub from @occluze/umber/scrub.",module:(e,t)=>{let a=t.charAt(0).toUpperCase()+t.slice(1);return`data-umber-${t} on ${u(e)}: no module "${t}". Load ${d[t]} next to umber.js, or umber.use(${a}) with import { ${a} } from "@occluze/umber/${t}".`},slow:e=>`A GL element took more than ${e}s to load, so its normal DOM image/text shows until it has loaded (slow network or a very large image? Use a smaller image).`,set:(e,t,a,s)=>`plane.set("${t}") on ${u(e)}: no effect on this plane has a uniform "${t}", so no shader reads it${x(t,a)}. Effects here: ${s}. Declare it in the effect's uniforms: { ${t}: 0 }.`,play:()=>'plane.play(): this plane has no effect with a `play` uniform. Add one (umber.effect(name, { play: "uShow", ... })) or use plane.tween(name, { value: 1 }).',fade:()=>"This [data-umber] image or video has an opacity of its own from a stylesheet (a fade, transition or animation). Umber hides it once GL draws it, so GL can't follow that opacity and draws it fully. Put the opacity on its parent, or set it inline (GSAP and Webflow Interactions do).",image:()=>"data-umber element has no image. Put an <img> inside it or set data-umber-src.",cors:(e,t)=>`${u(e)}: its image ${t} could not become a texture, so the DOM image shows (not found, or on another domain without CORS headers? Serve it with Access-Control-Allow-Origin, or from this site's own domain).`,ktx2:e=>`The KTX2 picture ${e} could not be transcoded, so the <img>'s own file is drawn instead (not found, not a Basis Universal KTX2, chunks/basis_transcoder.js and .wasm missing next to chunks/basis.js, or a Content-Security-Policy without worker-src blob: and 'wasm-unsafe-eval'?).`,oval:e=>`${u(e)}: its rounded corners have different shapes (across / down), and GL draws one shape for all of them, so its DOM shows. Give every rounded corner the same proportion, or use clip-path for the shape.`,webgl2:()=>"WebGL2 is not available here; the site runs without GL.",glsl:(e,t,a,s)=>{if(e==="link")return`shader link failed (${t}): ${a}`;let r=/ERROR: \d+:(\d+)/.exec(a),n=r?Number(r[1]):0,o=s.split(`\n`).map((e,t)=>`${String(t+1).padStart(4)}${t+1===n?" >":" "} ${e}`).slice(Math.max(0,n-6),n+3).join(`\n`);return`${e} shader error in "${t}":\n${a}\n${o}`},hostless:e=>`createUmber({ host: "${e}" }): no such element; Umber made its own canvas host.`,tween:e=>`An Umber tween needs a number in { value }, got ${JSON.stringify(e)}.`,trigger:e=>`Unknown play trigger "${String(e)}". Use auto (default), scroll, load, manual or hover.`,edge:e=>`play start "${String(e)}": the first word is the element's edge (top, center or bottom). Using "top".`,line:e=>`play start "${String(e)}": the second word is a line on the screen (top, center, bottom, 80% or 600px).`,ease:e=>`Unknown ease "${String(e)}". Use "umber" (default), "linear", "ease-out", "cubic-bezier(a, b, c, d)", "linear(0, 0.6 40%, 1)", "spring(0.3)", or quad/cubic/quart/quint/sine/expo/circ with .in, .out or .inOut (e.g. "expo.out").`,var:e=>`"${e}": its custom property is not set here. Set it, or give var() a fallback.`,losses:e=>`WebGL context lost ${e} times; the plain DOM shows for the rest of this visit. Too many or too large GL images? Use smaller images or fewer data-umber elements.`,lost:()=>"WebGL context lost; the DOM shows until it is restored.",devicesThrew:()=>"createUmber({ devices }) threw; GL stays off.",install:e=>`module "${e}" install failed`,handler:(e,t)=>`a ${e}"${t}" handler threw:`,undo:()=>"umber.scope(): cleaning up one of its objects failed",scopeFn:()=>"umber.scope(fn): fn threw (what it made before that is still in the scope)",scopeAsync:()=>"umber.scope(async fn): fn rejected",frame:()=>"a frame callback threw:",tracker:()=>"a tracker failed to measure its element",absent:(e,t)=>`${e}: ${typeof t=="string"?`nothing matches "${t}"`:"no element given"}.`,unplaced:e=>`${e}: the element is not in the page yet. Call it after the element is added.`,noViews:()=>"umber.attach() is not available in this build (no chunks/views.js).",version:(e,t,a)=>`modules/${e}.js ${t} with umber.js ${a}: load both from the same version.`,scroll:e=>`createUmber({ scroll }) ${e?"needs a Lenis instance, an element, or { y, velocity }":"got something Umber can't read"}. Using the window scroll instead.`,devices:e=>`createUmber({ devices: ${JSON.stringify(e)} }) is not "desktop", "all", false or a function; using "desktop".`,twice:e=>`createUmber() was called twice; returning the existing engine${e.length?`, without this call's ${e.join(", ")}`:""}. Call umber.destroy() first to start fresh.`,uniformImage:()=>"uniform texture failed",script:(e,t)=>`umber.js ${e} was loaded twice (Umber ${t} is already on the page); keeping the first copy.`,added:()=>"umber.add(): this element has data-umber already; returning its plane.",attachOff:e=>`umber.attach(): off on this device (${e})`,destroy:()=>"umber.destroy(el): no element given (a selector that found nothing?), so nothing was destroyed. umber.destroy() with no argument ends the engine.",change:(e,t)=>`${e?`<html> still matches "${e}"`:"umber.transition() was not ended"} after ${t} s, so Umber ended it. ${e?"Take that flag off":"Call the end() it returns"} once the new page is in.`,renderer:()=>"umber.attach(el, { renderer, scene, camera }) needs your THREE.WebGLRenderer as `renderer`.",view:()=>"umber.view() draws on Umber's canvas, which is off on this device (createUmber devices). umber.attach() with its own canvas can run this scene here.",define:e=>`gl.${e}(name, ${e==="chunk"?"glsl":"definition"}) needs a name and a ${e==="chunk"?"GLSL string":"definition object"}.`,loop:()=>"umber.render() was called while Umber runs its own loop (two loops?). Use createUmber({ loop: false }) to drive it yourself.",render:()=>"umber.render() was called twice in one frame (two loops call it?). Call it from one loop only, with the frame time in ms: gsap.ticker.add((t) => umber.render(t * 1000)).",captureDpr:(e,t,a)=>`Frame-by-frame capture: GL draws at DPR ${+t.toFixed(2)}, not ${e}: this GPU draws at most ${a} px a side. Export smaller for GL as sharp as the text.`,captureWait:(e,t)=>`Frame-by-frame capture: ${u(e)} still isn't drawn after ${t} s; frames no longer wait for it. umber.inspect(el) says why.`,coverBackground:(e,t,a,s)=>`data-umber-id: ${e} landed in ${t}, whose opaque background stacks over the canvas (z-index ${a} >= ${s}) and hides it. Raise the canvas (createUmber({ zIndex })) or move that background.`,coverBox:(e,t,a)=>`data-umber-id: ${e} landed under ${t} (z-index ${a}), which paints over the canvas and hides it. Fly to an element that shows, or raise the canvas (createUmber({ zIndex })).`,groupDraw:()=>'data-umber="group": three.js layers and planes that read uBackdrop draw on the canvas, not in their group.',targetBudget:(e,t)=>`render targets hold ${e} MB on the GPU (umber.info.targetMB), past this device's ${t} MB image budget. Make them smaller: sim sizes, data-umber-<effect>-scale on passes, fewer groups, umber.target() sizes.`,targetDraws:e=>`target.draw(): more than ${e} different GLSL sources; the oldest are compiled again when drawn again. Pass values that change as uniforms, not in the GLSL.`,targetType:e=>`umber.target({ type: "${e}" }): the types are "u8", "half" and "float"; it is "half".`,snapshotNone:e=>`umber.snapshot(): ${e===null?"this element":`"${e}"`} has no GL plane to copy (a [data-umber] image, video, text or shader; three.js layers render their own).`,snapshotLate:()=>"umber.snapshot(): the plane did not draw within 5 s (still loading, an error, or 0 px); nothing was copied.",leaveGlsl:()=>"umber.leave(glsl): define `vec4 leave(vec2 uv)` (prev(uv) is the old page, next(uv) the new one, uProgress 0 -> 1).",leavePasses:(e,t)=>`umber.leave(): data-umber-pass changed with the page ("${e}" -> "${t}"), so the old page leaves under the new passes. Keep the same data-umber-pass on both pages (on <html>, which routers leave alone).`,passEffect:e=>`data-umber-pass: no effect "${e}" (yet). Define it with umber.effect("${e}", {...}); until then the passes run without it.`,passBlend:(e,t,a)=>`data-umber-${e}-blend="${t}": the blends are ${a.join(", ")}; it is "normal". Other modes: write them in the effect's color slot.`,passVertex:e=>`data-umber-pass: "${e}" moves vertices; a pass is one flat surface, so its vertex code is left out.`,include:e=>`#include "${e}": no chunk has that name, so this element shows its DOM. Define it with umber.chunk("${e}", glsl).`,instances:(e,t)=>`data-umber-instances="${e}": ${t}, so it draws once. Write a count ("64"), "tiles 24x16", "chars", "words", "lines", "echo 6" or "ink 3000".`,instancesText:e=>`data-umber-instances="${e}" is for data-umber="text" planes (one quad per ${e.slice(0,-1)}); this one draws once.`,instancesInk:()=>`data-umber-instances="ink" seeds particles from an image, video or text plane's pixels; a shader surface has none to read, so it draws once.`,attribute:(e,t,a)=>`effect "${e}": attribute ${t} ${a?"is one too many (13 per plane)":"needs a size of 1 to 4 (a number, or a function returning 1 to 4 numbers)"}; it is left out.`,attributeNone:(e,t)=>`plane.instances: no attribute "${e}" (effects declare them: attributes: { ${e}: 2 }). It has: ${t.join(", ")||"none"}.`,layer:e=>`data-umber="layer" needs data-umber-layer="name" and umber.layer("${e||"name"}", { setup, render }).`,model:()=>'data-umber="model" is drawn by the three module: add modules/three.js (or umber.use(Three) from "@occluze/umber/three"). Its DOM shows meanwhile.',layerEffect:e=>`data-umber-effect is ignored on layers ("${e}"): a layer draws itself.`,occludeSeeThrough:e=>`data-umber-occlude on ${u(e)}: its background isn't opaque (or it is faded), so GL under it is cut where the page shows through. Give it an opaque background, or remove data-umber-occlude.`,occludeCorners:e=>`data-umber-occlude on ${u(e)}: its corners mix shapes (round and oval), so it cuts nothing (GL draws over it). Give all its corners the same shape.`,simCompile:()=>"umber.sim(): a pass did not compile (the shader log is above); this sim stays still.",simField:(e,t)=>`sim.field("${e}"): this sim has no field "${e}"; its fields are ${t.join(", ")}.`,brushField:(e,t)=>`umber.brush(): this sim has no field "${e}"; it paints "${t}".`,simNext:()=>"umber.sim(options) needs `next` (GLSL: vec4 next(vec2 uv) { ... }) or `passes` ([{ into, next }]).",simFields:()=>"umber.sim(): `fields` names no field; nothing was made.",simName:(e,t)=>`umber.sim(): "${e}" is not one of its fields (${t.join(", ")}), or not a GLSL name; nothing was made.`,unitProgress:e=>`plane.text.progress("${e}"): one per line or word only ("lines" or "words"); a character takes its word's (chars[i].word).`,text3d:()=>`data-umber="text": a 3D transform inside it is painted as drawn now (GL can't undo it). Animate with a glyph() effect instead.`,videoBlocked:e=>`${u(e)}: the browser blocked its video as a texture (a cross-origin video without CORS headers?), so the DOM video shows. Serve it with Access-Control-Allow-Origin, or from this site's own domain.`,videoFrames:e=>`${u(e)}: its video frames can't become a texture (a video on another domain without CORS headers?), so the DOM video shows. Serve it with Access-Control-Allow-Origin, or from this site's own domain.`,videoCors:(e,t)=>`${u(e)}: the video at ${t} is on another domain that sends no CORS headers, so it can't become a texture and the DOM video shows. Serve it with Access-Control-Allow-Origin (Webflow's CDN and Bunny do), or from this site's own domain.`,videoPlay:(e,t,a)=>`${u(e)}: the browser can't play its video ${t} (MediaError ${String(a)}), so the DOM video shows. Check the file, its codec (H.264) and that the server answers Range requests.`,three:()=>'umber.renderer(THREE) needs the three.js module itself: import * as THREE from "three"; umber.renderer(THREE).',rendererParams:e=>`umber.renderer(THREE, params): there is one renderer for the visit, made by the first call; these params differ from its and do nothing: ${e.join(", ")}. Pass them on the first call.`,viewRenderer:()=>"umber.view() draws with umber.renderer(THREE): call (and await) that first, or pass render(f) to draw yourself.",viewPlane:()=>"umber.view(el): this element already has a GL plane (data-umber); give the view its own element.",placeholderRead:e=>`umber.placeholder(): ${e} could not be read (not found, or another domain without CORS headers).`,placeholder:e=>`data-umber-placeholder="${e}" is not a placeholder Umber can read; make one with umber.placeholder(src).`,imageSize:(e,t,a,s)=>`${e} is ${t}x${a} px, over this GPU's ${s} px: it is drawn shrunk, so softer. Crop it, or point data-umber-src at a smaller file.`,imageBudget:(e,t,a,s)=>`Images near the screen take ${e} MB of GPU memory${t?`, render targets and video frames ${t} MB more`:""}, over this device's ${a} MB (umber.info.gpuMB). The largest images: ${s.join(", ")}. Serve smaller files (srcset and sizes, or data-umber-src).`};var M=(e,t)=>`${u(e.el)} has data-umber but is ${Math.round(e.doc.w)}\xd7${Math.round(e.doc.h)} px after ${t/1e3} s, so it draws nothing: hidden (display: none), or it has no size yet (an <img> without width/height, an empty box). Give it a size or aspect-ratio, or leave data-umber off hidden elements.`,O="The [data-umber-host] element left with a page swap and the new page has none, so Umber put it back first in <body>. Keep it across swaps (data-turbo-permanent, transition:persist, hx-preserve) or put one on every page.";function S(e,a){let s=typeof e=="string"?document.querySelector(e):e;if(s?.nodeType!==1)return a.log.warn(`umber.inspect(): ${typeof e=="string"?`nothing matches "${e}"`:"no element given"}.`),null;let r=s.matches(t)?s:s.closest(t)??s,n;a.stage?n=D(a.stage,r):n={el:r,kind:null,status:"none",drawn:!1,why:[j(a,r)]};let o=n.notes?.length?` (${n.notes.join("; ")})`:"",i=n.drawn?`drawn${o}`:`not drawn: ${n.why.join("; ")}${o}`;return console.log(`[umber] inspect ${u(r)}: ${i}`,n),n}function j(e,a){return e.off?`GL is off for this visit: ${U.reason(e.off)}`:e.loading?"the GL runtime (chunks/gl.js) is still loading":a.matches(t)?"GL has not started: no frame ran yet":"not a GL element: it has no data-umber attribute"}function D(e,t){let a=e.planes.of(t),s=R(e),r=[];if(!a)return s.push(T(t)),{el:t,kind:null,status:"none",drawn:!1,why:s,notes:r,source:"",tier:e.gpu.tier.tier,effects:[],uniforms:{},program:null,rect:null,inView:!1,near:!1,texture:"none",modules:[],clips:[],geometry:null};E(a,s,r),z(e,a,s);let n=e.chunks.shapes?.report(a,r)??[];a.backHidden&&!a.domReason&&s.push("its back faces the viewer (backface-visibility: hidden), like its DOM"),C(a,r);let o=a.size,i=a.rect;return{el:t,kind:a.kind,status:a.status,drawn:s.length===0&&a.status==="ready",why:s,notes:r,source:F(a,t),tier:q(e,a),effects:a.effects.map(e=>({name:e.name,options:{...e.options}})),uniforms:N(e,a),program:a.programKey?{key:a.programKey,ready:!!a.program?.ready()}:null,rect:{x:i[0],y:i[1],width:i[2],height:i[3]},inView:a.zone.screen,near:a.zone.near,texture:a.textureState,modules:a.modules.list.map(e=>e.name),clips:n,geometry:{transform:B(a.level),size:[o[0],o[1]],corners:H(a),live:K(e,a,performance.now())}}}function z(e,t,a){t.domReason?a.push(`its DOM shows: ${(t.domReason==="oval"?U.oval(t.geomEl):t.domReason).replace(/^<[^>]+>: /,"")}`):t.status==="error"||t.textureState==="error"?a.push("it gave up and shows its DOM (see its [umber] warning: load failed, CORS, slow load or a shader error)"):t.el.isConnected?A(e,t,a):a.push("it is not in the page")}function C(e,t){for(let a of e.nodes)a.tag!=="html"&&(a.filter!=="none"||a.backdropFilter!=="none")&&t.push(`${u(a.el)} has a CSS filter; GL draws the element without it`)}function R(e){return e.gpu.context.off?["GL stepped aside after an error (see the [umber] error above); the DOM shows for this visit"]:e.gpu.context.gone?["the WebGL context is lost; the DOM shows until the browser gives it back"]:e.canvasHost.reason?[`GL is off: ${U.host(e.canvasHost.reason,e.canvasHost.ownership==="created")}`]:e.scheduler.paused?[e.scheduler.pauses.has("forced")?"forced colours (High Contrast) are on: GL is paused":"umber.pause() was called (umber.resume() draws again)"]:[]}function T(e){return e.matches(t)?e.isConnected?i()?.hasAttribute("data-umber-disable")?"<body> has data-umber-disable":"no plane yet (it arrived this frame; or call umber.scan(el))":"it is not in the page":'not a GL element: its data-umber names no kind GL draws ("image", "video", "text", "shader", "layer", "model" or "group"), and it is not a umber.view() element'}function E(e,t,a){for(let s of e.missing)s.startsWith("shader:")?t.push(`its shader "${s.slice(7)}" is not defined: umber.shader("${s.slice(7)||"name"}", { fragment })`):s.startsWith("module:")?t.push(`it needs the "${s.slice(7)}" module: load ${d[s.slice(7)]??`modules/${s.slice(7)}.js`}`):s.startsWith("chunk:")?t.push(s[6]?`#include "${s.slice(6)}" names no chunk: umber.chunk("${s.slice(6)}", glsl)`:"chunks/glsl.js (#include, shared helper names) is still downloading; its DOM shows until then"):a.push(`effect "${s}" is not defined (umber.effect("${s}", {...})); it draws without it`)}function A(e,t,a){let s=t.measured&&(t.doc.w===0||t.doc.h===0);s&&a.push(`its box is ${Math.round(t.doc.w)}\xd7${Math.round(t.doc.h)} px (display: none, or no size yet)`);let r=P(e,t);if(r&&a.push(r),t.kind!=="layer"&&t.kind!=="shader"&&!t.texture?.ready){let r=W(e,t,s);r&&a.push(r)}t.shapeWait&&a.push("chunks/shapes.js (what cuts, turns or tilts it) is still downloading; its DOM shows until then");let n=s?null:I(e,t);n&&a.push(n),t.morphHidden&&a.push("a data-umber-id morph is drawing it right now (flying in)");let o=g(t.el,e.canvasHost.el);o&&a.push(o)}function P(e,t){return t.kind==="layer"?t.layer?.ready?null:e.chunks.layers?e.chunks.layers.waiting(t):"chunks/layers.js (three.js layers) is still downloading":e.chunks.ob.has(t)?"chunks/video.js (video and module frames) is still downloading; its DOM shows until then":e.chunks.La.has(t)?"chunks/text.js (GL text) is still downloading; its DOM shows until then":t.program?t.program.ready()?null:"its shader is still compiling; its DOM shows until then":"it has no shader program (a compile error? see the console)"}function W(e,t,a){return t.modules.feed?`waiting for the first frame from its module (${t.modules.list.map(e=>e.name).join(", ")})`:t.textureState==="none"?a?null:"its pixels have not started loading (it loads when it comes near the screen)":t.textureState==="queued"?"decoded, waiting for its GPU upload (one per frame)":t.kind==="video"?'its video has no frame yet (paused with preload="none", or still buffering)':t.kind==="text"&&!e.chunks.text?"chunks/text.js (GL text) is still downloading; the DOM text shows until then":`its ${t.kind==="text"?"text is being painted":"image is loading"}`}function I(e,t){let a=t.rect,s=window.innerWidth||e.env.frame.screen.width,r=window.innerHeight||e.env.frame.screen.height;if(t.opacity<=.001&&t.layer?.def.followOpacity!==!1)return"its opacity (or a parent's) is 0";if(!(a[0]<s&&a[0]+a[2]>0&&a[1]<r&&a[1]+a[3]>0)){let t=e.canvasHost.viewport,n=s!==t.width||r!==t.height?`; the canvas is ${t.width}\xd7${t.height}`:"";return`it is off screen (at ${Math.round(a[0])}, ${Math.round(a[1])} px; the screen is ${s}\xd7${r}${n})`}return t.clips?.ka&&e.chunks.shapes?e.chunks.shapes.ka(t.clips.ka):null}function B(e){return e===2?"3d":e===1?"2d":"none"}function H(e){let t=e.size,a=e._c,s=[],r=[[0,0],[t[0],0],[t[0],t[1]],[0,t[1]]];for(let[e,t]of r){let r=a[2]*e+a[5]*t+a[8];s.push([(a[0]*e+a[3]*t+a[6])/r,(a[1]*e+a[4]*t+a[7])/r])}return s}function N(e,t){let a={},s=t.program?.state==="ok"?t.program.uniforms:null;for(let[r,n]of Object.entries(t.uniforms)){let t=n.value,o=t;t instanceof e.env.kit.Texture?o=`texture ${t.width}\xd7${t.height}`:ArrayBuffer.isView(t)&&(o=Array.from(t)),a[r]={value:o,used:s?s.has(r):null}}return a}function F(e,t){if(e.kind==="shader")return`shader "${e.shader?.name??t.getAttribute("data-umber-shader")??""}"`;if(e.kind==="layer")return`layer "${e.layer?.name??""}"`;if(e.kind==="text")return"the element's text";if(e.kind==="group")return"the GL planes inside it (a group)";if(e.modules.feed)return`module ${e.modules.list.map(e=>e.name).join(", ")}`;let a=e.media,s=a instanceof HTMLVideoElement||a instanceof HTMLImageElement?a.currentSrc||a.src:"";return(t.getAttribute("data-umber-src")??"")||s}function q(e,t){let a="scrub"in t?t.scrub:void 0,s=typeof a=="object"&&a!==null&&"tier"in a?a.tier:void 0;return typeof s=="string"?`${e.gpu.tier.tier} \xb7 scrub ${s}`:e.gpu.tier.tier}function K(e,t,a){return t.animUntil>a?t.animUntil===1/0?t.animLabel:`${t.animLabel}, ${((t.animUntil-a)/1e3).toFixed(2)} s left`:t.scrollLinked?t.animLabel:t.el.hasAttribute("data-umber-live")?"data-umber-live":t.live?"a sticky or fixed parent":e.scheduler.Na(a)?"live mode (a page change, umber.live())":null}export{O as hostLeft,S as print,U as words,M as zero};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=["image","video","text","shader","layer","model","group"],t=`:is(${e.map(e=>`[data-umber~=${e}]`).join()})`;var s=new Set(["data-umber","data-umber-effect","data-umber-shader","data-umber-layer","data-umber-instances"]),a=[...s,"style","class","hidden","media","disabled","data-umber-src","src","srcset","sizes","data-umber-occlude","data-umber-pass","data-umber-under","data-umber-order"];var r="[data-umber-occlude]",n=t+","+r;var o=`${t}:not([data-umber-status="error"]),[data-umber-occlude]`;var i=()=>document.body;var d={scrub:"modules/scrub.js"};var l=(e,t)=>e[t]??NaN;function h(e){if(!e||typeof e.tagName!="string")return"<?>";let t=e.tagName.toLowerCase();if(e.id)return`<${t}#${e.id}>`;let s=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return s?`<${t}.${s}>`:`<${t}>`}var u=2;function m(e,t){let s="",a=u+1;for(let r of t){let t=c(e.toLowerCase(),r.toLowerCase());t<a&&(s=r,a=t)}return s}function c(e,t){let s=Array.from({length:t.length+1},(e,t)=>t);for(let a=1;a<=e.length;a++){let r=a-1;s[0]=a;for(let n=1;n<=t.length;n++){let o=l(s,n);s[n]=Math.min(o+1,l(s,n-1)+1,r+(e[a-1]===t[n-1]?0:1)),r=o}}return l(s,t.length)}var f=e=>!!e.backgroundImage&&e.backgroundImage!=="none"||!/^(transparent|rgba\(.*,\s*0\))$/.test(e.backgroundColor||"transparent"),p=["transform","translate","rotate","scale","perspective","filter","backdropFilter","clipPath","maskImage","webkitMaskImage"],b=e=>e.position!=="static"&&e.zIndex!=="auto"||/fixed|sticky/.test(e.position)||parseFloat(e.opacity)<1||p.some(t=>(e[t]||"none")!=="none")||e.isolation==="isolate"||(e.mixBlendMode||"normal")!=="normal"||/\b(layout|paint|strict|content)\b/.test(e.contain)||/^(size|inline-size)$/.test(e.containerType)||/\b(transform|translate|rotate|scale|perspective|filter|opacity|clip-path|mask|isolation|mix-blend-mode|contain)\b/.test(e.willChange),w=e=>e!==null&&e!==document.body&&e!==document.documentElement;function g(e,t){let s=parseInt(getComputedStyle(t).zIndex,10);if(!(s>0))return null;let a=null,r="auto",n=[];for(let t=e;w(t);t=t.parentElement){let s=getComputedStyle(t);f(s)&&!(t===e&&e.matches("[data-umber~=shader]"))&&n.push(t),b(s)&&(a=t,r=s.position!=="static"?s.zIndex:"auto")}if(!a||r==="auto"||+r<s)return null;let o=n.filter(e=>a.contains(e)),i=o.find(t=>t!==e)??o[0];return i?i===e?`its own background covers Umber's canvas (z-index ${s}): ${h(a)} around it (z-index ${r}) is above the canvas, so that background paints over what GL draws of it. Remove its background (GL draws the element itself), or drop that z-index.`:`${i===a?`${h(a)} (z-index ${r}, with a background) covers Umber's canvas (z-index ${s})`:`${h(a)} (z-index ${r}) is above Umber's canvas (z-index ${s}), and the background of ${h(i)} inside it covers Umber's canvas`}: GL inside it is hidden. Drop that z-index (and give it data-umber-occlude if it must still cover the GL elements before it) or move the background behind the content.`:null}var $="https://umber.occluze.com";var v={textureSource:()=>"umber.texture(source) needs a canvas, ImageBitmap, video, image, ImageData or { data, width, height }.",textureSize:()=>"umber.texture(numbers) needs their size: umber.texture({ data, width, height }), 1, 2 or 4 numbers per texel."};var y={textUnsupported:e=>`data-umber="text" stays normal DOM text: it uses ${e}, which GL text cannot paint. Remove data-umber="text" or that style.`,textOverflow:e=>`data-umber="text" stays normal DOM text: its text runs past its box${e?", down":""}, and GL paints only the box. Let ${e?"its height follow its lines (no fixed height)":"it wrap (overflow-wrap: anywhere)"}, or put data-umber="text" on an element as ${e?"tall":"wide"} as its text.`};var x=(e,t)=>{let s=m(e,t);return s?` (did you mean "${s}"?)`:""},k=e=>e.split("|").slice(1).filter(e=>e!=="normal").join(" "),L=(e,t)=>{if(e==="umber.css")return"Umber's canvas host is not fixed: umber.css is not on this page, so GL is off and the DOM shows. Link umber.css in <head> on every page.";let s=e.slice(e.lastIndexOf(" has ")+5).split(":")[0];return`${e}, which makes Umber's fixed canvas ${s==="zoom"?"scale":"scroll or turn"} with the page, so GL is off and the DOM shows. Move the ${s} to a wrapper element inside <body>${t?"":", or move the [data-umber-host] element out of it"}.`},G={text:'data-umber="text" stays normal DOM text.',layers:'three.js layers (data-umber="layer", umber.view()) stay off and keep their DOM content.',video:"GL videos and module elements show their DOM.",glsl:"planes whose effects #include a chunk or share a helper name show their DOM.",instances:"planes with instances show their DOM.",flip:"elements jump to their new place and pictures change at once.",fx:"render targets stay off and backdrop planes show their DOM.",warm:"nothing is loaded ahead and placeholders stay off.",morph:"data-umber-id images reveal on their own page instead of flying.",shapes:"GL elements cut, turned or tilted by CSS show their DOM. Serve chunks/shapes.js next to chunks/gl.js.",sim:"sims stay still and uFlow reads nothing.",restore:"the DOM shows for the rest of this visit.",capture:"frames wait for nothing.",glyphs:"planes whose effects call glyph() show their DOM."},M={disabled:"switched off (devices: false, data-umber-disable on <body>, or ?umber=off in the URL)","no-webgl2":"this browser has no WebGL2",device:'a device or screen this site keeps effects off (devices: "desktop" / data-umber-devices, or media / data-umber-media)',editor:"inside the Webflow Designer / Editor (createUmber({ designer: true }) runs it there)","forced-colors":"forced colours (Windows High Contrast) are on","reduced-motion":'the visitor prefers reduced motion and reducedMotion is "off"',"save-data":"the browser asks to save data (createUmber({ respectSaveData: false }) ignores that)",software:"WebGL draws on the processor here (no usable GPU), which would make the page slow (createUmber({ software: true }) or data-umber-software on <body> runs it anyway)",context:"a WebGL2 context could not be created","load-failed":"chunks/gl.js failed to load","load-timeout":"chunks/gl.js took more than 4 s to download",blocked:"Occluze has turned Umber off for this site, or the page kept removing or hiding the Occluze badge","context-lost":"the WebGL context was lost more than 8 times",error:"an error inside a GL frame (see the [umber] error before this)",server:"not in a browser",destroyed:"umber.destroy() was called"},O=e=>M[e]??e,U={...v,...y,host:L,reason:O,off:e=>`GL off: ${O(e)}`,effect:(e,t,s)=>`data-umber-effect="${t}" on ${h(e)}: no effect with that name${x(t,s)}. Define it first with umber.effect("${t}", {...}): Umber ships no effects ("Writing effects" in ${$}/docs.md). Known: ${s.join(", ")||"none yet"}.`,shader:(e,t,s)=>`data-umber="shader" on ${h(e)} needs data-umber-shader="name" and umber.shader("${t||"name"}", { fragment: "..." })${t?x(t,s):""}.`,glyph:()=>'glyph() is for data-umber="text" planes; on other planes it answers one line, word and character covering the whole element.',busy:e=>`createUmber({ busy }): "${e}" is not a selector; ignored.`,gpu:e=>`?umber-gpu=${e} is ignored: use 0-5, m0-m5, low, mid or high.`,segments:(e,t,s)=>`umber.effect("${e}"): segments: ${t} is more than a grid holds; it draws with ${s}.`,reserved:e=>`${e} is one of Umber's own uniforms, so a uniform or option of yours with that name is left out: your GLSL reads Umber's ${e}. Rename yours (in umber.shader() an option "radius" is uRadius: call it "corner"). The names: "What your GLSL can use" in https://umber.occluze.com/docs.md.`,texture:e=>`${e}: a canvas, bitmap, video or numbers need umber.texture(source) from the input module (modules/input.js).`,own:e=>`module "${e}": plane.${e} is Umber's own. Rename the module.`,useTwice:e=>`umber.use(): a module named "${e}" is in use already; keeping the first one.`,use:()=>"umber.use(module) needs an Umber module (an object with a name), for example Scrub from @occluze/umber/scrub.",module:(e,t)=>{let s=t.charAt(0).toUpperCase()+t.slice(1);return`data-umber-${t} on ${h(e)}: no module "${t}". Load ${d[t]} next to umber.js, or umber.use(${s}) with import { ${s} } from "@occluze/umber/${t}".`},slow:e=>`A GL element took more than ${e}s to load, so its normal DOM image/text shows until it has loaded (slow network or a very large image? Use a smaller image).`,set:(e,t,s,a)=>`plane.set("${t}") on ${h(e)}: no effect on this plane has a uniform "${t}", so no shader reads it${x(t,s)}. Effects here: ${a}. Declare it in the effect's uniforms: { ${t}: 0 }.`,play:()=>'plane.play(): this plane has no effect with a `play` uniform. Add one (umber.effect(name, { play: "uShow", ... })) or use plane.tween(name, { value: 1 }).',fade:()=>"This [data-umber] image or video has an opacity of its own from a stylesheet (a fade, transition or animation). Umber hides it once GL draws it, so GL can't follow that opacity and draws it fully. Put the opacity on its parent, or set it inline (animation libraries and site builders' interactions do).",image:()=>"data-umber element has no image. Put an <img> inside it or set data-umber-src.",cors:(e,t)=>`${h(e)}: its image ${t} could not become a texture, so the DOM image shows (not found, or on another domain without CORS headers? Serve it with Access-Control-Allow-Origin, or from this site's own domain).`,ktx2:e=>`The KTX2 picture ${e} could not be transcoded, so the <img>'s own file is drawn instead (not found, not a Basis Universal KTX2, chunks/basis_transcoder.js and .wasm missing next to chunks/basis.js, or a Content-Security-Policy without worker-src blob: and 'wasm-unsafe-eval'?).`,oval:e=>`${h(e)}: its rounded corners have different shapes (across / down), and GL draws one shape for all of them, so its DOM shows. Give every rounded corner the same proportion, or use clip-path for the shape.`,webgl2:()=>"WebGL2 is not available here; the site runs without GL.",glsl:(e,t,s,a)=>{if(e==="link")return`shader link failed (${t}): ${s}`;let r=/ERROR: \d+:(\d+)/.exec(s),n=r?Number(r[1]):0,o=a.split(`\n`).map((e,t)=>`${String(t+1).padStart(4)}${t+1===n?" >":" "} ${e}`).slice(Math.max(0,n-6),n+3).join(`\n`);return`${e} shader error in "${t}":\n${s}\n${o}`},hostless:e=>`createUmber({ host: "${e}" }): no such element; Umber made its own canvas host.`,tween:e=>`An Umber tween needs a number in { value }, got ${JSON.stringify(e)}.`,trigger:e=>`Unknown play trigger "${String(e)}". Use auto (default), scroll, load, manual or hover.`,edge:e=>`play start "${String(e)}": the first word is the element's edge (top, center or bottom). Using "top".`,line:e=>`play start "${String(e)}": the second word is a line on the screen (top, center, bottom, 80% or 600px).`,ease:e=>`Unknown ease "${String(e)}". Use "umber" (default), "linear", "ease-out", "cubic-bezier(a, b, c, d)", "linear(0, 0.6 40%, 1)", "spring(0.3)", or quad/cubic/quart/quint/sine/expo/circ with .in, .out or .inOut (e.g. "expo.out").`,var:e=>`"${e}": its custom property is not set here. Set it, or give var() a fallback.`,losses:e=>`WebGL context lost ${e} times; the plain DOM shows for the rest of this visit. Too many or too large GL images? Use smaller images or fewer data-umber elements.`,lost:()=>"WebGL context lost; the DOM shows until it is restored.",devicesThrew:()=>"createUmber({ devices }) threw; GL stays off.",install:e=>`module "${e}" install failed`,handler:(e,t)=>`a ${e}"${t}" handler threw:`,undo:()=>"umber.scope(): cleaning up one of its objects failed",scopeFn:()=>"umber.scope(fn): fn threw (what it made before that is still in the scope)",scopeAsync:()=>"umber.scope(async fn): fn rejected",frame:()=>"a frame callback threw:",awake:e=>`A umber.on("frame", fn) callback has kept the page drawing frames for ${e} s while nothing else asked for one. It runs every frame until it is taken off: call off() when its work is done (fn's second argument, or what umber.on() returned), pass { el } so it runs only while that element is on or near the screen, or { always: false } to ride along on the frames Umber draws anyway.`,failed:e=>`GL ${e} failed; the plain DOM shows for the rest of this visit.`,threw:e=>`${h(e)}: an error while Umber made, measured or drew this element (below), so it shows its DOM from here on; every other GL element draws on. If the error comes from a value or an effect of yours, fix that; if it is Umber's own, please report it.`,partThrew:e=>`${e}: an error while Umber drew it (below), so it is off from here on; the page's GL elements draw on. If the error comes from a value or GLSL of yours, fix that; if it is Umber's own, please report it.`,tracker:()=>"a tracker failed to measure its element",absent:(e,t)=>`${e}: ${typeof t=="string"?`nothing matches "${t}"`:"no element given"}.`,unplaced:e=>`${e}: the element is not in the page yet. Call it after the element is added.`,version:(e,t,s)=>`modules/${e}.js ${t} with umber.js ${s}: load both from the same version.`,scroll:()=>"createUmber({ scroll }) takes the element that scrolls, or nothing for the window. A smooth scroller needs no option: Umber reads where it puts the page. Using the window scroll instead.",devices:e=>`createUmber({ devices: ${JSON.stringify(e)} }) is not "desktop", "all", false or a function; using "desktop".`,twice:e=>`createUmber() was called twice; returning the existing engine${e.length?`, without this call's ${e.join(", ")}`:""}. Call umber.destroy() first to start fresh.`,uniformImage:()=>"uniform texture failed",script:(e,t)=>`umber.js ${e} was loaded twice (Umber ${t} is already on the page); keeping the first copy.`,added:()=>"umber.add(): this element has data-umber already; returning its plane.",destroy:()=>"umber.destroy(el): no element given (a selector that found nothing?), so nothing was destroyed. umber.destroy() with no argument ends the engine.",change:(e,t)=>`${e?`<html> still matches "${e}"`:"umber.transition() was not ended"} after ${t} s, so Umber ended it: reveals play and the planes are measured as on a still page. If the change is over, ${e?"take that flag off":"call the end() it returns"} once the new page is in. If it is still running, it needs more time than Umber gives it: ${e?"start it with umber.transition(next, { timeout: 20 }) in place of busy":"umber.transition(next, { timeout: 20 })"} gives it 20 s.`,view:()=>"umber.view() draws on Umber's canvas, which is off on this device (createUmber devices), so this scene is not drawn here.",define:e=>`gl.${e}(name, ${e==="chunk"?"glsl":"definition"}) needs a name and a ${e==="chunk"?"GLSL string":"definition object"}.`,chunkGone:(e,t)=>`${e}; ${G[t]}`,captureDpr:(e,t,s)=>`Frame-by-frame capture: GL draws at DPR ${+t.toFixed(2)}, not ${e}: this GPU draws at most ${s} px a side. Export smaller for GL as sharp as the text.`,captureWait:(e,t)=>`Frame-by-frame capture: ${h(e)} still isn't drawn after ${t} s; frames no longer wait for it. umber.inspect(el) says why.`,textSplit:()=>'data-umber="text" is split in the DOM: GL paints it at rest and its DOM units stay transparent. Animate with a glyph() effect; keep the DOM animation for when GL is off.',coverBackground:(e,t,s,a)=>`data-umber-id: ${e} landed in ${t}, whose opaque background stacks over the canvas (z-index ${s} >= ${a}) and hides it. Raise the canvas (createUmber({ zIndex })) or move that background.`,coverBox:(e,t,s)=>`data-umber-id: ${e} landed under ${t} (z-index ${s}), which paints over the canvas and hides it. Fly to an element that shows, or raise the canvas (createUmber({ zIndex })).`,groupDraw:()=>'data-umber="group": three.js layers and planes that read uBackdrop draw on the canvas, not in their group.',targetBudget:(e,t)=>`render targets hold ${e} MB on the GPU (umber.info.targetMB), past this device's ${t} MB image budget. Make them smaller: sim sizes, data-umber-<effect>-scale on passes, fewer groups, umber.target() sizes.`,targetDraws:e=>`target.draw(): more than ${e} different GLSL sources; the oldest are compiled again when drawn again. Pass values that change as uniforms, not in the GLSL.`,targetType:e=>`umber.target({ type: "${e}" }): the types are "u8", "half" and "float"; it is "half".`,snapshotNone:e=>`umber.snapshot(): ${e===null?"this element":`"${e}"`} has no GL plane to copy (a [data-umber] image, video, text or shader; three.js layers render their own).`,snapshotLate:()=>"umber.snapshot(): the plane did not draw within 5 s (still loading, an error, or 0 px); nothing was copied.",leaveGlsl:()=>"umber.leave(glsl): define `vec4 leave(vec2 uv)` (prev(uv) is the old page, next(uv) the new one, uProgress 0 -> 1).",leavePasses:(e,t)=>`umber.leave(): data-umber-pass changed with the page ("${e}" -> "${t}"), so the old page leaves under the new passes. Keep the same data-umber-pass on both pages (on <html>, which routers leave alone).`,passEffect:e=>`data-umber-pass: no effect "${e}" (yet). Define it with umber.effect("${e}", {...}); until then the passes run without it.`,passBlend:(e,t,s)=>`data-umber-${e}-blend="${t}": the blends are ${s.join(", ")}; it is "normal". Other modes: write them in the effect's color slot.`,passVertex:e=>`data-umber-pass: "${e}" moves vertices; a pass is one flat surface, so its vertex code is left out.`,include:e=>`#include "${e}": no chunk has that name, so this element shows its DOM. Define it with umber.chunk("${e}", glsl).`,instances:(e,t)=>`data-umber-instances="${e}": ${t}, so it draws once. Write a count ("64"), "tiles 24x16", "chars", "words", "lines", "echo 6" or "ink 3000".`,instancesText:e=>`data-umber-instances="${e}" is for data-umber="text" planes (one quad per ${e.slice(0,-1)}); this one draws once.`,instancesInk:()=>`data-umber-instances="ink" seeds particles from an image, video or text plane's pixels; a shader surface has none to read, so it draws once.`,attribute:(e,t,s)=>`effect "${e}": attribute ${t} ${s?"is one too many (13 per plane)":"needs a size of 1 to 4 (a number, or a function returning 1 to 4 numbers)"}; it is left out.`,fontNotPrepared:(e,t)=>`GL text asks for "${e.split("|")[0]}" ${k(e)}, and only ${t.map(k).join(", ")} ${t.length>1?"are":"is"} prepared, so it is drawn from the glyph atlas (the browser's own painting of each word: less sharp when scaled or animated). A prepared font is matched by family, weight and style: give the build that face (an @font-face rule with its file in the site), or use a prepared weight.`,textSoft:e=>`GL text drawn ${e.toFixed(1)} times larger than it was painted, from the glyph atlas: soft while it moves (it is painted again once it rests). A prepared font is drawn from its outlines, sharp in any motion: give the build the font's file.`,lettersWhole:()=>`data-umber-instances="chars": this text holds right-to-left text, which cannot be drawn letter by letter, so each quad is a character's box and shows the text's picture there (ink outside the box is cut, and unitScale, unitTurn and unitAlpha move boxes, not letters).`,attributeNone:(e,t)=>`plane.instances: no attribute "${e}" (effects declare them: attributes: { ${e}: 2 }). It has: ${t.join(", ")||"none"}.`,layer:e=>`data-umber="layer" needs data-umber-layer="name" and umber.layer("${e||"name"}", { setup, render }).`,model:()=>'data-umber="model" is drawn by the three module: add modules/three.js (or umber.use(Three) from "@occluze/umber/three"). Its DOM shows meanwhile.',layerEffect:e=>`data-umber-effect is ignored on layers ("${e}"): a layer draws itself.`,occludeSeeThrough:e=>`data-umber-occlude on ${h(e)}: its background isn't opaque (or it is faded), so GL under it is cut where the page shows through. Give it an opaque background, or remove data-umber-occlude.`,occludeCorners:e=>`data-umber-occlude on ${h(e)}: its corners mix shapes (round and oval), so it cuts nothing (GL draws over it). Give all its corners the same shape.`,simCompile:()=>"umber.sim(): a pass did not compile (the shader log is above); this sim stays still.",simField:(e,t)=>`sim.field("${e}"): this sim has no field "${e}"; its fields are ${t.join(", ")}.`,brushField:(e,t)=>`umber.brush(): this sim has no field "${e}"; it paints "${t}".`,simNext:()=>"umber.sim(options) needs `next` (GLSL: vec4 next(vec2 uv) { ... }) or `passes` ([{ into, next }]).",simFields:()=>"umber.sim(): `fields` names no field; nothing was made.",simName:(e,t)=>`umber.sim(): "${e}" is not one of its fields (${t.join(", ")}), or not a GLSL name; nothing was made.`,unitProgress:e=>`plane.text.progress("${e}"): one per line or word only ("lines" or "words"); a character takes its word's (chars[i].word).`,text3d:()=>`data-umber="text": a 3D transform inside it is painted as drawn now (GL can't undo it). Animate with a glyph() effect instead.`,videoBlocked:e=>`${h(e)}: the browser blocked its video as a texture (a cross-origin video without CORS headers?), so the DOM video shows. Serve it with Access-Control-Allow-Origin, or from this site's own domain.`,videoFrames:e=>`${h(e)}: its video frames can't become a texture (a video on another domain without CORS headers?), so the DOM video shows. Serve it with Access-Control-Allow-Origin, or from this site's own domain.`,videoCors:(e,t)=>`${h(e)}: the video at ${t} is on another domain that sends no CORS headers, so it can't become a texture and the DOM video shows. Serve it with Access-Control-Allow-Origin (Webflow's CDN and Bunny do), or from this site's own domain.`,videoPlay:(e,t,s)=>`${h(e)}: the browser can't play its video ${t} (MediaError ${String(s)}), so the DOM video shows. Check the file, its codec (H.264) and that the server answers Range requests.`,three:()=>'umber.renderer(THREE) needs the three.js module itself: import * as THREE from "three"; umber.renderer(THREE).',rendererParams:e=>`umber.renderer(THREE, params): there is one renderer for the visit, made by the first call; these params differ from its and do nothing: ${e.join(", ")}. Pass them on the first call.`,viewRenderer:()=>"umber.view() draws with umber.renderer(THREE): call (and await) that first, or pass render(f) to draw yourself.",viewPlane:()=>"umber.view(el): this element already has a GL plane (data-umber); give the view its own element.",placeholderRead:e=>`umber.placeholder(): ${e} could not be read (not found, or another domain without CORS headers).`,placeholder:e=>`data-umber-placeholder="${e}" is not a placeholder Umber can read; make one with umber.placeholder(src).`,imageSize:(e,t,s,a)=>`${e} is ${t}x${s} px, over this GPU's ${a} px: it is drawn shrunk, so softer. Crop it, or point data-umber-src at a smaller file.`,imageBudget:(e,t,s,a)=>`Images near the screen take ${e} MB of GPU memory${t?`, render targets and video frames ${t} MB more`:""}, over this device's ${s} MB (umber.info.gpuMB). The largest images: ${a.join(", ")}. Serve smaller files (srcset and sizes, or data-umber-src).`};var S=(e,t)=>`${h(e.el)} has data-umber but is ${Math.round(e.doc.w)}\xd7${Math.round(e.doc.h)} px after ${t/1e3} s, so it draws nothing: hidden (display: none), or it has no size yet (an <img> without width/height, an empty box). Give it a size or aspect-ratio, or leave data-umber off hidden elements.`,D="The [data-umber-host] element left with a page swap and the new page has none, so Umber put it back first in <body>. Keep it across swaps (data-turbo-permanent, transition:persist, hx-preserve) or put one on every page.";function j(e,s){let a=typeof e=="string"?document.querySelector(e):e;if(a?.nodeType!==1)return s.log.warn(`umber.inspect(): ${typeof e=="string"?`nothing matches "${e}"`:"no element given"}.`),null;let r=a.matches(t)?a:a.closest(t)??a,n;s.stage?n=C(s.stage,r):n={el:r,kind:null,status:"none",drawn:!1,why:[z(s,r)]};let o=n.notes?.length?` (${n.notes.join("; ")})`:"",i=n.drawn?`drawn${o}`:`not drawn: ${n.why.join("; ")}${o}`;return console.log(`[umber] inspect ${h(r)}: ${i}`,n),n}function z(e,s){return e.off?`GL is off for this visit: ${U.reason(e.off)}`:e.loading?"the GL runtime (chunks/gl.js) is still loading":s.matches(t)?"GL has not started: no frame ran yet":"not a GL element: it has no data-umber attribute"}function C(e,t){let s=e.planes.of(t),a=T(e),r=[];if(!s)return a.push(I(t)),{el:t,kind:null,status:"none",drawn:!1,why:a,notes:r,source:"",tier:e.gpu.tier.tier,effects:[],uniforms:{},program:null,rect:null,inView:!1,near:!1,texture:"none",modules:[],clips:[],geometry:null};E(s,a,r),R(e,s,a);let n=e.chunks.shapes?.report(s,r)??[];s.backHidden&&!s.domReason&&a.push("its back faces the viewer (backface-visibility: hidden), like its DOM"),A(s,r);let o=s.size,i=s.rect;return{el:t,kind:s.kind,status:s.status,drawn:a.length===0&&s.status==="ready",why:a,notes:r,source:K(s,t),tier:V(e,s),effects:s.effects.map(e=>({name:e.name,options:{...e.options}})),uniforms:q(e,s),program:s.programKey?{key:s.programKey,ready:!!s.program?.ready()}:null,rect:{x:i[0],y:i[1],width:i[2],height:i[3]},inView:s.zone.screen,near:s.zone.near,texture:s.textureState,modules:s.modules.list.map(e=>e.name),clips:n,geometry:{transform:F(s.level),size:[o[0],o[1]],corners:N(s),live:J(e,s,performance.now())}}}function R(e,t,s){t.domReason?s.push(`its DOM shows: ${(t.domReason==="oval"?U.oval(t.geomEl):t.domReason).replace(/^<[^>]+>: /,"")}`):t.status==="error"||t.textureState==="error"?s.push("it gave up and shows its DOM (see its [umber] warning: load failed, CORS, slow load or a shader error)"):t.el.isConnected?W(e,t,s):s.push("it is not in the page")}function A(e,t){for(let s of e.nodes)s.tag!=="html"&&(s.filter!=="none"||s.backdropFilter!=="none")&&t.push(`${h(s.el)} has a CSS filter; GL draws the element without it`)}function T(e){return e.gpu.context.off?["GL stepped aside after an error (see the [umber] error above); the DOM shows for this visit"]:e.gpu.context.gone?["the WebGL context is lost; the DOM shows until the browser gives it back"]:e.canvasHost.reason?[`GL is off: ${U.host(e.canvasHost.reason,e.canvasHost.ownership==="created")}`]:e.scheduler.paused?[e.scheduler.pauses.has("forced")?"forced colours (High Contrast) are on: GL is paused":"umber.pause() was called (umber.resume() draws again)"]:[]}function I(e){return e.matches(t)?e.isConnected?i()?.hasAttribute("data-umber-disable")?"<body> has data-umber-disable":"no plane yet (it arrived this frame; or call umber.scan(el))":"it is not in the page":'not a GL element: its data-umber names no kind GL draws ("image", "video", "text", "shader", "layer", "model" or "group"), and it is not a umber.view() element'}function E(e,t,s){for(let a of e.missing)a.startsWith("shader:")?t.push(`its shader "${a.slice(7)}" is not defined: umber.shader("${a.slice(7)||"name"}", { fragment })`):a.startsWith("module:")?t.push(`it needs the "${a.slice(7)}" module: load ${d[a.slice(7)]??`modules/${a.slice(7)}.js`}`):a.startsWith("chunk:")?t.push(a[6]?`#include "${a.slice(6)}" names no chunk: umber.chunk("${a.slice(6)}", glsl)`:"chunks/glsl.js (#include, shared helper names) is still downloading; its DOM shows until then"):s.push(`effect "${a}" is not defined (umber.effect("${a}", {...})); it draws without it`)}function W(e,t,s){let a=t.measured&&(t.doc.w===0||t.doc.h===0);a&&s.push(`its box is ${Math.round(t.doc.w)}\xd7${Math.round(t.doc.h)} px (display: none, or no size yet)`);let r=B(e,t);if(r&&s.push(r),t.kind!=="layer"&&t.kind!=="shader"&&!t.texture?.ready){let r=P(e,t,a);r&&s.push(r)}t.shapeWait&&s.push("chunks/shapes.js (what cuts, turns or tilts it) is still downloading; its DOM shows until then");let n=a?null:H(e,t);n&&s.push(n),t.morphHidden&&s.push("a data-umber-id morph is drawing it right now (flying in)");let o=g(t.el,e.canvasHost.el);o&&s.push(o)}function B(e,t){return t.kind==="layer"?t.layer?.ready?null:e.chunks.layers?e.chunks.layers.waiting(t):"chunks/layers.js (three.js layers) is still downloading":e.chunks.Ml.has(t)?"chunks/video.js (video and module frames) is still downloading; its DOM shows until then":e.chunks.ae.has(t)?"chunks/text.js (GL text) is still downloading; its DOM shows until then":t.program?t.program.ready()?null:"its shader is still compiling; its DOM shows until then":"it has no shader program (a compile error? see the console)"}function P(e,t,s){return t.modules.feed?`waiting for the first frame from its module (${t.modules.list.map(e=>e.name).join(", ")})`:t.textureState==="none"?s?null:"its pixels have not started loading (it loads when it comes near the screen)":t.textureState==="queued"?"decoded, waiting for its GPU upload (one per frame)":t.kind==="video"?'its video has no frame yet (paused with preload="none", or still buffering)':t.kind==="text"&&!e.chunks.text?"chunks/text.js (GL text) is still downloading; the DOM text shows until then":`its ${t.kind==="text"?"text is being painted":"image is loading"}`}function H(e,t){let s=t.measured?null:t.el.getBoundingClientRect(),a=s?[s.x,s.y,s.width,s.height]:t.rect,r=window.innerWidth||e.env.frame.screen.width,n=window.innerHeight||e.env.frame.screen.height;if(t.opacity<=.001&&t.layer?.def.followOpacity!==!1)return"its opacity (or a parent's) is 0";if(!(a[0]<r&&a[0]+a[2]>0&&a[1]<n&&a[1]+a[3]>0)){let t=e.canvasHost.viewport,s=r!==t.width||n!==t.height?`; the canvas is ${t.width}\xd7${t.height}`:"";return`it is off screen (at ${Math.round(a[0])}, ${Math.round(a[1])} px; the screen is ${r}\xd7${n}${s})`}return t.clips?.Sh&&e.chunks.shapes?e.chunks.shapes.Sh(t.clips.Sh):null}function F(e){return e===2?"3d":e===1?"2d":"none"}function N(e){let t=e.size,s=e._s,a=[],r=[[0,0],[t[0],0],[t[0],t[1]],[0,t[1]]];for(let[e,t]of r){let r=s[2]*e+s[5]*t+s[8];a.push([(s[0]*e+s[3]*t+s[6])/r,(s[1]*e+s[4]*t+s[7])/r])}return a}function q(e,t){let s={},a=t.program?.state==="ok"?t.program.uniforms:null;for(let[r,n]of Object.entries(t.uniforms)){let t=n.value,o=t;t instanceof e.env.kit.Texture?o=`texture ${t.width}\xd7${t.height}`:ArrayBuffer.isView(t)&&(o=Array.from(t)),s[r]={value:o,used:a?a.has(r):null}}return s}function K(e,t){if(e.kind==="shader")return`shader "${e.shader?.name??t.getAttribute("data-umber-shader")??""}"`;if(e.kind==="layer")return`layer "${e.layer?.name??""}"`;if(e.kind==="text")return"the element's text";if(e.kind==="group")return"the GL planes inside it (a group)";if(e.modules.feed)return`module ${e.modules.list.map(e=>e.name).join(", ")}`;let s=e.media,a=s instanceof HTMLVideoElement||s instanceof HTMLImageElement?s.currentSrc||s.src:"";return(t.getAttribute("data-umber-src")??"")||a}function V(e,t){let s="scrub"in t?t.scrub:void 0,a=typeof s=="object"&&s!==null&&"tier"in s?s.tier:void 0;return typeof a=="string"?`${e.gpu.tier.tier} \xb7 scrub ${a}`:e.gpu.tier.tier}function J(e,t,s){return t.animUntil>s?t.animUntil===1/0?t.animLabel:`${t.animLabel}, ${((t.animUntil-s)/1e3).toFixed(2)} s left`:t.scrollLinked?t.animLabel:t.el.hasAttribute("data-umber-live")?"data-umber-live":t.live?"a sticky or fixed parent":e.scheduler.Ug(s)?"live mode (a page change, umber.live())":null}export{D as hostLeft,j as print,U as words,S as zero};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- var t=()=>{};var e=()=>Promise.reject(new Error("no words"));var n={configure:t,debug:!1,warnings:!1,info:t,warn:t,error:t,report:t,words:e},i=n;function s(t){i=t}function r(t){if(typeof t=="number"||typeof t=="boolean")return"float";if(Array.isArray(t)||ArrayBuffer.isView(t)){let e=t.length;return e===2?"vec2":e===3?"vec3":e===4?"vec4":e===9?"mat3":e===16?"mat4":null}return typeof t=="string"?"sampler2D":t&&typeof t=="object"?"highp sampler2D":null}var a=/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g;function o(t){let e=t.replace(/\\n/g,`\n`).replace(a," ");return t=>new RegExp(`\\buniform\\b[^;]*\\b${t}\\b`).test(e)}var u=3,l=["float","vec2","vec3","vec4"],h="gl_Position = vec4(0.0, 0.0, 2.0, 1.0); return;";function c(t,e,n){let i=e.mode,s=i==="chars"||i==="words"||i==="lines",a=`uniform float uInstances;\nuniform float uUmberWhole;\nuniform vec4 uUmberInst;\nfloat instance;\n`,u=a+`flat out float vUmberInstance;\n`,c=a+`flat in float vUmberInstance;\n`,f=`instance = float(gl_InstanceID);\n${i==="echo"?`instance = uInstances - 1.0 - instance;\n`:""}vUmberInstance = instance;\n`,d=`instance = vUmberInstance;\n`;if(i==="tiles"){let t=`tile = vec4(mod(instance, uUmberInst.x), floor(instance / uUmberInst.x), uUmberInst.xy);\ntileCenter = (tile.xy + 0.5) / tile.zw;\n`;u+=`vec4 tile;\nvec2 tileCenter;\n`,c+=`vec4 tile;\nvec2 tileCenter;\n`,f+=`${t}uv = (tile.xy + aPosition) / tile.zw;\nvUv = uv;\n`,d+=t}else if(s)u+=`layout(location = 1) in vec4 unitBox;\nlayout(location = 2) in vec4 unitValue;\nflat out vec4 vUmberBox;\nflat out vec4 vUmberUnit;\n`,c+=`flat in vec4 vUmberBox;\nflat in vec4 vUmberUnit;\nvec4 unitBox;\nvec4 unitValue;\n`,f+=`vUmberBox = unitBox;\nvUmberUnit = unitValue;\nif (uUmberWhole < 0.5) {\n uv = unitBox.xy + aPosition * unitBox.zw;\n vUv = uv;\n}\n`,d+=`unitBox = vUmberBox;\nunitValue = vUmberUnit;\n`;else if(i==="echo")u+=`layout(location = 1) in vec2 echoOffset;\nflat out vec2 vUmberEcho;\n`,c+=`flat in vec2 vUmberEcho;\nvec2 echoOffset;\n`,f+=`vUmberEcho = echoOffset;\nif (instance > 0.5 && dot(echoOffset, echoOffset) < 0.0025) { ${h} }\npos.xy += echoOffset;\n`,d+=`echoOffset = vUmberEcho;\n`;else if(i==="points"){let t=`vec4 point;\nvec4 umberPoint(float i) {\n uvec4 v = uvec4(uint(i)) * uvec4(1664525u, 22695477u, 134775813u, 1103515245u) + uvec4(1013904223u, 2891336453u, 2531011u, 12345u);\n v ^= v >> 16u; v *= 0x45d9f3bu; v ^= v >> 16u; v *= 0x45d9f3bu; v ^= v >> 16u;\n return vec4(v) / 4294967295.0;\n}\n`;u+=`${t}vec2 pointUv;\nout vec2 vUmberPointUv;\n`,c+=`${t}vec2 pointUv;\nin vec2 vUmberPointUv;\n`,f+=`point = umberPoint(instance);\npointUv = aPosition;\nvUmberPointUv = aPosition;\nuv = point.xy + (aPosition - 0.5) * uUmberInst.x / uSize;\nvUv = uv;\n`,d+=`point = umberPoint(instance);\npointUv = vUmberPointUv;\n`}else if(i==="ink"){let t=t=>`int umberW = int(uUmberInst.y);\ninkPoint = texelFetch(uUmberInk, ivec2(${t} % umberW, ${t} / umberW), 0);\n`,e=`uniform highp sampler2D uUmberInk;\nvec4 inkPoint;\n`;u+=e,c+=e,f+=`${t("gl_InstanceID")}if (uUmberWhole < 0.5) {\n if (inkPoint.w < 0.5) { ${h} }\n uv = inkPoint.xy + (aPosition - 0.5) * uUmberInst.x / uSize;\n vUv = uv;\n}\n`,d+=t("int(instance + 0.5)")}for(let t of n)u+=`layout(location = ${t.loc}) in ${l[t.size-1]} ${t.name};\n`;let m=t.effects.map(({def:t})=>`${t.vertex?.head??""}\n${t.vertex?.main??""}`).join(`\n`),v=t.effects.map(({def:t})=>`${t.vertex?.head??""}\n${t.fragment?.head??""}`).join(`\n`),b=new Set(["uUmberInk"]),p=o(v);for(let e in t.uniforms){let n=r(t.uniforms[e]);!n?.includes("sampler")||!new RegExp(`\\b${e}\\b`).test(m)||p(e)||(u+=`uniform ${n} ${e};\n`,c+=`uniform ${n} ${e};\n`,b.add(e))}let g=Object.fromEntries(Object.entries(t.uniforms).filter(([t])=>!b.has(t))),x=t.chunks??{vertex:"",fragment:""};return{...t,uniforms:g,effects:[{name:"instances",def:{vertex:{main:f},fragment:{uv:d}}},...t.effects],chunks:{vertex:`// instances\n${u}\n${x.vertex}`,fragment:`// instances\n${c}\n${x.fragment}`}}}function f(t){return typeof t=="number"?new Float64Array(t):new Float64Array(t)}function d(t){return typeof t=="number"?new Float32Array(t):new Float32Array(t)}var m=(t,e)=>t[e]??NaN;var v=.1,b=256,p=.05,g=["lines","words","chars"],x=`float umberRand(uint x){\nx^=x>>16;x*=0x7feb352du;x^=x>>15;x*=0x846ca68bu;x^=x>>16;\nreturn float(x)/4294967295.0;\n}\nvec2 umberFit(vec2 uv){\nif(uFitMode>1.5)return uv;\nvec2 r=uPlane/max(uImg,vec2(1.0));\nfloat s=uFitMode<0.5?max(r.x,r.y):min(r.x,r.y);\nvec2 sc=uImg*s;\nreturn(uv*uPlane-(uPlane-sc)*uFitPos)/sc;\n}\nvec4 color(vec2 uv){\nvec2 id=floor(uv*uSize);\nfloat n=id.y*uSize.x+id.x;\nif(n>=uCount)return vec4(0.0);\nuint base=uint(n)*151u+7u;\nfor(int k=0;k<48;k++){\nuint s=base*48u+uint(k)*3u;\nvec2 p=vec2(umberRand(s),umberRand(s+1u));\nvec2 f=umberFit(p);\nif(f.x<0.0||f.y<0.0||f.x>1.0||f.y>1.0)continue;\nvec4 c=textureLod(uSource,f,0.0);\nfloat ink=uLuma>0.5?dot(c.rgb,vec3(0.2126,0.7152,0.0722)):c.a;\nif(ink>0.02+0.96*umberRand(s+2u))return vec4(p,ink,1.0);\n}\nreturn vec4(0.0);\n}\n`;function y(t,e){if(typeof t=="number")return t;let n=t(0,e);return typeof n=="number"?1:Array.isArray(n)||ArrayBuffer.isView(n)?n.length:1}function w(t,e,n){return t==null?U(n):typeof t=="number"?t:m(t,e)||0}function U(t){let e=Math.imul(t^2654435769,2246822507);return e=Math.imul(e^e>>>13,3266489909),((e^e>>>16)>>>0)/4294967296}var A=class{constructor(t,e,n,i){this.stage=t;this.plane=e;this.spec=n;this.grid=null;this.vao=null;this.ga=[];this.Db=[];this.ab=d(4);this.Xa=new Float64Array(b*3);this.head=0;this.ha=0;this.moving=!1;this.version=-1;this.seeds=null;this.seeded=null;this.Ch=f(4);this.fx=null;this.gl=t.gpu.gl,this.count=n.count;let s=n.mode,r=s==="chars"||s==="words"||s==="lines";this.whole=r||s==="ink",s==="tiles"&&this.ab.set([n.cols,n.rows]),s==="points"&&(this.ab[0]=n.size),r&&this.ga.push(this.column(1,4),this.column(2,4)),s==="echo"&&this.ga.push(this.column(1,2)),this.Je(i),this.fd();let a=this.Db;this.key=`|i:${s}${a.map(t=>`,${t.name}${t.size}`).join("")}`,s==="ink"&&this.Oh(),this.api=this.handle()}Oh(){let t=this.stage;this.ab[0]=this.spec.size;let e=()=>this.seeds?.texture??null;this.plane.uniforms.uUmberInk={value:{get texture(){return e()}}},t.chunks.loadFx().then(e=>{this.fx=e,t.scheduler.markDirty()})}Je(t){let e=u,n=new Set;for(let{name:i,def:s}of t){let t=s.attributes??{};for(let s in t){if(n.has(s))continue;n.add(s);let r=t[s];if(r===void 0)continue;let a=y(r,this.count);if(!(a>=1&&a<=4)||e>15){this.stage.env.lib.say("attribute",[i,s,e>15],this.plane.el);continue}this.Db.push({name:s,size:a,loc:e});let o=this.column(e++,a);o.name=s,o.fill=r,this.ga.push(o)}}}column(t,e){return{loc:t,size:e,data:new Float32Array(Math.max(1,this.count)*e),buf:null,held:0,dirty:!0}}fd(){for(let t of this.ga)if(t.name){t.data.length!==Math.max(1,this.count)*t.size&&(t.data=new Float32Array(Math.max(1,this.count)*t.size));for(let e=0;e<this.count;e++){let n=typeof t.fill=="function"?t.fill(e,this.count):null;for(let i=0;i<t.size;i++)t.data[e*t.size+i]=w(n,i,e*4+i+t.loc*65536)}t.dirty=!0}}handle(){let t=t=>{let e=this.ga.find(e=>e.name===t);return e||this.stage.env.lib.say("attributeNone",[t,this.Db.map(t=>t.name)],this.plane.el),e},e=()=>this.count,n=()=>this.spec.mode,i=t=>{for(let e of this.ga)e.name&&(!t||e.name===t)&&(e.dirty=!0);this.stage.scheduler.markDirty()},s={get count(){return e()},get mode(){return n()},data(e){return t(e)?.data??null},set(e,n){let r=t(e);return r&&(r.data.set(Array.prototype.slice.call(n,0,r.data.length)),i(e)),s},update:i};return s}build(t){return c(t,this.spec,this.Db)}wrap(t){return this.grid!==t&&this.drop(),this.grid=t,this}update(t,e){let n=this.spec.mode;return n==="echo"?this.echo(t,e):n==="ink"?this.ink():n==="chars"||n==="words"||n==="lines"?this.units():!1}at(t){return(this.head+t)%b*3}push(t,e,n){let i=this.at(this.ha);this.ha<b?this.ha++:this.head=(this.head+1)%b,this.Xa[i]=t,this.Xa[i+1]=e,this.Xa[i+2]=n}echo(t,e){let n=e[0],i=e[1],s=this.ga[0];if(!s)return!1;this.nh(t,n,i);let r=this.ch(t,n,i,s.data),a=r||this.moving;return this.moving=r,a&&(s.dirty=!0),a}nh(t,e,n){let i=this.Xa;this.ha||this.push(t,e,n);let s=this.at(this.ha-1);t-m(i,s)>p&&this.push(t-1/60,m(i,s+1),m(i,s+2)),s=this.at(this.ha-1);let r=this.count*this.spec.delay+v,a=m(i,s);t>a&&(this.ha<2||a-m(i,this.at(this.ha-2))>=r/(b-4))?this.push(t,e,n):(i[s]=Math.max(a,t),i[s+1]=e,i[s+2]=n);let o=t-r;for(;this.ha>2&&m(i,this.at(1))<o;)this.head=(this.head+1)%b,this.ha--}ch(t,e,n,i){let s=this.Xa,r=!1,a=this.ha-1;for(let o=1;o<this.count;o++){let u=t-o*this.spec.delay;for(;a>0&&m(s,this.at(a))>u;)a--;let l=this.at(a),h=this.at(Math.min(a+1,this.ha-1)),c=m(s,l),f=m(s,h)-c,d=f>0?Math.min(1,Math.max(0,(u-c)/f)):0,v=m(s,l+1),b=m(s,l+2),p=(this.count-1-o)*2;i[p]=v+(m(s,h+1)-v)*d-e,i[p+1]=b+(m(s,h+2)-b)*d-n,(Math.abs(m(i,p))>.05||Math.abs(m(i,p+1))>.05)&&(r=!0)}return r}units(){let t=this.plane,e=t.text,n=e?.[this.spec.mode];if(!e||!n?.length)return!1;let[i,s]=this.ga;if(!i||!s)return!1;let r=!1;if(e.version!==this.version||this.whole){if(this.version=e.version,this.whole=!1,this.count!==n.length){this.count=n.length;for(let t of this.ga)t.data=new Float32Array(this.count*t.size);this.fd()}let s=t.layoutW+2*t.pad||1,a=t.layoutH+2*t.pad||1;n.forEach((e,n)=>{let r=e.box;i.data.set([(r.x+t.pad)/s,(r.y+t.pad)/a,r.w/s,r.h/a],n*4)}),i.dirty=!0,r=!0}let a=e.values,o=m(e.base,g.indexOf(this.spec.mode))*4,u=s.data;for(let t=0;t<this.count*4;t++)u[t]!==a[o+t]&&(u[t]=m(a,o+t)||0,s.dirty=!0,r=!0);return r}ink(){let t=this.plane,e=t.texture,n=this.fx,i=e?.ready?e.texture:null,s=t.text?t.text.version:i,r=this.Ch,a=t.fit<2?Math.round(t.size[0]/(t.size[1]||1)*1e3):0,o=r[0]===a&&r[1]===t.fit&&r[2]===t._g[0]&&r[3]===t._g[1];return!n||!e||!i||s===this.seeded&&o||this.stage.gpu.context.gone?!1:(this.seeded=s,r[0]=a,r[1]=t.fit,r[2]=t._g[0],r[3]=t._g[1],this.yh(n,e),this.whole=!1,!0)}yh(t,e){let n=this.plane,s=this.count,r=Math.min(256,Math.ceil(Math.sqrt(s)));this.ab[1]=r,this.seeds||(this.seeds=t.make({width:r,height:Math.ceil(s/r),type:"half",quiet:!0,msaa:0,attachments:1}),this.seeds.type==="u8"&&i.warn(`data-umber-instances="ink": this GPU can't render to half-float targets, so particles sit on a grid of 1/255 of the plane (visible on large planes).`)),this.seeds.draw(x,{uSource:{get texture(){return n.texture?.texture??null}},uPlane:new Float32Array(n.size),uImg:new Float32Array([e.width,e.height]),uFitMode:n.fit,uFitPos:new Float32Array(n._g),uLuma:this.spec.luma?1:0,uCount:s})}draw(){let t=this.gl,e=this.grid,n=this.plane.program;if(!(!e||!n)){this.vao||this.Cg(e);for(let e of this.ga)e.dirty&&(e.dirty=!1,t.bindBuffer(t.ARRAY_BUFFER,e.buf),e.held!==e.data.length?t.bufferData(t.ARRAY_BUFFER,e.data,t.DYNAMIC_DRAW):t.bufferSubData(t.ARRAY_BUFFER,0,e.data),e.held=e.data.length);n.set("uInstances",this.count),n.set("uUmberWhole",this.whole?1:0),n.set("uUmberInst",this.ab),t.bindVertexArray(this.vao),t.drawElementsInstanced(t.TRIANGLES,e.count,t.UNSIGNED_SHORT,0,this.whole?1:this.count)}}Cg(t){let e=this.gl;this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,t.buffers[0]??null),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.buffers[1]??null);for(let t of this.ga)t.buf=e.createBuffer(),t.held=0,t.dirty=!0,e.bindBuffer(e.ARRAY_BUFFER,t.buf),e.enableVertexAttribArray(t.loc),e.vertexAttribPointer(t.loc,t.size,e.FLOAT,!1,0,0),e.vertexAttribDivisor(t.loc,1)}drop(){let t=this.gl;if(this.vao&&!this.stage.gpu.context.gone){t.deleteVertexArray(this.vao);for(let e of this.ga)t.deleteBuffer(e.buf)}this.vao=null}lost(){this.vao=null,this.grid=null,this.seeded=null,this.spec.mode==="ink"&&(this.whole=!0)}dispose(){this.drop(),this.seeds?.release(),this.seeds=null}};var $=["chars","words","lines"],k=t=>t!==void 0&&/^-?[\d.]+$/.test(t)?+t:NaN;function F(t){return(t&&typeof t=="object"?Object.entries(t).map(([t,e])=>`${t} ${Array.isArray(e)?e.join("x"):e}`).join(" "):String(t)).toLowerCase().split(/[\s,]+/).filter(Boolean)}function I(t){return t==="echo"?6:t==="ink"?2e3:t==="points"?1e4:1}function P(t,e,n){let i=t.spec,s=/^(\d+)x(\d+)$/.exec(e);if(s)i.mode="tiles",i.cols=Number(s[1]),i.rows=Number(s[2]);else if(!isNaN(k(e)))i.count=k(e),t.counted=!0;else if($.includes(e))i.mode=e;else if(e==="luma"||e==="alpha")i.luma=e==="luma";else if(e==="tiles")i.mode="tiles";else{if(e==="echo"||e==="ink"||e==="points"||e==="count")return i.mode=e,isNaN(n)?1:(i.count=n,t.counted=!0,2);if(e==="delay"||e==="size")return isNaN(n)?`"${e}" needs a number after it`:(i[e]=n,2);if(e!=="units"&&e!=="source")return`"${e}" is not a word it knows`}return 1}function R(t){let e={spec:{mode:"count",count:1,cols:8,rows:8,delay:.05,size:2,luma:!1},counted:!1},n=F(t);if(!n.length)return"it is empty";let i=0;for(let t=n[i];t!==void 0;t=n[i]){let s=P(e,t,k(n[i+1]));if(typeof s=="string")return s;i+=s}let s=e.spec;return e.counted||(s.count=I(s.mode)),z(s)}function z(t){return t.mode==="tiles"&&(t.count=t.cols*t.rows),!(t.count>=1)||!(t.cols>=1)||!(t.rows>=1)?"its count is below 1":(t.count=Math.min(Math.round(t.count),t.mode==="echo"?64:65536),t.mode==="tiles"&&t.cols*t.rows>65536?`${t.cols} x ${t.rows} tiles is more than 65536`:(t.delay=Math.max(.001,t.delay),t.size=Math.max(.5,t.size),t))}var B=class{constructor(t){this.stage=t}part(t,e){let n=R(e),i=t.el;if(typeof n=="string"){this.stage.env.lib.say("instances",[typeof e=="string"||typeof e=="number"?String(e):JSON.stringify(e),n],i);return}if((n.mode==="chars"||n.mode==="words"||n.mode==="lines")&&t.kind!=="text"){this.stage.env.lib.say("instancesText",[n.mode],i);return}if(n.mode==="ink"&&t.kind==="shader"){this.stage.env.lib.say("instancesInk",[],i);return}let s=new A(this.stage,t,n,t.effects);t.instancing=s,Object.defineProperty(t,"instances",{value:s.api,configurable:!0,enumerable:!0}),t.modules.list.push({name:"instances",binding:{update:e=>s.update(e.time,t.rect),lost:()=>{s.lost()},destroy:()=>{s.dispose()}}})}};function M(t){return s(t.env.host.log),new B(t)}export{B as Instances,M as instances};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=()=>{};var t=()=>Promise.reject(new Error("no words"));var n={configure:e,debug:!1,warnings:!1,info:e,warn:e,error:e,report:e,words:t},i=n;function r(e){i=e}function s(e){if(typeof e=="number"||typeof e=="boolean")return"float";if(Array.isArray(e)||ArrayBuffer.isView(e)){let t=e.length;return t===2?"vec2":t===3?"vec3":t===4?"vec4":t===9?"mat3":t===16?"mat4":null}return typeof e=="string"?"sampler2D":e&&typeof e=="object"?"highp sampler2D":null}function u(e,t){let n=e=>e.charAt(0).toUpperCase()+e.slice(1),i=e=>e.split(/[-_\s]+/).map(n).join("");return`u${i(e)}${i(t)}`}var a=/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g;function o(e){let t=e.replace(/\\n/g,`\n`).replace(a," ");return e=>new RegExp(`\\buniform\\b[^;]*\\b${e}\\b`).test(t)}var l=3,h=["float","vec2","vec3","vec4"],c="gl_Position = vec4(0.0, 0.0, 2.0, 1.0); return;",f=/\bvec4 umberText\(vec2 f\) ?\{/,m=`\nvec4 umberText(vec2 f){\nif(uUmberQuads<0.5)return umberTextWhole(f);\nvec2 p=f*umberTextRow(0).xy;\nvec2 dx=dFdx(p);\nvec2 dy=dFdy(p);\nvec2 l=p-vUmberInk.xy;\nif(l.x<0.0||l.y<0.0||l.x>=vUmberInk.z||l.y>=vUmberInk.w)return vec4(0.0);\nvec4 a=vUmberRow;\nif(a.z<0.0){\nvec2 pxPer=1.0/max(vec2(length(vec2(dx.x,dy.x)),length(vec2(dx.y,dy.y))),vec2(1e-4));\nreturn vec4(vUmberTint.rgb,1.0)*(umberCurveGlyph(l,a,pxPer)*vUmberTint.a);\n}\nfloat lod=max(0.0,0.5*log2(max(dot(dx,dx),dot(dy,dy))));\nif(a.z>0.5)return textureLod(uUmberTextColor,(a.xy+l)/vec2(textureSize(uUmberTextColor,0)),lod)*vUmberTint.a;\nreturn vec4(vUmberTint.rgb,1.0)*(textureLod(uImage,(a.xy+l)/vec2(textureSize(uImage,0)),lod).r*vUmberTint.a);\n}`,d=`\nunitInk=unitBox;\nif(uUmberQuads>0.5){\nvec2 umberGrid=texelFetch(uUmberTextLayout,ivec2(0),0).xy;\nvec4 umberReach=uUmberReach*(umberGrid/uSize).yxyx;\nunitInk=umberInkBox/umberGrid.xyxy;\nuv=(umberInkBox.xy-umberReach.wx+aPosition*(umberInkBox.zw+umberReach.wx+umberReach.yz))/umberGrid;\nvUv=uv;\n}\nvUmberInk=umberInkBox;\nvUmberRow=umberGlyphRow;\nvUmberTint=umberTint;\n`,v=`\nvUmberAlpha=unitAlpha;\nif(unitAlpha<=0.0){gl_Position=vec4(0.0,0.0,2.0,1.0);return;}\nif(unitScale!=1.0||unitTurn!=0.0){\nvec2 umberD=(uv-unitInk.xy-0.5*unitInk.zw)*uSize;\nfloat umberC=cos(unitTurn);\nfloat umberS=sin(unitTurn);\npos.xy+=unitScale*vec2(umberC*umberD.x-umberS*umberD.y,umberS*umberD.x+umberC*umberD.y)-umberD;\n}\n`,b=`vec4 point;\nvec4 umberPoint(float i) {\n uvec4 v = uvec4(uint(i)) * uvec4(1664525u, 22695477u, 134775813u, 1103515245u) + uvec4(1013904223u, 2891336453u, 2531011u, 12345u);\n v ^= v >> 16u; v *= 0x45d9f3bu; v ^= v >> 16u; v *= 0x45d9f3bu; v ^= v >> 16u;\n return vec4(v) / 4294967295.0;\n}\n`;function x(e){let t=e.effects.map(({def:e})=>`${e.vertex?.head??""}\n${e.vertex?.main??""}`).join(`\n`),n=e.effects.map(({def:e})=>`${e.vertex?.head??""}\n${e.fragment?.head??""}`).join(`\n`),i=new Set(["uUmberInk"]),r=o(n),u="";for(let n in e.uniforms){let a=s(e.uniforms[n]);!a?.includes("sampler")||!new RegExp(`\\b${n}\\b`).test(t)||r(n)||(u+=`uniform ${a} ${n};\n`,i.add(n))}return{head:u,uniforms:Object.fromEntries(Object.entries(e.uniforms).filter(([e])=>!i.has(e)))}}function p({loc:e,glsl:t}){let n=["umberInkBox","umberGlyphRow","umberTint"].map((t,n)=>`layout(location = ${e+n}) in vec4 ${t};\n`).join(""),i=e=>`flat ${e} vec4 vUmberInk;\nflat ${e} vec4 vUmberRow;\nflat ${e} vec4 vUmberTint;\nflat ${e} float vUmberAlpha;\nuniform float uUmberQuads;\nvec4 unitInk;\n`;return{vertex:`${n}uniform highp sampler2D uUmberTextLayout;\nuniform vec4 uUmberReach;\n${i("out")}float unitScale = 1.0;\nfloat unitTurn = 0.0;\nfloat unitAlpha = 1.0;\n`,fragment:`${i("in")}${t.replace(f,"vec4 umberTextWhole(vec2 f) {")}${m}\n`}}function y(e,t,n,i=null){let r=t.mode,s=r==="chars"||r==="words"||r==="lines",u=`uniform float uInstances;\nuniform float uUmberWhole;\nuniform vec4 uUmberInst;\nfloat instance;\n`,a=u+`flat out float vUmberInstance;\n`,o=u+`flat in float vUmberInstance;\n`,l=`instance = float(gl_InstanceID);\n${r==="echo"?`instance = uInstances - 1.0 - instance;\n`:""}vUmberInstance = instance;\n`,f=`instance = vUmberInstance;\n`;if(r==="tiles"){let e=`tile = vec4(mod(instance, uUmberInst.x), floor(instance / uUmberInst.x), uUmberInst.xy);\ntileCenter = (tile.xy + 0.5) / tile.zw;\n`;a+=`vec4 tile;\nvec2 tileCenter;\n`,o+=`vec4 tile;\nvec2 tileCenter;\n`,l+=`${e}uv = (tile.xy + aPosition) / tile.zw;\nvUv = uv;\n`,f+=e}else if(s){if(a+=`layout(location = 1) in vec4 unitBox;\nlayout(location = 2) in vec4 unitValue;\nflat out vec4 vUmberBox;\nflat out vec4 vUmberUnit;\n`,o+=`flat in vec4 vUmberBox;\nflat in vec4 vUmberUnit;\nvec4 unitBox;\nvec4 unitValue;\n`,l+=`vUmberBox = unitBox;\nvUmberUnit = unitValue;\nif (uUmberWhole < 0.5) {\n uv = unitBox.xy + aPosition * unitBox.zw;\n vUv = uv;\n}\n`,f+=`unitBox = vUmberBox;\nunitValue = vUmberUnit;\n`,i){let e=p(i);a+=e.vertex,o+=e.fragment,l+=d,f+=`unitInk = uUmberQuads > 0.5 ? vUmberInk / umberTextRow(0).xyxy : unitBox;\n`}}else if(r==="echo")a+=`layout(location = 1) in vec2 echoOffset;\nflat out vec2 vUmberEcho;\n`,o+=`flat in vec2 vUmberEcho;\nvec2 echoOffset;\n`,l+=`vUmberEcho = echoOffset;\nif (instance > 0.5 && dot(echoOffset, echoOffset) < 0.0025) { ${c} }\npos.xy += echoOffset;\n`,f+=`echoOffset = vUmberEcho;\n`;else if(r==="points")a+=`${b}vec2 pointUv;\nout vec2 vUmberPointUv;\n`,o+=`${b}vec2 pointUv;\nin vec2 vUmberPointUv;\n`,l+=`point = umberPoint(instance);\npointUv = aPosition;\nvUmberPointUv = aPosition;\nuv = point.xy + (aPosition - 0.5) * uUmberInst.x / uSize;\nvUv = uv;\n`,f+=`point = umberPoint(instance);\npointUv = vUmberPointUv;\n`;else if(r==="ink"){let e=e=>`int umberW = int(uUmberInst.y);\ninkPoint = texelFetch(uUmberInk, ivec2(${e} % umberW, ${e} / umberW), 0);\n`,t=`uniform highp sampler2D uUmberInk;\nvec4 inkPoint;\n`;a+=t,o+=t,l+=`${e("gl_InstanceID")}if (uUmberWhole < 0.5) {\n if (inkPoint.w < 0.5) { ${c} }\n uv = inkPoint.xy + (aPosition - 0.5) * uUmberInst.x / uSize;\n vUv = uv;\n}\n`,f+=e("int(instance + 0.5)")}for(let e of n)a+=`layout(location = ${e.loc}) in ${h[e.size-1]} ${e.name};\n`;let m=x(e);a+=m.head,o+=m.head;let y=m.uniforms,g=e.chunks??{vertex:"",fragment:""};return{...e,uniforms:y,effects:[{name:"instances",def:{vertex:{main:l},fragment:{uv:f}}},...e.effects,...i&&s?[{name:"glyphs",def:{vertex:{main:v},fragment:{alpha:"alpha *= vUmberAlpha;"}}}]:[]],chunks:{vertex:`// instances\n${a}\n${g.vertex}`,fragment:`// instances\n${o}\n${g.fragment}`}}}function g(e){return typeof e=="number"?new Float64Array(e):new Float64Array(e)}function U(e){return typeof e=="number"?new Float32Array(e):new Float32Array(e)}var w=(e,t)=>e[t]??NaN;var k=.1,A=256,R=.05,I=["lines","words","chars"],$=`\nfloat umberRand(uint x){\nx^=x>>16;x*=0x7feb352du;x^=x>>15;x*=0x846ca68bu;x^=x>>16;\nreturn float(x)/4294967295.0;\n}\nvec2 umberFit(vec2 uv){\nif(uFitMode>1.5)return uv;\nvec2 r=uPlane/max(uImg,vec2(1.0));\nfloat s=uFitMode<0.5?max(r.x,r.y):min(r.x,r.y);\nvec2 sc=uImg*s;\nreturn(uv*uPlane-(uPlane-sc)*uFitPos)/sc;\n}\nvec4 color(vec2 uv){\nvec2 id=floor(uv*uSize);\nfloat n=id.y*uSize.x+id.x;\nif(n>=uCount)return vec4(0.0);\nuint base=uint(n)*151u+7u;\nfor(int k=0;k<48;k++){\nuint s=base*48u+uint(k)*3u;\nvec2 p=vec2(umberRand(s),umberRand(s+1u));\nvec2 f=umberFit(p);\nif(f.x<0.0||f.y<0.0||f.x>1.0||f.y>1.0)continue;\nvec4 c=textureLod(uSource,f,0.0);\nfloat ink=uLuma>0.5?dot(c.rgb,vec3(0.2126,0.7152,0.0722)):c.a;\nif(ink>0.02+0.96*umberRand(s+2u))return vec4(p,ink,1.0);\n}\nreturn vec4(0.0);\n}\n`;function F(e,t){if(typeof e=="number")return e;let n=e(0,t);return typeof n=="number"?1:Array.isArray(n)||ArrayBuffer.isView(n)?n.length:1}function z(e,t,n){return e==null?N(n):typeof e=="number"?e:w(e,t)||0}function N(e){let t=Math.imul(e^2654435769,2246822507);return t=Math.imul(t^t>>>13,3266489909),((t^t>>>16)>>>0)/4294967296}var P=class{constructor(e,t,n,i){this.stage=e;this.plane=t;this.spec=n;this.grid=null;this.vao=null;this.Ni=[];this.kf=[];this.Li=U(4);this.Zl=new Float64Array(A*3);this.head=0;this.Rb=0;this.moving=!1;this.version=-1;this.ih=[];this.glyphs=!1;this.reach=U(4);this.seeds=null;this.seeded=null;this.Dh=g(4);this.fx=null;this.gl=e.gpu.gl,this.count=n.count;let r=n.mode,s=r==="chars"||r==="words"||r==="lines";this.whole=s||r==="ink",r==="tiles"&&this.Li.set([n.cols,n.rows]),r==="points"&&(this.Li[0]=n.size),s&&this.Ni.push(this.column(1,4),this.column(2,4)),r==="echo"&&this.Ni.push(this.column(1,2)),this.Se(i),this.effectNames=i.map(e=>e.name);let u=l+this.kf.length;r==="chars"&&t.kind==="text"&&u<=13&&(this.ih=[this.column(u,4),this.column(u+1,4),this.column(u+2,4)],this.Ni.push(...this.ih)),this.Eg();let a=this.kf;this.key=`|i:${r}${a.map(e=>`,${e.name}${e.size}`).join("")}`,r==="ink"&&this.Ge(),this.api=this.handle()}Ge(){let e=this.stage;this.Li[0]=this.spec.size;let t=()=>this.seeds?.texture??null;this.plane.uniforms.uUmberInk={value:{get texture(){return t()}}},e.chunks.loadFx().then(t=>{this.fx=t,e.scheduler.markDirty()})}Se(e){let t=l,n=new Set;for(let{name:i,def:r}of e){let e=r.attributes??{};for(let r in e){if(n.has(r))continue;n.add(r);let s=e[r];if(s===void 0)continue;let u=F(s,this.count);if(!(u>=1&&u<=4)||t>15){this.stage.env.lib.say("attribute",[i,r,t>15],this.plane.el);continue}this.kf.push({name:r,size:u,loc:t});let a=this.column(t++,u);a.name=r,a.fill=s,this.Ni.push(a)}}}column(e,t){return{loc:e,size:t,data:new Float32Array(Math.max(1,this.count)*t),buf:null,held:0,dirty:!0}}Eg(){for(let e of this.Ni)if(e.name){e.data.length!==Math.max(1,this.count)*e.size&&(e.data=new Float32Array(Math.max(1,this.count)*e.size));for(let t=0;t<this.count;t++){let n=typeof e.fill=="function"?e.fill(t,this.count):null;for(let i=0;i<e.size;i++)e.data[t*e.size+i]=z(n,i,t*4+i+e.loc*65536)}e.dirty=!0}}handle(){let e=e=>{let t=this.Ni.find(t=>t.name===e);return t||this.stage.env.lib.say("attributeNone",[e,this.kf.map(e=>e.name)],this.plane.el),t},t=()=>this.count,n=()=>this.spec.mode,i=e=>{for(let t of this.Ni)t.name&&(!e||t.name===e)&&(t.dirty=!0);this.stage.scheduler.markDirty()},r={get count(){return t()},get mode(){return n()},data(t){return e(t)?.data??null},set(t,n){let s=e(t);return s&&(s.data.set(Array.prototype.slice.call(n,0,s.data.length)),i(t)),r},update:i};return r}build(e){let[t]=this.ih,n=this.stage.chunks.text;return y(e,this.spec,this.kf,t&&n?{loc:t.loc,glsl:n.glsl}:null)}Yi(e){let t=this.plane,[n,i,r]=this.ih,s=this.stage.chunks.text?.glyphs(t),u=t.texture;if(!n||!i||!r||!u||!s||s.length>e.length)return!1;for(let e of this.ih)e.data.fill(0);let a=u.width/(t.layoutW+2*t.pad+t.rounding[0]||1),o=new Uint8Array(e.length);for(let{entry:u,x:l,y:h,tint:c}of s){let s=u.curve,f=(l+(s?u.x:u.ox))/a-t.pad,m=(h+(s?u.y:u.oy))/a-t.pad,d=-1,v=1/0;e.forEach(({box:e},t)=>{let n=Math.abs(f-e.x)+Math.abs(m-e.y-.8*e.h);!o[t]&&n<v&&(v=n,d=t)});let b=e[d]?.box;if(!b||v>b.h)return!1;o[d]=1,n.data.set([l,h,u.w,u.h],d*4),i.data.set(s?[u.x,u.y,-s[1],s[0]]:[u.x,u.y,u.page,0],d*4),r.data.set(c,d*4)}for(let e of this.ih)e.dirty=!0;return!0}J(){let e=this.plane.texture?.revision,t=e!==this.revision;return this.revision=e,t}Ac(){let e=this.reach.fill(0);for(let t of this.effectNames){let n=this.plane.uniforms[u(t,"reach")]?.value;for(let t=0;t<4;t++){let i=typeof n=="number"?n:Number(n?.[t])||0;i>w(e,t)&&(e[t]=i)}}return e}wrap(e){return this.grid!==e&&this.drop(),this.grid=e,this}update(e,t){let n=this.spec.mode;return n==="echo"?this.echo(e,t):n==="ink"?this.ink():n==="chars"||n==="words"||n==="lines"?this.units():!1}at(e){return(this.head+e)%A*3}push(e,t,n){let i=this.at(this.Rb);this.Rb<A?this.Rb++:this.head=(this.head+1)%A,this.Zl[i]=e,this.Zl[i+1]=t,this.Zl[i+2]=n}echo(e,t){let n=t[0],i=t[1],r=this.Ni[0];if(!r)return!1;this._h(e,n,i);let s=this.Aa(e,n,i,r.data),u=s||this.moving;return this.moving=s,u&&(r.dirty=!0),u}_h(e,t,n){let i=this.Zl;this.Rb||this.push(e,t,n);let r=this.at(this.Rb-1);e-w(i,r)>R&&this.push(e-1/60,w(i,r+1),w(i,r+2)),r=this.at(this.Rb-1);let s=this.count*this.spec.delay+k,u=w(i,r);e>u&&(this.Rb<2||u-w(i,this.at(this.Rb-2))>=s/(A-4))?this.push(e,t,n):(i[r]=Math.max(u,e),i[r+1]=t,i[r+2]=n);let a=e-s;for(;this.Rb>2&&w(i,this.at(1))<a;)this.head=(this.head+1)%A,this.Rb--}Aa(e,t,n,i){let r=this.Zl,s=!1,u=this.Rb-1;for(let a=1;a<this.count;a++){let o=e-a*this.spec.delay;for(;u>0&&w(r,this.at(u))>o;)u--;let l=this.at(u),h=this.at(Math.min(u+1,this.Rb-1)),c=w(r,l),f=w(r,h)-c,m=f>0?Math.min(1,Math.max(0,(o-c)/f)):0,d=w(r,l+1),v=w(r,l+2),b=(this.count-1-a)*2;i[b]=d+(w(r,h+1)-d)*m-t,i[b+1]=v+(w(r,h+2)-v)*m-n,(Math.abs(w(i,b))>.05||Math.abs(w(i,b+1))>.05)&&(s=!0)}return s}units(){let e=this.plane,t=e.text,n=t?.[this.spec.mode];if(!t||!n?.length)return!1;let[i,r]=this.Ni;if(!i||!r)return!1;let s=!1,u=this.J();if(t.version!==this.version||this.whole||u){if(this.version=t.version,this.whole=!1,this.count!==n.length){this.count=n.length;for(let e of this.Ni)e.data=new Float32Array(this.count*e.size),e.dirty=!0;this.Eg()}let r=e.layoutW+2*e.pad+e.rounding[0]||1,u=e.layoutH+2*e.pad+e.rounding[1]||1;n.forEach((t,n)=>{let s=t.box;i.data.set([(s.x+e.pad)/r,(s.y+e.pad)/u,s.w/r,s.h/u],n*4)}),i.dirty=!0,this.glyphs=this.spec.mode==="chars"&&this.Yi(n),s=!0}let a=t.values,o=w(t.base,I.indexOf(this.spec.mode))*4,l=r.data;for(let e=0;e<this.count*4;e++)l[e]!==a[o+e]&&(l[e]=w(a,o+e)||0,r.dirty=!0,s=!0);return s}ink(){let e=this.plane,t=e.texture,n=this.fx,i=t?.ready?t.texture:null,r=e.text?e.text.version:i,s=this.Dh,u=e.fit<2?Math.round(e.size[0]/(e.size[1]||1)*1e3):0,a=s[0]===u&&s[1]===e.fit&&s[2]===e._M[0]&&s[3]===e._M[1];return!n||!t||!i||r===this.seeded&&a||this.stage.gpu.context.gone?!1:(this.seeded=r,s[0]=u,s[1]=e.fit,s[2]=e._M[0],s[3]=e._M[1],this.$a(n,t),this.whole=!1,!0)}$a(e,t){let n=this.plane,r=this.count,s=Math.min(256,Math.ceil(Math.sqrt(r)));this.Li[1]=s,this.seeds||(this.seeds=e.make({width:s,height:Math.ceil(r/s),type:"half",quiet:!0,msaa:0,attachments:1}),this.seeds.type==="u8"&&i.warn(`data-umber-instances="ink": this GPU can't render to half-float targets, so particles sit on a grid of 1/255 of the plane (visible on large planes).`)),this.seeds.draw($,{uSource:{get texture(){return n.texture?.texture??null}},uPlane:new Float32Array(n.size),uImg:new Float32Array([t.width,t.height]),uFitMode:n.fit,uFitPos:new Float32Array(n._M),uLuma:this.spec.luma?1:0,uCount:r})}draw(){let e=this.gl,t=this.grid,n=this.plane.program;if(!(!t||!n)){this.vao||this.Df(t);for(let t of this.Ni)t.dirty&&(t.dirty=!1,e.bindBuffer(e.ARRAY_BUFFER,t.buf),t.held!==t.data.length?e.bufferData(e.ARRAY_BUFFER,t.data,e.DYNAMIC_DRAW):e.bufferSubData(e.ARRAY_BUFFER,0,t.data),t.held=t.data.length);n.set("uInstances",this.count),n.set("uUmberWhole",this.whole?1:0),n.set("uUmberInst",this.Li),this.ih.length&&(n.set("uUmberQuads",this.glyphs&&!this.whole?1:0),n.set("uUmberReach",this.Ac())),e.bindVertexArray(this.vao),e.drawElementsInstanced(e.TRIANGLES,t.count,e.UNSIGNED_SHORT,0,this.whole?1:this.count)}}Df(e){let t=this.gl;this.vao=t.createVertexArray(),t.bindVertexArray(this.vao),t.bindBuffer(t.ARRAY_BUFFER,e.buffers[0]??null),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,e.buffers[1]??null);for(let e of this.Ni)e.buf=t.createBuffer(),e.held=0,e.dirty=!0,t.bindBuffer(t.ARRAY_BUFFER,e.buf),t.enableVertexAttribArray(e.loc),t.vertexAttribPointer(e.loc,e.size,t.FLOAT,!1,0,0),t.vertexAttribDivisor(e.loc,1)}drop(){let e=this.gl;if(this.vao&&!this.stage.gpu.context.gone){e.deleteVertexArray(this.vao);for(let t of this.Ni)e.deleteBuffer(t.buf)}this.vao=null}lost(){this.vao=null,this.grid=null,this.seeded=null,this.spec.mode==="ink"&&(this.whole=!0)}dispose(){this.drop(),this.seeds?.release(),this.seeds=null}};var B=["chars","words","lines"],M=e=>e!==void 0&&/^-?[\d.]+$/.test(e)?+e:NaN;function T(e){return(e&&typeof e=="object"?Object.entries(e).map(([e,t])=>`${e} ${Array.isArray(t)?t.join("x"):t}`).join(" "):String(e)).toLowerCase().split(/[\s,]+/).filter(Boolean)}function S(e){return e==="echo"?6:e==="ink"?2e3:e==="points"?1e4:1}function E(e,t,n){let i=e.spec,r=/^(\d+)x(\d+)$/.exec(t);if(r)i.mode="tiles",i.cols=Number(r[1]),i.rows=Number(r[2]);else if(!isNaN(M(t)))i.count=M(t),e.counted=!0;else if(B.includes(t))i.mode=t;else if(t==="luma"||t==="alpha")i.luma=t==="luma";else if(t==="tiles")i.mode="tiles";else{if(t==="echo"||t==="ink"||t==="points"||t==="count")return i.mode=t,isNaN(n)?1:(i.count=n,e.counted=!0,2);if(t==="delay"||t==="size")return isNaN(n)?`"${t}" needs a number after it`:(i[t]=n,2);if(t!=="units"&&t!=="source")return`"${t}" is not a word it knows`}return 1}function D(e){let t={spec:{mode:"count",count:1,cols:8,rows:8,delay:.05,size:2,luma:!1},counted:!1},n=T(e);if(!n.length)return"it is empty";let i=0;for(let e=n[i];e!==void 0;e=n[i]){let r=E(t,e,M(n[i+1]));if(typeof r=="string")return r;i+=r}let r=t.spec;return t.counted||(r.count=S(r.mode)),_(r)}function _(e){return e.mode==="tiles"&&(e.count=e.cols*e.rows),!(e.count>=1)||!(e.cols>=1)||!(e.rows>=1)?"its count is below 1":(e.count=Math.min(Math.round(e.count),e.mode==="echo"?64:65536),e.mode==="tiles"&&e.cols*e.rows>65536?`${e.cols} x ${e.rows} tiles is more than 65536`:(e.delay=Math.max(.001,e.delay),e.size=Math.max(.5,e.size),e))}var L=class{constructor(e){this.stage=e}part(e,t){let n=D(t),i=e.el;if(typeof n=="string"){this.stage.env.lib.say("instances",[typeof t=="string"||typeof t=="number"?String(t):JSON.stringify(t),n],i);return}if((n.mode==="chars"||n.mode==="words"||n.mode==="lines")&&e.kind!=="text"){this.stage.env.lib.say("instancesText",[n.mode],i);return}if(n.mode==="ink"&&e.kind==="shader"){this.stage.env.lib.say("instancesInk",[],i);return}let r=new P(this.stage,e,n,e.effects);e.instancing=r,Object.defineProperty(e,"instances",{value:r.api,configurable:!0,enumerable:!0}),e.modules.list.push({name:"instances",binding:{update:t=>r.update(t.time,e.rect),lost:()=>{r.lost()},destroy:()=>{r.dispose()}}})}};function O(e){return r(e.env.host.log),new L(e)}export{L as Instances,O as instances};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- var e=()=>{};var t=()=>Promise.reject(new Error("no words"));var r={configure:e,debug:!1,warnings:!1,info:e,warn:e,error:e,report:e,words:t},i=r;function a(e){i=e}var s=(e,t)=>e[t]??NaN;function n(e){if(!e||typeof e.tagName!="string")return"<?>";let t=e.tagName.toLowerCase();if(e.id)return`<${t}#${e.id}>`;let r=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return r?`<${t}.${r}>`:`<${t}>`}var h=e=>e,l=["uniformMatrix2fv","uniformMatrix3fv","uniformMatrix4fv",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"uniformMatrix2x3fv","uniformMatrix2x4fv","uniformMatrix3x2fv","uniformMatrix3x4fv","uniformMatrix4x2fv","uniformMatrix4x3fv"],o=["uniform1iv","uniform2iv","uniform3iv","uniform4iv"],d=["uniform1uiv","uniform2uiv","uniform3uiv","uniform4uiv"];function u(e,t,r){return(t===e.UNSIGNED_INT||t>=e.UNSIGNED_INT_VEC2&&t<=e.UNSIGNED_INT_VEC4?d:o)[r-1]}var c=class{constructor(e,t,r,i="program"){this.gl=e;this.vertex=t;this.fragment=r;this.uniforms=new Map;this.state="pending";this.started=!1;this.error=null;this.shaders=[];this.options=typeof i=="string"?{label:i}:i;let a=globalThis.occluzeCapture;this.Eb=a?.version===1?null:e.getExtension("KHR_parallel_shader_compile");let s=h(e.createProgram());if(!s)throw new Error("the WebGL context is lost");this.program=s,this.options.lazy||this.start()}start(){if(this.started)return;this.started=!0;let e=this.gl,t=this.program,r,i;try{r=m(e,e.VERTEX_SHADER,this.vertex),i=m(e,e.FRAGMENT_SHADER,this.fragment)}catch{this.state="failed";return}e.attachShader(t,r),e.attachShader(t,i),e.bindAttribLocation(t,0,"aPosition");for(let[r,i]of this.options.attributes??[])e.bindAttribLocation(t,i,r);e.linkProgram(t),this.shaders=[r,i],this.Eb||this.Yb()}ready(){return this.state!=="pending"?this.state==="ok":this.compiled()?(this.Yb(),this.state==="ok"):!1}compiled(){return this.start(),this.state!=="pending"?!0:!this.Eb||!!this.gl.getProgramParameter(this.program,this.Eb.COMPLETION_STATUS_KHR)}get failed(){return this.state==="failed"}Yb(){if(this.start(),this.state!=="pending")return;let e=this.gl,t=this.program;if(!e.getProgramParameter(t,e.LINK_STATUS)){this.error=this.yg(),this.Vb(),e.deleteProgram(t),this.state="failed";return}this.Vb();let r=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let i=0;i<r;i++){let r=e.getActiveUniform(t,i);if(!r)continue;let a=r.name.replace(/\[0\]$/,""),s=e.getUniformLocation(t,r.name);s&&this.uniforms.set(a,{location:s,type:r.type,size:r.size})}this.state="ok"}yg(){let e=this.gl,[t,r]=this.shaders,i=y(e,t);if(i!==null)return["vertex",this.options.label,i,this.vertex];let a=y(e,r);return a!==null?["fragment",this.options.label,a,this.fragment]:["link",this.options.label,e.getProgramInfoLog(this.program)??"",""]}Vb(){for(let e of this.shaders)this.gl.deleteShader(e);this.shaders=[]}set(e,t){let r=this.state==="ok"?this.uniforms.get(e):void 0;!r||t==null||(typeof t=="number"?g(this.gl,r,t):f(this.gl,r,t))}dispose(){this.Vb(),this.state!=="failed"&&this.gl.deleteProgram(this.program)}};function g(e,t,r){if(t.last===r)return;t.last=r;let{type:i,location:a}=t;i===e.FLOAT?e.uniform1f(a,r):i===e.UNSIGNED_INT?e.uniform1ui(a,r):e.uniform1i(a,r)}function p(e,t){let r=e.last;if(r?.length===t.length){let e=t.length;for(;e--&&r[e]===t[e];);if(e<0)return!1}else r=[],e.last=r;for(let e=0;e<t.length;e++)r[e]=s(t,e);return!0}function f(e,t,r){if(!p(t,r))return;let{type:i,location:a}=t,s=l[i-e.FLOAT_MAT2];if(i===e.FLOAT_VEC2)e.uniform2fv(a,r);else if(i===e.FLOAT_VEC3)e.uniform3fv(a,r,0,Math.min(r.length,t.size*3));else if(i===e.FLOAT_VEC4)e.uniform4fv(a,r);else if(s)e[s](a,!1,r);else if(i===e.FLOAT)e.uniform1fv(a,r);else{let s=u(e,i,r.length/t.size);s&&e[s](a,r)}}function m(e,t,r){let i=h(e.createShader(t));if(!i)throw new Error("the WebGL context is lost");return e.shaderSource(i,r),e.compileShader(i),i}function y(e,t){return t&&!e.getShaderParameter(t,e.COMPILE_STATUS)?e.getShaderInfoLog(t)??"":null}var v=`#version 300 es\nlayout(location=0)in vec2 aPosition;\nuniform vec2 uCanvas;\nuniform vec4 uRect;\nout vec2 vUv;\nvoid main(){\nvUv=aPosition;\nvec2 px=uRect.xy+aPosition*uRect.zw;\ngl_Position=vec4(px/uCanvas*2.0-1.0,0.0,1.0);\n}\n`,x=`#version 300 es\nprecision highp float;\nin vec2 vUv;\nuniform sampler2D uImage;\nuniform float uAlpha;\nout vec4 outColor;\nvoid main(){\noutColor=texture(uImage,vUv)*uAlpha;\n}\n`,w=class{constructor(e){this.gl=e;this.program=null;this.Ha=[];this.rect=[]}get(){return this.program??=new c(this.gl,v,x,"layer fade")}draw(e,t,r,i){let a=this.get();if(!a.ready())return!1;let s=this.gl,n=this.Ha,h=this.rect;return n[0]=r.width,n[1]=r.height,h[0]=e.x,h[1]=e.y,h[2]=e.dw,h[3]=e.dh,s.useProgram(a.program),a.set("uCanvas",n),a.set("uRect",h),a.set("uAlpha",t),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,e.texture),a.set("uImage",0),i.draw(),!0}forget(){this.program=null}dispose(){this.program?.dispose(),this.program=null}};var E="model";var T=e=>e.matches("[data-umber~=model]"),_=e=>T(e)?E:e.getAttribute("data-umber-layer")??"";function b(e,t,r){e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,t,r),e.disable(e.SCISSOR_TEST),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.frontFace(e.CCW),e.disable(e.STENCIL_TEST),e.disable(e.SAMPLE_ALPHA_TO_COVERAGE),e.disable(e.SAMPLE_COVERAGE),e.depthMask(!0),e.colorMask(!0,!0,!0,!0),e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(null),e.bindVertexArray(null),e.activeTexture(e.TEXTURE0),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)}function S(e,t,r,i){return i.x=Math.round(e.x*r),i.y=Math.round((t-e.y-e.height)*r),i.width=Math.max(0,Math.round(e.width*r)),i.height=Math.max(0,Math.round(e.height*r)),i}var M=class{constructor(e){this.stage=e;this.Nf={x:0,y:0,width:0,height:0};this.full={x:0,y:0,width:0,height:0};this.ask={x:0,y:0,width:0,height:0};this.view={px:{x:0,y:0,width:0,height:0},dpr:1,clip:{x:0,y:0,width:0,height:0}};this.fade=new w(e.gpu.gl)}upright(e){this.stage.fallbacks.Fa(e,`${n(e.el)}: a three.js layer is drawn upright; GL can't turn or tilt a layer's own drawing. Turn the camera in your scene instead.`)}begin(e,t){b(this.stage.gpu.gl,this.stage.gpu.canvas.width,this.stage.gpu.canvas.height);for(let r of e)r.layer?.ready&&this.captured(r)&&this.capture(r,t,this.scale(r))}create(e){let t=this.stage,r=e.el,i=T(r),a=_(r),s=t.env.registry.layers.get(a);if(!s||typeof s.render!="function")return i?t.env.lib.say("model",[]):t.env.lib.say("layer",[a]),e.setStatus("error"),!1;r.hasAttribute("data-umber-effect")&&t.env.lib.say("layerEffect",[a]);let n=i?t.env.lib.config(r,"data-umber-model",s.options??{}):t.env.lib.config(r,"data-umber-layer",s.options??{});return this.build(e,a,s,n),!0}build(e,t,r,i){e.layer=new L(r,this.context(e,t,i),()=>{this.Wa(e)}),this.fade.get()}setup(e){let t=this.stage,r=e.layer;if(!r)return;e.textureState="loading";let a=++r.gen,s;try{s=r.def.setup?.(r.ctx)}catch(t){this.failed(e,"setup",t);return}Promise.resolve(s).then(s=>{if(a!==r.gen||!t.planes.all.includes(e)||t.gpu.context.gone){try{R(s)&&s()}catch(e){i.error(`layer "${r.name}" cleanup failed`,e)}return}b(t.gpu.gl,t.gpu.canvas.width,t.gpu.canvas.height),r.cleanup=R(s)?s:void 0,r.ready=!0,r.sizeKey=-1,e.textureState="ready",e._i(),t.scheduler.wake(2)},t=>{a===r.gen&&this.failed(e,"setup",t)})}failed(e,t,r){i.error(`layer "${e.layer?.name}" ${t} failed; its element keeps its DOM content.`,r),e.layer&&(e.layer.ready=!1),e.textureState="error",e.setStatus("error")}cut(e,t){let r=e.clips?.ia?e.clips.scissorPx:null;if(!r)return t;let i=this.Nf;return i.x=Math.max(t.x,r[0]),i.y=Math.max(t.y,r[1]),i.width=Math.max(0,Math.min(t.x+t.width,r[0]+r[2])-i.x),i.height=Math.max(0,Math.min(t.y+t.height,r[1]+r[3])-i.y),i}context(e,t,r){let i=this.stage,a=t=>this.cut(e,t),s={name:t,el:e.el,gl:i.gpu.gl,canvas:i.gpu.canvas,options:r,state:{},engine:i.env.host.engine,rect:{x:0,y:0,width:0,height:0},px:{x:0,y:0,width:0,height:0},viewport:i.canvasHost.viewport,dpr:1,mouse:{x:.5,y:.5},scrollVelocity:0,opacity:1,time:0,frame:null,get reducedMotion(){return i.env.reducedMotion},wake(e){i.scheduler.wake(e)},busy(r){r?e._a.add(`layer:${t}`):e._a.delete(`layer:${t}`),i.scheduler.markDirty()},three(t){let r=s.px;if(t.resetState?.(),t.autoClear=!1,t.setViewport?.(r.x,r.y,r.width,r.height),e.layer?.def.scissor!==!1){let i=e.layer?.clip??a(r);t.setScissor?.(i.x,i.y,i.width,i.height),t.setScissorTest?.(!0)}}};return s}draw(e,t,r){let i=this.stage,a=e.layer;if(!a)return;let s=a.ctx,n=e.rect;s.rect.x=n[0],s.rect.y=n[1],s.rect.width=n[2],s.rect.height=n[3],r?(Object.assign(s.px,r.px),s.dpr=r.dpr):(s.dpr=i.canvasHost.dpr*i.gpu.renderer.adaptive.scale,S(s.rect,i.canvasHost.viewport.height,s.dpr,s.px)),a.clip=r?r.clip:null,s.time=i.env.frame.time,s.frame=t,s.scrollVelocity=i.env.frame.velocity,s.opacity=e.opacity,s.mouse.x=(i.env.frame.pointer.x-n[0])/Math.max(n[2],1),s.mouse.y=(i.env.frame.pointer.y-n[1])/Math.max(n[3],1);let h=i.gpu.gl,l=s.px.width*65536+s.px.height;try{if(l!==a.sizeKey&&(a.sizeKey=l,a.def.resize?.(s)),a.def.scissor!==!1){let t=a.clip??this.cut(e,s.px);h.enable(h.SCISSOR_TEST),h.scissor(t.x,t.y,t.width,t.height)}h.viewport(s.px.x,s.px.y,s.px.width,s.px.height),h.depthMask(!0),h.clear(h.DEPTH_BUFFER_BIT),a.def.render(s)}catch(t){this.failed(e,"render",t)}b(h,i.gpu.canvas.width,i.gpu.canvas.height)}capture(e,t,r){let i=this.stage.gpu.gl,a=e.layer;if(!a)return;let s=this.stage.canvasHost.dpr*this.stage.gpu.renderer.adaptive.scale,n=this.tg(e,a,s);if(n.width<1||n.height<1){this.Wa(e);return}let h=this.ji(n,r,s),l=h.clip;if(i.enable(i.SCISSOR_TEST),i.scissor(l.x,l.y,l.width,l.height),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),this.draw(e,t,r<1?h:void 0),a.clip=null,!a.ready){this.Wa(e);return}P(i,a,n,l)}tg(e,t,r){let i=this.stage.gpu.canvas,a=this.full,s=this.ask,n=t.def.scissor!==!1;if(n){let t=e.rect;s.x=t[0],s.y=t[1],s.width=t[2],s.height=t[3],S(s,this.stage.canvasHost.viewport.height,r,a)}else a.x=0,a.y=0,a.width=i.width,a.height=i.height;return s.x=Math.max(0,a.x),s.y=Math.max(0,a.y),s.width=Math.min(i.width,a.x+a.width)-s.x,s.height=Math.min(i.height,a.y+a.height)-s.y,n&&e.clips?.ia&&Object.assign(s,this.cut(e,s)),s}ji(e,t,r){let i=this.full,a=this.view,s=a.clip;return s.x=t<1?0:e.x,s.y=t<1?0:e.y,s.width=Math.max(1,Math.round(e.width*t)),s.height=Math.max(1,Math.round(e.height*t)),a.px.x=Math.round(s.x-(e.x-i.x)*t),a.px.y=Math.round(s.y-(e.y-i.y)*t),a.px.width=Math.max(0,Math.round(i.width*t)),a.px.height=Math.max(0,Math.round(i.height*t)),a.dpr=r*t,a}scale(e){let t=e.layer?.def.dpr,r=this.stage.canvasHost.dpr*this.stage.gpu.renderer.adaptive.scale;return t&&t>0&&t<r-.01?t/r:1}alpha(e){return e.layer?.def.followOpacity===!1?1:e.opacity}captured(e){return this.scale(e)<1||this.alpha(e)<.999?!0:e.layer?.def.passes===!0&&this.stage.chunks.fx?.passing===!0}Rf(e,t){let r=this.stage,a=e.layer?.fade;if(r.gpu.gl.disable(r.gpu.gl.SCISSOR_TEST),!a||!this.fade.draw(a,this.alpha(e),r.gpu.canvas,r.gpu.programs.grid(1))){let r=this.fade.get();r.error&&i.warn(`layer fade: ${r.error[2]}`),this.draw(e,t)}}waiting(e){return e.zone.near?"its layer is still setting up":"its layer sets up when it comes near the screen"}Wa(e){let t=e.layer;t?.fade&&(this.stage.gpu.context.gone||this.stage.gpu.gl.deleteTexture(t.fade.texture),t.fade=null)}render(e,t){e.layer?.fade&&this.captured(e)?this.Rf(e,t):(this.Wa(e),this.draw(e,t))}},R=e=>typeof e=="function",A=e=>e.createTexture();function P(e,t,r,i){let a=t.fade;if(a?.width!==i.width||a.height!==i.height){let r=a?.texture??A(e);if(!r)return;e.bindTexture(e.TEXTURE_2D,r),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,i.width,i.height,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),a={texture:r,width:i.width,height:i.height,x:0,y:0,dw:0,dh:0},t.fade=a}a.x=r.x,a.y=r.y,a.dw=r.width,a.dh=r.height,e.bindTexture(e.TEXTURE_2D,a.texture),e.copyTexSubImage2D(e.TEXTURE_2D,0,0,0,i.x,i.y,i.width,i.height)}var L=class{constructor(e,t,r){this.def=e;this.ctx=t;this.Wa=r;this.ready=!1;this.sizeKey=-1;this.gen=0;this.fade=null;this.clip=null;this.name=t.name}stop(){try{this.cleanup?.()}catch(e){i.error(`layer "${this.name}" cleanup failed`,e)}}lost(){this.stop(),this.cleanup=void 0,this.ready=!1,this.gen++,this.fade=null}dispose(){this.stop(),this.gen++,this.Wa()}};var C=e=>typeof e=="object"&&e!==null&&typeof e.WebGLRenderer=="function",U=e=>typeof e=="object"&&e!==null&&!!e.isPerspectiveCamera;function N(e){return typeof e=="number"?e:Array.isArray(e)?e[1]:void 0}var O=e=>e.state.options.scene,I=e=>e.state.options.camera;function D(e){let t=e.state,r={time:0,dt:0,ratio:1,frame:0,width:0,height:0,dpr:1,rect:t.tracker.rect,progress:0,velocity:0,reducedMotion:!1,renderer:null,scene:O(e),camera:I(e),view:t.view};return i=>{let a=i.frame;return r.time=i.time,r.dt=a?.dt??0,r.ratio=a?.ratio??1,r.frame=a?.frame??0,r.width=i.rect.width,r.height=i.rect.height,r.dpr=i.dpr,r.rect=t.tracker.rect,r.progress=e.plane?.progress??0,r.velocity=a?.scroll.velocity??0,r.reducedMotion=e.stage.env.reducedMotion,r.renderer=e.renderer(),r}}function k(e){let t=e.state,r=t.options,i=D(e),a=r.setup;return{setup:a?()=>a({el:t.el,renderer:e.renderer(),scene:O(e),camera:I(e),view:t.view}):void 0,render(a){let s=i(a);r.animate?.(s)===!0&&!s.reducedMotion?e.plane?._a.add("view:animate"):e.plane?._a.delete("view:animate");let n=e.renderer();n&&a.three(n),r.render?r.render(s):n?.render(O(e),I(e)),e.drawnOnce||(e.drawnOnce=!0,t.setStatus("ready"))},resize(a){let s=I(e);r.aspect!==!1&&U(s)&&a.rect.height>0&&(s.aspect=a.rect.width/a.rect.height,s.updateProjectionMatrix?.()),r.resize?.(i(a)),t.emit("resize")},animate:!1,scissor:r.scissor,followOpacity:r.followOpacity,dpr:N(r.dpr),passes:r.passes}}function F(e,t,r){return{wake(t){e.scheduler.wake(t)},busy(){for(let e of[...t._a])e.startsWith("view:")&&e!=="view:animate"&&t._a.delete(e);for(let e of r.busy)t._a.add(`view:${e}`);e.scheduler.markDirty()},get width(){return Math.round(t.rect[2])},get height(){return Math.round(t.rect[3])},get dpr(){return t.layer?.ctx.dpr??0},destroy(){t.destroyed||e.planes.remove(t)}}}var G=class{constructor(e){this.stage=e;this.renderer=null;this.params={};this.entries=new Set}create(e,t={}){if(this.renderer){let e=Object.keys(t).filter(e=>t[e]!==this.params[e]);return e.length&&this.stage.env.lib.say("rendererParams",[e]),this.renderer}if(!C(e))return this.stage.env.lib.say("three",[]),null;let r=this.stage;if(r.gpu.context.gone)return null;let a;try{a=new e.WebGLRenderer({...t,canvas:r.gpu.canvas,context:r.gpu.gl})}catch(e){return i.error("umber.renderer(THREE): three.js could not use Umber's WebGL2 context",e),null}return a.autoClear=!1,a.setPixelRatio?.(1),a.setSize?.(r.gpu.canvas.width,r.gpu.canvas.height,!1),this.renderer=a,this.params=t,b(r.gpu.gl,r.gpu.canvas.width,r.gpu.canvas.height),r.scheduler.wake(1),a}resized(e,t){this.renderer?.setSize?.(e,t,!1)}view(e){let t=this.stage;!e.options.render&&!this.renderer&&t.env.lib.say("viewRenderer",[]);let r={stage:t,state:e,renderer:()=>this.renderer,plane:null,drawnOnce:!1},i=k(r);if(t.planes.of(e.el))return t.env.lib.say("viewPlane",[],e.el),null;let a=t.factory.cf(e.el,i);r.plane=a;let s={plane:a,state:e,redraw:()=>{r.drawnOnce=!1}};this.entries.add(s),a.on("error",()=>{e.setStatus("error","render")}),a.on("destroy",()=>{this.entries.delete(s),e.destroyed||e.view.destroy()});for(let t of e.busy)a._a.add(`view:${t}`);return e.wanted&&t.scheduler.wake(e.wanted),F(t,a,e)}lost(){for(let{state:e,redraw:t}of this.entries)t(),e.setStatus("lost"),e.emit("lost")}restored(){for(let{state:e}of this.entries)e.emit("restored")}dispose(){try{this.renderer?.dispose?.()}catch(e){i.error("the shared three.js renderer failed to dispose",e)}this.renderer=null,this.params={}}};function W(e){a(e.env.host.log),e.chunks.layers=new M(e);let t=e.chunks.views=new G(e);for(let t of e.planes.all.slice())t.kind==="layer"&&!t.layer&&t.el.isConnected&&e.planes.ca(t);return t}export{W as layers};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=()=>{};var t=()=>Promise.reject(new Error("no words"));var r={configure:e,debug:!1,warnings:!1,info:e,warn:e,error:e,report:e,words:t},i=r;function a(e){i=e}var s=(e,t)=>e[t]??NaN;function n(e){if(!e||typeof e.tagName!="string")return"<?>";let t=e.tagName.toLowerCase();if(e.id)return`<${t}#${e.id}>`;let r=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return r?`<${t}.${r}>`:`<${t}>`}var h=e=>e,l=["uniformMatrix2fv","uniformMatrix3fv","uniformMatrix4fv",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"uniformMatrix2x3fv","uniformMatrix2x4fv","uniformMatrix3x2fv","uniformMatrix3x4fv","uniformMatrix4x2fv","uniformMatrix4x3fv"],o=["uniform1iv","uniform2iv","uniform3iv","uniform4iv"],d=["uniform1uiv","uniform2uiv","uniform3uiv","uniform4uiv"];function u(e,t,r){return(t===e.UNSIGNED_INT||t>=e.UNSIGNED_INT_VEC2&&t<=e.UNSIGNED_INT_VEC4?d:o)[r-1]}var c=0,g=0,p=0,f=3e3,m=.02,v=.005,y=/direct3d|^(mozilla)?$/i,x=0,w=0,E=.001,T=!1,_=4,b=500;var M=()=>performance.now()<c,S=class{constructor(e,t,r,i="program"){this.gl=e;this.vertex=t;this.fragment=r;this.uniforms=new Map;this.state="pending";this.started=!1;this.error=null;this.shaders=[];this.options=typeof i=="string"?{label:i}:i;let a=globalThis.occluzeCapture;this.now=a?.version===1,this.Uf=this.now?null:e.getExtension("KHR_parallel_shader_compile");let s=h(e.createProgram());if(!s)throw new Error("the WebGL context is lost");this.program=s,this.options.lazy||this.start()}start(e){if(this.started||!e&&M())return;this.started=!0;let t=this.gl,r=this.program,i,a;try{i=P(t,t.VERTEX_SHADER,this.vertex),a=P(t,t.FRAGMENT_SHADER,this.fragment)}catch{this.state="failed";return}t.attachShader(r,i),t.attachShader(r,a),t.bindAttribLocation(r,0,"aPosition");for(let[e,i]of this.options.attributes??[])t.bindAttribLocation(r,i,e);if(t.linkProgram(r),this.shaders=[i,a],this.Uf)return;if(this.now){this.T();return}if(t.flush(),!x){let e=t.getParameter(t.RENDERER);w=x=y.test(typeof e=="string"?e:"")?m:v}M()||(g=c=performance.now(),p=0);let s=f+this.vertex.length+this.fragment.length;p+=s,c+=Math.min(b,w*s)}ready(){return this.state!=="pending"?this.state==="ok":this.compiled()?(this.T(),this.state==="ok"):!1}compiled(){return this.start(),this.state!=="pending"?!0:this.Uf?!!this.gl.getProgramParameter(this.program,this.Uf.COMPLETION_STATUS_KHR):this.started&&!M()}get failed(){return this.state==="failed"}get eh(){return!this.Uf&&!this.now}T(){if(this.start(!0),this.state!=="pending")return;let e=this.gl,t=this.program,r=performance.now(),i=e.getProgramParameter(t,e.LINK_STATUS),a=performance.now();if(a-r>_?(w=Math.max(x,(Math.min(a,c+a-r)-g)/p),c=a,T=!0):!T&&!this.Uf&&(w=Math.max(E,w/2)),!i){this.error=this.ze(),this.ob(),e.deleteProgram(t),this.state="failed";return}this.ob();let s=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){let i=e.getActiveUniform(t,r);if(!i)continue;let a=i.name.replace(/\[0\]$/,""),s=e.getUniformLocation(t,i.name);s&&this.uniforms.set(a,{location:s,type:i.type,size:i.size})}this.state="ok"}ze(){let e=this.gl,[t,r]=this.shaders,i=C(e,t);if(i!==null)return["vertex",this.options.label,i,this.vertex];let a=C(e,r);return a!==null?["fragment",this.options.label,a,this.fragment]:["link",this.options.label,e.getProgramInfoLog(this.program)??"",""]}ob(){for(let e of this.shaders)this.gl.deleteShader(e);this.shaders=[]}set(e,t){let r=this.state==="ok"?this.uniforms.get(e):void 0;!r||t==null||(typeof t=="number"?A(this.gl,r,t):L(this.gl,r,t))}dispose(){this.ob(),this.state!=="failed"&&this.gl.deleteProgram(this.program)}},R=(e,t)=>t>=e.FLOAT_VEC2&&t<=e.FLOAT_MAT4&&t!==e.BOOL||t>=e.FLOAT_MAT2x3&&t<=e.FLOAT_MAT4x3||t>=e.UNSIGNED_INT_VEC2&&t<=e.UNSIGNED_INT_VEC4;function A(e,t,r){let{type:i,location:a}=t;t.last===r||R(e,i)||(t.last=r,i===e.FLOAT?e.uniform1f(a,r):i===e.UNSIGNED_INT?e.uniform1ui(a,r):e.uniform1i(a,r))}function U(e,t){let r=e.last;if(r?.length===t.length){let e=t.length;for(;e--&&r[e]===t[e];);if(e<0)return!1}else r=[],e.last=r;for(let e=0;e<t.length;e++)r[e]=s(t,e);return!0}function L(e,t,r){if(!U(t,r))return;let{type:i,location:a}=t,s=l[i-e.FLOAT_MAT2];if(i===e.FLOAT_VEC2)e.uniform2fv(a,r);else if(i===e.FLOAT_VEC3)e.uniform3fv(a,r,0,Math.min(r.length,t.size*3));else if(i===e.FLOAT_VEC4)e.uniform4fv(a,r);else if(s)e[s](a,!1,r);else if(i===e.FLOAT)e.uniform1fv(a,r);else{let s=u(e,i,r.length/t.size);s&&e[s](a,r)}}function P(e,t,r){let i=h(e.createShader(t));if(!i)throw new Error("the WebGL context is lost");return e.shaderSource(i,r),e.compileShader(i),i}function C(e,t){return t&&!e.getShaderParameter(t,e.COMPILE_STATUS)?e.getShaderInfoLog(t)??"":null}var N=`#version 300 es\nlayout(location=0)in vec2 aPosition;\nuniform vec2 uCanvas;\nuniform vec4 uRect;\nout vec2 vUv;\nvoid main(){\nvUv=aPosition;\nvec2 px=uRect.xy+aPosition*uRect.zw;\ngl_Position=vec4(px/uCanvas*2.0-1.0,0.0,1.0);\n}\n`,O=`#version 300 es\nprecision highp float;\nin vec2 vUv;\nuniform sampler2D uImage;\nuniform float uAlpha;\nout vec4 outColor;\nvoid main(){\noutColor=texture(uImage,vUv)*uAlpha;\n}\n`,I=class{constructor(e){this.gl=e;this.program=null;this.Lj=[];this.rect=[]}get(){return this.program??=new S(this.gl,N,O,"layer fade")}draw(e,t,r,i){let a=this.get();if(!a.ready())return!1;let s=this.gl,n=this.Lj,h=this.rect;return n[0]=r.width,n[1]=r.height,h[0]=e.x,h[1]=e.y,h[2]=e.dw,h[3]=e.dh,s.useProgram(a.program),a.set("uCanvas",n),a.set("uRect",h),a.set("uAlpha",t),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,e.texture),a.set("uImage",0),i.draw(),!0}forget(){this.program=null}dispose(){this.program?.dispose(),this.program=null}};var D="model";var k=e=>e.matches("[data-umber~=model]"),F=e=>k(e)?D:e.getAttribute("data-umber-layer")??"";function G(e,t,r){e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,t,r),e.disable(e.SCISSOR_TEST),e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.frontFace(e.CCW),e.disable(e.STENCIL_TEST),e.disable(e.SAMPLE_ALPHA_TO_COVERAGE),e.disable(e.SAMPLE_COVERAGE),e.depthMask(!0),e.colorMask(!0,!0,!0,!0),e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),e.useProgram(null),e.bindVertexArray(null),e.activeTexture(e.TEXTURE0),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)}function z(e,t,r,i){return i.x=Math.round(e.x*r),i.y=Math.round((t-e.y-e.height)*r),i.width=Math.max(0,Math.round(e.width*r)),i.height=Math.max(0,Math.round(e.height*r)),i}var V=class{constructor(e){this.stage=e;this.mg={x:0,y:0,width:0,height:0};this.full={x:0,y:0,width:0,height:0};this.ask={x:0,y:0,width:0,height:0};this.view={px:{x:0,y:0,width:0,height:0},dpr:1,clip:{x:0,y:0,width:0,height:0}};this.fade=new I(e.gpu.gl)}upright(e){this.stage.fallbacks.Ja(e,`${n(e.el)}: a three.js layer is drawn upright; GL can't turn or tilt a layer's own drawing. Turn the camera in your scene instead.`)}begin(e,t){G(this.stage.gpu.gl,this.stage.gpu.canvas.width,this.stage.gpu.canvas.height);for(let r of e)r.layer?.ready&&this.captured(r)&&this.capture(r,t,this.scale(r))}create(e){let t=this.stage,r=e.el,i=k(r),a=F(r),s=t.env.registry.layers.get(a);if(!s||typeof s.render!="function")return i?t.env.lib.say("model",[]):t.env.lib.say("layer",[a]),e.setStatus("error"),!1;r.hasAttribute("data-umber-effect")&&t.env.lib.say("layerEffect",[a]);let n=i?t.env.lib.config(r,"data-umber-model",s.options??{}):t.env.lib.config(r,"data-umber-layer",s.options??{});return this.build(e,a,s,n),!0}build(e,t,r,i){e.layer=new B(r,this.context(e,t,i),()=>{this.Rd(e)}),this.fade.get()}setup(e){let t=this.stage,r=e.layer;if(!r)return;e.textureState="loading";let a=++r.gen,s;try{s=r.def.setup?.(r.ctx)}catch(t){this.failed(e,"setup",t);return}Promise.resolve(s).then(s=>{if(a!==r.gen||!t.planes.all.includes(e)||t.gpu.context.gone){try{$(s)&&s()}catch(e){i.error(`layer "${r.name}" cleanup failed`,e)}return}G(t.gpu.gl,t.gpu.canvas.width,t.gpu.canvas.height),r.cleanup=$(s)?s:void 0,r.ready=!0,r.hl=-1,e.textureState="ready",e._o(),t.scheduler.wake(2)},t=>{a===r.gen&&this.failed(e,"setup",t)})}failed(e,t,r){i.error(`layer "${e.layer?.name}" ${t} failed; its element keeps its DOM content.`,r),e.layer&&(e.layer.ready=!1),e.textureState="error",e.setStatus("error")}cut(e,t){let r=e.clips?.lb?e.clips.scissorPx:null;if(!r)return t;let i=this.mg;return i.x=Math.max(t.x,r[0]),i.y=Math.max(t.y,r[1]),i.width=Math.max(0,Math.min(t.x+t.width,r[0]+r[2])-i.x),i.height=Math.max(0,Math.min(t.y+t.height,r[1]+r[3])-i.y),i}context(e,t,r){let i=this.stage,a=t=>this.cut(e,t),s={name:t,el:e.el,gl:i.gpu.gl,canvas:i.gpu.canvas,options:r,state:{},engine:i.env.host.engine,rect:{x:0,y:0,width:0,height:0},px:{x:0,y:0,width:0,height:0},viewport:i.canvasHost.viewport,dpr:1,mouse:{x:.5,y:.5},scrollVelocity:0,opacity:1,time:0,frame:null,get reducedMotion(){return i.env.reducedMotion},wake(e){i.scheduler.wake(e)},busy(r){r?e._U.add(`layer:${t}`):e._U.delete(`layer:${t}`),i.scheduler.markDirty()},three(t){let r=s.px;if(t.resetState?.(),t.autoClear=!1,t.setViewport?.(r.x,r.y,r.width,r.height),e.layer?.def.scissor!==!1){let i=e.layer?.clip??a(r);t.setScissor?.(i.x,i.y,i.width,i.height),t.setScissorTest?.(!0)}}};return s}draw(e,t,r){let i=this.stage,a=e.layer;if(!a)return;let s=a.ctx,n=e.rect;s.rect.x=n[0],s.rect.y=n[1],s.rect.width=n[2],s.rect.height=n[3],r?(Object.assign(s.px,r.px),s.dpr=r.dpr):(s.dpr=i.canvasHost.dpr*i.gpu.renderer.adaptive.scale,z(s.rect,i.canvasHost.viewport.height,s.dpr,s.px)),a.clip=r?r.clip:null,s.time=i.env.frame.time,s.frame=t,s.scrollVelocity=i.env.frame.velocity,s.opacity=e.opacity,s.mouse.x=(i.env.frame.pointer.x-n[0])/Math.max(n[2],1),s.mouse.y=(i.env.frame.pointer.y-n[1])/Math.max(n[3],1);let h=i.gpu.gl,l=s.px.width*65536+s.px.height;try{if(l!==a.hl&&(a.hl=l,a.def.resize?.(s)),a.def.scissor!==!1){let t=a.clip??this.cut(e,s.px);h.enable(h.SCISSOR_TEST),h.scissor(t.x,t.y,t.width,t.height)}h.viewport(s.px.x,s.px.y,s.px.width,s.px.height),h.depthMask(!0),h.clear(h.DEPTH_BUFFER_BIT),a.def.render(s)}catch(t){this.failed(e,"render",t)}G(h,i.gpu.canvas.width,i.gpu.canvas.height)}capture(e,t,r){let i=this.stage.gpu.gl,a=e.layer;if(!a)return;let s=this.stage.canvasHost.dpr*this.stage.gpu.renderer.adaptive.scale,n=this.hk(e,a,s);if(n.width<1||n.height<1){this.Rd(e);return}let h=this.Le(n,r,s),l=h.clip;if(i.enable(i.SCISSOR_TEST),i.scissor(l.x,l.y,l.width,l.height),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),this.draw(e,t,r<1?h:void 0),a.clip=null,!a.ready){this.Rd(e);return}X(i,a,n,l)}hk(e,t,r){let i=this.stage.gpu.canvas,a=this.full,s=this.ask,n=t.def.scissor!==!1;if(n){let t=e.rect;s.x=t[0],s.y=t[1],s.width=t[2],s.height=t[3],z(s,this.stage.canvasHost.viewport.height,r,a)}else a.x=0,a.y=0,a.width=i.width,a.height=i.height;return s.x=Math.max(0,a.x),s.y=Math.max(0,a.y),s.width=Math.min(i.width,a.x+a.width)-s.x,s.height=Math.min(i.height,a.y+a.height)-s.y,n&&e.clips?.lb&&Object.assign(s,this.cut(e,s)),s}Le(e,t,r){let i=this.full,a=this.view,s=a.clip;return s.x=t<1?0:e.x,s.y=t<1?0:e.y,s.width=Math.max(1,Math.round(e.width*t)),s.height=Math.max(1,Math.round(e.height*t)),a.px.x=Math.round(s.x-(e.x-i.x)*t),a.px.y=Math.round(s.y-(e.y-i.y)*t),a.px.width=Math.max(0,Math.round(i.width*t)),a.px.height=Math.max(0,Math.round(i.height*t)),a.dpr=r*t,a}scale(e){let t=e.layer?.def.dpr,r=this.stage.canvasHost.dpr*this.stage.gpu.renderer.adaptive.scale;return t&&t>0&&t<r-.01?t/r:1}alpha(e){return e.layer?.def.followOpacity===!1?1:e.opacity}captured(e){return this.scale(e)<1||this.alpha(e)<.999?!0:e.layer?.def.passes===!0&&this.stage.chunks.fx?.passing===!0}Uh(e,t){let r=this.stage,a=e.layer?.fade;if(r.gpu.gl.disable(r.gpu.gl.SCISSOR_TEST),!a||!this.fade.draw(a,this.alpha(e),r.gpu.canvas,r.gpu.programs.grid(1))){let r=this.fade.get();r.error&&i.warn(`layer fade: ${r.error[2]}`),this.draw(e,t)}}waiting(e){return e.zone.near?"its layer is still setting up":"its layer sets up when it comes near the screen"}Rd(e){let t=e.layer;t?.fade&&(this.stage.gpu.context.gone||this.stage.gpu.gl.deleteTexture(t.fade.texture),t.fade=null)}render(e,t){e.layer?.fade&&this.captured(e)?this.Uh(e,t):(this.Rd(e),this.draw(e,t))}},$=e=>typeof e=="function",H=e=>e.createTexture();function X(e,t,r,i){let a=t.fade;if(a?.width!==i.width||a.height!==i.height){let r=a?.texture??H(e);if(!r)return;e.bindTexture(e.TEXTURE_2D,r),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,i.width,i.height,0,e.RGBA,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),a={texture:r,width:i.width,height:i.height,x:0,y:0,dw:0,dh:0},t.fade=a}a.x=r.x,a.y=r.y,a.dw=r.width,a.dh=r.height,e.bindTexture(e.TEXTURE_2D,a.texture),e.copyTexSubImage2D(e.TEXTURE_2D,0,0,0,i.x,i.y,i.width,i.height)}var B=class{constructor(e,t,r){this.def=e;this.ctx=t;this.Rd=r;this.ready=!1;this.hl=-1;this.gen=0;this.fade=null;this.clip=null;this.name=t.name}stop(){try{this.cleanup?.()}catch(e){i.error(`layer "${this.name}" cleanup failed`,e)}}lost(){this.stop(),this.cleanup=void 0,this.ready=!1,this.gen++,this.fade=null}dispose(){this.stop(),this.gen++,this.Rd()}};var W=e=>typeof e=="object"&&e!==null&&typeof e.WebGLRenderer=="function",j=e=>typeof e=="object"&&e!==null&&!!e.isPerspectiveCamera;function K(e){return typeof e=="number"?e:Array.isArray(e)?e[1]:void 0}var Y=e=>e.state.options.scene,q=e=>e.state.options.camera;function J(e){let t=e.state,r={time:0,dt:0,ratio:1,frame:0,width:0,height:0,dpr:1,rect:t.tracker.rect,progress:0,velocity:0,reducedMotion:!1,renderer:null,scene:Y(e),camera:q(e),view:t.view};return i=>{let a=i.frame;return r.time=i.time,r.dt=a?.dt??0,r.ratio=a?.ratio??1,r.frame=a?.frame??0,r.width=i.rect.width,r.height=i.rect.height,r.dpr=i.dpr,r.rect=t.tracker.rect,r.progress=e.plane?.progress??0,r.velocity=a?.scroll.velocity??0,r.reducedMotion=e.stage.env.reducedMotion,r.renderer=e.renderer(),r}}async function Q(e){let t=e.renderer(),r=Y(e),a=q(e);if(!(!t?.compileAsync||!r||!a))try{await t.compileAsync(r,a)}catch(e){i.info("umber.view(): the scene's shaders compile at its first draw",e)}}function Z(e){let t=e.state,r=t.options,i=J(e),a=r.setup;return{async setup(){let r=await(a?.({el:t.el,renderer:e.renderer(),scene:Y(e),camera:q(e),view:t.view}));return await Q(e),r},render(a){let s=i(a);r.animate?.(s)===!0&&!s.reducedMotion?e.plane?._U.add("view:animate"):e.plane?._U.delete("view:animate");let n=e.renderer();n&&a.three(n),r.render?r.render(s):n?.render(Y(e),q(e)),e.drawnOnce||(e.drawnOnce=!0,t.setStatus("ready"))},resize(a){let s=q(e);r.aspect!==!1&&j(s)&&a.rect.height>0&&(s.aspect=a.rect.width/a.rect.height,s.updateProjectionMatrix?.()),r.resize?.(i(a)),t.emit("resize")},animate:!1,scissor:r.scissor,followOpacity:r.followOpacity,dpr:K(r.dpr),passes:r.passes}}function ee(e,t,r){return{wake(t){e.scheduler.wake(t)},busy(){for(let e of[...t._U])e.startsWith("view:")&&e!=="view:animate"&&t._U.delete(e);for(let e of r.busy)t._U.add(`view:${e}`);e.scheduler.markDirty()},get width(){return Math.round(t.rect[2])},get height(){return Math.round(t.rect[3])},get dpr(){return t.layer?.ctx.dpr??0},destroy(){t.destroyed||e.planes.remove(t)}}}var te=class{constructor(e){this.stage=e;this.renderer=null;this.params={};this.entries=new Set}create(e,t={}){if(this.renderer){let e=Object.keys(t).filter(e=>t[e]!==this.params[e]);return e.length&&this.stage.env.lib.say("rendererParams",[e]),this.renderer}if(!W(e))return this.stage.env.lib.say("three",[]),null;let r=this.stage;if(r.gpu.context.gone)return null;let a;try{a=new e.WebGLRenderer({...t,canvas:r.gpu.canvas,context:r.gpu.gl})}catch(e){return i.error("umber.renderer(THREE): three.js could not use Umber's WebGL2 context",e),null}return a.autoClear=!1,a.setPixelRatio?.(1),a.setSize?.(r.gpu.canvas.width,r.gpu.canvas.height,!1),this.renderer=a,this.params=t,G(r.gpu.gl,r.gpu.canvas.width,r.gpu.canvas.height),r.scheduler.wake(1),a}resized(e,t){this.renderer?.setSize?.(e,t,!1)}view(e){let t=this.stage;!e.options.render&&!this.renderer&&t.env.lib.say("viewRenderer",[]);let r={stage:t,state:e,renderer:()=>this.renderer,plane:null,drawnOnce:!1},i=Z(r);if(t.planes.of(e.el))return t.env.lib.say("viewPlane",[],e.el),null;let a=t.factory.Gl(e.el,i);r.plane=a;let s={plane:a,state:e,redraw:()=>{r.drawnOnce=!1}};this.entries.add(s),a.on("error",()=>{e.setStatus("error","render")}),a.on("destroy",()=>{this.entries.delete(s),e.destroyed||e.view.destroy()});for(let t of e.busy)a._U.add(`view:${t}`);return e.wanted&&t.scheduler.wake(e.wanted),ee(t,a,e)}lost(){for(let{state:e,redraw:t}of this.entries)t(),e.setStatus("lost"),e.emit("lost")}restored(){for(let{state:e}of this.entries)e.emit("restored")}dispose(){try{this.renderer?.dispose?.()}catch(e){i.error("the shared three.js renderer failed to dispose",e)}this.renderer=null,this.params={}}};function re(e){a(e.env.host.log),e.chunks.layers=new V(e);let t=e.chunks.views=new te(e);for(let t of e.planes.all.slice())t.kind==="layer"&&!t.layer&&t.el.isConnected&&e.planes.pe(t);return t}export{re as layers};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- var e=["scroll","scrollfx","router","handoff","scrub","input","debug","three"],t=t=>e.includes(t),o=e=>(e??"").split(/[\s,]+/).filter(Boolean);var r=/^(localhost|127\.0\.0\.1|\[::1\]|.+\.localhost|.+\.test|(10\.\d+|172\.(1[6-9]|2\d|3[01])|192\.168)\.\d+\.\d+|\[f([cd][\da-f]|e[89ab])[\da-f]:[\da-f:.]*\])$/;var a=3e3,n=700,c=e=>(console.warn(`Umber: couldn't check ${e}'s licence at umber.occluze.com, so this page shows without GL.`),"unreachable"),i=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function s(e,t){let o="1=MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKx8yfTMpNDg7/qifhBeSBVuQpfmTv4kKTlCyfOvjhK8VRNKAUYRCMIED2z7Q81eEyxqGc5Z8yMAxPYODPLchvQ==".split(",").find(t=>t.startsWith(`${e.kid}=`))?.slice(e.kid.length+1);if(!o||e.host!==t||e.until*1e3<=Date.now()||!("subtle"in crypto))return!1;try{let t=await crypto.subtle.importKey("spki",i(o),{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),r=`${e.host}|${e.until}|${e.preview?1:0}`;return await crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},t,i(e.sig),(new TextEncoder).encode(r))}catch{return!1}}var l=e=>typeof e=="object"&&e!==null&&"ok"in e&&e.ok===!0&&"sig"in e&&"kid"in e;function u(e){if("timeout"in AbortSignal)return AbortSignal.timeout(e);let t=new AbortController;return setTimeout(()=>{t.abort()},e),t.signal}async function d(e,t,o){return!l(e)||!await s(e,t)?!1:(e.preview&&o?.().then(e=>{e.showBadge()},()=>{}),!0)}async function h(e,t,o){try{let r=await fetch(e,{credentials:"omit",cache:"force-cache",signal:u(n)});if(r.ok&&await d(await r.json(),t,o))return"yes"}catch{}return c(t)}async function m(n,i){let s=location.hostname;if(!s&&location.protocol!=="file:")return c(location.protocol);if(!s||r.test(s)){s&&console.info(`Umber runs here without a licence. Before launch, add your key from occluze.com/dashboard to the umber.js tag (data-umber-key) or createUmber({ key }).\nAdd-ons load from the umber.js tag: data-umber-modules="scroll router" (also handoff, scrub, input, debug, three). Docs: occluze.com/umber/llms.txt`);let r=document.querySelector("script[data-umber-modules]")?.dataset.umberModules,a=o(r).filter(e=>!t(e));return a.length&&console.error(`Umber: data-umber-modules names ${a.join(", ")}, which isn't an add-on, so umber.js doesn't load it. The add-ons are ${e.join(", ")}.`),"yes"}let l=`https://umber.occluze.com/v2/check?k=${encodeURIComponent(n??"")}&h=${encodeURIComponent(s)}`,m;try{let e=await fetch(l,{credentials:"omit",signal:u(a)});if(!e.ok)return await h(l,s,i);m=await e.json()}catch{return h(l,s,i)}return typeof m=="object"&&m!==null&&"ok"in m&&m.ok===!1?(console.warn(n?`Umber: ${s} isn't on your domains, so this page shows without GL. To add it, turn on Approve automatically and reload: https://occluze.com/dashboard?view=umber`:"Umber: this page has no key, so it shows without GL. Find yours at https://occluze.com/dashboard?view=umber"),"no"):await d(m,s,i)?"yes":c(s)}export{m as ask};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=["scrollfx","handoff","scrub","input","debug","three"],t=t=>e.includes(t),o=e=>(e??"").split(/[\s,]+/).filter(Boolean);var n=/^(localhost|127\.0\.0\.1|\[::1\]|.+\.localhost|.+\.test|(10\.\d+|172\.(1[6-9]|2\d|3[01])|192\.168)\.\d+\.\d+|\[f([cd][\da-f]|e[89ab])[\da-f]:[\da-f:.]*\])$/;var r=3e3,a=700,i=100,c=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function s(e,t){let o="1=MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKx8yfTMpNDg7/qifhBeSBVuQpfmTv4kKTlCyfOvjhK8VRNKAUYRCMIED2z7Q81eEyxqGc5Z8yMAxPYODPLchvQ==".split(",").find(t=>t.startsWith(`${e.kid}=`))?.slice(e.kid.length+1);if(e.host!==t)return"forged";if(!o||e.until*1e3<=Date.now()||!("subtle"in crypto))return"unknown";try{let t=await crypto.subtle.importKey("spki",c(o),{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),n=`${e.host}|${e.until}|${e.preview?1:0}`;return await crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},t,c(e.sig),(new TextEncoder).encode(n))?"yes":"forged"}catch{return"forged"}}var u=e=>typeof e=="object"&&e!==null&&"ok"in e&&e.ok===!0&&"sig"in e&&"kid"in e;function l(e){if("timeout"in AbortSignal)return AbortSignal.timeout(e);let t=new AbortController;return setTimeout(()=>{t.abort()},e),t.signal}function d({load:e,host:t}){if(!e)return;let o=()=>e().then(e=>{e.showBadge(t)});o().catch(o).catch(()=>{t&&(console.warn("Umber: the Occluze badge (chunks/badge.js) could not be loaded, so Umber has stopped and the page shows without GL. The free version of Umber shows the badge; a site on a licence runs without it: https://occluze.com/dashboard?view=umber"),t.gone())})}async function h(e,t,o){let n=u(e)?await s(e,t):"forged";return n==="yes"&&e.preview&&d(o),n}async function m(e,t,o){try{let n=await fetch(e,{credentials:"omit",cache:"force-cache",signal:l(a)});if(n.ok&&await h(await n.json(),t,o)==="yes")return"yes"}catch{}return"unreachable"}var f=new Set;function b(e,t){let o=l(e);f.add(o),o.addEventListener("abort",()=>{f.delete(o),t()})}var y="umber-check:";function w(e){return new Promise(t=>{let o=document.createElement("iframe"),n=e=>{removeEventListener("message",a),o.remove(),t(e)},a=e=>{let t=e.data;if(!(e.source!==o.contentWindow||typeof t!="string"||!t.startsWith(y)))try{n(JSON.parse(t.slice(y.length)))}catch{n(void 0)}};addEventListener("message",a),b(r,()=>{n(void 0)});try{o.setAttribute("sandbox","allow-scripts"),o.name=e,o.style.display="none",o.srcdoc=`<script src="${new URL("recheck.js",import.meta.url).href}"><\/script>`,document.documentElement.append(o)}catch{n(void 0)}})}function p(){let e=new URL("https://umber.occluze.com/v2/check").origin,t=()=>{},o=new Promise(o=>{t=t=>{t.disposition==="enforce"&&t.blockedURI.startsWith(e)&&o(!0)}});return document.addEventListener("securitypolicyviolation",t),async()=>{let e=new Promise(e=>{b(i,()=>{e(!1)})}),n=await Promise.race([o,e]);return document.removeEventListener("securitypolicyviolation",t),n}}var g="Your key and your sites: https://occluze.com/dashboard?view=umber";function v(e,t){return console.warn(`Umber: ${e}, so Umber runs with the Occluze badge. ${g}`),d(t),"no"}var k=(e,t,o)=>typeof e=="object"&&e!==null&&t in e&&e[t]===o;function U(n){n&&console.info(`Umber runs here without a licence. Before launch, add your key from occluze.com/dashboard to the umber.js tag (data-umber-key) or createUmber({ key }).\nAdd-ons load from the umber.js tag: data-umber-modules="scrollfx handoff" (also scrub, input, debug, three). Docs: occluze.com/umber/llms.txt`);let r=document.querySelector("script[data-umber-modules]")?.dataset.umberModules,a=o(r).filter(e=>!t(e));a.length&&console.error(`Umber: data-umber-modules names ${a.join(", ")}, which isn't an add-on, so umber.js doesn't load it. The add-ons are ${e.join(", ")}.`)}async function $(e,t,o,n){if(k(e,"ok",!1))return k(e,"blocked",!0)?(console.warn(`Umber: Occluze has turned Umber off for ${o}, so this page shows without GL.`),"blocked"):v(t?`${o} isn't on your list of sites (add it under Umber's Domains)`:"this page has no key",n);if(!k(e,"ok",!0))return"unreachable";let r=await h(e,o,n);return r==="forged"?v(`the licence check's answer for ${o} isn't one Occluze signed`,n):r==="yes"?"yes":"unreachable"}async function A(e,t,o,a){let i={load:t,host:o&&a&&{engine:o(),gone:a}},c=location.hostname;if(!c&&location.protocol!=="file:")return d(i),"no";if(!c||n.test(c))return U(c),"yes";let s=`https://umber.occluze.com/v2/check?k=${encodeURIComponent(e??"")}&h=${encodeURIComponent(c)}`,u=p(),h,f=!1;try{let e=await fetch(s,{credentials:"omit",signal:l(r)});e.ok&&(h=await e.json())}catch{f=!0}if(h!==void 0)return $(h,e,c,i);if(await m(s,c,i)==="yes")return"yes";if(f&&await u())return v(`this page's Content Security Policy stops the licence check (add ${new URL(s).origin} to connect-src)`,i);let b=await w(s);return b===void 0?"unreachable":$(b,e,c,i)}export{A as ask};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- function t(t){let e=[],s=t??"",i=/[\s,]*(\S+)([^,]*)/g;for(let t=i.exec(s);t;t=i.exec(s)){let[s,n,r=""]=t;if(!n)break;let o=n.replace(/,+$/,"");o!==n&&(i.lastIndex=t.index+s.indexOf(n)+n.length),e.push([o,o!==n?"1x":r.trim()||"1x"])}return e}function e(t){let s=/^calc\((.+)\)$/.exec(t)?.[1];if(s!==void 0){let[t="",...i]=s.trim().split(/\s+([+-])\s+/),n=e(t);for(let t=0;t<i.length;t+=2)n+=(i[t]==="-"?-1:1)*e(i[t+1]??"");return n}let i=/^([\d.]+)(vw|px|r?em)$/.exec(t);if(!i)return innerWidth;let[,n="",r]=i,o=Number(n);return r==="vw"?innerWidth*o/100:r==="px"?o:o*16}function s(t){for(let s of i(t)){let t=n(s),i=t>0?s.slice(0,t):"";if(s&&(!i||matchMedia(i).matches))return e(s.slice(t+1))}return innerWidth}function i(t){let e=[],s=0,i=0;for(let n=0;n<=t.length;n++){let r=t.charAt(n);r==="("?s++:r===")"?s--:!s&&(r===","||n===t.length)&&(e.push(t.slice(i,n).trim()),i=n+1)}return e}function n(t){let e=-1;for(let s=0,i=0;s<t.length;s++){let n=t.charAt(s);n==="("?i++:n===")"?i--:!i&&/\s/.test(n)&&(e=s)}return e}function r(e){let i=e.ownerDocument.baseURI||document.baseURI,n=t=>t?new URL(t,i).href:"",r=t(e.getAttribute("srcset")).map(([t,e])=>({url:t,size:parseFloat(e)||1,width:e.endsWith("w")})),o=e.getAttribute("src");o&&!r.some(t=>t.width||t.size===1)&&r.push({url:o,size:1,width:!1});let[l]=r;if(!l)return"";let h=window.devicePixelRatio||1,a=h;return l.width&&(a=s(e.getAttribute("sizes")??"")*h),r.sort((t,e)=>t.size-e.size),n((r.find(t=>t.size>=a)??r.at(-1)??l).url)}function o(t){return typeof t=="number"?new Float32Array(t):new Float32Array(t)}var l=(t,e)=>t[e]??NaN;var h={duration:1,ease:"umber"},a=3e3,u=3e3,c=8;function d(t,e){return t.includes(`data-umber-id="${e}"`)||t.includes(`data-umber-id='${e}'`)||t.includes(`data-umber-id=${e}`)}var f=(t,e)=>t.querySelector(`[data-umber-id="${e.replace(/["\\]/g,"\\$&")}"]`),p=t=>typeof t=="object"&&t!==null&&"querySelector"in t&&typeof t.querySelector=="function",g=t=>typeof t=="object"&&t!==null&&"then"in t&&typeof t.then=="function";function m(t){let e=t&&typeof t=="object"&&"html"in t?t.html:t;return typeof e=="string"?e?t=>d(e,t):null:p(e)?t=>!!f(e,t):null}function y(t){return t[2]>0&&t[3]>0&&t[0]<window.innerWidth&&t[0]+t[2]>0&&t[1]<window.innerHeight&&t[1]+t[3]>0}var b=t=>t.opacity<=.001&&y(t.rect);function v(e){let s=e.media,i=[e.el.getAttribute("data-umber-src")??""];if(s?.tagName==="IMG"){let e=s;i.push(e.currentSrc,e.getAttribute("src")??"",...t(e.getAttribute("srcset")).map(t=>t[0]))}return i.filter(Boolean).map(t=>new URL(t,document.baseURI).href)}function x(t,e){let s=v(t);return v(e).some(t=>s.includes(t))}var w=t=>{t.morphHidden=!1,t.el.removeAttribute("data-umber-morphing")};function z(t,e){t.ub&&t.ub!==e&&w(t.ub)}function k(t,e){let{from:s,to:i}=t,n=s._c,r=s.rect;if(!i.level&&A(t.originXf)){n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=1,n[5]=0,n[6]=r[0],n[7]=r[1],s.size[0]=r[2],s.size[1]=r[3],s.level=0;return}let o=t.originXf,h=i._c,a=o[8]||1,u=h[8]||1;for(let t=0;t<9;t++){let s=l(o,t)/a;n[t]=s+(l(h,t)/u-s)*e}s.size[0]=t.originSize[0]+(i.size[0]-t.originSize[0])*e,s.size[1]=t.originSize[1]+(i.size[1]-t.originSize[1])*e,s.level=1,s.xfReason=null;let c=s.size[0]/2,d=s.size[1]/2,f=n[2]*c+n[5]*d+n[8],p=s._v;p[0]=(n[0]*c+n[3]*d+n[6])/f-c,p[1]=(n[1]*c+n[4]*d+n[7])/f-d,p[2]=s.size[0],p[3]=s.size[1]}function A(t){return t[0]===1&&t[1]===0&&t[2]===0&&t[3]===0&&t[4]===1&&t[5]===0&&t[8]===1}function S(t){return t.sx=NaN,t}function _(t){let{from:e,to:s}=t;e.rect.set(s.rect),e.radius.set(s.radius),e._b=s._b,e._c.set(s._c),e.size.set(s.size),e.opacity=1}function C(t,e,s){let i=t.rect,n=t._v,r=t._c;i[0]+=e,i[1]+=s,n[0]+=e,n[1]+=s,r[0]+=e*r[2],r[1]+=s*r[2],r[3]+=e*r[5],r[4]+=s*r[5],r[6]+=e*r[8],r[7]+=s*r[8]}function N(t){for(let e of t.plays.la.keys()){let s=t.uniforms[e];s&&(s.value=1)}}function R(t,e,s){for(let i of t.plays.la.keys()){let n=t.uniforms[i];n&&typeof n.value=="number"&&n.value<1&&s.to(n,{value:1,duration:Math.max(.3,e),ease:"cubic.out"})}}var M=class{constructor(t){this.host=t;this.snapshots=new Map;this.flights=[];this.parked=new Set;this.later=new Map;this.Sb=0;this.Xh=t=>{t.el.isConnected&&this.host.transitions.ongoing&&!t.destroyed||(this.parked.delete(t),t.destroyed||this.Gb(t,!0))}}snap(t,e,s=0,i=null){let n=this.host.env.frame,r=t.scrolls?n.scrollX:n.pageX,l=t.scrolls?n.scrollY:n.pageY,h=o(4),a=o(9),u=o(2),c=o(4);return h.set(t.rect),a.set(t._c),u.set(t.size),c.set(t.radius),{plane:t,rect:h,xf:a,size:u,radius:c,ky:t._b,opacity:t.opacity,frozen:e,ub:i,until:s,sx:r,sy:l,ex:t.doc.x-r,ey:t.doc.y-l}}get busy(){return this.flights.length>0}holds(t){for(let e of this.snapshots.values())if(e.plane===t)return!0;return!1}capture(t,e=!1){e||this.settle(),t&&typeof t.then=="function"&&(this.known(t),t=void 0);let s=m(t);e||this.Of(s),this.Tg(s),t&&typeof t=="object"&&!("html"in t)&&this.preload(t),this.snapshots.size&&this.host.scheduler.markDirty()}Of(t){for(let e of this.flights.slice()){if(!t?.(e.id)){_(e),this.finish(e,e.to.drawable());continue}this.flights.splice(this.flights.indexOf(e),1),this.snapshots.set(e.id,S(this.snap(e.from,!0,0,e.to)))}}Tg(t){let e=this.host.planes.all,s=e.filter(t=>t.visible).concat(e.filter(t=>!t.visible&&b(t)));for(let e of s){let s=e.el.getAttribute("data-umber-id");!s||e.kind==="layer"||this.snapshots.has(s)||e.status!=="ready"||e.morphHidden||t&&!t(s)||(this.snapshots.set(s,this.snap(e,!!t)),t&&this.host.planes.detach(e))}}known(t){if(g(t)){let e=this.Sb;t.then(t=>{e===this.Sb&&this.known(t)},()=>{});return}let e=m(t);if(e){for(let[t,s]of this.snapshots)s.frozen||s.until||(e(t)?this.host.planes.all.includes(s.plane)&&(this.snapshots.set(t,this.snap(s.plane,!0)),this.host.planes.detach(s.plane)):this.drop(t));typeof t=="object"&&t&&!("html"in t)&&this.preload(t)}}preload(t){for(let e of this.snapshots.keys()){let s=f(t,e),i=s?.matches("img")?s:s?.querySelector("img"),n=i&&!i.parentElement?.querySelector("source")&&r(i);n&&fetch(n,{mode:"cors",credentials:"omit"}).catch(()=>{})}}keep(t){let e=t.el.getAttribute("data-umber-id");return!e||this.snapshots.has(e)||t.kind==="layer"||t.status!=="ready"||t.morphHidden||this.host.env.reducedMotion||!t.visible&&!b(t)?!1:(this.wait(e,this.snap(t,!1,performance.now()+u)),!0)}wait(t,e){let s=[...this.snapshots].filter(([,t])=>t.until).sort((t,e)=>t[1].until-e[1].until),[i]=s;i&&s.length>=c&&this.drop(i[0]),this.snapshots.set(t,e),setTimeout(()=>{this.snapshots.get(t)===e&&this.drop(t)},e.until-performance.now())}drop(t){let e=this.snapshots.get(t);e&&(this.snapshots.delete(t),this.release(e),this.host.scheduler.markDirty())}forget(t){for(let[e,s]of this.snapshots)if(s.plane===t)return this.snapshots.delete(e),!0;return!1}claim(t){let e=t.el.getAttribute("data-umber-id");for(let t of this.flights.slice())t.id===e&&!t.to.el.isConnected&&this.Nd(t);let s=e?this.snapshots.get(e):void 0,i=this.host;if(!e||!s||t.kind==="layer"||i.env.reducedMotion)return!1;if(!i.env.kit.onScreen(t.el))return i.scheduler.changing&&s.plane.el.isConnected&&this.later.set(e,t),!1;this.later.delete(e),this.snapshots.delete(e),z(s,t);let n=s.plane,r=s.frozen?s:this.snap(n,!1);s.frozen||i.planes.detach(n);let o=this.vg(e,r,t);return n.opacity=r.opacity,t._E=!0,t.morphHidden=!0,N(t),t.el.setAttribute("data-umber-morphing",""),R(n,o,i.env.tweens),i.scheduler.markDirty(),!0}vg(t,e,s){let i=this.host.env,n=i.lib.config(s.el,"data-umber-morph",h),r=Math.max(0,n.duration||0);return this.flights.push({id:t,from:e.plane,to:s,origin:e.rect,originXf:e.xf,originSize:e.size,originRadius:e.radius,originKy:e.ky,originOpacity:e.opacity,start:i.now,duration:r,ease:i.kit.ease(n.ease),doneAt:0,same:x(e.plane,s)}),r}retry(){let t=[];for(let[e,s]of this.later){let i=this.snapshots.get(e);i?.plane.el.isConnected&&s.el.isConnected||(this.later.delete(e),i&&s.el.isConnected&&this.host.planes.all.includes(s)&&this.claim(s)?t.push(s):i&&this.drop(e))}return t}Nd(t){this.flights.splice(this.flights.indexOf(t),1),w(t.to),this.wait(t.id,S(this.snap(t.from,!0,performance.now()+u)))}settle(t=!0){t&&(this.later.clear(),this.Sb++);for(let[e,s]of this.snapshots)!t&&(s.until||this.later.has(e))||this.drop(e);this.Yd()}Yd(){this.parked.forEach(this.Xh)}update(t){if(this.snapshots.size&&this.follow(),this.parked.size&&this.Yd(),!this.flights.length)return!1;for(let e=this.flights.length;e--;){let s=this.flights[e];if(!s)continue;let i=s.to;!this.host.planes.all.includes(i)||i.status==="error"||i.textureState==="error"?this.Ph(s):this.fly(s,t)}return!0}Ph(t){let{from:e,to:s}=t;s.status!=="error"&&!s.el.isConnected&&(this.host.scheduler.changing||!e.el.isConnected&&this.host.transitions.ongoing)?this.Nd(t):this.finish(t,!1)}fly(t,e){let{from:s,to:i}=t,n=t.duration>0?Math.min(1,(e-t.start)/(t.duration*1e3)):1,r=t.ease(n),o=i.rect;for(let e=0;e<4;e++){let n=l(t.origin,e),h=l(t.originRadius,e);s.rect[e]=n+(l(o,e)-n)*r,s.radius[e]=h+(l(i.radius,e)-h)*r}if(s._b=t.originKy+(i._b-t.originKy)*r,k(t,r),s.opacity=t.originOpacity+((this.host.transitions.ongoing?1:i.opacity)-t.originOpacity)*r,n<1)return;t.doneAt||(t.doneAt=e),(i.opacity>=.99||!this.host.transitions.ongoing)&&i.drawable()?this.finish(t,!0):e-t.doneAt>a&&this.finish(t,!1)}follow(){for(let t of this.snapshots.values())t.frozen&&t.sx===t.sx&&this.dg(t)}dg(t){let e=t.plane,s=this.host.env.frame,i=e.scrolls?s.scrollX:s.pageX,n=e.scrolls?s.scrollY:s.pageY;if(i===t.sx&&n===t.sy)return;let r=e.el.isConnected?e.el.getBoundingClientRect():null;if(!r?.width){t.sx=NaN;return}let o=e.pinned?r.left-t.ex:t.sx-i,l=e.pinned?r.top-t.ey:t.sy-n;t.sx=i,t.sy=n,t.ex=r.left,t.ey=r.top,!(!o&&!l)&&(C(e,o,l),t.rect.set(e.rect),t.xf.set(e._c),this.host.scheduler.markDirty())}draw(t){if(this.snapshots.size)for(let e of this.snapshots.values())e.frozen&&!this.host.planes.all.includes(e.plane)&&t(e.plane);for(let e of this.flights){let{from:s,to:i}=e,n=s.texture;e.same&&i.texture?.ready&&s.kind==="image"&&(s.texture=i.texture),t(s),s.texture=n}}cancel(){for(let t of this.flights.slice())this.finish(t,!1);this.settle(),this.parked.forEach(t=>{this.Gb(t,!0)}),this.parked.clear()}finish(t,e){if(this.flights.splice(this.flights.indexOf(t),1),e){t.to.morphHidden=!1;let e=t.to.el;this.host.env.host.loadCovers?.().then(t=>t.landed(e,this.host.canvasHost.el,this.host.env.lib.say),()=>{})}else w(t.to);this.Gb(t.from,!e),this.host.scheduler.markDirty()}Gb(t,e){t.el.isConnected?this.host.transitions.ongoing&&!e?this.parked.add(t):this.host.planes.attach(t):this.host.planes.discard(t)}release(t){z(t);let e=t.plane;this.host.planes.all.includes(e)||this.Gb(e,!0)}};function O(t){return t.chunks.morph=new M(t)}export{O as morph};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ function t(t){let e=[],s=t??"",i=/[\s,]*(\S+)([^,]*)/g;for(let t=i.exec(s);t;t=i.exec(s)){let[s,n,r=""]=t;if(!n)break;let o=n.replace(/,+$/,"");o!==n&&(i.lastIndex=t.index+s.indexOf(n)+n.length),e.push([o,o!==n?"1x":r.trim()||"1x"])}return e}function e(t){let s=/^calc\((.+)\)$/.exec(t)?.[1];if(s!==void 0){let[t="",...i]=s.trim().split(/\s+([+-])\s+/),n=e(t);for(let t=0;t<i.length;t+=2)n+=(i[t]==="-"?-1:1)*e(i[t+1]??"");return n}let i=/^([\d.]+)(vw|px|r?em)$/.exec(t);if(!i)return innerWidth;let[,n="",r]=i,o=Number(n);return r==="vw"?innerWidth*o/100:r==="px"?o:o*16}function s(t){for(let s of i(t)){let t=n(s),i=t>0?s.slice(0,t):"";if(s&&(!i||matchMedia(i).matches))return e(s.slice(t+1))}return innerWidth}function i(t){let e=[],s=0,i=0;for(let n=0;n<=t.length;n++){let r=t.charAt(n);r==="("?s++:r===")"?s--:!s&&(r===","||n===t.length)&&(e.push(t.slice(i,n).trim()),i=n+1)}return e}function n(t){let e=-1;for(let s=0,i=0;s<t.length;s++){let n=t.charAt(s);n==="("?i++:n===")"?i--:!i&&/\s/.test(n)&&(e=s)}return e}function r(e){let i=e.ownerDocument.baseURI||document.baseURI,n=t=>t?new URL(t,i).href:"",r=t(e.getAttribute("srcset")).map(([t,e])=>({url:t,size:parseFloat(e)||1,width:e.endsWith("w")})),o=e.getAttribute("src");o&&!r.some(t=>t.width||t.size===1)&&r.push({url:o,size:1,width:!1});let[l]=r;if(!l)return"";let h=window.devicePixelRatio||1,a=h;return l.width&&(a=s(e.getAttribute("sizes")??"")*h),r.sort((t,e)=>t.size-e.size),n((r.find(t=>t.size>=a)??r.at(-1)??l).url)}function o(t){return typeof t=="number"?new Float32Array(t):new Float32Array(t)}var l=(t,e)=>t[e]??NaN;var h={duration:1,ease:"umber"},a=3e3,u=3e3,d=8;function c(t,e){return t.includes(`data-umber-id="${e}"`)||t.includes(`data-umber-id='${e}'`)||t.includes(`data-umber-id=${e}`)}var f=(t,e)=>t.querySelector(`[data-umber-id="${e.replace(/["\\]/g,"\\$&")}"]`),p=t=>typeof t=="object"&&t!==null&&"querySelector"in t&&typeof t.querySelector=="function",g=t=>typeof t=="object"&&t!==null&&"then"in t&&typeof t.then=="function";function m(t){let e=t&&typeof t=="object"&&"html"in t?t.html:t;return typeof e=="string"?e?t=>c(e,t):null:p(e)?t=>!!f(e,t):null}function y(t){return t[2]>0&&t[3]>0&&t[0]<window.innerWidth&&t[0]+t[2]>0&&t[1]<window.innerHeight&&t[1]+t[3]>0}var w=t=>t.opacity<=.001&&y(t.rect);function x(e){let s=e.media,i=[e.el.getAttribute("data-umber-src")??""];if(s?.tagName==="IMG"){let e=s;i.push(e.currentSrc,e.getAttribute("src")??"",...t(e.getAttribute("srcset")).map(t=>t[0]))}return i.filter(Boolean).map(t=>new URL(t,document.baseURI).href)}function b(t,e){let s=x(t);return x(e).some(t=>s.includes(t))}var k=t=>{t.morphHidden=!1,t.el.removeAttribute("data-umber-morphing")};function z(t,e){t.Ik&&t.Ik!==e&&k(t.Ik)}function v(t,e){let{from:s,to:i}=t,n=s._s,r=s.rect;if(!i.level&&A(t.originXf)){n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=1,n[5]=0,n[6]=r[0],n[7]=r[1],s.size[0]=r[2],s.size[1]=r[3],s.level=0;return}let o=t.originXf,h=i._s,a=o[8]||1,u=h[8]||1;for(let t=0;t<9;t++){let s=l(o,t)/a;n[t]=s+(l(h,t)/u-s)*e}s.size[0]=t.originSize[0]+(i.size[0]-t.originSize[0])*e,s.size[1]=t.originSize[1]+(i.size[1]-t.originSize[1])*e,s.level=1,s.xfReason=null;let d=s.size[0]/2,c=s.size[1]/2,f=n[2]*d+n[5]*c+n[8],p=s._x;p[0]=(n[0]*d+n[3]*c+n[6])/f-d,p[1]=(n[1]*d+n[4]*c+n[7])/f-c,p[2]=s.size[0],p[3]=s.size[1]}function A(t){return t[0]===1&&t[1]===0&&t[2]===0&&t[3]===0&&t[4]===1&&t[5]===0&&t[8]===1}function S(t){return t.sx=NaN,t}function _(t){let{from:e,to:s}=t;e.rect.set(s.rect),e.radius.set(s.radius),e._w=s._w,e._s.set(s._s),e.size.set(s.size),e.opacity=1}function j(t,e,s){let i=t.rect,n=t._x,r=t._s;i[0]+=e,i[1]+=s,n[0]+=e,n[1]+=s,r[0]+=e*r[2],r[1]+=s*r[2],r[3]+=e*r[5],r[4]+=s*r[5],r[6]+=e*r[8],r[7]+=s*r[8]}function I(t){for(let e of t.plays.za.keys()){let s=t.uniforms[e];s&&(s.value=1)}}function C(t,e,s){for(let i of t.plays.za.keys()){let n=t.uniforms[i];n&&typeof n.value=="number"&&n.value<1&&s.to(n,{value:1,duration:Math.max(.3,e),ease:"cubic.out"})}}var R=class{constructor(t){this.host=t;this.snapshots=new Map;this.flights=[];this.parked=new Set;this.later=new Map;this.Ij=0;this.jg=t=>{t.el.isConnected&&this.host.transitions.ongoing&&!t.destroyed||(this.parked.delete(t),t.destroyed||this.wk(t,!0))}}snap(t,e,s=0,i=null){let n=this.host.env.frame,r=t.scrolls?n.scrollX:n.pageX,l=t.scrolls?n.scrollY:n.pageY,h=o(4),a=o(9),u=o(2),d=o(4);return h.set(t.rect),a.set(t._s),u.set(t.size),d.set(t.radius),{plane:t,rect:h,xf:a,size:u,radius:d,ky:t._w,opacity:t.opacity,frozen:e,Ik:i,until:s,sx:r,sy:l,ex:t.doc.x-r,ey:t.doc.y-l}}get busy(){return this.flights.length>0}holds(t){for(let e of this.snapshots.values())if(e.plane===t)return!0;return!1}capture(t,e=!1){e||this.settle(),t&&typeof t.then=="function"&&(this.known(t),t=void 0);let s=m(t);e||this.xa(s),this.rj(s),t&&typeof t=="object"&&!("html"in t)&&this.preload(t),this.snapshots.size&&this.host.scheduler.markDirty()}xa(t){for(let e of this.flights.slice()){if(!t?.(e.id)){_(e),this.finish(e,e.to.drawable());continue}this.flights.splice(this.flights.indexOf(e),1),this.snapshots.set(e.id,S(this.snap(e.from,!0,0,e.to)))}}rj(t){let e=this.host.planes.all,s=e.filter(t=>t.visible).concat(e.filter(t=>!t.visible&&w(t)));for(let e of s){let s=e.el.getAttribute("data-umber-id");!s||e.kind==="layer"||this.snapshots.has(s)||e.status!=="ready"||e.morphHidden||t&&!t(s)||(this.snapshots.set(s,this.snap(e,!!t)),t&&this.host.planes.detach(e))}}known(t){if(g(t)){let e=this.Ij;t.then(t=>{e===this.Ij&&this.known(t)},()=>{});return}let e=m(t);if(e){for(let[t,s]of this.snapshots)s.frozen||s.until||(e(t)?this.host.planes.all.includes(s.plane)&&(this.snapshots.set(t,this.snap(s.plane,!0)),this.host.planes.detach(s.plane)):this.drop(t));typeof t=="object"&&t&&!("html"in t)&&this.preload(t)}}preload(t){for(let e of this.snapshots.keys()){let s=f(t,e),i=s?.matches("img")?s:s?.querySelector("img"),n=i&&!i.parentElement?.querySelector("source")&&r(i);n&&fetch(n,{mode:"cors",credentials:"omit"}).catch(()=>{})}}keep(t){let e=t.el.getAttribute("data-umber-id");return!e||this.snapshots.has(e)||t.kind==="layer"||t.status!=="ready"||t.morphHidden||this.host.env.reducedMotion||!t.visible&&!w(t)?!1:(this.wait(e,this.snap(t,!1,performance.now()+u)),!0)}wait(t,e){let s=[...this.snapshots].filter(([,t])=>t.until).sort((t,e)=>t[1].until-e[1].until),[i]=s;i&&s.length>=d&&this.drop(i[0]),this.snapshots.set(t,e),setTimeout(()=>{this.snapshots.get(t)===e&&this.drop(t)},e.until-performance.now())}drop(t){let e=this.snapshots.get(t);e&&(this.snapshots.delete(t),this.release(e),this.host.scheduler.markDirty())}forget(t){for(let[e,s]of this.snapshots)if(s.plane===t)return this.snapshots.delete(e),!0;return!1}flies(t){return this.snapshots.has(t)||this.flights.some(e=>e.id===t)}claim(t){let e=t.el.getAttribute("data-umber-id");for(let t of this.flights.slice())t.id===e&&!t.to.el.isConnected&&this.xd(t);let s=e?this.snapshots.get(e):void 0,i=this.host;if(!e||!s||t.kind==="layer"||i.env.reducedMotion)return!1;if(!i.env.kit.onScreen(t.el))return i.scheduler.changing&&s.plane.el.isConnected&&this.later.set(e,t),!1;this.later.delete(e),this.snapshots.delete(e),z(s,t);let n=s.plane,r=s.frozen?s:this.snap(n,!1);s.frozen||i.planes.detach(n);let o=this.Bh(e,r,t);return n.opacity=r.opacity,t._D=!0,t.morphHidden=!0,I(t),t.el.setAttribute("data-umber-morphing",""),C(n,o,i.env.tweens),i.scheduler.markDirty(),!0}Bh(t,e,s){let i=this.host.env,n=i.lib.config(s.el,"data-umber-morph",h),r=Math.max(0,n.duration||0);return this.flights.push({id:t,from:e.plane,to:s,origin:e.rect,originXf:e.xf,originSize:e.size,originRadius:e.radius,originKy:e.ky,originOpacity:e.opacity,start:i.now,duration:r,ease:i.kit.ease(n.ease),doneAt:0,same:b(e.plane,s)}),r}retry(){let t=[];for(let[e,s]of this.later){let i=this.snapshots.get(e);i?.plane.el.isConnected&&s.el.isConnected||(this.later.delete(e),i&&s.el.isConnected&&this.host.planes.all.includes(s)&&this.claim(s)?t.push(s):i&&this.drop(e))}return t}xd(t){this.flights.splice(this.flights.indexOf(t),1),k(t.to),this.wait(t.id,S(this.snap(t.from,!0,performance.now()+u)))}settle(t=!0){t&&(this.later.clear(),this.Ij++);for(let[e,s]of this.snapshots)!t&&(s.until||this.later.has(e))||this.drop(e);this.Pa()}Pa(){this.parked.forEach(this.jg)}update(t){if(this.snapshots.size&&this.follow(),this.parked.size&&this.Pa(),!this.flights.length)return!1;for(let e=this.flights.length;e--;){let s=this.flights[e];if(!s)continue;let i=s.to;!this.host.planes.all.includes(i)||i.status==="error"||i.textureState==="error"?this.pd(s):this.fly(s,t)}return!0}pd(t){let{from:e,to:s}=t;s.status!=="error"&&!s.el.isConnected&&(this.host.scheduler.changing||!e.el.isConnected&&this.host.transitions.ongoing)?this.xd(t):this.finish(t,!1)}fly(t,e){let{from:s,to:i}=t,n=t.duration>0?Math.min(1,(e-t.start)/(t.duration*1e3)):1,r=t.ease(n),o=i.rect;for(let e=0;e<4;e++){let n=l(t.origin,e),h=l(t.originRadius,e);s.rect[e]=n+(l(o,e)-n)*r,s.radius[e]=h+(l(i.radius,e)-h)*r}if(s._w=t.originKy+(i._w-t.originKy)*r,v(t,r),s.opacity=t.originOpacity+((this.host.transitions.ongoing?1:i.opacity)-t.originOpacity)*r,n<1)return;t.doneAt||(t.doneAt=e),(i.opacity>=.99||!this.host.transitions.ongoing)&&i.drawable()?this.finish(t,!0):e-t.doneAt>a&&this.finish(t,!1)}follow(){for(let t of this.snapshots.values())t.frozen&&t.sx===t.sx&&this.Yd(t)}Yd(t){let e=t.plane,s=this.host.env.frame,i=e.scrolls?s.scrollX:s.pageX,n=e.scrolls?s.scrollY:s.pageY;if(i===t.sx&&n===t.sy)return;let r=e.el.isConnected?e.el.getBoundingClientRect():null;if(!r?.width){t.sx=NaN;return}let o=e.pinned?r.left-t.ex:t.sx-i,l=e.pinned?r.top-t.ey:t.sy-n;t.sx=i,t.sy=n,t.ex=r.left,t.ey=r.top,!(!o&&!l)&&(j(e,o,l),t.rect.set(e.rect),t.xf.set(e._s),this.host.scheduler.markDirty())}draw(t){if(this.snapshots.size)for(let[e,s]of this.snapshots)s.frozen&&!this.host.planes.all.includes(s.plane)&&!this.drawn(s.plane,t)&&this.drop(e);let e=this.flights;for(let s=0,i=e[0];i;i=e[++s]){let{from:e,to:n}=i,r=e.texture;i.same&&n.texture?.ready&&e.kind==="image"&&(e.texture=n.texture);let o=this.drawn(e,t);e.texture=r,!o&&(this.finish(i,!1),s--)}}drawn(t,e){try{return e(t),!0}catch(e){let s=this.host;return s.env.lib.say("threw",[t.el],e),s.gpu.renderer.reset(),s.chunks.fx?.bind(),!1}}cancel(){for(let t of this.flights.slice())this.finish(t,!1);this.settle(),this.parked.forEach(t=>{this.wk(t,!0)}),this.parked.clear()}finish(t,e){if(this.flights.splice(this.flights.indexOf(t),1),e){t.to.morphHidden=!1;let e=t.to.el;this.host.env.host.loadCovers?.().then(t=>t.landed(e,this.host.canvasHost.el,this.host.env.lib.say),()=>{})}else k(t.to);this.wk(t.from,!e),this.host.scheduler.markDirty()}wk(t,e){t.el.isConnected?this.host.transitions.ongoing&&!e?this.parked.add(t):this.host.planes.attach(t):this.host.planes.discard(t)}release(t){z(t);let e=t.plane;this.host.planes.all.includes(e)||this.wk(e,!0)}};function M(t){return t.chunks.morph=new R(t)}export{M as morph};
@@ -0,0 +1,2 @@
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var t=.016666666666666666;function s(t,s){let i=1/0;for(let{fps:e}of t)i=e?Math.min(i,typeof e=="string"?100/s/parseFloat(e):1/e):0;return i===1/0?0:i}var i=.1,e=8;function h(){let t=typeof document>"u"?null:document.timeline.currentTime;return typeof t=="number"?performance.now()-t:-1}var r=[1,.85,.7,.55],n=2,a=45,l=150,o=15,d=4,u=60,f=.9,c=3;function m(t,s,i,{dt:e,busy:r=h()}){return t<0&&r>e*1e3-s?0:t<0?i?a/l:1:t>s*.6?1:0}var g=class{constructor(s){this.callbacks=s;this.scale=1;this.index=0;this.settle=30;this.te=!1;this.slowFrames=0;this.Xi=0;this.refresh=t;this.last=1/0;this.from=0;this.qj=150;this.fk=-1;this.drawnAt=-1;this.gaps=[];this.chosen=0;this.always=[];this.asked=0;this.time=0;this.count=0;this.squares=0;this.Cl=0;this.low=0;this.uj=!1;this.ef=!1;this.flipped=!1;this.before=0}frame(t,s,i,e){let h=t.frame-this.fk===1;this.fk=t.frame,this.learn(t,h);let n=h?Math.max(this.last,t.dt):1/0;this.last=t.dt,n<this.refresh&&(this.refresh=n);let o=this.refresh,d=t.dt*60;if(this.settle>0||s)return this.settle=Math.max(0,this.settle-d),!1;if(!h)return!1;if(this.before)return this.weigh(t.dt,e);let u=Math.max(this.asked,this.chosen);if(u&&i<0&&t.dt<=u*1.5)return!1;this.tally(t.dt,d,m(i,o*1e3,e,t)),this.slowFrames?this.add(t.dt):this.time=this.count=this.squares=0;let f=e?a:l;if(this.slowFrames>f&&this.index<r.length-1&&!this.te){this.qj=Math.min(this.qj*2,2400),this.flipped=this.ef;let t=this.time/this.count,s=this.spread();return this.from=this.index,this.setIndex(this.index+1),this.before=t,this.Cl=s,!0}return this.Xi>this.qj&&this.index>0?(this.ef=!0,this.setIndex(this.index-1),!0):!1}learn({time:t,dt:h},r){let n=this.callbacks?.entries().filter(t=>t.always)??[];if(this.asked=s(n,this.callbacks?.fps??60),(n.length!==this.always.length||n.some((t,s)=>t!==this.always[s]))&&(this.always=n,this.chosen=0,this.gaps.length=0),t===void 0)return;let a=this.drawnAt<0?-1:t-this.drawnAt;if(this.drawnAt=t,r){this.chosen&&h<this.chosen*.75&&(this.chosen=0),this.chosen||(this.gaps.length=0);return}if(a<=0||a>=i){this.gaps.length=0;return}let l=this.gaps;l.push(a),l.length>e&&l.shift(),l.length===e&&Math.max(...l)-Math.min(...l)<=this.refresh*1.5&&(this.chosen=l.reduce((t,s)=>t+s,0)/e)}tally(t,s,i){if(t>this.refresh*1.5){let t=Math.min(s,o);this.slowFrames+=i*t,this.Xi=Math.max(0,this.Xi-d*t)}else{let i=t<this.refresh*1.2;(i||!this.flipped)&&(this.Xi+=s),i&&(this.slowFrames=Math.max(0,this.slowFrames-s))}}weigh(t,s){if(this.add(t),this.time*60<u)return!1;let{before:i,index:e,from:h,Cl:a,low:l}=this,o=this.time/this.count,d=this.spread(),m=c*Math.sqrt(a+d);if(l){let t=i<o*f-m;return this.low=0,this.uj=t,this.te=!t,this.setIndex(t?l:e),t}if(o<i*f-m){let t=s||this.uj;return this.setIndex(t?e:h),t?!1:(this.low=e,this.before=o,this.Cl=d,!0)}let g=e-h<n&&e<r.length-1;return this.te=!g,this.setIndex(g?e+1:h),g&&(this.before=i,this.Cl=a),!0}add(t){this.time+=t,this.count++,this.squares+=t*t}spread(){let t=this.time/this.count;return Math.max(0,this.squares/this.count-t*t)/this.count}hj(){this.settle=30,this.slowFrames=0,this.Xi=0,this.time=0,this.count=0,this.squares=0}rest(t){this.settle=Math.max(this.settle,t)}reset(){this.refresh=t,this.last=1/0,this.settle=30,this.te=!1,this.before=this.low=0,this.ef=this.flipped=this.uj=!1}setIndex(t){this.index=t,this.scale=r[t]??1,this.before=0,this.hj()}};var p=t=>t;var w=class{constructor(t){this.gl=t;this.ms=-1;this.pending=[];this.active=null;this.$i=t.getExtension("EXT_disjoint_timer_query_webgl2")}get supported(){return!!this.$i}begin(){if(!this.$i||this.active||this.pending.length>3)return;let t=p(this.gl.createQuery());t&&(this.gl.beginQuery(this.$i.TIME_ELAPSED_EXT,t),this.active=t)}end(){!this.$i||!this.active||(this.gl.endQuery(this.$i.TIME_ELAPSED_EXT),this.pending.push(this.active),this.active=null)}poll(){let t=this.gl;if(!this.$i)return;let s=t.getParameter(this.$i.GPU_DISJOINT_EXT),i=this.pending[0];for(;i!==void 0&&t.getQueryParameter(i,t.QUERY_RESULT_AVAILABLE);){let e=t.getQueryParameter(i,t.QUERY_RESULT);s||(this.ms=e/1e6),t.deleteQuery(i),this.pending.shift(),i=this.pending[0]}}dispose(){this.active&&this.end(),this.pending.forEach(t=>{this.gl.deleteQuery(t)}),this.pending=[]}};export{g as AdaptiveResolution,w as GPUTimer};
@@ -1,2 +1,2 @@
1
- /*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
2
- var e=()=>{};function a({loops:e,natives:a}){let{queue:t,ours:n}=e,{raf:o,caf:r}=a;if(!(!t||!n||!o||!r)){window.requestAnimationFrame===n[0]&&(window.requestAnimationFrame=o),window.cancelAnimationFrame===n[1]&&(window.cancelAnimationFrame=r),e.queue=e.wake=e.ours=null;for(let e of t.values())o(e);delete a.raf,delete a.caf}}var t="page loops";function n(e,a){let t=a?.options;if(!a||!t?.autoRaf||typeof a.raf!="function")return null;let n=e=>{a.raf?.(e)};t.autoRaf=!1,typeof a._rafId=="number"&&window.cancelAnimationFrame(a._rafId);let o=a.scrollTo,r=e.frame.time*1e3,l=function(...a){let t=o?.apply(this,a);return e.wake(1),t};o&&(a.scrollTo=l);let i=e.add(t=>{a.time=r,r=t.time*1e3,n(r),(a.animate?.isRunning||a.isScrolling==="smooth")&&e.wake(1)},{phase:"measure",order:-3e3,label:"lenis"});return e.wake(1),()=>{i(),a.scrollTo===l&&delete a.scrollTo,t.autoRaf=!0,a.time=0,window.requestAnimationFrame(n)}}function o(o,r,l,i=window.gsap){let{loops:u,run:s}=r,{queue:f}=u;if(!f)return e;let m=new WeakMap,w=new WeakMap,p=e=>(a,t)=>{let n=w.get(a);n||(n={label:m.get(a)??(a.name||"page loop"),phase:0,order:-1500,page:!0},w.set(a,n)),e(n,t)};u.wake=()=>{o.wake(1)},window.cancelAnimationFrame(u.pump),u.pump=0;let c=o.add(()=>{let{meter:e}=o;s(o.stamp,e&&p(e))},{phase:"measure",order:-1500,label:t});f.size&&o.wake(1);let d=n(o,l);if(typeof i?.ticker.wake=="function"){let e=new Set(f.values());i.ticker.wake();for(let a of f.values())e.has(a)||m.set(a,"gsap")}return()=>{c(),d?.(),a(r)}}export{t as PAGE_LOOPS,o as drive};
1
+ /*! Umber v0.4.1 | (c) Ravi Klaassens | UNLICENSED */
2
+ var e=()=>{};function a({loops:e,natives:a}){let{queue:n,ours:o}=e,{raf:t,caf:r}=a;if(!(!n||!o||!t||!r)){window.requestAnimationFrame===o[0]&&(window.requestAnimationFrame=t),window.cancelAnimationFrame===o[1]&&(window.cancelAnimationFrame=r),e.queue=e.wake=e.ours=null;for(let e of n.values())t(e);delete a.raf,delete a.caf}}var n="page loops";function o(o,t){let{loops:r,run:l}=t,{queue:i}=r;if(!i)return e;let u=new WeakMap,m=e=>(a,n)=>{let o=u.get(a);o||(o={label:a.name||"page loop",phase:-1,order:0,page:!0},u.set(a,o)),e(o,n)};r.wake=()=>{o.wakePage()},window.cancelAnimationFrame(r.pump),r.pump=0;let p=o.add(()=>{let{meter:e}=o;l(o.stamp,e&&m(e))},{label:n},!0);return i.size&&o.wakePage(),()=>{p(),a(t)}}export{n as PAGE_LOOPS,o as drive};