@fjandin/react-shader 0.0.17 → 0.0.18

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,11 +1,18 @@
1
- import type { Vec2, Vec3, Vec4, Vec4Array } from "./types";
1
+ import type { FrameInfo, Vec2, Vec3, Vec4, Vec4Array } from "./types";
2
2
  type GpuUniformValue = number | Vec2 | Vec3 | Vec4 | Vec4Array;
3
3
  export interface ReactGpuShaderProps {
4
4
  className?: string;
5
5
  fragment: string;
6
6
  uniforms?: Record<string, GpuUniformValue>;
7
7
  fullscreen?: boolean;
8
+ timeScale?: number;
9
+ onFrame?: (info: FrameInfo) => void;
10
+ onClick?: (info: FrameInfo) => void;
11
+ onMouseMove?: (info: FrameInfo) => void;
12
+ onMouseDown?: (info: FrameInfo) => void;
13
+ onMouseUp?: (info: FrameInfo) => void;
14
+ onMouseWheel?: (info: FrameInfo, wheelDelta: number) => void;
8
15
  }
9
- export declare function ReactGpuShader({ className, fragment, uniforms, fullscreen }: ReactGpuShaderProps): import("react/jsx-runtime").JSX.Element;
16
+ export declare function ReactGpuShader({ className, fragment, uniforms, fullscreen, timeScale, onFrame, onClick, onMouseMove, onMouseDown, onMouseUp, onMouseWheel, }: ReactGpuShaderProps): import("react/jsx-runtime").JSX.Element;
10
17
  export {};
11
18
  //# sourceMappingURL=ReactGpuShader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReactGpuShader.d.ts","sourceRoot":"","sources":["../src/ReactGpuShader.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAG1D,KAAK,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AAE9D,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAuBD,wBAAgB,cAAc,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAkB,EAAE,EAAE,mBAAmB,2CAkDxG"}
