1616 * See the License for the specific language governing permissions and
1717 * limitations under the License.
1818 */
19- import type { ExtractProps } from '../../../CoreTextureManager.js' ;
2019import type { WebGlCoreRenderer } from '../WebGlCoreRenderer.js' ;
2120import {
2221 WebGlCoreShader ,
@@ -27,70 +26,14 @@ import type { UniformInfo } from '../internal/ShaderUtils.js';
2726import type { WebGlCoreCtxTexture } from '../WebGlCoreCtxTexture.js' ;
2827import {
2928 ShaderEffect ,
29+ type EffectDescUnion ,
3030 type ShaderEffectUniform ,
3131 type ShaderEffectValueMap ,
32+ type BaseEffectDesc ,
3233} from './effects/ShaderEffect.js' ;
3334import type { EffectMap } from '../../../CoreShaderManager.js' ;
3435import { assertTruthy } from '../../../../utils.js' ;
3536
36- export interface BaseEffectDesc {
37- name ?: string ;
38- type : keyof EffectMap ;
39- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40- props : Record < string , any > ;
41- }
42-
43- export interface EffectDesc <
44- T extends { name ?: string ; type : keyof EffectMap } = {
45- name ?: string ;
46- type : keyof EffectMap ;
47- } ,
48- > extends BaseEffectDesc {
49- name ?: T [ 'name' ] ;
50- type : T [ 'type' ] ;
51- props : ExtractProps < EffectMap [ T [ 'type' ] ] > ;
52- }
53-
54- /**
55- * Allows the `keyof EffectMap` to be mapped over and form an discriminated
56- * union of all the EffectDescs structures individually.
57- *
58- * @remarks
59- * When used like the following:
60- * ```
61- * MapEffectDescs<keyof EffectMap>[]
62- * ```
63- * The resultant type will be a discriminated union like so:
64- * ```
65- * (
66- * {
67- * name: 'effect1',
68- * type: 'radius',
69- * props?: {
70- * radius?: number | number[];
71- * }
72- * } |
73- * {
74- * name: 'effect2',
75- * type: 'border',
76- * props?: {
77- * width?: number;
78- * color?: number;
79- * }
80- * } |
81- * // ...
82- * )[]
83- * ```
84- * Which means TypeScript will now base its type checking on the `type` field
85- * and will know exactly what the `props` field should be based on the `type`
86- * field.
87- */
88- type MapEffectDescs < T extends keyof EffectMap > = T extends keyof EffectMap
89- ? EffectDesc < { type : T ; name : string } >
90- : never ;
91-
92- export type EffectDescUnion = MapEffectDescs < keyof EffectMap > ;
93-
9437export interface DynamicShaderProps
9538 extends DimensionsShaderProp ,
9639 AlphaShaderProp {
0 commit comments