@react-three/fiber 8.12.2 → 8.13.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.
@@ -1,11 +1,13 @@
1
- import * as React from 'react';
2
- import type { Options as ResizeOptions } from 'react-use-measure';
3
- import { RenderProps } from '../core';
4
- export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
5
- children: React.ReactNode;
6
- fallback?: React.ReactNode;
7
- resize?: ResizeOptions;
8
- eventSource?: HTMLElement | React.MutableRefObject<HTMLElement>;
9
- eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen';
10
- }
11
- export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
1
+ import * as React from 'react';
2
+ import type { Options as ResizeOptions } from 'react-use-measure';
3
+ import { RenderProps } from '../core';
4
+ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
5
+ children: React.ReactNode;
6
+ fallback?: React.ReactNode;
7
+ resize?: ResizeOptions;
8
+ eventSource?: HTMLElement | React.MutableRefObject<HTMLElement>;
9
+ eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen';
10
+ }
11
+ export interface Props extends CanvasProps {
12
+ }
13
+ export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
@@ -1,4 +1,4 @@
1
- import { UseBoundStore } from 'zustand';
2
- import { RootState } from '../core/store';
3
- import { EventManager } from '../core/events';
4
- export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
1
+ import { UseBoundStore } from 'zustand';
2
+ import { RootState } from '../core/store';
3
+ import { EventManager } from '../core/events';
4
+ export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
@@ -350,6 +350,10 @@ function createRenderer(_roots, _getEventPriority) {
350
350
  }
351
351
 
352
352
  var _window$document, _window$navigator;
353
+ /**
354
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
355
+ */
356
+ const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
353
357
  /**
354
358
  * The current THREE.ColorManagement instance, if present.
355
359
  */
