-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy paththree-types.ts
82 lines (69 loc) · 2.6 KB
/
three-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type * as THREE from 'three'
import type {} from 'react'
import type {} from 'react/jsx-runtime'
import type {} from 'react/jsx-dev-runtime'
import type { Args, EventHandlers, InstanceProps, ConstructorRepresentation } from './core'
import type { Overwrite, Mutable } from './core/utils'
export interface MathRepresentation {
set(...args: number[]): any
}
export interface VectorRepresentation extends MathRepresentation {
setScalar(value: number): any
}
export type MathTypes = MathRepresentation | THREE.Euler | THREE.Color
export type MathType<T extends MathTypes> = T extends THREE.Color
? Args<typeof THREE.Color> | THREE.ColorRepresentation
: T extends VectorRepresentation | THREE.Layers | THREE.Euler
? T | Parameters<T['set']> | number
: T | Parameters<T['set']>
export type MathProps<P> = {
[K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
}
export type Vector2 = MathType<THREE.Vector2>
export type Vector3 = MathType<THREE.Vector3>
export type Vector4 = MathType<THREE.Vector4>
export type Color = MathType<THREE.Color>
export type Layers = MathType<THREE.Layers>
export type Quaternion = MathType<THREE.Quaternion>
export type Euler = MathType<THREE.Euler>
export type Matrix3 = MathType<THREE.Matrix3>
export type Matrix4 = MathType<THREE.Matrix4>
export interface RaycastableRepresentation {
raycast(raycaster: THREE.Raycaster, intersects: THREE.Intersection[]): void
}
export type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
export interface ReactProps<P> {
children?: React.ReactNode
ref?: React.Ref<P>
key?: React.Key
}
export type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P>>
>
export type ThreeElement<T extends ConstructorRepresentation> = Mutable<
Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
>
type ThreeExports = typeof THREE
type ThreeElementsImpl = {
[K in keyof ThreeExports as Uncapitalize<K>]: ThreeExports[K] extends ConstructorRepresentation
? ThreeElement<ThreeExports[K]>
: never
}
export interface ThreeElements extends ThreeElementsImpl {
primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
}
declare module 'react' {
namespace JSX {
interface IntrinsicElements extends ThreeElements {}
}
}
declare module 'react/jsx-runtime' {
namespace JSX {
interface IntrinsicElements extends ThreeElements {}
}
}
declare module 'react/jsx-dev-runtime' {
namespace JSX {
interface IntrinsicElements extends ThreeElements {}
}
}