micugl 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # micugl
2
+
3
+ Lightweight React shader library
@@ -0,0 +1 @@
1
+ "use strict";const v=require("react/jsx-runtime"),h=require("react"),U=require("./useUniformUpdaters-DGX0mf9g.js");class A{constructor(e){this.passes=[],this.pingPongIds=new Set,this.webglManager=e}addPass(e){this.passes.push(e),e.outputFramebuffer&&this.pingPongIds.add(e.outputFramebuffer),e.inputTextures.forEach(s=>{s.bindingType==="readwrite"&&this.pingPongIds.add(s.id)})}clearPasses(){this.passes=[],this.pingPongIds.clear()}execute(e){const s=this.webglManager.context,u=this.webglManager.fbo;for(const r of this.passes){if(r.outputFramebuffer)if(this.pingPongIds.has(r.outputFramebuffer)){const{write:t}=u.getPingPongIndices(r.outputFramebuffer);u.bindFramebuffer(r.outputFramebuffer,t)}else u.bindFramebuffer(r.outputFramebuffer);else u.bindFramebuffer(null);this.webglManager.prepareRender(r.programId,r.renderOptions),r.inputTextures.forEach(t=>{let i=t.bindingType==="read"?0:1;if(this.pingPongIds.has(t.id)){const{read:o,write:g}=u.getPingPongIndices(t.id);i=t.bindingType==="read"||t.bindingType==="readwrite"?o:g}u.bindTexture(t.id,t.textureUnit,i),this.webglManager.setUniform(r.programId,`u_${t.id}`,t.textureUnit,"sampler2D")}),this.webglManager.updateUniforms(r.programId,e),r.uniforms&&Object.entries(r.uniforms).forEach(([t,i])=>{const o=typeof i.value=="function"?i.value(e,s.canvas.width,s.canvas.height):i.value;this.webglManager.setUniform(r.programId,t,o,i.type)}),s.drawArrays(s.TRIANGLE_STRIP,0,4),r.outputFramebuffer&&this.pingPongIds.has(r.outputFramebuffer)&&u.swapTextures(r.outputFramebuffer),r.inputTextures.forEach(t=>{t.bindingType==="readwrite"&&this.pingPongIds.has(t.id)&&u.swapTextures(t.id)})}}initializeResources(){for(const e of this.passes){const s=this.webglManager.resources.get(e.programId);s&&!s.buffers.a_position&&(this.webglManager.createBuffer(e.programId,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),this.webglManager.setAttributeOnce(e.programId,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}))}}}const _="",j={},L=({programConfigs:a,passes:e,framebuffers:s,className:u=_,style:r=j,useDevicePixelRatio:t=!0})=>{const i=h.useRef(null),o=h.useRef(null),g=h.useRef(null),l=h.useRef(null),p=h.useRef(0),b=h.useRef(n=>{const f=o.current,c=g.current;if(!f||!c)return;const w=n-p.current;c.execute(w),l.current=requestAnimationFrame(b.current)}),m=h.useCallback(()=>{if(!i.current||!o.current)return;const n=window.innerWidth,f=window.innerHeight;o.current.setSize(n,f,t);const c=o.current,w=c.context.canvas;Object.entries(s??[]).forEach(([d,F])=>{const P=F.width||w.width,E=F.height||w.height;c.fbo.resizeFramebuffer(d,P,E)})},[s,t]);return h.useEffect(()=>{if(i.current)try{const n=new U.WebGLManager(i.current);o.current=n,Object.entries(a).forEach(([c,w])=>{n.createProgram(c,w)}),Object.entries(s??[]).forEach(([c,w])=>{n.fbo.createFramebuffer(c,w)});const f=new A(n);return g.current=f,e.forEach(c=>{f.addPass(c)}),f.initializeResources(),m(),p.current=performance.now(),l.current=requestAnimationFrame(b.current),window.addEventListener("resize",m),()=>{window.removeEventListener("resize",m),l.current&&cancelAnimationFrame(l.current),o.current&&o.current.destroyAll()}}catch(n){return console.error("Failed to initialize WebGL:",n),()=>{}}},[a,e,s,m]),h.useEffect(()=>{const n=g.current;n&&(n.clearPasses(),e.forEach(f=>{n.addPass(f)}),n.initializeResources())},[e]),v.jsx("canvas",{ref:i,className:u,style:{width:"100%",height:"100%",display:"block",...r}})},M=({programId:a,secondaryProgramId:e,iterations:s=1,uniforms:u,secondaryUniforms:r={},framebufferOptions:t={width:0,height:0,textureCount:2,textureOptions:{minFilter:WebGLRenderingContext.LINEAR,magFilter:WebGLRenderingContext.LINEAR}},renderOptions:i={clear:!0},customPasses:o})=>{const g=U.useUniformUpdaters(a,u),l=U.useUniformUpdaters(e??`${a}-secondary`,r);return h.useMemo(()=>{const p=`${a}-fb-a`,b=`${a}-fb-b`,m={[p]:t,[b]:t};let n=[];if(o)n=o;else{n.push({programId:a,inputTextures:[],outputFramebuffer:p,renderOptions:i});for(let d=0;d<s;d++){const F=e&&d%2===1?e:a,P=d%2===0?p:b,E=d%2===0?b:p,R=e&&d%2===1?l[e]:g[a],y={};R.forEach(T=>{const S=T.updateFn;y[T.name]={type:T.type,value:(x,I,z)=>S(x,I,z)}}),n.push({programId:F,inputTextures:[{id:P,textureUnit:0,bindingType:"read"}],outputFramebuffer:E,uniforms:y,renderOptions:i})}const f=s%2===0?b:p,c={};(e?l[e]:g[a]).forEach(d=>{const F=d.updateFn;c[d.name]={type:d.type,value:(P,E,R)=>F(P,E,R)}}),n.push({programId:e??a,inputTextures:[{id:f,textureUnit:0,bindingType:"read"}],outputFramebuffer:null,uniforms:c,renderOptions:i})}return{passes:n,framebuffers:m}},[a,e,s,g,l,t,i,o])},C={clear:!0,clearColor:[0,0,0,1]},N=({programId:a,shaderConfig:e,secondaryProgramId:s,secondaryShaderConfig:u,iterations:r=1,uniforms:t,secondaryUniforms:i,framebufferOptions:o,className:g="",style:l,customPasses:p,renderOptions:b=C})=>{const m=s??`${a}-secondary`,n={[a]:e};u&&(n[m]=u);const{passes:f,framebuffers:c}=M({programId:a,secondaryProgramId:u?m:void 0,iterations:r,uniforms:t,secondaryUniforms:i,framebufferOptions:o,renderOptions:b,customPasses:p});return v.jsx(L,{programConfigs:n,passes:f,framebuffers:c,className:g,style:l})};exports.BasePingPongShaderComponent=N;exports.Passes=A;exports.PingPongShaderEngine=L;exports.usePingPongPasses=M;
@@ -0,0 +1,273 @@
1
+ import { jsx as A } from "react/jsx-runtime";
2
+ import { useRef as F, useCallback as S, useEffect as R, useMemo as z } from "react";
3
+ import { W as _, u as v } from "./useUniformUpdaters-D5WtqZpp.mjs";
4
+ class W {
5
+ constructor(e) {
6
+ this.passes = [], this.pingPongIds = /* @__PURE__ */ new Set(), this.webglManager = e;
7
+ }
8
+ addPass(e) {
9
+ this.passes.push(e), e.outputFramebuffer && this.pingPongIds.add(e.outputFramebuffer), e.inputTextures.forEach((s) => {
10
+ s.bindingType === "readwrite" && this.pingPongIds.add(s.id);
11
+ });
12
+ }
13
+ clearPasses() {
14
+ this.passes = [], this.pingPongIds.clear();
15
+ }
16
+ execute(e) {
17
+ const s = this.webglManager.context, u = this.webglManager.fbo;
18
+ for (const r of this.passes) {
19
+ if (r.outputFramebuffer)
20
+ if (this.pingPongIds.has(r.outputFramebuffer)) {
21
+ const { write: t } = u.getPingPongIndices(r.outputFramebuffer);
22
+ u.bindFramebuffer(r.outputFramebuffer, t);
23
+ } else
24
+ u.bindFramebuffer(r.outputFramebuffer);
25
+ else
26
+ u.bindFramebuffer(null);
27
+ this.webglManager.prepareRender(r.programId, r.renderOptions), r.inputTextures.forEach((t) => {
28
+ let i = t.bindingType === "read" ? 0 : 1;
29
+ if (this.pingPongIds.has(t.id)) {
30
+ const { read: o, write: p } = u.getPingPongIndices(t.id);
31
+ i = t.bindingType === "read" || t.bindingType === "readwrite" ? o : p;
32
+ }
33
+ u.bindTexture(t.id, t.textureUnit, i), this.webglManager.setUniform(
34
+ r.programId,
35
+ `u_${t.id}`,
36
+ t.textureUnit,
37
+ "sampler2D"
38
+ );
39
+ }), this.webglManager.updateUniforms(r.programId, e), r.uniforms && Object.entries(r.uniforms).forEach(([t, i]) => {
40
+ const o = typeof i.value == "function" ? i.value(e, s.canvas.width, s.canvas.height) : i.value;
41
+ this.webglManager.setUniform(
42
+ r.programId,
43
+ t,
44
+ o,
45
+ i.type
46
+ );
47
+ }), s.drawArrays(s.TRIANGLE_STRIP, 0, 4), r.outputFramebuffer && this.pingPongIds.has(r.outputFramebuffer) && u.swapTextures(r.outputFramebuffer), r.inputTextures.forEach((t) => {
48
+ t.bindingType === "readwrite" && this.pingPongIds.has(t.id) && u.swapTextures(t.id);
49
+ });
50
+ }
51
+ }
52
+ initializeResources() {
53
+ for (const e of this.passes) {
54
+ const s = this.webglManager.resources.get(e.programId);
55
+ s && !s.buffers.a_position && (this.webglManager.createBuffer(
56
+ e.programId,
57
+ "a_position",
58
+ new Float32Array([
59
+ -1,
60
+ -1,
61
+ 1,
62
+ -1,
63
+ -1,
64
+ 1,
65
+ 1,
66
+ 1
67
+ ])
68
+ ), this.webglManager.setAttributeOnce(e.programId, "a_position", {
69
+ name: "a_position",
70
+ size: 2,
71
+ type: "FLOAT",
72
+ normalized: !1,
73
+ stride: 0,
74
+ offset: 0
75
+ }));
76
+ }
77
+ }
78
+ }
79
+ const C = "", N = {}, j = ({
80
+ programConfigs: a,
81
+ passes: e,
82
+ framebuffers: s,
83
+ className: u = C,
84
+ style: r = N,
85
+ useDevicePixelRatio: t = !0
86
+ }) => {
87
+ const i = F(null), o = F(null), p = F(null), l = F(null), g = F(0), h = F((n) => {
88
+ const f = o.current, c = p.current;
89
+ if (!f || !c) return;
90
+ const m = n - g.current;
91
+ c.execute(m), l.current = requestAnimationFrame(h.current);
92
+ }), b = S(() => {
93
+ if (!i.current || !o.current) return;
94
+ const n = window.innerWidth, f = window.innerHeight;
95
+ o.current.setSize(n, f, t);
96
+ const c = o.current, m = c.context.canvas;
97
+ Object.entries(s ?? []).forEach(([d, w]) => {
98
+ const T = w.width || m.width, E = w.height || m.height;
99
+ c.fbo.resizeFramebuffer(d, T, E);
100
+ });
101
+ }, [s, t]);
102
+ return R(() => {
103
+ if (i.current)
104
+ try {
105
+ const n = new _(i.current);
106
+ o.current = n, Object.entries(a).forEach(([c, m]) => {
107
+ n.createProgram(c, m);
108
+ }), Object.entries(s ?? []).forEach(([c, m]) => {
109
+ n.fbo.createFramebuffer(c, m);
110
+ });
111
+ const f = new W(n);
112
+ return p.current = f, e.forEach((c) => {
113
+ f.addPass(c);
114
+ }), f.initializeResources(), b(), g.current = performance.now(), l.current = requestAnimationFrame(h.current), window.addEventListener("resize", b), () => {
115
+ window.removeEventListener("resize", b), l.current && cancelAnimationFrame(l.current), o.current && o.current.destroyAll();
116
+ };
117
+ } catch (n) {
118
+ return console.error("Failed to initialize WebGL:", n), () => {
119
+ };
120
+ }
121
+ }, [a, e, s, b]), R(() => {
122
+ const n = p.current;
123
+ n && (n.clearPasses(), e.forEach((f) => {
124
+ n.addPass(f);
125
+ }), n.initializeResources());
126
+ }, [e]), /* @__PURE__ */ A(
127
+ "canvas",
128
+ {
129
+ ref: i,
130
+ className: u,
131
+ style: {
132
+ width: "100%",
133
+ height: "100%",
134
+ display: "block",
135
+ ...r
136
+ }
137
+ }
138
+ );
139
+ }, G = ({
140
+ programId: a,
141
+ secondaryProgramId: e,
142
+ iterations: s = 1,
143
+ uniforms: u,
144
+ secondaryUniforms: r = {},
145
+ framebufferOptions: t = {
146
+ width: 0,
147
+ height: 0,
148
+ textureCount: 2,
149
+ textureOptions: {
150
+ minFilter: WebGLRenderingContext.LINEAR,
151
+ magFilter: WebGLRenderingContext.LINEAR
152
+ }
153
+ },
154
+ renderOptions: i = { clear: !0 },
155
+ customPasses: o
156
+ }) => {
157
+ const p = v(a, u), l = v(
158
+ e ?? `${a}-secondary`,
159
+ r
160
+ );
161
+ return z(() => {
162
+ const g = `${a}-fb-a`, h = `${a}-fb-b`, b = {
163
+ [g]: t,
164
+ [h]: t
165
+ };
166
+ let n = [];
167
+ if (o)
168
+ n = o;
169
+ else {
170
+ n.push({
171
+ programId: a,
172
+ inputTextures: [],
173
+ outputFramebuffer: g,
174
+ renderOptions: i
175
+ });
176
+ for (let d = 0; d < s; d++) {
177
+ const w = e && d % 2 === 1 ? e : a, T = d % 2 === 0 ? g : h, E = d % 2 === 0 ? h : g, P = e && d % 2 === 1 ? l[e] : p[a], U = {};
178
+ P.forEach((y) => {
179
+ const L = y.updateFn;
180
+ U[y.name] = {
181
+ type: y.type,
182
+ value: (M, I, x) => L(M, I, x)
183
+ };
184
+ }), n.push({
185
+ programId: w,
186
+ inputTextures: [{
187
+ id: T,
188
+ textureUnit: 0,
189
+ bindingType: "read"
190
+ }],
191
+ outputFramebuffer: E,
192
+ uniforms: U,
193
+ renderOptions: i
194
+ });
195
+ }
196
+ const f = s % 2 === 0 ? h : g, c = {};
197
+ (e ? l[e] : p[a]).forEach((d) => {
198
+ const w = d.updateFn;
199
+ c[d.name] = {
200
+ type: d.type,
201
+ value: (T, E, P) => w(T, E, P)
202
+ };
203
+ }), n.push({
204
+ programId: e ?? a,
205
+ inputTextures: [{
206
+ id: f,
207
+ textureUnit: 0,
208
+ bindingType: "read"
209
+ }],
210
+ outputFramebuffer: null,
211
+ uniforms: c,
212
+ renderOptions: i
213
+ });
214
+ }
215
+ return { passes: n, framebuffers: b };
216
+ }, [
217
+ a,
218
+ e,
219
+ s,
220
+ p,
221
+ l,
222
+ t,
223
+ i,
224
+ o
225
+ ]);
226
+ }, O = {
227
+ clear: !0,
228
+ clearColor: [0, 0, 0, 1]
229
+ }, k = ({
230
+ programId: a,
231
+ shaderConfig: e,
232
+ secondaryProgramId: s,
233
+ secondaryShaderConfig: u,
234
+ iterations: r = 1,
235
+ uniforms: t,
236
+ secondaryUniforms: i,
237
+ framebufferOptions: o,
238
+ className: p = "",
239
+ style: l,
240
+ customPasses: g,
241
+ renderOptions: h = O
242
+ }) => {
243
+ const b = s ?? `${a}-secondary`, n = {
244
+ [a]: e
245
+ };
246
+ u && (n[b] = u);
247
+ const { passes: f, framebuffers: c } = G({
248
+ programId: a,
249
+ secondaryProgramId: u ? b : void 0,
250
+ iterations: r,
251
+ uniforms: t,
252
+ secondaryUniforms: i,
253
+ framebufferOptions: o,
254
+ renderOptions: h,
255
+ customPasses: g
256
+ });
257
+ return /* @__PURE__ */ A(
258
+ j,
259
+ {
260
+ programConfigs: n,
261
+ passes: f,
262
+ framebuffers: c,
263
+ className: p,
264
+ style: l
265
+ }
266
+ );
267
+ };
268
+ export {
269
+ k as B,
270
+ W as P,
271
+ j as a,
272
+ G as u
273
+ };
@@ -0,0 +1 @@
1
+ "use strict";const n=require("react"),S=require("react/jsx-runtime"),h=require("./useUniformUpdaters-DGX0mf9g.js"),F={},U="",D={},I={},b=({programConfigs:i,renderCallback:l,renderOptions:s=F,className:d=U,style:f=D,uniformUpdaters:R=I,useFastPath:g=!1,useDevicePixelRatio:A=!0})=>{const E=n.useRef(null),a=n.useRef(null),T=n.useRef(null),u=n.useRef(null),L=n.useRef(0),p=n.useRef(t=>{const e=a.current,r=T.current;if(!e||!r)return;const m=t-L.current,c=e.context;if(g)e.fastRender(r,m,s.clear),c.drawArrays(c.TRIANGLE_STRIP,0,4);else{const o=e.resources.get(r);if(!o)return;e.prepareRender(r,s),_(m,o,c)}u.current=requestAnimationFrame(p.current)}),_=n.useCallback((t,e,r)=>{l(t,e,r)},[l]);n.useEffect(()=>{p.current=t=>{const e=a.current,r=T.current;if(!e||!r)return;const m=t-L.current,c=e.context;if(g)e.fastRender(r,m,s.clear),c.drawArrays(c.TRIANGLE_STRIP,0,4);else{const o=e.resources.get(r);if(!o)return;e.prepareRender(r,s),_(m,o,c)}u.current=requestAnimationFrame(p.current)}},[s,g,_]);const w=n.useCallback(()=>{if(!E.current||!a.current)return;const t=window.innerWidth,e=window.innerHeight;a.current.setSize(t,e,A)},[A]);return n.useEffect(()=>{if(E.current)try{const t=new h.WebGLManager(E.current);a.current=t,w();const e=Object.entries(i);if(e.length>0){const[r,m]=e[0];t.createProgram(r,m),t.createBuffer(r,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),T.current=r,t.setAttributeOnce(r,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0});const c=R[r];c&&c.forEach(o=>{t.registerUniformUpdater(r,o.name,o.type,o.updateFn)})}return L.current=performance.now(),u.current=requestAnimationFrame(p.current),window.addEventListener("resize",w),()=>{window.removeEventListener("resize",w),u.current&&cancelAnimationFrame(u.current),a.current&&a.current.destroyAll()}}catch(t){return console.error("Failed to initialize WebGL:",t),()=>{}}},[i,R,w]),S.jsx("canvas",{ref:E,className:d,style:f})},k=()=>{const[i,l]=n.useState(!1);return n.useEffect(()=>{const s=()=>{const f=document.documentElement.classList.contains("dark");l(f)};s();const d=new MutationObserver(f=>{f.forEach(R=>{R.attributeName==="class"&&s()})});return d.observe(document.documentElement,{attributes:!0}),()=>{d.disconnect()}},[]),i},N={clear:!0,clearColor:[0,0,0,1]},M=({programId:i,shaderConfig:l,uniforms:s,className:d="",style:f,renderOptions:R=N})=>{const g={[i]:l},A=h.useUniformUpdaters(i,s),E=(a,T,u)=>{u.drawArrays(u.TRIANGLE_STRIP,0,4)};return S.jsx(b,{programConfigs:g,renderCallback:E,uniformUpdaters:A,className:d,style:f,useFastPath:!0,renderOptions:R})};exports.BaseShaderComponent=M;exports.ShaderEngine=b;exports.useDarkMode=k;
@@ -0,0 +1,151 @@
1
+ import { useRef as E, useCallback as b, useEffect as S, useState as h } from "react";
2
+ import { jsx as F } from "react/jsx-runtime";
3
+ import { W as I, u as D } from "./useUniformUpdaters-D5WtqZpp.mjs";
4
+ const U = {}, k = "", N = {}, v = {}, y = ({
5
+ programConfigs: i,
6
+ renderCallback: f,
7
+ renderOptions: n = U,
8
+ className: l = k,
9
+ style: u = N,
10
+ uniformUpdaters: d = v,
11
+ useFastPath: R = !1,
12
+ useDevicePixelRatio: A = !0
13
+ }) => {
14
+ const g = E(null), c = E(null), p = E(null), a = E(null), L = E(0), T = E((t) => {
15
+ const e = c.current, r = p.current;
16
+ if (!e || !r) return;
17
+ const m = t - L.current, s = e.context;
18
+ if (R)
19
+ e.fastRender(r, m, n.clear), s.drawArrays(s.TRIANGLE_STRIP, 0, 4);
20
+ else {
21
+ const o = e.resources.get(r);
22
+ if (!o) return;
23
+ e.prepareRender(r, n), _(m, o, s);
24
+ }
25
+ a.current = requestAnimationFrame(T.current);
26
+ }), _ = b((t, e, r) => {
27
+ f(t, e, r);
28
+ }, [f]);
29
+ S(() => {
30
+ T.current = (t) => {
31
+ const e = c.current, r = p.current;
32
+ if (!e || !r) return;
33
+ const m = t - L.current, s = e.context;
34
+ if (R)
35
+ e.fastRender(r, m, n.clear), s.drawArrays(s.TRIANGLE_STRIP, 0, 4);
36
+ else {
37
+ const o = e.resources.get(r);
38
+ if (!o) return;
39
+ e.prepareRender(r, n), _(m, o, s);
40
+ }
41
+ a.current = requestAnimationFrame(T.current);
42
+ };
43
+ }, [n, R, _]);
44
+ const w = b(() => {
45
+ if (!g.current || !c.current) return;
46
+ const t = window.innerWidth, e = window.innerHeight;
47
+ c.current.setSize(t, e, A);
48
+ }, [A]);
49
+ return S(() => {
50
+ if (g.current)
51
+ try {
52
+ const t = new I(g.current);
53
+ c.current = t, w();
54
+ const e = Object.entries(i);
55
+ if (e.length > 0) {
56
+ const [r, m] = e[0];
57
+ t.createProgram(r, m), t.createBuffer(
58
+ r,
59
+ "a_position",
60
+ new Float32Array([
61
+ -1,
62
+ -1,
63
+ 1,
64
+ -1,
65
+ -1,
66
+ 1,
67
+ 1,
68
+ 1
69
+ ])
70
+ ), p.current = r, t.setAttributeOnce(r, "a_position", {
71
+ name: "a_position",
72
+ size: 2,
73
+ type: "FLOAT",
74
+ normalized: !1,
75
+ stride: 0,
76
+ offset: 0
77
+ });
78
+ const s = d[r];
79
+ s && s.forEach((o) => {
80
+ t.registerUniformUpdater(
81
+ r,
82
+ o.name,
83
+ o.type,
84
+ o.updateFn
85
+ );
86
+ });
87
+ }
88
+ return L.current = performance.now(), a.current = requestAnimationFrame(T.current), window.addEventListener("resize", w), () => {
89
+ window.removeEventListener("resize", w), a.current && cancelAnimationFrame(a.current), c.current && c.current.destroyAll();
90
+ };
91
+ } catch (t) {
92
+ return console.error("Failed to initialize WebGL:", t), () => {
93
+ };
94
+ }
95
+ }, [i, d, w]), /* @__PURE__ */ F(
96
+ "canvas",
97
+ {
98
+ ref: g,
99
+ className: l,
100
+ style: u
101
+ }
102
+ );
103
+ }, G = () => {
104
+ const [i, f] = h(!1);
105
+ return S(() => {
106
+ const n = () => {
107
+ const u = document.documentElement.classList.contains("dark");
108
+ f(u);
109
+ };
110
+ n();
111
+ const l = new MutationObserver((u) => {
112
+ u.forEach((d) => {
113
+ d.attributeName === "class" && n();
114
+ });
115
+ });
116
+ return l.observe(document.documentElement, { attributes: !0 }), () => {
117
+ l.disconnect();
118
+ };
119
+ }, []), i;
120
+ }, M = {
121
+ clear: !0,
122
+ clearColor: [0, 0, 0, 1]
123
+ }, O = ({
124
+ programId: i,
125
+ shaderConfig: f,
126
+ uniforms: n,
127
+ className: l = "",
128
+ style: u,
129
+ renderOptions: d = M
130
+ }) => {
131
+ const R = { [i]: f }, A = D(i, n);
132
+ return /* @__PURE__ */ F(
133
+ y,
134
+ {
135
+ programConfigs: R,
136
+ renderCallback: (c, p, a) => {
137
+ a.drawArrays(a.TRIANGLE_STRIP, 0, 4);
138
+ },
139
+ uniformUpdaters: A,
140
+ className: l,
141
+ style: u,
142
+ useFastPath: !0,
143
+ renderOptions: d
144
+ }
145
+ );
146
+ };
147
+ export {
148
+ O as B,
149
+ y as S,
150
+ G as u
151
+ };
@@ -0,0 +1,129 @@
1
+ "use strict";const C=require("react/jsx-runtime"),y=require("./useUniformUpdaters-DGX0mf9g.js"),a=require("./BaseShaderComponent-BSBIvn4B.js"),o=`
2
+ attribute vec2 a_position;
3
+ varying vec2 v_texCoord;
4
+
5
+ void main() {
6
+ gl_Position = vec4(a_position, 0.0, 1.0);
7
+ v_texCoord = a_position * 0.5 + 0.5;
8
+ }
9
+ `,i=`
10
+ precision highp float;
11
+
12
+ uniform vec2 u_resolution;
13
+ uniform float u_time;
14
+ uniform float u_marbleScale;
15
+ uniform float u_turbulence;
16
+ uniform float u_swirl;
17
+ uniform vec3 u_colorStart;
18
+ uniform vec3 u_colorEnd;
19
+ uniform vec3 u_veinColor;
20
+ uniform float u_veinFrequency;
21
+ uniform float u_veinWidth;
22
+ uniform float u_tileScale;
23
+
24
+ varying vec2 v_texCoord;
25
+
26
+ float hash(float n) {
27
+ return fract(sin(n) * 43758.5453123);
28
+ }
29
+
30
+ float hash(vec2 p) {
31
+ return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123);
32
+ }
33
+
34
+ float noise(vec2 x) {
35
+ vec2 i = floor(x);
36
+ vec2 f = fract(x);
37
+
38
+ float a = hash(i);
39
+ float b = hash(i + vec2(1.0, 0.0));
40
+ float c = hash(i + vec2(0.0, 1.0));
41
+ float d = hash(i + vec2(1.0, 1.0));
42
+
43
+ vec2 u = f * f * (3.0 - 2.0 * f);
44
+
45
+ return clamp(mix(mix(a, b, u.x), mix(c, d, u.x), u.y), 0.0, 1.0);
46
+ }
47
+
48
+ float fbm(vec2 p, int octaves) {
49
+ float value = 0.0;
50
+ float amplitude = 0.5;
51
+ float frequency = 1.0;
52
+ float maxValue = 0.0;
53
+
54
+ for (int i = 0; i < 10; i++) {
55
+ if (i >= octaves) break;
56
+ value += amplitude * noise(p * frequency);
57
+ maxValue += amplitude;
58
+ frequency *= 2.0;
59
+ amplitude *= 0.5;
60
+ }
61
+
62
+ return value / maxValue;
63
+ }
64
+
65
+ vec2 swirl(vec2 p, float strength) {
66
+ float theta = fbm(p, 3) * strength;
67
+ float c = cos(theta);
68
+ float s = sin(theta);
69
+ return vec2(
70
+ p.x * c - p.y * s,
71
+ p.x * s + p.y * c
72
+ );
73
+ }
74
+
75
+ vec2 applyTilePixelation(vec2 uv, float tileScale) {
76
+ vec2 cell = floor(uv * tileScale);
77
+ float cellHash = (1.3 * fbm(u_time * 0.00002 * vec2(pow(pow(cell.x * cell.y, 2.0), 0.5), 2.0) + cell, 1) + 0.8 * hash(cell)) * 0.5;
78
+ float hashValue = cellHash * 3.0;
79
+ float pixelSize = 1.0;
80
+
81
+ if (hashValue < 1.0) pixelSize = 32.0;
82
+ else if (hashValue < 1.3) pixelSize = 16.0;
83
+ else if (hashValue < 1.8) pixelSize = 64.0;
84
+ else if (hashValue < 1.85) pixelSize = 16.0;
85
+ else if (hashValue < 2.2) pixelSize = 64.0;
86
+ else if (hashValue < 2.3) pixelSize = 16.0;
87
+ else if (hashValue < 2.6) pixelSize = 32.0;
88
+ else pixelSize = 128.0;
89
+
90
+ return floor(uv * pixelSize) / pixelSize;
91
+ }
92
+
93
+ void main() {
94
+ vec2 uv = v_texCoord * 2.0 - 1.0;
95
+ uv = uv * u_resolution / min(u_resolution.x, u_resolution.y);
96
+
97
+ vec2 pixelatedUv = applyTilePixelation(uv, u_tileScale);
98
+
99
+ float time = u_time * 0.25;
100
+
101
+ vec2 swirlUv = swirl(pixelatedUv + vec2(time * 0.0005, time * 0.00083), max(0.0, min(10.0, u_swirl)));
102
+
103
+ float baseNoise = fbm(swirlUv * max(0.1, u_marbleScale) + vec2(time * 0.1, time * 0.13), 5);
104
+
105
+ float turbulenceAmount = max(0.0, min(1.0, u_turbulence));
106
+ float turbulence = turbulenceAmount * fbm(swirlUv * max(0.1, u_marbleScale) * 2.0 + vec2(time * -0.15), 2);
107
+ baseNoise = clamp(baseNoise + turbulence, 0.0, 1.0);
108
+
109
+ float veinFreq = max(0.1, u_veinFrequency);
110
+ float veinW = max(0.1, min(5.0, u_veinWidth));
111
+ float veins = abs(sin(baseNoise * veinFreq * 3.14159));
112
+ veins = pow(veins, veinW);
113
+ veins = clamp(veins, 0.0, 1.0);
114
+
115
+ vec3 baseColor = mix(u_colorStart, u_colorEnd, baseNoise);
116
+
117
+ vec3 marbleColor = mix(baseColor, u_veinColor, veins);
118
+
119
+ float highlight = pow(fbm(swirlUv * max(0.1, u_marbleScale) * 4.0, 2), 3.0) * 0.2;
120
+
121
+ marbleColor = floor(marbleColor * 32.0) / 32.0;
122
+ marbleColor = mix(marbleColor, u_veinColor, veins * 0.5);
123
+ marbleColor = marbleColor + 0.0425;
124
+ marbleColor = clamp(marbleColor, 0.0, 1.0);
125
+
126
+ marbleColor = mix(marbleColor, u_veinColor, 0.7);
127
+ gl_FragColor = vec4(marbleColor, 1.0);
128
+ }
129
+ `,g=[.8,.8,.9],w=[.3,.3,.6],V=[.1,.1,.3],q=[.2,.2,.3],O=[.1,.1,.2],R=[.05,.05,.1],z=({marbleScale:t=3,tileScale:r=1,turbulence:u=.5,swirl:n=6,veinFrequency:c=6,veinWidth:s=2,colorStart:v=g,colorEnd:f=w,veinColor:m=V,colorStartDark:h=q,colorEndDark:p=O,veinColorDark:_=R,className:b="",style:x})=>{const e=a.useDarkMode(),l=S=>()=>new Float32Array(S),d=y.createShaderConfig({vertexShader:o,fragmentShader:i,uniformNames:{u_marbleScale:"float",u_tileScale:"float",u_turbulence:"float",u_swirl:"float",u_colorStart:"vec3",u_colorEnd:"vec3",u_veinColor:"vec3",u_veinFrequency:"float",u_veinWidth:"float"}});return C.jsx(a.BaseShaderComponent,{programId:"marble-shader",shaderConfig:d,className:b,style:x,uniforms:{marbleScale:{value:t,type:"float"},tileScale:{value:r,type:"float"},turbulence:{value:u,type:"float"},swirl:{value:n,type:"float"},veinFrequency:{value:c,type:"float"},veinWidth:{value:s,type:"float"},colorStart:{type:"vec3",value:l(e?h:v)},colorEnd:{type:"vec3",value:l(e?p:f)},veinColor:{type:"vec3",value:l(e?_:m)}}})};exports.Marble=z;exports.marbleFragmentShader=i;exports.marbleVertexShader=o;