@@ -635,6 +639,21 @@ function applyProps$1(instance, data) {
635
639
  if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
636
640
  for (let i = 0; i < changes.length; i++) {
637
641
  let [key, value, isEvent, keys] = changes[i];
642
+
643
+ // Alias (output)encoding => (output)colorSpace (since r152)
644
+ // https://github.com/pmndrs/react-three-fiber/pull/2829
645
+ if (hasColorSpace(instance)) {
646
+ const sRGBEncoding = 3001;
647
+ const SRGBColorSpace = 'srgb';
648
+ const LinearSRGBColorSpace = 'srgb-linear';
649
+ if (key === 'encoding') {
650
+ key = 'colorSpace';
651
+ value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
652
+ } else if (key === 'outputEncoding') {
653
+ key = 'outputColorSpace';
654
+ value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
655
+ }
656
+ }
638
657
  let currentInstance = instance;
639
658
  let targetProp = currentInstance[key];
640
659
 
@@ -703,12 +722,14 @@ function applyProps$1(instance, data) {
703
722
  // Else, just overwrite the value
704
723
  } else {
705
724
  currentInstance[key] = value;
725
+
706
726
  // Auto-convert sRGB textures, for now ...
707
727
  // https://github.com/pmndrs/react-three-fiber/issues/344
708
- if (!rootState.linear && currentInstance[key] instanceof THREE.Texture &&
728
+ if (currentInstance[key] instanceof THREE.Texture &&
709
729
  // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
710
730
  currentInstance[key].format === THREE.RGBAFormat && currentInstance[key].type === THREE.UnsignedByteType) {
711
- currentInstance[key].encoding = THREE.sRGBEncoding;
731
+ const texture = currentInstance[key];
732
+ if (hasColorSpace(texture) && hasColorSpace(rootState.gl)) texture.colorSpace = rootState.gl.outputColorSpace;else texture.encoding = rootState.gl.outputEncoding;
712
733
  }
713
734
  }
714
735
  invalidateInstance(instance);
@@ -1888,10 +1909,14 @@ function createRoot(canvas) {
1888
1909
  if (ColorManagement) {
1889
1910
  if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
1890
1911
  }
1891
- const outputEncoding = linear ? THREE.LinearEncoding : THREE.sRGBEncoding;
1892
- const toneMapping = flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping;
1893
- if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
1894
- if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping;
1912
+
1913
+ // Set color space and tonemapping preferences
1914
+ const LinearEncoding = 3000;
1915
+ const sRGBEncoding = 3001;
1916
+ applyProps(gl, {
1917
+ outputEncoding: linear ? LinearEncoding : sRGBEncoding,
1918
+ toneMapping: flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping
1919
+ });
1895
1920
 
1896
1921
  // Update color management state
1897
1922
  if (state.legacy !== legacy) state.set(() => ({
@@ -377,6 +377,10 @@ function createRenderer(_roots, _getEventPriority) {
377
377
  }
378
378
 
379
379
  var _window$document, _window$navigator;
380
+ /**
381
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
382
+ */
383
+ const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
380
384
  /**
381
385
  * The current THREE.ColorManagement instance, if present.
382
386
  */
@@ -662,6 +666,21 @@ function applyProps$1(instance, data) {
662
666
  if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
663
667
  for (let i = 0; i < changes.length; i++) {
664
668
  let [key, value, isEvent, keys] = changes[i];
669
+
670
+ // Alias (output)encoding => (output)colorSpace (since r152)
671
+ // https://github.com/pmndrs/react-three-fiber/pull/2829
672
+ if (hasColorSpace(instance)) {
673
+ const sRGBEncoding = 3001;
674
+ const SRGBColorSpace = 'srgb';
675
+ const LinearSRGBColorSpace = 'srgb-linear';
676
+ if (key === 'encoding') {
677
+ key = 'colorSpace';
678
+ value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
679
+ } else if (key === 'outputEncoding') {
680
+ key = 'outputColorSpace';
681
+ value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
682
+ }
683
+ }
665
684
  let currentInstance = instance;
666
685
  let targetProp = currentInstance[key];
667
686
 
@@ -730,12 +749,14 @@ function applyProps$1(instance, data) {
730
749
  // Else, just overwrite the value
731
750
  } else {
732
751
  currentInstance[key] = value;
752
+
733
753
  // Auto-convert sRGB textures, for now ...
734
754
  // https://github.com/pmndrs/react-three-fiber/issues/344
735
- if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture &&
755
+ if (currentInstance[key] instanceof THREE__namespace.Texture &&
736
756
  // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
737
757
  currentInstance[key].format === THREE__namespace.RGBAFormat && currentInstance[key].type === THREE__namespace.UnsignedByteType) {
738
- currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
758
+ const texture = currentInstance[key];
759
+ if (hasColorSpace(texture) && hasColorSpace(rootState.gl)) texture.colorSpace = rootState.gl.outputColorSpace;else texture.encoding = rootState.gl.outputEncoding;
739
760
  }
740
761
  }
741
762
  invalidateInstance(instance);
@@ -1915,10 +1936,14 @@ function createRoot(canvas) {
1915
1936
  if (ColorManagement) {
1916
1937
  if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
1917
1938
  }
1918
- const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
1919
- const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
1920
- if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
1921
- if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping;
1939
+
1940
+ // Set color space and tonemapping preferences
1941
+ const LinearEncoding = 3000;
1942
+ const sRGBEncoding = 3001;
1943
+ applyProps(gl, {
1944
+ outputEncoding: linear ? LinearEncoding : sRGBEncoding,
1945
+ toneMapping: flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping
1946
+ });
1922
1947
 
1923
1948
  // Update color management state
1924
1949
  if (state.legacy !== legacy) state.set(() => ({
@@ -377,6 +377,10 @@ function createRenderer(_roots, _getEventPriority) {
377
377
  }
378
378
 
379
379
  var _window$document, _window$navigator;
380
+ /**
381
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
382
+ */
383
+ const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
380
384
  /**
381
385
  * The current THREE.ColorManagement instance, if present.
382
386
  */
@@ -662,6 +666,21 @@ function applyProps$1(instance, data) {
662
666
  if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
663
667
  for (let i = 0; i < changes.length; i++) {
664
668
  let [key, value, isEvent, keys] = changes[i];
669
+
670
+ // Alias (output)encoding => (output)colorSpace (since r152)
671
+ // https://github.com/pmndrs/react-three-fiber/pull/2829
672
+ if (hasColorSpace(instance)) {
673
+ const sRGBEncoding = 3001;
674
+ const SRGBColorSpace = 'srgb';
675
+ const LinearSRGBColorSpace = 'srgb-linear';
676
+ if (key === 'encoding') {
677
+ key = 'colorSpace';
678
+ value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
679
+ } else if (key === 'outputEncoding') {
680
+ key = 'outputColorSpace';
681
+ value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
682
+ }
683
+ }
665
684
  let currentInstance = instance;
666
685
  let targetProp = currentInstance[key];
667
686
 
@@ -730,12 +749,14 @@ function applyProps$1(instance, data) {
730
749
  // Else, just overwrite the value
731
750
  } else {
732
751
  currentInstance[key] = value;
752
+
733
753
  // Auto-convert sRGB textures, for now ...
734
754
  // https://github.com/pmndrs/react-three-fiber/issues/344
735
- if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture &&
755
+ if (currentInstance[key] instanceof THREE__namespace.Texture &&
736
756
  // sRGB textures must be RGBA8 since r137 https://github.com/mrdoob/three.js/pull/23129
737
757
  currentInstance[key].format === THREE__namespace.RGBAFormat && currentInstance[key].type === THREE__namespace.UnsignedByteType) {
738
- currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
758
+ const texture = currentInstance[key];
759
+ if (hasColorSpace(texture) && hasColorSpace(rootState.gl)) texture.colorSpace = rootState.gl.outputColorSpace;else texture.encoding = rootState.gl.outputEncoding;
739
760
  }
740
761
  }
741
762
  invalidateInstance(instance);
@@ -1915,10 +1936,14 @@ function createRoot(canvas) {
1915
1936
  if (ColorManagement) {
1916
1937
  if ('enabled' in ColorManagement) ColorManagement.enabled = !legacy;else if ('legacyMode' in ColorManagement) ColorManagement.legacyMode = legacy;
1917
1938
  }
1918
- const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
1919
- const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
1920
- if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
1921
- if (gl.toneMapping !== toneMapping) gl.toneMapping = toneMapping;
1939
+
1940
+ // Set color space and tonemapping preferences
1941
+ const LinearEncoding = 3000;
1942
+ const sRGBEncoding = 3001;
1943
+ applyProps(gl, {
1944
+ outputEncoding: linear ? LinearEncoding : sRGBEncoding,
1945
+ toneMapping: flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping
1946
+ });
1922
1947
 
1923
1948
  // Update color management state
1924
1949
  if (state.legacy !== legacy) state.set(() => ({
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-ab4b9c97.cjs.dev.js');
5
+ var index = require('./index-f4b96a62.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-1fcbd5a8.cjs.prod.js');
5
+ var index = require('./index-ed22818c.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-21bbaaf9.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-21bbaaf9.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-22ee0173.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-22ee0173.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-ab4b9c97.cjs.dev.js');
5
+ var index = require('../../dist/index-f4b96a62.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-1fcbd5a8.cjs.prod.js');
5
+ var index = require('../../dist/index-ed22818c.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-21bbaaf9.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-21bbaaf9.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-22ee0173.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-22ee0173.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.12.2",
3
+ "version": "8.13.0",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",