@occluze/umber 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +78 -48
  3. package/dist/chunks/badge.js +2 -0
  4. package/dist/chunks/basis.js +2 -0
  5. package/dist/chunks/basis_transcoder.js +2 -0
  6. package/dist/chunks/basis_transcoder.wasm +0 -0
  7. package/dist/chunks/capture.js +2 -2
  8. package/dist/chunks/covers.js +2 -2
  9. package/dist/chunks/curves.js +2 -0
  10. package/dist/chunks/flip.js +2 -2
  11. package/dist/chunks/fx.js +2 -102
  12. package/dist/chunks/gl.js +2 -180
  13. package/dist/chunks/glsl.js +2 -239
  14. package/dist/chunks/inspect.js +2 -6
  15. package/dist/chunks/instances.js +2 -93
  16. package/dist/chunks/layers.js +2 -21
  17. package/dist/chunks/licence.js +2 -2
  18. package/dist/chunks/morph.js +2 -2
  19. package/dist/chunks/patch.js +2 -0
  20. package/dist/chunks/prepared.js +2 -0
  21. package/dist/chunks/profiler.js +2 -0
  22. package/dist/chunks/restore.js +2 -2
  23. package/dist/chunks/shapes.js +2 -2
  24. package/dist/chunks/sim.js +2 -22
  25. package/dist/chunks/text.js +2 -52
  26. package/dist/chunks/video.js +2 -2
  27. package/dist/chunks/views.js +2 -2
  28. package/dist/chunks/vocabulary.js +2 -0
  29. package/dist/chunks/warm.js +2 -2
  30. package/dist/frameworks/astro.mjs +2 -0
  31. package/dist/frameworks/react.mjs +2 -0
  32. package/dist/frameworks/svelte.mjs +2 -0
  33. package/dist/frameworks/vue.mjs +2 -0
  34. package/dist/modules/debug.js +2 -36
  35. package/dist/modules/debug.mjs +2 -36
  36. package/dist/modules/handoff.js +2 -2
  37. package/dist/modules/handoff.mjs +2 -2
  38. package/dist/modules/input.js +2 -2
  39. package/dist/modules/input.mjs +2 -2
  40. package/dist/modules/router-swap.js +2 -13
  41. package/dist/modules/router.js +2 -2
  42. package/dist/modules/router.mjs +2 -2
  43. package/dist/modules/scroll-more.js +2 -0
  44. package/dist/modules/scroll-touch.js +2 -0
  45. package/dist/modules/scroll.js +2 -2
  46. package/dist/modules/scroll.mjs +2 -2
  47. package/dist/modules/scrollfx.js +2 -0
  48. package/dist/modules/scrollfx.mjs +2 -0
  49. package/dist/modules/scrub.js +2 -8
  50. package/dist/modules/scrub.mjs +2 -8
  51. package/dist/modules/three.js +2 -0
  52. package/dist/modules/three.mjs +2 -0
  53. package/dist/node/assets.mjs +9 -0
  54. package/dist/node/astro.mjs +47 -0
  55. package/dist/node/cli.mjs +109 -0
  56. package/dist/node/shared-3Q24RNIF.mjs +602 -0
  57. package/dist/node/shared-4FIU6DYP.mjs +200 -0
  58. package/dist/node/vite.mjs +10 -0
  59. package/dist/umber.css +2 -2
  60. package/dist/umber.js +2 -2
  61. package/dist/umber.mjs +2 -2
  62. package/docs/AI-quick.md +116 -54
  63. package/docs/AI.md +1275 -805
  64. package/docs/npm.md +37 -26
  65. package/package.json +181 -12
  66. package/types/assets.d.ts +87 -0
  67. package/types/astro.d.ts +43 -0
  68. package/types/debug.d.ts +17 -16
  69. package/types/esm.d.ts +12 -12
  70. package/types/global.d.ts +17 -0
  71. package/types/handoff.d.ts +26 -25
  72. package/types/input.d.ts +63 -55
  73. package/types/loop.d.ts +75 -0
  74. package/types/module.d.ts +108 -0
  75. package/types/react.d.ts +15 -0
  76. package/types/router.d.ts +87 -45
  77. package/types/scroll.d.ts +96 -38
  78. package/types/scrollfx.d.ts +80 -0
  79. package/types/scrub.d.ts +33 -32
  80. package/types/svelte.d.ts +16 -0
  81. package/types/three.d.ts +226 -0
  82. package/types/umber.d.ts +633 -357
  83. package/types/vite.d.ts +33 -0
  84. package/types/vue.d.ts +14 -0
