/** Alias type for value that can be null */ export type Nullable = T | null; /** * Alias type for number that are floats */ export type float = number; /** * Alias type for number that are doubles. */ export type double = number; /** * Alias type for number that are integer */ export type int = number; /** * Empty */ export type Empty = []; /** * Removes the first element of T and shifts */ export type Shift = T extends unknown[] ? (((...x: T) => void) extends (h: any, ...t: infer I) => void ? I : []) : unknown; /** * Gets the first element of T */ export type First = T extends unknown[] ? (((...x: T) => void) extends (h: infer I, ...t: any) => void ? I : []) : never; /** * Inserts A into T at the start of T */ export type Unshift = T extends unknown[] ? (((h: A, ...t: T) => void) extends (...i: infer I) => void ? I : unknown) : never; /** * Removes the last element of T */ export type Pop = T extends unknown[] ? (((...x: T) => void) extends (...i: [...infer I, any]) => void ? I : unknown) : never; /** * Gets the last element of T */ export type Last = T extends unknown[] ? (((...x: T) => void) extends (...i: [...infer H, infer I]) => void ? I : unknown) : never; /** * Appends A to T */ export type Push = T extends unknown[] ? (((...a: [...T, A]) => void) extends (...i: infer I) => void ? I : unknown) : never; /** * Concats A and B */ export type Concat = { 0: A; 1: Concat, Shift>; }[Empty extends B ? 0 : 1]; /** * Extracts from A what is not B * * @remarks * It does not remove duplicates (so Remove\<[0, 0, 0], [0, 0]\> yields [0]). This is intended and necessary behavior. */ export type Remove = { 0: A; 1: Remove, Shift>; }[Empty extends B ? 0 : 1]; /** * The length of T */ export type Length = T extends { length: number; } ? T["length"] : never; type _FromLength = { 0: R; 1: _FromLength>; }[Length extends N ? 0 : 1]; /** * Creates a tuple of length N */ export type FromLength = _FromLength; /** * Increments N */ export type Increment = Length, 0>>; /** * Decrements N */ export type Decrement = Length>>; /** * Gets the sum of A and B */ export type Add = Length, _FromLength>>; /** * Subtracts B from A */ export type Subtract = Length, _FromLength>>; /** * Gets the type of an array's members */ export type Member = D extends 0 ? T : T extends (infer U)[] ? Member : null> : T; /** * Flattens an array */ export type FlattenArray = A extends (infer U)[] ? Member, D>[] : A extends unknown[] ? { [K in keyof A]: Member; } : A; /** * Whether T is a tuple */ export type IsTuple = T extends [] ? false : T extends [infer Head, ...infer Rest] ? true : false; /** * Flattens a tuple */ export type FlattenTuple = A extends [infer U, ...infer Rest] ? (U extends unknown[] ? [...U, ...FlattenTuple] : [U, ...FlattenTuple]) : []; /** * Flattens an array or tuple */ export type Flatten = IsTuple extends true ? FlattenTuple : FlattenArray; type _Tuple = R["length"] extends N ? R : _Tuple; /** * Creates a tuple of T with length N */ export type Tuple = _Tuple; /** Alias type for number array or Float32Array */ export type FloatArray = number[] | Float32Array; /** Alias type for number array or Float32Array or Int32Array or Uint32Array or Uint16Array */ export type IndicesArray = number[] | Int32Array | Uint32Array | Uint16Array; /** * Alias type for all TypedArrays */ export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; /** * Alias for types that can be used by a Buffer or VertexBuffer. */ export type DataArray = number[] | ArrayBuffer | ArrayBufferView; /** * Alias type for primitive types */ type Primitive = undefined | null | boolean | string | number | Function | Element; /** * Type modifier to make all the properties of an object Readonly */ export type Immutable = T extends Primitive ? T : T extends Array ? ReadonlyArray : DeepImmutable; /** * Type modifier to make all the properties of an object Readonly recursively */ export type DeepImmutable = T extends Primitive ? T : T extends Array ? DeepImmutableArray : DeepImmutableObject; /** * Type modifier to make all the properties of an object NonNullable */ export type NonNullableFields = { [P in keyof T]: NonNullable; }; /** * Type modifier to make all the properties of an object Writable (remove "readonly") */ export type WritableObject = { -readonly [P in keyof T]: T[P]; }; /** * Type modifier to make object properties readonly. */ export type DeepImmutableObject = { readonly [K in keyof T]: DeepImmutable; }; /** @internal */ interface DeepImmutableArray extends ReadonlyArray> { } /** @internal */ export type Constructor any, I extends InstanceType = InstanceType> = { new (...args: ConstructorParameters): I; }; /** * Alias type for image sources */ export type ImageSource = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas; /** * Type for typed array like objects */ export interface TypedArrayLike extends ArrayBufferView { /** * The size in bytes of the array. */ readonly length: number; [n: number]: number; } /** * Interface for a constructor of a TypedArray. */ export interface TypedArrayConstructor { new (length: number): T; new (elements: Iterable): T; new (buffer: ArrayBufferLike, byteOffset?: number, length?: number): T; /** * The size in bytes of each element in the array. */ readonly BYTES_PER_ELEMENT: number; } export {};