micugl 0.0.10 → 0.0.12
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("react/jsx-runtime"),t=require("react"),F=require("../../../core/managers/WebGLManager.js"),b={},y="",I={},h={},U=({programConfigs:E,renderCallback:T,renderOptions:o=b,className:L=y,style:S=I,uniformUpdaters:p=h,useFastPath:R=!1,useDevicePixelRatio:w=!0})=>{const f=t.useRef(null),a=t.useRef(null),l=t.useRef(null),u=t.useRef(null),g=t.useRef(0),m=t.useRef(r=>{const e=a.current,n=l.current;if(!e||!n)return;const c=r-g.current,s=e.context;if(R)e.fastRender(n,c,o.clear),s.drawArrays(s.TRIANGLE_STRIP,0,4);else{const i=e.resources.get(n);if(!i)return;e.prepareRender(n,o),A(c,i,s)}u.current=requestAnimationFrame(m.current)}),A=t.useCallback((r,e,n)=>{T(r,e,n)},[T]);t.useEffect(()=>{m.current=r=>{const e=a.current,n=l.current;if(!e||!n)return;const c=r-g.current,s=e.context;if(R)e.fastRender(n,c,o.clear),s.drawArrays(s.TRIANGLE_STRIP,0,4);else{const i=e.resources.get(n);if(!i)return;e.prepareRender(n,o),A(c,i,s)}u.current=requestAnimationFrame(m.current)}},[o,R,A]);const d=t.useCallback(()=>{if(!f.current||!a.current)return;const r=window.innerWidth,e=window.innerHeight;a.current.setSize(r,e,w)},[w]);return t.useEffect(()=>{if(!f.current)return;const r=new F.WebGLManager(f.current);a.current=r,d();const[[e,n]]=Object.entries(E);return r.createProgram(e,n),r.createBuffer(e,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),r.setAttributeOnce(e,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}),l.current=e,g.current=performance.now(),u.current=requestAnimationFrame(m.current),window.addEventListener("resize",d),()=>{window.removeEventListener("resize",d),u.current&&cancelAnimationFrame(u.current),r.destroyAll()}},[E,d]),t.useEffect(()=>{const r=a.current,e=l.current;if(!r||!e)return;const n=p[e];n&&n.forEach(c=>{r.registerUniformUpdater(e,c.name,c.type,c.updateFn)})},[p]),_.jsx("canvas",{ref:f,className:L,style:S})};exports.ShaderEngine=U;
|
|
@@ -1,106 +1,82 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { WebGLManager as
|
|
4
|
-
const
|
|
1
|
+
import { jsx as I } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useCallback as _, useEffect as g } from "react";
|
|
3
|
+
import { WebGLManager as U } from "../../../core/managers/WebGLManager.mjs";
|
|
4
|
+
const h = {}, y = "", z = {}, N = {}, q = ({
|
|
5
5
|
programConfigs: E,
|
|
6
|
-
renderCallback:
|
|
7
|
-
renderOptions:
|
|
8
|
-
className:
|
|
9
|
-
style:
|
|
10
|
-
uniformUpdaters:
|
|
11
|
-
useFastPath:
|
|
12
|
-
useDevicePixelRatio:
|
|
6
|
+
renderCallback: T,
|
|
7
|
+
renderOptions: a = h,
|
|
8
|
+
className: F = y,
|
|
9
|
+
style: S = z,
|
|
10
|
+
uniformUpdaters: w = N,
|
|
11
|
+
useFastPath: A = !1,
|
|
12
|
+
useDevicePixelRatio: L = !0
|
|
13
13
|
}) => {
|
|
14
|
-
const f =
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
14
|
+
const f = s(null), o = s(null), m = s(null), i = s(null), R = s(0), l = s((r) => {
|
|
15
|
+
const e = o.current, n = m.current;
|
|
16
|
+
if (!e || !n) return;
|
|
17
|
+
const t = r - R.current, c = e.context;
|
|
18
|
+
if (A)
|
|
19
|
+
e.fastRender(n, t, a.clear), c.drawArrays(c.TRIANGLE_STRIP, 0, 4);
|
|
20
20
|
else {
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
|
|
21
|
+
const u = e.resources.get(n);
|
|
22
|
+
if (!u) return;
|
|
23
|
+
e.prepareRender(n, a), p(t, u, c);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
}),
|
|
27
|
-
|
|
28
|
-
}, [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
25
|
+
i.current = requestAnimationFrame(l.current);
|
|
26
|
+
}), p = _((r, e, n) => {
|
|
27
|
+
T(r, e, n);
|
|
28
|
+
}, [T]);
|
|
29
|
+
g(() => {
|
|
30
|
+
l.current = (r) => {
|
|
31
|
+
const e = o.current, n = m.current;
|
|
32
|
+
if (!e || !n) return;
|
|
33
|
+
const t = r - R.current, c = e.context;
|
|
34
|
+
if (A)
|
|
35
|
+
e.fastRender(n, t, a.clear), c.drawArrays(c.TRIANGLE_STRIP, 0, 4);
|
|
36
36
|
else {
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
|
|
37
|
+
const u = e.resources.get(n);
|
|
38
|
+
if (!u) return;
|
|
39
|
+
e.prepareRender(n, a), p(t, u, c);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
i.current = requestAnimationFrame(l.current);
|
|
42
42
|
};
|
|
43
|
-
}, [
|
|
44
|
-
const
|
|
43
|
+
}, [a, A, p]);
|
|
44
|
+
const d = _(() => {
|
|
45
45
|
if (!f.current || !o.current) return;
|
|
46
|
-
const
|
|
47
|
-
o.current.setSize(
|
|
48
|
-
}, [
|
|
49
|
-
return
|
|
50
|
-
if (f.current)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
size: 2,
|
|
73
|
-
type: "FLOAT",
|
|
74
|
-
normalized: !1,
|
|
75
|
-
stride: 0,
|
|
76
|
-
offset: 0
|
|
77
|
-
});
|
|
78
|
-
const t = T[e];
|
|
79
|
-
t && t.forEach((c) => {
|
|
80
|
-
n.registerUniformUpdater(
|
|
81
|
-
e,
|
|
82
|
-
c.name,
|
|
83
|
-
c.type,
|
|
84
|
-
c.updateFn
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return A.current = performance.now(), u.current = requestAnimationFrame(m.current), window.addEventListener("resize", l), () => {
|
|
89
|
-
window.removeEventListener("resize", l), u.current && cancelAnimationFrame(u.current), o.current && o.current.destroyAll();
|
|
90
|
-
};
|
|
91
|
-
} catch (n) {
|
|
92
|
-
return console.error("Failed to initialize WebGL:", n), () => {
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}, [E, T, l]), /* @__PURE__ */ S(
|
|
46
|
+
const r = window.innerWidth, e = window.innerHeight;
|
|
47
|
+
o.current.setSize(r, e, L);
|
|
48
|
+
}, [L]);
|
|
49
|
+
return g(() => {
|
|
50
|
+
if (!f.current) return;
|
|
51
|
+
const r = new U(f.current);
|
|
52
|
+
o.current = r, d();
|
|
53
|
+
const [[e, n]] = Object.entries(E);
|
|
54
|
+
return r.createProgram(e, n), r.createBuffer(e, "a_position", new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1])), r.setAttributeOnce(e, "a_position", {
|
|
55
|
+
name: "a_position",
|
|
56
|
+
size: 2,
|
|
57
|
+
type: "FLOAT",
|
|
58
|
+
normalized: !1,
|
|
59
|
+
stride: 0,
|
|
60
|
+
offset: 0
|
|
61
|
+
}), m.current = e, R.current = performance.now(), i.current = requestAnimationFrame(l.current), window.addEventListener("resize", d), () => {
|
|
62
|
+
window.removeEventListener("resize", d), i.current && cancelAnimationFrame(i.current), r.destroyAll();
|
|
63
|
+
};
|
|
64
|
+
}, [E, d]), g(() => {
|
|
65
|
+
const r = o.current, e = m.current;
|
|
66
|
+
if (!r || !e) return;
|
|
67
|
+
const n = w[e];
|
|
68
|
+
n && n.forEach((t) => {
|
|
69
|
+
r.registerUniformUpdater(e, t.name, t.type, t.updateFn);
|
|
70
|
+
});
|
|
71
|
+
}, [w]), /* @__PURE__ */ I(
|
|
96
72
|
"canvas",
|
|
97
73
|
{
|
|
98
74
|
ref: f,
|
|
99
|
-
className:
|
|
100
|
-
style:
|
|
75
|
+
className: F,
|
|
76
|
+
style: S
|
|
101
77
|
}
|
|
102
78
|
);
|
|
103
79
|
};
|
|
104
80
|
export {
|
|
105
|
-
|
|
81
|
+
q as ShaderEngine
|
|
106
82
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UniformParam,
|
|
1
|
+
import { UniformParam, UniformUpdaterDef } from '../../types';
|
|
2
2
|
export declare const useUniformUpdaters: (programId: string, uniforms: Record<string, UniformParam>) => {
|
|
3
|
-
[x: string]: UniformUpdaterDef<UniformType>[];
|
|
3
|
+
[x: string]: UniformUpdaterDef<import('../../types').UniformType>[];
|
|
4
4
|
};
|
|
@@ -5,4 +5,4 @@ export declare function createUniformUpdaters<T extends UniformType>(configs: {
|
|
|
5
5
|
type: T;
|
|
6
6
|
value: UniformValue<T>;
|
|
7
7
|
}[]): UniformUpdaterDef<T>[];
|
|
8
|
-
export declare function createCommonUpdaters(): UniformUpdaterDef
|
|
8
|
+
export declare function createCommonUpdaters(): UniformUpdaterDef[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "micugl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Micu gl - Small React shader library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@types/node": "^22.14.0",
|
|
42
42
|
"@types/react": "^18.0.0 || ^19.0.0",
|
|
43
43
|
"@types/react-dom": "^18.0.0 || ^19.0.0",
|
|
44
|
+
"ajv": "^8",
|
|
44
45
|
"eslint": "^9.25.0",
|
|
45
46
|
"eslint-plugin-react-dom": "^1.48.4",
|
|
46
47
|
"eslint-plugin-react-hooks": "^5.2.0",
|