@@ -1,239 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- var S={hash:{used:/\bumberHash\s*\(/,defined:/\bfloat\s+umberHash\s*\(/,code:`float umberHash(vec2 p){
3
- p=fract(p*vec2(123.34,456.21));
4
- p+=dot(p,p+45.32);
5
- return fract(p.x*p.y);
6
- }
7
- float umberHash(vec3 p){
8
- p=fract(p*vec3(0.1031,0.1030,0.0973));
9
- p+=dot(p,p.yxz+33.33);
10
- return fract((p.x+p.y)*p.z);
11
- }`},noise2:{used:/\bnoise\s*\(/,defined:/\bfloat\s+noise\s*\(\s*(?:in\s+)?vec2\b/,needs:["hash"],code:`float noise(vec2 p){
12
- vec2 i=floor(p);
13
- vec2 f=fract(p);
14
- vec2 k=f*f*(3.0-2.0*f);
15
- return 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);
16
- }`},noise3:{used:/\bnoise\s*\(/,defined:/\bfloat\s+noise\s*\(\s*(?:in\s+)?vec3\b/,needs:["hash"],code:`float noise(vec3 p){
17
- vec3 i=floor(p);
18
- vec3 f=fract(p);
19
- vec3 k=f*f*(3.0-2.0*f);
20
- vec2 e=vec2(1.0,0.0);
21
- float a=mix(mix(umberHash(i),umberHash(i+e.xyy),k.x),mix(umberHash(i+e.yxy),umberHash(i+e.xxy),k.x),k.y);
22
- float 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);
23
- return mix(a,b,k.z);
24
- }`},fbm:{used:/\bfbm\s*\(/,defined:/\bfloat\s+fbm\s*\(\s*(?:in\s+)?vec2\b/,needs:["noise2"],code:`float fbm(vec2 p){
25
- float v=0.0;
26
- float a=0.5;
27
- for(int i=0;i<4;i++){
28
- v+=a*noise(p);
29
- p=p*2.03+17.0;
30
- a*=0.5;
31
- }
32
- return v/0.9375;
33
- }`},screenPx:{used:/\bscreenPx\s*\(/,defined:/\bvec2\s+screenPx\s*\(/,code:`#ifdef UMBER_FRAGMENT
34
- vec2 screenPx(){
35
- return uSurface.xy+vec2(gl_FragCoord.x,uCanvas.y-gl_FragCoord.y)/uCanvas*uSurface.zw;
36
- }
37
- #endif`},screenUv:{used:/\bscreenUv\s*\(/,defined:/\bvec2\s+screenUv\s*\(/,needs:["screenPx"],code:`#ifdef UMBER_FRAGMENT
38
- vec2 screenUv(){
39
- return screenPx()/uViewport;
40
- }
41
- #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){
42
- vec2 f=uv;
43
- if(uFit<1.5){
44
- vec2 ratio=uSize/max(uPrevSize,vec2(1.0));
45
- float s=uFit<0.5?max(ratio.x,ratio.y):min(ratio.x,ratio.y);
46
- vec2 scaled=uPrevSize*s;
47
- f=(uv*uSize-(uSize-scaled)*uFitPosition)/scaled;
48
- }
49
- vec4 c=texture(uPrev,f);
50
- if(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);
51
- return c;
52
- }`},rotate2d:{used:/\brotate2d\s*\(/,defined:/\bmat2\s+rotate2d\s*\(/,code:`mat2 rotate2d(float a){
53
- float c=cos(a);
54
- float s=sin(a);
55
- return mat2(c,s,-s,c);
56
- }`}};var O={info(){},warn:(e,...t)=>console.warn("[umber]",e,...t),once:(e,...t)=>console.warn("[umber]",e,...t),error:(e,...t)=>console.error("[umber]",e,...t)},y=O;function A(e){e&&(y=e)}var I=/^[ \t]*#include[ \t]+["<]?([\w-]+)[">]?[ \t]*$/gm,F=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 w({effects:e,shader:t,...s},i,c){let l=new Set,d=[],E=()=>({code:[],seen:new Set}),k=E(),p=E(),u=(o,r)=>o.replace(I,(a,n)=>{if(r.seen.has(n))return"";r.seen.add(n),l.add(n);let f=c.get(n);return f==null?d.includes(n)||d.push(n):r.code.push(`// chunk: ${n}
57
- ${u(f,r)}`),""}),x=(o,r)=>{if(!o)return o;let a={};for(let n in o)typeof o[n]=="string"&&(a[n]=r(o[n]));return a},b=e.map(({name:o,def:r})=>({name:o,def:{...r,vertex:x(r.vertex,a=>u(a,k)),fragment:x(r.fragment,a=>u(a,p))}})),B=t&&{name:t.name,def:{...t.def,head:u(t.def.head||"",p),fragment:u(t.def.fragment,p)}},C=b.map(({def:o})=>D(`${o.vertex?.head||""}
58
- ${o.fragment?.head||""}`)),g=new Map;for(let o of[...C,D(B?.def.head||"")])for(let r of o)g.set(r,(g.get(r)||0)+1);if(b.forEach((o,r)=>{let a=[...C[r]].filter(h=>g.get(h)>1);if(!a.length)return;let n=new RegExp(`(^|[^.\\w])(${a.join("|")})\\b`,"g"),f=h=>h.replace(n,`$1e${r}_$2`);o.def={...o.def,vertex:x(o.def.vertex,f),fragment:x(o.def.fragment,f)}}),d.length){for(let o of d)i.missing.push(`chunk:${o}`),y.warn(`#include "${o}": no chunk has that name, so this element shows its DOM. Define it with gl.chunk("${o}", glsl).`,i.el);return i.setStatus("error"),null}return{...s,effects:b,shader:B,chunks:{vertex:k.code.join(`
59
-
60
- `),fragment:p.code.join(`
61
-
62
- `)},included:[...l]}}function D(e){let t="",s=0;for(let c of e.replace(/\/\/.*|\/\*[\s\S]*?\*\//g,""))(c==="}"||c===")")&&s--,s||(t+=c),(c==="{"||c==="(")&&s++;t=t.replace(/\b(uniform|in|out|precision|layout)\b[^;]*;/g,"");let i=new Set;for(let c of t.matchAll(/#define\s+(\w+)|\b(\w+)\s+(\w+)\s*[(=;,[]/g)){let l=c[1]||c[3];!F.has(l)&&!F.has(c[2]||"")&&i.add(l)}return i}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)"},m={};for(let e in P){let t=`${e}In`;m[t]={code:`float ${t}(float t){
63
- t=clamp(t,0.0,1.0);
64
- return ${P[e]};
65
- }`},m[`${e}Out`]={needs:[t],code:`float ${e}Out(float t){
66
- return 1.0-${t}(1.0-t);
67
- }`},m[`${e}InOut`]={needs:[t],code:`float ${e}InOut(float t){
68
- return t<0.5?${t}(t*2.0)*0.5:1.0-${t}(2.0-t*2.0)*0.5;
69
- }`}}var R={...m,umberBezierAxis:{code:`float umberBezierAxis(float t,float p1,float p2){
70
- float c=3.0*p1;
71
- float b=3.0*(p2-p1)-c;
72
- return(((1.0-c-b)*t+b)*t+c)*t;
73
- }`},cubicBezier:{needs:["umberBezierAxis"],code:`float cubicBezier(float x,vec4 h){
74
- if(x<=0.0||x>=1.0)return clamp(x,0.0,1.0);
75
- float lo=0.0;
76
- float hi=1.0;
77
- for(int i=0;i<20;i++){
78
- float t=(lo+hi)*0.5;
79
- if(umberBezierAxis(t,h.x,h.z)<x)lo=t;
80
- else hi=t;
81
- }
82
- return umberBezierAxis((lo+hi)*0.5,h.y,h.w);
83
- }`},umberEase:{needs:["cubicBezier"],code:`float umberEase(float t){
84
- return cubicBezier(t,vec4(0.625,0.05,0.0,1.0));
85
- }`},stagger:{code:`float stagger(float progress,float index,float count,float overlap){
86
- float o=1.0-clamp(overlap,0.0,1.0);
87
- float w=1.0/(1.0+max(count-1.0,0.0)*o);
88
- return clamp((progress-index*w*o)/w,0.0,1.0);
89
- }`}};var z={umberHash3u:{code:`uvec3 umberHash3u(uvec3 v){
90
- v=v*0x9E3779B9u+v.yzx;
91
- v^=v>>16u;
92
- v=v*0x85EBCA6Bu+v.zxy;
93
- v^=v>>13u;
94
- v*=0xC2B2AE35u;
95
- v^=v>>16u;
96
- return v;
97
- }`},umberRand3:{needs:["umberHash3u"],code:`vec3 umberRand3(vec3 p){
98
- return vec3(umberHash3u(uvec3(ivec3(floor(p+0.5)))))*(1.0/4294967296.0);
99
- }`},snoise:{needs:["umberRand3"],code:`float umberCorner(vec2 i,vec2 x){
100
- float t=max(0.5-dot(x,x),0.0);
101
- float a=umberRand3(vec3(i,0.0)).x*6.28318530718;
102
- t*=t;
103
- return t*t*dot(vec2(cos(a),sin(a)),x);
104
- }
105
- float snoise(vec2 p){
106
- const float F=0.36602540378;
107
- const float G=0.2113248654;
108
- vec2 i=floor(p+(p.x+p.y)*F);
109
- vec2 x0=p-i+(i.x+i.y)*G;
110
- vec2 o=x0.x>x0.y?vec2(1.0,0.0):vec2(0.0,1.0);
111
- return 99.2*(umberCorner(i,x0)+umberCorner(i+o,x0-o+G)+umberCorner(i+1.0,x0-1.0+2.0*G));
112
- }
113
- float umberCorner(vec3 i,vec3 x){
114
- float t=max(0.5-dot(x,x),0.0);
115
- vec3 h=umberRand3(i);
116
- float z=h.x*2.0-1.0;
117
- float a=h.y*6.28318530718;
118
- float r=sqrt(1.0-z*z);
119
- t*=t;
120
- return t*t*dot(vec3(r*cos(a),r*sin(a),z),x);
121
- }
122
- float snoise(vec3 p){
123
- vec3 i=floor(p+(p.x+p.y+p.z)/3.0);
124
- vec3 x0=p-i+(i.x+i.y+i.z)/6.0;
125
- vec3 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));
126
- vec3 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)));
127
- return 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));
128
- }`},pnoise:{needs:["umberRand3"],code:`float umberSlope(vec2 i,vec2 period,float spin,vec2 x){
129
- float a=umberRand3(vec3(mod(i,period),1.0)).x*6.28318530718+spin;
130
- return dot(vec2(cos(a),sin(a)),x);
131
- }
132
- float pnoise(vec2 p,vec2 period,float spin){
133
- vec2 n=max(floor(period+0.5),1.0);
134
- vec2 i=floor(p);
135
- vec2 f=p-i;
136
- vec2 u=f*f*f*(f*(f*6.0-15.0)+10.0);
137
- float a=umberSlope(i,n,spin,f);
138
- float b=umberSlope(i+vec2(1.0,0.0),n,spin,f-vec2(1.0,0.0));
139
- float c=umberSlope(i+vec2(0.0,1.0),n,spin,f-vec2(0.0,1.0));
140
- float d=umberSlope(i+1.0,n,spin,f-1.0);
141
- return 1.41421356*mix(mix(a,b,u.x),mix(c,d,u.x),u.y);
142
- }`},cellular:{needs:["umberRand3"],code:`vec2 cellular(vec2 p){
143
- vec2 i=floor(p);
144
- vec2 f=p-i;
145
- vec2 d=vec2(8.0);
146
- for(int y= -1;y<=1;y++)
147
- for(int x= -1;x<=1;x++){
148
- vec2 c=vec2(float(x),float(y));
149
- float l=length(c+umberRand3(vec3(i+c,2.0)).xy-f);
150
- if(l<d.x)d=vec2(l,d.x);
151
- else if(l<d.y)d.y=l;
152
- }
153
- return d;
154
- }
155
- vec2 cellular(vec3 p){
156
- vec3 i=floor(p);
157
- vec3 f=p-i;
158
- vec2 d=vec2(8.0);
159
- for(int z= -1;z<=1;z++)
160
- for(int y= -1;y<=1;y++)
161
- for(int x= -1;x<=1;x++){
162
- vec3 c=vec3(float(x),float(y),float(z));
163
- float l=length(c+umberRand3(i+c)-f);
164
- if(l<d.x)d=vec2(l,d.x);
165
- else if(l<d.y)d.y=l;
166
- }
167
- return d;
168
- }`}};var L={sdCircle:{code:`float sdCircle(vec2 p,float r){
169
- return length(p)-r;
170
- }`},sdBox:{code:`float sdBox(vec2 p,vec2 b){
171
- vec2 d=abs(p)-b;
172
- return length(max(d,0.0))+min(max(d.x,d.y),0.0);
173
- }`},sdSegment:{code:`float sdSegment(vec2 p,vec2 a,vec2 b){
174
- vec2 pa=p-a;
175
- vec2 ba=b-a;
176
- return length(pa-ba*clamp(dot(pa,ba)/max(dot(ba,ba),1e-8),0.0,1.0));
177
- }`},opRound:{code:`float opRound(float d,float r){
178
- return d-r;
179
- }`},opOnion:{code:`float opOnion(float d,float w){
180
- return abs(d)-w;
181
- }`},opSmoothUnion:{code:`float opSmoothUnion(float a,float b,float k){
182
- float h=clamp(0.5+0.5*(b-a)/max(k,1e-6),0.0,1.0);
183
- return mix(b,a,h)-k*h*(1.0-h);
184
- }`},opSmoothSubtract:{code:`float opSmoothSubtract(float a,float b,float k){
185
- float h=clamp(0.5-0.5*(a+b)/max(k,1e-6),0.0,1.0);
186
- return mix(a,-b,h)+k*h*(1.0-h);
187
- }`},opSmoothIntersect:{code:`float opSmoothIntersect(float a,float b,float k){
188
- float h=clamp(0.5-0.5*(b-a)/max(k,1e-6),0.0,1.0);
189
- return mix(b,a,h)+k*h*(1.0-h);
190
- }`},aa:{code:`#ifdef UMBER_FRAGMENT
191
- float aa(float d){
192
- return clamp(0.5-d/max(length(vec2(dFdx(d),dFdy(d))),1e-6),0.0,1.0);
193
- }
194
- #endif`}};var H={blendNormal:{code:`vec3 blendNormal(vec3 base,vec3 top,float opacity){
195
- return mix(base,top,opacity);
196
- }`},blendAdd:{code:`vec3 blendAdd(vec3 base,vec3 top,float opacity){
197
- return mix(base,min(base+top,1.0),opacity);
198
- }`},blendScreen:{code:`vec3 blendScreen(vec3 base,vec3 top,float opacity){
199
- return mix(base,base+top-base*top,opacity);
200
- }`},blendMultiply:{code:`vec3 blendMultiply(vec3 base,vec3 top,float opacity){
201
- return mix(base,base*top,opacity);
202
- }`}};var G={umberBayer2:{code:`float umberBayer2(vec2 p){
203
- p=mod(floor(p),2.0);
204
- return mod(2.0*p.x+3.0*p.y,4.0);
205
- }`},bayer4:{needs:["umberBayer2"],code:`float bayer4(vec2 p){
206
- return(4.0*umberBayer2(p)+umberBayer2(p*0.5)+0.5)/16.0;
207
- }`},bayer8:{needs:["umberBayer2"],code:`float bayer8(vec2 p){
208
- return(16.0*umberBayer2(p)+4.0*umberBayer2(p*0.5)+umberBayer2(p*0.25)+0.5)/64.0;
209
- }`},blueNoise:{code:`const uint umberBlue[64]=uint[64](
210
- 0xA9D7054Au,0x772B5FE1u,0x31BDE549u,0x2DDF1F4Eu,0x7333A2FEu,0xD4FB890Bu,0x698C159Au,0xC29678F0u,
211
- 0xECC37E63u,0x1C3AB14Du,0xB041F358u,0x123FD30Au,0x145524E7u,0xBC67CE97u,0xC723A582u,0x8BAB5E85u,
212
- 0xF5B59D45u,0xEB017A29u,0x5070CC32u,0xD62F1BF9u,0x866CCA03u,0x4BADE240u,0x38DD0D90u,0x75B9E39Fu,
213
- 0xDA1A37F8u,0x6B20A15Au,0x7CB45CFFu,0x52916806u,0xBA9562A7u,0xBFD17608u,0xED199B2Eu,0xDC253CC1u,
214
- 0xE84CC50Eu,0x1146F634u,0x8D43D581u,0x7FA3D056u,0x832272EEu,0xB69364ACu,0x28A861F1u,0x4717FA74u,
215
- 0x99CF39AEu,0x5726E013u,0xC8E40236u,0x8E60B70Cu,0x54FD00DBu,0xA47DC43Du,0x4F876EC0u,0x27E93598u,
216
- 0xB888669Eu,0xD907EA71u,0xDE16FC48u,0x537BD26Au,0x102CBE3Eu,0x846530A0u,0x2AB39421u,0xC909AA44u,
217
- 0xCB79E61Du,0xEFB251F4u,0x8059CD3Bu,0xF28A18F7u,0x425D8FAFu,0x0FC6921Eu,0xD8046DA6u,0x6F5BBB9Cu
218
- );
219
- float blueNoise(vec2 p){
220
- ivec2 q=ivec2(mod(floor(p),16.0));
221
- int i=q.y*16+q.x;
222
- return(float((umberBlue[i>>2]>>(uint(i&3)*8u))&255u)+0.5)/256.0;
223
- }`},dither:{code:`vec3 dither(vec3 color,float threshold,float levels){
224
- float n=max(levels-1.0,1.0);
225
- return floor(color*n+threshold)/n;
226
- }`}};var $={srgbToLinear:{code:`vec3 srgbToLinear(vec3 c){
227
- return mix(c/12.92,pow((max(c,0.0)+0.055)/1.055,vec3(2.4)),step(0.04045,c));
228
- }`},linearToSrgb:{code:`vec3 linearToSrgb(vec3 c){
229
- return mix(c*12.92,1.055*pow(max(c,0.0),vec3(1.0/2.4))-0.055,step(0.0031308,c));
230
- }`},linearToOklab:{code:`vec3 linearToOklab(vec3 c){
231
- vec3 lms=c*mat3(0.4122214708,0.5363325363,0.0514459929,0.2119034982,0.6806995451,0.1073969566,0.0883024619,0.2817188376,0.6299787005);
232
- lms=sign(lms)*pow(abs(lms),vec3(1.0/3.0));
233
- return lms*mat3(0.2104542553,0.7936177850,-0.0040720468,1.9779984951,-2.4285922050,0.4505937099,0.0259040371,0.7827717662,-0.8086757660);
234
- }`},oklabToLinear:{code:`vec3 oklabToLinear(vec3 c){
235
- vec3 lms=c*mat3(1.0,0.3963377774,0.2158037573,1.0,-0.1055613458,-0.0638541728,1.0,-0.0894841775,-1.2914855480);
236
- return(lms*lms*lms)*mat3(4.0767416621,-3.3077115913,0.2309699292,-1.2684380046,2.6097574011,-0.3413193965,-0.0041960863,-0.7034186147,1.7076147010);
237
- }`},mixOklab:{needs:["srgbToLinear","linearToSrgb","linearToOklab","oklabToLinear"],code:`vec3 mixOklab(vec3 a,vec3 b,float t){
238
- return linearToSrgb(oklabToLinear(mix(linearToOklab(srgbToLinear(a)),linearToOklab(srgbToLinear(b)),t)));
239
- }`}};var v={...R,...z,...L,...H,...G,...$},M="(?:float|u?int|bool|void|[iu]?vec[234]|mat[234])",T={};for(let e in v)T[e]={used:new RegExp(`\\b${e}\\s*\\(`),defined:new RegExp(`\\b${M}\\s+${e}\\s*\\(`),code:v[e].code,needs:v[e].needs};var se={...S,...T},N=e=>`// ${e}() from the helper pack`;function ie(e){A(e.host.log);let t=e.registry.chunks;for(let s in v)t.has(s)||t.set(s,N(s));return w}export{v as GLSL,se as GLSL_HELPERS,ie as glsl,N as packChunk};
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,6 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- var h="[data-gl]",O=new Set(["data-gl","data-gl-effect","data-gl-shader","data-gl-layer","data-gl-instances"]),P=[...O,"style","class","hidden","media","disabled","data-gl-src","src","srcset","sizes","data-gl-occlude","data-gl-pass","data-gl-under"];var C="[data-gl-occlude]",B=h+","+C;var b={scrub:"modules/scrub.js"};function l(e){if(!e||typeof e.tagName!="string")return"<?>";let n=e.tagName.toLowerCase();if(e.id)return`<${n}#${e.id}>`;let t=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return t?`<${n}.${t}>`:`<${n}>`}function x(e,n){let t="",s=3;for(let r of n){let i=U(e.toLowerCase(),r.toLowerCase());i<s&&(t=r,s=i)}return t}function U(e,n){let t=Array.from({length:n.length+1},(s,r)=>r);for(let s=1;s<=e.length;s++){let r=t[0];t[0]=s;for(let i=1;i<=n.length;i++){let a=t[i];t[i]=Math.min(t[i]+1,t[i-1]+1,r+(e[s-1]===n[i-1]?0:1)),r=a}}return t[n.length]}var I=e=>!!e.backgroundImage&&e.backgroundImage!=="none"||!/^(transparent|rgba\(.*,\s*0\))$/.test(e.backgroundColor||"transparent"),z=["transform","translate","rotate","scale","perspective","filter","backdropFilter","clipPath","maskImage","webkitMaskImage"],D=e=>e.position!=="static"&&e.zIndex!=="auto"||/fixed|sticky/.test(e.position)||parseFloat(e.opacity)<1||z.some(n=>(e[n]||"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);function k(e,n){let t=parseInt(getComputedStyle(n).zIndex,10);if(!(t>0))return null;let s=null,r="auto",i=[];for(let a=e;a&&a!==document.body&&a!==document.documentElement;a=a.parentElement){let d=getComputedStyle(a);I(d)&&!(a===e&&e.getAttribute("data-gl")==="shader")&&i.push(a),D(d)&&(s=a,r=d.position!=="static"?d.zIndex:"auto")}return!s||r==="auto"||+r<t||!i.some(a=>s.contains(a))?null:`${l(s)} (z-index ${r}, with a background) covers Umber's canvas (z-index ${t}): GL inside it is hidden. Drop that z-index (and give it data-gl-occlude if it must still cover the GL elements before it) or move the background behind the content.`}var L="https://umber.occluze.com";var w=(e,n)=>{let t=x(e,n);return t?` (did you mean "${t}"?)`:""},_=(e,n)=>{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 t=e.slice(e.lastIndexOf(" has ")+5).split(":")[0];return`${e}, which makes Umber's fixed canvas ${t==="zoom"?"scale":"scroll or turn"} with the page, so GL is off and the DOM shows. Move the ${t} to a wrapper element inside <body>${n?"":", or move the [data-gl-host] element out of it"}.`},A={disabled:"switched off (devices: false, data-gl-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-gl-devices, or media / data-gl-media)',editor:"inside the Webflow Designer / Editor (createGL({ 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 (createGL({ respectSaveData: false }) ignores that)",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)","context-lost":"the WebGL context was lost more than 2 times",error:"an error inside a GL frame (see the [umber] error before this)",server:"not in a browser",destroyed:"gl.destroy() was called"},S=e=>A[e]||e,p={host:_,reason:S,off:e=>`GL off: ${S(e)}`,type:(e,n,t)=>`data-gl="${n}" on ${l(e)} is not a GL type${w(n,t)}; it is drawn as an image. Use one of: ${t.join(", ")}.`,effect:(e,n,t)=>`data-gl-effect="${n}" on ${l(e)}: no effect with that name${w(n,t)}. Define it first with gl.effect("${n}", {...}): Umber ships no effects ("Writing effects" in ${L}/docs.md). Known: ${t.join(", ")||"none yet"}.`,shader:(e,n,t)=>`data-gl="shader" on ${l(e)} needs data-gl-shader="name" and gl.shader("${n||"name"}", { fragment: "..." })${n?w(n,t):""}.`,glyph:()=>'glyph() is for data-gl="text" planes; on other planes it answers one line, word and character covering the whole element.',busy:e=>`createGL({ busy }): "${e}" is not a selector; ignored.`,gpu:e=>`?umber-gpu=${e} is ignored: use 0-5, m0-m5, low, mid or high.`,texture:e=>`${e}: a canvas, bitmap, video or numbers need gl.texture(source) from the input module (modules/input.js).`,own:e=>`module "${e}": plane.${e} is Umber's own. Rename the module.`,useTwice:e=>`gl.use(): a module named "${e}" is in use already; keeping the first one.`,use:()=>"gl.use(module) needs an Umber module (an object with a name), for example Scrub from @occluze/umber/scrub.",module:(e,n)=>{let t=n.charAt(0).toUpperCase()+n.slice(1);return`data-gl-${n} on ${l(e)}: no module "${n}". Load ${b[n]} next to umber.js, or gl.use(${t}) with import { ${t} } from "@occluze/umber/${n}".`},slow:e=>`A GL element took more than ${e}s to load, so its normal DOM image/text is shown instead (slow network or a very large image? Use a smaller image).`,set:(e,n,t,s)=>`plane.set("${n}") on ${l(e)}: no effect on this plane has a uniform "${n}", so no shader reads it${w(n,t)}. Effects here: ${s}. Declare it in the effect's uniforms: { ${n}: 0 }.`,play:()=>'plane.play(): this plane has no effect with a `play` uniform. Add one (gl.effect(name, { play: "uShow", ... })) or use plane.tween(name, { value: 1 }).',image:()=>"data-gl element has no image. Put an <img> inside it or set data-gl-src.",cors:(e,n)=>`${l(e)}: its image ${n} 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).`,oval:e=>`${l(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,n,t,s)=>{if(e==="link")return`shader link failed (${n}): ${t}`;let r=Number((t.match(/ERROR: \d+:(\d+)/)||[])[1]||0),i=s.split(`
3
- `).map((a,d)=>`${String(d+1).padStart(4)}${d+1===r?" >":" "} ${a}`).slice(Math.max(0,r-6),r+3).join(`
4
- `);return`${e} shader error in "${n}":
5
- ${t}
6
- ${i}`},hostless:e=>`createGL({ 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-gl elements.`,lost:()=>"WebGL context lost; the DOM shows until it is restored.",devicesThrew:()=>"createGL({ devices }) threw; GL stays off.",install:e=>`module "${e}" install failed`,handler:(e,n)=>`a ${e}"${n}" handler threw:`,undo:()=>"gl.scope(): cleaning up one of its objects failed",scopeFn:()=>"gl.scope(fn): fn threw (what it made before that is still in the scope)",scopeAsync:()=>"gl.scope(async fn): fn rejected",frame:()=>"a frame callback threw:",tracker:()=>"a tracker failed to measure its element",absent:(e,n)=>`${e}: ${typeof n=="string"?`nothing matches "${n}"`:"no element given"}.`,unplaced:e=>`${e}: the element is not in the page yet. Call it after the element is added.`,noViews:()=>"gl.attach() is not available in this build (no chunks/views.js).",version:(e,n,t)=>`modules/${e}.js ${n} with umber.js ${t}: load both from the same version.`,scroll:e=>`createGL({ scroll }) ${e?"needs a Lenis instance, an element, or { y, velocity }":"got something Umber can't read"}. Using the window scroll instead.`,devices:e=>`createGL({ devices: ${JSON.stringify(e)} }) is not "desktop", "all", false or a function; using "desktop".`,twice:()=>"createGL() was called twice; returning the existing engine. Call gl.destroy() first to start fresh.",uniformImage:()=>"uniform texture failed",script:(e,n)=>`umber.js ${e} was loaded twice (Umber ${n} is already on the page); keeping the first copy.`,added:()=>"gl.add(): this element has data-gl already; returning its plane.",attachOff:e=>`gl.attach(): off on this device (${e})`,destroy:()=>"gl.destroy(el): no element given (a selector that found nothing?), so nothing was destroyed. gl.destroy() with no argument ends the engine.",change:(e,n)=>`${e?`<html> still matches "${e}"`:"gl.transition() was not ended"} after ${n} s, so Umber ended it. ${e?"Take that flag off":"Call the end() it returns"} once the new page is in.`,renderer:()=>"gl.attach(el, { renderer, scene, camera }) needs your THREE.WebGLRenderer as `renderer`.",view:()=>"gl.view() draws on Umber's canvas, which is off on this device (createGL devices). gl.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:()=>"gl.render() was called while Umber runs its own loop (two loops?). Use createGL({ loop: false }) to drive it yourself.",render:()=>"gl.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) => gl.render(t * 1000)).",captureDpr:(e,n,t)=>`Frame-by-frame capture: GL draws at DPR ${+n.toFixed(2)}, not ${e}: this GPU draws at most ${t} px a side. Export smaller for GL as sharp as the text.`,captureWait:(e,n)=>`Frame-by-frame capture: ${l(e)} still isn't drawn after ${n} s; frames no longer wait for it. gl.inspect(el) says why.`};var T=(e,n)=>`${l(e.el)} has data-gl but is ${Math.round(e.doc.w)}\xD7${Math.round(e.doc.h)} px after ${n/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-gl off hidden elements.`,W="The [data-gl-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,n){let t=typeof e=="string"?document.querySelector(e):e;if(!t||t.nodeType!==1)return n.log.warn(`gl.inspect(): ${typeof e=="string"?`nothing matches "${e}"`:"no element given"}.`),null;let s=t.matches(h)?t:t.closest(h)||t,r;if(n.stage)r=H(n.stage,s);else{let d=n.off?[`GL is off for this visit: ${p.reason(n.off)}`]:n.loading?["the GL runtime (chunks/gl.js) is still loading"]:[s.matches(h)?"GL has not started: no frame ran yet":"not a GL element: it has no data-gl attribute"];r={el:s,kind:null,status:"none",drawn:!1,why:d}}let i=r.notes?.length?` (${r.notes.join("; ")})`:"",a=r.drawn?`drawn${i}`:`not drawn: ${r.why.join("; ")}${i}`;return console.log(`[umber] inspect ${l(s)}: ${a}`,r),r}function H(e,n){let t=e.plane(n),s=[],r=[];if(e.failed?s.push("GL stepped aside after an error (see the [umber] error above); the DOM shows for this visit"):e.lost?s.push("the WebGL context is lost; the DOM shows until the browser gives it back"):e.hostReason?s.push(`GL is off: ${p.host(e.hostReason,e.ownHost)}`):e.paused&&s.push(e.forcedPause?"forced colours (High Contrast) are on: GL is paused":"gl.pause() was called (gl.resume() draws again)"),!t)return n.matches("[data-gl]")?n.isConnected?document.body?.hasAttribute("data-gl-disable")?s.push("<body> has data-gl-disable"):s.push("no plane yet (it arrived this frame; or call gl.scan(el))"):s.push("it is not in the page"):s.push("not a GL element: it has no data-gl attribute (and is not a gl.view() element)"),{el:n,kind:null,status:"none",drawn:!1,why:s,notes:r,source:"",tier:e.tier,effects:[],uniforms:{},program:null,rect:null,inView:!1,near:!1,texture:"none",modules:[],clips:[],geometry:null};for(let o of t.missing)o.startsWith("shader:")?s.push(`its shader "${o.slice(7)}" is not defined: gl.shader("${o.slice(7)||"name"}", { fragment })`):o.startsWith("module:")?s.push(`it needs the "${o.slice(7)}" module: load ${b[o.slice(7)]||`modules/${o.slice(7)}.js`}`):o.startsWith("chunk:")?s.push(o[6]?`#include "${o.slice(6)}" names no chunk: gl.chunk("${o.slice(6)}", glsl)`:"chunks/glsl.js (#include, shared helper names) is still downloading; its DOM shows until then"):r.push(`effect "${o}" is not defined (gl.effect("${o}", {...})); it draws without it`);let i=t.rect,a=window.innerWidth||e.screen.width,d=window.innerHeight||e.screen.height,M=a!==e.viewport.width||d!==e.viewport.height?`; the canvas is ${e.viewport.width}\xD7${e.viewport.height}`:"";if(t.domReason)s.push(`its DOM shows: ${(t.domReason==="oval"?p.oval(t.geomEl):t.domReason).replace(/^<[^>]+>: /,"")}`);else if(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)");else if(!t.el.isConnected)s.push("it is not in the page");else{let o=t.measured&&(t.doc.w===0||t.doc.h===0);o&&s.push(`its box is ${Math.round(t.doc.w)}\xD7${Math.round(t.doc.h)} px (display: none, or no size yet)`),t.kind==="layer"?t._layer?.ready||s.push(e.layers?e.layers.waiting(t):"chunks/layers.js (three.js layers) is still downloading"):e.videoWaiting.has(t)?s.push("chunks/video.js (video and module frames) is still downloading; its DOM shows until then"):t.program?t.program.ready()||s.push("its shader is still compiling; its DOM shows until then"):s.push("it has no shader program (a compile error? see the console)"),t.kind!=="layer"&&t.kind!=="shader"&&!t.texture?.ready&&(t._mods.feed?s.push(`waiting for the first frame from its module (${t._mods.list.map(g=>g.name).join(", ")})`):t.textureState==="none"?o||s.push("its pixels have not started loading (it loads when it comes near the screen)"):t.textureState==="queued"?s.push("decoded, waiting for its GPU upload (one per frame)"):t.kind==="video"?s.push('its video has no frame yet (paused with preload="none", or still buffering)'):t.kind==="text"&&!e.text?s.push("chunks/text.js (GL text) is still downloading; the DOM text shows until then"):s.push(`its ${t.kind==="text"?"text is being painted":"image is loading"}`)),t.shapeWait&&s.push("chunks/shapes.js (what cuts, turns or tilts it) is still downloading; its DOM shows until then"),o||(t.opacity<=.001&&t._layer?.def.followOpacity!==!1?s.push("its opacity (or a parent's) is 0"):i[0]<a&&i[0]+i[2]>0&&i[1]<d&&i[1]+i[3]>0?t.clips?.cutBy&&e.shapes&&s.push(e.shapes.cutBy(t.clips.cutBy)):s.push(`it is off screen (at ${Math.round(i[0])}, ${Math.round(i[1])} px; the screen is ${a}\xD7${d}${M})`)),t.morphHidden&&s.push("a data-gl-id morph is drawing it right now (flying in)");let c=k(t.el,e.hostEl);c&&s.push(c)}let G=e.shapes?.report(t,r)||[];t.backHidden&&!t.domReason&&s.push("its back faces the viewer (backface-visibility: hidden), like its DOM");for(let o of t.nodes)o.tag!=="html"&&(o.filter!=="none"||o.backdropFilter!=="none")&&r.push(`${l(o.el)} has a CSS filter; GL draws the element without it`);let m=t.size,u=t.drawXf,$=[];for(let[o,c]of[[0,0],[m[0],0],[m[0],m[1]],[0,m[1]]]){let g=u[2]*o+u[5]*c+u[8];$.push([(u[0]*o+u[3]*c+u[6])/g,(u[1]*o+u[4]*c+u[7])/g])}let R={transform:t.level===2?"3d":t.level===1?"2d":"none",size:[m[0],m[1]],corners:$,live:V(e,t,performance.now())},v={},E=t.program?.state==="ok"?t.program.uniforms:null;for(let o in t.uniforms){let c=t.uniforms[o].value;v[o]={value:c instanceof e.Texture?`texture ${c.width}\xD7${c.height}`:ArrayBuffer.isView(c)?Array.from(c):c,used:E?E.has(o):null}}let f=t.media,N=t.kind==="shader"?`shader "${t.shader?.name||n.getAttribute("data-gl-shader")||""}"`:t.kind==="layer"?`layer "${t._layer?.name||""}"`:t.kind==="text"?"the element's text":t.kind==="group"?"the GL planes inside it (a group)":t._mods.feed?`module ${t._mods.list.map(o=>o.name).join(", ")}`:n.getAttribute("data-gl-src")||(f instanceof HTMLVideoElement||f instanceof HTMLImageElement?f.currentSrc||f.src:""),y=t.scrub;return{el:n,kind:t.kind,status:t.status,drawn:s.length===0&&t.status==="ready",why:s,notes:r,source:N,tier:y&&typeof y.tier=="string"?`${e.tier} \xB7 scrub ${y.tier}`:e.tier,effects:t.effects.map(o=>({name:o.name,options:{...o.options}})),uniforms:v,program:t.programKey?{key:t.programKey,ready:!!t.program?.ready()}:null,rect:{x:i[0],y:i[1],width:i[2],height:i[3]},inView:t.inView,near:t.near,texture:t.textureState,modules:t._mods.list.map(o=>o.name),clips:G,geometry:R}}function V(e,n,t){return n.animUntil>t?n.animUntil===1/0?n.animLabel:`${n.animLabel}, ${((n.animUntil-t)/1e3).toFixed(2)} s left`:n.scrollLinked?n.animLabel:n.el.hasAttribute("data-gl-live")?"data-gl-live":n.live?"a sticky or fixed parent":e.isLive(t)?"live mode (a page change, gl.live())":null}export{W as hostLeft,j as print,p as words,T as zero};
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,93 +1,2 @@
1
- /*! Umber v0.2.1 | (c) Ravi Klaassens | UNLICENSED */
2
- var I={info(){},warn:(s,...e)=>console.warn("[umber]",s,...e),once:(s,...e)=>console.warn("[umber]",s,...e),error:(s,...e)=>console.error("[umber]",s,...e)},x=I;function R(s){s&&(x=s)}function S(s){if(typeof s=="number"||typeof s=="boolean")return"float";if(Array.isArray(s)||ArrayBuffer.isView(s)){let e=s.length;return e===2?"vec2":e===3?"vec3":e===4?"vec4":e===9?"mat3":e===16?"mat4":null}return typeof s=="string"?"sampler2D":s&&typeof s=="object"?"highp sampler2D":null}var P=3,F=["float","vec2","vec3","vec4"],E="gl_Position = vec4(0.0, 0.0, 2.0, 1.0); return;";function $(s,e,n){let t=e.mode,o=t==="chars"||t==="words"||t==="lines",r=`uniform float uInstances;
3
- uniform float uUmberWhole;
4
- uniform vec4 uUmberInst;
5
- float instance;
6
- `,i=r+`flat out float vUmberInstance;
7
- `,u=r+`flat in float vUmberInstance;
8
- `,m=`instance = float(gl_InstanceID);
9
- ${t==="echo"?`instance = uInstances - 1.0 - instance;
10
- `:""}vUmberInstance = instance;
11
- `,l=`instance = vUmberInstance;
12
- `;if(t==="tiles"){let a=`tile = vec4(mod(instance, uUmberInst.x), floor(instance / uUmberInst.x), uUmberInst.xy);
13
- tileCenter = (tile.xy + 0.5) / tile.zw;
14
- `;i+=`vec4 tile;
15
- vec2 tileCenter;
16
- `,u+=`vec4 tile;
17
- vec2 tileCenter;
18
- `,m+=`${a}uv = (tile.xy + aPosition) / tile.zw;
19
- vUv = uv;
20
- `,l+=a}else if(o)i+=`layout(location = 1) in vec4 unitBox;
21
- layout(location = 2) in vec4 unitValue;
22
- flat out vec4 vUmberBox;
23
- flat out vec4 vUmberUnit;
24
- `,u+=`flat in vec4 vUmberBox;
25
- flat in vec4 vUmberUnit;
26
- vec4 unitBox;
27
- vec4 unitValue;
28
- `,m+=`vUmberBox = unitBox;
29
- vUmberUnit = unitValue;
30
- if (uUmberWhole < 0.5) {
31
- uv = unitBox.xy + aPosition * unitBox.zw;
32
- vUv = uv;
33
- }
34
- `,l+=`unitBox = vUmberBox;
35
- unitValue = vUmberUnit;
36
- `;else if(t==="echo")i+=`layout(location = 1) in vec2 echoOffset;
37
- flat out vec2 vUmberEcho;
38
- `,u+=`flat in vec2 vUmberEcho;
39
- vec2 echoOffset;
40
- `,m+=`vUmberEcho = echoOffset;
41
- if (instance > 0.5 && dot(echoOffset, echoOffset) < 0.0025) { ${E} }
42
- pos.xy += echoOffset;
43
- `,l+=`echoOffset = vUmberEcho;
44
- `;else if(t==="ink"){let a=v=>`int umberW = int(uUmberInst.y);
45
- inkPoint = texelFetch(uUmberInk, ivec2(${v} % umberW, ${v} / umberW), 0);
46
- `,h=`uniform highp sampler2D uUmberInk;
47
- vec4 inkPoint;
48
- `;i+=h,u+=h,m+=`${a("gl_InstanceID")}if (uUmberWhole < 0.5) {
49
- if (inkPoint.w < 0.5) { ${E} }
50
- uv = inkPoint.xy + (aPosition - 0.5) * uUmberInst.x / uSize;
51
- vUv = uv;
52
- }
53
- `,l+=a("int(instance + 0.5)")}for(let a of n)i+=`layout(location = ${a.loc}) in ${F[a.size-1]} ${a.name};
54
- `;let c=s.effects.map(({def:a})=>`${a.vertex?.head||""}
55
- ${a.vertex?.main||""}`).join(`
56
- `),d=s.effects.map(({def:a})=>`${a.vertex?.head||""}
57
- ${a.fragment?.head||""}`).join(`
58
- `),f={...s.uniforms};delete f.uUmberInk;for(let a in s.uniforms){let h=S(s.uniforms[a]);!h?.includes("sampler")||!new RegExp(`\\b${a}\\b`).test(c)||new RegExp(`uniform\\s+(\\w+\\s+)?\\w+\\s+${a}\\b`).test(d)||(i+=`uniform ${h} ${a};
59
- `,u+=`uniform ${h} ${a};
60
- `,delete f[a])}let p=s.chunks||{vertex:"",fragment:""};return{...s,uniforms:f,effects:[{name:"instances",def:{vertex:{main:m},fragment:{uv:l}}},...s.effects],chunks:{vertex:`// instances
61
- ${i}
62
- ${p.vertex}`,fragment:`// instances
63
- ${u}
64
- ${p.fragment}`}}}var k=.1,b=256,C=.05,M=["lines","words","chars"],B=`
65
- float umberRand(uint x) {
66
- x ^= x >> 16; x *= 0x7feb352du; x ^= x >> 15; x *= 0x846ca68bu; x ^= x >> 16;
67
- return float(x) / 4294967295.0;
68
- }
69
- // The plane's object-fit (shaders.ts fitUv) with the plane's own numbers.
70
- vec2 umberFit(vec2 uv) {
71
- if (uFitMode > 1.5) return uv;
72
- vec2 r = uPlane / max(uImg, vec2(1.0));
73
- float s = uFitMode < 0.5 ? max(r.x, r.y) : min(r.x, r.y);
74
- vec2 sc = uImg * s;
75
- return (uv * uPlane - (uPlane - sc) * uFitPos) / sc;
76
- }
77
- vec4 color(vec2 uv) {
78
- vec2 id = floor(uv * uSize);
79
- float n = id.y * uSize.x + id.x;
80
- if (n >= uCount) return vec4(0.0);
81
- uint base = uint(n) * 151u + 7u;
82
- for (int k = 0; k < 48; k++) {
83
- uint s = base * 48u + uint(k) * 3u;
84
- vec2 p = vec2(umberRand(s), umberRand(s + 1u));
85
- vec2 f = umberFit(p);
86
- if (f.x < 0.0 || f.y < 0.0 || f.x > 1.0 || f.y > 1.0) continue;
87
- vec4 c = texture(uSource, f);
88
- float ink = uLuma > 0.5 ? dot(c.rgb, vec3(0.2126, 0.7152, 0.0722)) * c.a : c.a;
89
- if (ink > 0.02 + 0.96 * umberRand(s + 2u)) return vec4(p, ink, 1.0);
90
- }
91
- return vec4(0.0);
92
- }
93
- `;function N(s){let e=Math.imul(s^2654435769,2246822507);return e=Math.imul(e^e>>>13,3266489909),((e^e>>>16)>>>0)/4294967296}var w=class{constructor(e,n,t,o){this.stage=e;this.plane=n;this.spec=t;this.grid=null;this.vao=null;this.cols=[];this.attrs=[];this.ja=new Float32Array(4);this.hist=new Float64Array(b*3);this.head=0;this.ca=0;this.moving=!1;this.version=-1;this.seeds=null;this.seeded=null;this.qc=new Float64Array(4);this.fx=null;this.gl=e.gl,this.count=t.count;let r=t.mode,i=r==="chars"||r==="words"||r==="lines";this.whole=i||r==="ink",r==="tiles"&&this.ja.set([t.cols,t.rows]),i&&this.cols.push(this.column(1,4),this.column(2,4)),r==="echo"&&this.cols.push(this.column(1,2));let u=P,m=new Set;for(let{name:l,def:c}of o)for(let d in c.attributes||{}){if(m.has(d))continue;m.add(d);let f=c.attributes[d],p=typeof f=="function"?f(0,this.count):0,a=typeof f=="number"?f:Array.isArray(p)||ArrayBuffer.isView(p)?p.length:1;if(!(a>=1&&a<=4)||u>15){x.warn(`effect "${l}": attribute ${d} ${u>15?"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.`,n.el);continue}this.attrs.push({name:d,size:a,loc:u});let h=this.column(u++,a);h.name=d,h.fill=f,this.cols.push(h)}if(this.xb(),this.key=`|i:${r}${this.attrs.map(l=>`,${l.name}${l.size}`).join("")}`,r==="ink"){this.ja[0]=t.size;let l=this;n.uniforms.uUmberInk={value:{get texture(){return l.seeds?.texture||null}}},e.loadFx().then(c=>{this.fx=c,e.markDirty()})}this.api=this.handle()}column(e,n){return{loc:e,size:n,data:new Float32Array(Math.max(1,this.count)*n),buf:null,held:0,dirty:!0}}xb(){for(let e of this.cols)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 n=0;n<this.count;n++){let t=typeof e.fill=="function"?e.fill(n,this.count):null;for(let o=0;o<e.size;o++)e.data[n*e.size+o]=t==null?N(n*4+o+e.loc*65536):typeof t=="number"?t:+t[o]||0}e.dirty=!0}}handle(){let e=this,n=t=>{let o=e.cols.find(r=>r.name===t);return o||x.warn(`plane.instances: no attribute "${t}" (effects declare them: attributes: { ${t}: 2 }). It has: ${e.attrs.map(r=>r.name).join(", ")||"none"}.`,e.plane.el),o};return{get count(){return e.count},get mode(){return e.spec.mode},data(t){return n(t)?.data||null},set(t,o){let r=n(t);return r&&(r.data.set(Array.prototype.slice.call(o,0,r.data.length)),this.update(t)),this},update(t){for(let o of e.cols)o.name&&(!t||o.name===t)&&(o.dirty=!0);e.stage.markDirty()}}}build(e){return $(e,this.spec,this.attrs)}wrap(e){return this.grid!==e&&this.drop(),this.grid=e,this}update(e,n){let t=this.spec.mode;return t==="echo"?this.echo(e,n):t==="ink"?this.ink():t==="chars"||t==="words"||t==="lines"?this.units():!1}at(e){return(this.head+e)%b*3}push(e,n,t){let o=this.at(this.ca);this.ca<b?this.ca++:this.head=(this.head+1)%b,this.hist[o]=e,this.hist[o+1]=n,this.hist[o+2]=t}echo(e,n){let t=this.hist,o=n[0],r=n[1];this.ca||this.push(e,o,r);let i=this.at(this.ca-1);e-t[i]>C&&this.push(e-1/60,t[i+1],t[i+2]),i=this.at(this.ca-1);let u=this.count*this.spec.delay+k;e>t[i]&&(this.ca<2||t[i]-t[this.at(this.ca-2)]>=u/(b-4))?this.push(e,o,r):(t[i]=Math.max(t[i],e),t[i+1]=o,t[i+2]=r);let m=e-u;for(;this.ca>2&&t[this.at(1)]<m;)this.head=(this.head+1)%b,this.ca--;let l=this.cols[0],c=l.data,d=!1,f=this.ca-1;for(let a=1;a<this.count;a++){let h=e-a*this.spec.delay;for(;f>0&&t[this.at(f)]>h;)f--;let v=this.at(f),g=this.at(Math.min(f+1,this.ca-1)),U=t[g]>t[v]?Math.min(1,Math.max(0,(h-t[v])/(t[g]-t[v]))):0,y=(this.count-1-a)*2;c[y]=t[v+1]+(t[g+1]-t[v+1])*U-o,c[y+1]=t[v+2]+(t[g+2]-t[v+2])*U-r,(Math.abs(c[y])>.05||Math.abs(c[y+1])>.05)&&(d=!0)}let p=d||this.moving;return this.moving=d,p&&(l.dirty=!0),p}units(){let e=this.plane,n=e.text,t=n?.[this.spec.mode];if(!n||!t?.length)return!1;let[o,r]=this.cols,i=!1;if(n.version!==this.version||this.whole){if(this.version=n.version,this.whole=!1,this.count!==t.length){this.count=t.length;for(let f of this.cols)f.data=new Float32Array(this.count*f.size);this.xb()}let c=e.layoutW+2*e.pad||1,d=e.layoutH+2*e.pad||1;t.forEach((f,p)=>{let a=f.box;o.data.set([(a.x+e.pad)/c,(a.y+e.pad)/d,a.w/c,a.h/d],p*4)}),o.dirty=i=!0}let u=n.values,m=n.base[M.indexOf(this.spec.mode)]*4,l=r.data;for(let c=0;c<this.count*4;c++)l[c]!==u[m+c]&&(l[c]=u[m+c]||0,r.dirty=i=!0);return i}ink(){let e=this.plane,n=e.texture,t=this.fx,o=n?.ready?n.texture:null,r=e.text?e.text.version:o,i=this.qc,u=e.fit<2?Math.round(e.size[0]/(e.size[1]||1)*1e3):0,m=i[0]===u&&i[1]===e.fit&&i[2]===e.fitPosition[0]&&i[3]===e.fitPosition[1];if(!t||!o||r===this.seeded&&m||this.stage.lost)return!1;this.seeded=r,i[0]=u,i[1]=e.fit,i[2]=e.fitPosition[0],i[3]=e.fitPosition[1];let l=this.count,c=Math.min(256,Math.ceil(Math.sqrt(l)));return this.ja[1]=c,this.seeds||(this.seeds=t.make({width:c,height:Math.ceil(l/c),type:"half",quiet:!0,msaa:0,attachments:1}),this.seeds.type==="u8"&&x.once(`data-gl-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(B,{uSource:{get texture(){return e.texture?.texture||null}},uPlane:new Float32Array(e.size),uImg:new Float32Array([n.width,n.height]),uFitMode:e.fit,uFitPos:new Float32Array(e.fitPosition),uLuma:this.spec.luma?1:0,uCount:l}),this.whole=!1,!0}draw(){let e=this.gl,n=this.grid;if(!this.vao){this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,n.buffers[0]),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n.buffers[1]);for(let r of this.cols)r.buf=e.createBuffer(),r.held=0,r.dirty=!0,e.bindBuffer(e.ARRAY_BUFFER,r.buf),e.enableVertexAttribArray(r.loc),e.vertexAttribPointer(r.loc,r.size,e.FLOAT,!1,0,0),e.vertexAttribDivisor(r.loc,1)}for(let r of this.cols)r.dirty&&(r.dirty=!1,e.bindBuffer(e.ARRAY_BUFFER,r.buf),r.held!==r.data.length?e.bufferData(e.ARRAY_BUFFER,r.data,e.DYNAMIC_DRAW):e.bufferSubData(e.ARRAY_BUFFER,0,r.data),r.held=r.data.length);let t=this.plane.program,o=this.whole?1:this.count;t.set("uInstances",this.count),t.set("uUmberWhole",this.whole?1:0),t.set("uUmberInst",this.ja),e.bindVertexArray(this.vao),e.drawElementsInstanced(e.TRIANGLES,n.count,e.UNSIGNED_SHORT,0,o)}drop(){let e=this.gl;if(this.vao&&!this.stage.lost){e.deleteVertexArray(this.vao);for(let n of this.cols)e.deleteBuffer(n.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 D=["chars","words","lines"],_=s=>s!==void 0&&/^-?[\d.]+$/.test(s)?+s:NaN;function z(s){let e=s&&typeof s=="object"?Object.entries(s).map(([r,i])=>`${r} ${Array.isArray(i)?i.join("x"):i}`).join(" "):String(s),n={mode:"count",count:1,cols:8,rows:8,delay:.05,size:2,luma:!1},t=!1,o=e.toLowerCase().split(/[\s,]+/).filter(Boolean);if(!o.length)return"it is empty";for(let r=0;r<o.length;r++){let i=o[r],u=_(o[r+1]),m=/^(\d+)x(\d+)$/.exec(i);if(m)n.mode="tiles",n.cols=+m[1],n.rows=+m[2];else if(!isNaN(_(i)))n.count=_(i),t=!0;else if(D.includes(i))n.mode=i;else if(i==="luma"||i==="alpha")n.luma=i==="luma";else if(i==="tiles")n.mode="tiles";else if(i==="echo"||i==="ink"||i==="count")n.mode=i,isNaN(u)||(n.count=u,t=!0,r++);else if(i==="delay"||i==="size"){if(isNaN(u))return`"${i}" needs a number after it`;n[i]=u,r++}else if(i!=="units"&&i!=="source")return`"${i}" is not a word it knows`}return t||(n.count=n.mode==="echo"?6:n.mode==="ink"?2e3:1),n.mode==="tiles"&&(n.count=n.cols*n.rows),!(n.count>=1)||!(n.cols>=1)||!(n.rows>=1)?"its count is below 1":(n.count=Math.min(Math.round(n.count),n.mode==="echo"?64:65536),n.mode==="tiles"&&n.cols*n.rows>65536?`${n.cols} x ${n.rows} tiles is more than 65536`:(n.delay=Math.max(.001,n.delay),n.size=Math.max(.5,n.size),n))}var A=class{constructor(e){this.stage=e}part(e,n){let t=z(n),o=e.el;if(typeof t=="string"){x.warn(`data-gl-instances="${typeof n=="object"?JSON.stringify(n):n}": ${t}, so it draws once. Write a count ("64"), "tiles 24x16", "chars", "words", "lines", "echo 6" or "ink 3000".`,o);return}if((t.mode==="chars"||t.mode==="words"||t.mode==="lines")&&e.kind!=="text"){x.warn(`data-gl-instances="${t.mode}" is for data-gl="text" planes (one quad per ${t.mode.slice(0,-1)}); this one draws once.`,o);return}if(t.mode==="ink"&&e.kind==="shader"){x.warn(`data-gl-instances="ink" seeds particles from an image, video or text plane's pixels; a shader surface has none to read, so it draws once.`,o);return}let i=new w(this.stage,e,t,e.effects);e._inst=i,Object.defineProperty(e,"instances",{value:i.api,configurable:!0,enumerable:!0}),e._mods.list.push({name:"instances",binding:{update:u=>i.update(u.time,e.rect),lost:()=>i.lost(),destroy:()=>i.dispose()}})}};function K(s){return R(s.host.log),new A(s)}export{A as Instances,K as instances};
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};