1
+ {"version":3,"file":"ReactGpuShader.d.ts","sourceRoot":"","sources":["../src/ReactGpuShader.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGrE,KAAK,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AAE9D,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC1C,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACnC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACnC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACvC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACvC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACrC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;CAC7D;AAuBD,wBAAgB,cAAc,CAAC,EAC7B,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,UAAkB,EAClB,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,GACb,EAAE,mBAAmB,2CAyDrB"}
@@ -0,0 +1,2 @@
1
+ export declare function WebGpuMandelbrotDemo(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=mandelbrot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mandelbrot.d.ts","sourceRoot":"","sources":["../../../src/example/examples/mandelbrot.tsx"],"names":[],"mappings":"AA8BA,wBAAgB,oBAAoB,4CAiFnC"}
@@ -0,0 +1,2 @@
1
+ export declare function WebGpuMandelbrotDemo2(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=mandelbrot2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mandelbrot2.d.ts","sourceRoot":"","sources":["../../../src/example/examples/mandelbrot2.tsx"],"names":[],"mappings":"AA4HA,wBAAgB,qBAAqB,4CAiGpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu.d.ts","sourceRoot":"","sources":["../../../src/example/examples/webgpu.tsx"],"names":[],"mappings":"AA4CA,wBAAgB,UAAU,4CA8BzB"}
1
+ {"version":3,"file":"webgpu.d.ts","sourceRoot":"","sources":["../../../src/example/examples/webgpu.tsx"],"names":[],"mappings":"AAmDA,wBAAgB,UAAU,4CAgHzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../src/example/frontend.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,aAAa,CAAA;AAwBpB,wBAAgB,GAAG,4CAyBlB"}
1
+ {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../src/example/frontend.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,aAAa,CAAA;AA0BpB,wBAAgB,GAAG,4CAyClB"}
@@ -1,9 +1,16 @@
1
- import type { Vec2, Vec3, Vec4, Vec4Array } from "../types";
1
+ import type { FrameInfo, Vec2, Vec3, Vec4, Vec4Array } from "../types";
2
2
  type GpuUniformValue = number | Vec2 | Vec3 | Vec4 | Vec4Array;
3
3
  interface UseWebGPUOptions {
4
4
  fragment: string;
5
5
  uniforms?: Record<string, GpuUniformValue>;
6
6
  onError?: (error: Error) => void;
7
+ timeScale?: number;
8
+ onFrame?: (info: FrameInfo) => void;
9
+ onClick?: (info: FrameInfo) => void;
10
+ onMouseMove?: (info: FrameInfo) => void;
11
+ onMouseDown?: (info: FrameInfo) => void;
12
+ onMouseUp?: (info: FrameInfo) => void;
13
+ onMouseWheel?: (info: FrameInfo, wheelDelta: number) => void;
7
14
  }
8
15
  export declare function useWebGPU(options: UseWebGPUOptions): {
9
16
  canvasRef: import("react").RefObject<HTMLCanvasElement>;
@@ -1 +1 @@
1
- {"version":3,"file":"useWebGPU.d.ts","sourceRoot":"","sources":["../../src/hooks/useWebGPU.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAG3D,KAAK,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AAE9D,UAAU,gBAAgB;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC;AA+WD,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB;;;EA0NlD"}
1
+ {"version":3,"file":"useWebGPU.d.ts","sourceRoot":"","sources":["../../src/hooks/useWebGPU.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGtE,KAAK,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AAE9D,UAAU,gBAAgB;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACnC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACnC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACvC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACvC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACrC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;CAC7D;AA+WD,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB;;;EA8QlD"}
package/dist/index.cjs CHANGED
@@ -275,10 +275,10 @@ function inferWgslType(value) {
275
275
  }
276
276
  if (isVec4Array(value)) {
277
277
  return {
278
- wgslType: `array<vec4f, ${value.length}>`,
278
+ wgslType: `array<vec4f, 100>`,
279
279
  baseType: "vec4f",
280
280
  isArray: true,
281
- arrayLength: value.length
281
+ arrayLength: 100
282
282
  };
283
283
  }
284
284
  if (isVec4(value)) {
@@ -537,12 +537,37 @@ function useWebGPU(options) {
537
537
  const mouseLeftDownRef = import_react2.useRef(false);
538
538
  const canvasRectRef = import_react2.useRef(null);
539
539
  const onErrorRef = import_react2.useRef(options.onError);
540
+ const onFrameRef = import_react2.useRef(options.onFrame);
541
+ const onClickRef = import_react2.useRef(options.onClick);
542
+ const onMouseDownRef = import_react2.useRef(options.onMouseDown);
543
+ const onMouseUpRef = import_react2.useRef(options.onMouseUp);
544
+ const onMouseMoveRef = import_react2.useRef(options.onMouseMove);
545
+ const onMouseWheelRef = import_react2.useRef(options.onMouseWheel);
546
+ const timeScaleRef = import_react2.useRef(options.timeScale ?? 1);
540
547
  const fragmentRef = import_react2.useRef(options.fragment);
541
548
  const uniformsRef = import_react2.useRef(options.uniforms);
542
549
  const dprRef = import_react2.useRef(window.devicePixelRatio || 1);
543
550
  onErrorRef.current = options.onError;
551
+ onFrameRef.current = options.onFrame;
552
+ onClickRef.current = options.onClick;
553
+ onMouseDownRef.current = options.onMouseDown;
554
+ onMouseUpRef.current = options.onMouseUp;
555
+ onMouseMoveRef.current = options.onMouseMove;
556
+ onMouseWheelRef.current = options.onMouseWheel;
557
+ timeScaleRef.current = options.timeScale ?? 1;
544
558
  fragmentRef.current = options.fragment;
545
559
  uniformsRef.current = options.uniforms;
560
+ const buildFrameInfo = import_react2.useCallback((deltaTime) => {
561
+ const canvas = canvasRef.current;
562
+ return {
563
+ deltaTime,
564
+ time: elapsedTimeRef.current,
565
+ resolution: [canvas?.width ?? 0, canvas?.height ?? 0],
566
+ mouse: mouseRef.current,
567
+ mouseNormalized: mouseNormalizedRef.current,
568
+ mouseLeftDown: mouseLeftDownRef.current
569
+ };
570
+ }, []);
546
571
  const render = import_react2.useCallback((time) => {
547
572
  const state = stateRef.current;
548
573
  const canvas = canvasRef.current;
@@ -551,7 +576,10 @@ function useWebGPU(options) {
551
576
  }
552
577
  const deltaTime = lastFrameTimeRef.current === 0 ? 0 : (time - lastFrameTimeRef.current) / 1000;
553
578
  lastFrameTimeRef.current = time;
554
- elapsedTimeRef.current += deltaTime;
579
+ elapsedTimeRef.current += deltaTime * timeScaleRef.current;
580
+ if (onFrameRef.current) {
581
+ onFrameRef.current(buildFrameInfo(deltaTime));
582
+ }
555
583
  const { device, context, pipeline, uniformBuffer, uniformBindGroup, uniformLayout } = state;
556
584
  const dpr = dprRef.current;
557
585
  const displayWidth = canvas.clientWidth;
@@ -608,7 +636,7 @@ function useWebGPU(options) {
608
636
  renderPass.end();
609
637
  device.queue.submit([commandEncoder.finish()]);
610
638
  animationFrameRef.current = requestAnimationFrame(render);
611
- }, []);
639
+ }, [buildFrameInfo]);
612
640
  import_react2.useEffect(() => {
613
641
  const canvas = canvasRef.current;
614
642
  if (!canvas)
@@ -676,28 +704,41 @@ function useWebGPU(options) {
676
704
  (mouseRef.current[0] - canvas.width / 2) / minDimension,
677
705
  (mouseRef.current[1] - canvas.height / 2) / minDimension
678
706
  ];
707
+ onMouseMoveRef.current?.(buildFrameInfo(0));
679
708
  };
680
709
  const handleMouseDown = (event) => {
681
710
  if (event.button === 0) {
682
711
  mouseLeftDownRef.current = true;
683
712
  }
713
+ onMouseDownRef.current?.(buildFrameInfo(0));
684
714
  };
685
715
  const handleMouseUp = (event) => {
686
716
  if (event.button === 0) {
687
717
  mouseLeftDownRef.current = false;
688
718
  }
719
+ onMouseUpRef.current?.(buildFrameInfo(0));
720
+ };
721
+ const handleClick = () => {
722
+ onClickRef.current?.(buildFrameInfo(0));
723
+ };
724
+ const handleMouseWheel = (event) => {
725
+ onMouseWheelRef.current?.(buildFrameInfo(0), event.deltaY);
689
726
  };
690
727
  window.addEventListener("mousemove", handleMouseMove);
691
728
  window.addEventListener("mousedown", handleMouseDown);
692
729
  window.addEventListener("mouseup", handleMouseUp);
730
+ canvas.addEventListener("click", handleClick);
731
+ window.addEventListener("wheel", handleMouseWheel);
693
732
  return () => {
694
733
  resizeObserver.disconnect();
695
734
  window.removeEventListener("scroll", updateRect);
696
735
  window.removeEventListener("mousemove", handleMouseMove);
697
736
  window.removeEventListener("mousedown", handleMouseDown);
698
737
  window.removeEventListener("mouseup", handleMouseUp);
738
+ canvas.removeEventListener("click", handleClick);
739
+ window.removeEventListener("wheel", handleMouseWheel);
699
740
  };
700
- }, []);
741
+ }, [buildFrameInfo]);
701
742
  return { canvasRef, mouseRef };
702
743
  }
703
744
 
@@ -721,7 +762,19 @@ var CANVAS_STYLE = {
721
762
  width: "100%",
722
763
  height: "100%"
723
764
  };
724
- function ReactGpuShader({ className, fragment, uniforms, fullscreen = false }) {
765
+ function ReactGpuShader({
766
+ className,
767
+ fragment,
768
+ uniforms,
769
+ fullscreen = false,
770
+ timeScale,
771
+ onFrame,
772
+ onClick,
773
+ onMouseMove,
774
+ onMouseDown,
775
+ onMouseUp,
776
+ onMouseWheel
777
+ }) {
725
778
  const [error, setError] = import_react3.useState(null);
726
779
  const handleError = import_react3.useCallback((err) => {
727
780
  setError(err.message);
@@ -733,7 +786,14 @@ function ReactGpuShader({ className, fragment, uniforms, fullscreen = false }) {
733
786
  const { canvasRef } = useWebGPU({
734
787
  fragment,
735
788
  uniforms,
736
- onError: handleError
789
+ onError: handleError,
790
+ timeScale,
791
+ onFrame,
792
+ onClick,
793
+ onMouseMove,
794
+ onMouseDown,
795
+ onMouseUp,
796
+ onMouseWheel
737
797
  });
738
798
  const containerStyle = import_react3.useMemo(() => fullscreen ? FULLSCREEN_CONTAINER_STYLE : DEFAULT_CONTAINER_STYLE, [fullscreen]);
739
799
  if (error) {
package/dist/index.js CHANGED
@@ -229,10 +229,10 @@ function inferWgslType(value) {
229
229
  }
230
230
  if (isVec4Array(value)) {
231
231
  return {
232
- wgslType: `array<vec4f, ${value.length}>`,
232
+ wgslType: `array<vec4f, 100>`,
233
233
  baseType: "vec4f",
234
234
  isArray: true,
235
- arrayLength: value.length
235
+ arrayLength: 100
236
236
  };
237
237
  }
238
238
  if (isVec4(value)) {
@@ -491,12 +491,37 @@ function useWebGPU(options) {
491
491
  const mouseLeftDownRef = useRef2(false);
492
492
  const canvasRectRef = useRef2(null);
493
493
  const onErrorRef = useRef2(options.onError);
494
+ const onFrameRef = useRef2(options.onFrame);
495
+ const onClickRef = useRef2(options.onClick);
496
+ const onMouseDownRef = useRef2(options.onMouseDown);
497
+ const onMouseUpRef = useRef2(options.onMouseUp);
498
+ const onMouseMoveRef = useRef2(options.onMouseMove);
499
+ const onMouseWheelRef = useRef2(options.onMouseWheel);
500
+ const timeScaleRef = useRef2(options.timeScale ?? 1);
494
501
  const fragmentRef = useRef2(options.fragment);
495
502
  const uniformsRef = useRef2(options.uniforms);
496
503
  const dprRef = useRef2(window.devicePixelRatio || 1);
497
504
  onErrorRef.current = options.onError;
505
+ onFrameRef.current = options.onFrame;
506
+ onClickRef.current = options.onClick;
507
+ onMouseDownRef.current = options.onMouseDown;
508
+ onMouseUpRef.current = options.onMouseUp;
509
+ onMouseMoveRef.current = options.onMouseMove;
510
+ onMouseWheelRef.current = options.onMouseWheel;
511
+ timeScaleRef.current = options.timeScale ?? 1;
498
512
  fragmentRef.current = options.fragment;
499
513
  uniformsRef.current = options.uniforms;
514
+ const buildFrameInfo = useCallback2((deltaTime) => {
515
+ const canvas = canvasRef.current;
516
+ return {
517
+ deltaTime,
518
+ time: elapsedTimeRef.current,
519
+ resolution: [canvas?.width ?? 0, canvas?.height ?? 0],
520
+ mouse: mouseRef.current,
521
+ mouseNormalized: mouseNormalizedRef.current,
522
+ mouseLeftDown: mouseLeftDownRef.current
523
+ };
524
+ }, []);
500
525
  const render = useCallback2((time) => {
501
526
  const state = stateRef.current;
502
527
  const canvas = canvasRef.current;
@@ -505,7 +530,10 @@ function useWebGPU(options) {
505
530
  }
506
531
  const deltaTime = lastFrameTimeRef.current === 0 ? 0 : (time - lastFrameTimeRef.current) / 1000;
507
532
  lastFrameTimeRef.current = time;
508
- elapsedTimeRef.current += deltaTime;
533
+ elapsedTimeRef.current += deltaTime * timeScaleRef.current;
534
+ if (onFrameRef.current) {
535
+ onFrameRef.current(buildFrameInfo(deltaTime));
536
+ }
509
537
  const { device, context, pipeline, uniformBuffer, uniformBindGroup, uniformLayout } = state;
510
538
  const dpr = dprRef.current;
511
539
  const displayWidth = canvas.clientWidth;
@@ -562,7 +590,7 @@ function useWebGPU(options) {
562
590
  renderPass.end();
563
591
  device.queue.submit([commandEncoder.finish()]);
564
592
  animationFrameRef.current = requestAnimationFrame(render);
565
- }, []);
593
+ }, [buildFrameInfo]);
566
594
  useEffect(() => {
567
595
  const canvas = canvasRef.current;
568
596
  if (!canvas)
@@ -630,28 +658,41 @@ function useWebGPU(options) {
630
658
  (mouseRef.current[0] - canvas.width / 2) / minDimension,
631
659
  (mouseRef.current[1] - canvas.height / 2) / minDimension
632
660
  ];
661
+ onMouseMoveRef.current?.(buildFrameInfo(0));
633
662
  };
634
663
  const handleMouseDown = (event) => {
635
664
  if (event.button === 0) {
636
665
  mouseLeftDownRef.current = true;
637
666
  }
667
+ onMouseDownRef.current?.(buildFrameInfo(0));
638
668
  };
639
669
  const handleMouseUp = (event) => {
640
670
  if (event.button === 0) {
641
671
  mouseLeftDownRef.current = false;
642
672
  }
673
+ onMouseUpRef.current?.(buildFrameInfo(0));
674
+ };
675
+ const handleClick = () => {
676
+ onClickRef.current?.(buildFrameInfo(0));
677
+ };
678
+ const handleMouseWheel = (event) => {
679
+ onMouseWheelRef.current?.(buildFrameInfo(0), event.deltaY);
643
680
  };
644
681
  window.addEventListener("mousemove", handleMouseMove);
645
682
  window.addEventListener("mousedown", handleMouseDown);
646
683
  window.addEventListener("mouseup", handleMouseUp);
684
+ canvas.addEventListener("click", handleClick);
685
+ window.addEventListener("wheel", handleMouseWheel);
647
686
  return () => {
648
687
  resizeObserver.disconnect();
649
688
  window.removeEventListener("scroll", updateRect);
650
689
  window.removeEventListener("mousemove", handleMouseMove);
651
690
  window.removeEventListener("mousedown", handleMouseDown);
652
691
  window.removeEventListener("mouseup", handleMouseUp);
692
+ canvas.removeEventListener("click", handleClick);
693
+ window.removeEventListener("wheel", handleMouseWheel);
653
694
  };
654
- }, []);
695
+ }, [buildFrameInfo]);
655
696
  return { canvasRef, mouseRef };
656
697
  }
657
698
 
@@ -675,7 +716,19 @@ var CANVAS_STYLE = {
675
716
  width: "100%",
676
717
  height: "100%"
677
718
  };
678
- function ReactGpuShader({ className, fragment, uniforms, fullscreen = false }) {
719
+ function ReactGpuShader({
720
+ className,
721
+ fragment,
722
+ uniforms,
723
+ fullscreen = false,
724
+ timeScale,
725
+ onFrame,
726
+ onClick,
727
+ onMouseMove,
728
+ onMouseDown,
729
+ onMouseUp,
730
+ onMouseWheel
731
+ }) {
679
732
  const [error, setError] = useState2(null);
680
733
  const handleError = useCallback3((err) => {
681
734
  setError(err.message);
@@ -687,7 +740,14 @@ function ReactGpuShader({ className, fragment, uniforms, fullscreen = false }) {
687
740
  const { canvasRef } = useWebGPU({
688
741
  fragment,
689
742
  uniforms,
690
- onError: handleError
743
+ onError: handleError,
744
+ timeScale,
745
+ onFrame,
746
+ onClick,
747
+ onMouseMove,
748
+ onMouseDown,
749
+ onMouseUp,
750
+ onMouseWheel
691
751
  });
692
752
  const containerStyle = useMemo(() => fullscreen ? FULLSCREEN_CONTAINER_STYLE : DEFAULT_CONTAINER_STYLE, [fullscreen]);
693
753
  if (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fjandin/react-shader",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "React component for rendering WebGL shaders",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",