@instantshader/react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +74 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 InstantGradient (instantgradient.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @instantshader/react
|
|
2
|
+
|
|
3
|
+
React bindings for [instantshader](https://www.npmjs.com/package/instantshader), a
|
|
4
|
+
zero-dependency animated WebGL gradient engine. Drop a `<Flow>` or `<Beam>`
|
|
5
|
+
component into any sized wrapper to mount a live, animated gradient. Built by
|
|
6
|
+
[InstantGradient](https://instantgradient.com/shaders).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @instantshader/react
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { Flow } from "@instantshader/react";
|
|
18
|
+
|
|
19
|
+
export function Background() {
|
|
20
|
+
return (
|
|
21
|
+
<Flow
|
|
22
|
+
colors={["#4f46e5", "#ec4899", "#22d3ee"]}
|
|
23
|
+
style={{ width: "100%", height: "100%" }}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CSSProperties, ReactElement } from "react";
|
|
2
|
+
import { ParamDef, ShaderDef, ShaderDef as ShaderDef$1, beam, flow } from "instantshader";
|
|
3
|
+
|
|
4
|
+
//#region src/ShaderCanvas.d.ts
|
|
5
|
+
interface ShaderCanvasProps {
|
|
6
|
+
shader: ShaderDef$1;
|
|
7
|
+
colors: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Merged into the shader's current params (removed/omitted keys are NOT
|
|
10
|
+
* reset to their default — they keep whatever value was last applied).
|
|
11
|
+
* Setting this prop back to `undefined` does not revert to defaults
|
|
12
|
+
* either: the underlying MountHandle is only updated when `params` is
|
|
13
|
+
* truthy, so the last applied values simply stick.
|
|
14
|
+
*/
|
|
15
|
+
params?: Record<string, number>;
|
|
16
|
+
/**
|
|
17
|
+
* Setting this prop back to `undefined` does NOT revert playback to the
|
|
18
|
+
* default speed — the underlying MountHandle is only updated when `speed`
|
|
19
|
+
* is not `undefined`, so whatever speed was last applied keeps playing.
|
|
20
|
+
*/
|
|
21
|
+
speed?: number;
|
|
22
|
+
seed?: number;
|
|
23
|
+
paused?: boolean;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Mounts a live InstantShader gradient into a wrapper `<div>`. The canvas
|
|
29
|
+
* fills that div at 100%/100% (mountGradient styles it that way), so the
|
|
30
|
+
* consumer MUST give the wrapper an explicit size (via `style`, `className`,
|
|
31
|
+
* or a sized parent) — this component does not impose one beyond
|
|
32
|
+
* `position: relative`.
|
|
33
|
+
*/
|
|
34
|
+
declare function ShaderCanvas({
|
|
35
|
+
shader,
|
|
36
|
+
colors,
|
|
37
|
+
params,
|
|
38
|
+
speed,
|
|
39
|
+
seed,
|
|
40
|
+
paused,
|
|
41
|
+
className,
|
|
42
|
+
style
|
|
43
|
+
}: ShaderCanvasProps): ReactElement;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/shaders.d.ts
|
|
46
|
+
declare function Flow(props: Omit<ShaderCanvasProps, "shader">): ReactElement;
|
|
47
|
+
declare function Beam(props: Omit<ShaderCanvasProps, "shader">): ReactElement;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { Beam, Flow, type ParamDef, ShaderCanvas, type ShaderCanvasProps, type ShaderDef, beam, flow };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { beam, beam as beam$1, flow, flow as flow$1, mountGradient } from "instantshader";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/ShaderCanvas.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Mounts a live InstantShader gradient into a wrapper `<div>`. The canvas
|
|
9
|
+
* fills that div at 100%/100% (mountGradient styles it that way), so the
|
|
10
|
+
* consumer MUST give the wrapper an explicit size (via `style`, `className`,
|
|
11
|
+
* or a sized parent) — this component does not impose one beyond
|
|
12
|
+
* `position: relative`.
|
|
13
|
+
*/
|
|
14
|
+
function ShaderCanvas({ shader, colors, params, speed, seed, paused, className, style }) {
|
|
15
|
+
const containerRef = useRef(null);
|
|
16
|
+
const handleRef = useRef(null);
|
|
17
|
+
const p = useMemo(() => params, [params ? Object.entries(params).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${k}:${v}`).join(",") : ""]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const container = containerRef.current;
|
|
20
|
+
if (!container) return;
|
|
21
|
+
const handle = mountGradient(container, {
|
|
22
|
+
shader,
|
|
23
|
+
colors,
|
|
24
|
+
params: p,
|
|
25
|
+
speed,
|
|
26
|
+
seed
|
|
27
|
+
});
|
|
28
|
+
handleRef.current = handle;
|
|
29
|
+
if (paused) handle.pause();
|
|
30
|
+
return () => {
|
|
31
|
+
handle.dispose();
|
|
32
|
+
handleRef.current = null;
|
|
33
|
+
};
|
|
34
|
+
}, [shader, seed]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
handleRef.current?.setColors(colors);
|
|
37
|
+
}, [colors]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (p) handleRef.current?.setParams(p);
|
|
40
|
+
}, [p]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (speed !== void 0) handleRef.current?.setSpeed(speed);
|
|
43
|
+
}, [speed]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (paused) handleRef.current?.pause();
|
|
46
|
+
else handleRef.current?.resume();
|
|
47
|
+
}, [paused]);
|
|
48
|
+
return /* @__PURE__ */ jsx("div", {
|
|
49
|
+
ref: containerRef,
|
|
50
|
+
className,
|
|
51
|
+
style: {
|
|
52
|
+
position: "relative",
|
|
53
|
+
...style
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/shaders.tsx
|
|
60
|
+
function Flow(props) {
|
|
61
|
+
return /* @__PURE__ */ jsx(ShaderCanvas, {
|
|
62
|
+
shader: flow$1,
|
|
63
|
+
...props
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function Beam(props) {
|
|
67
|
+
return /* @__PURE__ */ jsx(ShaderCanvas, {
|
|
68
|
+
shader: beam$1,
|
|
69
|
+
...props
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { Beam, Flow, ShaderCanvas, beam, flow };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@instantshader/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for InstantShader animated WebGL gradients.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ugolbck/instantshader.git",
|
|
10
|
+
"directory": "packages/react"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://instantgradient.com/shaders",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"webgl",
|
|
32
|
+
"shader",
|
|
33
|
+
"gradient",
|
|
34
|
+
"mesh-gradient",
|
|
35
|
+
"animated-gradient",
|
|
36
|
+
"react"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"instantshader": "0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "^18 || ^19",
|
|
43
|
+
"react-dom": "^18 || ^19"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"lint:pkg": "publint && attw --pack . --profile esm-only"
|
|
49
|
+
}
|
|
50
|
+
}
|