@fjandin/react-shader 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,3 +1,3 @@
1
1
  import type { ReactShaderProps } from "./types";
2
- export declare function ReactShader({ className, fragment, vertex, uniforms, fullscreen, timeScale, onFrame, onClick, onMouseMove, }: ReactShaderProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function ReactShader({ className, fragment, vertex, uniforms, fullscreen, timeScale, onFrame, onClick, onMouseMove, onMouseDown, onMouseUp, }: ReactShaderProps): import("react/jsx-runtime").JSX.Element;
3
3
  //# sourceMappingURL=ReactShader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReactShader.d.ts","sourceRoot":"","sources":["../src/ReactShader.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAgC/C,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,QAAQ,EACR,MAAuB,EACvB,QAAQ,EACR,UAAkB,EAClB,SAAa,EACb,OAAO,EACP,OAAO,EACP,WAAW,GACZ,EAAE,gBAAgB,2CAuDlB"}
1
+ {"version":3,"file":"ReactShader.d.ts","sourceRoot":"","sources":["../src/ReactShader.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAgC/C,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,QAAQ,EACR,MAAuB,EACvB,QAAQ,EACR,UAAkB,EAClB,SAAa,EACb,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,SAAS,GACV,EAAE,gBAAgB,2CAyDlB"}
@@ -6,6 +6,8 @@ interface UseWebGLOptions {
6
6
  onError?: (error: Error) => void;
7
7
  onFrame?: (info: FrameInfo) => void;
8
8
  onClick?: (info: FrameInfo) => void;
9
+ onMouseDown?: (info: FrameInfo) => void;
10
+ onMouseUp?: (info: FrameInfo) => void;
9
11
  onMouseMove?: (info: FrameInfo) => void;
10
12
  timeScale?: number;
11
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useWebGL.d.ts","sourceRoot":"","sources":["../../src/hooks/useWebGL.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAIvD,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,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,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAqED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe;;;EAmQhD"}
1
+ {"version":3,"file":"useWebGL.d.ts","sourceRoot":"","sources":["../../src/hooks/useWebGL.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAIvD,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,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,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACrC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAA;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAqED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe;;;EAyRhD"}
package/dist/index.cjs CHANGED
@@ -269,6 +269,8 @@ function useWebGL(options) {
269
269
  const onErrorRef = import_react.useRef(options.onError);
270
270
  const onFrameRef = import_react.useRef(options.onFrame);
271
271
  const onClickRef = import_react.useRef(options.onClick);
272
+ const onMouseDownRef = import_react.useRef(options.onMouseDown);
273
+ const onMouseUpRef = import_react.useRef(options.onMouseUp);
272
274
  const onMouseMoveRef = import_react.useRef(options.onMouseMove);
273
275
  const timeScaleRef = import_react.useRef(options.timeScale ?? 1);
274
276
  const vertexRef = import_react.useRef(options.vertex);
@@ -285,6 +287,8 @@ function useWebGL(options) {
285
287
  onErrorRef.current = options.onError;
286
288
  onFrameRef.current = options.onFrame;
287
289
  onClickRef.current = options.onClick;
290
+ onMouseDownRef.current = options.onMouseDown;
291
+ onMouseUpRef.current = options.onMouseUp;
288
292
  onMouseMoveRef.current = options.onMouseMove;
289
293
  timeScaleRef.current = options.timeScale ?? 1;
290
294
  vertexRef.current = options.vertex;
@@ -298,6 +302,7 @@ function useWebGL(options) {
298
302
  return;
299
303
  const deltaTime = lastFrameTimeRef.current === 0 ? 0 : (time - lastFrameTimeRef.current) / 1000;
300
304
  lastFrameTimeRef.current = time;
305
+ elapsedTimeRef.current += deltaTime * timeScaleRef.current;
301
306
  const { gl, program, positionAttributeLocation, uniformLocationCache } = state;
302
307
  const elapsedTime = elapsedTimeRef.current;
303
308
  const dpr = dprRef.current;
@@ -425,11 +430,27 @@ function useWebGL(options) {
425
430
  if (event.button === 0) {
426
431
  mouseLeftDownRef.current = true;
427
432
  }
433
+ onMouseDownRef.current?.({
434
+ deltaTime: 0,
435
+ time: elapsedTimeRef.current,
436
+ resolution: [canvas.width, canvas.height],
437
+ mouse: mouseRef.current,
438
+ mouseNormalized: mouseNormalizedRef.current,
439
+ mouseLeftDown: mouseLeftDownRef.current
440
+ });
428
441
  };
429
442
  const handleMouseUp = (event) => {
430
443
  if (event.button === 0) {
431
444
  mouseLeftDownRef.current = false;
432
445
  }
446
+ onMouseUpRef.current?.({
447
+ deltaTime: 0,
448
+ time: elapsedTimeRef.current,
449
+ resolution: [canvas.width, canvas.height],
450
+ mouse: mouseRef.current,
451
+ mouseNormalized: mouseNormalizedRef.current,
452
+ mouseLeftDown: mouseLeftDownRef.current
453
+ });
433
454
  };
434
455
  const handleClick = () => {
435
456
  if (!onClickRef.current)
@@ -495,7 +516,9 @@ function ReactShader({
495
516
  timeScale = 1,
496
517
  onFrame,
497
518
  onClick,
498
- onMouseMove
519
+ onMouseMove,
520
+ onMouseDown,
521
+ onMouseUp
499
522
  }) {
500
523
  const [error, setError] = import_react2.useState(null);
501
524
  const handleError = import_react2.useCallback((err) => {
@@ -513,6 +536,8 @@ function ReactShader({
513
536
  onFrame,
514
537
  onClick,
515
538
  onMouseMove,
539
+ onMouseDown,
540
+ onMouseUp,
516
541
  timeScale
517
542
  });
518
543
  const containerStyle = import_react2.useMemo(() => fullscreen ? FULLSCREEN_CONTAINER_STYLE : DEFAULT_CONTAINER_STYLE, [fullscreen]);
package/dist/index.js CHANGED
@@ -229,6 +229,8 @@ function useWebGL(options) {
229
229
  const onErrorRef = useRef(options.onError);
230
230
  const onFrameRef = useRef(options.onFrame);
231
231
  const onClickRef = useRef(options.onClick);
232
+ const onMouseDownRef = useRef(options.onMouseDown);
233
+ const onMouseUpRef = useRef(options.onMouseUp);
232
234
  const onMouseMoveRef = useRef(options.onMouseMove);
233
235
  const timeScaleRef = useRef(options.timeScale ?? 1);
234
236
  const vertexRef = useRef(options.vertex);
@@ -245,6 +247,8 @@ function useWebGL(options) {
245
247
  onErrorRef.current = options.onError;
246
248
  onFrameRef.current = options.onFrame;
247
249
  onClickRef.current = options.onClick;
250
+ onMouseDownRef.current = options.onMouseDown;
251
+ onMouseUpRef.current = options.onMouseUp;
248
252
  onMouseMoveRef.current = options.onMouseMove;
249
253
  timeScaleRef.current = options.timeScale ?? 1;
250
254
  vertexRef.current = options.vertex;
@@ -258,6 +262,7 @@ function useWebGL(options) {
258
262
  return;
259
263
  const deltaTime = lastFrameTimeRef.current === 0 ? 0 : (time - lastFrameTimeRef.current) / 1000;
260
264
  lastFrameTimeRef.current = time;
265
+ elapsedTimeRef.current += deltaTime * timeScaleRef.current;
261
266
  const { gl, program, positionAttributeLocation, uniformLocationCache } = state;
262
267
  const elapsedTime = elapsedTimeRef.current;
263
268
  const dpr = dprRef.current;
@@ -385,11 +390,27 @@ function useWebGL(options) {
385
390
  if (event.button === 0) {
386
391
  mouseLeftDownRef.current = true;
387
392
  }
393
+ onMouseDownRef.current?.({
394
+ deltaTime: 0,
395
+ time: elapsedTimeRef.current,
396
+ resolution: [canvas.width, canvas.height],
397
+ mouse: mouseRef.current,
398
+ mouseNormalized: mouseNormalizedRef.current,
399
+ mouseLeftDown: mouseLeftDownRef.current
400
+ });
388
401
  };
389
402
  const handleMouseUp = (event) => {
390
403
  if (event.button === 0) {
391
404
  mouseLeftDownRef.current = false;
392
405
  }
406
+ onMouseUpRef.current?.({
407
+ deltaTime: 0,
408
+ time: elapsedTimeRef.current,
409
+ resolution: [canvas.width, canvas.height],
410
+ mouse: mouseRef.current,
411
+ mouseNormalized: mouseNormalizedRef.current,
412
+ mouseLeftDown: mouseLeftDownRef.current
413
+ });
393
414
  };
394
415
  const handleClick = () => {
395
416
  if (!onClickRef.current)
@@ -455,7 +476,9 @@ function ReactShader({
455
476
  timeScale = 1,
456
477
  onFrame,
457
478
  onClick,
458
- onMouseMove
479
+ onMouseMove,
480
+ onMouseDown,
481
+ onMouseUp
459
482
  }) {
460
483
  const [error, setError] = useState(null);
461
484
  const handleError = useCallback2((err) => {
@@ -473,6 +496,8 @@ function ReactShader({
473
496
  onFrame,
474
497
  onClick,
475
498
  onMouseMove,
499
+ onMouseDown,
500
+ onMouseUp,
476
501
  timeScale
477
502
  });
478
503
  const containerStyle = useMemo(() => fullscreen ? FULLSCREEN_CONTAINER_STYLE : DEFAULT_CONTAINER_STYLE, [fullscreen]);
package/dist/types.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface ReactShaderProps {
24
24
  onFrame?: (info: FrameInfo) => void;
25
25
  onClick?: (info: FrameInfo) => void;
26
26
  onMouseMove?: (info: FrameInfo) => void;
27
+ onMouseDown?: (info: FrameInfo) => void;
28
+ onMouseUp?: (info: FrameInfo) => void;
27
29
  }
28
30
  export interface DefaultUniforms {
29
31
  iTime: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACnC,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAC3C,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAEnD,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,CAAA;AACjC,MAAM,MAAM,SAAS,GAAG,IAAI,EAAE,CAAA;AAC9B,MAAM,MAAM,SAAS,GAAG,IAAI,EAAE,CAAA;AAC9B,MAAM,MAAM,SAAS,GAAG,IAAI,EAAE,CAAA;AAE9B,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAEvG,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,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AAE,IAAI,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,IAAI,CAAA;CAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fjandin/react-shader",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "React component for rendering WebGL shaders",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",