import flow from "lodash-es/flow" ; import map from "lodash-es/map" ; import { default as pr } from "lodash-es/partialRight" ; import takeRight from "lodash-es/takeRight" ; /**
 * A No-Op function
 */ export function noop ( ) { } param options param requiredOptions export function checkRequiredOptions ( options , requiredOptions ) { for ( const optionName of requiredOptions ) { if ( ! ( optionName in options ) ) { throw new Error ( "Required option " + optionName + " not found" ) ; } } } param val export function glslFloatRepr ( val ) { return val + ( parseFloat ( val ) % 1 === 0 ? ".0" : "" ) ; } /**
 * Color type. R, G, B
 */ export type Color = [ number , number , number ] ; param color function isColor ( color ) { return Array . isArray ( color ) && color . length === 3 ; } param color export function parseColor ( color ) { if ( isColor ( color ) ) { return color ; } else { color = color . toLowerCase ( ) ; let match = color . match ( /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/ ) ; if ( match ) { return flow ( [ pr ( takeRight , 3 ) , pr ( map , ( channel ) => { return parseInt ( channel , 16 ) ; } ) , ] ) ( match ) as Color ; } match = color . match ( /^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/ ) ; if ( match ) { return flow ( [ pr ( takeRight , 3 ) , pr ( map , ( channel ) => { return Math . min ( parseInt ( channel , 10 ) , 255 ) ; } ) , ] ) ( match ) as Color ; } } throw new Error ( "Invalid Color Format" ) ; } param color export function parseColorNorm ( color ) { return map ( parseColor ( color ) , ( value ) => value / 255 ) as Color ; } param src param error export function logShaderError ( src , error ) { const lines = src . split ( "\n" ) ; const ndigits = lines . length . toString ( ) . length ; const errorPosMatch = error . match ( /(\d+):(\d+)/ ) ; let errorPos ; if ( errorPosMatch ) { errorPos = [ parseInt ( errorPosMatch [ 1 ] , 10 ) , parseInt ( errorPosMatch [ 2 ] , 10 ) ] ; } const numberedLines = map ( lines , ( line , index ) => { let i ; let lineNumber = ( index + 1 ) + "" ; for ( i = 0 ; i < ( ndigits - lineNumber . length ) ; i ++ ) { lineNumber = "0" + lineNumber ; } let errorIndicator = "" ; if ( errorPos && errorPos [ 1 ] === index + 1 ) { let indent = "" ; for ( i = 0 ; i < errorPos [ 0 ] + ndigits + 2 ; i ++ ) { indent += " " ; } errorIndicator = "\n" + indent + "^\n" + indent + error ; } return lineNumber + ": " + line + errorIndicator ; } ) . join ( "\n" ) ; console . log ( "Shader Error : \n" + numberedLines ) ; } /**
 * Blend Modes
 */ export enum BlendMode { REPLACE = 1 , MAXIMUM , MINIMUM , FIFTY_FIFTY , ADDITIVE , SUB_DEST_SRC , SUB_SRC_DEST , MULTIPLY , MULTIPLY2 , ADJUSTABLE , ALPHA , ABSOLUTE_DIFFERENCE } /**
 * AudioChannels
 */ export enum AudioChannels { CENTER = 0 , LEFT , RIGHT } /**
 * AudioSource
 */ export enum AudioSource { SPECTRUM = 1 , WAVEFORM } param count param chars export function randString ( count , chars ) { const randStr = [ ] ; chars = chars || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ; for ( let i = 0 ; i < count ; i ++ ) { randStr . push ( chars . charAt ( Math . floor ( Math . random ( ) * chars . length ) ) ) ; } return randStr . join ( "" ) ; } /**
 * WebGL data types
 */ export enum WebGLVarType { TEXTURE2D = "texture2D" , _1F = "1f" , _2F = "2f" , _3F = "3f" , _4F = "4f" , _1I = "1i" , _2I = "2i" , _3I = "3i" , _4I = "4i" , _1FV = "1fv" , _2FV = "2fv" , _3FV = "3fv" , _4FV = "4fv" , _1IV = "1iv" , _2IV = "2iv" , _3IV = "3iv" , _4IV = "4iv" } export type FloatArray = number [ ] | Float32Array | Float64Array ; export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array ; export function isTypedArray ( array ) { return ( array instanceof Int8Array || array instanceof Uint8Array || array instanceof Uint8ClampedArray || array instanceof Int16Array || array instanceof Uint16Array || array instanceof Int32Array || array instanceof Uint32Array || array instanceof Float32Array || array instanceof Float64Array ) ; } param num param min param max export function clamp ( num , min , max ) { return Math . min ( Math . max ( num , min ) , max ) ; } param obj param name export function getProperty ( obj , name ) { if ( typeof name === "string" ) { name = name . split ( "." ) ; } const value = obj [ name . shift ( ) ] ; if ( value ) { if ( name . length > 0 ) { return getProperty ( value , name ) ; } else { return value ; } } } param obj param name param value export function setProperty ( obj , name , value ) { if ( typeof name === "string" ) { name = name . split ( "." ) ; } const propertyName = name . shift ( ) ; if ( name . length === 0 ) { obj [ propertyName ] = value ; } else { setProperty ( obj [ propertyName ] , name , value ) ; } } param value param sep export function flatString ( value , sep = "\n" ) { if ( typeof ( value ) === "string" ) { return value ; } else { return value . join ( sep ) ; } }