export interface GlslVariable { /** Variable type, e.g. 'vec3' or 'float' */ variableType: string; /** Minified variable name */ variableName: string; } /** Map of original unminified names to their minified details */ export interface GlslVariableMap { [original: string]: GlslVariable; } /** A minified shader output by webpack-glsl-minify */ export interface GlslShader { /** Minified GLSL code */ sourceCode: string; /** Uniform variable names. Maps the original unminified name to its minified details. */ uniforms: GlslVariableMap; /** Constant variables. Maps the orignal unminified name to the substitution value. */ consts: GlslVariableMap; } export interface GlslFile { /** Full path of the file (for resolving further @include directives) */ path?: string; /** Unparsed file contents */ contents: string; } /** * Helper class to minify tokens and track reserved ones */ export declare class TokenMap { private options; constructor(options: GlslMinifyOptions); /** * The underlying token map itself. Although the data type is GlslUniform, it is used for all tokens, not just * uniforms. The type property of GlslUniform is only set for uniforms, however. */ private tokens; /** * Adds keywords to the reserved list to prevent minifying them. * @param keywords Array of strings containing keywords to preserve */ reserveKeywords(keywords: string[]): void; /** * Number of tokens minified. Used to generate unique names. Although we could be more sophisticated, and count * usage, we simply assign names in order. Few shaders have more than 52 variables (the number of single-letter * variable names), so simple is good enough. */ private minifiedTokenCount; /** * Converts a token number to a name */ static getMinifiedName(tokenCount: number): string; /** * Minifies a token * @param name Token name * @param uniformType If the token is a uniform, the data type * @returns Minified token name */ minifyToken(name: string, uniformType?: string): string; /** * Returns the uniforms and their associated data types */ getUniforms(): GlslVariableMap; } export declare enum TokenType { /** A user-created token such as a custom function or variable name */ ttToken = 0, /** * A built-in token in the GLSL language, such as a function or reserved keyword. (Note: types and type qualifiers * are handled specially below) */ ttReservedToken = 1, /** A variable type: int, float, vec2, etc. */ ttType = 2, /** The attribute keyword */ ttAttribute = 3, /** The uniform keyword */ ttUniform = 4, /** The varying keyword */ ttVarying = 5, /** The layout keyword */ ttLayout = 6, /** The in and out keywords */ ttInOut = 7, /** An operator, excluding parentheses, dots, braces, brackets, and semicolons */ ttOperator = 8, /** ( */ ttOpenParenthesis = 9, /** ) */ ttCloseParenthesis = 10, /** { */ ttOpenBrace = 11, /** } */ ttCloseBrace = 12, /** [ */ ttOpenBracket = 13, /** ] */ ttCloseBracket = 14, /** A semicolon */ ttSemicolon = 15, /** The dot operator. This operator has special meaning in GLSL due to vector swizzle masks. */ ttDot = 16, /** A numeric value */ ttNumeric = 17, /** A GLSL preprocessor directive */ ttPreprocessor = 18, /** Special value used in the parser when there is no token */ ttNone = 19 } /** Implementation of NodeJS's readFile() API. */ export declare type ReadFileImpl = (filename: string, directory?: string) => Promise; /** Stub implementation of NodeJS's readFile() API to work in browsers and non-NodeJS environments */ declare function nullReadFile(_filename: string, _directory?: string): Promise; /** Implementation of NodeJS's dirname() API */ export declare type DirnameImpl = (p: string) => string; /** Stub implementation of NodeJS's dirname() API to work in browsers and non-NodeJS environments */ export declare function nullDirname(_p: string): string; /** Options for the GLSL shader minifier */ export interface GlslMinifyOptions { /** Output format. Default = 'object'. */ output?: GlslOutputFormat; /** Uses ES modules syntax. Applies to the "object" and "source" output formats. Default = false. */ esModule?: boolean; /** Strips any #version directives. Default = false. */ stripVersion?: boolean; /** Disables name mangling of #defines. Default = false. */ preserveDefines?: boolean; /** Disables name mangling of uniforms. Default = false. */ preserveUniforms?: boolean; /** Disables name mangling of variables. Default = false. */ preserveVariables?: boolean; /** Disables all mangling. Default = false. */ preserveAll?: boolean; /** Additional variable names or keywords to explicitly disable name mangling */ nomangle?: string[]; /** Only process includes, leave the rest of the file as-is (for development) Default = false. */ includesOnly?: boolean; } /** * Output format. Default is 'object'. * * 'object': Outputs a JavaScript file exporting an object. The object contains the source code and map of mangled * uniforms and consts. * * 'source': Outputs a JavaScript file exporting the source code as a string. Automatically disables mangling. * * 'sourceOnly': Outputs a GLSL file without the JavaScript wrapper. Automatically disables mangling. Only supported * in the CLI app, not the Webpack loader. */ export declare type GlslOutputFormat = 'object' | 'source' | 'sourceOnly'; /** GLSL shader minifier */ export declare class GlslMinify { /** List of tokens minified by the parser */ private tokens; /** * Constructor * @param options Minifier options. See GlslMinifyOptions for details. * @param readFile Implementation of NodeJS's readFile() API. Three variations are included with the * webpack-glsl-minify package: nodeReadFile() for NodeJS apps, webpackReadFile() for the Webpack plugin, and * nullReadFile() for browsers and other environments that don't support reading files from the local disk. * @param dirname Implementation of NodeJS's dirname() API. Two variations are included with the webpack-glsl-minify * package: nodeDirname() for NodeJS and Webpack and nullDirname() for browsers and other environments that don't * support reading files from the local disk. */ constructor(options?: GlslMinifyOptions, readFile?: typeof nullReadFile, dirname?: typeof nullDirname); execute(content: string): Promise; executeFile(input: GlslFile): Promise; protected processIncludes(content: GlslFile): Promise; /** * The first pass of the preprocessor removes comments */ protected preprocessPass1(content: string): string; private constValues; /** * Substitution values are of the form "$0$" */ private substitutionValueCount; private assignSubstitionValue; /** * The second pass of the preprocessor handles nomange and define directives */ protected preprocessPass2(content: string): string; /** Determines the token type of a token string */ protected static getTokenType(token: string): TokenType; /** * The final pass consists of the actual minifier itself */ protected minifier(content: string): string; executeAndStringify(content: string): Promise; executeFileAndStringify(input: GlslFile): Promise; /** Similar to JSON.stringify(), except without double-quotes around property names */ static stringify(obj: any): string; protected options: GlslMinifyOptions; protected readFile: ReadFileImpl; protected dirname: DirnameImpl; } export {};