Skip to content

Commit

Permalink
Restrict swizzle options (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Methuselah96 authored Jan 4, 2025
1 parent 39b0b03 commit 034af1c
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions types/three/src/nodes/tsl/TSLCore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,29 @@ export interface NodeElements {

export function addMethodChaining(name: string, nodeElement: unknown): void;

export type SwizzleCharacter = "x" | "y" | "z" | "w" | "r" | "g" | "b" | "a" | "s" | "t" | "p" | "q";

export type SwizzleOption = Exclude<
| `${SwizzleCharacter}`
| `${SwizzleCharacter}${SwizzleCharacter}`
| `${SwizzleCharacter}${SwizzleCharacter}${SwizzleCharacter}`
| `${SwizzleCharacter}${SwizzleCharacter}${SwizzleCharacter}${SwizzleCharacter}`,
"abs" | "sqrt"
>;
type XYZWCharacter = "x" | "y" | "z" | "w";
type RGBACharacter = "r" | "g" | "b" | "a";
type STPQCharacter = "s" | "t" | "p" | "q";

type XYZWSwizzle =
| `${XYZWCharacter}`
| `${XYZWCharacter}${XYZWCharacter}`
| `${XYZWCharacter}${XYZWCharacter}${XYZWCharacter}`
| `${XYZWCharacter}${XYZWCharacter}${XYZWCharacter}${XYZWCharacter}`;

type RGBASwizzle =
| `${RGBACharacter}`
| `${RGBACharacter}${RGBACharacter}`
| `${RGBACharacter}${RGBACharacter}${RGBACharacter}`
| `${RGBACharacter}${RGBACharacter}${RGBACharacter}${RGBACharacter}`;

type STPQSwizzle =
| `${STPQCharacter}`
| `${STPQCharacter}${STPQCharacter}`
| `${STPQCharacter}${STPQCharacter}${STPQCharacter}`
| `${STPQCharacter}${STPQCharacter}${STPQCharacter}${STPQCharacter}`;

export type SwizzleOption = XYZWSwizzle | RGBASwizzle | STPQSwizzle;

export type Swizzable<T extends Node = Node> =
& T
Expand Down

0 comments on commit 034af1c

Please sign in to comment.